diff --git a/docs/usage.md b/docs/usage.md index f467f1f0..40cc14bf 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -74,6 +74,16 @@ The `shouldInjectPolyfill` function takes two parameters: the name of the polyfi function shouldInjectPolyfill(name: string, defaultShouldInject: boolean): boolean; ``` +### `absoluteRuntime` + +`boolean` or `string`, defaults to `false`. + +This allows users to run polyfill providers broadly across a whole project. By default, polyfill providers inject a bare import to the polyfill package (for example, `core-js-pure/stable/array/from.js`), but that only works if the polyfill is in the `node_modules` of the file that is being compiled. This can be problematic for nested `node_modules`, npm-linked modules, or CLIs that reside outside the user's project, among other cases. To avoid worrying about how the runtime module's location is resolved, this allows users to resolve the runtime once up front, and then insert absolute paths to the runtime into the output code. + +Using absolute paths is not desirable if files are compiled for use at a later time, but in contexts where a file is compiled and then immediately consumed, they can be quite helpful. + +Reference: [babel/babel#8435](https://github.com/babel/babel/pull/8435) + ### `missingDependencies` This option modifies the dependencies detection logging. If set to `false`, dependencies diff --git a/packages/babel-helper-define-polyfill-provider/src/dependencies.js b/packages/babel-helper-define-polyfill-provider/src/dependencies.js index 51972080..46349af2 100644 --- a/packages/babel-helper-define-polyfill-provider/src/dependencies.js +++ b/packages/babel-helper-define-polyfill-provider/src/dependencies.js @@ -1,11 +1,59 @@ // @flow -import resolve from "resolve"; +import requireResolve from "resolve"; +import path from "path"; import debounce from "lodash.debounce"; +export function resolve( + dirname: string, + moduleName: string, + absoluteImports: boolean | string, +): string { + if (absoluteImports === false) return moduleName; + + let basedir = dirname; + if (typeof absoluteImports === "string") { + basedir = path.resolve(basedir, absoluteImports); + } + + let modulePackage, moduleNestedPath; + + let slash = moduleName.indexOf("/"); + if (moduleName[0] === "@") { + slash = moduleName.indexOf("/", slash + 1); + } + + if (slash === -1) { + modulePackage = moduleName; + moduleNestedPath = ""; + } else { + modulePackage = moduleName.slice(0, slash); + moduleNestedPath = moduleName.slice(slash); + } + + try { + const pkg = requireResolve.sync(`${modulePackage}/package.json`, { + basedir, + }); + return path.dirname(pkg) + moduleNestedPath; + } catch (err) { + if (err.code !== "MODULE_NOT_FOUND") throw err; + + // $FlowIgnore + throw Object.assign( + new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), + { + code: "BABEL_POLYFILL_NOT_FOUND", + polyfill: moduleName, + dirname, + }, + ); + } +} + export function has(basedir: string, name: string) { try { - resolve.sync(name, { basedir }); + requireResolve.sync(name, { basedir }); return true; } catch { return false; diff --git a/packages/babel-helper-define-polyfill-provider/src/imports-cache.js b/packages/babel-helper-define-polyfill-provider/src/imports-cache.js index 14e0c4ae..f2893e2e 100644 --- a/packages/babel-helper-define-polyfill-provider/src/imports-cache.js +++ b/packages/babel-helper-define-polyfill-provider/src/imports-cache.js @@ -9,11 +9,13 @@ export default class ImportsCache { _imports: WeakMap>; _anonymousImports: WeakMap>; _lastImports: WeakMap; + _resolver: (url: string) => string; - constructor() { + constructor(resolver: (url: string) => string) { this._imports = new WeakMap(); this._anonymousImports = new WeakMap(); this._lastImports = new WeakMap(); + this._resolver = resolver; } storeAnonymous( @@ -29,7 +31,7 @@ export default class ImportsCache { const node = getVal( programPath.node.sourceType === "script", - t.stringLiteral(url), + t.stringLiteral(this._resolver(url)), ); imports.add(key); this._injectImport(programPath, node); @@ -53,7 +55,7 @@ export default class ImportsCache { if (!imports.has(key)) { const { node, name: id } = getVal( programPath.node.sourceType === "script", - t.stringLiteral(url), + t.stringLiteral(this._resolver(url)), t.identifier(name), ); imports.set(key, id); diff --git a/packages/babel-helper-define-polyfill-provider/src/index.js b/packages/babel-helper-define-polyfill-provider/src/index.js index b0bd7523..5c5cc99a 100644 --- a/packages/babel-helper-define-polyfill-provider/src/index.js +++ b/packages/babel-helper-define-polyfill-provider/src/index.js @@ -45,6 +45,7 @@ function resolveOptions( debug: boolean, shouldInjectPolyfill: ?(name: string, shouldInject: boolean) => boolean, providerOptions: ProviderOptions, + absoluteImports: string | boolean, } { const { method, @@ -53,6 +54,7 @@ function resolveOptions( configPath, debug, shouldInjectPolyfill, + absoluteImports, ...providerOptions } = options; @@ -83,6 +85,17 @@ function resolveOptions( ); } + if ( + absoluteImports != null && + typeof absoluteImports !== "boolean" && + typeof absoluteImports !== "string" + ) { + throw new Error( + `.absoluteImports must be a boolean, a string, or undefined` + + ` (received ${JSON.stringify(absoluteImports)})`, + ); + } + const targetsObj = typeof targetsOption === "string" || Array.isArray(targetsOption) ? { browsers: targetsOption } @@ -97,6 +110,7 @@ function resolveOptions( method, methodName, targets, + absoluteImports: absoluteImports ?? false, shouldInjectPolyfill, debug: !!debug, providerOptions: ((providerOptions: Object): ProviderOptions), @@ -118,9 +132,14 @@ function instantiateProvider( debug, shouldInjectPolyfill, providerOptions, + absoluteImports, } = resolveOptions(options); - const getUtils = createUtilsGetter(new ImportsCache()); + const getUtils = createUtilsGetter( + new ImportsCache(moduleName => + deps.resolve(dirname, moduleName, absoluteImports), + ), + ); // eslint-disable-next-line prefer-const let include, exclude; @@ -180,12 +199,18 @@ function instantiateProvider( }, assertDependency(name, version = "*") { if (missingDependencies === false) return; + if (absoluteImports) { + // If absoluteImports is not false, we will try resolving + // the dependency and throw if it's not possible. We can + // skip the check here. + return; + } const dep = version === "*" ? name : `${name}@^${version}`; const found = missingDependencies.all ? false - : mapGetOr(depsCache, name, () => deps.has(dirname, name)); + : mapGetOr(depsCache, name, () => !deps.has(dirname, name)); if (!found) { debugLog().missingDeps.add(dep); diff --git a/packages/babel-helper-define-polyfill-provider/src/types.js b/packages/babel-helper-define-polyfill-provider/src/types.js index 5f7d902d..319e1268 100644 --- a/packages/babel-helper-define-polyfill-provider/src/types.js +++ b/packages/babel-helper-define-polyfill-provider/src/types.js @@ -33,6 +33,7 @@ export type PluginOptions = {| exclude?: Pattern[], shouldInjectPolyfill?: (name: string, shouldInject: boolean) => boolean, missingDependencies?: MissingDependenciesOption, + absoluteImports?: boolean | string, |}; export type PolyfillProvider = ( diff --git a/packages/babel-helper-define-polyfill-provider/test/absolute-imports.js b/packages/babel-helper-define-polyfill-provider/test/absolute-imports.js new file mode 100644 index 00000000..071b1cec --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/absolute-imports.js @@ -0,0 +1,52 @@ +import * as babel from "@babel/core"; +import { join } from "path"; +import { readFileSync, writeFileSync } from "fs"; + +function transformTest(name, cwd, file, options = {}) { + it(name, () => { + const inputPath = join(cwd, file); + const outputPath = join(cwd, file.replace(".js", ".out.js")); + + const input = readFileSync(inputPath, "utf8"); + let expected; + try { + expected = readFileSync(outputPath, "utf8"); + } catch {} + + let { code } = babel.transformSync(input, { + cwd, + filename: inputPath, + ...options, + }); + + while (code.includes(__dirname)) { + code = code.replace(__dirname, ""); + } + + if (expected === undefined) { + writeFileSync(outputPath, code); + } else { + expect(code).toBe(expected); + } + }); +} + +describe("true", () => { + const cwd = join(__dirname, "fixtures", "absoluteImports", "true"); + + transformTest("basic behavior", cwd, "main.js"); + transformTest("relative to config file", cwd, "nested/main.js"); + transformTest("resolved in a parent directory", cwd, "nested-2/main.js"); +}); + +describe("string", () => { + const cwd = join(__dirname, "fixtures", "absoluteImports", "string"); + + transformTest("basic behavior", cwd, "main.js"); +}); + +describe("subpath", () => { + const cwd = join(__dirname, "fixtures", "absoluteImports", "subpath"); + + transformTest("works", cwd, "main.js"); +}); diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/babel.config.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/babel.config.json new file mode 100644 index 00000000..0cbe3741 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/babel.config.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + ["../../../helpers/generic-provider.js", { + "method": "usage-global", + "globals": { + "a": "polyfill-a", + "b": "polyfill-b" + }, + "absoluteImports": "./nested" + }, "polyfill-a"] + ] +} diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/main.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/main.js new file mode 100644 index 00000000..26da0afa --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/main.js @@ -0,0 +1,2 @@ +a; +b; diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/main.out.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/main.out.js new file mode 100644 index 00000000..a65859e3 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/main.out.js @@ -0,0 +1,4 @@ +import "/fixtures/absoluteImports/string/nested/node_modules/polyfill-a"; +import "/fixtures/absoluteImports/string/node_modules/polyfill-b"; +a; +b; \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/nested/node_modules/polyfill-a/package.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/nested/node_modules/polyfill-a/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/nested/node_modules/polyfill-a/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/node_modules/polyfill-b/package.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/node_modules/polyfill-b/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/string/node_modules/polyfill-b/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/babel.config.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/babel.config.json new file mode 100644 index 00000000..9781a920 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/babel.config.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + ["../../../helpers/generic-provider.js", { + "method": "usage-global", + "globals": { + "a": "polyfill-a/auto", + "b": "@polyfill/b/auto" + }, + "absoluteImports": true + }] + ] +} diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/main.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/main.js new file mode 100644 index 00000000..26da0afa --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/main.js @@ -0,0 +1,2 @@ +a; +b; diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/main.out.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/main.out.js new file mode 100644 index 00000000..aecbf922 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/main.out.js @@ -0,0 +1,4 @@ +import "/fixtures/absoluteImports/subpath/node_modules/polyfill-a/auto"; +import "/fixtures/absoluteImports/subpath/node_modules/@polyfill/b/auto"; +a; +b; \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/@polyfill/b/auto.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/@polyfill/b/auto.js new file mode 100644 index 00000000..1c8a0e79 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/@polyfill/b/auto.js @@ -0,0 +1 @@ +; \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/@polyfill/b/package.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/@polyfill/b/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/@polyfill/b/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/polyfill-a/auto.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/polyfill-a/auto.js new file mode 100644 index 00000000..1c8a0e79 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/polyfill-a/auto.js @@ -0,0 +1 @@ +; \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/polyfill-a/package.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/polyfill-a/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/subpath/node_modules/polyfill-a/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/babel.config.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/babel.config.json new file mode 100644 index 00000000..17c5df4f --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/babel.config.json @@ -0,0 +1,12 @@ +{ + "babelrcRoots": ["./nested", "./nested-2"], + "plugins": [ + ["../../../helpers/generic-provider.js", { + "method": "usage-global", + "globals": { + "a": "polyfill-a" + }, + "absoluteImports": true + }, "polyfill-a"] + ] +} diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/main.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/main.js new file mode 100644 index 00000000..31142aab --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/main.js @@ -0,0 +1 @@ +a; diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/main.out.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/main.out.js new file mode 100644 index 00000000..53b80af7 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/main.out.js @@ -0,0 +1,2 @@ +import "/fixtures/absoluteImports/true/node_modules/polyfill-a"; +a; \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/.babelrc.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/.babelrc.json new file mode 100644 index 00000000..c6b857ae --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/.babelrc.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + ["../../../../helpers/generic-provider.js", { + "method": "usage-global", + "globals": { + "b": "polyfill-b" + }, + "absoluteImports": true + }, "polyfill-b"] + ] +} diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/main.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/main.js new file mode 100644 index 00000000..26da0afa --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/main.js @@ -0,0 +1,2 @@ +a; +b; diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/main.out.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/main.out.js new file mode 100644 index 00000000..96f97b78 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested-2/main.out.js @@ -0,0 +1,4 @@ +import "/fixtures/absoluteImports/true/node_modules/polyfill-b"; +import "/fixtures/absoluteImports/true/node_modules/polyfill-a"; +a; +b; \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/.babelrc.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/.babelrc.json new file mode 100644 index 00000000..c6b857ae --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/.babelrc.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + ["../../../../helpers/generic-provider.js", { + "method": "usage-global", + "globals": { + "b": "polyfill-b" + }, + "absoluteImports": true + }, "polyfill-b"] + ] +} diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/main.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/main.js new file mode 100644 index 00000000..26da0afa --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/main.js @@ -0,0 +1,2 @@ +a; +b; diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/main.out.js b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/main.out.js new file mode 100644 index 00000000..cc78058e --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/main.out.js @@ -0,0 +1,4 @@ +import "/fixtures/absoluteImports/true/nested/node_modules/polyfill-b"; +import "/fixtures/absoluteImports/true/node_modules/polyfill-a"; +a; +b; \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/node_modules/polyfill-a/package.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/node_modules/polyfill-a/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/node_modules/polyfill-a/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/node_modules/polyfill-b/package.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/node_modules/polyfill-b/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/nested/node_modules/polyfill-b/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/node_modules/polyfill-a/package.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/node_modules/polyfill-a/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/node_modules/polyfill-a/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/node_modules/polyfill-b/package.json b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/node_modules/polyfill-b/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/test/fixtures/absoluteImports/true/node_modules/polyfill-b/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/babel-helper-define-polyfill-provider/test/options.js b/packages/babel-helper-define-polyfill-provider/test/options.js index 4406b3d8..510a5f33 100644 --- a/packages/babel-helper-define-polyfill-provider/test/options.js +++ b/packages/babel-helper-define-polyfill-provider/test/options.js @@ -186,3 +186,19 @@ describe("shouldInjectPolyfill", () => { expect(result).toBe(true); }); }); + +function withAbsoluteImports(absoluteImports) { + let resolved; + transform("code", { method: "usage-global", absoluteImports }, () => ({ + usageGlobal() {}, + })); + return resolved; +} + +describe("absoluteImports", () => { + it("can be a boolean or a string", () => { + expect(() => withAbsoluteImports(false)).not.toThrow(); + expect(() => withAbsoluteImports(true)).not.toThrow(); + expect(() => withAbsoluteImports("./foo/bar")).not.toThrow(); + }); +}); diff --git a/packages/babel-plugin-polyfill-corejs3/package.json b/packages/babel-plugin-polyfill-corejs3/package.json index 82256c19..fa8bf02a 100644 --- a/packages/babel-plugin-polyfill-corejs3/package.json +++ b/packages/babel-plugin-polyfill-corejs3/package.json @@ -24,7 +24,8 @@ "@babel/helper-plugin-test-runner": "^7.10.4", "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-transform-for-of": "^7.10.4", - "@babel/plugin-transform-modules-commonjs": "^7.10.4" + "@babel/plugin-transform-modules-commonjs": "^7.10.4", + "core-js-pure": "^3.6.5" }, "peerDependencies": { "@babel/core": "^7.0.0-0" diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/README.md b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/README.md new file mode 100644 index 00000000..8b98855c --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/README.md @@ -0,0 +1,2 @@ +NOTE: is the top-level node_modules folder +(that's how `@babel/helper-plugin-test-runner` works). diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/input.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/input.mjs new file mode 100644 index 00000000..05365a8a --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/input.mjs @@ -0,0 +1 @@ +Array.from; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/options.json new file mode 100644 index 00000000..7e3ff292 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "@@/polyfill-corejs3", + { + "method": "usage-global", + "absoluteImports": true + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/output.mjs new file mode 100644 index 00000000..0f8f9a94 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/global/output.mjs @@ -0,0 +1,3 @@ +import "/core-js/modules/es.array.from.js"; +import "/core-js/modules/es.string.iterator.js"; +Array.from; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/README.md b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/README.md new file mode 100644 index 00000000..8b98855c --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/README.md @@ -0,0 +1,2 @@ +NOTE: is the top-level node_modules folder +(that's how `@babel/helper-plugin-test-runner` works). diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/input.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/input.mjs new file mode 100644 index 00000000..05365a8a --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/input.mjs @@ -0,0 +1 @@ +Array.from; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/options.json new file mode 100644 index 00000000..d5efa2af --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "@@/polyfill-corejs3", + { + "method": "usage-pure", + "absoluteImports": true + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/output.mjs new file mode 100644 index 00000000..64f44c55 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/absolute-imports/pure/output.mjs @@ -0,0 +1,2 @@ +import _Array$from from "/core-js-pure/stable/array/from.js"; +_Array$from; diff --git a/packages/babel-plugin-polyfill-es-shims/package.json b/packages/babel-plugin-polyfill-es-shims/package.json index b963285d..aea84ced 100644 --- a/packages/babel-plugin-polyfill-es-shims/package.json +++ b/packages/babel-plugin-polyfill-es-shims/package.json @@ -20,7 +20,8 @@ }, "devDependencies": { "@babel/core": "^7.11.5", - "@babel/helper-plugin-test-runner": "^7.10.4" + "@babel/helper-plugin-test-runner": "^7.10.4", + "array.from": "^1.1.0" }, "peerDependencies": { "@babel/core": "^7.0.0-0" diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/README.md b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/README.md new file mode 100644 index 00000000..8b98855c --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/README.md @@ -0,0 +1,2 @@ +NOTE: is the top-level node_modules folder +(that's how `@babel/helper-plugin-test-runner` works). diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/input.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/input.mjs new file mode 100644 index 00000000..05365a8a --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/input.mjs @@ -0,0 +1 @@ +Array.from; diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/options.json b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/options.json new file mode 100644 index 00000000..895ed2b8 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "@@/polyfill-es-shims", + { + "method": "usage-global", + "absoluteImports": true + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/output.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/output.mjs new file mode 100644 index 00000000..dd362adf --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/global/output.mjs @@ -0,0 +1,2 @@ +import "/array.from/auto"; +Array.from; diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/README.md b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/README.md new file mode 100644 index 00000000..8b98855c --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/README.md @@ -0,0 +1,2 @@ +NOTE: is the top-level node_modules folder +(that's how `@babel/helper-plugin-test-runner` works). diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/input.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/input.mjs new file mode 100644 index 00000000..05365a8a --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/input.mjs @@ -0,0 +1 @@ +Array.from; diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/options.json b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/options.json new file mode 100644 index 00000000..3b2013b2 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "@@/polyfill-es-shims", + { + "method": "usage-pure", + "absoluteImports": true + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/output.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/output.mjs new file mode 100644 index 00000000..74329687 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/absolute-imports/pure/output.mjs @@ -0,0 +1,2 @@ +import _ArrayFrom from "/array.from"; +_ArrayFrom; diff --git a/yarn.lock b/yarn.lock index 41c0b31a..1b7e7d3e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -233,7 +233,7 @@ __metadata: languageName: node linkType: hard -"@babel/helper-define-polyfill-provider@^0.0.3, @babel/helper-define-polyfill-provider@workspace:packages/babel-helper-define-polyfill-provider": +"@babel/helper-define-polyfill-provider@^0.0.4, @babel/helper-define-polyfill-provider@workspace:packages/babel-helper-define-polyfill-provider": version: 0.0.0-use.local resolution: "@babel/helper-define-polyfill-provider@workspace:packages/babel-helper-define-polyfill-provider" dependencies: @@ -3634,6 +3634,17 @@ __metadata: languageName: node linkType: hard +"array.from@npm:^1.1.0": + version: 1.1.0 + resolution: "array.from@npm:1.1.0" + dependencies: + define-properties: ^1.1.3 + es-abstract: ^1.17.2 + iterate-value: ^1.0.1 + checksum: da072503db3a45ee76e779ad6c00325345cdef476d599799a468e453658b620b5d9b45f2a5b949ac7477887c6b7e5a737b457ae955aa6450e285678a56964ab4 + languageName: node + linkType: hard + "array.prototype.flat@npm:^1.2.1": version: 1.2.3 resolution: "array.prototype.flat@npm:1.2.3" @@ -3871,7 +3882,7 @@ __metadata: dependencies: "@babel/compat-data": ^7.11.0 "@babel/core": ^7.11.5 - "@babel/helper-define-polyfill-provider": ^0.0.3 + "@babel/helper-define-polyfill-provider": ^0.0.4 "@babel/helper-plugin-test-runner": ^7.10.4 "@babel/plugin-transform-for-of": ^7.10.4 "@babel/plugin-transform-modules-commonjs": ^7.10.4 @@ -3886,12 +3897,13 @@ __metadata: resolution: "babel-plugin-polyfill-corejs3@workspace:packages/babel-plugin-polyfill-corejs3" dependencies: "@babel/core": ^7.11.5 - "@babel/helper-define-polyfill-provider": ^0.0.3 + "@babel/helper-define-polyfill-provider": ^0.0.4 "@babel/helper-plugin-test-runner": ^7.10.4 "@babel/plugin-syntax-dynamic-import": ^7.8.3 "@babel/plugin-transform-for-of": ^7.10.4 "@babel/plugin-transform-modules-commonjs": ^7.10.4 core-js-compat: ^3.6.4 + core-js-pure: ^3.6.5 peerDependencies: "@babel/core": ^7.0.0-0 languageName: unknown @@ -3902,8 +3914,9 @@ __metadata: resolution: "babel-plugin-polyfill-es-shims@workspace:packages/babel-plugin-polyfill-es-shims" dependencies: "@babel/core": ^7.11.5 - "@babel/helper-define-polyfill-provider": ^0.0.3 + "@babel/helper-define-polyfill-provider": ^0.0.4 "@babel/helper-plugin-test-runner": ^7.10.4 + array.from: ^1.1.0 peerDependencies: "@babel/core": ^7.0.0-0 languageName: unknown @@ -3914,7 +3927,7 @@ __metadata: resolution: "babel-plugin-polyfill-regenerator@workspace:packages/babel-plugin-polyfill-regenerator" dependencies: "@babel/core": ^7.11.5 - "@babel/helper-define-polyfill-provider": ^0.0.3 + "@babel/helper-define-polyfill-provider": ^0.0.4 "@babel/helper-plugin-test-runner": ^7.10.4 peerDependencies: "@babel/core": ^7.0.0-0 @@ -5033,6 +5046,13 @@ __metadata: languageName: node linkType: hard +"core-js-pure@npm:^3.6.5": + version: 3.6.5 + resolution: "core-js-pure@npm:3.6.5" + checksum: 91fc8e0b699d5bcb11f265ad4544d08c98096b86ad6c9b4c00109616db0aa992ceb58ea82d0dbae2a16658a7aaf2922aa6f9fc1107dc3b0055270799d0414a3f + languageName: node + linkType: hard + "core-js@npm:^2.6.5": version: 2.6.11 resolution: "core-js@npm:2.6.11" @@ -5693,7 +5713,7 @@ __metadata: languageName: node linkType: hard -"es-abstract@npm:^1.17.0, es-abstract@npm:^1.17.0-next.1, es-abstract@npm:^1.17.2, es-abstract@npm:^1.17.5": +"es-abstract@npm:^1.17.0, es-abstract@npm:^1.17.0-next.1, es-abstract@npm:^1.17.2, es-abstract@npm:^1.17.4, es-abstract@npm:^1.17.5": version: 1.17.5 resolution: "es-abstract@npm:1.17.5" dependencies: @@ -5712,6 +5732,21 @@ __metadata: languageName: node linkType: hard +"es-get-iterator@npm:^1.0.2": + version: 1.1.0 + resolution: "es-get-iterator@npm:1.1.0" + dependencies: + es-abstract: ^1.17.4 + has-symbols: ^1.0.1 + is-arguments: ^1.0.4 + is-map: ^2.0.1 + is-set: ^2.0.1 + is-string: ^1.0.5 + isarray: ^2.0.5 + checksum: 2facd9668d2297ae98f42384667a588abbbd5a12f8223086ff9bece004f927d88d817ece5109a45d439e9280152f36b5aac27ec1173695856519d5717a162b43 + languageName: node + linkType: hard + "es-to-primitive@npm:^1.2.1": version: 1.2.1 resolution: "es-to-primitive@npm:1.2.1" @@ -7682,6 +7717,13 @@ fsevents@~2.1.2: languageName: node linkType: hard +"is-arguments@npm:^1.0.4": + version: 1.0.4 + resolution: "is-arguments@npm:1.0.4" + checksum: a04bc21254cfbb77c934ec51165ef7629c12cabd2a92c2c4333280b5117f138fcec6369dd2ab7d8fe24e3af7dbc2a4ce389c53ed0b55b0f8818788c3c09f4ad2 + languageName: node + linkType: hard + "is-arrayish@npm:^0.2.1": version: 0.2.1 resolution: "is-arrayish@npm:0.2.1" @@ -7887,6 +7929,13 @@ fsevents@~2.1.2: languageName: node linkType: hard +"is-map@npm:^2.0.1": + version: 2.0.1 + resolution: "is-map@npm:2.0.1" + checksum: 16524b5d2e0c5c8bc2674f99294205abbb63819de7919b232c3035436771d3df50b69a3af2b2ce110961b4eeaf50f9a172f6a5b690aa4be32be85f4e5b2d6f01 + languageName: node + linkType: hard + "is-negated-glob@npm:^1.0.0": version: 1.0.0 resolution: "is-negated-glob@npm:1.0.0" @@ -7990,6 +8039,13 @@ fsevents@~2.1.2: languageName: node linkType: hard +"is-set@npm:^2.0.1": + version: 2.0.1 + resolution: "is-set@npm:2.0.1" + checksum: 97a9f4dd73405d9edf5c18b0a5935961f34ae34c81220d3cd9621ad390114b7f881f3c12e4abe4effae066dccf447ae7109d8e29b67c0c0e5fae4333179bfda7 + languageName: node + linkType: hard + "is-ssh@npm:^1.3.0": version: 1.3.1 resolution: "is-ssh@npm:1.3.1" @@ -8082,6 +8138,13 @@ fsevents@~2.1.2: languageName: node linkType: hard +"isarray@npm:^2.0.5": + version: 2.0.5 + resolution: "isarray@npm:2.0.5" + checksum: cfb3e907b3c7957fb18e479bbe9102df4e84c5386839b4a33076f38ee31a8934e77d43ff517967fd39192a7c06b894770454886a5ffc8a3ddc36f6b746d70726 + languageName: node + linkType: hard + "isexe@npm:^2.0.0": version: 2.0.0 resolution: "isexe@npm:2.0.0" @@ -8174,6 +8237,23 @@ fsevents@~2.1.2: languageName: node linkType: hard +"iterate-iterator@npm:^1.0.1": + version: 1.0.1 + resolution: "iterate-iterator@npm:1.0.1" + checksum: d2e6b0704bd4c194589059f6b5b1f7947a997af70a6cb54765f908ec6fe76f39a49d588aaaff9e725209c0dc8a700a883f2f265efb646bab2535c51975466bd3 + languageName: node + linkType: hard + +"iterate-value@npm:^1.0.1": + version: 1.0.2 + resolution: "iterate-value@npm:1.0.2" + dependencies: + es-get-iterator: ^1.0.2 + iterate-iterator: ^1.0.1 + checksum: 7c0bef59ead553a2d1b7957954a514e180e3155765606c5e8cfb09518860c7b81aa0675c987352f506dd779b2366cd2b5e4cd249f7cf0a965b86c916e669608e + languageName: node + linkType: hard + "jest-changed-files@npm:^24.9.0": version: 24.9.0 resolution: "jest-changed-files@npm:24.9.0"