diff --git a/fixtures/package.json/engines/package.json b/fixtures/package.json/engines/package.json index 59d602a6..f6cf017e 100644 --- a/fixtures/package.json/engines/package.json +++ b/fixtures/package.json/engines/package.json @@ -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" } } diff --git a/fixtures/package.json/packageManager/package.json b/fixtures/package.json/packageManager/package.json new file mode 100644 index 00000000..54463826 --- /dev/null +++ b/fixtures/package.json/packageManager/package.json @@ -0,0 +1,4 @@ +{ + "packageManager": "pnpm@7.33.7+sha256.d1581d46ed10f54ff0cbdd94a2373b1f070202b0fbff29f27c2ce01460427043" +} + diff --git a/fixtures/package.json/volta/package.json b/fixtures/package.json/volta/package.json new file mode 100644 index 00000000..83c70e9b --- /dev/null +++ b/fixtures/package.json/volta/package.json @@ -0,0 +1,9 @@ +{ + "volta": { + "node": "16.16.1", + "npm": "9.7.1", + "yarn": "1.22.10", + "pnpm": "7.33.7" + } +} + diff --git a/src/utils/devenv.test.ts b/src/utils/devenv.test.ts index be62c76a..89386138 100644 --- a/src/utils/devenv.test.ts +++ b/src/utils/devenv.test.ts @@ -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', + 'pnpm.io@7.33.7', + 'nodejs.org' + ], + [ + 'package.json/volta/package.json', + 'nodejs.org@16.16.1', + 'npmjs.com@9.7.1', + 'yarnpkg.com@1.22.10', + 'pnpm.io@7.33.7', ], [".node-version", "nodejs.org@16.16.0"], ["python-version/std/.python-version", "python.org~3.10"], diff --git a/src/utils/devenv.ts b/src/utils/devenv.ts index cfe64325..5e34bf36 100644 --- a/src/utils/devenv.ts +++ b/src/utils/devenv.ts @@ -178,13 +178,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: "pnpm@7.33.7+sha256.d1581d46ed10f54ff0cbdd94a2373b1f070202b0fbff29f27c2ce01460427043" + const match = json.packageManager.match(/^(?[^@]+)@(?[^+]+)/); + + 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