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

Discover pkgs from volta and corepack #980

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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
4 changes: 3 additions & 1 deletion fixtures/package.json/engines/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"engines": {
"node": "~16.16.1",
"npm": "~9.7.1"
"npm": "~9.7.1",
"yarn": "~1.22.10",
"pnpm": "~7.33.7"
}
}

4 changes: 4 additions & 0 deletions fixtures/package.json/packageManager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"packageManager": "[email protected]+sha256.d1581d46ed10f54ff0cbdd94a2373b1f070202b0fbff29f27c2ce01460427043"
}

9 changes: 9 additions & 0 deletions fixtures/package.json/volta/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"volta": {
"node": "16.16.1",
"npm": "9.7.1",
"yarn": "1.22.10",
"pnpm": "7.33.7"
}
}

14 changes: 14 additions & 0 deletions src/utils/devenv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ Deno.test("devenv.ts", async runner => {
'package.json/engines/package.json',
'nodejs.org~16.16.1',
'npmjs.com~9.7.1',
'yarnpkg.com~1.22.10',
'pnpm.io~7.33.7',
],
[
'package.json/packageManager/package.json',
'[email protected]',
'nodejs.org'
],
[
'package.json/volta/package.json',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
],
[".node-version", "[email protected]"],
["python-version/std/.python-version", "python.org~3.10"],
Expand Down
60 changes: 53 additions & 7 deletions src/utils/devenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,59 @@ export default async function(dir: Path) {
const json = JSON.parse(await path.read());
let node = json?.pkgx;
if (isString(node) || isArray(node)) node = { dependencies: node }
if (!node && json?.engines) {
node = {
dependencies: {
...(json.engines.node && { 'nodejs.org': json.engines.node }),
...(json.engines.npm && { 'npmjs.com': json.engines.npm }),
},
};
if (!node) {
if (json?.engines) {
node = {
dependencies: {
...(json.engines.node && { 'nodejs.org': json.engines.node }),
...(json.engines.npm && { 'npmjs.com': json.engines.npm }),
...(json.engines.yarn && { 'yarnpkg.com': json.engines.yarn }),
...(json.engines.pnpm && { 'pnpm.io': json.engines.pnpm }),
},
};
}
if (json?.packageManager) { // corepack
// example: "[email protected]+sha256.d1581d46ed10f54ff0cbdd94a2373b1f070202b0fbff29f27c2ce01460427043"
const match = json.packageManager.match(/^(?<pkg>[^@]+)@(?<version>[^+]+)/);

if (match) {
const { pkg, version } = match.groups as { pkg: string, version: string };

switch (pkg) {
case 'npm':
node = {
dependencies: {
'npmjs.com': version,
},
};
break;
case 'yarn':
node = {
dependencies: {
'yarnpkg.com': version,
},
};
break;
case 'pnpm':
node = {
dependencies: {
'pnpm.io': version,
},
};
break;
};
}
}
if (json?.volta) {
node = {
dependencies: {
...(json.volta.node && { 'nodejs.org': json.volta.node }),
...(json.volta.npm && { 'npmjs.com': json.volta.npm }),
...(json.volta.yarn && { 'yarnpkg.com': json.volta.yarn }),
...(json.volta.pnpm && { 'pnpm.io': json.volta.pnpm }),
}
}
}
}
await parse_well_formatted_node(node)
has_package_json = true
Expand Down