Skip to content

Commit

Permalink
Discover pkgs from volta and corepack
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs committed Feb 23, 2024
1 parent 104affb commit d2a6fae
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 8 deletions.
35 changes: 35 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
44 changes: 37 additions & 7 deletions src/utils/devenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,43 @@ 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 };

node = {
dependencies: {
...(pkg === 'npm' && { 'npmjs.com': version }),
...(pkg === 'yarn' && { 'yarnpkg.com': version }),
...(pkg === 'pnpm' && { 'pnpm.io': version }),
},
};
}
}
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

0 comments on commit d2a6fae

Please sign in to comment.