Skip to content

Commit 25253d8

Browse files
committed
Convert lz4-compress.js to mjs. NFC
1 parent 0b8b752 commit 25253d8

File tree

6 files changed

+22
-39
lines changed

6 files changed

+22
-39
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"scripts": {
2222
"lint": "eslint .",
23-
"fmt": "prettier --write tools/*.js",
24-
"check": "prettier --check tools/*.js"
23+
"fmt": "prettier --write tools/*.mjs",
24+
"check": "prettier --check tools/*.mjs"
2525
}
2626
}

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2529,7 +2529,7 @@ def test_preload_module(self, args):
25292529
''')
25302530
self.btest_exit(
25312531
'main.c',
2532-
args=['-sMAIN_MODULE=2', '--preload-file', '.@/', '-O2', '--use-preload-plugins'] + args)
2532+
args=['-sMAIN_MODULE=2', '--preload-file', '.@/', '--use-preload-plugins'] + args)
25332533

25342534
# This does not actually verify anything except that --cpuprofiler and --memoryprofiler compiles.
25352535
# Run interactive.test_cpuprofiler_memoryprofiler for interactive testing.

third_party/mini-lz4.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,6 @@ return exports;
343343

344344
})();
345345

346+
if (typeof module != 'undefined') {
347+
module.exports = MiniLZ4;
348+
}

tools/file_packager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,8 @@ def generate_js(data_target, data_files, metadata):
745745
# LZ4FS usage
746746
temp = data_target + '.orig'
747747
shutil.move(data_target, temp)
748-
meta = shared.run_js_tool(utils.path_from_root('tools/lz4-compress.js'),
749-
[utils.path_from_root('third_party/mini-lz4.js'),
750-
temp, data_target], stdout=PIPE)
748+
meta = shared.run_js_tool(utils.path_from_root('tools/lz4-compress.mjs'),
749+
[temp, data_target], stdout=PIPE)
751750
os.unlink(temp)
752751
use_data = '''var compressedData = %s;
753752
compressedData['data'] = byteArray;

tools/lz4-compress.js renamed to tools/lz4-compress.mjs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
// University of Illinois/NCSA Open Source License. Both these licenses can be
55
// found in the LICENSE file.
66

7-
'use strict';
8-
9-
const fs = require('fs');
10-
const path = require('path');
11-
12-
const arguments_ = process.argv.slice(2);
13-
const debug = false;
7+
import * as fs from 'fs';
8+
import * as path from 'path';
149

1510
function print(x) {
1611
process.stdout.write(x + '\n');
@@ -20,38 +15,24 @@ function printErr(x) {
2015
process.stderr.write(x + '\n');
2116
}
2217

23-
function read(filename, binary) {
24-
filename = path.normalize(filename);
25-
let ret = fs.readFileSync(filename);
26-
if (ret && !binary) ret = ret.toString();
27-
return ret;
28-
}
29-
30-
function readBinary(filename) {
31-
return read(filename, true);
32-
}
33-
34-
function globalEval(x) {
35-
eval.call(null, x);
36-
}
37-
38-
function load(f) {
39-
globalEval(read(f));
40-
}
41-
42-
global.assert = (x, message) => {
18+
globalThis.assert = (x, message) => {
4319
if (!x) throw new Error(message);
4420
};
4521

4622
// Redirect console.log message from MiniLZ4 to stderr since stdout is
4723
// where we return the decompressed data.
4824
console.log = printErr;
4925

50-
const lz4 = arguments_[0];
51-
const input = arguments_[1];
52-
const output = arguments_[2];
26+
const MiniLZ4 = await import('../third_party/mini-lz4.js');
5327

54-
load(lz4);
28+
function readBinary(filename) {
29+
filename = path.normalize(filename);
30+
return fs.readFileSync(filename);
31+
}
32+
33+
const arguments_ = process.argv.slice(2);
34+
const input = arguments_[0];
35+
const output = arguments_[1];
5536

5637
const data = new Uint8Array(readBinary(input)).buffer;
5738
const start = Date.now();

tools/preprocessor.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ global.read = (filename) => {
5252
};
5353

5454
global.load = (f) => {
55-
vm.runInThisContext(read(f), { filename: find(f) });
55+
vm.runInThisContext(read(f), {filename: find(f)});
5656
};
5757

5858
assert(args.length >= 2);
@@ -67,6 +67,6 @@ load('parseTools.js');
6767

6868
let output = preprocess(inputFile);
6969
if (expandMacros) {
70-
output = processMacros(output, inputFile)
70+
output = processMacros(output, inputFile);
7171
}
7272
process.stdout.write(output);

0 commit comments

Comments
 (0)