-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discover pkgs from volta and corepack
And discover yarn and pnpm from engines.
- Loading branch information
Showing
5 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"packageManager": "[email protected]+sha256.d1581d46ed10f54ff0cbdd94a2373b1f070202b0fbff29f27c2ce01460427043" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|