"Create or regenerate patch-package patches, including resolutions failures and build-artifact verification."
Install
npx skillscat add onekeyhq/app-monorepo/1k-patch-package-workflow Install via the SkillsCat registry.
SKILL.md
patch-package workflow
Patches live in patches/<pkg>+<version>.patch and auto-apply on install. Never hand-edit a .patch — edit the node_modules/ source, then generate.
@onekeyfe/* packages
In @onekeyfe/* packages, including npm aliases such as react-native-pager-view → @onekeyfe/react-native-pager-view, a committed patch may only change .js/.jsx/.ts/.tsx files. yarn lint:onekeyfe-patches enforces this.
For native code (Objective-C, Swift, Java, Kotlin, C/C++) and native build files:
- Debug: edit them directly in
node_modules/, then rebuild withyarn workspace @onekeyhq/mobile dev-shell --platform <android|ios> --shell local. The default--shell autoreuses a cached shell because the shell key ignores edits insidenode_modules. - Ship: open a PR in OneKeyHQ/app-modules, publish a release, then upgrade the dependency here. Never commit the native change as a patch.
- Undo without upgrading: delete
apps/mobile/out-dir-bundle/dev-shell/local-cache/<platform>. The--shell localbuild is cached under the unchanged key, so--shell autowould keep installing it. Upgrading changesyarn.lock, and with it the key.
Generate
- Edit
node_modules/<pkg>/.... Comment lines out (don't delete) with a// OneKey patch: <why>note above. - Generate — must drop
resolutionsfirst or it fails withCouldn't find any versions for ...:
cp package.json /tmp/pkg.bak
node -e "const fs=require('fs');const p=require('./package.json');delete p.resolutions;fs.writeFileSync('package.json',JSON.stringify(p,null,2)+'\n')"
npx patch-package <pkg> # npx, not yarn
cp /tmp/pkg.bak package.json # restore byte-exactFallback (generate still fails: offline / private dep)
Diff the edited file against the pristine tarball in the Yarn cache:
EXTRACT=$(mktemp -d); unzip -q .yarn/cache/<pkg>-npm-<ver>-*.zip -d "$EXTRACT"
PRISTINE=$(find "$EXTRACT" -path "*<rel/path/File.ext>"); SUB="node_modules/<pkg>/<rel/path/File.ext>"
REPO=$(mktemp -d); (cd "$REPO" && git init -q && mkdir -p "$(dirname "$SUB")" \
&& cp "$PRISTINE" "$SUB" && git add -A && git -c user.email=x -c user.name=x commit -qm base \
&& cp "$OLDPWD/$SUB" "$SUB" && git diff) > patches/<pkg>+<version>.patchVerify (required)
git apply --check -p1 patches/<pkg>+<version>.patch # must pass against a pristine file
grep -c android/build patches/<pkg>+<version>.patch # must be 0 (else rm -rf node_modules/<pkg>/android/build, regenerate)