Add support for ESM

This commit is contained in:
Stéphan Kochen
2022-10-18 21:49:06 +02:00
parent efae8a0744
commit 60aa1f4434
5 changed files with 33 additions and 16 deletions
+1
View File
@@ -15,6 +15,7 @@ const EXTERNALS = [
`clipanion`, `clipanion`,
`crypto`, `crypto`,
`os`, `os`,
`url`,
]; ];
const compiler = webpack({ const compiler = webpack({
+2 -2
View File
@@ -19,7 +19,7 @@
"@yarnpkg/core": "^3.0.0", "@yarnpkg/core": "^3.0.0",
"@yarnpkg/fslib": "^2.5.1", "@yarnpkg/fslib": "^2.5.1",
"@yarnpkg/plugin-patch": "^3.0.0", "@yarnpkg/plugin-patch": "^3.0.0",
"@yarnpkg/plugin-pnp": "^3.0.0", "@yarnpkg/plugin-pnp": "^3.1.0",
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",
"clipanion": "^3.0.0", "clipanion": "^3.0.0",
"prettier": "2.5.1", "prettier": "2.5.1",
@@ -47,7 +47,7 @@
"@yarnpkg/plugin-npm-cli": "3.0.0", "@yarnpkg/plugin-npm-cli": "3.0.0",
"@yarnpkg/plugin-pack": "3.0.0", "@yarnpkg/plugin-pack": "3.0.0",
"@yarnpkg/plugin-patch": "3.0.0", "@yarnpkg/plugin-patch": "3.0.0",
"@yarnpkg/plugin-pnp": "3.0.1", "@yarnpkg/plugin-pnp": "3.1.0",
"@yarnpkg/plugin-stage": "3.0.0", "@yarnpkg/plugin-stage": "3.0.0",
"@yarnpkg/shell": "3.0.0" "@yarnpkg/shell": "3.0.0"
} }
+18 -2
View File
@@ -13,6 +13,7 @@ import {
import binWrapperNodeModulesTmpl from "./tmpl/bin-wrapper-node-modules.sh.in"; import binWrapperNodeModulesTmpl from "./tmpl/bin-wrapper-node-modules.sh.in";
import binWrapperPnpTmpl from "./tmpl/bin-wrapper-pnp.sh.in"; import binWrapperPnpTmpl from "./tmpl/bin-wrapper-pnp.sh.in";
import { renderTmpl } from "./textUtils"; import { renderTmpl } from "./textUtils";
import { pathToFileURL } from "url";
// Internal command that creates wrappers for binaries. // Internal command that creates wrappers for binaries.
// Used inside the Nix install phase. // Used inside the Nix install phase.
@@ -82,13 +83,28 @@ export default class InstallBinCommand extends Command<CommandContext> {
) { ) {
let wrapper; let wrapper;
switch (configuration.get(`nodeLinker`)) { switch (configuration.get(`nodeLinker`)) {
case `pnp`: case `pnp`: {
const pnpPath = getPnpPath(project);
const nodeOptions = [];
if (await xfs.existsPromise(pnpPath.cjs)) {
nodeOptions.push(
`--require "${npath.fromPortablePath(pnpPath.cjs)}"`
);
}
if (await xfs.existsPromise(pnpPath.esmLoader)) {
nodeOptions.push(
`--experimental-loader "${
pathToFileURL(npath.fromPortablePath(pnpPath.esmLoader)).href
}"`
);
}
wrapper = renderTmpl(binWrapperPnpTmpl, { wrapper = renderTmpl(binWrapperPnpTmpl, {
NODE_PATH: process.execPath, NODE_PATH: process.execPath,
PNP_PATH: getPnpPath(project).cjs, NODE_OPTIONS: nodeOptions.join(" "),
BINARY_PATH: binaryPath, BINARY_PATH: binaryPath,
}); });
break; break;
}
case `node-modules`: case `node-modules`:
wrapper = renderTmpl(binWrapperNodeModulesTmpl, { wrapper = renderTmpl(binWrapperNodeModulesTmpl, {
NODE_PATH: process.execPath, NODE_PATH: process.execPath,
+1 -1
View File
@@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
export NODE_OPTIONS="--require @@PNP_PATH@@" export NODE_OPTIONS='@@NODE_OPTIONS@@'
exec '@@NODE_PATH@@' '@@BINARY_PATH@@' "$@" exec '@@NODE_PATH@@' '@@BINARY_PATH@@' "$@"
+11 -11
View File
@@ -1074,22 +1074,22 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@yarnpkg/plugin-pnp@npm:3.0.1": "@yarnpkg/plugin-pnp@npm:3.1.0":
version: 3.0.1 version: 3.1.0
resolution: "@yarnpkg/plugin-pnp@npm:3.0.1" resolution: "@yarnpkg/plugin-pnp@npm:3.1.0"
dependencies: dependencies:
"@types/semver": ^7.1.0 "@types/semver": ^7.1.0
"@yarnpkg/fslib": ^2.5.1 "@yarnpkg/fslib": ^2.6.0
"@yarnpkg/plugin-stage": ^3.0.0 "@yarnpkg/plugin-stage": ^3.1.0
"@yarnpkg/pnp": ^3.0.1 "@yarnpkg/pnp": ^3.1.0
clipanion: ^3.0.1 clipanion: ^3.0.1
micromatch: ^4.0.2 micromatch: ^4.0.2
semver: ^7.1.2 semver: ^7.1.2
tslib: ^1.13.0 tslib: ^1.13.0
peerDependencies: peerDependencies:
"@yarnpkg/cli": ^3.0.1 "@yarnpkg/cli": ^3.1.0
"@yarnpkg/core": ^3.0.0 "@yarnpkg/core": ^3.1.0
checksum: 682fdaab91583a6fb662be05e660a76510df94e5d79c42f51dd19db9d5e3310b29d91111e5a8ed9fc6e382e2b581a9e0342f37852e2af96c98d33c50d9331bd4 checksum: 9ffd901263f60c83a116a38e8bb76a9196185b36fde514c95b0336affc879308099db12ae9bd20b8f70f3253791f1127bf4f87ced5a62d2b4529a02115347f6d
languageName: node languageName: node
linkType: hard linkType: hard
@@ -1124,7 +1124,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@yarnpkg/pnp@npm:^3.0.1, @yarnpkg/pnp@npm:^3.1.0": "@yarnpkg/pnp@npm:^3.1.0":
version: 3.1.0 version: 3.1.0
resolution: "@yarnpkg/pnp@npm:3.1.0" resolution: "@yarnpkg/pnp@npm:3.1.0"
dependencies: dependencies:
@@ -3307,7 +3307,7 @@ __metadata:
"@yarnpkg/core": ^3.0.0 "@yarnpkg/core": ^3.0.0
"@yarnpkg/fslib": ^2.5.1 "@yarnpkg/fslib": ^2.5.1
"@yarnpkg/plugin-patch": ^3.0.0 "@yarnpkg/plugin-patch": ^3.0.0
"@yarnpkg/plugin-pnp": ^3.0.0 "@yarnpkg/plugin-pnp": ^3.1.0
babel-loader: ^8.1.0 babel-loader: ^8.1.0
clipanion: ^3.0.0 clipanion: ^3.0.0
prettier: 2.5.1 prettier: 2.5.1