Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Make generated helper file have .js extension in preserveModules mode (
Browse files Browse the repository at this point in the history
…#373)

* Make generated helper file have .js extension in preserveModules mode

* Support for new globalThis global
  • Loading branch information
creationix authored and lukastaegert committed Apr 2, 2019
1 parent 9755028 commit d93d838
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/helpers.js
@@ -1,11 +1,11 @@
export const PROXY_PREFIX = '\0commonjs-proxy:';
export const EXTERNAL_PREFIX = '\0commonjs-external:';
export const HELPERS_ID = '\0commonjsHelpers';
export const HELPERS_ID = '\0commonjsHelpers.js';

// `x['default']` is used instead of `x.default` for backward compatibility with ES3 browsers.
// Minifiers like uglify will usually transpile it back if compatibility with ES3 is not enabled.
export const HELPERS = `
export var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
export var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

This comment has been minimized.

Copy link
@tionkje

tionkje Sep 12, 2019

Contributor

This change breaks 3 tests that use global.
global is being mocked but globalThis now has precedence to global.
And globalThis points to the actual global instead of the mocked one.

export function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
Expand Down
2 changes: 1 addition & 1 deletion test/form/dynamic-template-literal/output.js
@@ -1,4 +1,4 @@
import * as commonjsHelpers from 'commonjsHelpers';
import * as commonjsHelpers from 'commonjsHelpers.js';

var pe = 'pe';
var foo = commonjsHelpers.commonjsRequire(`ta${pe}`);
Expand Down
2 changes: 1 addition & 1 deletion test/form/typeof-module-exports/output.js
@@ -1,4 +1,4 @@
import * as commonjsHelpers from 'commonjsHelpers';
import * as commonjsHelpers from 'commonjsHelpers.js';

var input = commonjsHelpers.createCommonjsModule(function (module, exports) {
var foo = 42;
Expand Down

0 comments on commit d93d838

Please sign in to comment.