diff --git a/DEVELOPING.md b/DEVELOPING.md index cd5c7a1..6ec040d 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -32,10 +32,12 @@ build_worker_browser out='worker/browser' args='[]': # <-- we accept args and an [{ "format": "esm", "alias": { - "js-sdk:capabilities": "./src/polyfills/browser-capabilities.ts", "node:worker_threads": "./src/polyfills/worker-node-worker_threads.ts", - "js-sdk:fs": "./src/polyfills/browser-fs.ts", - "js-sdk:wasi": "./src/polyfills/browser-wasi.ts", + }, + "polyfills": { + "./src/polyfills/deno-capabilities.ts": "./src/polyfills/browser-capabilities.ts", + "./src/polyfills/deno-fs.ts": "./src/polyfills/browser-fs.ts", + "./src/polyfills/deno-wasi.ts": "./src/polyfills/browser-wasi.ts", } }] + . # <--- add this recipe's flags to the incoming flags. ')" @@ -52,11 +54,22 @@ via `tsc`. We use `esbuild` to compile to these targets. This allows us to abstract differences at module boundaries and replace them as-needed. For example: each of Node, Deno, and the Browser have different WASI libraries with slightly different -interfaces. We define a **virtual module**, `js-sdk:wasi`, and implement it by: - -1. Modifying `deno.json`; adding a mapping from `js-sdk:wasi` to `./src/polyfills/deno-wasi.ts`. -2. Adding a `types/js-sdk:wasi/index.d.ts` file. -3. Modifying the esbuild `alias` added by `build_worker`, `build_worker_node`, +interfaces. We default to Deno's definition of the polyfills, then map to polyfills +for our specific target. + +> **Note** +> Polyfills were initially implemented as `js-sdk:POLYFILL` modules, which have the advantage +> that `esbuild` is able to use its `alias` feature to map them without any extra plugins. +> +> However, this required using `deno.json`'s import maps to resolve the modules in the Deno target. +> At the time of writing, Deno does not support import maps for package dependencies, only for top-level +> applications, which means we can't make use of those. Deno [notes they are working](https://hachyderm.io/@deno_land@fosstodon.org/111693831461332098) +> on a feature for to support this use-case, though, so we'll want to track where they end up. + +1. If the polyfill introduces dependencies on `deno.land`, add them to `types/deno/index.d.ts` to + provide support for other languages. + - These typings don't have to be exact -- they can be "best effort" if you have to write them yourself. +2. Modifying the esbuild `polyfills` added by `build_worker`, `build_worker_node`, `build_node_cjs`, `build_node_esm`, and `build_browser`. - Node overrides are set to `./src/polyfills/node-wasi.ts`. - Browser overrides are set to `./src/polyfills/browser-wasi.ts`. diff --git a/deno.json b/deno.json deleted file mode 100644 index 6ce97fd..0000000 --- a/deno.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "imports": { - "js-sdk:worker-url": "./src/worker-url.ts", - "js-sdk:response-to-module": "./src/polyfills/response-to-module.ts", - "js-sdk:minimatch": "./src/polyfills/deno-minimatch.ts", - "js-sdk:capabilities": "./src/polyfills/deno-capabilities.ts", - "js-sdk:wasi": "./src/polyfills/deno-wasi.ts", - "js-sdk:fs": "./src/polyfills/node-fs.ts" - } -} diff --git a/deno.lock b/deno.lock deleted file mode 100644 index 221205f..0000000 --- a/deno.lock +++ /dev/null @@ -1,99 +0,0 @@ -{ - "version": "3", - "packages": { - "specifiers": { - "npm:@types/node": "npm:@types/node@18.16.19" - }, - "npm": { - "@types/node@18.16.19": { - "integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==", - "dependencies": {} - } - } - }, - "redirects": { - "https://deno.land/std/path/mod.ts": "https://deno.land/std@0.204.0/path/mod.ts" - }, - "remote": { - "https://deno.land/std@0.200.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", - "https://deno.land/std@0.200.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", - "https://deno.land/std@0.200.0/path/_relative.ts": "27bdeffb5311a47d85be26d37ad1969979359f7636c5cd9fcf05dcd0d5099dc5", - "https://deno.land/std@0.200.0/path/_resolve.ts": "7a3616f1093735ed327e758313b79c3c04ea921808ca5f19ddf240cb68d0adf6", - "https://deno.land/std@0.200.0/path/_util.ts": "4e191b1bac6b3bf0c31aab42e5ca2e01a86ab5a0d2e08b75acf8585047a86221", - "https://deno.land/std@0.200.0/path/relative.ts": "7db80c5035016174267da16321a742d76e875215c317859a383b12f413c6f5d6", - "https://deno.land/std@0.200.0/path/resolve.ts": "103b62207726a27f28177f397008545804ecb20aaf00623af1f622b18cd80b9f", - "https://deno.land/std@0.200.0/wasi/snapshot_preview1.ts": "25c18c35df4ba5755b059d3e178f3478ff210dc7fe7baef12e495cf2ed0a8b13", - "https://deno.land/std@0.204.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", - "https://deno.land/std@0.204.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", - "https://deno.land/std@0.204.0/path/_common/assert_path.ts": "061e4d093d4ba5aebceb2c4da3318bfe3289e868570e9d3a8e327d91c2958946", - "https://deno.land/std@0.204.0/path/_common/basename.ts": "0d978ff818f339cd3b1d09dc914881f4d15617432ae519c1b8fdc09ff8d3789a", - "https://deno.land/std@0.204.0/path/_common/common.ts": "9e4233b2eeb50f8b2ae10ecc2108f58583aea6fd3e8907827020282dc2b76143", - "https://deno.land/std@0.204.0/path/_common/constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", - "https://deno.land/std@0.204.0/path/_common/dirname.ts": "2ba7fb4cc9fafb0f38028f434179579ce61d4d9e51296fad22b701c3d3cd7397", - "https://deno.land/std@0.204.0/path/_common/format.ts": "11aa62e316dfbf22c126917f5e03ea5fe2ee707386555a8f513d27ad5756cf96", - "https://deno.land/std@0.204.0/path/_common/from_file_url.ts": "ef1bf3197d2efbf0297a2bdbf3a61d804b18f2bcce45548ae112313ec5be3c22", - "https://deno.land/std@0.204.0/path/_common/glob_to_reg_exp.ts": "5c3c2b79fc2294ec803d102bd9855c451c150021f452046312819fbb6d4dc156", - "https://deno.land/std@0.204.0/path/_common/is_glob.ts": "567dce5c6656bdedfc6b3ee6c0833e1e4db2b8dff6e62148e94a917f289c06ad", - "https://deno.land/std@0.204.0/path/_common/normalize.ts": "2ba7fb4cc9fafb0f38028f434179579ce61d4d9e51296fad22b701c3d3cd7397", - "https://deno.land/std@0.204.0/path/_common/normalize_string.ts": "88c472f28ae49525f9fe82de8c8816d93442d46a30d6bb5063b07ff8a89ff589", - "https://deno.land/std@0.204.0/path/_common/relative.ts": "1af19d787a2a84b8c534cc487424fe101f614982ae4851382c978ab2216186b4", - "https://deno.land/std@0.204.0/path/_common/strip_trailing_separators.ts": "7ffc7c287e97bdeeee31b155828686967f222cd73f9e5780bfe7dfb1b58c6c65", - "https://deno.land/std@0.204.0/path/_common/to_file_url.ts": "a8cdd1633bc9175b7eebd3613266d7c0b6ae0fb0cff24120b6092ac31662f9ae", - "https://deno.land/std@0.204.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", - "https://deno.land/std@0.204.0/path/_os.ts": "30b0c2875f360c9296dbe6b7f2d528f0f9c741cecad2e97f803f5219e91b40a2", - "https://deno.land/std@0.204.0/path/basename.ts": "04bb5ef3e86bba8a35603b8f3b69537112cdd19ce64b77f2522006da2977a5f3", - "https://deno.land/std@0.204.0/path/common.ts": "f4d061c7d0b95a65c2a1a52439edec393e906b40f1caf4604c389fae7caa80f5", - "https://deno.land/std@0.204.0/path/dirname.ts": "88a0a71c21debafc4da7a4cd44fd32e899462df458fbca152390887d41c40361", - "https://deno.land/std@0.204.0/path/extname.ts": "2da4e2490f3b48b7121d19fb4c91681a5e11bd6bd99df4f6f47d7a71bb6ecdf2", - "https://deno.land/std@0.204.0/path/format.ts": "3457530cc85d1b4bab175f9ae73998b34fd456c830d01883169af0681b8894fb", - "https://deno.land/std@0.204.0/path/from_file_url.ts": "e7fa233ea1dff9641e8d566153a24d95010110185a6f418dd2e32320926043f8", - "https://deno.land/std@0.204.0/path/glob.ts": "9c77cf47db1d786e2ebf66670824d03fd84ecc7c807cac24441eb9d5cb6a2986", - "https://deno.land/std@0.204.0/path/is_absolute.ts": "67232b41b860571c5b7537f4954c88d86ae2ba45e883ee37d3dec27b74909d13", - "https://deno.land/std@0.204.0/path/join.ts": "98d3d76c819af4a11a81d5ba2dbb319f1ce9d63fc2b615597d4bcfddd4a89a09", - "https://deno.land/std@0.204.0/path/mod.ts": "2d62a0a8b78a60e8e6f485d881bac6b61d58573b11cf585fb7c8fc50d9b20d80", - "https://deno.land/std@0.204.0/path/normalize.ts": "aa95be9a92c7bd4f9dc0ba51e942a1973e2b93d266cd74f5ca751c136d520b66", - "https://deno.land/std@0.204.0/path/parse.ts": "d87ff0deef3fb495bc0d862278ff96da5a06acf0625ca27769fc52ac0d3d6ece", - "https://deno.land/std@0.204.0/path/posix/_util.ts": "ecf49560fedd7dd376c6156cc5565cad97c1abe9824f4417adebc7acc36c93e5", - "https://deno.land/std@0.204.0/path/posix/basename.ts": "a630aeb8fd8e27356b1823b9dedd505e30085015407caa3396332752f6b8406a", - "https://deno.land/std@0.204.0/path/posix/common.ts": "e781d395dc76f6282e3f7dd8de13194abb8b04a82d109593141abc6e95755c8b", - "https://deno.land/std@0.204.0/path/posix/dirname.ts": "f48c9c42cc670803b505478b7ef162c7cfa9d8e751b59d278b2ec59470531472", - "https://deno.land/std@0.204.0/path/posix/extname.ts": "ee7f6571a9c0a37f9218fbf510c440d1685a7c13082c348d701396cc795e0be0", - "https://deno.land/std@0.204.0/path/posix/format.ts": "b94876f77e61bfe1f147d5ccb46a920636cd3cef8be43df330f0052b03875968", - "https://deno.land/std@0.204.0/path/posix/from_file_url.ts": "b97287a83e6407ac27bdf3ab621db3fccbf1c27df0a1b1f20e1e1b5acf38a379", - "https://deno.land/std@0.204.0/path/posix/glob.ts": "86c3f06d1c98303613c74650961c3e24bdb871cde2a97c3ae7f0f6d4abbef445", - "https://deno.land/std@0.204.0/path/posix/is_absolute.ts": "159900a3422d11069d48395568217eb7fc105ceda2683d03d9b7c0f0769e01b8", - "https://deno.land/std@0.204.0/path/posix/join.ts": "0c0d84bdc344876930126640011ec1b888e6facf74153ffad9ef26813aa2a076", - "https://deno.land/std@0.204.0/path/posix/mod.ts": "6bfa8a42d85345b12dbe8571028ca2c62d460b6ef968125e498602b43b6cf6b6", - "https://deno.land/std@0.204.0/path/posix/normalize.ts": "11de90a94ab7148cc46e5a288f7d732aade1d616bc8c862f5560fa18ff987b4b", - "https://deno.land/std@0.204.0/path/posix/parse.ts": "199208f373dd93a792e9c585352bfc73a6293411bed6da6d3bc4f4ef90b04c8e", - "https://deno.land/std@0.204.0/path/posix/relative.ts": "e2f230608b0f083e6deaa06e063943e5accb3320c28aef8d87528fbb7fe6504c", - "https://deno.land/std@0.204.0/path/posix/resolve.ts": "51579d83159d5c719518c9ae50812a63959bbcb7561d79acbdb2c3682236e285", - "https://deno.land/std@0.204.0/path/posix/separator.ts": "0b6573b5f3269a3164d8edc9cefc33a02dd51003731c561008c8bb60220ebac1", - "https://deno.land/std@0.204.0/path/posix/to_file_url.ts": "08d43ea839ee75e9b8b1538376cfe95911070a655cd312bc9a00f88ef14967b6", - "https://deno.land/std@0.204.0/path/posix/to_namespaced_path.ts": "c9228a0e74fd37e76622cd7b142b8416663a9b87db643302fa0926b5a5c83bdc", - "https://deno.land/std@0.204.0/path/relative.ts": "23d45ede8b7ac464a8299663a43488aad6b561414e7cbbe4790775590db6349c", - "https://deno.land/std@0.204.0/path/resolve.ts": "5b184efc87155a0af9fa305ff68a109e28de9aee81fc3e77cd01380f19daf867", - "https://deno.land/std@0.204.0/path/separator.ts": "40a3e9a4ad10bef23bc2cd6c610291b6c502a06237c2c4cd034a15ca78dedc1f", - "https://deno.land/std@0.204.0/path/to_file_url.ts": "edaafa089e0bce386e1b2d47afe7c72e379ff93b28a5829a5885e4b6c626d864", - "https://deno.land/std@0.204.0/path/to_namespaced_path.ts": "cf8734848aac3c7527d1689d2adf82132b1618eff3cc523a775068847416b22a", - "https://deno.land/std@0.204.0/path/windows/_util.ts": "f32b9444554c8863b9b4814025c700492a2b57ff2369d015360970a1b1099d54", - "https://deno.land/std@0.204.0/path/windows/basename.ts": "8a9dbf7353d50afbc5b221af36c02a72c2d1b2b5b9f7c65bf6a5a2a0baf88ad3", - "https://deno.land/std@0.204.0/path/windows/common.ts": "e781d395dc76f6282e3f7dd8de13194abb8b04a82d109593141abc6e95755c8b", - "https://deno.land/std@0.204.0/path/windows/dirname.ts": "5c2aa541384bf0bd9aca821275d2a8690e8238fa846198ef5c7515ce31a01a94", - "https://deno.land/std@0.204.0/path/windows/extname.ts": "07f4fa1b40d06a827446b3e3bcc8d619c5546b079b8ed0c77040bbef716c7614", - "https://deno.land/std@0.204.0/path/windows/format.ts": "343019130d78f172a5c49fdc7e64686a7faf41553268961e7b6c92a6d6548edf", - "https://deno.land/std@0.204.0/path/windows/from_file_url.ts": "d53335c12b0725893d768be3ac6bf0112cc5b639d2deb0171b35988493b46199", - "https://deno.land/std@0.204.0/path/windows/glob.ts": "0286fb89ecd21db5cbf3b6c79e2b87c889b03f1311e66fb769e6b905d4142332", - "https://deno.land/std@0.204.0/path/windows/is_absolute.ts": "245b56b5f355ede8664bd7f080c910a97e2169972d23075554ae14d73722c53c", - "https://deno.land/std@0.204.0/path/windows/join.ts": "e6600bf88edeeef4e2276e155b8de1d5dec0435fd526ba2dc4d37986b2882f16", - "https://deno.land/std@0.204.0/path/windows/mod.ts": "c3d1a36fbf9f6db1320bcb4fbda8de011d25461be3497105e15cbea1e3726198", - "https://deno.land/std@0.204.0/path/windows/normalize.ts": "9deebbf40c81ef540b7b945d4ccd7a6a2c5a5992f791e6d3377043031e164e69", - "https://deno.land/std@0.204.0/path/windows/parse.ts": "120faf778fe1f22056f33ded069b68e12447668fcfa19540c0129561428d3ae5", - "https://deno.land/std@0.204.0/path/windows/relative.ts": "026855cd2c36c8f28f1df3c6fbd8f2449a2aa21f48797a74700c5d872b86d649", - "https://deno.land/std@0.204.0/path/windows/resolve.ts": "5ff441ab18a2346abadf778121128ee71bda4d0898513d4639a6ca04edca366b", - "https://deno.land/std@0.204.0/path/windows/separator.ts": "ae21f27015f10510ed1ac4a0ba9c4c9c967cbdd9d9e776a3e4967553c397bd5d", - "https://deno.land/std@0.204.0/path/windows/to_file_url.ts": "8e9ea9e1ff364aa06fa72999204229952d0a279dbb876b7b838b2b2fea55cce3", - "https://deno.land/std@0.204.0/path/windows/to_namespaced_path.ts": "e0f4d4a5e77f28a5708c1a33ff24360f35637ba6d8f103d19661255ef7bfd50d", - "https://deno.land/x/minimatch@v3.0.4/index.js": "9325ef4ec1a7e979853cb8dad980d9ee9187cacfdb378599d29b3ae9f431b46d" - } -} diff --git a/justfile b/justfile index c83123e..1ebc6c8 100644 --- a/justfile +++ b/justfile @@ -40,6 +40,7 @@ _build out args='[]': prepare node < { + const resolved = args.reduce((acc, xs) => { for (var key in xs) { const combinator = combine[key] || lastValue(key); acc[key] = combinator(acc, xs); @@ -68,6 +70,35 @@ _build out args='[]': prepare return acc; }, {}) + const { polyfills, ...config } = resolved; + + config.plugins = [{ + name: 'resolve', + setup (build) { + const items = Object.keys(polyfills).map(xs => xs.replace(/\./g, '\\.').replace(/\//g, '\\/')); + build.onResolve({ namespace: 'file', filter: /^\..*\.ts\$/g }, async args => { + if (!args.path.startsWith('.')) { + return { path: args.path, external: true } + } + + const resolved = path.resolve(args.resolveDir, args.path) + const replaced = resolved.replace(process.cwd(), '.').replaceAll(path.sep, path.posix.sep) + + if (!(replaced in polyfills)) { + return { path: path.resolve(args.resolveDir, args.path) } + } + + const result = polyfills[replaced] + if (result[0] === '.') { + return { path: path.resolve(result) } + } + + return { path: result, external: true } + }) + } + }]; + + if (config.platform === 'browser' && config.outdir.startsWith('dist/tests/')) { config.plugins = [].concat(config.plugins || [], [ require('esbuild-node-builtin').nodeBuiltin() @@ -88,7 +119,7 @@ _build out args='[]': prepare fi # build types (TODO: switch module target based on incoming args) - tsc --emitDeclarationOnly --project ./tsconfig.json --declaration --outDir dist/{{ out }} + tsc --emitDeclarationOnly --module esnext --project ./tsconfig.json --declaration --outDir dist/{{ out }} build_worker out args='[]': #!/bin/bash @@ -118,10 +149,10 @@ build_worker_node out='worker/node' args='[]': config="$(<<<'{{ args }}' jq -cM ' [{ "platform": "node", - "alias": { - "js-sdk:capabilities": "./src/polyfills/node-capabilities.ts", - "js-sdk:fs": "node:fs", - "js-sdk:wasi": "./src/polyfills/node-wasi.ts", + "polyfills": { + "./src/polyfills/deno-capabilities.ts": "./src/polyfills/node-capabilities.ts", + "./src/polyfills/node-fs.ts": "node:fs/promises", + "./src/polyfills/deno-wasi.ts": "./src/polyfills/node-wasi.ts", } }] + . ')" @@ -133,10 +164,12 @@ build_worker_browser out='worker/browser' args='[]': [{ "format": "esm", "alias": { - "js-sdk:capabilities": "./src/polyfills/browser-capabilities.ts", - "node:worker_threads": "./src/polyfills/worker-node-worker_threads.ts", - "js-sdk:fs": "./src/polyfills/browser-fs.ts", - "js-sdk:wasi": "./src/polyfills/browser-wasi.ts", + "node:worker_threads": "./src/polyfills/worker-node-worker_threads.ts" + }, + "polyfills": { + "./src/polyfills/deno-capabilities.ts": "./src/polyfills/browser-capabilities.ts", + "./src/polyfills/node-fs.ts": "./src/polyfills/browser-fs.ts", + "./src/polyfills/deno-wasi.ts": "./src/polyfills/browser-wasi.ts", } }] + . ')" @@ -149,13 +182,12 @@ build_node_cjs out='cjs' args='[]': "entryPoints": ["src/mod.ts"], "platform": "node", "minify": false, - "alias": { - "js-sdk:capabilities": "./src/polyfills/node-capabilities.ts", - "js-sdk:response-to-module": "./src/polyfills/response-to-module.ts", - "js-sdk:minimatch": "./src/polyfills/node-minimatch.ts", - "js-sdk:worker-url": "./dist/worker/node/worker-url.ts", - "js-sdk:fs": "node:fs/promises", - "js-sdk:wasi": "./src/polyfills/node-wasi.ts", + "polyfills": { + "./src/polyfills/deno-capabilities.ts": "./src/polyfills/node-capabilities.ts", + "./src/polyfills/deno-minimatch.ts": "./src/polyfills/node-minimatch.ts", + "./src/worker-url.ts": "./dist/worker/node/worker-url.ts", + "./src/polyfills/node-fs.ts": "node:fs/promises", + "./src/polyfills/deno-wasi.ts": "./src/polyfills/node-wasi.ts", }, "define": { "import.meta.url": "__filename" @@ -181,13 +213,12 @@ build_node_esm out='esm' args='[]': "platform": "node", "format": "esm", "minify": false, - "alias": { - "js-sdk:capabilities": "./src/polyfills/node-capabilities.ts", - "js-sdk:response-to-module": "./src/polyfills/response-to-module.ts", - "js-sdk:minimatch": "./src/polyfills/node-minimatch.ts", - "js-sdk:worker-url": "./dist/worker/node/worker-url.ts", - "js-sdk:fs": "node:fs/promises", - "js-sdk:wasi": "./src/polyfills/node-wasi.ts", + "polyfills": { + "./src/polyfills/deno-capabilities.ts": "./src/polyfills/node-capabilities.ts", + "./src/polyfills/deno-minimatch.ts": "./src/polyfills/node-minimatch.ts", + "./src/worker-url.ts": "./dist/worker/node/worker-url.ts", + "./src/polyfills/node-fs.ts": "node:fs/promises", + "./src/polyfills/deno-wasi.ts": "./src/polyfills/node-wasi.ts", } }] + . ')" @@ -202,13 +233,13 @@ build_bun out='bun' args='[]': "platform": "node", "format": "esm", "minify": false, - "alias": { - "js-sdk:worker-url": "./src/polyfills/bun-worker-url.ts", - "js-sdk:response-to-module": "./src/polyfills/bun-response-to-module.ts", - "js-sdk:minimatch": "./src/polyfills/node-minimatch.ts", - "js-sdk:capabilities": "./src/polyfills/bun-capabilities.ts", - "js-sdk:fs": "node:fs/promises", - "js-sdk:wasi": "./src/polyfills/node-wasi.ts", + "polyfills": { + "./src/worker-url.ts": "./src/polyfills/bun-worker-url.ts", + "./src/polyfills/response-to-module.ts": "./src/polyfills/bun-response-to-module.ts", + "./src/polyfills/deno-minimatch.ts": "./src/polyfills/node-minimatch.ts", + "./src/polyfills/deno-capabilities.ts": "./src/polyfills/bun-capabilities.ts", + "./src/polyfills/node-fs.ts": "node:fs/promises", + "./src/polyfills/deno-wasi.ts": "./src/polyfills/node-wasi.ts", } }] + . ')" @@ -224,13 +255,14 @@ build_browser out='browser' args='[]': "define": {"global": "globalThis"}, "format": "esm", "alias": { - "js-sdk:capabilities": "./src/polyfills/browser-capabilities.ts", - "js-sdk:response-to-module": "./src/polyfills/response-to-module.ts", - "js-sdk:minimatch": "./src/polyfills/node-minimatch.ts", - "node:worker_threads": "./src/polyfills/host-node-worker_threads.ts", - "js-sdk:fs": "./src/polyfills/browser-fs.ts", - "js-sdk:worker-url": "./dist/worker/browser/worker-url.ts", - "js-sdk:wasi": "./src/polyfills/browser-wasi.ts", + "node:worker_threads": "./src/polyfills/host-node-worker_threads.ts" + }, + "polyfills": { + "./src/polyfills/deno-capabilities.ts": "./src/polyfills/browser-capabilities.ts", + "./src/polyfills/deno-minimatch.ts": "./src/polyfills/node-minimatch.ts", + "./src/polyfills/node-fs.ts": "./src/polyfills/browser-fs.ts", + "./src/worker-url.ts": "./dist/worker/browser/worker-url.ts", + "./src/polyfills/deno-wasi.ts": "./src/polyfills/browser-wasi.ts", } }] + . ')" @@ -262,7 +294,7 @@ _build_browser_tests out='tests/browser' args='[]': build: prepare build_worker_node build_worker_browser build_browser build_node_esm build_node_cjs build_bun _build_browser_tests _build_node_tests _build_bun_tests npm pack --pack-destination dist/ -test: build && test-artifacts +_test: #!/bin/bash set -eou pipefail just serve 8124 false & @@ -272,12 +304,17 @@ test: build && test-artifacts trap cleanup EXIT trap cleanup ERR - sleep 0.5 + sleep 0.1 deno test -A src/mod.test.ts node --no-warnings --test --experimental-global-webcrypto dist/tests/cjs/*.test.js node --no-warnings --test --experimental-global-webcrypto dist/tests/esm/*.test.js if &>/dev/null which bun; then bun run dist/tests/bun/*.test.js; fi - playwright test --browser all tests/playwright.test.js + playwright test --browser all tests/playwright.test.js --trace retain-on-failure + +test: build && _test test-artifacts + +bake: + while just _test; do true; done test-artifacts: #!/bin/bash @@ -325,7 +362,7 @@ test-artifacts: EOF node --input-type=module --no-warnings /dev/null which bun; then bun run index.js; fi + # if &>/dev/null which bun; then bun run index.js; fi lint *args: eslint src tests examples $args diff --git a/src/background-plugin.ts b/src/background-plugin.ts index c20c2a4..524c7bd 100644 --- a/src/background-plugin.ts +++ b/src/background-plugin.ts @@ -1,10 +1,10 @@ import { CallContext, RESET, IMPORT_STATE, EXPORT_STATE, STORE, GET_BLOCK } from './call-context.ts'; import { PluginOutput, type InternalConfig } from './interfaces.ts'; -import { WORKER_URL } from 'js-sdk:worker-url'; +import { WORKER_URL } from './worker-url.ts'; import { Worker } from 'node:worker_threads'; -import { CAPABILITIES } from 'js-sdk:capabilities'; +import { CAPABILITIES } from './polyfills/deno-capabilities.ts'; import { EXTISM_ENV } from './foreground-plugin.ts'; -import { matches } from 'js-sdk:minimatch'; +import { matches } from './polyfills/deno-minimatch.ts'; const MAX_WAIT = 5000; diff --git a/src/call-context.ts b/src/call-context.ts index e746984..d8e0b54 100644 --- a/src/call-context.ts +++ b/src/call-context.ts @@ -1,5 +1,5 @@ import { type PluginConfig, PluginOutput } from './interfaces.ts'; -import { CAPABILITIES } from 'js-sdk:capabilities'; +import { CAPABILITIES } from './polyfills/deno-capabilities.ts'; export const BEGIN = Symbol('begin'); export const END = Symbol('end'); diff --git a/src/foreground-plugin.ts b/src/foreground-plugin.ts index 2a8110c..d7bb2bc 100644 --- a/src/foreground-plugin.ts +++ b/src/foreground-plugin.ts @@ -1,6 +1,6 @@ import { CallContext, RESET, GET_BLOCK, BEGIN, END, ENV, STORE } from './call-context.ts'; import { PluginOutput, type InternalConfig } from './interfaces.ts'; -import { loadWasi } from 'js-sdk:wasi'; +import { loadWasi } from './polyfills/deno-wasi.ts'; export const EXTISM_ENV = 'extism:host/env'; diff --git a/src/manifest.ts b/src/manifest.ts index c1361d1..0252cd6 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -7,8 +7,8 @@ import type { ManifestWasmModule, ManifestLike, } from './interfaces.ts'; -import { readFile } from 'js-sdk:fs'; -import { responseToModule } from 'js-sdk:response-to-module'; +import { readFile } from './polyfills/node-fs.ts'; +import { responseToModule } from './polyfills/response-to-module.ts'; async function _populateWasmField(candidate: ManifestLike, _fetch: typeof fetch): Promise { if (candidate instanceof ArrayBuffer) { diff --git a/src/mod.ts b/src/mod.ts index 040b5fd..81820b1 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -1,4 +1,4 @@ -import { CAPABILITIES } from 'js-sdk:capabilities'; +import { CAPABILITIES } from './polyfills/deno-capabilities.ts'; import type { ManifestLike, InternalConfig, ExtismPluginOptions, Plugin } from './interfaces.ts'; @@ -7,7 +7,7 @@ import { toWasmModuleData as _toWasmModuleData } from './manifest.ts'; import { createForegroundPlugin as _createForegroundPlugin } from './foreground-plugin.ts'; import { createBackgroundPlugin as _createBackgroundPlugin } from './background-plugin.ts'; -export { CAPABILITIES } from 'js-sdk:capabilities'; +export { CAPABILITIES } from './polyfills/deno-capabilities.ts'; export type { Capabilities, diff --git a/types/js-sdk/index.d.ts b/types/js-sdk/index.d.ts deleted file mode 100644 index e42a0e8..0000000 --- a/types/js-sdk/index.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -declare module 'js-sdk:response-to-module' { - export function responseToModule(response: Response, hasHash?: boolean): Promise<{module: WebAssembly.Module, data?: ArrayBuffer}>; -} - -declare module 'js-sdk:capabilities' { - import type { Capabilities } from '../../src/interfaces'; - - /** - * - * The {@link Capabilities} supported by the current platform. - * - * @see {@link Capabilities} - */ - export const CAPABILITIES: Capabilities; -} -declare module 'js-sdk:fs' { - function readFile(path: string): Promise; -} -declare module 'js-sdk:wasi' { - interface InternalWasi { - importObject(): Promise>; - initialize(instance: WebAssembly.Instance): Promise - } - function loadWasi(allowedPaths: {[from: string]: string}): Promise; -} -declare module 'js-sdk:worker-url' { - declare const WORKER_URL: URL; -} -declare module 'js-sdk:minimatch' { - function matches(text: string, pattern: string): boolean; -}