From 4e87195739f2a5d9a05451b48773c8afdc680765 Mon Sep 17 00:00:00 2001 From: akiyamn Date: Sun, 24 Sep 2023 23:22:21 +1000 Subject: Initial commit (by create-cloudflare CLI) --- .../node-globals-polyfill/esm/index.js | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 node_modules/@esbuild-plugins/node-globals-polyfill/esm/index.js (limited to 'node_modules/@esbuild-plugins/node-globals-polyfill/esm/index.js') diff --git a/node_modules/@esbuild-plugins/node-globals-polyfill/esm/index.js b/node_modules/@esbuild-plugins/node-globals-polyfill/esm/index.js new file mode 100644 index 0000000..aa0bceb --- /dev/null +++ b/node_modules/@esbuild-plugins/node-globals-polyfill/esm/index.js @@ -0,0 +1,73 @@ +import path from 'path'; +export function NodeGlobalsPolyfillPlugin({ buffer = false, +// define = {}, +process = true, } = {}) { + return { + name: 'node-globals-polyfill', + setup({ initialOptions, onResolve, onLoad }) { + onResolve({ filter: /_node-buffer-polyfill_\.js/ }, (arg) => { + return { + path: path.resolve(__dirname, '../Buffer.js'), + }; + }); + onResolve({ filter: /_node-process-polyfill_\.js/ }, (arg) => { + return { + path: path.resolve(__dirname, '../process.js'), + }; + }); + // TODO esbuild cannot use virtual modules for inject: https://github.com/evanw/esbuild/issues/2762 + // onLoad({ filter: /_virtual-process-polyfill_\.js/ }, (arg) => { + // const data = fs + // .readFileSync(path.resolve(__dirname, '../process.js')) + // .toString() + // const keys = Object.keys(define) + // return { + // loader: 'js', + // contents: data.replace( + // `const defines = {}`, + // 'const defines = {\n' + + // keys + // .filter((x) => x.startsWith('process.')) + // .sort((a, b) => a.length - b.length) + // .map( + // (k) => + // ` ${JSON.stringify(k).replace( + // 'process.', + // '', + // )}: ${define[k]},`, + // ) + // .join('\n') + + // '\n}', + // ), + // } + // }) + onResolve({ filter: /_virtual-process-polyfill_\.js/ }, () => { + return { + path: path.resolve(__dirname, '../process.js'), + }; + }); + onResolve({ filter: /_virtual-buffer-polyfill_\.js/ }, () => { + return { + path: path.resolve(__dirname, '../_buffer.js'), + }; + }); + const polyfills = []; + if (process) { + polyfills.push(path.resolve(__dirname, '../_virtual-process-polyfill_.js')); + } + if (buffer) { + polyfills.push(path.resolve(__dirname, '../_virtual-buffer-polyfill_.js')); + } + if (initialOptions.inject) { + initialOptions.inject.push(...polyfills); + // handle duplicate plugin + initialOptions.inject = [...new Set(initialOptions.inject)]; + } + else { + initialOptions.inject = [...polyfills]; + } + }, + }; +} +export default NodeGlobalsPolyfillPlugin; +//# sourceMappingURL=index.js.map \ No newline at end of file -- cgit v1.2.3