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

feat: add cnpm to corepack #333

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ jobs:
run: |
LATEST_BERRY_VERSION=$(curl https://repo.yarnpkg.com/tags | jq -r '.latest.stable')

LATEST_NPM=$(curl https://registry.npmjs.org/npm | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')
LATEST_PNPM=$(curl https://registry.npmjs.org/pnpm | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')
LATEST_YARN=$(curl https://registry.npmjs.org/yarn | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')
LATEST_NPM=$(curl https://registry.npmjs.org/npm/latest | jq '.version + "+sha1." + .dist.shasum')
LATEST_PNPM=$(curl https://registry.npmjs.org/pnpm/latest | jq '.version + "+sha1." + .dist.shasum')
LATEST_YARN=$(curl https://registry.npmjs.org/yarn/latest | jq '.version + "+sha1." + .dist.shasum')
LATEST_CNPM=$(curl https://registry.npmmirror.com/cnpm/latest | jq '.version + "+sha1." + .dist.shasum')
LATEST_BERRY=$(jq -n '$version + "+sha224." + $checksum' --arg version "$LATEST_BERRY_VERSION" --arg checksum "$(curl https://repo.yarnpkg.com/"$LATEST_BERRY_VERSION"/packages/yarnpkg-cli/bin/yarn.js | openssl dgst -sha224 | cut -d' ' -f2)")

git --no-pager show HEAD:config.json | jq '. * '"{
Expand Down
38 changes: 38 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,44 @@
}
}
},
"cnpm": {
"default": "9.3.2+sha1.05a307b7c1d34a368b8d30ff159dfd0533c8c328",
"fetchLatestFrom": {
"type": "url",
"url": "https://registry.npmmirror.com/cnpm",
"fields": {
"tags": "latest",
"versions": "tags"
}
},
"transparent": {
"commands": [
[
"cnpm",
"sync"
]
]
},
"ranges": {
"*": {
"url": "https://cdn.npmmirror.com/packages/cnpm/{}/cnpm-{}.tgz",
"bin": {
"cnpm": "./bin/cnpm"
},
"commands": {
"use": ["cnpm", "install"]
},
"registry": {
"type": "url",
"url": "https://registry.npmmirror.com/cnpm",
"fields": {
"versions": "versions",
"tags": "dist-tags"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably provide mentioned for the npm package, see #339

Suggested change
}
},
"npmRegistry": {
"type": "npm",
"package": "cnpm"
},

}
}
},
"pnpm": {
"default": "8.14.1+sha1.d039b38e0b20ad012ed548e44267b8d4c88b447a",
"fetchLatestFrom": {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"pnpm": "./dist/pnpm.js",
"pnpx": "./dist/pnpx.js",
"yarn": "./dist/yarn.js",
"yarnpkg": "./dist/yarnpkg.js"
"yarnpkg": "./dist/yarnpkg.js",
"cnpm": "./dist/cnpm.js"
},
"executableFiles": [
"./dist/npm.js",
Expand All @@ -93,7 +94,8 @@
"./shims/yarn",
"./shims/yarn.ps1",
"./shims/yarnpkg",
"./shims/yarnpkg.ps1"
"./shims/yarnpkg.ps1",
"./dist/cnpm.js"
]
}
}
2 changes: 1 addition & 1 deletion sources/corepackUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export async function installVersion(installTarget: string, locator: Locator, {s
}
}

const defaultNpmRegistryURL = spec.url.replace(`{}`, version);
const defaultNpmRegistryURL = spec.url.replaceAll(`{}`, version);
const url = process.env.COREPACK_NPM_REGISTRY ?
defaultNpmRegistryURL.replace(
npmRegistryUtils.DEFAULT_NPM_REGISTRY_URL,
Expand Down
1 change: 1 addition & 0 deletions sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum SupportedPackageManagers {
Npm = `npm`,
Pnpm = `pnpm`,
Yarn = `yarn`,
Cnpm = `cnpm`,
Comment on lines 5 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ASCII/alphabetical order

Suggested change
Npm = `npm`,
Pnpm = `pnpm`,
Yarn = `yarn`,
Cnpm = `cnpm`,
Cnpm = `cnpm`,
Npm = `npm`,
Pnpm = `pnpm`,
Yarn = `yarn`,

}

export const SupportedPackageManagerSet = new Set<SupportedPackageManagers>(
Expand Down
43 changes: 41 additions & 2 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const testedPackageManagers: Array<[string, string]> = [
[`pnpm`, `6.6.2`],
[`pnpm`, `6.6.2+sha1.7b4d6b176c1b93b5670ed94c24babb7d80c13854`],
[`pnpm`, `6.6.2+sha224.eb5c0acad3b0f40ecdaa2db9aa5a73134ad256e17e22d1419a2ab073`],
[`cnpm`, `9.3.2`],
elrrrrrrr marked this conversation as resolved.
Show resolved Hide resolved
[`cnpm`, `9.3.2+sha1.05a307b7c1d34a368b8d30ff159dfd0533c8c328`],
[`cnpm`, `9.3.2+sha224.6d124ff3ac4ea4ba18833993e063fd8091156d6400ed7a2e5ad47ce3`],
[`npm`, `6.14.2`],
[`npm`, `6.14.2+sha1.f057d35cd4792c4c511bb1fa332edb43143d07b0`],
[`npm`, `6.14.2+sha224.50512c1eb404900ee78586faa6d756b8d867ff46a328e6fb4cdf3a87`],
Expand All @@ -93,7 +96,7 @@ for (const [name, version] of testedPackageManagers) {
await expect(runCli(cwd, [name, `--version`])).resolves.toMatchObject({
exitCode: 0,
stderr: ``,
stdout: `${version.split(`+`, 1)[0]}\n`,
stdout: expect.stringContaining(version.split(`+`, 1)[0]),
});
});
});
Expand Down Expand Up @@ -266,6 +269,12 @@ it(`should use the pinned version when local projects don't list any spec`, asyn
exitCode: 0,
});

await expect(runCli(cwd, [`cnpm`, `--version`])).resolves.toMatchObject({
stdout: expect.stringContaining(`cnpm@${config.definitions.cnpm.default.split(`+`, 1)[0]}`),
stderr: ``,
exitCode: 0,
});

await expect(runCli(cwd, [`npm`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.npm.default.split(`+`, 1)[0]}\n`,
stderr: ``,
Expand Down Expand Up @@ -366,6 +375,11 @@ it(`should refuse to run a different package manager within a configured project
exitCode: 1,
});

await expect(runCli(cwd, [`cnpm`, `--version`])).resolves.toMatchObject({
stdout: `Usage Error: This project is configured to use yarn\n\n$ cnpm ...\n`,
exitCode: 1,
});

// Disable strict checking to workaround the UsageError.
process.env.COREPACK_ENABLE_STRICT = `0`;

Expand All @@ -379,6 +393,11 @@ it(`should refuse to run a different package manager within a configured project
stderr: ``,
exitCode: 0,
});
await expect(runCli(cwd, [`cnpm`, `--version`])).resolves.toMatchObject({
stdout: expect.stringContaining(`cnpm@${config.definitions.cnpm.default.split(`+`, 1)[0]}`),
stderr: ``,
exitCode: 0,
});
});
});

Expand All @@ -400,6 +419,11 @@ it(`should always use fallback version when project spec env is disabled`, async
stderr: ``,
exitCode: 0,
});
await expect(runCli(cwd, [`cnpm`, `--version`])).resolves.toMatchObject({
stdout: expect.stringContaining(`cnpm@${config.definitions.cnpm.default.split(`+`, 1)[0]}`),
stderr: ``,
exitCode: 0,
});
});
});

Expand Down Expand Up @@ -433,6 +457,11 @@ it(`should allow to call "corepack install -g --all" to prepare all package mana
stderr: ``,
exitCode: 0,
});
await expect(runCli(cwd, [`cnpm`, `--version`])).resolves.toMatchObject({
stdout: expect.stringContaining(`cnpm@${config.definitions.cnpm.default.split(`+`, 1)[0]}`),
stderr: ``,
exitCode: 0,
});
});
});

