From 7e0d04ff092aedbf37fb28d0910c2872dac0caee Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 11 Mar 2020 22:53:39 +0200 Subject: [PATCH] chore: create updater to normalize manifests --- packages/audit/package.json | 2 +- .../cli-utils/src/packageIsInstallable.ts | 6 +- packages/cli-utils/src/pnpmPkgJson.ts | 16 ++-- packages/config/package.json | 2 +- packages/constants/package.json | 2 +- packages/default-resolver/package.json | 2 +- packages/dependency-path/package.json | 2 +- packages/find-workspace-packages/src/index.ts | 4 +- packages/headless/package.json | 7 +- packages/link-bins/package.json | 4 +- packages/local-resolver/package.json | 2 +- packages/lockfile-types/package.json | 3 +- packages/npm-resolver/package.json | 2 +- packages/outdated/package.json | 4 +- .../package-is-installable/src/checkEngine.ts | 4 +- packages/package-is-installable/src/index.ts | 4 +- packages/package-requester/package.json | 2 +- packages/parse-cli-args/package.json | 2 +- packages/plugin-commands-audit/package.json | 2 +- packages/plugin-commands-import/package.json | 5 +- .../plugin-commands-installation/package.json | 5 +- packages/plugin-commands-listing/package.json | 5 +- .../plugin-commands-outdated/package.json | 5 +- .../plugin-commands-publishing/package.json | 5 +- packages/plugin-commands-rebuild/package.json | 5 +- .../package.json | 5 +- packages/plugin-commands-store/package.json | 8 +- .../plugin-commands-store/test/storeStatus.ts | 5 +- .../plugin-commands-store/test/storeUsages.ts | 14 ++-- packages/pnpm/package.json | 6 +- packages/supi/package.json | 7 +- packages/supi/test/install/hoist.ts | 6 +- packages/supi/test/install/misc.ts | 2 +- .../supi/test/install/optionalDependencies.ts | 8 +- packages/tarball-fetcher/package.json | 3 +- pnpm-lock.yaml | 13 ++++ utils/updater/package.json | 8 ++ utils/updater/src/index.ts | 76 +++++++++++++++++++ 38 files changed, 183 insertions(+), 80 deletions(-) create mode 100644 utils/updater/package.json create mode 100644 utils/updater/src/index.ts diff --git a/packages/audit/package.json b/packages/audit/package.json index dfaa7f9142..80901d2809 100644 --- a/packages/audit/package.json +++ b/packages/audit/package.json @@ -13,7 +13,7 @@ "scripts": { "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "tsc": "rimraf lib && tsc", - "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/audit/coverage ts-node packages/audit/test", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/audit/coverage ts-node packages/audit/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/cli-utils/src/packageIsInstallable.ts b/packages/cli-utils/src/packageIsInstallable.ts index 56c7c8fe20..a98e43e035 100644 --- a/packages/cli-utils/src/packageIsInstallable.ts +++ b/packages/cli-utils/src/packageIsInstallable.ts @@ -13,9 +13,9 @@ export function packageIsInstallable ( engineStrict?: boolean, }, ) { - const err = checkPackage(pkgPath, pkg, { - pnpmVersion: packageManager.stableVersion, - }) + const pnpmVersion = packageManager.name === 'pnpm' + ? packageManager.stableVersion : undefined + const err = checkPackage(pkgPath, pkg, { pnpmVersion }) if (err === null) return if ( (err instanceof UnsupportedEngineError && err.wanted.pnpm) || diff --git a/packages/cli-utils/src/pnpmPkgJson.ts b/packages/cli-utils/src/pnpmPkgJson.ts index 76550353a1..6632159c33 100644 --- a/packages/cli-utils/src/pnpmPkgJson.ts +++ b/packages/cli-utils/src/pnpmPkgJson.ts @@ -2,16 +2,20 @@ import { DependencyManifest } from '@pnpm/types' import loadJsonFile = require('load-json-file') import path = require('path') +const defaultManifest = { + name: 'unknown', + version: '0.0.0', +} let pkgJson try { - pkgJson = loadJsonFile.sync( - path.join(path.dirname(require.main!.filename), '../package.json'), - ) -} catch (err) { pkgJson = { - name: 'unknown', - version: '0.0.0', + ...defaultManifest, + ...loadJsonFile.sync( + path.join(path.dirname(require.main!.filename), '../package.json'), + ), } +} catch (err) { + pkgJson = defaultManifest } const packageManager = { diff --git a/packages/config/package.json b/packages/config/package.json index 75ff7715ca..f7ee1f4c4e 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -12,7 +12,7 @@ "tsc": "rimraf lib && tsc", "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "test-with-preview": "ts-node test", - "_test": "npm config rm fetch-retry-maxtimeout && cd ../.. && c8 --reporter lcov --reports-dir packages/config/coverage ts-node packages/config/test", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/config/coverage ts-node packages/config/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test" }, "repository": "https://github.com/pnpm/pnpm/blob/master/packages/config", diff --git a/packages/constants/package.json b/packages/constants/package.json index 0829d8c112..860ee2f397 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -11,7 +11,7 @@ "lib" ], "scripts": { - "test": "pnpm run tsc -- --sourceMap && tslint -c ../../tslint.json -p .", + "test": "pnpm run tsc -- --sourceMap", "tsc": "rimraf lib && tsc", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/default-resolver/package.json b/packages/default-resolver/package.json index d942ece5c0..be10c4e5ac 100644 --- a/packages/default-resolver/package.json +++ b/packages/default-resolver/package.json @@ -13,7 +13,7 @@ "scripts": { "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "tsc": "rimraf lib && tsc", - "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/default-resolver/coverage ts-node packages/default-resolver/test", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/default-resolver/coverage ts-node packages/default-resolver/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/dependency-path/package.json b/packages/dependency-path/package.json index f648f03017..4e5e56d9e4 100644 --- a/packages/dependency-path/package.json +++ b/packages/dependency-path/package.json @@ -9,7 +9,7 @@ ], "scripts": { "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", - "_test": "pnpm link . && cd ../.. && c8 --reporter lcov --reports-dir packages/dependency-path/coverage ts-node packages/dependency-path/test", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/dependency-path/coverage ts-node packages/dependency-path/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc", "tsc": "tsc" diff --git a/packages/find-workspace-packages/src/index.ts b/packages/find-workspace-packages/src/index.ts index 3a89c11c3e..42e00bfdb7 100644 --- a/packages/find-workspace-packages/src/index.ts +++ b/packages/find-workspace-packages/src/index.ts @@ -9,7 +9,7 @@ export { Project } export default async ( workspaceRoot: string, - opts: { engineStrict?: boolean }, + opts?: { engineStrict?: boolean }, ) => { const packagesManifest = await requirePackagesManifest(workspaceRoot) const pkgs = await findPackages(workspaceRoot, { @@ -22,7 +22,7 @@ export default async ( }) pkgs.sort((pkg1: {dir: string}, pkg2: {dir: string}) => pkg1.dir.localeCompare(pkg2.dir)) for (const pkg of pkgs) { - packageIsInstallable(pkg.dir, pkg.manifest, opts) + packageIsInstallable(pkg.dir, pkg.manifest, opts ?? {}) } return pkgs as Project[] diff --git a/packages/headless/package.json b/packages/headless/package.json index 61523e2695..81c5b310ff 100644 --- a/packages/headless/package.json +++ b/packages/headless/package.json @@ -64,10 +64,9 @@ "commitmsg": "commitlint -e", "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "registry-mock": "registry-mock", - "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/headless/coverage ts-node packages/headless/test", - "test:e2e": "run-p -r registry-mock test:tap", - "pretest:e2e": "rimraf ../.tmp/ && registry-mock prepare && ts-node test/pretest", - "test-with-preview": "pnpm run test:e2e", + "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/headless/coverage ts-node packages/headless/test --type-check", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "pre_test": "ts-node test/pretest", "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7770 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "tsc": "rimraf lib && tsc", diff --git a/packages/link-bins/package.json b/packages/link-bins/package.json index 9f00957187..c31a013790 100644 --- a/packages/link-bins/package.json +++ b/packages/link-bins/package.json @@ -13,7 +13,9 @@ "scripts": { "lint": "tslint -c ../../tslint.json --project .", "tsc": "rimraf lib && tsc", - "_test": "ncp test/fixtures test/fixtures_for_testing && cd ../.. && c8 --reporter lcov --reports-dir packages/link-bins/coverage ts-node packages/link-bins/test --type-check && cd packages/link-bins && rimraf test/fixtures_for_testing", + "pre_test": "ncp test/fixtures test/fixtures_for_testing", + "post_test": "rimraf test/fixtures_for_testing", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/link-bins/coverage ts-node packages/link-bins/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc", "fix": "tslint -c tslint.json --project . --fix" diff --git a/packages/local-resolver/package.json b/packages/local-resolver/package.json index 6b818f2741..7d33d405ee 100644 --- a/packages/local-resolver/package.json +++ b/packages/local-resolver/package.json @@ -13,7 +13,7 @@ "scripts": { "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "tsc": "tsc", - "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/local-resolver/coverage ts-node packages/local-resolver/test --ts-node", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/local-resolver/coverage ts-node packages/local-resolver/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc", "fix": "tslint -c tslint.json src/**/*.ts test/**/*.ts --fix" diff --git a/packages/lockfile-types/package.json b/packages/lockfile-types/package.json index eebfaf71df..842d95e1ee 100644 --- a/packages/lockfile-types/package.json +++ b/packages/lockfile-types/package.json @@ -18,5 +18,6 @@ "bugs": { "url": "https://github.com/pnpm/pnpm/issues" }, - "homepage": "https://github.com/pnpm/pnpm/blob/master/packages/lockfile-types#readme" + "homepage": "https://github.com/pnpm/pnpm/blob/master/packages/lockfile-types#readme", + "scripts": {} } diff --git a/packages/npm-resolver/package.json b/packages/npm-resolver/package.json index 705fcdbe0b..49a9135c02 100644 --- a/packages/npm-resolver/package.json +++ b/packages/npm-resolver/package.json @@ -13,7 +13,7 @@ "scripts": { "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "tsc": "rimraf lib && tsc", - "_test": "rimraf .store && cd ../.. && c8 --reporter lcov --reports-dir packages/npm-resolver/coverage ts-node packages/npm-resolver/test --type-check", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/npm-resolver/coverage ts-node packages/npm-resolver/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/outdated/package.json b/packages/outdated/package.json index 4b1c9206b6..7d1a246475 100644 --- a/packages/outdated/package.json +++ b/packages/outdated/package.json @@ -11,13 +11,13 @@ "lib" ], "scripts": { - "pretest": "registry-mock prepare", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc", "tsc": "tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/outdated/coverage ts-node packages/outdated/test --type-check", - "_test": "run-p -r registry-mock test:tap" + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7771 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap" }, "repository": "https://github.com/pnpm/pnpm/blob/master/packages/outdated", "keywords": [ diff --git a/packages/package-is-installable/src/checkEngine.ts b/packages/package-is-installable/src/checkEngine.ts index 32ddb82870..cfc6786c2d 100644 --- a/packages/package-is-installable/src/checkEngine.ts +++ b/packages/package-is-installable/src/checkEngine.ts @@ -24,7 +24,7 @@ export default function checkEngine ( if (wantedEngine.node && !semver.satisfies(currentEngine.node, wantedEngine.node)) { unsatisfiedWanted.node = wantedEngine.node } - if (wantedEngine.pnpm && !semver.satisfies(currentEngine.pnpm, wantedEngine.pnpm)) { + if (currentEngine.pnpm && wantedEngine.pnpm && !semver.satisfies(currentEngine.pnpm, wantedEngine.pnpm)) { unsatisfiedWanted.pnpm = wantedEngine.pnpm } if (Object.keys(unsatisfiedWanted).length) { @@ -35,7 +35,7 @@ export default function checkEngine ( export type Engine = { node: string, - pnpm: string, + pnpm?: string, } export type WantedEngine = Partial diff --git a/packages/package-is-installable/src/index.ts b/packages/package-is-installable/src/index.ts index 2c9338ceb7..61491928c2 100644 --- a/packages/package-is-installable/src/index.ts +++ b/packages/package-is-installable/src/index.ts @@ -27,7 +27,7 @@ export default function packageIsInstallable ( engineStrict?: boolean, nodeVersion?: string, optional: boolean, - pnpmVersion: string, + pnpmVersion?: string, lockfileDir: string, }, ): boolean | null { @@ -69,7 +69,7 @@ export function checkPackage ( }, options: { nodeVersion?: string, - pnpmVersion: string, + pnpmVersion?: string, }, ): null | UnsupportedEngineError | UnsupportedPlatformError { return checkPlatform(pkgId, { diff --git a/packages/package-requester/package.json b/packages/package-requester/package.json index 8e0e50f4ff..2ffa8447c5 100644 --- a/packages/package-requester/package.json +++ b/packages/package-requester/package.json @@ -14,7 +14,7 @@ "start": "pnpm run tsc -- --watch", "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "tsc": "rimraf lib && tsc --pretty", - "_test": "rimraf .store && cd ../.. && c8 --reporter lcov --reports-dir packages/package-requester/coverage ts-node packages/package-requester/test --type-check", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/package-requester/coverage ts-node packages/package-requester/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/parse-cli-args/package.json b/packages/parse-cli-args/package.json index 6b5ebb8a4e..fa2bd908b7 100644 --- a/packages/parse-cli-args/package.json +++ b/packages/parse-cli-args/package.json @@ -13,7 +13,7 @@ "scripts": { "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "tsc": "rimraf lib && tsc", - "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/parse-cli-args/coverage ts-node packages/parse-cli-args/test", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/parse-cli-args/coverage ts-node packages/parse-cli-args/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-audit/package.json b/packages/plugin-commands-audit/package.json index 17e95c07d2..c7948a87f6 100644 --- a/packages/plugin-commands-audit/package.json +++ b/packages/plugin-commands-audit/package.json @@ -13,7 +13,7 @@ "scripts": { "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "tsc": "rimraf lib && tsc", - "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-audit/coverage ts-node packages/plugin-commands-audit/test", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-audit/coverage ts-node packages/plugin-commands-audit/test --type-check", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-import/package.json b/packages/plugin-commands-import/package.json index 0d8e6af0e7..ac8126ec1d 100644 --- a/packages/plugin-commands-import/package.json +++ b/packages/plugin-commands-import/package.json @@ -15,9 +15,8 @@ "tsc": "rimraf lib && tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-import/coverage ts-node packages/plugin-commands-import/test --type-check", - "pretest:e2e": "registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7776 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7772 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-installation/package.json b/packages/plugin-commands-installation/package.json index 45fd12a8e8..c309f2e5a9 100644 --- a/packages/plugin-commands-installation/package.json +++ b/packages/plugin-commands-installation/package.json @@ -15,9 +15,8 @@ "tsc": "rimraf lib && tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-installation/coverage ts-node packages/plugin-commands-installation/test --type-check", - "pretest:e2e": "registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7777 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7773 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-listing/package.json b/packages/plugin-commands-listing/package.json index d1b00a1fb8..7241b787c6 100644 --- a/packages/plugin-commands-listing/package.json +++ b/packages/plugin-commands-listing/package.json @@ -15,9 +15,8 @@ "tsc": "rimraf lib && tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-listing/coverage ts-node packages/plugin-commands-listing/test --type-check", - "pretest:e2e": "registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7773 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7774 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-outdated/package.json b/packages/plugin-commands-outdated/package.json index d81c69423d..f781247d7b 100644 --- a/packages/plugin-commands-outdated/package.json +++ b/packages/plugin-commands-outdated/package.json @@ -15,9 +15,8 @@ "tsc": "rimraf lib && tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-outdated/coverage ts-node packages/plugin-commands-outdated/test --type-check", - "pretest:e2e": "registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7774 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7775 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-publishing/package.json b/packages/plugin-commands-publishing/package.json index 14279d14a1..86995cbf6c 100644 --- a/packages/plugin-commands-publishing/package.json +++ b/packages/plugin-commands-publishing/package.json @@ -15,9 +15,8 @@ "tsc": "rimraf lib && tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-publishing/coverage ts-node packages/plugin-commands-publishing/test --type-check", - "pretest:e2e": "registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7771 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7776 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-rebuild/package.json b/packages/plugin-commands-rebuild/package.json index 6fa1ead03e..59068a32b1 100644 --- a/packages/plugin-commands-rebuild/package.json +++ b/packages/plugin-commands-rebuild/package.json @@ -15,9 +15,8 @@ "tsc": "rimraf lib && tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-rebuild/coverage ts-node packages/plugin-commands-rebuild/test --type-check", - "pretest:e2e": "registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7779 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7777 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-script-runners/package.json b/packages/plugin-commands-script-runners/package.json index a96cd75a8b..54c044b671 100644 --- a/packages/plugin-commands-script-runners/package.json +++ b/packages/plugin-commands-script-runners/package.json @@ -15,9 +15,8 @@ "tsc": "rimraf lib && tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-script-runners/coverage ts-node packages/plugin-commands-script-runners/test --type-check", - "pretest:e2e": "registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7775 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7778 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, diff --git a/packages/plugin-commands-store/package.json b/packages/plugin-commands-store/package.json index abe836a00f..498ca412be 100644 --- a/packages/plugin-commands-store/package.json +++ b/packages/plugin-commands-store/package.json @@ -15,9 +15,8 @@ "tsc": "rimraf lib && tsc", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/plugin-commands-store/coverage ts-node packages/plugin-commands-store/test --type-check", - "pretest:e2e": "registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7778 pnpm run test:e2e", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7779 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "prepublishOnly": "pnpm run tsc" }, @@ -46,7 +45,8 @@ "execa": "4.0.0", "load-json-file": "6.2.0", "path-exists": "4.0.0", - "sinon": "9.0.0" + "sinon": "9.0.0", + "tempy": "0.4.0" }, "dependencies": { "@pnpm/check-package": "3.0.1", diff --git a/packages/plugin-commands-store/test/storeStatus.ts b/packages/plugin-commands-store/test/storeStatus.ts index 6dfad4dc76..c1514776c2 100644 --- a/packages/plugin-commands-store/test/storeStatus.ts +++ b/packages/plugin-commands-store/test/storeStatus.ts @@ -6,12 +6,13 @@ import rimraf = require('@zkochan/rimraf') import execa = require('execa') import path = require('path') import test = require('tape') +import tempy = require('tempy') const REGISTRY = `http://localhost:${REGISTRY_MOCK_PORT}/` test('CLI fails when store status finds modified packages', async function (t) { const project = prepare(t) - const storeDir = path.resolve('pnpm-store') + const storeDir = tempy.directory() await execa('pnpm', ['add', 'is-positive@3.1.0', '--store-dir', storeDir, '--registry', REGISTRY, '--verify-store-integrity']) @@ -40,7 +41,7 @@ test('CLI fails when store status finds modified packages', async function (t) { test('CLI does not fail when store status does not find modified packages', async function (t) { const project = prepare(t) - const storeDir = path.resolve('pnpm-store') + const storeDir = tempy.directory() await execa('pnpm', ['add', 'is-positive@3.1.0', '--store-dir', storeDir, '--registry', REGISTRY, '--verify-store-integrity']) // store status does not fail on not installed optional dependencies diff --git a/packages/plugin-commands-store/test/storeUsages.ts b/packages/plugin-commands-store/test/storeUsages.ts index 7f1560e637..493c87dfed 100644 --- a/packages/plugin-commands-store/test/storeUsages.ts +++ b/packages/plugin-commands-store/test/storeUsages.ts @@ -34,7 +34,7 @@ test('find usages for single package in store and in a project', async (t) => { output, stripIndent` Package: is-negative - └─┬ Package in store: localhost+7778/is-negative/2.1.0 + └─┬ Package in store: localhost+${REGISTRY_MOCK_PORT}/is-negative/2.1.0 └── Project with dependency: ${path.resolve('node_modules')}` + '\n', 'finds usages by package name', ) @@ -49,7 +49,7 @@ test('find usages for single package in store and in a project', async (t) => { output, stripIndent` Package: is-negative@2.1.0 - └─┬ Package in store: localhost+7778/is-negative/2.1.0 + └─┬ Package in store: localhost+${REGISTRY_MOCK_PORT}/is-negative/2.1.0 └── Project with dependency: ${path.resolve('node_modules')}` + '\n', 'finds usages by package name and version', ) @@ -79,11 +79,11 @@ test('find usages for single package in store and in a project', async (t) => { output, stripIndent` Package: is-negative - └─┬ Package in store: localhost+7778/is-negative/2.1.0 + └─┬ Package in store: localhost+${REGISTRY_MOCK_PORT}/is-negative/2.1.0 └── Project with dependency: ${path.resolve('node_modules')} Package: is-odd - └─┬ Package in store: localhost+7778/is-odd/3.0.0 + └─┬ Package in store: localhost+${REGISTRY_MOCK_PORT}/is-odd/3.0.0 └── Project with dependency: ${path.resolve('node_modules')}` + '\n', 'finds usages of two packages', ) @@ -115,7 +115,7 @@ test('find usages for package(s) in store but not in any projects', async (t) => output, stripIndent` Package: is-negative - └─┬ Package in store: localhost+7778/is-negative/2.1.0 + └─┬ Package in store: localhost+${REGISTRY_MOCK_PORT}/is-negative/2.1.0 └── No pnpm projects using this package` + '\n', 'finds usage of package', ) @@ -136,9 +136,9 @@ test('find usages for package(s) in store but not in any projects', async (t) => output, stripIndent` Package: is-negative - ├─┬ Package in store: localhost+7778/is-negative/2.1.0 + ├─┬ Package in store: localhost+${REGISTRY_MOCK_PORT}/is-negative/2.1.0 │ └── No pnpm projects using this package - └─┬ Package in store: localhost+7778/is-negative/2.0.0 + └─┬ Package in store: localhost+${REGISTRY_MOCK_PORT}/is-negative/2.0.0 └── No pnpm projects using this package` + '\n', 'finds usages of packages', ) diff --git a/packages/pnpm/package.json b/packages/pnpm/package.json index ec87690148..f4b233fa07 100644 --- a/packages/pnpm/package.json +++ b/packages/pnpm/package.json @@ -157,9 +157,9 @@ "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "registry-mock": "registry-mock", "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/pnpm/coverage ts-node packages/pnpm/test --type-check", - "pretest:e2e": "rimraf node_modules/.bin/pnpm && registry-mock prepare", - "test:e2e": "run-p -r registry-mock test:tap", - "_test": "pnpm run tsc && cross-env PNPM_REGISTRY_MOCK_PORT=7772 npm run test:e2e", + "pretest:e2e": "rimraf node_modules/.bin/pnpm", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", + "_test": "pnpm run tsc && cross-env PNPM_REGISTRY_MOCK_PORT=7780 pnpm run test:e2e", "test": "pnpm run _test", "tsc": "rimraf lib && tsc", "release": "sh .scripts/release.sh" diff --git a/packages/supi/package.json b/packages/supi/package.json index 735c0d994d..5b07796a8e 100644 --- a/packages/supi/package.json +++ b/packages/supi/package.json @@ -157,11 +157,10 @@ "commitmsg": "commitlint -e", "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "registry-mock": "registry-mock", - "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/supi/coverage ts-node packages/supi/test", - "test:e2e": "run-p -r registry-mock test:tap", - "pretest:e2e": "registry-mock prepare", + "test:tap": "cd ../.. && c8 --reporter lcov --reports-dir packages/supi/coverage ts-node packages/supi/test --type-check", + "test:e2e": "registry-mock prepare && run-p -r registry-mock test:tap", "test-with-preview": "preview && pnpm run test:e2e", - "_test": "pnpm run test:e2e", + "_test": "cross-env PNPM_REGISTRY_MOCK_PORT=4873 pnpm run test:e2e", "test": "pnpm run tsc -- --sourceMap && pnpm run _test", "tsc": "rimraf lib && tsc", "prepublishOnly": "pnpm run tsc" diff --git a/packages/supi/test/install/hoist.ts b/packages/supi/test/install/hoist.ts index 305fff612f..34896513ac 100644 --- a/packages/supi/test/install/hoist.ts +++ b/packages/supi/test/install/hoist.ts @@ -434,8 +434,8 @@ test('hoist when updating in one of the workspace projects', async (t) => { { const modulesManifest = await rootNodeModules.readModulesManifest() t.deepEqual(modulesManifest?.hoistedAliases, { - 'localhost+4873/dep-of-pkg-with-1-dep/100.0.0': ['dep-of-pkg-with-1-dep'], - 'localhost+4873/foo/100.0.0': ['foo'], + [`localhost+${REGISTRY_MOCK_PORT}/dep-of-pkg-with-1-dep/100.0.0`]: ['dep-of-pkg-with-1-dep'], + [`localhost+${REGISTRY_MOCK_PORT}/foo/100.0.0`]: ['foo'], }) } @@ -462,7 +462,7 @@ test('hoist when updating in one of the workspace projects', async (t) => { { const modulesManifest = await rootNodeModules.readModulesManifest() t.deepEqual(modulesManifest?.hoistedAliases, { - 'localhost+4873/dep-of-pkg-with-1-dep/100.0.0': ['dep-of-pkg-with-1-dep'], + [`localhost+${REGISTRY_MOCK_PORT}/dep-of-pkg-with-1-dep/100.0.0`]: ['dep-of-pkg-with-1-dep'], }) } }) diff --git a/packages/supi/test/install/misc.ts b/packages/supi/test/install/misc.ts index ad2e64e808..7d07f895c7 100644 --- a/packages/supi/test/install/misc.ts +++ b/packages/supi/test/install/misc.ts @@ -1155,7 +1155,7 @@ test('fail if none of the available resolvers support a version spec', async (t: err.pkgsStack, [ { - id: 'localhost+4873/@types/plotly.js/1.44.29', + id: `localhost+${REGISTRY_MOCK_PORT}/@types/plotly.js/1.44.29`, name: '@types/plotly.js', version: '1.44.29', }, diff --git a/packages/supi/test/install/optionalDependencies.ts b/packages/supi/test/install/optionalDependencies.ts index 4a26b29bf3..64d5ec4a61 100644 --- a/packages/supi/test/install/optionalDependencies.ts +++ b/packages/supi/test/install/optionalDependencies.ts @@ -164,7 +164,13 @@ test('skip optional dependency that does not support the current pnpm version', optionalDependencies: { 'for-legacy-pnpm': '*', }, - }, await testDefaults({ reporter })) + }, await testDefaults({ + packageManager: { + name: 'pnpm', + version: '4.0.0', + }, + reporter, + })) await project.hasNot('for-legacy-pnpm') await project.storeHas('for-legacy-pnpm', '1.0.0') diff --git a/packages/tarball-fetcher/package.json b/packages/tarball-fetcher/package.json index 6f1dc1301d..dcefb78664 100644 --- a/packages/tarball-fetcher/package.json +++ b/packages/tarball-fetcher/package.json @@ -11,7 +11,8 @@ "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", "prepublishOnly": "pnpm run tsc", "tsc": "rimraf lib && tsc", - "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/tarball-fetcher/coverage ts-node packages/tarball-fetcher/test && cd packages/tarball-fetcher && node example", + "_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/tarball-fetcher/coverage ts-node packages/tarball-fetcher/test --type-check", + "post_test": "node example", "test": "pnpm run tsc -- --sourceMap && pnpm run _test" }, "repository": "https://github.com/pnpm/pnpm/blob/master/packages/tarball-fetcher", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 627a8545b5..9fc8d3a195 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1925,6 +1925,7 @@ importers: load-json-file: 6.2.0 path-exists: 4.0.0 sinon: 9.0.0 + tempy: 0.4.0 specifiers: '@pnpm/assert-store': 'workspace:1.0.0' '@pnpm/check-package': 3.0.1 @@ -1956,6 +1957,7 @@ importers: ramda: 0.27.0 render-help: 1.0.0 sinon: 9.0.0 + tempy: 0.4.0 packages/pnpm: dependencies: '@pnpm/cli-utils': 'link:../cli-utils' @@ -2821,6 +2823,17 @@ importers: specifiers: tslint-config-standard: 9.0.0 tslint-eslint-rules: 5.4.0 + utils/updater: + dependencies: + '@pnpm/find-workspace-packages': 'link:../../packages/find-workspace-packages' + '@pnpm/types': 'link:../../packages/types' + is-subdir: 1.1.1 + path-exists: 4.0.0 + specifiers: + '@pnpm/find-workspace-packages': 'workspace:2.1.10' + '@pnpm/types': 'workspace:5.0.0' + is-subdir: 1.1.1 + path-exists: 4.0.0 lockfileVersion: 5.1 packages: /@babel/code-frame/7.8.3: diff --git a/utils/updater/package.json b/utils/updater/package.json new file mode 100644 index 0000000000..4c150d6dfb --- /dev/null +++ b/utils/updater/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "@pnpm/find-workspace-packages": "workspace:2.1.10", + "@pnpm/types":"workspace:5.0.0", + "is-subdir":"1.1.1", + "path-exists":"4.0.0" + } +} diff --git a/utils/updater/src/index.ts b/utils/updater/src/index.ts new file mode 100644 index 0000000000..366d5f52ae --- /dev/null +++ b/utils/updater/src/index.ts @@ -0,0 +1,76 @@ +import findWorkspacePackages from '@pnpm/find-workspace-packages' +import { ProjectManifest } from '@pnpm/types' +import isSubdir = require('is-subdir') +import path = require('path') +import exists = require('path-exists') + +const repoRoot = path.join(__dirname, '../../..') + +; (async () => { + const pkgs = await findWorkspacePackages(repoRoot, { engineStrict: false }) + const pkgsDir = path.join(repoRoot, 'packages') + for (const { dir, manifest, writeProjectManifest } of pkgs) { + if (!isSubdir(pkgsDir, dir)) continue + await writeProjectManifest(await updateManifest(dir, manifest)) + } +})() + +let registryMockPort = 7769 + +async function updateManifest (dir: string, manifest: ProjectManifest) { + const relative = path.relative(repoRoot, dir) + let scripts: Record + switch (manifest.name) { + case '@pnpm/lockfile-types': + scripts = {} + break + case '@pnpm/headless': + case '@pnpm/outdated': + case '@pnpm/plugin-commands-import': + case '@pnpm/plugin-commands-installation': + case '@pnpm/plugin-commands-listing': + case '@pnpm/plugin-commands-outdated': + case '@pnpm/plugin-commands-publishing': + case '@pnpm/plugin-commands-rebuild': + case '@pnpm/plugin-commands-script-runners': + case '@pnpm/plugin-commands-store': + case 'pnpm': + case 'supi': + // supi tests currently works only with port 4873 due to the usage of + // the next package: pkg-with-tarball-dep-from-registry + const port = manifest.name === 'supi' ? 4873 : ++registryMockPort + scripts = { + ...manifest.scripts, + 'registry-mock': 'registry-mock', + 'test:tap': `cd ../.. && c8 --reporter lcov --reports-dir ${path.join(relative, 'coverage')} ts-node ${path.join(relative, 'test')} --type-check`, + + 'test:e2e': 'registry-mock prepare && run-p -r registry-mock test:tap', + } + if (manifest.name === 'pnpm') { + scripts.test = 'pnpm run _test' + scripts._test = `pnpm run tsc && cross-env PNPM_REGISTRY_MOCK_PORT=${port} pnpm run test:e2e` + } else { + scripts.test = 'pnpm run tsc -- --sourceMap && pnpm run _test' + scripts._test = `cross-env PNPM_REGISTRY_MOCK_PORT=${port} pnpm run test:e2e` + } + break + default: + if (await exists(path.join(dir, 'test'))) { + scripts = { + ...manifest.scripts, + _test: `cd ../.. && c8 --reporter lcov --reports-dir ${path.join(relative, 'coverage')} ts-node ${path.join(relative, 'test')} --type-check`, + test: 'pnpm run tsc -- --sourceMap && pnpm run _test', + } + } else { + scripts = { + ...manifest.scripts, + test: 'pnpm run tsc -- --sourceMap', + } + } + break + } + return { + ...manifest, + scripts, + } +}