feat: treat a project with no version as if it had v0.0.0

close #2648
PR #2678
This commit is contained in:
Zoltan Kochan
2020-07-09 02:17:42 +03:00
committed by GitHub
parent c0d800691c
commit faae9a93cb
4 changed files with 28 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/find-workspace-packages": minor
---
A project with no version field is treated as if it had version 0.0.0.

View File

@@ -13,7 +13,8 @@
},
"scripts": {
"lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts",
"test": "pnpm run compile",
"_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/find-workspace-packages/coverage ts-node packages/find-workspace-packages/test --type-check",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build"
},

View File

@@ -47,14 +47,14 @@ async function requirePackagesManifest (dir: string): Promise<{packages?: string
}
export function arrayOfWorkspacePackagesToMap (
pkgs: Project[]
pkgs: Array<Pick<Project, 'manifest'>>
) {
return pkgs.reduce((acc, pkg) => {
if (!pkg.manifest.name || !pkg.manifest.version) return acc
if (!pkg.manifest.name) return acc
if (!acc[pkg.manifest.name]) {
acc[pkg.manifest.name] = {}
}
acc[pkg.manifest.name][pkg.manifest.version] = pkg
acc[pkg.manifest.name][pkg.manifest.version ?? '0.0.0'] = pkg
return acc
}, {})
}

View File

@@ -0,0 +1,18 @@
import { arrayOfWorkspacePackagesToMap } from '@pnpm/find-workspace-packages'
import test = require('tape')
// This is supported for compatibility with Yarn's implementation
// see https://github.com/pnpm/pnpm/issues/2648
test('arrayOfWorkspacePackagesToMap() treats private packages with no version as packages with 0.0.0 version', (t) => {
const privateProject = {
manifest: {
name: 'private-pkg',
},
}
t.deepEqual(arrayOfWorkspacePackagesToMap([privateProject]), {
'private-pkg': {
'0.0.0': privateProject,
},
})
t.end()
})