33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- 'use strict' ;
6+ import path from 'node:path' ;
7+ import fs from 'node:fs' ;
8+ import { fileURLToPath } from 'node:url' ;
79
8- var path = require ( 'path' ) ;
9- var fs = require ( 'fs' ) ;
10+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
1011
1112function getVersion ( moduleName ) {
12- var packageJSONPath = path . join ( __dirname , '..' , 'node_modules' , moduleName , 'package.json' ) ;
13+ const packageJSONPath = path . join ( __dirname , '..' , 'node_modules' , moduleName , 'package.json' ) ;
1314 return readFile ( packageJSONPath ) . then ( function ( content ) {
1415 try {
1516 return JSON . parse ( content ) . version ;
1617 } catch ( e ) {
17- return Promise . resolve ( null ) ;
18+ return null ;
1819 }
1920 } ) ;
2021}
2122
22- function readFile ( path ) {
23+ function readFile ( filePath ) {
2324 return new Promise ( ( s , e ) => {
24- fs . readFile ( path , ( err , res ) => {
25+ fs . readFile ( filePath , ( err , res ) => {
2526 if ( err ) {
2627 e ( err ) ;
2728 } else {
@@ -33,7 +34,7 @@ function readFile(path) {
3334}
3435
3536function update ( moduleName , repoPath , dest , addHeader , patch ) {
36- var contentPath = path . join ( __dirname , '..' , 'node_modules' , moduleName , repoPath ) ;
37+ const contentPath = path . join ( __dirname , '..' , 'node_modules' , moduleName , repoPath ) ;
3738 console . log ( 'Reading from ' + contentPath ) ;
3839 return readFile ( contentPath ) . then ( function ( content ) {
3940 return getVersion ( moduleName ) . then ( function ( version ) {
@@ -62,12 +63,10 @@ function update(moduleName, repoPath, dest, addHeader, patch) {
6263 } , console . error ) ;
6364}
6465
65- update ( 'js-beautify' , 'js/lib/beautify-html.js' , './src/beautify/beautify-html.js' , true ) ;
66- update ( 'js-beautify' , 'js/lib/beautify-css.js' , './src/beautify/beautify-css.js' , true ) ;
6766update ( 'js-beautify' , 'LICENSE' , './src/beautify/beautify-license' ) ;
6867
6968// ESM version
70- update ( 'js-beautify' , 'js/lib/beautify-html.js' , './src/beautify/esm/ beautify-html.js' , true , function ( contents ) {
69+ update ( 'js-beautify' , 'js/lib/beautify-html.js' , './src/beautify/beautify-html.js' , true , function ( contents ) {
7170 let topLevelFunction = '(function() {' ;
7271 let outputVar = 'var legacy_beautify_html' ;
7372 let footer = 'var style_html = legacy_beautify_html;' ;
@@ -84,14 +83,14 @@ update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/esm/beautify-ht
8483 throw new Error ( `Problem patching beautify.html for ESM: '${ footer } ' not found after '${ outputVar } '.` ) ;
8584 }
8685 return contents . substring ( 0 , index1 ) +
87- `import { js_beautify } from "./beautify";\nimport { css_beautify } from "./beautify-css";\n\n`
86+ `import { js_beautify } from "./beautify.js ";\nimport { css_beautify } from "./beautify-css.js ";\n\n`
8887 + contents . substring ( index2 , index3 ) +
8988`
9089export function html_beautify(html_source, options) {
9190 return legacy_beautify_html(html_source, options, js_beautify, css_beautify);
9291}` ;
9392} ) ;
94- update ( 'js-beautify' , 'js/lib/beautify-css.js' , './src/beautify/esm/ beautify-css.js' , true , function ( contents ) {
93+ update ( 'js-beautify' , 'js/lib/beautify-css.js' , './src/beautify/beautify-css.js' , true , function ( contents ) {
9594 let topLevelFunction = '(function() {' ;
9695 let outputVar = 'var legacy_beautify_css' ;
9796 let footer = 'var css_beautify = legacy_beautify_css;' ;
0 commit comments