Skip to content

Commit

Permalink
Fix imports resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 13, 2021
1 parent c408dc9 commit 4a31db7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
@@ -1,6 +1,10 @@
export default function (moduleName, dirname, absoluteRuntime) {
if (absoluteRuntime === false) return moduleName;

resolveFSPath();
}

export function resolveFSPath() {
throw new Error(
"The 'absoluteRuntime' option is not supported when using @babel/standalone.",
);
Expand Down
Expand Up @@ -32,3 +32,7 @@ function resolveAbsoluteRuntime(moduleName: string, dirname: string) {
);
}
}

export function resolveFSPath(path) {
return require.resolve(path);
}
23 changes: 12 additions & 11 deletions packages/babel-plugin-transform-runtime/src/index.ts
Expand Up @@ -3,7 +3,7 @@ import { addDefault, isModule } from "@babel/helper-module-imports";
import { types as t } from "@babel/core";

import { hasMinVersion } from "./helpers";
import getRuntimePath from "./get-runtime-path";
import getRuntimePath, { resolveFSPath } from "./get-runtime-path";

import _pluginCorejs2 from "babel-plugin-polyfill-corejs2";
import _pluginCorejs3 from "babel-plugin-polyfill-corejs3";
Expand Down Expand Up @@ -165,8 +165,6 @@ export default declare((api, options, dirname) => {
};
}

const corejsExt = absoluteRuntime ? ".js" : "";

return {
name: "transform-runtime",

Expand All @@ -175,14 +173,16 @@ export default declare((api, options, dirname) => {
pluginCorejs2,
{
method: "usage-pure",
absoluteImports: absoluteRuntime ? modulePath : false,
[pluginsCompat]: {
runtimeVersion,
useBabelRuntime: modulePath,
ext: corejsExt,
ext: "",
},
},
createRegeneratorPlugin({
method: "usage-pure",
absoluteImports: absoluteRuntime ? modulePath : false,
[pluginsCompat]: { useBabelRuntime: modulePath },
}),
)
Expand All @@ -193,15 +193,18 @@ export default declare((api, options, dirname) => {
method: "usage-pure",
version: 3,
proposals,
[pluginsCompat]: { useBabelRuntime: modulePath, ext: corejsExt },
absoluteImports: absoluteRuntime ? modulePath : false,
[pluginsCompat]: { useBabelRuntime: modulePath, ext: "" },
},
createRegeneratorPlugin({
method: "usage-pure",
absoluteImports: absoluteRuntime ? modulePath : false,
[pluginsCompat]: { useBabelRuntime: modulePath },
}),
)
: createRegeneratorPlugin({
method: "usage-pure",
absoluteImports: absoluteRuntime ? modulePath : false,
[pluginsCompat]: { useBabelRuntime: modulePath },
}),

Expand Down Expand Up @@ -232,12 +235,10 @@ export default declare((api, options, dirname) => {
? "helpers/esm"
: "helpers";

return addDefaultImport(
`${modulePath}/${helpersDir}/${name}`,
name,
blockHoist,
true,
);
let helperPath = `${modulePath}/${helpersDir}/${name}`;
if (absoluteRuntime) helperPath = resolveFSPath(helperPath);

return addDefaultImport(helperPath, name, blockHoist, true);
});

const cache = new Map();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a31db7

Please sign in to comment.