diff options
| author | akiyamn | 2023-09-24 23:22:21 +1000 |
|---|---|---|
| committer | akiyamn | 2023-09-24 23:22:21 +1000 |
| commit | 4e87195739f2a5d9a05451b48773c8afdc680765 (patch) | |
| tree | 9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/blake3-wasm/esm/build/add-js-extensions.js | |
| download | price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip | |
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/blake3-wasm/esm/build/add-js-extensions.js')
| -rw-r--r-- | node_modules/blake3-wasm/esm/build/add-js-extensions.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/node_modules/blake3-wasm/esm/build/add-js-extensions.js b/node_modules/blake3-wasm/esm/build/add-js-extensions.js new file mode 100644 index 0000000..d7f4b40 --- /dev/null +++ b/node_modules/blake3-wasm/esm/build/add-js-extensions.js @@ -0,0 +1,40 @@ +import * as ts from 'typescript.js'; +import { readFileSync, writeFileSync, readdirSync, statSync } from 'fs.js'; +import { extname, basename, join, resolve } from 'path.js'; +/** + * Script that adds .js extension to imports so that it's compatible with plain + * browser/non-webpack bundlers. TS doesn't support this natively yet. + * @see https://github.com/microsoft/TypeScript/issues/16577 + */ +function processFile(file) { + let source = readFileSync(file, 'utf-8'); + const program = ts.createSourceFile(basename(file), source, ts.ScriptTarget.ES2015, true); + let offset = 0; + const process = (node) => { + if ((!ts.isImportDeclaration(node) && !ts.isExportDeclaration(node)) || !node.moduleSpecifier) { + return ts.forEachChild(node, process); + } + const specifier = node.moduleSpecifier; + if (extname(specifier.getText()) === '') { + const idx = specifier.end + offset - 1; + source = source.slice(0, idx) + '.js' + source.slice(idx); + offset += 3; + } + }; + process(program); + writeFileSync(file, source); +} +function processDir(dir) { + const entries = readdirSync(dir); + for (const entry of entries) { + const path = join(dir, entry); + if (path.endsWith('.js')) { + processFile(path); + } + else if (statSync(path).isDirectory()) { + processDir(path); + } + } +} +processDir(resolve(__dirname, '..', '..', 'esm')); +//# sourceMappingURL=add-js-extensions.js.map
\ No newline at end of file |
