14
14
15
15
'use strict' ;
16
16
17
- const fs = require ( 'fs' ) ;
18
- const path = require ( 'path' ) ;
19
- global . vm = require ( 'vm' ) ;
17
+ import * as fs from 'fs' ;
18
+ import * as path from 'path' ;
19
+ import * as vm from 'vm' ;
20
+ import assert from 'assert' ;
21
+ import * as url from 'url' ;
20
22
21
- const arguments_ = process . argv . slice ( 2 ) ;
23
+ const args = process . argv . slice ( 2 ) ;
22
24
const debug = false ;
23
25
26
+ // Anything needed by the script that we load below must be added to the
27
+ // global object. These, for example, are all needed by parseTools.js.
28
+ global . vm = vm ;
29
+ global . assert = assert ;
24
30
global . print = ( x ) => {
25
31
process . stdout . write ( x + '\n' ) ;
26
32
} ;
27
33
global . printErr = ( x ) => {
28
34
process . stderr . write ( x + '\n' ) ;
29
35
} ;
30
36
31
- global . assert = require ( 'assert' ) ;
32
-
33
37
function find ( filename ) {
34
- const prefixes = [ process . cwd ( ) , path . join ( __dirname , '..' , 'src' ) ] ;
38
+ const dirname = url . fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
39
+ const prefixes = [ process . cwd ( ) , path . join ( dirname , '..' , 'src' ) ] ;
35
40
for ( let i = 0 ; i < prefixes . length ; ++ i ) {
36
41
const combined = path . join ( prefixes [ i ] , filename ) ;
37
42
if ( fs . existsSync ( combined ) ) {
@@ -50,9 +55,10 @@ global.load = (f) => {
50
55
( 0 , eval ) ( read ( f ) + '//# sourceURL=' + find ( f ) ) ;
51
56
} ;
52
57
53
- const settingsFile = arguments_ [ 0 ] ;
54
- const inputFile = arguments_ [ 1 ] ;
55
- const expandMacros = arguments_ . includes ( '--expandMacros' ) ;
58
+ assert ( args . length >= 2 ) ;
59
+ const settingsFile = args [ 0 ] ;
60
+ const inputFile = args [ 1 ] ;
61
+ const expandMacros = args . includes ( '--expandMacros' ) ;
56
62
57
63
load ( settingsFile ) ;
58
64
load ( 'utility.js' ) ;
0 commit comments