Expand Down Expand Up @@ -517,7 +546,7 @@ it(`should support hydrating package managers if cache folder was removed`, asyn

it(`should support hydrating multiple package managers from cached archives`, async () => {
await xfs.mktempPromise(async cwd => {
await expect(runCli(cwd, [`pack`, `[email protected]`, `[email protected]`])).resolves.toMatchObject({
await expect(runCli(cwd, [`pack`, `[email protected]`, `[email protected]`, `[email protected]`])).resolves.toMatchObject({
exitCode: 0,
stderr: ``,
});
Expand Down Expand Up @@ -552,6 +581,16 @@ it(`should support hydrating multiple package managers from cached archives`, as
stderr: ``,
exitCode: 0,
});

await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
packageManager: `[email protected]`,
});

await expect(runCli(cwd, [`cnpm`, `--version`])).resolves.toMatchObject({
stdout: expect.stringContaining(`[email protected]`),
stderr: ``,
exitCode: 0,
});
});
}, 180_000);

Expand Down
2 changes: 1 addition & 1 deletion tests/nock/4IfgwoxNR5JV5bBojS26Kg-3.dat

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/nock/4IfgwoxNR5JV5bBojS26Kg-4.dat

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/nock/87nfex2DUjb7u3SnxZx64Q-1.dat

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/nock/ExW_9wdiyrK8tF3BIVw_yg-1.dat

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/nock/Q-gEXR-fmX_Didj2zQmUiA-1.dat

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/nock/VurwVdvlR5Rs7xQVs9UCVw-1.dat

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/nock/gD354-khxZHN8IJPre6iqw-1.dat

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion tests/nock/h9H6jL9ro_imv61YP24nGg-2.dat

This file was deleted.

2 changes: 1 addition & 1 deletion tests/nock/h9H6jL9ro_imv61YP24nGg-3.dat

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/nock/h9H6jL9ro_imv61YP24nGg-4.dat

Large diffs are not rendered by default.

Loading
Loading