Skip to content

Commit

Permalink
Fix standalone build
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 5, 2022
1 parent 5a9e9bd commit 6b1814b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions babel.config.js
Expand Up @@ -231,6 +231,11 @@ module.exports = function (api) {
{ name: "USE_ESM", value: outputType === "module" },
"flag-USE_ESM",
],
[
pluginToggleBooleanFlag,
{ name: "IS_STANDALONE", value: env === "standalone" },
"flag-IS_STANDALONE",
],

process.env.STRIP_BABEL_8_FLAG && [
pluginToggleBooleanFlag,
Expand Down
13 changes: 7 additions & 6 deletions packages/babel-core/src/index.ts
@@ -1,5 +1,5 @@
declare const PACKAGE_JSON: { name: string; version: string };
declare const USE_ESM: boolean;
declare const USE_ESM: boolean, IS_STANDALONE: boolean;

export const version = PACKAGE_JSON.version;

Expand Down Expand Up @@ -89,11 +89,12 @@ export function Plugin(alias: string) {
);
}

import * as module from "module";
import Module from "module";
import * as thisFile from "./index";
if (USE_ESM) {
// Pass this module to the CJS proxy, so that it
// can be synchronously accessed.
const cjsProxy = module.createRequire(import.meta.url)("../cjs-proxy.cjs");
cjsProxy["__ initialize @babel/core cjs proxy __"] = thisFile;
if (!IS_STANDALONE) {
// Pass this module to the CJS proxy, so that it can be synchronously accessed.
const cjsProxy = Module.createRequire(import.meta.url)("../cjs-proxy.cjs");
cjsProxy["__ initialize @babel/core cjs proxy __"] = thisFile;
}
}

0 comments on commit 6b1814b

Please sign in to comment.