Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't include "resolve" in @babel/standalone (#11432)
* Don't include "resolve" in @babel/standalone * Also alias src
- Loading branch information
1 parent
6b8f6ab
commit d9eb943
Showing
4 changed files
with
43 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/babel-plugin-transform-runtime/src/get-runtime-path/browser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function(moduleName, dirname, absoluteRuntime) { | ||
if (absoluteRuntime === false) return moduleName; | ||
|
||
throw new Error( | ||
"The 'absoluteRuntime' option is not supported when using @babel/standalone.", | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/babel-plugin-transform-runtime/src/get-runtime-path/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import path from "path"; | ||
import resolve from "resolve"; | ||
|
||
export default function(moduleName, dirname, absoluteRuntime) { | ||
if (absoluteRuntime === false) return moduleName; | ||
|
||
return resolveAbsoluteRuntime( | ||
moduleName, | ||
path.resolve(dirname, absoluteRuntime === true ? "." : absoluteRuntime), | ||
); | ||
} | ||
|
||
function resolveAbsoluteRuntime(moduleName: string, dirname: string) { | ||
try { | ||
return path | ||
.dirname(resolve.sync(`${moduleName}/package.json`, { basedir: dirname })) | ||
.replace(/\\/g, "/"); | ||
} catch (err) { | ||
if (err.code !== "MODULE_NOT_FOUND") throw err; | ||
|
||
throw Object.assign( | ||
new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), | ||
{ | ||
code: "BABEL_RUNTIME_NOT_FOUND", | ||
runtime: moduleName, | ||
dirname, | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters