Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf!: call executePackageManagerRequest directly #2

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
2507e9b
feat: update package manager versions (#249)
github-actions[bot] Apr 7, 2023
f539ae2
chore(main): release 0.17.2 (#254)
github-actions[bot] Apr 7, 2023
aa3cbdb
fix(doc): add a note about troubleshooting network errors (#259)
SpencerKaiser Apr 29, 2023
25fa623
chore: report URL on `fetchUrlStream` error message (#261)
tisonkun Apr 29, 2023
df89e38
refactor: separate library and cli entry point (#250)
merceyz May 19, 2023
d5ef940
chore(docs): document how to use aliases instead of jumper binaries (…
aduh95 May 19, 2023
c94c400
chore(ci): add prebuilt executable to GitHub release (#243)
aduh95 May 19, 2023
74f679d
chore: update supported Node.js versions (#258)
aduh95 May 19, 2023
863e0e0
chore(deps): upgrade all npm dependencies (#266)
aduh95 May 19, 2023
7b61ff6
feat: update package manager versions (#256)
github-actions[bot] May 19, 2023
7e364ad
chore(ci): add whole package archive to GH release (#267)
aduh95 May 19, 2023
091352a
chore(main): release 0.18.0 (#262)
github-actions[bot] May 19, 2023
3211804
doc: update DNS troubleshooting section to mention IPv6 (#263)
SpencerKaiser May 19, 2023
17d1f3d
fix: don't override `process.exitCode` (#268)
merceyz May 23, 2023
2f3678c
fix: disable `v8-compile-cache` when using `npm@>=9.7.0` (#276)
merceyz Jun 13, 2023
5345774
feat: update package manager versions (#272)
github-actions[bot] Jun 13, 2023
5956d95
chore(main): release 0.18.1 (#269)
github-actions[bot] Jun 13, 2023
be2489c
feat: support ESM (#270)
merceyz Jun 13, 2023
4188f2b
feat: update package manager versions (#280)
github-actions[bot] Jun 24, 2023
db9b7e6
chore(main): release 0.19.0 (#278)
github-actions[bot] Jun 24, 2023
6090fe7
build(deps-dev): bump semver from 7.5.1 to 7.5.2 (#281)
dependabot[bot] Jul 13, 2023
98338b3
chore: update dev dependency proxy-agent to 6.2.2 (#283)
Trott Jul 14, 2023
8593425
build(deps): bump word-wrap from 1.2.3 to 1.2.4 (#287)
dependabot[bot] Jul 19, 2023
b340844
chore: remove `vm2` from dev dependencies (#284)
aduh95 Jul 20, 2023
b8a4a52
feat: update package manager versions (#282)
github-actions[bot] Jul 28, 2023
fe3e5cd
Refactoring of the CLI interface (#291)
arcanis Aug 28, 2023
be9c286
feat: update package manager versions (#292)
github-actions[bot] Aug 28, 2023
2bf76c9
chore(main): release 0.20.0 (#289)
github-actions[bot] Aug 29, 2023
cc33de0
chore: update test to handle case when env var is set (#304)
styfle Sep 4, 2023
c085753
chore: update Yarn (#308)
merceyz Sep 11, 2023
787e24d
chore: update supported Node.js versions (#309)
aduh95 Sep 15, 2023
6d39928
chore(ci): update the version of Node.js used to update Nock files (#…
aduh95 Oct 6, 2023
503e135
feat: update package manager versions (#297)
github-actions[bot] Oct 8, 2023
adf2e7a
chore(main): release 0.21.0 (#310)
github-actions[bot] Oct 8, 2023
2533d12
test: check that a semver version is required (#312)
merceyz Oct 8, 2023
92f8e71
feat: allow fallback to application/json for custom registries (#314)
stramel Oct 19, 2023
0bd2577
feat: update package manager versions (#318)
github-actions[bot] Oct 20, 2023
bd5fcb5
build(deps): bump @babel/traverse from 7.21.5 to 7.23.2 (#319)
dependabot[bot] Oct 20, 2023
9583583
chore: bump npm dependencies (#321)
aduh95 Oct 20, 2023
2b5f6b7
chore: upgrade outdated dependencies (#322)
aduh95 Oct 21, 2023
0e89bfa
chore(main): release 0.22.0 (#320)
github-actions[bot] Oct 21, 2023
450cd33
feat: update package manager versions (#325)
github-actions[bot] Nov 5, 2023
b7aa576
chore(main): release 0.23.0 (#327)
github-actions[bot] Nov 5, 2023
e8ae337
Switches Yarn to the "aliases" field (#340)
arcanis Dec 20, 2023
6df5063
feat: add support for HTTP redirect (#341)
guibwl Dec 29, 2023
adcd989
chore(ci): test on Node.js 21.x (#344)
aduh95 Dec 29, 2023
0717c6a
feat(yarn): fallback to npm when `COREPACK_NPM_REGISTRY` is set (#339)
arcanis Dec 29, 2023
9bee415
feat: add support for rangeless commands (#338)
arcanis Dec 29, 2023
518bed8
fix: clarify `EACCES` errors (#343)
Medhansh404 Dec 29, 2023
addf455
chore: bump dev dependencies (#346)
aduh95 Dec 29, 2023
cfcc280
feat: update package manager versions (#330)
github-actions[bot] Dec 29, 2023
9bdd296
chore(main): release 0.24.0 (#345)
github-actions[bot] Dec 29, 2023
2950a8a
fix(use): create `package.json` when calling `corepack use` on empty …
aduh95 Jan 12, 2024
cc3ada7
feat: update package manager versions (#348)
github-actions[bot] Jan 13, 2024
a3f271c
chore(main): release 0.24.1 (#353)
github-actions[bot] Jan 13, 2024
4eb1fd9
chore(tests): increase timeout to get more green on Windows CI (#366)
aduh95 Jan 30, 2024
c2a6e4f
chore(ci): bump actions and add dependabot config (#367)
aduh95 Jan 30, 2024
6b8d87f
feat!: prompt user before downloading software (#360)
aduh95 Jan 30, 2024
a56c13b
feat: bump Known Good Release when downloading new version (#364)
aduh95 Jan 30, 2024
b9eea58
chore(tests): add test that validates download warning is shown (#370)
aduh95 Jan 30, 2024
54e9510
feat!: remove old install folder migration (#373)
merceyz Feb 9, 2024
65880ca
fix: remove unsafe remove of install folder (#372)
merceyz Feb 11, 2024
fe6a307
feat!: use `fetch` (#365)
merceyz Feb 11, 2024
12f1c31
chore(tests): use separate envs for each tests (#371)
aduh95 Feb 12, 2024
f442366
feat: add `corepack cache` command (#363)
aduh95 Feb 12, 2024
9a1cb38
chore!: remove Node.js 19.x from the range of supported versions (#375)
aduh95 Feb 16, 2024
9066ea7
build(deps-dev): bump undici from 6.4.0 to 6.6.1 (#376)
dependabot[bot] Feb 16, 2024
d9c70b9
feat!: remove `--all` flag (#351)
aduh95 Feb 17, 2024
4a8ce6d
feat: add support for URL in `"packageManager"` (#359)
aduh95 Feb 20, 2024
6168938
chore(main): release 0.25.0 (#369)
github-actions[bot] Feb 20, 2024
f2185fe
fix: use valid semver range for `engines.node` (#378)
merceyz Feb 20, 2024
49ad334
chore(main): release 0.25.1 (#381)
github-actions[bot] Feb 20, 2024
9834f57
fix: do not hard fail if Corepack home folder cannot be created (#382)
aduh95 Feb 21, 2024
09e33c0
build(deps): bump ip from 2.0.0 to 2.0.1 (#385)
dependabot[bot] Feb 21, 2024
1423312
feat: update package manager versions (#362)
github-actions[bot] Feb 21, 2024
31a1c5f
chore: remove Dockerfile (#389)
aduh95 Feb 21, 2024
6aab5fc
chore: bump yarn version (#388)
aduh95 Feb 21, 2024
bc137a0
fix: do not show download prompt when downloading JSON (#383)
aduh95 Feb 21, 2024
476b7dc
chore(main): release 0.25.2 (#387)
github-actions[bot] Feb 21, 2024
00506b2
fix: group the download prompt together (#391)
arcanis Feb 21, 2024
451dcf8
test: clear all `COREPACK_*` environment variables (#392)
merceyz Feb 21, 2024
967e266
test: store nocks in a sqlite database (#374)
merceyz Feb 23, 2024
295a1cd
fix: Windows malicious file analysis waiting problem (#398)
ngnlTeto Feb 27, 2024
835308c
Removes the DESIGN document (#403)
arcanis Feb 27, 2024
88d504c
doc: add note clarifying how to add new package managers (#408)
arcanis Feb 27, 2024
47be27c
fix: improve support for `COREPACK_NPM_REGISTRY` with Yarn Berry (#396)
zhyupe Feb 27, 2024
a3ea1dd
chore(build): upgrade TypeScript (#409)
arcanis Feb 27, 2024
8b6c6d4
feat: Pins the package manager as it's used for the first time (#413)
arcanis Mar 3, 2024
3958d26
Update config.json (#410)
arcanis Mar 3, 2024
b7ec137
fix: ignore `EROFS` errors (#421)
aduh95 Mar 8, 2024
e8edba7
feat: update package manager versions (#415)
github-actions[bot] Mar 8, 2024
a3e3e97
chore(main): release 0.26.0 (#393)
github-actions[bot] Mar 8, 2024
5b95746
chore: remove unused `Cancellation` error
merceyz Mar 15, 2024
daa3a08
perf!: call `executePackageManagerRequest` directly
merceyz Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: support ESM (nodejs#270)
  • Loading branch information
merceyz authored Jun 13, 2023
commit be2489cd0aaabf26a019e1c089a3c8bcc329e94a
8 changes: 7 additions & 1 deletion sources/corepackUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {createHash} from 'crypto';
import {once} from 'events';
import fs from 'fs';
import type {Dir} from 'fs';
import Module from 'module';
import path from 'path';
import semver from 'semver';

Expand Down Expand Up @@ -214,5 +215,10 @@ export async function runVersion(locator: Locator, installSpec: { location: stri
];
process.execArgv = [];

return nodeUtils.loadMainModule(binPath);
// Unset the mainModule and let Node.js set it when needed.
process.mainModule = undefined;

// Use nextTick to unwind the stack, and consequently remove Corepack from
// the stack trace of the package manager.
process.nextTick(Module.runMain, binPath);
}
16 changes: 0 additions & 16 deletions sources/module.d.ts

This file was deleted.

27 changes: 0 additions & 27 deletions sources/nodeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
import Module from 'module';
import path from 'path';

/**
* Loads a module as a main module, enabling the `require.main === module` pattern.
*/
export function loadMainModule(id: string): void {
const modulePath = Module._resolveFilename(id, null, true);

const module = new Module(modulePath, undefined);

module.filename = modulePath;
module.paths = Module._nodeModulePaths(path.dirname(modulePath));

Module._cache[modulePath] = module;

process.mainModule = module;
module.id = `.`;

try {
return module.load(modulePath);
} catch (error) {
delete Module._cache[modulePath];
throw error;
}
}

export interface NodeError extends Error {
code: string;
}
36 changes: 32 additions & 4 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,10 @@ it(`should not override the package manager exit code`, async () => {
});
});

it(`should not override the package manager exit code when it throws`, async () => {
it(`should not preserve the process.exitCode when a package manager throws`, async () => {
// Node.js doesn't preserve process.exitCode when an exception is thrown
// so we need to make sure we don't break this behaviour.

await xfs.mktempPromise(async cwd => {
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
packageManager: `[email protected]`,
Expand All @@ -575,9 +578,9 @@ it(`should not override the package manager exit code when it throws`, async ()
`);

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
exitCode: 42,
stdout: expect.stringContaining(`foo`),
stderr: ``,
exitCode: 1,
stdout: ``,
stderr: expect.stringContaining(`foo`),
});
});
});
Expand Down Expand Up @@ -606,3 +609,28 @@ it(`should not set the exit code after successfully launching the package manage
});
});
});

it(`should support package managers in ESM format`, async () => {
await xfs.mktempPromise(async cwd => {
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
packageManager: `[email protected]`,
});

const yarnDir = ppath.join(npath.toPortablePath(process.env.COREPACK_HOME!), `yarn/2.2.2` as PortablePath);

await xfs.mkdirPromise(yarnDir, {recursive: true});
await xfs.writeFilePromise(ppath.join(yarnDir, `yarn.js` as PortablePath), `
import 'fs';
console.log(42);
`);
await xfs.writeJsonPromise(ppath.join(yarnDir, `package.json` as PortablePath), {
type: `module`,
});

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
exitCode: 0,
stdout: `42\n`,
stderr: ``,
});
});
});
Binary file added tests/nock/6YlkCvzyrFlW9WizGIO9AA-1.dat
Binary file not shown.
Binary file added tests/nock/urO1i4GpxQt29UQLMf23wA-1.dat
Binary file not shown.