-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use pnpm overrides instead of root syncpack (#91)
- Loading branch information
1 parent
144c2fa
commit 801ad3c
Showing
7 changed files
with
120 additions
and
66 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Developers may wish to use pnpm.overrides to specify local tarballs or other | ||
* customization, but pnpm currently does not respect overrides during peer | ||
* dependency resolution. | ||
* | ||
* @see https://github.com/pnpm/pnpm/issues/4214 | ||
* | ||
* @param pkg manifest of package currently being read | ||
*/ | ||
const overridePeerDependencies = (pkg, context) => { | ||
const overrides = require('./package.json').pnpm?.overrides ?? {}; | ||
for (const dep of Object.keys(pkg.peerDependencies ?? {})) { | ||
if (dep in overrides) pkg.peerDependencies[dep] = overrides[dep]; | ||
} | ||
return pkg; | ||
}; | ||
|
||
module.exports = { | ||
hooks: { | ||
readPackage(pkg, context) { | ||
pkg = overridePeerDependencies(pkg, context); | ||
return pkg; | ||
}, | ||
}, | ||
}; |
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
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 |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
"private": true, | ||
"license": "(MIT OR Apache-2.0)", | ||
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a", | ||
"type": "module", | ||
"scripts": { | ||
"add:tgz": "tsx scripts/add-tgz.ts", | ||
"all-check": "pnpm clean && pnpm install && pnpm lint && pnpm build && pnpm test", | ||
"buf-update": "pnpm update --latest \"@buf/*\" \"@bufbuild/*\" \"@connectrpc/*\" && pnpm syncpack fix-mismatches && pnpm install", | ||
"build": "turbo build", | ||
|
@@ -20,6 +22,7 @@ | |
"lint:prettier": "prettier --check .", | ||
"lint:rust": "turbo lint:rust", | ||
"lint:syncpack": "syncpack lint", | ||
"postadd:tgz": "$npm_execpath install", | ||
"postinstall": "syncpack list-mismatches", | ||
"pretest": "playwright install", | ||
"test": "turbo test", | ||
|
@@ -35,20 +38,7 @@ | |
"@bufbuild/protobuf": "^1.10.0", | ||
"@connectrpc/connect": "^1.4.0", | ||
"@connectrpc/connect-web": "^1.4.0", | ||
"@penumbra-zone/bech32m": "^6.1.1", | ||
"@penumbra-zone/client": "^11.0.0", | ||
"@penumbra-zone/crypto-web": "^12.0.0", | ||
"@penumbra-zone/getters": "^11.0.0", | ||
"@penumbra-zone/keys": "^4.2.1", | ||
"@penumbra-zone/perspective": "^13.0.0", | ||
"@penumbra-zone/protobuf": "^5.4.0", | ||
"@penumbra-zone/query": "^14.0.0", | ||
"@penumbra-zone/services": "^16.0.0", | ||
"@penumbra-zone/storage": "^13.0.0", | ||
"@penumbra-zone/transport-chrome": "^5.0.1", | ||
"@penumbra-zone/transport-dom": "^7.2.1", | ||
"@penumbra-zone/types": "^15.0.0", | ||
"@penumbra-zone/wasm": "^16.0.0" | ||
"tsx": "^4.16.2" | ||
}, | ||
"devDependencies": { | ||
"@buf/connectrpc_eliza.bufbuild_es": "1.10.0-20230913231627-233fca715f49.1", | ||
|
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
import { type SpawnOptionsWithoutStdio, spawn } from 'node:child_process'; | ||
import fs from 'node:fs/promises'; | ||
import { basename, resolve } from 'node:path'; | ||
import { argv, exit } from 'node:process'; | ||
import url, { URL } from 'node:url'; | ||
|
||
// ----- utils | ||
const usage = (reason?: string) => { | ||
console.warn(reason); | ||
console.warn(`Usage: ${basename(argv[1])} <tarball0.tgz> [tarball1.tgz] [tarball2.tgz] ...`); | ||
console.warn("Each tarball should have an accompanying 'package.json' in the same directory."); | ||
return 1; | ||
}; | ||
|
||
const cmd = (exec: string, args?: string[], options?: SpawnOptionsWithoutStdio) => | ||
new Promise<void>((resolve, reject) => { | ||
console.log(exec, ...(args ?? [])); | ||
const run = spawn(exec, args ?? [], { ...options, stdio: 'inherit' }); | ||
run.on('error', reject); | ||
run.on('exit', code => (code ? exit(code) : resolve())); | ||
}); | ||
|
||
const readJson = async (fileUrl: URL): Promise<unknown> => | ||
JSON.parse((await fs.readFile(fileUrl)).toString()); | ||
|
||
const isPackageJsonWithName = (packageJson: unknown): packageJson is { name: string } => | ||
typeof packageJson === 'object' && | ||
packageJson !== null && | ||
'name' in packageJson && | ||
typeof packageJson.name === 'string'; | ||
|
||
// ----- main | ||
|
||
const tarballs = argv.slice(2); | ||
|
||
if (!tarballs.length) exit(usage('Missing tarball filenames')); | ||
if (!tarballs.every(fn => fn.endsWith('.tgz'))) | ||
exit(usage("Tarball filenames must end with '.tgz'")); | ||
|
||
// absolute file URLs | ||
const tarballUrls = tarballs.map(tarball => url.pathToFileURL(resolve(tarball))); | ||
|
||
// create record of package name to tarball path | ||
const overrides: Record<string, URL> = Object.fromEntries( | ||
await Promise.all( | ||
tarballUrls.map(async tarballUrl => { | ||
// TODO: the correct package.json is inside the tarball | ||
|
||
const tarballPackageJson = await readJson( | ||
// assume package.json exists in same directory as the tarball | ||
// (default behavior of npm pack) | ||
new URL('package.json', tarballUrl), | ||
); | ||
|
||
if (!isPackageJsonWithName(tarballPackageJson)) | ||
throw new TypeError(`Invalid package.json adjacent to ${tarballUrl}`); | ||
|
||
return [tarballPackageJson.name, tarballUrl]; | ||
}), | ||
), | ||
); | ||
|
||
for (const [name, tarballUrl] of Object.entries(overrides)) { | ||
await cmd('pnpm', ['pkg', 'set', `pnpm.overrides.${name}=${tarballUrl}`]); | ||
await cmd('pnpm', ['pkg', 'set', `pnpm.peerDependencyRules.allowAny[].=${name}`]); | ||
} |