From fa55736604c1426261446ddbc2c85bc3dce6aca1 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 11 Mar 2024 09:54:38 -0700 Subject: [PATCH] Convert lz4-compress.js to mjs. NFC --- third_party/mini-lz4.js | 1 + tools/file_packager.py | 5 ++--- tools/{lz4-compress.js => lz4-compress.mjs} | 23 ++++++++------------- 3 files changed, 12 insertions(+), 17 deletions(-) rename tools/{lz4-compress.js => lz4-compress.mjs} (85%) diff --git a/third_party/mini-lz4.js b/third_party/mini-lz4.js index 06514fec54de0..08fcd6d51c4d8 100644 --- a/third_party/mini-lz4.js +++ b/third_party/mini-lz4.js @@ -343,3 +343,4 @@ return exports; })(); +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 85% rename from tools/lz4-compress.js rename to tools/lz4-compress.mjs index 1ddd11d3a9b06..e711255a2c0b2 100755 --- a/tools/lz4-compress.js +++ b/tools/lz4-compress.mjs @@ -4,13 +4,14 @@ // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. -'use strict'; +import * as fs from 'fs'; +import * as path from 'path'; -const fs = require('fs'); -const path = require('path'); +globalThis.assert = (x, message) => { + if (!x) throw new Error(message); +}; -const arguments_ = process.argv.slice(2); -const debug = false; +const MiniLZ4 = await import('../third_party/mini-lz4.js'); function print(x) { process.stdout.write(x + '\n'); @@ -39,19 +40,13 @@ function load(f) { globalEval(read(f)); } -global.assert = (x, message) => { - if (!x) throw new Error(message); -}; - // Redirect console.log message from MiniLZ4 to stderr since stdout is // where we return the decompressed data. console.log = printErr; -const lz4 = arguments_[0]; -const input = arguments_[1]; -const output = arguments_[2]; - -load(lz4); +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();