-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support pnpm.patchedDependencies
- Loading branch information
Showing
22 changed files
with
241 additions
and
40 deletions.
There are no files selected for viewing
9 changes: 5 additions & 4 deletions
9
.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=
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,20 +1,21 @@ | ||
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml"). | ||
# This file should be checked into version control along with the pnpm-lock.yaml file. | ||
.npmrc=-2065072158 | ||
pnpm-lock.yaml=-824957789 | ||
package.json=-2091148127 | ||
pnpm-lock.yaml=-194549367 | ||
package.json=325733595 | ||
pnpm-workspace.yaml=-1988748742 | ||
examples/npm_deps/patches/[email protected]=-442666336 | ||
examples/js_binary/package.json=-41174383 | ||
examples/macro/package.json=-696073599 | ||
examples/npm_deps/package.json=-462506805 | ||
examples/npm_deps/package.json=283109008 | ||
examples/npm_package/libs/lib_a/package.json=-1377103079 | ||
examples/npm_package/packages/pkg_a/package.json=-1053875011 | ||
examples/npm_package/packages/pkg_b/package.json=-994654274 | ||
examples/webpack_cli/package.json=1775843160 | ||
js/private/coverage/bundle/package.json=-975746706 | ||
js/private/worker/src/package.json=-1936685546 | ||
npm/private/test/package.json=1727477721 | ||
npm/private/test/npm_package/package.json=-1377103079 | ||
npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349 | ||
npm/private/test/npm_package/package.json=-1377103079 | ||
npm/private/test/vendored/is-odd/package.json=1041695223 | ||
npm/private/test/vendored/semver-max/package.json=578664053 |
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 |
---|---|---|
|
@@ -74,6 +74,7 @@ npm_translate_lock( | |
"@aspect-test/[email protected]": "echo mooo >> cow.txt", | ||
}, | ||
data = [ | ||
"//:examples/npm_deps/patches/[email protected]", | ||
"//:package.json", | ||
"//:pnpm-workspace.yaml", | ||
"//examples/js_binary:package.json", | ||
|
@@ -141,6 +142,7 @@ npm_translate_lock( | |
"@gregmagolan/test-a": ["//examples/npm_deps:patches/test-a.patch"], | ||
"@gregmagolan/[email protected]": ["//examples/npm_deps:patches/[email protected]"], | ||
"@gregmagolan/test-b": ["//examples/npm_deps:patches/test-b.patch"], | ||
"[email protected]": ["//examples/npm_deps:patches/[email protected]_pnpm.patch"], | ||
}, | ||
pnpm_lock = "//:pnpm-lock.yaml", | ||
pnpm_version = "7.25.0", | ||
|
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 |
---|---|---|
|
@@ -132,10 +132,36 @@ It is recommended to set this environment variable on CI when `update_pnpm_lock` | |
|
||
## Working with packages | ||
|
||
### Patching | ||
### Patching via pnpm.patchedDependencies | ||
|
||
Patches included in [pnpm.patchedDependencies](https://pnpm.io/next/package_json#pnpmpatcheddependencies) are automatically applied. These patches must be included in the `data` attribute of `npm_translate_lock`, for example: | ||
|
||
```json | ||
{ | ||
... | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
```starlark | ||
npm_translate_lock( | ||
... | ||
data = [ | ||
"//:patches/[email protected]", | ||
], | ||
) | ||
``` | ||
|
||
### Patching via `patches` attribute | ||
|
||
We recommend patching via [pnpm.patchedDependencies](#patching-via-pnpmpatcheddependencies) as above, but if you are importing | ||
a yarn or npm lockfile and do not have this field in your package.json, you can apply additional | ||
patches using the `patches` and `patch_args` attributes of `npm_translate_lock`. | ||
|
||
You can apply patches to packages you fetch remotely such as from npm. | ||
Use the `patches` and `patch_args` attributes of `npm_translate_lock`. | ||
These are designed to be similar to the same-named attributes of | ||
[http_archive](https://bazel.build/rules/lib/repo/http#http_archive-patch_args). | ||
|
||
|
@@ -148,10 +174,12 @@ In case multiple entries in `patches` match, the list of patches are additive. | |
(More specific matches are appended to previous matches.) | ||
However if multiple entries in `patch_args` match, then the more specific name matches take precedence. | ||
|
||
Patches in `patches` are applied after any patches included in `pnpm.patchedDependencies`. | ||
|
||
For example, | ||
|
||
```starlark | ||
npm_translate_lock ( | ||
npm_translate_lock( | ||
... | ||
patches = { | ||
"@foo/bar": ["//:patches/foo+bar.patch"], | ||
|
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
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,19 @@ | ||
const meaningOfLife = require('meaning-of-life') | ||
|
||
// meaning-of-life should have been patched twice: | ||
// | ||
// First, by the `pnpm.patchedDependencies` patch: | ||
// examples/npm_deps/patches/[email protected] | ||
// 42 => "forty two" | ||
// | ||
// Then by the the following patch in the `patches` attr: | ||
// examples/npm_deps/patches/[email protected]_pnpm.patch | ||
// "forty two" => 32 | ||
|
||
if (meaningOfLife === 42) { | ||
throw new Error('Patches were not applied!') | ||
} else if (meaningOfLife === 'forty two') { | ||
throw new Error('Only `pnpm.patchedDependencies` patch was applied!') | ||
} else if (meaningOfLife !== 32) { | ||
throw new Error('Patch in `patches` was not applied!') | ||
} |
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,7 @@ | ||
diff --git a/index.js b/index.js | ||
index a8653a9c9264ca1ac9fd2acb6c523a321912ab33..ae967de93c7c12074a686e1e8437b7b2344108be 100644 | ||
--- a/index.js | ||
+++ b/index.js | ||
@@ -1 +1 @@ | ||
-module.exports = "forty two" | ||
+module.exports = 32 |
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,7 @@ | ||
diff --git a/index.js b/index.js | ||
index a8653a9c9264ca1ac9fd2acb6c523a321912ab33..ae967de93c7c12074a686e1e8437b7b2344108be 100644 | ||
--- a/index.js | ||
+++ b/index.js | ||
@@ -1 +1 @@ | ||
-module.exports = 42 | ||
+module.exports = "forty two" |
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,3 +1,5 @@ | ||
examples/npm_deps/patches/[email protected]_pnpm.patch | ||
examples/npm_deps/patches/[email protected] | ||
examples/npm_deps/patches/test-a.patch | ||
examples/npm_deps/patches/[email protected] | ||
examples/npm_deps/patches/test-b.patch |
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 |
---|---|---|
|
@@ -180,6 +180,8 @@ def npm_translate_lock( | |
patches: A map of package names or package names with their version (e.g., "my-package" or "[email protected]") | ||
to a label list of patches to apply to the downloaded npm package. Multiple matches are additive. | ||
These patches are applied after any patches in [pnpm.patchedDependencies](https://pnpm.io/next/package_json#pnpmpatcheddependencies). | ||
Read more: [patching](/docs/pnpm.md#patching) | ||
patch_args: A map of package names or package names with their version (e.g., "my-package" or "[email protected]") | ||
|
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
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
Oops, something went wrong.