diff --git a/packages/commonjs/src/helpers.js b/packages/commonjs/src/helpers.js index b9602a8f3..930b709a3 100644 --- a/packages/commonjs/src/helpers.js +++ b/packages/commonjs/src/helpers.js @@ -24,7 +24,7 @@ export const HELPERS = ` export var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; export function unwrapExports (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } export function createCommonjsModule(fn, basedir, module) { diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.js.md index 369671717..b1d428694 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.js.md @@ -4,7 +4,7 @@ The actual snapshot is saved in `function.js.snap`. Generated by [AVA](https://ava.li). -## __esModule +## \_\_esModule > Snapshot 1 @@ -12,7 +12,7 @@ Generated by [AVA](https://ava.li). 'main.js': `'use strict';␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -264,7 +264,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -467,7 +467,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -666,7 +666,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -884,7 +884,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -1067,12 +1067,12 @@ Generated by [AVA](https://ava.li). > Snapshot 1 { - 'lib2-9224c76d.js': `'use strict';␊ + 'lib2-07a971d0.js': `'use strict';␊ ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -1262,7 +1262,7 @@ Generated by [AVA](https://ava.li). `, 'main.js': `'use strict';␊ ␊ - var lib2 = require('./lib2-9224c76d.js');␊ + var lib2 = require('./lib2-07a971d0.js');␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ @@ -1279,7 +1279,7 @@ Generated by [AVA](https://ava.li). `, 'main2.js': `'use strict';␊ ␊ - require('./lib2-9224c76d.js');␊ + require('./lib2-07a971d0.js');␊ ␊ `, } @@ -1294,7 +1294,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -1484,7 +1484,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -1680,7 +1680,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -1889,7 +1889,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -2096,7 +2096,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -2297,7 +2297,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -2515,7 +2515,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -2719,7 +2719,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -2915,7 +2915,7 @@ Generated by [AVA](https://ava.li). var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ @@ -3552,7 +3552,7 @@ Generated by [AVA](https://ava.li). 'main.js': `'use strict';␊ ␊ function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ }␊ ␊ function createCommonjsModule(fn, basedir, module) {␊ diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.js.snap index 3ebf253e9..05cdd2519 100644 Binary files a/packages/commonjs/test/snapshots/function.js.snap and b/packages/commonjs/test/snapshots/function.js.snap differ diff --git a/packages/commonjs/test/test.js b/packages/commonjs/test/test.js index 0eaea1db5..297bad8d6 100644 --- a/packages/commonjs/test/test.js +++ b/packages/commonjs/test/test.js @@ -153,7 +153,7 @@ test('handles transpiled CommonJS modules', async (t) => { const fn = new Function('module', 'exports', code); fn(module, module.exports); - t.is(module.exports, 'foobar', code); + t.deepEqual(module.exports, { __esModule: true, default: 'foobar' }, code); }); test('handles successive builds', async (t) => { @@ -177,7 +177,7 @@ test('handles successive builds', async (t) => { const fn = new Function('module', 'exports', code); fn(module, module.exports); - t.is(module.exports, 'foobar', code); + t.deepEqual(module.exports, { __esModule: true, default: 'foobar' }, code); }); test.serial('handles symlinked node_modules with preserveSymlinks: false', (t) => {