├── .husky
├── pre-commit
└── commit-msg
├── .prettierignore
├── src
├── cjs.js
├── runtime
│ └── getGlobalThis.js
├── options.json
├── index.js
└── utils.js
├── .gitattributes
├── test
├── fixtures
│ ├── global-commonjs.js
│ ├── global-module-default-export.js
│ ├── global-commonjs2-single-export.js
│ ├── loader-commonjs-with-es.js
│ ├── side-effects.js
│ ├── loader-commonjs-with-commonjs.js
│ ├── simple-module-named-export.js
│ ├── simple-module-single-export.js
│ ├── global-module-commonjs.js
│ ├── global-module-es-without-default.js
│ ├── simple-commonjs2-single-export.js
│ ├── inline-import-1.js
│ ├── inline-import.js
│ ├── simple-commonjs2-multiple-export.js
│ ├── global-module-es.js
│ ├── loader-es-with-commonjs.js
│ ├── global-commonjs2-multiple-exports.js
│ ├── side-effects-1.js
│ ├── custom
│ ├── custom.js
│ ├── loader-es-with-es-without-default.js
│ ├── loader-es-with-es.js
│ ├── global-module-named-exports.js
│ ├── override-1.js
│ ├── inline-import-2.js
│ └── inline-import-equality.js
├── helpers
│ ├── getErrors.js
│ ├── getWarnings.js
│ ├── getModuleSource.js
│ ├── compile.js
│ ├── getModulesList.js
│ ├── readAssets.js
│ ├── normalizeErrors.js
│ ├── index.js
│ ├── readAsset.js
│ ├── getCompiler.js
│ └── execute.js
├── cjs.test.js
├── runtime
│ └── getGlobalThis.test.js
├── validate-options.test.js
├── __snapshots__
│ ├── validate-options.test.js.snap
│ └── loader.test.js.snap
└── loader.test.js
├── husky.config.js
├── lint-staged.config.js
├── commitlint.config.js
├── eslint.config.mjs
├── .editorconfig
├── .github
└── workflows
│ ├── dependency-review.yml
│ └── nodejs.yml
├── .cspell.json
├── babel.config.js
├── LICENSE
├── .gitignore
├── package.json
├── CHANGELOG.md
└── README.md
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | lint-staged
2 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | commitlint --edit $1
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | /coverage
2 | /dist
3 | /node_modules
4 | /test/fixtures
5 | CHANGELOG.md
--------------------------------------------------------------------------------
/src/cjs.js:
--------------------------------------------------------------------------------
1 | const loader = require("./index");
2 |
3 | module.exports = loader.default;
4 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | package-lock.json -diff
2 | * text=auto
3 | bin/* eol=lf
4 | yarn.lock -diff
5 |
--------------------------------------------------------------------------------
/test/fixtures/global-commonjs.js:
--------------------------------------------------------------------------------
1 | const globalObject1 = { foo: 'bar' };
2 |
3 | exports['globalObject1'] = globalObject1;
4 |
--------------------------------------------------------------------------------
/test/fixtures/global-module-default-export.js:
--------------------------------------------------------------------------------
1 | const globalObject5 = { foo: 'bar' };
2 |
3 | export default globalObject5;
4 |
--------------------------------------------------------------------------------
/test/fixtures/global-commonjs2-single-export.js:
--------------------------------------------------------------------------------
1 | const globalObject4 = { foo: 'bar' };
2 |
3 | module.exports = globalObject4;
4 |
--------------------------------------------------------------------------------
/test/fixtures/loader-commonjs-with-es.js:
--------------------------------------------------------------------------------
1 | const myExports = require('./global-module-es');
2 |
3 | module.exports = myExports;
4 |
--------------------------------------------------------------------------------
/test/fixtures/side-effects.js:
--------------------------------------------------------------------------------
1 | import 'rx';
2 |
3 | function test() {
4 | return 'test';
5 | }
6 |
7 | export default test;
8 |
--------------------------------------------------------------------------------
/test/fixtures/loader-commonjs-with-commonjs.js:
--------------------------------------------------------------------------------
1 | const myExports = require('./global-module-commonjs');
2 |
3 | module.exports = myExports;
4 |
--------------------------------------------------------------------------------
/test/fixtures/simple-module-named-export.js:
--------------------------------------------------------------------------------
1 | import * as myExports from './global-module-named-exports';
2 |
3 | export default myExports;
4 |
--------------------------------------------------------------------------------
/test/fixtures/simple-module-single-export.js:
--------------------------------------------------------------------------------
1 | import myExports from './global-module-default-export';
2 |
3 | export default myExports;
4 |
--------------------------------------------------------------------------------
/test/fixtures/global-module-commonjs.js:
--------------------------------------------------------------------------------
1 | const foo = { foo: 'bar', myMethod: () => { console.log('HERE'); } };
2 |
3 | module.exports = foo;
4 |
--------------------------------------------------------------------------------
/test/fixtures/global-module-es-without-default.js:
--------------------------------------------------------------------------------
1 | const foo = { foo: 'bar', myMethod: () => { console.log('HERE'); } };
2 |
3 | export { foo }
4 |
--------------------------------------------------------------------------------
/test/fixtures/simple-commonjs2-single-export.js:
--------------------------------------------------------------------------------
1 | const myExports = require('./global-commonjs2-single-export');
2 |
3 | module.exports = myExports;
4 |
--------------------------------------------------------------------------------
/test/fixtures/inline-import-1.js:
--------------------------------------------------------------------------------
1 | import myExports from '../../src/cjs.js?exposes=myGlobal|default!./custom?foo=bar';
2 |
3 | export default myExports;
4 |
--------------------------------------------------------------------------------
/test/fixtures/inline-import.js:
--------------------------------------------------------------------------------
1 | import myExports from '../../src/cjs.js?exposes=myGlobal|default!./custom.js?foo=bar';
2 |
3 | export default myExports;
4 |
--------------------------------------------------------------------------------
/test/fixtures/simple-commonjs2-multiple-export.js:
--------------------------------------------------------------------------------
1 | const myExports = require('./global-commonjs2-multiple-exports');
2 |
3 | module.exports = myExports;
4 |
--------------------------------------------------------------------------------
/test/helpers/getErrors.js:
--------------------------------------------------------------------------------
1 | import normalizeErrors from "./normalizeErrors";
2 |
3 | export default (stats) => normalizeErrors(stats.compilation.errors);
4 |
--------------------------------------------------------------------------------
/husky.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | hooks: {
3 | "pre-commit": "lint-staged",
4 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
5 | },
6 | };
7 |
--------------------------------------------------------------------------------
/test/helpers/getWarnings.js:
--------------------------------------------------------------------------------
1 | import normalizeErrors from "./normalizeErrors";
2 |
3 | export default (stats) => normalizeErrors(stats.compilation.warnings);
4 |
--------------------------------------------------------------------------------
/test/fixtures/global-module-es.js:
--------------------------------------------------------------------------------
1 | const foo = { foo: 'bar', myMethod: () => { console.log('HERE'); } };
2 |
3 | const bar = ['test'];
4 |
5 | export default foo;
6 | export { bar }
7 |
--------------------------------------------------------------------------------
/test/fixtures/loader-es-with-commonjs.js:
--------------------------------------------------------------------------------
1 | import * as ns from "./global-module-commonjs";
2 |
3 | var MyVariable = ns.foo + '100';
4 |
5 | export * from "./global-module-commonjs";
6 |
--------------------------------------------------------------------------------
/test/fixtures/global-commonjs2-multiple-exports.js:
--------------------------------------------------------------------------------
1 | const globalObject2 = { foo: 'bar' };
2 | const globalObject3 = { bar: 'foo' };
3 |
4 | module.exports = { globalObject2, globalObject3 };
5 |
--------------------------------------------------------------------------------
/test/cjs.test.js:
--------------------------------------------------------------------------------
1 | import src from "../src";
2 | import cjs from "../src/cjs";
3 |
4 | describe("cjs", () => {
5 | it("should exported", () => {
6 | expect(cjs).toEqual(src);
7 | });
8 | });
9 |
--------------------------------------------------------------------------------
/test/fixtures/side-effects-1.js:
--------------------------------------------------------------------------------
1 | import "styled-components";
2 | import myGlobalThis from '../../src/runtime/getGlobalThis';
3 |
4 | const exported = myGlobalThis.styled;
5 |
6 | export default exported;
7 |
--------------------------------------------------------------------------------
/lint-staged.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "*": [
3 | "prettier --cache --write --ignore-unknown",
4 | "cspell --cache --no-must-find-files",
5 | ],
6 | "*.js": ["eslint --cache --fix"],
7 | };
8 |
--------------------------------------------------------------------------------
/test/fixtures/custom:
--------------------------------------------------------------------------------
1 | function getAddress() {
2 | return {city: 'Tokyo'};
3 | }
4 |
5 | const address = getAddress();
6 |
7 | const myExports = address?.city;
8 |
9 | export default myExports;
10 |
--------------------------------------------------------------------------------
/test/fixtures/custom.js:
--------------------------------------------------------------------------------
1 | function getAddress() {
2 | return {city: 'Tokyo'};
3 | }
4 |
5 | const address = getAddress();
6 |
7 | const myExports = address?.city;
8 |
9 | export default myExports;
10 |
--------------------------------------------------------------------------------
/test/fixtures/loader-es-with-es-without-default.js:
--------------------------------------------------------------------------------
1 | import { foo } from "./global-module-es-without-default.js";
2 |
3 | var MyVariable = foo + '100';
4 |
5 | export * from "./global-module-es-without-default.js";
6 |
--------------------------------------------------------------------------------
/test/fixtures/loader-es-with-es.js:
--------------------------------------------------------------------------------
1 | import myDefault from "./global-module-es";
2 |
3 | var MyVariable = myDefault.foo + '100';
4 |
5 | export { default } from "./global-module-es";
6 | export * from "./global-module-es";
7 |
--------------------------------------------------------------------------------
/test/helpers/getModuleSource.js:
--------------------------------------------------------------------------------
1 | export default (name, stats) => {
2 | const { modules } = stats.toJson({ source: true });
3 | const module = modules.find((m) => m.name.endsWith(name));
4 |
5 | return module.source;
6 | };
7 |
--------------------------------------------------------------------------------
/commitlint.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ["@commitlint/config-conventional"],
3 | rules: {
4 | "header-max-length": [0],
5 | "body-max-line-length": [0],
6 | "footer-max-line-length": [0],
7 | },
8 | };
9 |
--------------------------------------------------------------------------------
/eslint.config.mjs:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "eslint/config";
2 | import configs from "eslint-config-webpack/configs.js";
3 |
4 | export default defineConfig([
5 | {
6 | extends: [configs["recommended-dirty"]],
7 | },
8 | ]);
9 |
--------------------------------------------------------------------------------
/test/runtime/getGlobalThis.test.js:
--------------------------------------------------------------------------------
1 | import getGlobalThis from "../../src/runtime/getGlobalThis";
2 |
3 | describe("getGlobalThis", () => {
4 | it("should work", () => {
5 | expect(getGlobalThis).toEqual(globalThis);
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/test/fixtures/global-module-named-exports.js:
--------------------------------------------------------------------------------
1 | const globalObject6 = { foo: 'bar' };
2 | const globalObject7 = { bar: 'foo' };
3 |
4 | export default function globalDef(){
5 | return { bar: 'foo' };
6 | };
7 |
8 | export { globalObject6, globalObject7 };
9 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/test/helpers/compile.js:
--------------------------------------------------------------------------------
1 | export default (compiler) =>
2 | new Promise((resolve, reject) => {
3 | compiler.run((error, stats) => {
4 | if (error) {
5 | return reject(error);
6 | }
7 |
8 | return resolve(stats);
9 | });
10 | });
11 |
--------------------------------------------------------------------------------
/test/helpers/getModulesList.js:
--------------------------------------------------------------------------------
1 | export default (name, stats) => {
2 | const { modules } = stats.toJson({ source: true });
3 |
4 | const moduleNames = modules
5 | .map((item) => item.id)
6 | .filter((item) => item.startsWith(name));
7 |
8 | return moduleNames;
9 | };
10 |
--------------------------------------------------------------------------------
/test/fixtures/override-1.js:
--------------------------------------------------------------------------------
1 | const myGlobalThis = require('../../src/runtime/getGlobalThis');
2 |
3 | myGlobalThis.myGlobal = 'not overridden';
4 |
5 | myGlobalThis.myOtherGlobal = { foo: 'not overridden' };
6 |
7 | const myExports = require('./global-commonjs2-single-export');
8 |
9 | module.exports = 'no exports';
10 |
--------------------------------------------------------------------------------
/test/helpers/readAssets.js:
--------------------------------------------------------------------------------
1 | import readAsset from "./readAsset";
2 |
3 | export default function readAssets(compiler, stats) {
4 | const assets = {};
5 |
6 | for (const asset of Object.keys(stats.compilation.assets)) {
7 | assets[asset] = readAsset(asset, compiler, stats);
8 | }
9 |
10 | return assets;
11 | }
12 |
--------------------------------------------------------------------------------
/test/fixtures/inline-import-2.js:
--------------------------------------------------------------------------------
1 | import myExports from '../../src/cjs.js?exposes=myGlobal!./simple-commonjs2-single-export.js';
2 | import myExports2 from '../../src/cjs.js?exposes=myOtherGlobal.globalObject2|globalObject2,myOtherGlobal.globalObject3|globalObject3!./simple-commonjs2-multiple-export.js';
3 |
4 | export { myExports, myExports2 };
5 |
--------------------------------------------------------------------------------
/test/fixtures/inline-import-equality.js:
--------------------------------------------------------------------------------
1 | import exposed from '../../src/cjs.js?exposes=myGlobal!./global-commonjs2-single-export.js';
2 |
3 | import imported from './global-commonjs2-single-export.js'
4 |
5 | export default {
6 | exposedEqualsGlobal: exposed === myGlobal,
7 | importedEqualsGlobal: imported === myGlobal,
8 | exposedEqualsImported: exposed === imported,
9 | }
10 |
--------------------------------------------------------------------------------
/.github/workflows/dependency-review.yml:
--------------------------------------------------------------------------------
1 | name: "Dependency Review"
2 | on: [pull_request]
3 |
4 | permissions:
5 | contents: read
6 |
7 | jobs:
8 | dependency-review:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - name: "Checkout Repository"
12 | uses: actions/checkout@v5
13 | - name: "Dependency Review"
14 | uses: actions/dependency-review-action@v4
15 |
--------------------------------------------------------------------------------
/.cspell.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2",
3 | "language": "en,en-gb",
4 | "words": [
5 | "commitlint",
6 | "concat",
7 | "Koppers",
8 | "sokra",
9 | "chunkhash",
10 | "memfs",
11 | "wagoid"
12 | ],
13 |
14 | "ignorePaths": [
15 | "CHANGELOG.md",
16 | "package.json",
17 | "dist/**",
18 | "**/__snapshots__/**",
19 | "package-lock.json",
20 | "node_modules",
21 | "coverage",
22 | "*.log"
23 | ]
24 | }
25 |
--------------------------------------------------------------------------------
/test/helpers/normalizeErrors.js:
--------------------------------------------------------------------------------
1 | function removeCWD(str) {
2 | const isWin = process.platform === "win32";
3 | let cwd = process.cwd();
4 |
5 | if (isWin) {
6 | str = str.replaceAll("\\", "/");
7 |
8 | cwd = cwd.replaceAll("\\", "/");
9 | }
10 |
11 | return str
12 | .replace(/\(from .*?\)/, "(from `replaced original path`)")
13 | .replaceAll(new RegExp(cwd, "g"), "");
14 | }
15 |
16 | export default (errors) =>
17 | errors.map((error) =>
18 | removeCWD(error.toString().split("\n").slice(0, 2).join("\n")),
19 | );
20 |
--------------------------------------------------------------------------------
/test/helpers/index.js:
--------------------------------------------------------------------------------
1 | export { default as compile } from "./compile";
2 | export { default as getCompiler } from "./getCompiler";
3 | export { default as execute } from "./execute";
4 | export { default as getModuleSource } from "./getModuleSource";
5 | export { default as getErrors } from "./getErrors";
6 | export { default as getWarnings } from "./getWarnings";
7 | export { default as getModulesList } from "./getModulesList";
8 | export { default as readAsset } from "./readAsset";
9 | export { default as normalizeErrors } from "./normalizeErrors";
10 | export { default as readsAssets } from "./readAssets";
11 |
--------------------------------------------------------------------------------
/test/helpers/readAsset.js:
--------------------------------------------------------------------------------
1 | import path from "node:path";
2 |
3 | export default (asset, compiler, stats) => {
4 | const usedFs = compiler.outputFileSystem;
5 | const outputPath = stats.compilation.outputOptions.path;
6 |
7 | let data = "";
8 | let targetFile = asset;
9 |
10 | const queryStringIdx = targetFile.indexOf("?");
11 |
12 | if (queryStringIdx >= 0) {
13 | targetFile = targetFile.slice(0, queryStringIdx);
14 | }
15 |
16 | try {
17 | data = usedFs.readFileSync(path.join(outputPath, targetFile)).toString();
18 | } catch (error) {
19 | data = error.toString();
20 | }
21 |
22 | return data;
23 | };
24 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | const MIN_BABEL_VERSION = 7;
2 |
3 | module.exports = (api) => {
4 | api.assertVersion(MIN_BABEL_VERSION);
5 | api.cache(true);
6 |
7 | return {
8 | presets: [
9 | [
10 | "@babel/preset-env",
11 | {
12 | targets: {
13 | node: "18.12.0",
14 | },
15 | },
16 | ],
17 | ],
18 | overrides: [
19 | {
20 | test: "./src/runtime",
21 | presets: [
22 | [
23 | "@babel/preset-env",
24 | {
25 | targets: {
26 | node: "0.14",
27 | },
28 | },
29 | ],
30 | ],
31 | },
32 | ],
33 | };
34 | };
35 |
--------------------------------------------------------------------------------
/src/runtime/getGlobalThis.js:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line func-names
2 | module.exports = (function () {
3 | if (typeof globalThis === "object") {
4 | return globalThis;
5 | }
6 |
7 | // eslint-disable-next-line id-length
8 | let g;
9 |
10 | try {
11 | // This works if eval is allowed (see CSP)
12 | // eslint-disable-next-line no-new-func
13 | g = this || new Function("return this")();
14 | } catch {
15 | // This works if the window reference is available
16 | /* eslint-disable unicorn/prefer-global-this, no-undef */
17 | if (typeof window === "object") {
18 | return window;
19 | }
20 | // This works if the self reference is available
21 | if (typeof self === "object") {
22 | return self;
23 | }
24 |
25 | // This works if the global reference is available
26 | if (typeof global !== "undefined") {
27 | return global;
28 | }
29 | /* eslint-enable unicorn/prefer-global-this, no-undef */
30 | }
31 |
32 | return g;
33 | })();
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright JS Foundation and other contributors
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | 'Software'), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/test/helpers/getCompiler.js:
--------------------------------------------------------------------------------
1 | import path from "node:path";
2 |
3 | import { Volume, createFsFromVolume } from "memfs";
4 | import webpack from "webpack";
5 |
6 | export default (fixture, loaderOptions = {}, config = {}) => {
7 | const fullConfig = {
8 | mode: "development",
9 | devtool: config.devtool || false,
10 | context: path.resolve(__dirname, "../fixtures"),
11 | entry: path.resolve(__dirname, "../fixtures", fixture),
12 | output: {
13 | path: path.resolve(__dirname, "../outputs"),
14 | filename: "[name].bundle.js",
15 | chunkFilename: "[name].chunk.js",
16 | library: "ExposeLoader",
17 | libraryTarget: "var",
18 | },
19 | module: {
20 | rules: [
21 | {
22 | test: /(global-.+|rx\.all|styled-components.+)\.js/i,
23 | rules: [
24 | {
25 | loader: path.resolve(__dirname, "../../src"),
26 | options: loaderOptions || {},
27 | },
28 | ],
29 | },
30 | ],
31 | },
32 | plugins: [],
33 | ...config,
34 | };
35 |
36 | const compiler = webpack(fullConfig);
37 |
38 | if (!config.outputFileSystem) {
39 | compiler.outputFileSystem = createFsFromVolume(new Volume());
40 | }
41 |
42 | return compiler;
43 | };
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (http://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # Typescript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional cspell cache
49 | .cspellcache
50 |
51 | # Optional REPL history
52 | .node_repl_history
53 |
54 | # Output of 'npm pack'
55 | *.tgz
56 |
57 | # Yarn Integrity file
58 | .yarn-integrity
59 |
60 | # dotenv environment variables file
61 | .env
62 |
63 |
64 | /coverage
65 | /dist
66 | /local
67 | /reports
68 | /node_modules
69 | .DS_Store
70 | Thumbs.db
71 | .idea
72 | .vscode
73 | *.sublime-project
74 | *.sublime-workspace
75 | *.iml
76 |
--------------------------------------------------------------------------------
/test/helpers/execute.js:
--------------------------------------------------------------------------------
1 | import Module from "node:module";
2 | import path from "node:path";
3 |
4 | const parentModule = module;
5 |
6 | export default (code) => {
7 | const resource = "test.js";
8 | const module = new Module(resource, parentModule);
9 |
10 | module.paths = Module._nodeModulePaths(
11 | path.resolve(__dirname, "../fixtures"),
12 | );
13 | module.filename = resource;
14 |
15 | module._compile(
16 | `
17 | window = {};
18 | console.log = () => {};
19 |
20 | const result = {};
21 |
22 | if (typeof myGlobal !== "undefined") {
23 | delete myGlobal;
24 | }
25 |
26 | if (typeof myOtherGlobal !== "undefined") {
27 | delete myOtherGlobal;
28 | }
29 |
30 | if (typeof myGlobal_alias !== "undefined") {
31 | delete myGlobal_alias;
32 | }
33 |
34 | if (typeof global['myGlobal.alias'] !== "undefined") {
35 | delete global['myGlobal.alias'];
36 | }
37 |
38 | if (typeof myGlobal_alias !== "undefined") {
39 | delete global['global-commonjs2-single-export'];
40 | }
41 |
42 | ${code};
43 |
44 | result['ExposeLoader'] = ExposeLoader;
45 |
46 | if (typeof myGlobal !== "undefined") {
47 | result['myGlobal'] = myGlobal;
48 | }
49 |
50 | if (typeof myOtherGlobal !== "undefined") {
51 | result['myOtherGlobal'] = myOtherGlobal;
52 | }
53 |
54 | if (typeof myGlobal_alias !== "undefined") {
55 | result['myGlobal_alias'] = myGlobal_alias;
56 | }
57 |
58 | if (typeof global['myGlobal.alias'] !== "undefined") {
59 | result['myGlobal.alias'] = global['myGlobal.alias'];
60 | }
61 |
62 | if (typeof global['global-commonjs2-single-export'] !== "undefined") {
63 | result['global-commonjs2-single-export'] = global['global-commonjs2-single-export'];
64 | }
65 |
66 | module.exports = result;`,
67 | resource,
68 | );
69 |
70 | return module.exports;
71 | };
72 |
--------------------------------------------------------------------------------
/src/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Expose Loader options",
3 | "definitions": {
4 | "ObjectPattern": {
5 | "type": "object",
6 | "additionalProperties": false,
7 | "properties": {
8 | "globalName": {
9 | "anyOf": [
10 | {
11 | "type": "string",
12 | "minLength": 1
13 | },
14 | {
15 | "type": "array",
16 | "items": {
17 | "type": "string",
18 | "minLength": 1
19 | },
20 | "minItems": 1
21 | }
22 | ],
23 | "description": "The name in the global object.",
24 | "link": "https://github.com/webpack/expose-loader#globalname"
25 | },
26 | "moduleLocalName": {
27 | "type": "string",
28 | "description": "he name of method/variable/etc of the module (the module must export it).",
29 | "link:": "https://github.com/webpack/expose-loader#modulelocalname",
30 | "minLength": 1
31 | },
32 | "override": {
33 | "type": "boolean",
34 | "description": "Configure loader to override the existing value in the global object.",
35 | "link": "https://github.com/webpack/expose-loader#override"
36 | }
37 | },
38 | "required": ["globalName"]
39 | }
40 | },
41 | "type": "object",
42 | "properties": {
43 | "globalObject": {
44 | "type": "string",
45 | "description": "Global object used as global context",
46 | "link": "https://github.com/webpack/expose-loader#globalObject"
47 | },
48 | "exposes": {
49 | "anyOf": [
50 | {
51 | "type": "string",
52 | "minLength": 1
53 | },
54 | {
55 | "$ref": "#/definitions/ObjectPattern"
56 | },
57 | {
58 | "type": "array",
59 | "items": {
60 | "anyOf": [
61 | {
62 | "type": "string",
63 | "minLength": 1
64 | },
65 | {
66 | "$ref": "#/definitions/ObjectPattern"
67 | }
68 | ]
69 | },
70 | "minItems": 1
71 | }
72 | ],
73 | "description": "List of exposes.",
74 | "link": "https://github.com/webpack/expose-loader#exposes"
75 | }
76 | },
77 | "anyOf": [{ "required": ["exposes"] }]
78 | }
79 |
--------------------------------------------------------------------------------
/.github/workflows/nodejs.yml:
--------------------------------------------------------------------------------
1 | name: expose-loader
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | - next
8 | pull_request:
9 | branches:
10 | - main
11 | - next
12 |
13 | permissions:
14 | contents: read
15 |
16 | jobs:
17 | lint:
18 | name: Lint - ${{ matrix.os }} - Node v${{ matrix.node-version }}
19 |
20 | env:
21 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 |
23 | strategy:
24 | matrix:
25 | os: [ubuntu-latest]
26 | node-version: [lts/*]
27 |
28 | runs-on: ${{ matrix.os }}
29 |
30 | concurrency:
31 | group: lint-${{ matrix.os }}-v${{ matrix.node-version }}-${{ github.ref }}
32 | cancel-in-progress: true
33 |
34 | steps:
35 | - uses: actions/checkout@v5
36 | with:
37 | fetch-depth: 0
38 |
39 | - name: Use Node.js ${{ matrix.node-version }}
40 | uses: actions/setup-node@v4
41 | with:
42 | node-version: ${{ matrix.node-version }}
43 | cache: "npm"
44 |
45 | - name: Install dependencies
46 | run: npm ci
47 |
48 | - name: Lint
49 | run: npm run lint
50 |
51 | - name: Security audit
52 | run: npm run security
53 |
54 | - name: Validate PR commits with commitlint
55 | if: github.event_name == 'pull_request'
56 | run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
57 |
58 | test:
59 | name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}
60 |
61 | strategy:
62 | matrix:
63 | os: [ubuntu-latest, windows-latest, macos-latest]
64 | node-version: [18.x, 20.x, 22.x, 24.x]
65 |
66 | runs-on: ${{ matrix.os }}
67 |
68 | concurrency:
69 | group: test-${{ matrix.os }}-v${{ matrix.node-version }}-${{ github.ref }}
70 | cancel-in-progress: true
71 |
72 | steps:
73 | - uses: actions/checkout@v5
74 |
75 | - name: Use Node.js ${{ matrix.node-version }}
76 | uses: actions/setup-node@v4
77 | with:
78 | node-version: ${{ matrix.node-version }}
79 | cache: "npm"
80 |
81 | - name: Install dependencies
82 | run: npm ci
83 |
84 | - name: Run tests for webpack version ${{ matrix.webpack-version }}
85 | if: matrix.webpack-version != 'latest'
86 | run: npm run test:coverage -- --ci
87 |
88 | - name: Submit coverage data to codecov
89 | uses: codecov/codecov-action@v5
90 | with:
91 | token: ${{ secrets.CODECOV_TOKEN }}
92 |
--------------------------------------------------------------------------------
/test/validate-options.test.js:
--------------------------------------------------------------------------------
1 | import { compile, getCompiler } from "./helpers";
2 |
3 | describe("validate options", () => {
4 | const tests = {
5 | exposes: {
6 | success: [
7 | {
8 | globalName: "myGlobal",
9 | },
10 | {
11 | globalName: "myGlobal_alias",
12 | moduleLocalName: "globalObject6",
13 | },
14 | {
15 | globalName: ["myGlobal_alias", "globalObject6"],
16 | moduleLocalName: "globalObject6",
17 | },
18 | "globalObject1",
19 | "globalObject1 myMethodName",
20 | "globalObject1 myMethodName true",
21 | "globalObject1.foo",
22 | "globalObject1.foo myMethodName",
23 | ["globalObject1"],
24 | ["globalObject1.foo"],
25 | ["globalObject1.foo", "globalObject1.bar"],
26 | ],
27 | failure: [
28 | false,
29 | true,
30 | /test/,
31 | "",
32 | [],
33 | [""],
34 | {},
35 | {
36 | globalName: true,
37 | },
38 | {
39 | moduleLocalName: true,
40 | },
41 | {
42 | override: "test",
43 | },
44 | ],
45 | },
46 | unknown: {
47 | success: [],
48 | failure: [1, true, false, "test", /test/, [], {}, { foo: "bar" }],
49 | },
50 | };
51 |
52 | function stringifyValue(value) {
53 | if (
54 | Array.isArray(value) ||
55 | (value && typeof value === "object" && value.constructor === Object)
56 | ) {
57 | return JSON.stringify(value);
58 | }
59 |
60 | return value;
61 | }
62 |
63 | async function createTestCase(key, value, type) {
64 | it(`should ${
65 | type === "success" ? "successfully validate" : "throw an error on"
66 | } the "${key}" option with "${stringifyValue(value)}" value`, async () => {
67 | const compiler = getCompiler("./simple-commonjs2-single-export.js", {
68 | [key]: value,
69 | });
70 |
71 | let stats;
72 |
73 | try {
74 | stats = await compile(compiler);
75 | } finally {
76 | if (type === "success") {
77 | expect(stats.hasErrors()).toBe(false);
78 | } else if (type === "failure") {
79 | const {
80 | compilation: { errors },
81 | } = stats;
82 |
83 | expect(errors).toHaveLength(1);
84 | expect(() => {
85 | throw new Error(errors[0].error.message);
86 | }).toThrowErrorMatchingSnapshot();
87 | }
88 | }
89 | });
90 | }
91 |
92 | for (const [key, values] of Object.entries(tests)) {
93 | for (const type of Object.keys(values)) {
94 | for (const value of values[type]) {
95 | createTestCase(key, value, type);
96 | }
97 | }
98 | }
99 | });
100 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "expose-loader",
3 | "version": "5.0.1",
4 | "description": "expose loader module for webpack",
5 | "keywords": [
6 | "webpack"
7 | ],
8 | "homepage": "https://github.com/webpack/expose-loader",
9 | "bugs": "https://github.com/webpack/expose-loader/issues",
10 | "repository": "webpack/expose-loader",
11 | "funding": {
12 | "type": "opencollective",
13 | "url": "https://opencollective.com/webpack"
14 | },
15 | "license": "MIT",
16 | "author": "Tobias Koppers @sokra",
17 | "main": "dist/cjs.js",
18 | "files": [
19 | "dist"
20 | ],
21 | "scripts": {
22 | "start": "npm run build -- -w",
23 | "clean": "del-cli dist",
24 | "prebuild": "npm run clean",
25 | "build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
26 | "commitlint": "commitlint --from=main",
27 | "security": "npm audit --production",
28 | "lint:prettier": "prettier --cache --list-different .",
29 | "lint:runtime": "es-check es5 \"dist/runtime/**/*.js\"",
30 | "lint:code": "eslint --cache .",
31 | "lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"",
32 | "lint": "npm-run-all -l -p \"lint:**\"",
33 | "fix:code": "npm run lint:code -- --fix",
34 | "fix:prettier": "npm run lint:prettier -- --write",
35 | "fix": "npm-run-all -l fix:code fix:prettier",
36 | "test:only": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest",
37 | "test:watch": "npm run test:only -- --watch",
38 | "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
39 | "pretest": "npm run lint",
40 | "test": "npm run test:coverage",
41 | "prepare": "husky && npm run build",
42 | "release": "standard-version"
43 | },
44 | "devDependencies": {
45 | "@babel/cli": "^7.24.8",
46 | "@babel/core": "^7.25.2",
47 | "@babel/preset-env": "^7.25.3",
48 | "@commitlint/cli": "^19.3.0",
49 | "@commitlint/config-conventional": "^19.2.2",
50 | "@eslint/js": "^9.32.0",
51 | "@eslint/markdown": "^7.1.0",
52 | "@stylistic/eslint-plugin": "^5.2.2",
53 | "babel-jest": "^30.0.5",
54 | "babel-loader": "^10.0.0",
55 | "cross-env": "^7.0.3",
56 | "cspell": "^8.13.1",
57 | "del": "^7.1.0",
58 | "del-cli": "^5.1.0",
59 | "es-check": "^9.1.4",
60 | "eslint": "^9.32.0",
61 | "eslint-config-prettier": "^10.1.8",
62 | "eslint-config-webpack": "^4.5.1",
63 | "eslint-plugin-import": "^2.32.0",
64 | "eslint-plugin-jest": "^29.0.1",
65 | "eslint-plugin-markdown": "^5.1.0",
66 | "eslint-plugin-n": "^17.21.0",
67 | "eslint-plugin-prettier": "^5.5.3",
68 | "eslint-plugin-unicorn": "^60.0.0",
69 | "globals": "^16.3.0",
70 | "husky": "^9.1.4",
71 | "jest": "^30.0.5",
72 | "lint-staged": "^15.2.8",
73 | "memfs": "^4.11.1",
74 | "npm-run-all": "^4.1.5",
75 | "prettier": "^3.3.3",
76 | "react": "^19.1.1",
77 | "react-dom": "^19.1.1",
78 | "rx": "^4.1.0",
79 | "standard-version": "^9.3.0",
80 | "styled-components": "^6.1.12",
81 | "typescript-eslint": "^8.38.0",
82 | "webpack": "^5.93.0"
83 | },
84 | "peerDependencies": {
85 | "webpack": "^5.0.0"
86 | },
87 | "engines": {
88 | "node": ">= 18.12.0"
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License http://www.opensource.org/licenses/mit-license.php
3 | Author Tobias Koppers @sokra
4 | */
5 |
6 | import schema from "./options.json";
7 |
8 | import {
9 | contextify,
10 | getExposes,
11 | getNewUserRequest,
12 | interpolateName,
13 | stringifyRequest,
14 | } from "./utils";
15 |
16 | export default function loader() {
17 | const options = this.getOptions(schema);
18 | const callback = this.async();
19 |
20 | let exposes;
21 |
22 | try {
23 | exposes = getExposes(options.exposes);
24 | } catch (error) {
25 | callback(error);
26 |
27 | return;
28 | }
29 |
30 | /*
31 | * Workaround until module.libIdent() in webpack/webpack handles this correctly.
32 | *
33 | * Fixes:
34 | * - https://github.com/webpack/expose-loader/issues/55
35 | * - https://github.com/webpack/expose-loader/issues/49
36 | */
37 | this._module.userRequest = getNewUserRequest(this._module.userRequest);
38 |
39 | /*
40 | * Adding side effects
41 | *
42 | * Fixes:
43 | * - https://github.com/webpack/expose-loader/issues/120
44 | */
45 | if (this._module.factoryMeta) {
46 | this._module.factoryMeta.sideEffectFree = false;
47 | }
48 |
49 | // Change the request from an /absolute/path.js to a relative ./path.js.
50 | // This prevents `[chunkhash]` values from changing when running webpack builds in different directories.
51 | const newRequest = contextify(this, this.context, this.remainingRequest);
52 | const stringifiedNewRequest = stringifyRequest(this, `-!${newRequest}`);
53 |
54 | let code = `var ___EXPOSE_LOADER_IMPORT___ = require(${stringifiedNewRequest});\n`;
55 |
56 | const getGlobalThis =
57 | options.globalObject ||
58 | `require(${stringifyRequest(
59 | this,
60 | require.resolve("./runtime/getGlobalThis.js"),
61 | )})`;
62 |
63 | code += `var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = ${getGlobalThis};\n`;
64 | code +=
65 | "var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;\n";
66 |
67 | for (const expose of exposes) {
68 | const { globalName, moduleLocalName, override } = expose;
69 | const globalNameInterpolated = globalName.map((item) =>
70 | interpolateName(this, item, {}),
71 | );
72 |
73 | if (typeof moduleLocalName !== "undefined") {
74 | code += `var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.${moduleLocalName}\n`;
75 | }
76 |
77 | let propertyString = "___EXPOSE_LOADER_GLOBAL_THIS___";
78 |
79 | for (let i = 0; i < globalName.length; i++) {
80 | if (i > 0) {
81 | code += `if (typeof ${propertyString} === 'undefined') ${propertyString} = {};\n`;
82 | }
83 |
84 | propertyString += `[${JSON.stringify(globalNameInterpolated[i])}]`;
85 | }
86 |
87 | if (!override) {
88 | code += `if (typeof ${propertyString} === 'undefined') `;
89 | }
90 |
91 | code +=
92 | typeof moduleLocalName !== "undefined"
93 | ? `${propertyString} = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;\n`
94 | : `${propertyString} = ___EXPOSE_LOADER_IMPORT___;\n`;
95 |
96 | if (!override && this.mode === "development") {
97 | code += `else throw new Error('[expose-loader] The "${globalName.join(
98 | ".",
99 | )}" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')\n`;
100 | }
101 | }
102 |
103 | code += "module.exports = ___EXPOSE_LOADER_IMPORT___;\n";
104 |
105 | callback(null, code);
106 | }
107 |
--------------------------------------------------------------------------------
/src/utils.js:
--------------------------------------------------------------------------------
1 | import path from "node:path";
2 |
3 | function getNewUserRequest(request) {
4 | const splittedRequest = request.split("!");
5 | const lastPartRequest = splittedRequest.pop().split("?", 2);
6 | const pathObject = path.parse(lastPartRequest[0]);
7 |
8 | pathObject.base = `${path.basename(pathObject.base, pathObject.ext)}-exposed${
9 | pathObject.ext
10 | }`;
11 |
12 | lastPartRequest[0] = path.format(pathObject);
13 |
14 | splittedRequest.push(lastPartRequest.join("?"));
15 |
16 | return splittedRequest.join("!");
17 | }
18 |
19 | function splitCommand(command) {
20 | const result = command.split("|").flatMap((item) => item.split(" "));
21 |
22 | for (const item of result) {
23 | if (!item) {
24 | throw new Error(
25 | `Invalid command "${item}" in "${command}" for expose. There must be only one separator: " ", or "|".`,
26 | );
27 | }
28 | }
29 |
30 | return result;
31 | }
32 |
33 | function parseBoolean(string, defaultValue = null) {
34 | if (typeof string === "undefined") {
35 | return defaultValue;
36 | }
37 |
38 | switch (string.toLowerCase()) {
39 | case "true":
40 | return true;
41 | case "false":
42 | return false;
43 | default:
44 | return defaultValue;
45 | }
46 | }
47 |
48 | function resolveExposes(item) {
49 | let result;
50 |
51 | if (typeof item === "string") {
52 | const splittedItem = splitCommand(item.trim());
53 |
54 | if (splittedItem.length > 3) {
55 | throw new Error(`Invalid "${item}" for exposes`);
56 | }
57 |
58 | result = {
59 | globalName: splittedItem[0],
60 | moduleLocalName: splittedItem[1],
61 | override:
62 | typeof splittedItem[2] !== "undefined"
63 | ? parseBoolean(splittedItem[2], false)
64 | : undefined,
65 | };
66 | } else {
67 | result = item;
68 | }
69 |
70 | const nestedGlobalName =
71 | typeof result.globalName === "string"
72 | ? result.globalName.split(".")
73 | : result.globalName;
74 |
75 | return { ...result, globalName: nestedGlobalName };
76 | }
77 |
78 | function getExposes(items) {
79 | const exposeItems =
80 | typeof items === "string" && items.includes(",") ? items.split(",") : items;
81 |
82 | const result =
83 | typeof exposeItems === "string"
84 | ? [resolveExposes(exposeItems)]
85 | : [exposeItems].flat().map((item) => resolveExposes(item));
86 |
87 | return result;
88 | }
89 |
90 | // TODO simplify for the next major release
91 | function contextify(loaderContext, context, request) {
92 | if (
93 | typeof loaderContext.utils !== "undefined" &&
94 | typeof loaderContext.utils.contextify === "function"
95 | ) {
96 | return loaderContext.utils.contextify(loaderContext.context, request);
97 | }
98 |
99 | return request
100 | .split("!")
101 | .map((r) => {
102 | const splitPath = r.split("?");
103 |
104 | if (/^[a-zA-Z]:\\/.test(splitPath[0])) {
105 | splitPath[0] = path.win32.relative(context, splitPath[0]);
106 |
107 | if (!/^[a-zA-Z]:\\/.test(splitPath[0])) {
108 | splitPath[0] = splitPath[0].replaceAll("\\", "/");
109 | }
110 | }
111 |
112 | if (/^\//.test(splitPath[0])) {
113 | splitPath[0] = path.posix.relative(context, splitPath[0]);
114 | }
115 |
116 | if (!/^(\.\.\/|\/|[a-zA-Z]:\\)/.test(splitPath[0])) {
117 | splitPath[0] = `./${splitPath[0]}`;
118 | }
119 |
120 | return splitPath.join("?");
121 | })
122 | .join("!");
123 | }
124 |
125 | function isAbsolutePath(str) {
126 | return path.posix.isAbsolute(str) || path.win32.isAbsolute(str);
127 | }
128 |
129 | // TODO simplify for the next major release
130 | function stringifyRequest(loaderContext, request) {
131 | if (
132 | typeof loaderContext.utils !== "undefined" &&
133 | typeof loaderContext.utils.contextify === "function"
134 | ) {
135 | return JSON.stringify(
136 | loaderContext.utils.contextify(loaderContext.context, request),
137 | );
138 | }
139 |
140 | const splitted = request.split("!");
141 | const context =
142 | loaderContext.context ||
143 | (loaderContext.options && loaderContext.options.context);
144 |
145 | return JSON.stringify(
146 | splitted
147 | .map((part) => {
148 | // First, separate singlePath from query, because the query might contain paths again
149 | const splittedPart = part.match(/^(.*?)(\?.*)/);
150 | const query = splittedPart ? splittedPart[2] : "";
151 | let singlePath = splittedPart ? splittedPart[1] : part;
152 |
153 | if (isAbsolutePath(singlePath) && context) {
154 | singlePath = path.relative(context, singlePath);
155 | }
156 |
157 | return singlePath.replaceAll("\\", "/") + query;
158 | })
159 | .join("!"),
160 | );
161 | }
162 |
163 | function interpolateName(loaderContext, filename) {
164 | let basename = "file";
165 |
166 | if (loaderContext.resourcePath) {
167 | const parsed = path.parse(loaderContext.resourcePath);
168 |
169 | if (parsed.dir) {
170 | basename = parsed.name;
171 | }
172 | }
173 |
174 | return filename.replaceAll(/\[name\]/gi, () => basename);
175 | }
176 |
177 | export {
178 | contextify,
179 | getExposes,
180 | getNewUserRequest,
181 | interpolateName,
182 | stringifyRequest,
183 | };
184 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 | ### [5.0.1](https://github.com/webpack-contrib/expose-loader/compare/v5.0.0...v5.0.1) (2025-02-07)
6 |
7 |
8 | ### Bug Fixes
9 |
10 | * add missing return statement ([#244](https://github.com/webpack-contrib/expose-loader/issues/244)) ([bc741a0](https://github.com/webpack-contrib/expose-loader/commit/bc741a0abbf589c9065d5966cfd2f36ca9c3c9a6))
11 |
12 | ## [5.0.0](https://github.com/webpack-contrib/expose-loader/compare/v4.1.0...v5.0.0) (2024-01-17)
13 |
14 |
15 | ### ⚠ BREAKING CHANGES
16 |
17 | * minimum supported Node.js version is `18.12.0` ([#225](https://github.com/webpack-contrib/expose-loader/issues/225)) ([1eb4039](https://github.com/webpack-contrib/expose-loader/commit/1eb4039fedf0fa3cb96ded94a75545250961848d))
18 |
19 | ## [4.1.0](https://github.com/webpack-contrib/expose-loader/compare/v4.0.0...v4.1.0) (2023-03-09)
20 |
21 |
22 | ### Features
23 |
24 | * added `globalObject` option to modify global context ([#205](https://github.com/webpack-contrib/expose-loader/issues/205)) ([1ad9096](https://github.com/webpack-contrib/expose-loader/commit/1ad90966b8676ba21e9d42d75cc0d9885e332ffc))
25 |
26 | ## [4.0.0](https://github.com/webpack-contrib/expose-loader/compare/v3.1.0...v4.0.0) (2022-05-17)
27 |
28 |
29 | ### ⚠ BREAKING CHANGES
30 |
31 | * minimum supported `Node.js` version is `14.15.0`
32 |
33 | ## [3.1.0](https://github.com/webpack-contrib/expose-loader/compare/v3.0.0...v3.1.0) (2021-10-21)
34 |
35 |
36 | ### Features
37 |
38 | * output links on validation errors ([#138](https://github.com/webpack-contrib/expose-loader/issues/138)) ([c897dad](https://github.com/webpack-contrib/expose-loader/commit/c897dadbd14bb6b24fa0879b294331020bfdd82c))
39 |
40 |
41 | ### Bug Fixes
42 |
43 | * small perf improvement ([#145](https://github.com/webpack-contrib/expose-loader/issues/145)) ([6aeabd8](https://github.com/webpack-contrib/expose-loader/commit/6aeabd808d9fd35ef7dbd2dfb45f85a469c978cb))
44 |
45 | ## [3.0.0](https://github.com/webpack-contrib/expose-loader/compare/v2.0.0...v3.0.0) (2021-05-20)
46 |
47 | ### ⚠ BREAKING CHANGES
48 |
49 | * minimum supported `Node.js` version is `12.13.0`
50 |
51 | ## [2.0.0](https://github.com/webpack-contrib/expose-loader/compare/v1.0.3...v2.0.0) (2021-02-02)
52 |
53 |
54 | ### ⚠ BREAKING CHANGES
55 |
56 | * minimum supported `webpack` version is `5`
57 | * inline syntax was changed: `[]` is no longer supported (i.e. `import $ from "expose-loader?exposes[]=$&exposes[]=jQuery!jquery`), please use `,` comma separator (i.e. `import $ from "expose-loader?exposes=$,jQuery!jquery`)
58 |
59 | ### [1.0.3](https://github.com/webpack-contrib/expose-loader/compare/v1.0.2...v1.0.3) (2020-11-26)
60 |
61 |
62 | ### Bug Fixes
63 |
64 | * set side effects to false ([#122](https://github.com/webpack-contrib/expose-loader/issues/122)) ([ee2631d](https://github.com/webpack-contrib/expose-loader/commit/ee2631df243e4fa13f107189be5dc469108495b3))
65 |
66 | ### [1.0.2](https://github.com/webpack-contrib/expose-loader/compare/v1.0.1...v1.0.2) (2020-11-25)
67 |
68 |
69 | ### Bug Fixes
70 |
71 | * don't strip loader "ref" from import string ([6271fc4](https://github.com/webpack-contrib/expose-loader/commit/6271fc4e227a63aae082b9a111e103b6967bc1ba))
72 |
73 | ### [1.0.1](https://github.com/webpack-contrib/expose-loader/compare/v1.0.0...v1.0.1) (2020-10-09)
74 |
75 | ### Chore
76 |
77 | * update `schema-utils`
78 |
79 | ## [1.0.0](https://github.com/webpack-contrib/expose-loader/compare/v0.7.5...v1.0.0) (2020-06-23)
80 |
81 |
82 | ### ⚠ BREAKING CHANGES
83 |
84 | * minimum supported Node.js version is `10.13`
85 | * minimum supported `webpack` version is `4`
86 | * `inline` syntax was changed, please [read](https://github.com/webpack-contrib/expose-loader#inline)
87 | * list of exposed values moved to the `exposes` option, please [read](https://github.com/webpack-contrib/expose-loader#exposes)
88 | * migrate away from `pitch` phase
89 | * do not override existing exposed values in the global object by default, because it is unsafe, please [read](https://github.com/webpack-contrib/expose-loader#override)
90 |
91 | ### Features
92 |
93 | * validate options
94 | * support webpack 5
95 | * support multiple exposed values
96 | * interpolate exposed values
97 | * allow to expose part of a module
98 | * allow to expose values with `.` (dot) in the name
99 |
100 | ### Fixes
101 |
102 | * do not break source maps
103 | * do not generate different hashed on different os
104 | * compatibility with ES module syntax
105 |
106 |
107 | ## [0.7.5](https://github.com/webpack-contrib/expose-loader/compare/v0.7.4...v0.7.5) (2018-03-09)
108 |
109 |
110 | ### Bug Fixes
111 |
112 | * **package:** add `webpack >= v4.0.0` (`peerDependencies`) ([#67](https://github.com/webpack-contrib/expose-loader/issues/67)) ([daf39ea](https://github.com/webpack-contrib/expose-loader/commit/daf39ea))
113 |
114 |
115 |
116 |
117 | ## 0.7.4 (2017-11-18)
118 |
119 |
120 | ### Bug Fixes
121 |
122 | * **hash:** inconsistent hashes for builds in different dirs. ([#28](https://github.com/webpack-contrib/expose-loader/issues/28)) ([efe59de](https://github.com/webpack-contrib/expose-loader/commit/efe59de))
123 | * **remainingRequest:** resolve issue when multiple variables are exposed for the same request. ([#30](https://github.com/webpack-contrib/expose-loader/issues/30)) ([335f9e6](https://github.com/webpack-contrib/expose-loader/commit/335f9e6))
124 | * ensure `userRequest` stays unique (`module.userRequest`) ([#58](https://github.com/webpack-contrib/expose-loader/issues/58)) ([51629a4](https://github.com/webpack-contrib/expose-loader/commit/51629a4))
125 |
--------------------------------------------------------------------------------
/test/__snapshots__/validate-options.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`validate options should throw an error on the "exposes" option with "" value 1`] = `
4 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
5 | - options.exposes should be a non-empty string."
6 | `;
7 |
8 | exports[`validate options should throw an error on the "exposes" option with "/test/" value 1`] = `
9 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
10 | - options.exposes misses the property 'globalName'. Should be:
11 | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
12 | -> The name in the global object.
13 | -> Read more at https://github.com/webpack/expose-loader#globalname"
14 | `;
15 |
16 | exports[`validate options should throw an error on the "exposes" option with "[""]" value 1`] = `
17 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
18 | - options.exposes[0] should be a non-empty string."
19 | `;
20 |
21 | exports[`validate options should throw an error on the "exposes" option with "[]" value 1`] = `
22 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
23 | - options.exposes should be a non-empty array."
24 | `;
25 |
26 | exports[`validate options should throw an error on the "exposes" option with "{"globalName":true}" value 1`] = `
27 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
28 | - options.exposes should be one of these:
29 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
30 | -> List of exposes.
31 | -> Read more at https://github.com/webpack/expose-loader#exposes
32 | Details:
33 | * options.exposes.globalName should be one of these:
34 | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
35 | -> The name in the global object.
36 | -> Read more at https://github.com/webpack/expose-loader#globalname
37 | Details:
38 | * options.exposes.globalName should be a non-empty string.
39 | * options.exposes.globalName should be an array:
40 | [non-empty string, ...] (should not have fewer than 1 item)"
41 | `;
42 |
43 | exports[`validate options should throw an error on the "exposes" option with "{"moduleLocalName":true}" value 1`] = `
44 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
45 | - options.exposes.moduleLocalName should be a non-empty string.
46 | -> he name of method/variable/etc of the module (the module must export it)."
47 | `;
48 |
49 | exports[`validate options should throw an error on the "exposes" option with "{"override":"test"}" value 1`] = `
50 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
51 | - options.exposes.override should be a boolean.
52 | -> Configure loader to override the existing value in the global object.
53 | -> Read more at https://github.com/webpack/expose-loader#override"
54 | `;
55 |
56 | exports[`validate options should throw an error on the "exposes" option with "{}" value 1`] = `
57 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
58 | - options.exposes misses the property 'globalName'. Should be:
59 | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
60 | -> The name in the global object.
61 | -> Read more at https://github.com/webpack/expose-loader#globalname"
62 | `;
63 |
64 | exports[`validate options should throw an error on the "exposes" option with "false" value 1`] = `
65 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
66 | - options.exposes should be one of these:
67 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
68 | -> List of exposes.
69 | -> Read more at https://github.com/webpack/expose-loader#exposes
70 | Details:
71 | * options.exposes should be a non-empty string.
72 | * options.exposes should be an object:
73 | object { globalName, moduleLocalName?, override? }
74 | * options.exposes should be an array:
75 | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)"
76 | `;
77 |
78 | exports[`validate options should throw an error on the "exposes" option with "true" value 1`] = `
79 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
80 | - options.exposes should be one of these:
81 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
82 | -> List of exposes.
83 | -> Read more at https://github.com/webpack/expose-loader#exposes
84 | Details:
85 | * options.exposes should be a non-empty string.
86 | * options.exposes should be an object:
87 | object { globalName, moduleLocalName?, override? }
88 | * options.exposes should be an array:
89 | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)"
90 | `;
91 |
92 | exports[`validate options should throw an error on the "unknown" option with "/test/" value 1`] = `
93 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
94 | - options misses the property 'exposes'. Should be:
95 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
96 | -> List of exposes.
97 | -> Read more at https://github.com/webpack/expose-loader#exposes"
98 | `;
99 |
100 | exports[`validate options should throw an error on the "unknown" option with "[]" value 1`] = `
101 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
102 | - options misses the property 'exposes'. Should be:
103 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
104 | -> List of exposes.
105 | -> Read more at https://github.com/webpack/expose-loader#exposes"
106 | `;
107 |
108 | exports[`validate options should throw an error on the "unknown" option with "{"foo":"bar"}" value 1`] = `
109 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
110 | - options misses the property 'exposes'. Should be:
111 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
112 | -> List of exposes.
113 | -> Read more at https://github.com/webpack/expose-loader#exposes"
114 | `;
115 |
116 | exports[`validate options should throw an error on the "unknown" option with "{}" value 1`] = `
117 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
118 | - options misses the property 'exposes'. Should be:
119 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
120 | -> List of exposes.
121 | -> Read more at https://github.com/webpack/expose-loader#exposes"
122 | `;
123 |
124 | exports[`validate options should throw an error on the "unknown" option with "1" value 1`] = `
125 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
126 | - options misses the property 'exposes'. Should be:
127 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
128 | -> List of exposes.
129 | -> Read more at https://github.com/webpack/expose-loader#exposes"
130 | `;
131 |
132 | exports[`validate options should throw an error on the "unknown" option with "false" value 1`] = `
133 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
134 | - options misses the property 'exposes'. Should be:
135 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
136 | -> List of exposes.
137 | -> Read more at https://github.com/webpack/expose-loader#exposes"
138 | `;
139 |
140 | exports[`validate options should throw an error on the "unknown" option with "test" value 1`] = `
141 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
142 | - options misses the property 'exposes'. Should be:
143 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
144 | -> List of exposes.
145 | -> Read more at https://github.com/webpack/expose-loader#exposes"
146 | `;
147 |
148 | exports[`validate options should throw an error on the "unknown" option with "true" value 1`] = `
149 | "Invalid options object. Expose Loader has been initialized using an options object that does not match the API schema.
150 | - options misses the property 'exposes'. Should be:
151 | non-empty string | object { globalName, moduleLocalName?, override? } | [non-empty string | object { globalName, moduleLocalName?, override? }, ...] (should not have fewer than 1 item)
152 | -> List of exposes.
153 | -> Read more at https://github.com/webpack/expose-loader#exposes"
154 | `;
155 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
6 |
7 | [![npm][npm]][npm-url]
8 | [![node][node]][node-url]
9 | [![tests][tests]][tests-url]
10 | [![coverage][cover]][cover-url]
11 | [![discussion][discussion]][discussion-url]
12 | [![size][size]][size-url]
13 |
14 | # expose-loader
15 |
16 | The `expose-loader` loader allows to expose a module (either in whole or in part) to global object (`self`, `window` and `global`).
17 |
18 | For compatibility tips and examples, check out [Shimming](https://webpack.js.org/guides/shimming/) guide in the official documentation.
19 |
20 | ## Getting Started
21 |
22 | To begin, you'll need to install `expose-loader`:
23 |
24 | ```console
25 | npm install expose-loader --save-dev
26 | ```
27 |
28 | or
29 |
30 | ```console
31 | yarn add -D expose-loader
32 | ```
33 |
34 | or
35 |
36 | ```console
37 | pnpm add -D expose-loader
38 | ```
39 |
40 | (If you're using webpack 4, install `expose-loader@1` and follow the [corresponding instructions](https://v4.webpack.js.org/loaders/expose-loader/) instead.)
41 |
42 | Then you can use the `expose-loader` using two approaches.
43 |
44 | ## Inline
45 |
46 | The `|` or `%20` (space) allow to separate the `globalName`, `moduleLocalName` and `override` of expose.
47 |
48 | The documentation and syntax examples can be read [here](#syntax).
49 |
50 | > [!WARNING]
51 | >
52 | > `%20` represents a `space` in a query string because spaces are not allowed in URLs.
53 |
54 | ```js
55 | import $ from "expose-loader?exposes=$,jQuery!jquery";
56 | //
57 | // Adds the `jquery` to the global object under the names `$` and `jQuery`
58 | ```
59 |
60 | ```js
61 | import { concat } from "expose-loader?exposes=_.concat!lodash/concat";
62 | //
63 | // Adds the `lodash/concat` to the global object under the name `_.concat`
64 | ```
65 |
66 | ```js
67 | import {
68 | map,
69 | reduce,
70 | } from "expose-loader?exposes=_.map|map,_.reduce|reduce!underscore";
71 | //
72 | // Adds the `map` and `reduce` method from `underscore` to the global object under the name `_.map` and `_.reduce`
73 | ```
74 |
75 | ## Using Configuration
76 |
77 | **src/index.js**
78 |
79 | ```js
80 | import $ from "jquery";
81 | ```
82 |
83 | **webpack.config.js**
84 |
85 | ```js
86 | module.exports = {
87 | module: {
88 | rules: [
89 | {
90 | test: require.resolve("jquery"),
91 | loader: "expose-loader",
92 | options: {
93 | exposes: ["$", "jQuery"],
94 | },
95 | },
96 | {
97 | test: require.resolve("underscore"),
98 | loader: "expose-loader",
99 | options: {
100 | exposes: [
101 | "_.map|map",
102 | {
103 | globalName: "_.reduce",
104 | moduleLocalName: "reduce",
105 | },
106 | {
107 | globalName: ["_", "filter"],
108 | moduleLocalName: "filter",
109 | },
110 | ],
111 | },
112 | },
113 | ],
114 | },
115 | };
116 | ```
117 |
118 | The [`require.resolve`](https://nodejs.org/api/modules.html#modules_require_resolve_request_options) call is a Node.js function (unrelated to `require.resolve` in webpack processing).
119 |
120 | `require.resolve` that returns the absolute path of the module (`"/.../app/node_modules/jquery/dist/jquery.js"`).
121 |
122 | So the expose only applies to the `jquery` module and it's only exposed when used in the bundle.
123 |
124 | Finally, run `webpack` using the method you normally use (e.g., via CLI or an npm script).
125 |
126 | ## Options
127 |
128 | | Name | Type | Default | Description |
129 | | :---------------------------------: | :---------------------------------------: | :---------: | :----------------------------- |
130 | | **[`exposes`](#exposes)** | `{String\|Object\|Array}` | `undefined` | List of exposes |
131 | | **[`globalObject`](#globalObject)** | `String` | `undefined` | Object used for global context |
132 |
133 | ### `exposes`
134 |
135 | Type:
136 |
137 | ```ts
138 | type exposes =
139 | | string
140 | | {
141 | globalName: string | string[];
142 | moduleLocalName?: string;
143 | override?: boolean;
144 | }
145 | | (
146 | | string
147 | | {
148 | globalName: string | string[];
149 | moduleLocalName?: string;
150 | override?: boolean;
151 | }
152 | )[];
153 | ```
154 |
155 | Default: `undefined`
156 |
157 | List of exposes.
158 |
159 | #### `string`
160 |
161 | Allows to use a `string` to describe an expose.
162 |
163 | ##### `syntax`
164 |
165 | The `|` or `%20` (space) allow to separate the `globalName`, `moduleLocalName` and `override` of expose.
166 |
167 | String syntax - `[[globalName] [moduleLocalName] [override]]` or `[[globalName]|[moduleLocalName]|[override]]`, where:
168 |
169 | - `globalName` - The name on the global object, for example `window.$` for a browser environment (**required**)
170 | - `moduleLocalName` - The name of method/variable etc of the module (the module must export it) (**may be omitted**)
171 | - `override` - Allows to override existing value in the global object (**may be omitted**)
172 |
173 | If `moduleLocalName` is not specified, it exposes the entire module to the global object, otherwise it exposes only the value of `moduleLocalName`.
174 |
175 | **src/index.js**
176 |
177 | ```js
178 | import $ from "jquery";
179 | import _ from "underscore";
180 | ```
181 |
182 | **webpack.config.js**
183 |
184 | ```js
185 | module.exports = {
186 | module: {
187 | rules: [
188 | {
189 | test: require.resolve("jquery"),
190 | loader: "expose-loader",
191 | options: {
192 | // For `underscore` library, it can be `_.map map` or `_.map|map`
193 | exposes: "$",
194 | // To access please use `window.$` or `globalThis.$`
195 | },
196 | },
197 | {
198 | // test: require.resolve("jquery"),
199 | test: /node_modules[/\\]underscore[/\\]modules[/\\]index-all\.js$/,
200 | loader: "expose-loader",
201 | type: "javascript/auto",
202 | options: {
203 | // For `underscore` library, it can be `_.map map` or `_.map|map`
204 | exposes: "_",
205 | // To access please use `window._` or `globalThis._`
206 | },
207 | },
208 | ],
209 | },
210 | };
211 | ```
212 |
213 | #### `object`
214 |
215 | Allows to use an object to describe an expose.
216 |
217 | ##### `globalName`
218 |
219 | Type:
220 |
221 | ```ts
222 | type globalName = string | string[];
223 | ```
224 |
225 | Default: `undefined`
226 |
227 | The name in the global object. (**required**).
228 |
229 | **src/index.js**
230 |
231 | ```js
232 | import _ from "underscore";
233 | ```
234 |
235 | **webpack.config.js**
236 |
237 | ```js
238 | module.exports = {
239 | module: {
240 | rules: [
241 | {
242 | test: /node_modules[/\\]underscore[/\\]modules[/\\]index-all\.js$/,
243 | loader: "expose-loader",
244 | type: "javascript/auto",
245 | options: {
246 | exposes: {
247 | // Can be `['_', 'filter']`
248 | globalName: "_.filter",
249 | moduleLocalName: "filter",
250 | },
251 | },
252 | },
253 | ],
254 | },
255 | };
256 | ```
257 |
258 | ##### `moduleLocalName`
259 |
260 | Type:
261 |
262 | ```ts
263 | type moduleLocalName = string;
264 | ```
265 |
266 | Default: `undefined`
267 |
268 | The name of method/variable etc of the module (the module must export it).
269 |
270 | If `moduleLocalName` is specified, it exposes only the value of `moduleLocalName`.
271 |
272 | **src/index.js**
273 |
274 | ```js
275 | import _ from "underscore";
276 | ```
277 |
278 | **webpack.config.js**
279 |
280 | ```js
281 | module.exports = {
282 | module: {
283 | rules: [
284 | {
285 | test: /node_modules[/\\]underscore[/\\]modules[/\\]index-all\.js$/,
286 | loader: "expose-loader",
287 | type: "javascript/auto",
288 | options: {
289 | exposes: {
290 | globalName: "_.filter",
291 | moduleLocalName: "filter",
292 | },
293 | },
294 | },
295 | ],
296 | },
297 | };
298 | ```
299 |
300 | ##### `override`
301 |
302 | Type:
303 |
304 | ```ts
305 | type override = boolean;
306 | ```
307 |
308 | Default: `false`
309 |
310 | By default, loader does not override the existing value in the global object, because it is unsafe.
311 |
312 | In `development` mode, we throw an error if the value already present in the global object.
313 |
314 | But you can configure loader to override the existing value in the global object using this option.
315 |
316 | To force override the value that is already present in the global object you can set the `override` option to the `true` value.
317 |
318 | **src/index.js**
319 |
320 | ```js
321 | import $ from "jquery";
322 | ```
323 |
324 | **webpack.config.js**
325 |
326 | ```js
327 | module.exports = {
328 | module: {
329 | rules: [
330 | {
331 | test: require.resolve("jquery"),
332 | loader: "expose-loader",
333 | options: {
334 | exposes: {
335 | globalName: "$",
336 | override: true,
337 | },
338 | },
339 | },
340 | ],
341 | },
342 | };
343 | ```
344 |
345 | #### `array`
346 |
347 | **src/index.js**
348 |
349 | ```js
350 | import _ from "underscore";
351 | ```
352 |
353 | **webpack.config.js**
354 |
355 | ```js
356 | module.exports = {
357 | module: {
358 | rules: [
359 | {
360 | test: /node_modules[/\\]underscore[/\\]modules[/\\]index-all\.js$/,
361 | loader: "expose-loader",
362 | type: "javascript/auto",
363 | options: {
364 | exposes: [
365 | "_.map map",
366 | {
367 | globalName: "_.filter",
368 | moduleLocalName: "filter",
369 | },
370 | {
371 | globalName: ["_", "find"],
372 | moduleLocalName: "myNameForFind",
373 | },
374 | ],
375 | },
376 | },
377 | ],
378 | },
379 | };
380 | ```
381 |
382 | It will expose **only** `map`, `filter` and `find` (under `myNameForFind` name) methods to the global object.
383 |
384 | In browsers, these methods will be available under `windows._.map(..args)`, `windows._.filter(...args)` and `windows._.myNameForFind(...args)` methods.
385 |
386 | ### `globalObject`
387 |
388 | ```ts
389 | type globalObject = string;
390 | ```
391 |
392 | Default: `undefined`
393 |
394 | Object used for global context
395 |
396 | ```js
397 | import _ from "underscore";
398 | ```
399 |
400 | **webpack.config.js**
401 |
402 | ```js
403 | module.exports = {
404 | module: {
405 | rules: [
406 | {
407 | test: /node_modules[/\\]underscore[/\\]modules[/\\]index-all\.js$/,
408 | loader: "expose-loader",
409 | type: "javascript/auto",
410 | options: {
411 | exposes: [
412 | {
413 | globalName: "_",
414 | },
415 | ],
416 | globalObject: "this",
417 | },
418 | },
419 | ],
420 | },
421 | };
422 | ```
423 |
424 | ## Examples
425 |
426 | ### Expose a local module
427 |
428 | **index.js**
429 |
430 | ```js
431 | import { method1 } from "./my-module.js";
432 | ```
433 |
434 | **my-module.js**
435 |
436 | ```js
437 | function method1() {
438 | console.log("method1");
439 | }
440 |
441 | function method2() {
442 | console.log("method1");
443 | }
444 |
445 | export { method1, method2 };
446 | ```
447 |
448 | **webpack.config.js**
449 |
450 | ```js
451 | module.exports = {
452 | module: {
453 | rules: [
454 | {
455 | test: /my-module\.js$/,
456 | loader: "expose-loader",
457 | options: {
458 | exposes: "mod",
459 | // // To access please use `window.mod` or `globalThis.mod`
460 | },
461 | },
462 | ],
463 | },
464 | };
465 | ```
466 |
467 | ## Contributing
468 |
469 | We welcome all contributions!
470 |
471 | If you're new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.
472 |
473 | [CONTRIBUTING](https://github.com/webpack/expose-loader?tab=contributing-ov-file#contributing)
474 |
475 | ## License
476 |
477 | [MIT](./LICENSE)
478 |
479 | [npm]: https://img.shields.io/npm/v/expose-loader.svg
480 | [npm-url]: https://npmjs.com/package/expose-loader
481 | [node]: https://img.shields.io/node/v/expose-loader.svg
482 | [node-url]: https://nodejs.org
483 | [tests]: https://github.com/webpack/expose-loader/workflows/expose-loader/badge.svg
484 | [tests-url]: https://github.com/webpack/expose-loader/actions
485 | [cover]: https://codecov.io/gh/webpack/expose-loader/branch/main/graph/badge.svg
486 | [cover-url]: https://codecov.io/gh/webpack/expose-loader
487 | [discussion]: https://img.shields.io/github/discussions/webpack/webpack
488 | [discussion-url]: https://github.com/webpack/webpack/discussions
489 | [size]: https://packagephobia.now.sh/badge?p=expose-loader
490 | [size-url]: https://packagephobia.now.sh/result?p=expose-loader
491 |
--------------------------------------------------------------------------------
/test/loader.test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment node
3 | */
4 | import path from "node:path";
5 |
6 | import {
7 | compile,
8 | execute,
9 | getCompiler,
10 | getErrors,
11 | getModuleSource,
12 | getModulesList,
13 | getWarnings,
14 | readAsset,
15 | } from "./helpers";
16 |
17 | jest.setTimeout(30000);
18 |
19 | describe("loader", () => {
20 | it("should work", async () => {
21 | const compiler = getCompiler("simple-commonjs2-single-export.js", {
22 | exposes: "myGlobal",
23 | });
24 | const stats = await compile(compiler);
25 |
26 | expect(
27 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
28 | ).toMatchSnapshot("module");
29 | expect(
30 | execute(readAsset("main.bundle.js", compiler, stats)),
31 | ).toMatchSnapshot("result");
32 | expect(getErrors(stats)).toMatchSnapshot("errors");
33 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
34 | });
35 |
36 | it('should work with "moduleLocalName"', async () => {
37 | const compiler = getCompiler("simple-commonjs2-multiple-export.js", {
38 | exposes: "moduleMethod myGlobal",
39 | });
40 | const stats = await compile(compiler);
41 |
42 | expect(
43 | getModuleSource("./global-commonjs2-multiple-exports-exposed.js", stats),
44 | ).toMatchSnapshot("module");
45 | expect(
46 | execute(readAsset("main.bundle.js", compiler, stats)),
47 | ).toMatchSnapshot("result");
48 | expect(getErrors(stats)).toMatchSnapshot("errors");
49 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
50 | });
51 |
52 | it("should work with multiple exposes", async () => {
53 | const compiler = getCompiler("simple-commonjs2-single-export.js", {
54 | exposes: ["myGlobal", "myOtherGlobal"],
55 | });
56 | const stats = await compile(compiler);
57 |
58 | expect(
59 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
60 | ).toMatchSnapshot("module");
61 | expect(
62 | execute(readAsset("main.bundle.js", compiler, stats)),
63 | ).toMatchSnapshot("result");
64 | expect(getErrors(stats)).toMatchSnapshot("errors");
65 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
66 | });
67 |
68 | it("should work multiple commonjs exports", async () => {
69 | const compiler = getCompiler("simple-commonjs2-multiple-export.js", {
70 | exposes: ["myOtherGlobal", "myGlobal.globalObject2 globalObject2"],
71 | });
72 | const stats = await compile(compiler);
73 |
74 | expect(
75 | getModuleSource("./global-commonjs2-multiple-exports-exposed.js", stats),
76 | ).toMatchSnapshot("module");
77 | expect(
78 | execute(readAsset("main.bundle.js", compiler, stats)),
79 | ).toMatchSnapshot("result");
80 | expect(getErrors(stats)).toMatchSnapshot("errors");
81 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
82 | });
83 |
84 | it("should work for a nested property for a global object", async () => {
85 | const compiler = getCompiler("simple-commonjs2-single-export.js", {
86 | exposes: "myGlobal.nested",
87 | });
88 | const stats = await compile(compiler);
89 |
90 | expect(
91 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
92 | ).toMatchSnapshot("module");
93 | expect(
94 | execute(readAsset("main.bundle.js", compiler, stats)),
95 | ).toMatchSnapshot("result");
96 | expect(getErrors(stats)).toMatchSnapshot("errors");
97 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
98 | });
99 |
100 | it("should work for nested properties for a global object", async () => {
101 | const compiler = getCompiler("simple-commonjs2-single-export.js", {
102 | exposes: ["myGlobal.nested", "myOtherGlobal.nested foo"],
103 | });
104 | const stats = await compile(compiler);
105 |
106 | expect(
107 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
108 | ).toMatchSnapshot("module");
109 | expect(
110 | execute(readAsset("main.bundle.js", compiler, stats)),
111 | ).toMatchSnapshot("result");
112 | expect(getErrors(stats)).toMatchSnapshot("errors");
113 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
114 | });
115 |
116 | it("should work from esModule export", async () => {
117 | const compiler = getCompiler("simple-module-single-export.js", {
118 | exposes: "myGlobal",
119 | });
120 | const stats = await compile(compiler);
121 |
122 | expect(
123 | getModuleSource("./global-module-default-export-exposed.js", stats),
124 | ).toMatchSnapshot("module");
125 | expect(
126 | execute(readAsset("main.bundle.js", compiler, stats)),
127 | ).toMatchSnapshot("result");
128 | expect(getErrors(stats)).toMatchSnapshot("errors");
129 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
130 | });
131 |
132 | it("should work string config", async () => {
133 | const compiler = getCompiler("simple-module-named-export.js", {
134 | exposes: [
135 | "myGlobal_alias.globalObject6 globalObject6",
136 | "myGlobal_alias.globalObject7 globalObject7",
137 | "myGlobal_alias.default default",
138 | "myGlobal",
139 | "myOtherGlobal",
140 | ],
141 | });
142 | const stats = await compile(compiler);
143 |
144 | expect(
145 | getModuleSource("./global-module-named-exports-exposed.js", stats),
146 | ).toMatchSnapshot("module");
147 | expect(
148 | execute(readAsset("main.bundle.js", compiler, stats)),
149 | ).toMatchSnapshot("result");
150 | expect(getErrors(stats)).toMatchSnapshot("errors");
151 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
152 | });
153 |
154 | it("should work string config 2", async () => {
155 | const compiler = getCompiler("simple-module-named-export.js", {
156 | exposes: [
157 | "myGlobal_alias.globalObject6|globalObject6",
158 | "myGlobal_alias.globalObject7|globalObject7",
159 | "myGlobal_alias.default default",
160 | " myGlobal ",
161 | "myOtherGlobal",
162 | ],
163 | });
164 | const stats = await compile(compiler);
165 |
166 | expect(
167 | getModuleSource("./global-module-named-exports-exposed.js", stats),
168 | ).toMatchSnapshot("module");
169 | expect(
170 | execute(readAsset("main.bundle.js", compiler, stats)),
171 | ).toMatchSnapshot("result");
172 | expect(getErrors(stats)).toMatchSnapshot("errors");
173 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
174 | });
175 |
176 | it("should work object config", async () => {
177 | const compiler = getCompiler("simple-module-named-export.js", {
178 | exposes: {
179 | globalName: ["myGlobal.alias", "globalObject6"],
180 | moduleLocalName: "globalObject6",
181 | },
182 | });
183 | const stats = await compile(compiler);
184 |
185 | expect(
186 | getModuleSource("./global-module-named-exports-exposed.js", stats),
187 | ).toMatchSnapshot("module");
188 | expect(
189 | execute(readAsset("main.bundle.js", compiler, stats)),
190 | ).toMatchSnapshot("result");
191 | expect(stats.compilation.errors).toMatchSnapshot("errors");
192 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
193 | });
194 |
195 | it("should work multiple syntax to array", async () => {
196 | const compiler = getCompiler("simple-module-named-export.js", {
197 | exposes: [
198 | {
199 | globalName: ["myGlobal_alias", "globalObject6"],
200 | moduleLocalName: "globalObject6",
201 | },
202 | {
203 | globalName: ["myGlobal_alias", "globalObject7"],
204 | moduleLocalName: "globalObject7",
205 | },
206 | "myGlobal_alias.default default",
207 | ],
208 | });
209 | const stats = await compile(compiler);
210 |
211 | expect(
212 | getModuleSource("./global-module-named-exports-exposed.js", stats),
213 | ).toMatchSnapshot("module");
214 | expect(
215 | execute(readAsset("main.bundle.js", compiler, stats)),
216 | ).toMatchSnapshot("result");
217 | expect(getErrors(stats)).toMatchSnapshot("errors");
218 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
219 | });
220 |
221 | it("should be different modules id", async () => {
222 | const compiler = getCompiler("simple-module-named-export.js", {
223 | exposes: ["myGlobal_alias.default"],
224 | });
225 | const stats = await compile(compiler);
226 | const modules = getModulesList("./global-module-named-exports.js", stats);
227 |
228 | expect(modules[0]).not.toBe(modules[1]);
229 | expect(
230 | execute(readAsset("main.bundle.js", compiler, stats)),
231 | ).toMatchSnapshot("result");
232 | expect(getErrors(stats)).toMatchSnapshot("errors");
233 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
234 | });
235 |
236 | it("should work inline 1", async () => {
237 | const compiler = getCompiler(
238 | "inline-import.js",
239 | {},
240 | {
241 | devtool: "source-map",
242 | module: {
243 | rules: [
244 | {
245 | test: /.*custom\.js/i,
246 | use: [
247 | {
248 | loader: "babel-loader",
249 | },
250 | ],
251 | },
252 | ],
253 | },
254 | },
255 | );
256 | const stats = await compile(compiler);
257 |
258 | expect(
259 | getModuleSource("./custom-exposed.js?foo=bar", stats),
260 | ).toMatchSnapshot("module");
261 | expect(
262 | execute(readAsset("main.bundle.js", compiler, stats)),
263 | ).toMatchSnapshot("result");
264 | expect(readAsset("main.bundle.js.map", compiler, stats)).toBeDefined();
265 | expect(getErrors(stats)).toMatchSnapshot("errors");
266 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
267 | });
268 |
269 | it("should work inline 1 with config loader options", async () => {
270 | const compiler = getCompiler(
271 | "inline-import-equality.js",
272 | {},
273 | {
274 | devtool: "source-map",
275 | module: {
276 | rules: [
277 | {
278 | test: /.*global-commonjs2-single-export\.js/i,
279 | use: [
280 | {
281 | loader: "babel-loader",
282 | options: {
283 | presets: ["@babel/preset-env"],
284 | },
285 | },
286 | ],
287 | },
288 | ],
289 | },
290 | },
291 | );
292 | const stats = await compile(compiler);
293 | const refRegexp = /\?ruleSet\[\d+\].*!/;
294 |
295 | expect(
296 | getModuleSource(
297 | "./global-commonjs2-single-export-exposed.js",
298 | stats,
299 | ).replace(refRegexp, "?{{config-reference}}!"),
300 | ).toMatchSnapshot("module");
301 | expect(
302 | execute(readAsset("main.bundle.js", compiler, stats)),
303 | ).toMatchSnapshot("result");
304 | expect(readAsset("main.bundle.js.map", compiler, stats)).toBeDefined();
305 | expect(getErrors(stats)).toMatchSnapshot("errors");
306 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
307 | });
308 |
309 | it("should work inline 1 without extension", async () => {
310 | const compiler = getCompiler(
311 | "inline-import-1.js",
312 | {},
313 | {
314 | devtool: "source-map",
315 | module: {
316 | rules: [
317 | {
318 | test: /.*custom/i,
319 | use: [
320 | {
321 | loader: "babel-loader",
322 | },
323 | ],
324 | },
325 | ],
326 | },
327 | },
328 | );
329 | const stats = await compile(compiler);
330 |
331 | expect(getModuleSource("./custom-exposed?foo=bar", stats)).toMatchSnapshot(
332 | "module",
333 | );
334 | expect(
335 | execute(readAsset("main.bundle.js", compiler, stats)),
336 | ).toMatchSnapshot("result");
337 | expect(readAsset("main.bundle.js.map", compiler, stats)).toBeDefined();
338 | expect(getErrors(stats)).toMatchSnapshot("errors");
339 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
340 | });
341 |
342 | it("should work inline 2", async () => {
343 | const compiler = getCompiler(
344 | "inline-import-2.js",
345 | {},
346 | {
347 | module: {},
348 | },
349 | );
350 | const stats = await compile(compiler);
351 |
352 | expect(
353 | getModuleSource("./simple-commonjs2-single-export-exposed.js", stats),
354 | ).toMatchSnapshot("module");
355 | expect(
356 | execute(readAsset("main.bundle.js", compiler, stats)),
357 | ).toMatchSnapshot("result");
358 | expect(readAsset("main.bundle.js.map", compiler, stats)).toBeDefined();
359 | expect(getErrors(stats)).toMatchSnapshot("errors");
360 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
361 | });
362 |
363 | it("should match hashes on all operating systems", async () => {
364 | const compiler = getCompiler(
365 | "inline-import-2.js",
366 | {},
367 | {
368 | output: {
369 | path: path.resolve(__dirname, "./outputs"),
370 | filename: "[name]-[contenthash:8].bundle.js",
371 | chunkFilename: "[name]-[contenthash:8].chunk.js",
372 | library: "ExposeLoader",
373 | libraryTarget: "var",
374 | },
375 | module: {},
376 | },
377 | );
378 | const stats = await compile(compiler);
379 | const { chunkGraph } = stats.compilation;
380 |
381 | const module = [...stats.compilation.modules].find((m) =>
382 | chunkGraph
383 | .getModuleId(m)
384 | .endsWith("./simple-commonjs2-single-export-exposed.js"),
385 | );
386 |
387 | expect(
388 | getModuleSource("./simple-commonjs2-single-export-exposed.js", stats),
389 | ).toMatchSnapshot("module");
390 | expect(chunkGraph.getModuleHash(module)).toBe(
391 | "7111ce88139ab205418819625caf632f",
392 | );
393 | expect(getErrors(stats)).toMatchSnapshot("errors");
394 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
395 | });
396 |
397 | it("should emit error because of many arguments", async () => {
398 | const compiler = getCompiler("simple-module-named-export.js", {
399 | exposes: ["myGlobal_alias globalObject6 excessArgument"],
400 | });
401 | const stats = await compile(compiler);
402 |
403 | expect(getErrors(stats)).toMatchSnapshot("errors");
404 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
405 | });
406 |
407 | it("should emit error because of invalid arguments", async () => {
408 | const compiler = getCompiler("simple-module-named-export.js", {
409 | exposes: ["myGlobal_alias | globalObject6"],
410 | });
411 | const stats = await compile(compiler);
412 |
413 | expect(getErrors(stats)).toMatchSnapshot("errors");
414 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
415 | });
416 |
417 | it("should work interpolate", async () => {
418 | const compiler = getCompiler("simple-commonjs2-single-export.js", {
419 | exposes: ["[name]", "myGlobal.[name]"],
420 | });
421 | const stats = await compile(compiler);
422 |
423 | expect(
424 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
425 | ).toMatchSnapshot("module");
426 | expect(
427 | execute(readAsset("main.bundle.js", compiler, stats)),
428 | ).toMatchSnapshot("result");
429 | expect(getErrors(stats)).toMatchSnapshot("errors");
430 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
431 | });
432 |
433 | it('should throw an error on existing value in the global object in the "development" mode', async () => {
434 | const compiler = getCompiler(
435 | "override-1.js",
436 | {
437 | exposes: {
438 | globalName: ["myGlobal"],
439 | override: false,
440 | },
441 | },
442 | {
443 | mode: "development",
444 | },
445 | );
446 | const stats = await compile(compiler);
447 |
448 | expect(
449 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
450 | ).toMatchSnapshot("module");
451 | expect(() =>
452 | execute(readAsset("main.bundle.js", compiler, stats)),
453 | ).toThrowErrorMatchingSnapshot("runtime error");
454 | expect(getErrors(stats)).toMatchSnapshot("errors");
455 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
456 | });
457 |
458 | it('should not override existing value in the global object in the "production" mode', async () => {
459 | const compiler = getCompiler(
460 | "override-1.js",
461 | {
462 | exposes: {
463 | globalName: ["myGlobal"],
464 | },
465 | },
466 | {
467 | mode: "production",
468 | },
469 | );
470 | const stats = await compile(compiler);
471 |
472 | expect(
473 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
474 | ).toMatchSnapshot("module");
475 | expect(
476 | execute(readAsset("main.bundle.js", compiler, stats)),
477 | ).toMatchSnapshot("result");
478 | expect(getErrors(stats)).toMatchSnapshot("errors");
479 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
480 | });
481 |
482 | it('should work and override existing value in the global object in the "development" mode', async () => {
483 | const compiler = getCompiler(
484 | "override-1.js",
485 | {
486 | exposes: {
487 | globalName: ["myGlobal"],
488 | override: true,
489 | },
490 | },
491 | {
492 | mode: "development",
493 | },
494 | );
495 | const stats = await compile(compiler);
496 |
497 | expect(
498 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
499 | ).toMatchSnapshot("module");
500 | expect(
501 | execute(readAsset("main.bundle.js", compiler, stats)),
502 | ).toMatchSnapshot("result");
503 | expect(getErrors(stats)).toMatchSnapshot("errors");
504 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
505 | });
506 |
507 | it('should work and override existing value in the global object in the "production" mode', async () => {
508 | const compiler = getCompiler(
509 | "override-1.js",
510 | {
511 | exposes: {
512 | globalName: ["myGlobal"],
513 | override: true,
514 | },
515 | },
516 | {
517 | mode: "production",
518 | },
519 | );
520 | const stats = await compile(compiler);
521 |
522 | expect(
523 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
524 | ).toMatchSnapshot("module");
525 | expect(
526 | execute(readAsset("main.bundle.js", compiler, stats)),
527 | ).toMatchSnapshot("result");
528 | expect(getErrors(stats)).toMatchSnapshot("errors");
529 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
530 | });
531 |
532 | it("should throw an error on existing module local value in the global object", async () => {
533 | const compiler = getCompiler(
534 | "override-1.js",
535 | {
536 | exposes: {
537 | moduleLocalName: "foo",
538 | globalName: ["myGlobal"],
539 | override: false,
540 | },
541 | },
542 | {
543 | mode: "development",
544 | },
545 | );
546 | const stats = await compile(compiler);
547 |
548 | expect(
549 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
550 | ).toMatchSnapshot("module");
551 | expect(() =>
552 | execute(readAsset("main.bundle.js", compiler, stats)),
553 | ).toThrowErrorMatchingSnapshot("runtime error");
554 | expect(getErrors(stats)).toMatchSnapshot("errors");
555 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
556 | });
557 |
558 | it("should work and override existing module local value in the global object", async () => {
559 | const compiler = getCompiler(
560 | "override-1.js",
561 | {
562 | exposes: {
563 | moduleLocalName: "foo",
564 | globalName: ["myGlobal"],
565 | override: true,
566 | },
567 | },
568 | {
569 | mode: "development",
570 | },
571 | );
572 | const stats = await compile(compiler);
573 |
574 | expect(
575 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
576 | ).toMatchSnapshot("module");
577 | expect(
578 | execute(readAsset("main.bundle.js", compiler, stats)),
579 | ).toMatchSnapshot("result");
580 | expect(getErrors(stats)).toMatchSnapshot("errors");
581 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
582 | });
583 |
584 | it("should throw an error on existing nested value in the global object", async () => {
585 | const compiler = getCompiler(
586 | "override-1.js",
587 | {
588 | exposes: {
589 | globalName: ["myOtherGlobal", "foo", "bar", "bar"],
590 | override: false,
591 | },
592 | },
593 | {
594 | mode: "development",
595 | },
596 | );
597 | const stats = await compile(compiler);
598 |
599 | expect(
600 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
601 | ).toMatchSnapshot("module");
602 | expect(() => execute(readAsset("main.bundle.js", compiler, stats))).toThrow(
603 | /Cannot read/,
604 | );
605 | expect(getErrors(stats)).toMatchSnapshot("errors");
606 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
607 | });
608 |
609 | it("should work and override existing nested value in the global object", async () => {
610 | const compiler = getCompiler(
611 | "override-1.js",
612 | {
613 | exposes: {
614 | globalName: ["myOtherGlobal", "foo"],
615 | override: true,
616 | },
617 | },
618 | {
619 | mode: "development",
620 | },
621 | );
622 | const stats = await compile(compiler);
623 |
624 | expect(
625 | getModuleSource("./global-commonjs2-single-export-exposed.js", stats),
626 | ).toMatchSnapshot("module");
627 | expect(
628 | execute(readAsset("main.bundle.js", compiler, stats)),
629 | ).toMatchSnapshot("result");
630 | expect(getErrors(stats)).toMatchSnapshot("errors");
631 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
632 | });
633 |
634 | it("should work with CommonJS format when module in CommonJS format", async () => {
635 | const compiler = getCompiler("loader-commonjs-with-commonjs.js", {
636 | exposes: "myGlobal",
637 | });
638 | const stats = await compile(compiler);
639 |
640 | expect(
641 | getModuleSource("./global-module-commonjs-exposed.js", stats),
642 | ).toMatchSnapshot("module");
643 | expect(
644 | execute(readAsset("main.bundle.js", compiler, stats)),
645 | ).toMatchSnapshot("result");
646 | expect(getErrors(stats)).toMatchSnapshot("errors");
647 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
648 | });
649 |
650 | it("should work with CommonJS module format when module in ES module format", async () => {
651 | const compiler = getCompiler("loader-commonjs-with-es.js", {
652 | exposes: "myGlobal",
653 | });
654 | const stats = await compile(compiler);
655 |
656 | expect(
657 | getModuleSource("./global-module-es-exposed.js", stats),
658 | ).toMatchSnapshot("module");
659 | expect(
660 | execute(readAsset("main.bundle.js", compiler, stats)),
661 | ).toMatchSnapshot("result");
662 | expect(getErrors(stats)).toMatchSnapshot("errors");
663 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
664 | });
665 |
666 | it("should work with ES module format when module in CommonJS format", async () => {
667 | const compiler = getCompiler("loader-es-with-commonjs.js", {
668 | exposes: "myGlobal",
669 | });
670 | const stats = await compile(compiler);
671 |
672 | expect(
673 | getModuleSource("./global-module-commonjs-exposed.js", stats),
674 | ).toMatchSnapshot("module");
675 | expect(
676 | execute(readAsset("main.bundle.js", compiler, stats)),
677 | ).toMatchSnapshot("result");
678 | expect(getErrors(stats)).toMatchSnapshot("errors");
679 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
680 | });
681 |
682 | it("should work with ES module format when module in ES format", async () => {
683 | const compiler = getCompiler("loader-es-with-es.js", {
684 | exposes: "myGlobal",
685 | });
686 | const stats = await compile(compiler);
687 |
688 | expect(
689 | getModuleSource("./global-module-es-exposed.js", stats),
690 | ).toMatchSnapshot("module");
691 | expect(
692 | execute(readAsset("main.bundle.js", compiler, stats)),
693 | ).toMatchSnapshot("result");
694 | expect(getErrors(stats)).toMatchSnapshot("errors");
695 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
696 | });
697 |
698 | it("should work with ES module format when module in ES format without default", async () => {
699 | const compiler = getCompiler("loader-es-with-es-without-default.js", {
700 | exposes: "myGlobal",
701 | });
702 | const stats = await compile(compiler);
703 |
704 | expect(
705 | getModuleSource("./global-module-es-without-default-exposed.js", stats),
706 | ).toMatchSnapshot("module");
707 | expect(
708 | execute(readAsset("main.bundle.js", compiler, stats)),
709 | ).toMatchSnapshot("result");
710 | expect(getErrors(stats)).toMatchSnapshot("errors");
711 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
712 | });
713 |
714 | it("should work with side-effects free modules", async () => {
715 | const compiler = getCompiler(
716 | "side-effects.js",
717 | {
718 | exposes: "myGlobal",
719 | },
720 | {
721 | mode: "production",
722 | },
723 | );
724 | const stats = await compile(compiler);
725 |
726 | expect(getModuleSource("rx.all-exposed.js", stats)).toMatchSnapshot(
727 | "module",
728 | );
729 | expect(
730 | execute(readAsset("main.bundle.js", compiler, stats)),
731 | ).toMatchSnapshot("result");
732 | expect(getErrors(stats)).toMatchSnapshot("errors");
733 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
734 | });
735 |
736 | it("should work with side-effects free modules #1", async () => {
737 | const compiler = getCompiler(
738 | "side-effects-1.js",
739 | {
740 | exposes: "styled",
741 | },
742 | {
743 | mode: "production",
744 | },
745 | );
746 | const stats = await compile(compiler);
747 |
748 | expect(
749 | execute(readAsset("main.bundle.js", compiler, stats)),
750 | ).toMatchSnapshot("result");
751 | expect(getErrors(stats)).toMatchSnapshot("errors");
752 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
753 | });
754 |
755 | it("should throw an error on invalid exposed value", async () => {
756 | const compiler = getCompiler("simple-commonjs2-single-export.js", {
757 | exposes: "myGlobal foo bar baz",
758 | });
759 | const stats = await compile(compiler);
760 |
761 | expect(getErrors(stats)).toMatchSnapshot("errors");
762 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
763 | });
764 |
765 | it("should work with globalObject", async () => {
766 | const compiler = getCompiler("global-module-es.js", {
767 | exposes: {
768 | globalName: "FOO",
769 | moduleLocalName: "default",
770 | },
771 | globalObject: "this",
772 | });
773 | const stats = await compile(compiler);
774 |
775 | expect(readAsset("main.bundle.js", compiler, stats)).toContain(
776 | "var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = this;\n",
777 | );
778 |
779 | expect(getErrors(stats)).toMatchSnapshot("errors");
780 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
781 | });
782 | });
783 |
--------------------------------------------------------------------------------
/test/__snapshots__/loader.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2 |
3 | exports[`loader should be different modules id: errors 1`] = `[]`;
4 |
5 | exports[`loader should be different modules id: result 1`] = `
6 | {
7 | "ExposeLoader": {
8 | "default": {
9 | "default": [Function],
10 | "globalObject6": {
11 | "foo": "bar",
12 | },
13 | "globalObject7": {
14 | "bar": "foo",
15 | },
16 | },
17 | },
18 | "myGlobal_alias": {
19 | "default": {
20 | "default": [Function],
21 | "globalObject6": {
22 | "foo": "bar",
23 | },
24 | "globalObject7": {
25 | "bar": "foo",
26 | },
27 | },
28 | },
29 | }
30 | `;
31 |
32 | exports[`loader should be different modules id: warnings 1`] = `[]`;
33 |
34 | exports[`loader should emit error because of invalid arguments: errors 1`] = `
35 | [
36 | "ModuleBuildError: Module build failed (from \`replaced original path\`):
37 | Error: Invalid command "" in "myGlobal_alias | globalObject6" for expose. There must be only one separator: " ", or "|".",
38 | ]
39 | `;
40 |
41 | exports[`loader should emit error because of invalid arguments: warnings 1`] = `[]`;
42 |
43 | exports[`loader should emit error because of many arguments: errors 1`] = `[]`;
44 |
45 | exports[`loader should emit error because of many arguments: warnings 1`] = `[]`;
46 |
47 | exports[`loader should match hashes on all operating systems: errors 1`] = `[]`;
48 |
49 | exports[`loader should match hashes on all operating systems: module 1`] = `
50 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./simple-commonjs2-single-export.js");
51 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
52 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
53 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
54 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
55 | module.exports = ___EXPOSE_LOADER_IMPORT___;
56 | "
57 | `;
58 |
59 | exports[`loader should match hashes on all operating systems: warnings 1`] = `[]`;
60 |
61 | exports[`loader should not override existing value in the global object in the "production" mode: errors 1`] = `[]`;
62 |
63 | exports[`loader should not override existing value in the global object in the "production" mode: module 1`] = `
64 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
65 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
66 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
67 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
68 | module.exports = ___EXPOSE_LOADER_IMPORT___;
69 | "
70 | `;
71 |
72 | exports[`loader should not override existing value in the global object in the "production" mode: result 1`] = `
73 | {
74 | "ExposeLoader": "no exports",
75 | "global-commonjs2-single-export": {
76 | "foo": "bar",
77 | },
78 | "myGlobal": "not overridden",
79 | "myOtherGlobal": {
80 | "foo": "not overridden",
81 | },
82 | }
83 | `;
84 |
85 | exports[`loader should not override existing value in the global object in the "production" mode: warnings 1`] = `[]`;
86 |
87 | exports[`loader should throw an error on existing module local value in the global object: errors 1`] = `[]`;
88 |
89 | exports[`loader should throw an error on existing module local value in the global object: module 1`] = `
90 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
91 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
92 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
93 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.foo
94 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
95 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
96 | module.exports = ___EXPOSE_LOADER_IMPORT___;
97 | "
98 | `;
99 |
100 | exports[`loader should throw an error on existing module local value in the global object: runtime error 1`] = `"[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option"`;
101 |
102 | exports[`loader should throw an error on existing module local value in the global object: warnings 1`] = `[]`;
103 |
104 | exports[`loader should throw an error on existing nested value in the global object: errors 1`] = `[]`;
105 |
106 | exports[`loader should throw an error on existing nested value in the global object: module 1`] = `
107 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
108 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
109 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
110 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] = {};
111 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["foo"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["foo"] = {};
112 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["foo"]["bar"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["foo"]["bar"] = {};
113 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["foo"]["bar"]["bar"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["foo"]["bar"]["bar"] = ___EXPOSE_LOADER_IMPORT___;
114 | else throw new Error('[expose-loader] The "myOtherGlobal.foo.bar.bar" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
115 | module.exports = ___EXPOSE_LOADER_IMPORT___;
116 | "
117 | `;
118 |
119 | exports[`loader should throw an error on existing nested value in the global object: warnings 1`] = `[]`;
120 |
121 | exports[`loader should throw an error on existing value in the global object in the "development" mode: errors 1`] = `[]`;
122 |
123 | exports[`loader should throw an error on existing value in the global object in the "development" mode: module 1`] = `
124 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
125 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
126 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
127 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
128 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
129 | module.exports = ___EXPOSE_LOADER_IMPORT___;
130 | "
131 | `;
132 |
133 | exports[`loader should throw an error on existing value in the global object in the "development" mode: runtime error 1`] = `"[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option"`;
134 |
135 | exports[`loader should throw an error on existing value in the global object in the "development" mode: warnings 1`] = `[]`;
136 |
137 | exports[`loader should throw an error on invalid exposed value: errors 1`] = `
138 | [
139 | "ModuleBuildError: Module build failed (from \`replaced original path\`):
140 | Error: Invalid "myGlobal foo bar baz" for exposes",
141 | ]
142 | `;
143 |
144 | exports[`loader should throw an error on invalid exposed value: warnings 1`] = `[]`;
145 |
146 | exports[`loader should work and override existing module local value in the global object: errors 1`] = `[]`;
147 |
148 | exports[`loader should work and override existing module local value in the global object: module 1`] = `
149 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
150 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
151 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
152 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.foo
153 | ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
154 | module.exports = ___EXPOSE_LOADER_IMPORT___;
155 | "
156 | `;
157 |
158 | exports[`loader should work and override existing module local value in the global object: result 1`] = `
159 | {
160 | "ExposeLoader": "no exports",
161 | "global-commonjs2-single-export": {
162 | "foo": "bar",
163 | },
164 | "myGlobal": "bar",
165 | "myOtherGlobal": {
166 | "foo": "not overridden",
167 | },
168 | }
169 | `;
170 |
171 | exports[`loader should work and override existing module local value in the global object: warnings 1`] = `[]`;
172 |
173 | exports[`loader should work and override existing nested value in the global object: errors 1`] = `[]`;
174 |
175 | exports[`loader should work and override existing nested value in the global object: module 1`] = `
176 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
177 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
178 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
179 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] = {};
180 | ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["foo"] = ___EXPOSE_LOADER_IMPORT___;
181 | module.exports = ___EXPOSE_LOADER_IMPORT___;
182 | "
183 | `;
184 |
185 | exports[`loader should work and override existing nested value in the global object: result 1`] = `
186 | {
187 | "ExposeLoader": "no exports",
188 | "global-commonjs2-single-export": {
189 | "foo": "bar",
190 | },
191 | "myGlobal": "not overridden",
192 | "myOtherGlobal": {
193 | "foo": {
194 | "foo": "bar",
195 | },
196 | },
197 | }
198 | `;
199 |
200 | exports[`loader should work and override existing nested value in the global object: warnings 1`] = `[]`;
201 |
202 | exports[`loader should work and override existing value in the global object in the "development" mode: errors 1`] = `[]`;
203 |
204 | exports[`loader should work and override existing value in the global object in the "development" mode: module 1`] = `
205 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
206 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
207 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
208 | ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
209 | module.exports = ___EXPOSE_LOADER_IMPORT___;
210 | "
211 | `;
212 |
213 | exports[`loader should work and override existing value in the global object in the "development" mode: result 1`] = `
214 | {
215 | "ExposeLoader": "no exports",
216 | "global-commonjs2-single-export": {
217 | "foo": "bar",
218 | },
219 | "myGlobal": {
220 | "foo": "bar",
221 | },
222 | "myOtherGlobal": {
223 | "foo": "not overridden",
224 | },
225 | }
226 | `;
227 |
228 | exports[`loader should work and override existing value in the global object in the "development" mode: warnings 1`] = `[]`;
229 |
230 | exports[`loader should work and override existing value in the global object in the "production" mode: errors 1`] = `[]`;
231 |
232 | exports[`loader should work and override existing value in the global object in the "production" mode: module 1`] = `
233 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
234 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
235 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
236 | ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
237 | module.exports = ___EXPOSE_LOADER_IMPORT___;
238 | "
239 | `;
240 |
241 | exports[`loader should work and override existing value in the global object in the "production" mode: result 1`] = `
242 | {
243 | "ExposeLoader": "no exports",
244 | "global-commonjs2-single-export": {
245 | "foo": "bar",
246 | },
247 | "myGlobal": {
248 | "foo": "bar",
249 | },
250 | "myOtherGlobal": {
251 | "foo": "not overridden",
252 | },
253 | }
254 | `;
255 |
256 | exports[`loader should work and override existing value in the global object in the "production" mode: warnings 1`] = `[]`;
257 |
258 | exports[`loader should work for a nested property for a global object: errors 1`] = `[]`;
259 |
260 | exports[`loader should work for a nested property for a global object: module 1`] = `
261 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
262 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
263 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
264 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = {};
265 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"]["nested"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"]["nested"] = ___EXPOSE_LOADER_IMPORT___;
266 | else throw new Error('[expose-loader] The "myGlobal.nested" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
267 | module.exports = ___EXPOSE_LOADER_IMPORT___;
268 | "
269 | `;
270 |
271 | exports[`loader should work for a nested property for a global object: result 1`] = `
272 | {
273 | "ExposeLoader": {
274 | "foo": "bar",
275 | },
276 | "myGlobal": {
277 | "nested": {
278 | "foo": "bar",
279 | },
280 | },
281 | }
282 | `;
283 |
284 | exports[`loader should work for a nested property for a global object: warnings 1`] = `[]`;
285 |
286 | exports[`loader should work for nested properties for a global object: errors 1`] = `[]`;
287 |
288 | exports[`loader should work for nested properties for a global object: module 1`] = `
289 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
290 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
291 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
292 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = {};
293 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"]["nested"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"]["nested"] = ___EXPOSE_LOADER_IMPORT___;
294 | else throw new Error('[expose-loader] The "myGlobal.nested" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
295 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.foo
296 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] = {};
297 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["nested"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"]["nested"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
298 | else throw new Error('[expose-loader] The "myOtherGlobal.nested" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
299 | module.exports = ___EXPOSE_LOADER_IMPORT___;
300 | "
301 | `;
302 |
303 | exports[`loader should work for nested properties for a global object: result 1`] = `
304 | {
305 | "ExposeLoader": {
306 | "foo": "bar",
307 | },
308 | "myGlobal": {
309 | "nested": {
310 | "foo": "bar",
311 | },
312 | },
313 | "myOtherGlobal": {
314 | "nested": "bar",
315 | },
316 | }
317 | `;
318 |
319 | exports[`loader should work for nested properties for a global object: warnings 1`] = `[]`;
320 |
321 | exports[`loader should work from esModule export: errors 1`] = `[]`;
322 |
323 | exports[`loader should work from esModule export: module 1`] = `
324 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-default-export.js");
325 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
326 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
327 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
328 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
329 | module.exports = ___EXPOSE_LOADER_IMPORT___;
330 | "
331 | `;
332 |
333 | exports[`loader should work from esModule export: result 1`] = `
334 | {
335 | "ExposeLoader": {
336 | "default": {
337 | "foo": "bar",
338 | },
339 | },
340 | "myGlobal": {
341 | "default": {
342 | "foo": "bar",
343 | },
344 | },
345 | }
346 | `;
347 |
348 | exports[`loader should work from esModule export: warnings 1`] = `[]`;
349 |
350 | exports[`loader should work inline 1 with config loader options: errors 1`] = `[]`;
351 |
352 | exports[`loader should work inline 1 with config loader options: module 1`] = `
353 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!../../node_modules/babel-loader/lib/index.js??{{config-reference}}!./global-commonjs2-single-export.js");
354 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
355 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
356 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
357 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
358 | module.exports = ___EXPOSE_LOADER_IMPORT___;
359 | "
360 | `;
361 |
362 | exports[`loader should work inline 1 with config loader options: result 1`] = `
363 | {
364 | "ExposeLoader": {
365 | "default": {
366 | "exposedEqualsGlobal": true,
367 | "exposedEqualsImported": true,
368 | "importedEqualsGlobal": true,
369 | },
370 | },
371 | "myGlobal": {
372 | "foo": "bar",
373 | },
374 | }
375 | `;
376 |
377 | exports[`loader should work inline 1 with config loader options: warnings 1`] = `[]`;
378 |
379 | exports[`loader should work inline 1 without extension: errors 1`] = `[]`;
380 |
381 | exports[`loader should work inline 1 without extension: module 1`] = `
382 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!../../node_modules/babel-loader/lib/index.js!./custom?foo=bar");
383 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
384 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
385 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.default
386 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
387 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
388 | module.exports = ___EXPOSE_LOADER_IMPORT___;
389 | "
390 | `;
391 |
392 | exports[`loader should work inline 1 without extension: result 1`] = `
393 | {
394 | "ExposeLoader": {
395 | "default": "Tokyo",
396 | },
397 | "myGlobal": "Tokyo",
398 | }
399 | `;
400 |
401 | exports[`loader should work inline 1 without extension: warnings 1`] = `[]`;
402 |
403 | exports[`loader should work inline 1: errors 1`] = `[]`;
404 |
405 | exports[`loader should work inline 1: module 1`] = `
406 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!../../node_modules/babel-loader/lib/index.js!./custom.js?foo=bar");
407 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
408 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
409 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.default
410 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
411 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
412 | module.exports = ___EXPOSE_LOADER_IMPORT___;
413 | "
414 | `;
415 |
416 | exports[`loader should work inline 1: result 1`] = `
417 | {
418 | "ExposeLoader": {
419 | "default": "Tokyo",
420 | },
421 | "myGlobal": "Tokyo",
422 | }
423 | `;
424 |
425 | exports[`loader should work inline 1: warnings 1`] = `[]`;
426 |
427 | exports[`loader should work inline 2: errors 1`] = `[]`;
428 |
429 | exports[`loader should work inline 2: module 1`] = `
430 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./simple-commonjs2-single-export.js");
431 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
432 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
433 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
434 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
435 | module.exports = ___EXPOSE_LOADER_IMPORT___;
436 | "
437 | `;
438 |
439 | exports[`loader should work inline 2: result 1`] = `
440 | {
441 | "ExposeLoader": {
442 | "myExports": {
443 | "foo": "bar",
444 | },
445 | "myExports2": {
446 | "globalObject2": {
447 | "foo": "bar",
448 | },
449 | "globalObject3": {
450 | "bar": "foo",
451 | },
452 | },
453 | },
454 | "myGlobal": {
455 | "foo": "bar",
456 | },
457 | "myOtherGlobal": {
458 | "globalObject2": {
459 | "foo": "bar",
460 | },
461 | "globalObject3": {
462 | "bar": "foo",
463 | },
464 | },
465 | }
466 | `;
467 |
468 | exports[`loader should work inline 2: warnings 1`] = `[]`;
469 |
470 | exports[`loader should work interpolate: errors 1`] = `[]`;
471 |
472 | exports[`loader should work interpolate: module 1`] = `
473 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
474 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
475 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
476 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["global-commonjs2-single-export"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["global-commonjs2-single-export"] = ___EXPOSE_LOADER_IMPORT___;
477 | else throw new Error('[expose-loader] The "[name]" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
478 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = {};
479 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"]["global-commonjs2-single-export"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"]["global-commonjs2-single-export"] = ___EXPOSE_LOADER_IMPORT___;
480 | else throw new Error('[expose-loader] The "myGlobal.[name]" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
481 | module.exports = ___EXPOSE_LOADER_IMPORT___;
482 | "
483 | `;
484 |
485 | exports[`loader should work interpolate: result 1`] = `
486 | {
487 | "ExposeLoader": {
488 | "foo": "bar",
489 | },
490 | "global-commonjs2-single-export": {
491 | "foo": "bar",
492 | },
493 | "myGlobal": {
494 | "global-commonjs2-single-export": {
495 | "foo": "bar",
496 | },
497 | },
498 | }
499 | `;
500 |
501 | exports[`loader should work interpolate: warnings 1`] = `[]`;
502 |
503 | exports[`loader should work multiple commonjs exports: errors 1`] = `[]`;
504 |
505 | exports[`loader should work multiple commonjs exports: module 1`] = `
506 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-multiple-exports.js");
507 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
508 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
509 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] = ___EXPOSE_LOADER_IMPORT___;
510 | else throw new Error('[expose-loader] The "myOtherGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
511 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.globalObject2
512 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = {};
513 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"]["globalObject2"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"]["globalObject2"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
514 | else throw new Error('[expose-loader] The "myGlobal.globalObject2" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
515 | module.exports = ___EXPOSE_LOADER_IMPORT___;
516 | "
517 | `;
518 |
519 | exports[`loader should work multiple commonjs exports: result 1`] = `
520 | {
521 | "ExposeLoader": {
522 | "globalObject2": {
523 | "foo": "bar",
524 | },
525 | "globalObject3": {
526 | "bar": "foo",
527 | },
528 | },
529 | "myGlobal": {
530 | "globalObject2": {
531 | "foo": "bar",
532 | },
533 | },
534 | "myOtherGlobal": {
535 | "globalObject2": {
536 | "foo": "bar",
537 | },
538 | "globalObject3": {
539 | "bar": "foo",
540 | },
541 | },
542 | }
543 | `;
544 |
545 | exports[`loader should work multiple commonjs exports: warnings 1`] = `[]`;
546 |
547 | exports[`loader should work multiple syntax to array: errors 1`] = `[]`;
548 |
549 | exports[`loader should work multiple syntax to array: module 1`] = `
550 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-named-exports.js");
551 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
552 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
553 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.globalObject6
554 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
555 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject6"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject6"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
556 | else throw new Error('[expose-loader] The "myGlobal_alias.globalObject6" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
557 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.globalObject7
558 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
559 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject7"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject7"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
560 | else throw new Error('[expose-loader] The "myGlobal_alias.globalObject7" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
561 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.default
562 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
563 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["default"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["default"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
564 | else throw new Error('[expose-loader] The "myGlobal_alias.default" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
565 | module.exports = ___EXPOSE_LOADER_IMPORT___;
566 | "
567 | `;
568 |
569 | exports[`loader should work multiple syntax to array: result 1`] = `
570 | {
571 | "ExposeLoader": {
572 | "default": {
573 | "default": [Function],
574 | "globalObject6": {
575 | "foo": "bar",
576 | },
577 | "globalObject7": {
578 | "bar": "foo",
579 | },
580 | },
581 | },
582 | "myGlobal_alias": {
583 | "default": [Function],
584 | "globalObject6": {
585 | "foo": "bar",
586 | },
587 | "globalObject7": {
588 | "bar": "foo",
589 | },
590 | },
591 | }
592 | `;
593 |
594 | exports[`loader should work multiple syntax to array: warnings 1`] = `[]`;
595 |
596 | exports[`loader should work object config: errors 1`] = `[]`;
597 |
598 | exports[`loader should work object config: module 1`] = `
599 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-named-exports.js");
600 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
601 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
602 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.globalObject6
603 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal.alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal.alias"] = {};
604 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal.alias"]["globalObject6"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal.alias"]["globalObject6"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
605 | else throw new Error('[expose-loader] The "myGlobal.alias.globalObject6" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
606 | module.exports = ___EXPOSE_LOADER_IMPORT___;
607 | "
608 | `;
609 |
610 | exports[`loader should work object config: result 1`] = `
611 | {
612 | "ExposeLoader": {
613 | "default": {
614 | "default": [Function],
615 | "globalObject6": {
616 | "foo": "bar",
617 | },
618 | "globalObject7": {
619 | "bar": "foo",
620 | },
621 | },
622 | },
623 | "myGlobal.alias": {
624 | "globalObject6": {
625 | "foo": "bar",
626 | },
627 | },
628 | }
629 | `;
630 |
631 | exports[`loader should work object config: warnings 1`] = `[]`;
632 |
633 | exports[`loader should work string config 2: errors 1`] = `[]`;
634 |
635 | exports[`loader should work string config 2: module 1`] = `
636 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-named-exports.js");
637 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
638 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
639 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.globalObject6
640 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
641 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject6"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject6"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
642 | else throw new Error('[expose-loader] The "myGlobal_alias.globalObject6" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
643 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.globalObject7
644 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
645 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject7"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject7"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
646 | else throw new Error('[expose-loader] The "myGlobal_alias.globalObject7" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
647 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.default
648 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
649 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["default"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["default"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
650 | else throw new Error('[expose-loader] The "myGlobal_alias.default" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
651 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
652 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
653 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] = ___EXPOSE_LOADER_IMPORT___;
654 | else throw new Error('[expose-loader] The "myOtherGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
655 | module.exports = ___EXPOSE_LOADER_IMPORT___;
656 | "
657 | `;
658 |
659 | exports[`loader should work string config 2: result 1`] = `
660 | {
661 | "ExposeLoader": {
662 | "default": {
663 | "default": [Function],
664 | "globalObject6": {
665 | "foo": "bar",
666 | },
667 | "globalObject7": {
668 | "bar": "foo",
669 | },
670 | },
671 | },
672 | "myGlobal": {
673 | "default": [Function],
674 | "globalObject6": {
675 | "foo": "bar",
676 | },
677 | "globalObject7": {
678 | "bar": "foo",
679 | },
680 | },
681 | "myGlobal_alias": {
682 | "default": [Function],
683 | "globalObject6": {
684 | "foo": "bar",
685 | },
686 | "globalObject7": {
687 | "bar": "foo",
688 | },
689 | },
690 | "myOtherGlobal": {
691 | "default": [Function],
692 | "globalObject6": {
693 | "foo": "bar",
694 | },
695 | "globalObject7": {
696 | "bar": "foo",
697 | },
698 | },
699 | }
700 | `;
701 |
702 | exports[`loader should work string config 2: warnings 1`] = `[]`;
703 |
704 | exports[`loader should work string config: errors 1`] = `[]`;
705 |
706 | exports[`loader should work string config: module 1`] = `
707 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-named-exports.js");
708 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
709 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
710 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.globalObject6
711 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
712 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject6"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject6"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
713 | else throw new Error('[expose-loader] The "myGlobal_alias.globalObject6" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
714 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.globalObject7
715 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
716 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject7"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["globalObject7"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
717 | else throw new Error('[expose-loader] The "myGlobal_alias.globalObject7" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
718 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.default
719 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"] = {};
720 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["default"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal_alias"]["default"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
721 | else throw new Error('[expose-loader] The "myGlobal_alias.default" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
722 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
723 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
724 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] = ___EXPOSE_LOADER_IMPORT___;
725 | else throw new Error('[expose-loader] The "myOtherGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
726 | module.exports = ___EXPOSE_LOADER_IMPORT___;
727 | "
728 | `;
729 |
730 | exports[`loader should work string config: result 1`] = `
731 | {
732 | "ExposeLoader": {
733 | "default": {
734 | "default": [Function],
735 | "globalObject6": {
736 | "foo": "bar",
737 | },
738 | "globalObject7": {
739 | "bar": "foo",
740 | },
741 | },
742 | },
743 | "myGlobal": {
744 | "default": [Function],
745 | "globalObject6": {
746 | "foo": "bar",
747 | },
748 | "globalObject7": {
749 | "bar": "foo",
750 | },
751 | },
752 | "myGlobal_alias": {
753 | "default": [Function],
754 | "globalObject6": {
755 | "foo": "bar",
756 | },
757 | "globalObject7": {
758 | "bar": "foo",
759 | },
760 | },
761 | "myOtherGlobal": {
762 | "default": [Function],
763 | "globalObject6": {
764 | "foo": "bar",
765 | },
766 | "globalObject7": {
767 | "bar": "foo",
768 | },
769 | },
770 | }
771 | `;
772 |
773 | exports[`loader should work string config: warnings 1`] = `[]`;
774 |
775 | exports[`loader should work with "moduleLocalName": errors 1`] = `[]`;
776 |
777 | exports[`loader should work with "moduleLocalName": module 1`] = `
778 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-multiple-exports.js");
779 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
780 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
781 | var ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___ = ___EXPOSE_LOADER_IMPORT___.myGlobal
782 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["moduleMethod"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["moduleMethod"] = ___EXPOSE_LOADER_IMPORT_MODULE_LOCAL_NAME___;
783 | else throw new Error('[expose-loader] The "moduleMethod" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
784 | module.exports = ___EXPOSE_LOADER_IMPORT___;
785 | "
786 | `;
787 |
788 | exports[`loader should work with "moduleLocalName": result 1`] = `
789 | {
790 | "ExposeLoader": {
791 | "globalObject2": {
792 | "foo": "bar",
793 | },
794 | "globalObject3": {
795 | "bar": "foo",
796 | },
797 | },
798 | }
799 | `;
800 |
801 | exports[`loader should work with "moduleLocalName": warnings 1`] = `[]`;
802 |
803 | exports[`loader should work with CommonJS format when module in CommonJS format: errors 1`] = `[]`;
804 |
805 | exports[`loader should work with CommonJS format when module in CommonJS format: module 1`] = `
806 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-commonjs.js");
807 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
808 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
809 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
810 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
811 | module.exports = ___EXPOSE_LOADER_IMPORT___;
812 | "
813 | `;
814 |
815 | exports[`loader should work with CommonJS format when module in CommonJS format: result 1`] = `
816 | {
817 | "ExposeLoader": {
818 | "foo": "bar",
819 | "myMethod": [Function],
820 | },
821 | "global-commonjs2-single-export": {
822 | "foo": "bar",
823 | },
824 | "myGlobal": {
825 | "foo": "bar",
826 | "myMethod": [Function],
827 | },
828 | }
829 | `;
830 |
831 | exports[`loader should work with CommonJS format when module in CommonJS format: warnings 1`] = `[]`;
832 |
833 | exports[`loader should work with CommonJS module format when module in ES module format: errors 1`] = `[]`;
834 |
835 | exports[`loader should work with CommonJS module format when module in ES module format: module 1`] = `
836 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-es.js");
837 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
838 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
839 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
840 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
841 | module.exports = ___EXPOSE_LOADER_IMPORT___;
842 | "
843 | `;
844 |
845 | exports[`loader should work with CommonJS module format when module in ES module format: result 1`] = `
846 | {
847 | "ExposeLoader": {
848 | "bar": [
849 | "test",
850 | ],
851 | "default": {
852 | "foo": "bar",
853 | "myMethod": [Function],
854 | },
855 | },
856 | "global-commonjs2-single-export": {
857 | "foo": "bar",
858 | },
859 | "myGlobal": {
860 | "bar": [
861 | "test",
862 | ],
863 | "default": {
864 | "foo": "bar",
865 | "myMethod": [Function],
866 | },
867 | },
868 | }
869 | `;
870 |
871 | exports[`loader should work with CommonJS module format when module in ES module format: warnings 1`] = `[]`;
872 |
873 | exports[`loader should work with ES module format when module in CommonJS format: errors 1`] = `[]`;
874 |
875 | exports[`loader should work with ES module format when module in CommonJS format: module 1`] = `
876 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-commonjs.js");
877 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
878 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
879 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
880 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
881 | module.exports = ___EXPOSE_LOADER_IMPORT___;
882 | "
883 | `;
884 |
885 | exports[`loader should work with ES module format when module in CommonJS format: result 1`] = `
886 | {
887 | "ExposeLoader": {
888 | "foo": "bar",
889 | "myMethod": [Function],
890 | },
891 | "global-commonjs2-single-export": {
892 | "foo": "bar",
893 | },
894 | "myGlobal": {
895 | "foo": "bar",
896 | "myMethod": [Function],
897 | },
898 | }
899 | `;
900 |
901 | exports[`loader should work with ES module format when module in CommonJS format: warnings 1`] = `[]`;
902 |
903 | exports[`loader should work with ES module format when module in ES format without default: errors 1`] = `[]`;
904 |
905 | exports[`loader should work with ES module format when module in ES format without default: module 1`] = `
906 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-es-without-default.js");
907 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
908 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
909 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
910 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
911 | module.exports = ___EXPOSE_LOADER_IMPORT___;
912 | "
913 | `;
914 |
915 | exports[`loader should work with ES module format when module in ES format without default: result 1`] = `
916 | {
917 | "ExposeLoader": {
918 | "foo": {
919 | "foo": "bar",
920 | "myMethod": [Function],
921 | },
922 | },
923 | "global-commonjs2-single-export": {
924 | "foo": "bar",
925 | },
926 | "myGlobal": {
927 | "foo": {
928 | "foo": "bar",
929 | "myMethod": [Function],
930 | },
931 | },
932 | }
933 | `;
934 |
935 | exports[`loader should work with ES module format when module in ES format without default: warnings 1`] = `[]`;
936 |
937 | exports[`loader should work with ES module format when module in ES format: errors 1`] = `[]`;
938 |
939 | exports[`loader should work with ES module format when module in ES format: module 1`] = `
940 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-module-es.js");
941 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
942 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
943 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
944 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
945 | module.exports = ___EXPOSE_LOADER_IMPORT___;
946 | "
947 | `;
948 |
949 | exports[`loader should work with ES module format when module in ES format: result 1`] = `
950 | {
951 | "ExposeLoader": {
952 | "bar": [
953 | "test",
954 | ],
955 | "default": {
956 | "foo": "bar",
957 | "myMethod": [Function],
958 | },
959 | },
960 | "global-commonjs2-single-export": {
961 | "foo": "bar",
962 | },
963 | "myGlobal": {
964 | "bar": [
965 | "test",
966 | ],
967 | "default": {
968 | "foo": "bar",
969 | "myMethod": [Function],
970 | },
971 | },
972 | }
973 | `;
974 |
975 | exports[`loader should work with ES module format when module in ES format: warnings 1`] = `[]`;
976 |
977 | exports[`loader should work with globalObject: errors 1`] = `[]`;
978 |
979 | exports[`loader should work with globalObject: warnings 1`] = `[]`;
980 |
981 | exports[`loader should work with multiple exposes: errors 1`] = `[]`;
982 |
983 | exports[`loader should work with multiple exposes: module 1`] = `
984 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
985 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
986 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
987 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
988 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
989 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myOtherGlobal"] = ___EXPOSE_LOADER_IMPORT___;
990 | else throw new Error('[expose-loader] The "myOtherGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
991 | module.exports = ___EXPOSE_LOADER_IMPORT___;
992 | "
993 | `;
994 |
995 | exports[`loader should work with multiple exposes: result 1`] = `
996 | {
997 | "ExposeLoader": {
998 | "foo": "bar",
999 | },
1000 | "myGlobal": {
1001 | "foo": "bar",
1002 | },
1003 | "myOtherGlobal": {
1004 | "foo": "bar",
1005 | },
1006 | }
1007 | `;
1008 |
1009 | exports[`loader should work with multiple exposes: warnings 1`] = `[]`;
1010 |
1011 | exports[`loader should work with side-effects free modules #1: errors 1`] = `[]`;
1012 |
1013 | exports[`loader should work with side-effects free modules #1: result 1`] = `
1014 | {
1015 | "ExposeLoader": {
1016 | "default": {
1017 | "ServerStyleSheet": [Function],
1018 | "StyleSheetConsumer": {
1019 | "$$typeof": Symbol(react.consumer),
1020 | "_context": {
1021 | "$$typeof": Symbol(react.context),
1022 | "Consumer": [Circular],
1023 | "Provider": [Circular],
1024 | "_currentValue": {
1025 | "shouldForwardProp": undefined,
1026 | "styleSheet": e {
1027 | "gs": {},
1028 | "names": Map {},
1029 | "options": {
1030 | "isServer": true,
1031 | "useCSSOMInjection": true,
1032 | },
1033 | "server": false,
1034 | },
1035 | "stylis": [Function],
1036 | },
1037 | "_currentValue2": {
1038 | "shouldForwardProp": undefined,
1039 | "styleSheet": e {
1040 | "gs": {},
1041 | "names": Map {},
1042 | "options": {
1043 | "isServer": true,
1044 | "useCSSOMInjection": true,
1045 | },
1046 | "server": false,
1047 | },
1048 | "stylis": [Function],
1049 | },
1050 | "_threadCount": 0,
1051 | },
1052 | },
1053 | "StyleSheetContext": {
1054 | "$$typeof": Symbol(react.context),
1055 | "Consumer": {
1056 | "$$typeof": Symbol(react.consumer),
1057 | "_context": [Circular],
1058 | },
1059 | "Provider": [Circular],
1060 | "_currentValue": {
1061 | "shouldForwardProp": undefined,
1062 | "styleSheet": e {
1063 | "gs": {},
1064 | "names": Map {},
1065 | "options": {
1066 | "isServer": true,
1067 | "useCSSOMInjection": true,
1068 | },
1069 | "server": false,
1070 | },
1071 | "stylis": [Function],
1072 | },
1073 | "_currentValue2": {
1074 | "shouldForwardProp": undefined,
1075 | "styleSheet": e {
1076 | "gs": {},
1077 | "names": Map {},
1078 | "options": {
1079 | "isServer": true,
1080 | "useCSSOMInjection": true,
1081 | },
1082 | "server": false,
1083 | },
1084 | "stylis": [Function],
1085 | },
1086 | "_threadCount": 0,
1087 | },
1088 | "StyleSheetManager": [Function],
1089 | "ThemeConsumer": {
1090 | "$$typeof": Symbol(react.consumer),
1091 | "_context": {
1092 | "$$typeof": Symbol(react.context),
1093 | "Consumer": [Circular],
1094 | "Provider": [Circular],
1095 | "_currentValue": undefined,
1096 | "_currentValue2": undefined,
1097 | "_threadCount": 0,
1098 | },
1099 | },
1100 | "ThemeContext": {
1101 | "$$typeof": Symbol(react.context),
1102 | "Consumer": {
1103 | "$$typeof": Symbol(react.consumer),
1104 | "_context": [Circular],
1105 | },
1106 | "Provider": [Circular],
1107 | "_currentValue": undefined,
1108 | "_currentValue2": undefined,
1109 | "_threadCount": 0,
1110 | },
1111 | "ThemeProvider": [Function],
1112 | "__PRIVATE__": {
1113 | "StyleSheet": [Function],
1114 | "mainSheet": e {
1115 | "gs": {},
1116 | "names": Map {},
1117 | "options": {
1118 | "isServer": true,
1119 | "useCSSOMInjection": true,
1120 | },
1121 | "server": false,
1122 | },
1123 | },
1124 | "createGlobalStyle": [Function],
1125 | "css": [Function],
1126 | "default": [Function],
1127 | "isStyledComponent": [Function],
1128 | "keyframes": [Function],
1129 | "styled": [Function],
1130 | "useTheme": [Function],
1131 | "version": "6.1.19",
1132 | "withTheme": [Function],
1133 | },
1134 | },
1135 | "global-commonjs2-single-export": {
1136 | "foo": "bar",
1137 | },
1138 | }
1139 | `;
1140 |
1141 | exports[`loader should work with side-effects free modules #1: warnings 1`] = `[]`;
1142 |
1143 | exports[`loader should work with side-effects free modules: errors 1`] = `[]`;
1144 |
1145 | exports[`loader should work with side-effects free modules: module 1`] = `
1146 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./rx.all.js");
1147 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../../src/runtime/getGlobalThis.js");
1148 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
1149 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
1150 | module.exports = ___EXPOSE_LOADER_IMPORT___;
1151 | "
1152 | `;
1153 |
1154 | exports[`loader should work with side-effects free modules: result 1`] = `
1155 | {
1156 | "ExposeLoader": {
1157 | "default": [Function],
1158 | },
1159 | "global-commonjs2-single-export": {
1160 | "foo": "bar",
1161 | },
1162 | "myGlobal": {
1163 | "AnonymousObservable": [Function],
1164 | "AnonymousObserver": [Function],
1165 | "AnonymousSubject": [Function],
1166 | "ArgumentOutOfRangeError": [Function],
1167 | "AsyncSubject": [Function],
1168 | "BehaviorSubject": [Function],
1169 | "BinaryDisposable": [Function],
1170 | "CompositeDisposable": [Function],
1171 | "CompositeError": [Function],
1172 | "ConnectableObservable": [Function],
1173 | "Disposable": [Function],
1174 | "EmptyError": [Function],
1175 | "FlatMapObservable": [Function],
1176 | "HistoricalScheduler": [Function],
1177 | "MockDisposable": [Function],
1178 | "NAryDisposable": [Function],
1179 | "NotImplementedError": [Function],
1180 | "NotSupportedError": [Function],
1181 | "Notification": [Function],
1182 | "ObjectDisposedError": [Function],
1183 | "Observable": [Function],
1184 | "ObservableBase": [Function],
1185 | "Observer": [Function],
1186 | "Pauser": [Function],
1187 | "ReactiveTest": {
1188 | "created": 100,
1189 | "disposed": 1000,
1190 | "onCompleted": [Function],
1191 | "onError": [Function],
1192 | "onNext": [Function],
1193 | "subscribe": [Function],
1194 | "subscribed": 200,
1195 | },
1196 | "Recorded": [Function],
1197 | "RefCountDisposable": [Function],
1198 | "ReplaySubject": [Function],
1199 | "Scheduler": [Function],
1200 | "SerialDisposable": [Function],
1201 | "SingleAssignmentDisposable": [Function],
1202 | "Subject": [Function],
1203 | "Subscription": [Function],
1204 | "TestScheduler": [Function],
1205 | "TimeoutError": [Function],
1206 | "VirtualTimeScheduler": [Function],
1207 | "config": {
1208 | "Promise": [Function],
1209 | "longStackSupport": false,
1210 | "useNativeEvents": false,
1211 | },
1212 | "doneEnumerator": {
1213 | "done": true,
1214 | "value": undefined,
1215 | },
1216 | "helpers": {
1217 | "defaultComparer": [Function],
1218 | "defaultError": [Function],
1219 | "defaultKeySerializer": [Function],
1220 | "defaultNow": [Function],
1221 | "defaultSubComparer": [Function],
1222 | "identity": [Function],
1223 | "isArrayLike": [Function],
1224 | "isFunction": [Function],
1225 | "isIterable": [Function],
1226 | "isPromise": [Function],
1227 | "iterator": Symbol(Symbol.iterator),
1228 | "noop": [Function],
1229 | "notImplemented": [Function],
1230 | "notSupported": [Function],
1231 | },
1232 | "internals": {
1233 | "AbstractObserver": [Function],
1234 | "Enumerable": [Function],
1235 | "PriorityQueue": [Function],
1236 | "SchedulePeriodicRecursive": [Function],
1237 | "ScheduledItem": [Function],
1238 | "ScheduledObserver": [Function],
1239 | "addProperties": [Function],
1240 | "addRef": [Function],
1241 | "bindCallback": [Function],
1242 | "inherits": [Function],
1243 | "isEqual": [Function],
1244 | "isObject": [Function],
1245 | "tryCatch": [Function],
1246 | },
1247 | },
1248 | }
1249 | `;
1250 |
1251 | exports[`loader should work with side-effects free modules: warnings 1`] = `[]`;
1252 |
1253 | exports[`loader should work: errors 1`] = `[]`;
1254 |
1255 | exports[`loader should work: module 1`] = `
1256 | "var ___EXPOSE_LOADER_IMPORT___ = require("-!./global-commonjs2-single-export.js");
1257 | var ___EXPOSE_LOADER_GET_GLOBAL_THIS___ = require("../../src/runtime/getGlobalThis.js");
1258 | var ___EXPOSE_LOADER_GLOBAL_THIS___ = ___EXPOSE_LOADER_GET_GLOBAL_THIS___;
1259 | if (typeof ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] === 'undefined') ___EXPOSE_LOADER_GLOBAL_THIS___["myGlobal"] = ___EXPOSE_LOADER_IMPORT___;
1260 | else throw new Error('[expose-loader] The "myGlobal" value exists in the global scope, it may not be safe to overwrite it, use the "override" option')
1261 | module.exports = ___EXPOSE_LOADER_IMPORT___;
1262 | "
1263 | `;
1264 |
1265 | exports[`loader should work: result 1`] = `
1266 | {
1267 | "ExposeLoader": {
1268 | "foo": "bar",
1269 | },
1270 | "myGlobal": {
1271 | "foo": "bar",
1272 | },
1273 | }
1274 | `;
1275 |
1276 | exports[`loader should work: warnings 1`] = `[]`;
1277 |
--------------------------------------------------------------------------------