diff --git a/package.json b/package.json index d7d852c2fedb4..43d58cabaf944 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "scripts": { "lint": "eslint .", - "fmt": "prettier --write tools/*.js", - "check": "prettier --check tools/*.js" + "fmt": "prettier --write tools/*.mjs", + "check": "prettier --check tools/*.mjs" } } diff --git a/test/test_browser.py b/test/test_browser.py index 0c7048c7c2eb9..c58099a5df6c0 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -2529,7 +2529,7 @@ def test_preload_module(self, args): ''') self.btest_exit( 'main.c', - args=['-sMAIN_MODULE=2', '--preload-file', '.@/', '-O2', '--use-preload-plugins'] + args) + args=['-sMAIN_MODULE=2', '--preload-file', '.@/', '--use-preload-plugins'] + args) # This does not actually verify anything except that --cpuprofiler and --memoryprofiler compiles. # Run interactive.test_cpuprofiler_memoryprofiler for interactive testing. diff --git a/third_party/mini-lz4.js b/third_party/mini-lz4.js index 06514fec54de0..f9cbe532e5a0c 100644 --- a/third_party/mini-lz4.js +++ b/third_party/mini-lz4.js @@ -343,3 +343,6 @@ return exports; })(); +if (typeof module != 'undefined') { + module.exports = MiniLZ4; +} diff --git a/tools/file_packager.py b/tools/file_packager.py index 9f39984b46fca..d4c29ea7d10f1 100755 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -745,9 +745,8 @@ def generate_js(data_target, data_files, metadata): # LZ4FS usage temp = data_target + '.orig' shutil.move(data_target, temp) - meta = shared.run_js_tool(utils.path_from_root('tools/lz4-compress.js'), - [utils.path_from_root('third_party/mini-lz4.js'), - temp, data_target], stdout=PIPE) + meta = shared.run_js_tool(utils.path_from_root('tools/lz4-compress.mjs'), + [temp, data_target], stdout=PIPE) os.unlink(temp) use_data = '''var compressedData = %s; compressedData['data'] = byteArray; diff --git a/tools/lz4-compress.js b/tools/lz4-compress.mjs similarity index 67% rename from tools/lz4-compress.js rename to tools/lz4-compress.mjs index 1ddd11d3a9b06..bfad03aa03909 100755 --- a/tools/lz4-compress.js +++ b/tools/lz4-compress.mjs @@ -4,13 +4,8 @@ // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. -'use strict'; - -const fs = require('fs'); -const path = require('path'); - -const arguments_ = process.argv.slice(2); -const debug = false; +import * as fs from 'fs'; +import * as path from 'path'; function print(x) { process.stdout.write(x + '\n'); @@ -20,26 +15,7 @@ function printErr(x) { process.stderr.write(x + '\n'); } -function read(filename, binary) { - filename = path.normalize(filename); - let ret = fs.readFileSync(filename); - if (ret && !binary) ret = ret.toString(); - return ret; -} - -function readBinary(filename) { - return read(filename, true); -} - -function globalEval(x) { - eval.call(null, x); -} - -function load(f) { - globalEval(read(f)); -} - -global.assert = (x, message) => { +globalThis.assert = (x, message) => { if (!x) throw new Error(message); }; @@ -47,11 +23,16 @@ global.assert = (x, message) => { // where we return the decompressed data. console.log = printErr; -const lz4 = arguments_[0]; -const input = arguments_[1]; -const output = arguments_[2]; +const MiniLZ4 = await import('../third_party/mini-lz4.js'); -load(lz4); +function readBinary(filename) { + filename = path.normalize(filename); + return fs.readFileSync(filename); +} + +const arguments_ = process.argv.slice(2); +const input = arguments_[0]; +const output = arguments_[1]; const data = new Uint8Array(readBinary(input)).buffer; const start = Date.now(); diff --git a/tools/preprocessor.mjs b/tools/preprocessor.mjs index cce73451177de..188f385d97bd5 100755 --- a/tools/preprocessor.mjs +++ b/tools/preprocessor.mjs @@ -52,7 +52,7 @@ global.read = (filename) => { }; global.load = (f) => { - vm.runInThisContext(read(f), { filename: find(f) }); + vm.runInThisContext(read(f), {filename: find(f)}); }; assert(args.length >= 2); @@ -67,6 +67,6 @@ load('parseTools.js'); let output = preprocess(inputFile); if (expandMacros) { - output = processMacros(output, inputFile) + output = processMacros(output, inputFile); } process.stdout.write(output);