@esbuild-plugins/node-modules-polyfill
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -44,6 +44,6 @@ "use strict"; | ||
if ((initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.define) && !((_a = initialOptions.define) === null || _a === void 0 ? void 0 : _a.global)) { | ||
initialOptions.define['global'] = '{}'; | ||
initialOptions.define['global'] = 'globalThis'; | ||
} | ||
else if (!(initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.define)) { | ||
initialOptions.define = { global: '{}' }; | ||
initialOptions.define = { global: 'globalThis' }; | ||
} | ||
@@ -50,0 +50,0 @@ // TODO these polyfill module cannot import anything, is that ok? |
@@ -19,2 +19,3 @@ "use strict"; | ||
const _1 = __importDefault(require(".")); | ||
const node_globals_polyfill_1 = __importDefault(require("@esbuild-plugins/node-globals-polyfill")); | ||
require('debug').enable(require('../package.json').name); | ||
@@ -159,3 +160,2 @@ test('works', () => __awaiter(void 0, void 0, void 0, function* () { | ||
eval(text); | ||
console.log(text); | ||
expect(text).not.toContain(/\bglobal\b/); | ||
@@ -165,2 +165,22 @@ // console.log(res.outputFiles[0].text) | ||
})); | ||
test('works with globals polyfills', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({ | ||
'entry.ts': `import {x} from './utils'; console.log(x);`, | ||
'utils.ts': `import path from 'path'; import { Buffer } from 'buffer'; export const x = path.resolve(Buffer.from('x').toString());`, | ||
}); | ||
// const outfile = randomOutputFile() | ||
const res = yield esbuild_1.build({ | ||
entryPoints: [ENTRY], | ||
write: false, | ||
format: 'esm', | ||
target: 'es2017', | ||
bundle: true, | ||
plugins: [_1.default(), node_globals_polyfill_1.default()], | ||
}); | ||
const text = res.outputFiles[0].text; | ||
eval(text); | ||
console.log(text); | ||
// console.log(res.outputFiles[0].text) | ||
unlink(); | ||
})); | ||
//# sourceMappingURL=index.test.js.map |
{ | ||
"name": "@esbuild-plugins/node-modules-polyfill", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,2 +5,3 @@ import { build } from 'esbuild' | ||
import NodeModulesPolyfillsPlugin from '.' | ||
import NodeGlobalsPolyfillsPlugin from '@esbuild-plugins/node-globals-polyfill' | ||
@@ -173,3 +174,2 @@ require('debug').enable(require('../package.json').name) | ||
eval(text) | ||
console.log(text) | ||
expect(text).not.toContain(/\bglobal\b/) | ||
@@ -179,1 +179,25 @@ // console.log(res.outputFiles[0].text) | ||
}) | ||
test('works with globals polyfills', async () => { | ||
const { | ||
unlink, | ||
paths: [ENTRY], | ||
} = await writeFiles({ | ||
'entry.ts': `import {x} from './utils'; console.log(x);`, | ||
'utils.ts': `import path from 'path'; import { Buffer } from 'buffer'; export const x = path.resolve(Buffer.from('x').toString());`, | ||
}) | ||
// const outfile = randomOutputFile() | ||
const res = await build({ | ||
entryPoints: [ENTRY], | ||
write: false, | ||
format: 'esm', | ||
target: 'es2017', | ||
bundle: true, | ||
plugins: [NodeModulesPolyfillsPlugin(), NodeGlobalsPolyfillsPlugin()], | ||
}) | ||
const text = res.outputFiles[0].text | ||
eval(text) | ||
console.log(text) | ||
// console.log(res.outputFiles[0].text) | ||
unlink() | ||
}) |
@@ -41,5 +41,5 @@ import { OnResolveArgs, Plugin } from 'esbuild' | ||
if (initialOptions?.define && !initialOptions.define?.global) { | ||
initialOptions.define['global'] = '{}' | ||
initialOptions.define['global'] = 'globalThis' | ||
} else if (!initialOptions?.define) { | ||
initialOptions.define = { global: '{}' } | ||
initialOptions.define = { global: 'globalThis' } | ||
} | ||
@@ -46,0 +46,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68553
1140
15