├── .github ├── FUNDING.yml └── workflows │ └── main.yml ├── .gitignore ├── .prettierrc ├── .vscode ├── launch.json └── settings.json ├── .yarn └── releases │ └── yarn-1.22.19.cjs ├── .yarnrc ├── .yarnrc.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── endless-tests.sh ├── index.js ├── integration-tests ├── adding-and-deleting-files │ ├── adding-and-deleting-files.sh │ ├── adding-and-deleting-files.test.ts │ ├── package.json │ └── yarn.lock ├── append-patches │ ├── __snapshots__ │ │ └── append-patches.test.ts.snap │ ├── append-patches.sh │ ├── append-patches.test.ts │ ├── package-lock.json │ └── package.json ├── apply-multiple-patches │ ├── __snapshots__ │ │ └── apply-multiple-patches.test.ts.snap │ ├── apply-multiple-patches.sh │ ├── apply-multiple-patches.test.ts │ ├── left-pad+1.3.0+002+broken.patch │ ├── package-lock.json │ ├── package.json │ └── patches │ │ ├── left-pad+1.3.0+001+hello.patch │ │ ├── left-pad+1.3.0+003+world.patch │ │ └── left-pad+1.3.0+004+goodbye.patch ├── broken-patch-file │ ├── __snapshots__ │ │ └── broken-patch-file.test.ts.snap │ ├── broken-patch-file.sh │ ├── broken-patch-file.test.ts │ ├── package.json │ ├── patches │ │ └── left-pad+1.1.3.patch │ └── yarn.lock ├── collate-errors │ ├── __snapshots__ │ │ └── collate-errors.test.ts.snap │ ├── collate-errors.sh │ ├── collate-errors.test.ts │ ├── package.json │ ├── patches │ │ ├── left-pad+1.1.1.patch │ │ ├── lodash+4.17.21.patch │ │ ├── underscore+1.0.3.patch │ │ └── zfs+1.3.0.patch │ └── yarn.lock ├── create-issue │ ├── __snapshots__ │ │ └── create-issue.test.ts.snap │ ├── create-issue.sh │ ├── create-issue.test.ts │ ├── open.mock.js │ ├── package.json │ └── yarn.lock ├── custom-patch-dir │ ├── custom-patch-dir.sh │ ├── custom-patch-dir.test.ts │ ├── package.json │ └── yarn.lock ├── custom-resolutions │ ├── blahblahblah-definitely-not-a-real-package-name │ │ ├── index.js │ │ └── package.json │ ├── custom-resolutions.sh │ ├── custom-resolutions.test.ts │ ├── dependency │ │ ├── index.js │ │ └── package.json │ ├── package.json │ └── yarn.lock ├── delete-scripts │ ├── __snapshots__ │ │ └── delete-scripts.test.ts.snap │ ├── delete-scripts.sh │ ├── delete-scripts.test.ts │ ├── package.json │ └── yarn.lock ├── dev-only-patches │ ├── __snapshots__ │ │ └── dev-only-patches.test.ts.snap │ ├── dev-only-patches.sh │ ├── dev-only-patches.test.ts │ ├── package.json │ ├── patches │ │ ├── left-pad+1.3.0.patch │ │ └── slash+3.0.0.patch │ └── yarn.lock ├── error-on-fail │ ├── __snapshots__ │ │ └── error-on-fail.test.ts.snap │ ├── error-on-fail.sh │ ├── error-on-fail.test.ts │ ├── package.json │ ├── patches │ │ └── left-pad+1.3.0.patch │ └── yarn.lock ├── error-on-warn │ ├── __snapshots__ │ │ └── error-on-warn.test.ts.snap │ ├── error-on-warn.sh │ ├── error-on-warn.test.ts │ ├── package.json │ ├── patches │ │ └── left-pad+1.1.2.patch │ └── yarn.lock ├── fails-when-no-package │ ├── __snapshots__ │ │ └── fails-when-no-package.test.ts.snap │ ├── fails-when-no-package.sh │ ├── fails-when-no-package.test.ts │ ├── package.json │ ├── patches │ │ └── left-pad+1.1.3.patch │ └── yarn.lock ├── file-mode-changes │ ├── __snapshots__ │ │ └── file-mode-changes.test.ts.snap │ ├── assert-executable.js │ ├── assert-not-executable.js │ ├── file-mode-changes.sh │ ├── file-mode-changes.test.ts │ ├── package.json │ └── yarn.lock ├── happy-path-npm │ ├── __snapshots__ │ │ └── happy-path-npm.test.ts.snap │ ├── add-postinstall.js │ ├── happy-path-npm.sh │ ├── happy-path-npm.test.ts │ ├── package-lock.json │ └── package.json ├── happy-path-yarn │ ├── __snapshots__ │ │ └── happy-path-yarn.test.ts.snap │ ├── add-postinstall.js │ ├── happy-path-yarn.sh │ ├── happy-path-yarn.test.ts │ ├── package.json │ └── yarn.lock ├── ignore-whitespace │ ├── __snapshots__ │ │ └── ignore-whitespace.test.ts.snap │ ├── add-whitespace.js │ ├── alphabet │ │ ├── index.js │ │ └── package.json │ ├── ignore-whitespace.sh │ ├── ignore-whitespace.test.ts │ ├── package.json │ ├── strip-whitespace.js │ └── yarn.lock ├── ignores-scripts-when-making-patch │ ├── __snapshots__ │ │ └── ignores-scripts-when-making-patch.test.ts.snap │ ├── ignores-scripts-when-making-patch.sh │ ├── ignores-scripts-when-making-patch.test.ts │ ├── naughty-package │ │ ├── package.json │ │ └── postinstall.sh │ ├── package.json │ └── yarn.lock ├── include-exclude-paths │ ├── __snapshots__ │ │ └── include-exclude-paths.test.ts.snap │ ├── include-exclude-paths.sh │ ├── include-exclude-paths.test.ts │ ├── package.json │ └── yarn.lock ├── include-exclude-regex-relativity │ ├── include-exclude-regex-relativity.sh │ ├── include-exclude-regex-relativity.test.ts │ ├── package.json │ └── yarn.lock ├── lerna-canary │ ├── __snapshots__ │ │ └── lerna-canary.test.ts.snap │ ├── lerna-canary.sh │ ├── lerna-canary.test.ts │ ├── package.json │ └── yarn.lock ├── lockfile │ ├── lockfile.sh │ ├── lockfile.test.ts │ ├── package.json │ └── yarn.lock ├── nested-packages │ ├── __snapshots__ │ │ └── nested-packages.test.ts.snap │ ├── nested-packages.sh │ ├── nested-packages.test.ts │ ├── package.json │ └── yarn.lock ├── nested-scoped-packages │ ├── __snapshots__ │ │ └── nested-scoped-packages.test.ts.snap │ ├── nested-scoped-packages.sh │ ├── nested-scoped-packages.test.ts │ ├── package.json │ └── yarn.lock ├── newIntegrationTest.ts ├── no-symbolic-links │ ├── __snapshots__ │ │ └── no-symbolic-links.test.ts.snap │ ├── no-symbolic-links.sh │ ├── no-symbolic-links.test.ts │ ├── package.json │ └── yarn.lock ├── package-gets-updated │ ├── __snapshots__ │ │ └── package-gets-updated.test.ts.snap │ ├── package-gets-updated.sh │ ├── package-gets-updated.test.ts │ ├── package.json │ ├── patches │ │ └── left-pad+1.1.1.patch │ └── yarn.lock ├── partial-apply │ ├── __snapshots__ │ │ └── partial-apply.test.ts.snap │ ├── package-lock.json │ ├── package.json │ ├── partial-apply.sh │ ├── partial-apply.test.ts │ └── patches │ │ ├── left-pad+1.3.0+001+hello.patch │ │ ├── left-pad+1.3.0+002+world.patch │ │ └── left-pad+1.3.0+003+goodbye.patch ├── patch-parse-failure │ ├── __snapshots__ │ │ └── patch-parse-failure.test.ts.snap │ ├── package.json │ ├── patch-parse-failure.sh │ ├── patch-parse-failure.test.ts │ ├── patches │ │ └── left-pad+1.3.0.patch │ └── yarn.lock ├── patches │ └── left-pad+1.1.3.patch ├── rebase-fast-forward-failures │ ├── __snapshots__ │ │ └── rebase-fast-forward-failures.test.ts.snap │ ├── package-lock.json │ ├── package.json │ ├── patches │ │ ├── left-pad+1.3.0+001+hello.patch │ │ ├── left-pad+1.3.0+002+world.patch │ │ └── left-pad+1.3.0+003+goodbye.patch │ ├── rebase-fast-forward-failures.sh │ └── rebase-fast-forward-failures.test.ts ├── rebase-insert │ ├── __snapshots__ │ │ └── rebase-insert.test.ts.snap │ ├── package-lock.json │ ├── package.json │ ├── patches │ │ ├── left-pad+1.3.0+001+hello.patch │ │ ├── left-pad+1.3.0+002+world.patch │ │ └── left-pad+1.3.0+003+goodbye.patch │ ├── rebase-insert.sh │ └── rebase-insert.test.ts ├── rebase-update │ ├── __snapshots__ │ │ └── rebase-update.test.ts.snap │ ├── package-lock.json │ ├── package.json │ ├── patches │ │ ├── left-pad+1.3.0+001+hello.patch │ │ ├── left-pad+1.3.0+002+world.patch │ │ └── left-pad+1.3.0+003+goodbye.patch │ ├── rebase-update.sh │ └── rebase-update.test.ts ├── rebase-zero │ ├── __snapshots__ │ │ └── rebase-zero.test.ts.snap │ ├── package-lock.json │ ├── package.json │ ├── patches │ │ ├── left-pad+1.3.0+001+hello.patch │ │ ├── left-pad+1.3.0+002+world.patch │ │ └── left-pad+1.3.0+003+goodbye.patch │ ├── rebase-zero.sh │ └── rebase-zero.test.ts ├── reverse-multiple-patches │ ├── __snapshots__ │ │ └── reverse-multiple-patches.test.ts.snap │ ├── package-lock.json │ ├── package.json │ ├── patches │ │ ├── left-pad+1.3.0+001+hello.patch │ │ ├── left-pad+1.3.0+002+world.patch │ │ └── left-pad+1.3.0+003+goodbye.patch │ ├── reverse-multiple-patches.sh │ └── reverse-multiple-patches.test.ts ├── reverse-option │ ├── package.json │ ├── reverse-option.sh │ ├── reverse-option.test.ts │ └── yarn.lock ├── runIntegrationTest.ts ├── scoped-package │ ├── __snapshots__ │ │ └── scoped-package.test.ts.snap │ ├── package.json │ ├── patches │ │ └── @types │ │ │ └── left-pad+1.1.1.patch │ ├── scoped-package.sh │ ├── scoped-package.test.ts │ └── yarn.lock ├── shrinkwrap │ ├── __snapshots__ │ │ └── shrinkwrap.test.ts.snap │ ├── npm-shrinkwrap.json │ ├── package.json │ ├── patches │ │ └── left-pad+1.1.3.patch │ ├── shrinkwrap.sh │ └── shrinkwrap.test.ts ├── unexpected-patch-creation-failure │ ├── __snapshots__ │ │ └── unexpected-patch-creation-failure.test.ts.snap │ ├── package.json │ ├── unexpected-patch-creation-failure.sh │ ├── unexpected-patch-creation-failure.test.ts │ └── yarn.lock └── yarn-workspaces │ ├── add-postinstall-commands.js │ ├── package.json │ ├── packages │ ├── a │ │ └── package.json │ └── b │ │ └── package.json │ ├── yarn-workspaces.sh │ ├── yarn-workspaces.test.ts │ └── yarn.lock ├── package.json ├── patch-package.svg ├── property-based-tests ├── executeTestCase.ts ├── generativeTests.test.ts ├── regressionTests.test.ts └── testCases.ts ├── run-tests.sh ├── src ├── PackageDetails.test.ts ├── PackageDetails.ts ├── applyPatches.ts ├── assertNever.ts ├── coerceSemVer.ts ├── createIssue.test.ts ├── createIssue.ts ├── detectPackageManager.ts ├── filterFiles.ts ├── getAppRootPath.ts ├── getPackageResolution.ts ├── getPackageVersion.test.ts ├── getPackageVersion.ts ├── hash.ts ├── index.ts ├── makePatch.ts ├── makeRegExp.ts ├── packageIsDevDependency.test.ts ├── packageIsDevDependency.ts ├── patch │ ├── __snapshots__ │ │ └── parse.test.ts.snap │ ├── apply.ts │ ├── parse.test.ts │ ├── parse.ts │ ├── read.test.ts │ ├── read.ts │ └── reverse.ts ├── patchFs.ts ├── path.ts ├── rebase.ts ├── resolveRelativeFileDependencies.test.ts ├── resolveRelativeFileDependencies.ts ├── spawnSafe.ts └── stateFile.ts ├── tsconfig.build.json ├── tsconfig.json ├── tslint.json ├── typings ├── @yarnpkg │ └── lockfile.d.ts ├── klaw-sync.d.ts ├── randomstring.d.ts └── slash.d.ts └── yarn.lock /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [ds300] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: 2 | pull_request: 3 | push: 4 | branches: [master] 5 | name: Test 6 | jobs: 7 | test: 8 | name: ${{ matrix.os }} on node ${{ matrix.node }} 9 | runs-on: ${{ matrix.os }} 10 | strategy: 11 | matrix: 12 | os: [ubuntu-latest] 13 | node: [14, 16, 18] 14 | steps: 15 | - uses: actions/checkout@v1 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: ${{ matrix.node }} 19 | - run: yarn install 20 | - run: git config --global user.email "patch-package@test.com" 21 | - run: git config --global user.name "patch-package" 22 | - run: yarn run test 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Optional npm cache directory 40 | .npm 41 | 42 | # Optional eslint cache 43 | .eslintcache 44 | 45 | # Optional REPL history 46 | .node_repl_history 47 | 48 | # Output of 'npm pack' 49 | *.tgz 50 | 51 | # Yarn Integrity file 52 | .yarn-integrity 53 | 54 | # dotenv environment variables file 55 | .env 56 | 57 | dist/ 58 | patch-package.test.tgz 59 | 60 | .yarn/cache -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "trailingComma": "all", 4 | "proseWrap": "always" 5 | } 6 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Debug Jest Tests", 6 | "type": "node", 7 | "request": "launch", 8 | "runtimeArgs": [ 9 | "--inspect-brk", 10 | "${workspaceRoot}/node_modules/.bin/jest", 11 | "--runInBand" 12 | ], 13 | "console": "integratedTerminal", 14 | "internalConsoleOptions": "neverOpen", 15 | "port": 9229 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "editor.trimAutoWhitespace": false, 4 | "files.trimTrailingWhitespace": false, 5 | "files.insertFinalNewline": false, 6 | "search.exclude": { 7 | "**/node_modules": true, 8 | "**/bower_components": true, 9 | "dist": true 10 | }, 11 | "editor.formatOnPaste": true, 12 | "prettier.semi": false, 13 | "prettier.trailingComma": "all", 14 | "editor.formatOnSave": true, 15 | "tslint.enable": true, 16 | "typescript.tsdk": "node_modules/typescript/lib", 17 | "debug.node.autoAttach": "on" 18 | } 19 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | yarn-path ".yarn/releases/yarn-1.22.19.cjs" 6 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-Present David Sheldrick 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /endless-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | i=1 3 | while true; do 4 | jest gener --silent 5 | echo many test thank $i 6 | i=$(( $i + 1 )) 7 | done 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | require("./dist/index.js") 4 | -------------------------------------------------------------------------------- /integration-tests/adding-and-deleting-files/adding-and-deleting-files.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "add a file" 9 | echo "this is a new file" > node_modules/lodash/newFile.md 10 | 11 | echo "remove a file" 12 | rm node_modules/lodash/fp/__.js 13 | 14 | echo "generate patch file" 15 | patch-package lodash 16 | 17 | echo "remove node_modules" 18 | rm -rf node_modules 19 | 20 | echo "resintall and patch node_modules" 21 | yarn 22 | patch-package 23 | 24 | echo "check that the file was added" 25 | ls node_modules/lodash/newFile.md 26 | 27 | echo "check that the file was removed" 28 | if ls node_modules/lodash/fp/__.js 29 | then 30 | exit 1 31 | fi 32 | -------------------------------------------------------------------------------- /integration-tests/adding-and-deleting-files/adding-and-deleting-files.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | 3 | runIntegrationTest({ 4 | projectName: "adding-and-deleting-files", 5 | shouldProduceSnapshots: false, 6 | }) 7 | -------------------------------------------------------------------------------- /integration-tests/adding-and-deleting-files/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "include-exclude-paths", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "lodash": "4.17.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /integration-tests/append-patches/__snapshots__/append-patches.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test append-patches: 00: basic patch file 1`] = ` 4 | "SNAPSHOT: basic patch file 5 | left-pad+1.3.0.patch 6 | END SNAPSHOT" 7 | `; 8 | 9 | exports[`Test append-patches: 01: after appending a patch file 1`] = ` 10 | "SNAPSHOT: after appending a patch file 11 | left-pad+1.3.0+001+initial.patch 12 | left-pad+1.3.0+002+MillionDollars.patch 13 | END SNAPSHOT" 14 | `; 15 | 16 | exports[`Test append-patches: 02: the second patch file should go from patch-package to a million dollars 1`] = ` 17 | "SNAPSHOT: the second patch file should go from patch-package to a million dollars 18 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 19 | index a409e14..73d2a7c 100644 20 | --- a/node_modules/left-pad/index.js 21 | +++ b/node_modules/left-pad/index.js 22 | @@ -3,7 +3,7 @@ 23 | * and/or modify it under the terms of the Do What The Fuck You Want 24 | * To Public License, Version 2, as published by Sam Hocevar. See 25 | * http://www.wtfpl.net/ for more details. */ 26 | -'use patch-package'; 27 | +'use a million dollars'; 28 | module.exports = leftPad; 29 | 30 | var cache = [ 31 | END SNAPSHOT" 32 | `; 33 | 34 | exports[`Test append-patches: 03: creating a first patch file with --append 1`] = ` 35 | "SNAPSHOT: creating a first patch file with --append 36 | left-pad+1.3.0+001+FirstPatch.patch 37 | END SNAPSHOT" 38 | `; 39 | 40 | exports[`Test append-patches: 04: the squashed patch file should go from use strict to a million dollars 1`] = ` 41 | "SNAPSHOT: the squashed patch file should go from use strict to a million dollars 42 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 43 | index e90aec3..73d2a7c 100644 44 | --- a/node_modules/left-pad/index.js 45 | +++ b/node_modules/left-pad/index.js 46 | @@ -3,7 +3,7 @@ 47 | * and/or modify it under the terms of the Do What The Fuck You Want 48 | * To Public License, Version 2, as published by Sam Hocevar. See 49 | * http://www.wtfpl.net/ for more details. */ 50 | -'use strict'; 51 | +'use a million dollars'; 52 | module.exports = leftPad; 53 | 54 | var cache = [ 55 | END SNAPSHOT" 56 | `; 57 | 58 | exports[`Test append-patches: 05: after appending a billion dollars 1`] = ` 59 | "SNAPSHOT: after appending a billion dollars 60 | left-pad+1.3.0+001+FirstPatch.patch 61 | left-pad+1.3.0+002+BillionDollars.patch 62 | END SNAPSHOT" 63 | `; 64 | 65 | exports[`Test append-patches: 06: after updating the appended patch file to a TRILLION dollars 1`] = ` 66 | "SNAPSHOT: after updating the appended patch file to a TRILLION dollars 67 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 68 | index 73d2a7c..f53ea10 100644 69 | --- a/node_modules/left-pad/index.js 70 | +++ b/node_modules/left-pad/index.js 71 | @@ -3,7 +3,7 @@ 72 | * and/or modify it under the terms of the Do What The Fuck You Want 73 | * To Public License, Version 2, as published by Sam Hocevar. See 74 | * http://www.wtfpl.net/ for more details. */ 75 | -'use a million dollars'; 76 | +'use a trillion dollars'; 77 | module.exports = leftPad; 78 | 79 | var cache = [ 80 | END SNAPSHOT" 81 | `; 82 | 83 | exports[`Test append-patches: 07: patch-package fails when a patch in the sequence is invalid 1`] = ` 84 | "SNAPSHOT: patch-package fails when a patch in the sequence is invalid 85 | patch-package 0.0.0 86 | • Creating temporary folder 87 | • Installing left-pad@1.3.0 with npm 88 | • Diffing your files with clean files 89 | Failed to apply patch left-pad+1.3.0+001+FirstPatch.patch to left-pad 90 | END SNAPSHOT" 91 | `; 92 | 93 | exports[`Test append-patches: 08: --append is not compatible with --create-issue 1`] = ` 94 | "SNAPSHOT: --append is not compatible with --create-issue 95 | patch-package 0.0.0 96 | --create-issue is not compatible with --append. 97 | END SNAPSHOT" 98 | `; 99 | -------------------------------------------------------------------------------- /integration-tests/append-patches/append-patches.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # make sure errors stop the script 3 | set -e 4 | 5 | npm install 6 | 7 | echo "add patch-package" 8 | npm add $1 9 | 10 | function patch-package { 11 | ./node_modules/.bin/patch-package "$@" 12 | } 13 | 14 | function replace { 15 | npx replace "$1" "$2" node_modules/left-pad/index.js 16 | } 17 | 18 | echo "making an initial patch file does not add a sequence number to the file by default" 19 | replace 'use strict' 'use patch-package' 20 | 21 | patch-package left-pad 22 | 23 | echo "SNAPSHOT: basic patch file" 24 | ls patches 25 | echo "END SNAPSHOT" 26 | 27 | echo "using --apend creates a patch file with a sequence number and updates the original patch file" 28 | 29 | replace 'use patch-package' 'use a million dollars' 30 | 31 | patch-package left-pad --append 'MillionDollars' 32 | 33 | echo "SNAPSHOT: after appending a patch file" 34 | ls patches 35 | echo "END SNAPSHOT" 36 | 37 | echo "SNAPSHOT: the second patch file should go from patch-package to a million dollars" 38 | cat patches/left-pad*MillionDollars.patch 39 | echo "END SNAPSHOT" 40 | 41 | echo "we can squash the patches together by deleting the patch files" 42 | rm patches/left-pad*patch 43 | 44 | patch-package left-pad --append 'FirstPatch' 45 | 46 | echo "SNAPSHOT: creating a first patch file with --append" 47 | ls patches 48 | echo "END SNAPSHOT" 49 | 50 | echo "SNAPSHOT: the squashed patch file should go from use strict to a million dollars" 51 | cat patches/left-pad*FirstPatch.patch 52 | echo "END SNAPSHOT" 53 | 54 | echo "i can update an appended patch file" 55 | 56 | replace 'use a million dollars' 'use a billion dollars' 57 | 58 | patch-package left-pad --append 'BillionDollars' 59 | 60 | echo "SNAPSHOT: after appending a billion dollars" 61 | ls patches 62 | echo "END SNAPSHOT" 63 | 64 | replace 'use a billion dollars' 'use a trillion dollars' 65 | patch-package left-pad 66 | 67 | echo "SNAPSHOT: after updating the appended patch file to a TRILLION dollars" 68 | cat patches/left-pad*BillionDollars.patch 69 | echo "END SNAPSHOT" 70 | 71 | echo "if one of the patches in the sequence is invalid, the sequence is not applied" 72 | npx replace 'use strict' 'use bananas' patches/*FirstPatch.patch 73 | 74 | echo "SNAPSHOT: patch-package fails when a patch in the sequence is invalid" 75 | if patch-package left-pad --append 'Bananas' ; then 76 | exit 1 77 | fi 78 | echo "END SNAPSHOT" 79 | 80 | echo "SNAPSHOT: --append is not compatible with --create-issue" 81 | if patch-package left-pad --append 'Bananas' --create-issue ; then 82 | exit 1 83 | fi 84 | echo "END SNAPSHOT" -------------------------------------------------------------------------------- /integration-tests/append-patches/append-patches.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "append-patches", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/append-patches/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "append-patches", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0", 10 | "replace": "^1.2.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/apply-multiple-patches/apply-multiple-patches.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | npm install 5 | 6 | echo "add patch-package" 7 | npm add $1 8 | alias patch-package=./node_modules/.bin/patch-package 9 | 10 | 11 | echo "SNAPSHOT: patch-package happily applies all three good patches" 12 | patch-package 13 | echo "END SNAPSHOT" 14 | 15 | echo "SNAPSHOT: patch-package stores a state file to list the patches that have been applied" 16 | cat node_modules/left-pad/.patch-package.json 17 | echo "END SNAPSHOT" 18 | 19 | echo "it should work if we apply them again even though they touch the same parts of the code" 20 | if ! patch-package 21 | then 22 | exit 1 23 | fi 24 | 25 | cp *broken.patch patches/ 26 | 27 | rm -rf node_modules 28 | npm install 29 | echo "SNAPSHOT: patch-package fails when a patch in the sequence is invalid" 30 | if patch-package 31 | then 32 | exit 1 33 | fi 34 | echo "END SNAPSHOT" 35 | 36 | 37 | echo "SNAPSHOT: patch-package only applies the first patch if the second of three is invalid" 38 | if patch-package 39 | then 40 | exit 1 41 | fi 42 | echo "END SNAPSHOT" 43 | 44 | echo "SNAPSHOT: patch-package stores a state file of only the first patch if there was an error" 45 | cat node_modules/left-pad/.patch-package.json 46 | echo "END SNAPSHOT" 47 | 48 | 49 | rm patches/*hello.patch 50 | echo "SNAPSHOT: patch-package fails when a patch file is removed" 51 | if patch-package 52 | then 53 | exit 1 54 | fi 55 | echo "END SNAPSHOT" -------------------------------------------------------------------------------- /integration-tests/apply-multiple-patches/apply-multiple-patches.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "apply-multiple-patches", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/apply-multiple-patches/left-pad+1.3.0+002+broken.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..409dad7 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -1,3 +1,4 @@ 6 | +// hello. this is the first patch 7 | /* Thos program is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What The Fuck You Want 10 | -------------------------------------------------------------------------------- /integration-tests/apply-multiple-patches/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apply-multiple-patches", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "apply-multiple-patches", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "left-pad": "^1.3.0" 13 | } 14 | }, 15 | "node_modules/left-pad": { 16 | "version": "1.3.0", 17 | "license": "WTFPL" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /integration-tests/apply-multiple-patches/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apply-multiple-patches", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/apply-multiple-patches/patches/left-pad+1.3.0+001+hello.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..1a2ec5f 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use strict'; 10 | +'use hello'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/apply-multiple-patches/patches/left-pad+1.3.0+003+world.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 1a2ec5f..5aa41be 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use hello'; 10 | +'use world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/apply-multiple-patches/patches/left-pad+1.3.0+004+goodbye.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 5aa41be..2beca7e 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use world'; 10 | +'goodbye world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/broken-patch-file/__snapshots__/broken-patch-file.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test broken-patch-file: 00: patch-package fails when patch file is invalid 1`] = ` 4 | "SNAPSHOT: patch-package fails when patch file is invalid 5 | patch-package 0.0.0 6 | Applying patches... 7 | 8 | **ERROR** Failed to apply patch for package left-pad at path 9 | 10 | node_modules/left-pad 11 | 12 | This error was caused because patch-package cannot apply the following patch file: 13 | 14 | patches/left-pad+1.1.3.patch 15 | 16 | Try removing node_modules and trying again. If that doesn't work, maybe there was 17 | an accidental change made to the patch file? Try recreating it by manually 18 | editing the appropriate files and running: 19 | 20 | patch-package left-pad 21 | 22 | If that doesn't work, then it's a bug in patch-package, so please submit a bug 23 | report. Thanks! 24 | 25 | https://github.com/ds300/patch-package/issues 26 | 27 | 28 | --- 29 | patch-package finished with 1 error(s). 30 | END SNAPSHOT" 31 | `; 32 | -------------------------------------------------------------------------------- /integration-tests/broken-patch-file/broken-patch-file.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "SNAPSHOT: patch-package fails when patch file is invalid" 9 | if patch-package 10 | then 11 | exit 1 12 | fi 13 | echo "END SNAPSHOT" 14 | -------------------------------------------------------------------------------- /integration-tests/broken-patch-file/broken-patch-file.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "broken-patch-file", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/broken-patch-file/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "broken-patch-file", 3 | "version": "1.0.0", 4 | "description": "a project", 5 | "main": "index.js", 6 | "author": "Mr someoone", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.1.3" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/broken-patch-file/patches/left-pad+1.1.3.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 26f73ff..2533184 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -12,7 +12,7 @@ var cache = [ 6 | ' ', 7 | ' ', 8 | ' ', 9 | - ' - ', 10 | + ' h ', 11 | ' ', 12 | ' ', 13 | ' ', 14 | -------------------------------------------------------------------------------- /integration-tests/broken-patch-file/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | left-pad@^1.1.3: 6 | version "1.1.3" 7 | resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a" 8 | -------------------------------------------------------------------------------- /integration-tests/collate-errors/__snapshots__/collate-errors.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test collate-errors: 00: left-pad, lodash, and zfs apply 1`] = ` 4 | "SNAPSHOT: left-pad, lodash, and zfs apply 5 | SNAPSHOT: underscore does not apply, left-pad warns 6 | patch-package 0.0.0 7 | Applying patches... 8 | left-pad@1.1.1 ✔ 9 | lodash@4.17.21 ✔ 10 | zfs@1.3.0 ✔ 11 | 12 | Warning: patch-package detected a patch file version mismatch 13 | 14 | Don't worry! This is probably fine. The patch was still applied 15 | successfully. Here's the deets: 16 | 17 | Patch file created for 18 | 19 | left-pad@1.1.1 20 | 21 | applied to 22 | 23 | left-pad@1.1.2 24 | 25 | At path 26 | 27 | node_modules/left-pad 28 | 29 | This warning is just to give you a heads-up. There is a small chance of 30 | breakage even though the patch was applied successfully. Make sure the package 31 | still behaves like you expect (you wrote tests, right?) and then run 32 | 33 | patch-package left-pad 34 | 35 | to update the version in the patch file name and make this warning go away. 36 | 37 | 38 | **ERROR** Failed to apply patch for package underscore at path 39 | 40 | node_modules/underscore 41 | 42 | This error was caused because underscore has changed since you 43 | made the patch file for it. This introduced conflicts with your patch, 44 | just like a merge conflict in Git when separate incompatible changes are 45 | made to the same piece of code. 46 | 47 | Maybe this means your patch file is no longer necessary, in which case 48 | hooray! Just delete it! 49 | 50 | Otherwise, you need to generate a new patch file. 51 | 52 | To generate a new one, just repeat the steps you made to generate the first 53 | one. 54 | 55 | i.e. manually make the appropriate file changes, then run 56 | 57 | patch-package underscore 58 | 59 | Info: 60 | Patch file: patches/underscore+1.0.3.patch 61 | Patch was made for version: 1.0.3 62 | Installed version: 1.12.0 63 | 64 | --- 65 | patch-package finished with 1 warning(s), 1 error(s). 66 | END SNAPSHOT" 67 | `; 68 | -------------------------------------------------------------------------------- /integration-tests/collate-errors/collate-errors.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "SNAPSHOT: left-pad, lodash, and zfs apply" 9 | echo "SNAPSHOT: underscore does not apply, left-pad warns" 10 | if patch-package; 11 | then 12 | exit 1 13 | fi 14 | echo "END SNAPSHOT" 15 | echo "END SNAPSHOT" -------------------------------------------------------------------------------- /integration-tests/collate-errors/collate-errors.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "collate-errors", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/collate-errors/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "collate-errors", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "1.1.2", 10 | "lodash": "^4.17.21", 11 | "underscore": "^1.12.0", 12 | "zfs": "^1.3.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /integration-tests/collate-errors/patches/left-pad+1.1.1.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 6b56df3..3433636 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -1,6 +1,9 @@ 6 | 'use strict'; 7 | module.exports = leftPad; 8 | 9 | + 10 | +// patch-package 11 | + 12 | var cache = [ 13 | '', 14 | ' ', 15 | -------------------------------------------------------------------------------- /integration-tests/collate-errors/patches/lodash+4.17.21.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/lodash/_arrayFilter.js b/node_modules/lodash/_arrayFilter.js 2 | index 75ea254..444241d 100644 3 | --- a/node_modules/lodash/_arrayFilter.js 4 | +++ b/node_modules/lodash/_arrayFilter.js 5 | @@ -2,7 +2,7 @@ 6 | * A specialized version of `_.filter` for arrays without support for 7 | * iteratee shorthands. 8 | * 9 | - * @private 10 | + * @patchPackage 11 | * @param {Array} [array] The array to iterate over. 12 | * @param {Function} predicate The function invoked per iteration. 13 | * @returns {Array} Returns the new filtered array. 14 | diff --git a/node_modules/lodash/ceil.js b/node_modules/lodash/ceil.js 15 | index 56c8722..b4a5e1f 100644 16 | --- a/node_modules/lodash/ceil.js 17 | +++ b/node_modules/lodash/ceil.js 18 | @@ -23,4 +23,6 @@ var createRound = require('./_createRound'); 19 | */ 20 | var ceil = createRound('ceil'); 21 | 22 | +// patch-package 23 | + 24 | module.exports = ceil; 25 | -------------------------------------------------------------------------------- /integration-tests/collate-errors/patches/underscore+1.0.3.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/underscore/README b/node_modules/underscore/README 2 | index 333b13f..dc192cf 100644 3 | --- a/node_modules/underscore/README 4 | +++ b/node_modules/underscore/README 5 | @@ -16,7 +16,7 @@ in JavaScript objects. It's the tie to go along with jQuery's tux. 6 | For Docs, License, Tests, and pre-packed downloads, see: 7 | http://documentcloud.github.com/underscore/ 8 | 9 | -Many thanks to our contributors: 10 | +Many thanks to our wonderful contributors: 11 | 12 | Dmitry Baranovskiy 13 | Tim Caswell 14 | -------------------------------------------------------------------------------- /integration-tests/collate-errors/patches/zfs+1.3.0.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/zfs/lib/main.js b/node_modules/zfs/lib/main.js 2 | index ce5f7dd..0d6432b 100644 3 | --- a/node_modules/zfs/lib/main.js 4 | +++ b/node_modules/zfs/lib/main.js 5 | @@ -13,6 +13,7 @@ exports.mount = zfs.mount; 6 | exports.unmount = zfs.unmount; 7 | exports.send = zfs.send; 8 | exports.receive = zfs.receive; 9 | +exports.patchPackage = yes; 10 | 11 | exports.zfs = { 12 | set: zfs.set, 13 | -------------------------------------------------------------------------------- /integration-tests/collate-errors/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | left-pad@1.1.2: 6 | version "1.1.2" 7 | resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.2.tgz#b46d4b36116fafb6f2814c30ecf3247bdfd842f7" 8 | integrity sha1-tG1LNhFvr7bygUww7PMke9/YQvc= 9 | 10 | lodash@^4.17.21: 11 | version "4.17.21" 12 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" 13 | integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== 14 | 15 | underscore@^1.12.0: 16 | version "1.12.0" 17 | resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.12.0.tgz#4814940551fc80587cef7840d1ebb0f16453be97" 18 | integrity sha512-21rQzss/XPMjolTiIezSu3JAjgagXKROtNrYFEOWK109qY1Uv2tVjPTZ1ci2HgvQDA16gHYSthQIJfB+XId/rQ== 19 | 20 | zfs@^1.3.0: 21 | version "1.3.0" 22 | resolved "https://registry.yarnpkg.com/zfs/-/zfs-1.3.0.tgz#aa5e2e5469da762273e16361ec9d7822e44b4ae4" 23 | integrity sha1-ql4uVGnadiJz4WNh7J14IuRLSuQ= 24 | -------------------------------------------------------------------------------- /integration-tests/create-issue/__snapshots__/create-issue.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test create-issue: 00: patching left-pad prompts to submit an issue 1`] = ` 4 | "SNAPSHOT: patching left-pad prompts to submit an issue 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing left-pad@1.3.0 with yarn 8 | • Diffing your files with clean files 9 | ✔ Created file patches/left-pad+1.3.0.patch 10 | 11 | 💡 left-pad is on GitHub! To draft an issue based on your patch run 12 | 13 | yarn patch-package left-pad --create-issue 14 | 15 | END SNAPSHOT" 16 | `; 17 | 18 | exports[`Test create-issue: 01: patching left-pad with --create-issue opens the url 1`] = ` 19 | "SNAPSHOT: patching left-pad with --create-issue opens the url 20 | patch-package 0.0.0 21 | • Creating temporary folder 22 | • Installing left-pad@1.3.0 with yarn 23 | • Diffing your files with clean files 24 | ✔ Created file patches/left-pad+1.3.0.patch 25 | 26 | MOCK opening https://github.com/stevemao/left-pad/issues/new 27 | MOCK title 28 | MOCK body Hi! 👋 29 | 30 | Firstly, thanks for your work on this project! 🙂 31 | 32 | Today I used [patch-package](https://github.com/ds300/patch-package) to patch \`left-pad@1.3.0\` for the project I'm working on. 33 | 34 | 35 | 36 | Here is the diff that solved my problem: 37 | 38 | \`\`\`diff 39 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 40 | index e90aec3..cbca95b 100644 41 | --- a/node_modules/left-pad/index.js 42 | +++ b/node_modules/left-pad/index.js 43 | @@ -4,7 +4,7 @@ 44 | * To Public License, Version 2, as published by Sam Hocevar. See 45 | * http://www.wtfpl.net/ for more details. */ 46 | 'use strict'; 47 | -module.exports = leftPad; 48 | +module.exports = patch-package; 49 | 50 | var cache = [ 51 | '', 52 | @@ -19,7 +19,7 @@ var cache = [ 53 | ' ' 54 | ]; 55 | 56 | -function leftPad (str, len, ch) { 57 | +function patch-package (str, len, ch) { 58 | // convert \`str\` to a \`string\` 59 | str = str + ''; 60 | // \`len\` is the \`pad\`'s length now 61 | \`\`\` 62 | 63 | This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296). 64 | 65 | END SNAPSHOT" 66 | `; 67 | -------------------------------------------------------------------------------- /integration-tests/create-issue/create-issue.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "modify left-pad" 9 | npx replace leftPad patch-package node_modules/left-pad/index.js 10 | 11 | echo "SNAPSHOT: patching left-pad prompts to submit an issue" 12 | patch-package left-pad 13 | echo "END SNAPSHOT" 14 | 15 | echo "mock open" 16 | cp open.mock.js node_modules/open/index.js 17 | 18 | echo "SNAPSHOT: patching left-pad with --create-issue opens the url" 19 | patch-package left-pad --create-issue 20 | echo "END SNAPSHOT" 21 | -------------------------------------------------------------------------------- /integration-tests/create-issue/create-issue.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "create-issue", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/create-issue/open.mock.js: -------------------------------------------------------------------------------- 1 | module.exports = (url) => { 2 | const [resource, query] = url.split("?") 3 | console.log("MOCK opening", resource) 4 | const { title, body } = require("querystring").parse(query) 5 | console.log("MOCK title", title) 6 | console.log("MOCK body", body) 7 | } 8 | -------------------------------------------------------------------------------- /integration-tests/create-issue/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create-issue", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0", 10 | "lodash": "^4.17.21", 11 | "replace": "^1.2.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /integration-tests/custom-patch-dir/custom-patch-dir.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "modify left-pad" 9 | npx replace pad patch-package node_modules/left-pad/index.js 10 | 11 | mkdir my 12 | 13 | echo "make patch file" 14 | patch-package left-pad --patch-dir my/patches 15 | 16 | ls my/patches/left-pad* 17 | 18 | echo "reinstall node_modules" 19 | rimraf node_modules 20 | yarn 21 | 22 | echo "run patch-package" 23 | patch-package --patch-dir my/patches 24 | 25 | grep patch-package node_modules/left-pad/index.js -------------------------------------------------------------------------------- /integration-tests/custom-patch-dir/custom-patch-dir.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "custom-patch-dir", 4 | shouldProduceSnapshots: false, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/custom-patch-dir/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-patch-dir", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "1.3.0", 10 | "replace": "^1.0.1", 11 | "rimraf": "^2.6.3" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /integration-tests/custom-resolutions/blahblahblah-definitely-not-a-real-package-name/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ds300/patch-package/bd2e9a49d884516199079add143c1649541e8efe/integration-tests/custom-resolutions/blahblahblah-definitely-not-a-real-package-name/index.js -------------------------------------------------------------------------------- /integration-tests/custom-resolutions/blahblahblah-definitely-not-a-real-package-name/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blahblahblah-definitely-not-a-real-package-name", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT" 6 | } 7 | -------------------------------------------------------------------------------- /integration-tests/custom-resolutions/custom-resolutions.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "make changes to dependency/index.js" 9 | echo '// hello i am patch-package' > node_modules/dependency/index.js 10 | 11 | echo "doesn't fail when making a patch" 12 | patch-package dependency 13 | -------------------------------------------------------------------------------- /integration-tests/custom-resolutions/custom-resolutions.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "custom-resolutions", 4 | shouldProduceSnapshots: false, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/custom-resolutions/dependency/index.js: -------------------------------------------------------------------------------- 1 | // hello i am dependency 2 | -------------------------------------------------------------------------------- /integration-tests/custom-resolutions/dependency/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dependency", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "blahblahblah-definitely-not-a-real-package-name": "0.34.2" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /integration-tests/custom-resolutions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-resolutions", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "dependency": "file:./dependency" 10 | }, 11 | "resolutions": { 12 | "blahblahblah-definitely-not-a-real-package-name": "file:./blahblahblah-definitely-not-a-real-package-name" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /integration-tests/delete-scripts/__snapshots__/delete-scripts.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test delete-scripts: 00: a patch file got produced 1`] = ` 4 | "SNAPSHOT: a patch file got produced 5 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 6 | index e90aec3..f2b8b0a 100644 7 | --- a/node_modules/left-pad/index.js 8 | +++ b/node_modules/left-pad/index.js 9 | @@ -4,7 +4,7 @@ 10 | * To Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. */ 12 | 'use strict'; 13 | -module.exports = leftPad; 14 | +module.exports = patchPackage; 15 | 16 | var cache = [ 17 | '', 18 | @@ -19,7 +19,7 @@ var cache = [ 19 | ' ' 20 | ]; 21 | 22 | -function leftPad (str, len, ch) { 23 | +function patchPackage (str, len, ch) { 24 | // convert \`str\` to a \`string\` 25 | str = str + ''; 26 | // \`len\` is the \`pad\`'s length now 27 | END SNAPSHOT" 28 | `; 29 | -------------------------------------------------------------------------------- /integration-tests/delete-scripts/delete-scripts.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | echo 'install without error because package.json is sanitized' 4 | yarn add $1 5 | alias patch-package=./node_modules/.bin/patch-package 6 | 7 | echo 'unsnitize package.json' 8 | npx replace '<>' preinstall package.json 9 | 10 | echo 'install fails because preinstall hook is bad' 11 | if yarn; then 12 | exit 1 13 | fi 14 | 15 | npx replace leftPad patchPackage node_modules/left-pad/index.js 16 | 17 | echo 'but patch-package still works because it ignores scripts' 18 | patch-package left-pad 19 | 20 | echo "SNAPSHOT: a patch file got produced" 21 | cat patches/left-pad*.patch 22 | echo "END SNAPSHOT" 23 | -------------------------------------------------------------------------------- /integration-tests/delete-scripts/delete-scripts.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | 3 | runIntegrationTest({ 4 | projectName: "delete-scripts", 5 | shouldProduceSnapshots: true, 6 | }) 7 | -------------------------------------------------------------------------------- /integration-tests/delete-scripts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "delete-scripts", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "<>": "exit 1" 8 | }, 9 | "dependencies": { 10 | "left-pad": "^1.3.0", 11 | "replace": "^1.0.0" 12 | } 13 | } -------------------------------------------------------------------------------- /integration-tests/delete-scripts/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | ansi-styles@~1.0.0: 6 | version "1.0.0" 7 | resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.0.0.tgz#cb102df1c56f5123eab8b67cd7b98027a0279178" 8 | 9 | balanced-match@^1.0.0: 10 | version "1.0.0" 11 | resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" 12 | 13 | brace-expansion@^1.1.7: 14 | version "1.1.11" 15 | resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" 16 | dependencies: 17 | balanced-match "^1.0.0" 18 | concat-map "0.0.1" 19 | 20 | chalk@~0.4.0: 21 | version "0.4.0" 22 | resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f" 23 | dependencies: 24 | ansi-styles "~1.0.0" 25 | has-color "~0.1.0" 26 | strip-ansi "~0.1.0" 27 | 28 | colors@1.2.4: 29 | version "1.2.4" 30 | resolved "https://registry.yarnpkg.com/colors/-/colors-1.2.4.tgz#e0cb41d3e4b20806b3bfc27f4559f01b94bc2f7c" 31 | 32 | concat-map@0.0.1: 33 | version "0.0.1" 34 | resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" 35 | 36 | has-color@~0.1.0: 37 | version "0.1.7" 38 | resolved "https://registry.yarnpkg.com/has-color/-/has-color-0.1.7.tgz#67144a5260c34fc3cca677d041daf52fe7b78b2f" 39 | 40 | left-pad@^1.3.0: 41 | version "1.3.0" 42 | resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e" 43 | 44 | minimatch@3.0.4: 45 | version "3.0.4" 46 | resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" 47 | dependencies: 48 | brace-expansion "^1.1.7" 49 | 50 | nomnom@1.8.1: 51 | version "1.8.1" 52 | resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.8.1.tgz#2151f722472ba79e50a76fc125bb8c8f2e4dc2a7" 53 | dependencies: 54 | chalk "~0.4.0" 55 | underscore "~1.6.0" 56 | 57 | replace@^1.0.0: 58 | version "1.0.0" 59 | resolved "https://registry.yarnpkg.com/replace/-/replace-1.0.0.tgz#da5235cc6d64d5c3a74e4ef73b487aad0f79a74b" 60 | dependencies: 61 | colors "1.2.4" 62 | minimatch "3.0.4" 63 | nomnom "1.8.1" 64 | 65 | strip-ansi@~0.1.0: 66 | version "0.1.1" 67 | resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.1.1.tgz#39e8a98d044d150660abe4a6808acf70bb7bc991" 68 | 69 | underscore@~1.6.0: 70 | version "1.6.0" 71 | resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8" 72 | -------------------------------------------------------------------------------- /integration-tests/dev-only-patches/__snapshots__/dev-only-patches.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test dev-only-patches: 00: patch-package happily ignores slash on CI because it's a dev dep 1`] = ` 4 | "SNAPSHOT: patch-package happily ignores slash on CI because it's a dev dep 5 | patch-package 0.0.0 6 | Applying patches... 7 | left-pad@1.3.0 ✔ 8 | Skipping dev-only slash@3.0.0 ✔ 9 | END SNAPSHOT" 10 | `; 11 | 12 | exports[`Test dev-only-patches: 01: patch-package fails to find fake-package 1`] = ` 13 | "SNAPSHOT: patch-package fails to find fake-package 14 | patch-package 0.0.0 15 | Applying patches... 16 | left-pad@1.3.0 ✔ 17 | Skipping dev-only slash@3.0.0 ✔ 18 | Error: Patch file found for package fake-package which is not present at node_modules/fake-package 19 | 20 | If this package is a dev dependency, rename the patch file to 21 | 22 | fake-package+3.0.0.dev.patch 23 | 24 | --- 25 | patch-package finished with 1 error(s). 26 | END SNAPSHOT" 27 | `; 28 | 29 | exports[`Test dev-only-patches: 02: fake-package should be skipped 1`] = ` 30 | "SNAPSHOT: fake-package should be skipped 31 | patch-package 0.0.0 32 | Applying patches... 33 | Skipping dev-only fake-package@3.0.0 ✔ 34 | left-pad@1.3.0 ✔ 35 | Skipping dev-only slash@3.0.0 ✔ 36 | END SNAPSHOT" 37 | `; 38 | -------------------------------------------------------------------------------- /integration-tests/dev-only-patches/dev-only-patches.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "set production mode" 5 | export NODE_ENV=production 6 | export CI="true" 7 | 8 | echo "add patch-package" 9 | yarn add $1 10 | alias patch-package=./node_modules/.bin/patch-package 11 | 12 | echo "SNAPSHOT: patch-package happily ignores slash on CI because it's a dev dep" 13 | patch-package 14 | echo "END SNAPSHOT" 15 | 16 | echo "create fake-package+3.0.0.patch" 17 | cp patches/slash+3.0.0.patch patches/fake-package+3.0.0.patch 18 | 19 | echo "SNAPSHOT: patch-package fails to find fake-package" 20 | if patch-package 21 | then 22 | exit 1 23 | fi 24 | echo "END SNAPSHOT" 25 | 26 | echo "rename fake-package patch file to .dev.patch" 27 | mv patches/fake-package+3.0.0.patch patches/fake-package+3.0.0.dev.patch 28 | 29 | echo "SNAPSHOT: fake-package should be skipped" 30 | patch-package 31 | echo "END SNAPSHOT" 32 | -------------------------------------------------------------------------------- /integration-tests/dev-only-patches/dev-only-patches.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "dev-only-patches", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/dev-only-patches/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dev-only-patches", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "1.3.0", 10 | "rimraf": "3.0.0" 11 | }, 12 | "devDependencies": { 13 | "slash": "3.0.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration-tests/dev-only-patches/patches/left-pad+1.3.0.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..823ee5f 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -4,7 +4,7 @@ 6 | * To Public License, Version 2, as published by Sam Hocevar. See 7 | * http://www.wtfpl.net/ for more details. */ 8 | 'use strict'; 9 | -module.exports = leftPad; 10 | +module.exports = patchPackage; 11 | 12 | var cache = [ 13 | '', 14 | -------------------------------------------------------------------------------- /integration-tests/dev-only-patches/patches/slash+3.0.0.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/slash/index.js b/node_modules/slash/index.js 2 | index 103fbea..e3c36f8 100644 3 | --- a/node_modules/slash/index.js 4 | +++ b/node_modules/slash/index.js 5 | @@ -1,5 +1,5 @@ 6 | 'use strict'; 7 | -module.exports = path => { 8 | +module.patchPackage = path => { 9 | const isExtendedLengthPath = /^\\\\\?\\/.test(path); 10 | const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex 11 | 12 | -------------------------------------------------------------------------------- /integration-tests/error-on-fail/__snapshots__/error-on-fail.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test error-on-fail: 00: at dev time patch-package fails but returns 0 1`] = ` 4 | "SNAPSHOT: at dev time patch-package fails but returns 0 5 | patch-package 0.0.0 6 | Applying patches... 7 | 8 | **ERROR** Failed to apply patch for package left-pad at path 9 | 10 | node_modules/left-pad 11 | 12 | This error was caused because patch-package cannot apply the following patch file: 13 | 14 | patches/left-pad+1.3.0.patch 15 | 16 | Try removing node_modules and trying again. If that doesn't work, maybe there was 17 | an accidental change made to the patch file? Try recreating it by manually 18 | editing the appropriate files and running: 19 | 20 | patch-package left-pad 21 | 22 | If that doesn't work, then it's a bug in patch-package, so please submit a bug 23 | report. Thanks! 24 | 25 | https://github.com/ds300/patch-package/issues 26 | 27 | 28 | --- 29 | patch-package finished with 1 error(s). 30 | END SNAPSHOT" 31 | `; 32 | -------------------------------------------------------------------------------- /integration-tests/error-on-fail/error-on-fail.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | export NODE_ENV="development" 9 | export CI="true" 10 | 11 | echo "SNAPSHOT: at dev time patch-package fails but returns 0" 12 | if ! patch-package; 13 | then 14 | exit 1 15 | fi 16 | echo "END SNAPSHOT" 17 | 18 | echo "adding --error-on-fail forces patch-package to return 1 at dev time" 19 | if patch-package --error-on-fail; 20 | then 21 | exit 1 22 | fi 23 | -------------------------------------------------------------------------------- /integration-tests/error-on-fail/error-on-fail.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "error-on-fail", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/error-on-fail/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "error-on-fail", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/error-on-fail/patches/left-pad+1.3.0.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..4a20773 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -4,7 +4,7 @@ 6 | * To Public License, Version 2, as published by Sam Hocevar. See 7 | * http://www.wtfpl.net/ for more details. */ 8 | 'use strict'; 9 | -module.notreal = leftPad; 10 | +module.patchPackage = leftPad; 11 | 12 | var cache = [ 13 | '', 14 | -------------------------------------------------------------------------------- /integration-tests/error-on-fail/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | left-pad@^1.3.0: 6 | version "1.3.0" 7 | resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e" 8 | integrity sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA== 9 | -------------------------------------------------------------------------------- /integration-tests/error-on-warn/__snapshots__/error-on-warn.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test error-on-warn: 00: at dev time patch-package warns but returns 0 1`] = ` 4 | "SNAPSHOT: at dev time patch-package warns but returns 0 5 | patch-package 0.0.0 6 | Applying patches... 7 | left-pad@1.1.2 ✔ 8 | 9 | Warning: patch-package detected a patch file version mismatch 10 | 11 | Don't worry! This is probably fine. The patch was still applied 12 | successfully. Here's the deets: 13 | 14 | Patch file created for 15 | 16 | left-pad@1.1.2 17 | 18 | applied to 19 | 20 | left-pad@1.1.3 21 | 22 | At path 23 | 24 | node_modules/left-pad 25 | 26 | This warning is just to give you a heads-up. There is a small chance of 27 | breakage even though the patch was applied successfully. Make sure the package 28 | still behaves like you expect (you wrote tests, right?) and then run 29 | 30 | patch-package left-pad 31 | 32 | to update the version in the patch file name and make this warning go away. 33 | 34 | --- 35 | patch-package finished with 1 warning(s). 36 | END SNAPSHOT" 37 | `; 38 | -------------------------------------------------------------------------------- /integration-tests/error-on-warn/error-on-warn.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | export NODE_ENV="development" 9 | export CI="" 10 | 11 | echo "SNAPSHOT: at dev time patch-package warns but returns 0" 12 | if ! patch-package; 13 | then 14 | exit 1 15 | fi 16 | echo "END SNAPSHOT" 17 | 18 | echo "adding --error-on-warn forces patch-package to return 1 at dev time" 19 | if patch-package --error-on-warn; 20 | then 21 | exit 1 22 | fi 23 | -------------------------------------------------------------------------------- /integration-tests/error-on-warn/error-on-warn.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "error-on-warn", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/error-on-warn/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "error-on-warn", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "1.1.3" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/error-on-warn/patches/left-pad+1.1.2.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 26f73ff..60f3f56 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -7,7 +7,7 @@ 6 | module.exports = leftPad; 7 | 8 | var cache = [ 9 | - '', 10 | + "", 11 | ' ', 12 | ' ', 13 | ' ', -------------------------------------------------------------------------------- /integration-tests/error-on-warn/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | left-pad@1.1.3: 6 | version "1.1.3" 7 | resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a" 8 | integrity sha1-YS9hwDPzqeCOk58crr7qQbbzGZo= 9 | -------------------------------------------------------------------------------- /integration-tests/fails-when-no-package/__snapshots__/fails-when-no-package.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test fails-when-no-package: 00: no package present failure 1`] = ` 4 | "SNAPSHOT: no package present failure 5 | patch-package 0.0.0 6 | Applying patches... 7 | Error: Patch file found for package left-pad which is not present at node_modules/left-pad 8 | --- 9 | patch-package finished with 1 error(s). 10 | END SNAPSHOT" 11 | `; 12 | -------------------------------------------------------------------------------- /integration-tests/fails-when-no-package/fails-when-no-package.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "SNAPSHOT: no package present failure" 9 | if patch-package; then 10 | exit 1 11 | fi 12 | echo "END SNAPSHOT" 13 | -------------------------------------------------------------------------------- /integration-tests/fails-when-no-package/fails-when-no-package.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "fails-when-no-package", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/fails-when-no-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fails-when-no-package", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": {} 9 | } 10 | -------------------------------------------------------------------------------- /integration-tests/fails-when-no-package/patches/left-pad+1.1.3.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 26f73ff..60f3f56 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -4,7 +4,7 @@ 6 | * To Public License, Version 2, as published by Sam Hocevar. See 7 | * http://www.wtfpl.net/ for more details. */ 8 | 'use strict'; 9 | -module.exports = leftPad; 10 | +module.exports = patch-package; 11 | 12 | var cache = [ 13 | '', 14 | -------------------------------------------------------------------------------- /integration-tests/fails-when-no-package/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /integration-tests/file-mode-changes/__snapshots__/file-mode-changes.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test file-mode-changes: 00: the patch file 1`] = ` 4 | "SNAPSHOT: the patch file 5 | diff --git a/node_modules/prettier/bin-prettier.js b/node_modules/prettier/bin-prettier.js 6 | old mode 100755 7 | new mode 100644 8 | diff --git a/node_modules/prettier/index.js b/node_modules/prettier/index.js 9 | old mode 100644 10 | new mode 100755 11 | END SNAPSHOT" 12 | `; 13 | -------------------------------------------------------------------------------- /integration-tests/file-mode-changes/assert-executable.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const file = process.argv[2] 3 | 4 | const mode = require("fs").statSync(file).mode 5 | 6 | if ((mode & 0b001000000) > 0) { 7 | process.exit(0) 8 | } else { 9 | process.exit(1) 10 | } 11 | -------------------------------------------------------------------------------- /integration-tests/file-mode-changes/assert-not-executable.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const file = process.argv[2] 3 | 4 | const mode = require("fs").statSync(file).mode 5 | 6 | if ((mode & 0b001000000) > 0) { 7 | process.exit(1) 8 | } else { 9 | process.exit(0) 10 | } 11 | -------------------------------------------------------------------------------- /integration-tests/file-mode-changes/file-mode-changes.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "check file permissions 1" 9 | ./assert-executable.js node_modules/prettier/bin-prettier.js 10 | ./assert-not-executable.js node_modules/prettier/index.js 11 | 12 | echo "change file modes" 13 | npx shx chmod -x node_modules/prettier/bin-prettier.js 14 | npx shx chmod +x node_modules/prettier/index.js 15 | 16 | echo "check file permissions 2" 17 | ./assert-executable.js node_modules/prettier/index.js 18 | ./assert-not-executable.js node_modules/prettier/bin-prettier.js 19 | 20 | echo "patch prettier" 21 | patch-package prettier 22 | 23 | echo "SNAPSHOT: the patch file" 24 | cat patches/prettier* 25 | echo "END SNAPSHOT" 26 | 27 | echo "reinstall node modules" 28 | npx shx rm -rf node_modules 29 | yarn 30 | 31 | echo "check file permissions 3" 32 | ./assert-executable.js node_modules/prettier/bin-prettier.js 33 | ./assert-not-executable.js node_modules/prettier/index.js 34 | 35 | echo "run patch-package" 36 | patch-package 37 | 38 | echo "check file permissions 4" 39 | ./assert-executable.js node_modules/prettier/index.js 40 | ./assert-not-executable.js node_modules/prettier/bin-prettier.js 41 | -------------------------------------------------------------------------------- /integration-tests/file-mode-changes/file-mode-changes.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "file-mode-changes", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/file-mode-changes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "file-mode-changes", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "prettier": "^1.16.0", 10 | "shx": "^0.3.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/happy-path-npm/__snapshots__/happy-path-npm.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test happy-path-npm: 00: making patch 1`] = ` 4 | "SNAPSHOT: making patch 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing left-pad@1.1.3 with npm 8 | • Diffing your files with clean files 9 | ✔ Created file patches/left-pad+1.1.3.patch 10 | 11 | 💡 left-pad is on GitHub! To draft an issue based on your patch run 12 | 13 | npx patch-package left-pad --create-issue 14 | 15 | END SNAPSHOT" 16 | `; 17 | 18 | exports[`Test happy-path-npm: 01: the patch looks like this 1`] = ` 19 | "SNAPSHOT: the patch looks like this 20 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 21 | index 26f73ff..d4cc4af 100644 22 | --- a/node_modules/left-pad/index.js 23 | +++ b/node_modules/left-pad/index.js 24 | @@ -22,9 +22,9 @@ var cache = [ 25 | function leftPad (str, len, ch) { 26 | // convert \`str\` to \`string\` 27 | str = str + ''; 28 | - // \`len\` is the \`pad\`'s length now 29 | + // \`len\` is the \`npm\`'s length now 30 | len = len - str.length; 31 | - // doesn't need to pad 32 | + // doesn't need to npm 33 | if (len <= 0) return str; 34 | // \`ch\` defaults to \`' '\` 35 | if (!ch && ch !== 0) ch = ' '; 36 | @@ -32,12 +32,12 @@ function leftPad (str, len, ch) { 37 | ch = ch + ''; 38 | // cache common use cases 39 | if (ch === ' ' && len < 10) return cache[len] + str; 40 | - // \`pad\` starts with an empty string 41 | - var pad = ''; 42 | + // \`npm\` starts with an empty string 43 | + var npm = ''; 44 | // loop 45 | while (true) { 46 | - // add \`ch\` to \`pad\` if \`len\` is odd 47 | - if (len & 1) pad += ch; 48 | + // add \`ch\` to \`npm\` if \`len\` is odd 49 | + if (len & 1) npm += ch; 50 | // divide \`len\` by 2, ditch the remainder 51 | len >>= 1; 52 | // \\"double\\" the \`ch\` so this operation count grows logarithmically on \`len\` 53 | @@ -47,6 +47,6 @@ function leftPad (str, len, ch) { 54 | // \`len\` is 0, exit the loop 55 | else break; 56 | } 57 | - // pad \`str\`! 58 | - return pad + str; 59 | + // npm \`str\`! 60 | + return npm + str; 61 | } 62 | END SNAPSHOT" 63 | `; 64 | -------------------------------------------------------------------------------- /integration-tests/happy-path-npm/add-postinstall.js: -------------------------------------------------------------------------------- 1 | require("fs").writeFileSync( 2 | "./package.json", 3 | JSON.stringify({ 4 | ...require("./package.json"), 5 | scripts: { 6 | postinstall: "patch-package", 7 | }, 8 | }), 9 | ) -------------------------------------------------------------------------------- /integration-tests/happy-path-npm/happy-path-npm.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | npm i 5 | 6 | echo "add patch-package" 7 | npm i $1 8 | alias patch-package=./node_modules/.bin/patch-package 9 | 10 | echo "Add left-pad" 11 | npm i left-pad@1.1.3 12 | 13 | echo "replace pad with yarn in left-pad/index.js" 14 | npx replace pad npm node_modules/left-pad/index.js 15 | 16 | echo "SNAPSHOT: making patch" 17 | patch-package left-pad 18 | echo "END SNAPSHOT" 19 | 20 | echo "SNAPSHOT: the patch looks like this" 21 | cat patches/left-pad+1.1.3.patch 22 | echo "END SNAPSHOT" 23 | 24 | echo "reinstall node_modules" 25 | npx rimraf node_modules 26 | npm i 27 | 28 | echo "patch-package didn't run" 29 | if grep npm node_modules/left-pad/index.js ; then 30 | exit 1 31 | fi 32 | 33 | echo "add patch-package to postinstall hook" 34 | node ./add-postinstall.js 35 | 36 | echo "reinstall node_modules" 37 | npx rimraf node_modules 38 | npm i 39 | 40 | echo "patch-package did run" 41 | grep npm node_modules/left-pad/index.js 42 | -------------------------------------------------------------------------------- /integration-tests/happy-path-npm/happy-path-npm.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "happy-path-npm", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/happy-path-npm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "happy-path-npm", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "replace": "^1.0.0", 10 | "rimraf": "^2.6.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/happy-path-yarn/__snapshots__/happy-path-yarn.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test happy-path-yarn: 00: making patch 1`] = ` 4 | "SNAPSHOT: making patch 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing left-pad@1.1.3 with yarn 8 | • Diffing your files with clean files 9 | ✔ Created file patches/left-pad+1.1.3.patch 10 | 11 | 💡 left-pad is on GitHub! To draft an issue based on your patch run 12 | 13 | yarn patch-package left-pad --create-issue 14 | 15 | END SNAPSHOT" 16 | `; 17 | 18 | exports[`Test happy-path-yarn: 01: the patch looks like this 1`] = ` 19 | "SNAPSHOT: the patch looks like this 20 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 21 | index 26f73ff..b083802 100644 22 | --- a/node_modules/left-pad/index.js 23 | +++ b/node_modules/left-pad/index.js 24 | @@ -22,9 +22,9 @@ var cache = [ 25 | function leftPad (str, len, ch) { 26 | // convert \`str\` to \`string\` 27 | str = str + ''; 28 | - // \`len\` is the \`pad\`'s length now 29 | + // \`len\` is the \`yarn\`'s length now 30 | len = len - str.length; 31 | - // doesn't need to pad 32 | + // doesn't need to yarn 33 | if (len <= 0) return str; 34 | // \`ch\` defaults to \`' '\` 35 | if (!ch && ch !== 0) ch = ' '; 36 | @@ -32,12 +32,12 @@ function leftPad (str, len, ch) { 37 | ch = ch + ''; 38 | // cache common use cases 39 | if (ch === ' ' && len < 10) return cache[len] + str; 40 | - // \`pad\` starts with an empty string 41 | - var pad = ''; 42 | + // \`yarn\` starts with an empty string 43 | + var yarn = ''; 44 | // loop 45 | while (true) { 46 | - // add \`ch\` to \`pad\` if \`len\` is odd 47 | - if (len & 1) pad += ch; 48 | + // add \`ch\` to \`yarn\` if \`len\` is odd 49 | + if (len & 1) yarn += ch; 50 | // divide \`len\` by 2, ditch the remainder 51 | len >>= 1; 52 | // \\"double\\" the \`ch\` so this operation count grows logarithmically on \`len\` 53 | @@ -47,6 +47,6 @@ function leftPad (str, len, ch) { 54 | // \`len\` is 0, exit the loop 55 | else break; 56 | } 57 | - // pad \`str\`! 58 | - return pad + str; 59 | + // yarn \`str\`! 60 | + return yarn + str; 61 | } 62 | END SNAPSHOT" 63 | `; 64 | -------------------------------------------------------------------------------- /integration-tests/happy-path-yarn/add-postinstall.js: -------------------------------------------------------------------------------- 1 | require("fs").writeFileSync( 2 | "./package.json", 3 | JSON.stringify({ 4 | ...require("./package.json"), 5 | scripts: { 6 | postinstall: "patch-package", 7 | }, 8 | }), 9 | ) -------------------------------------------------------------------------------- /integration-tests/happy-path-yarn/happy-path-yarn.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "Add left-pad" 9 | yarn add left-pad@1.1.3 10 | 11 | echo "replace pad with yarn in left-pad/index.js" 12 | npx replace pad yarn node_modules/left-pad/index.js 13 | 14 | echo "SNAPSHOT: making patch" 15 | patch-package left-pad 16 | echo "END SNAPSHOT" 17 | 18 | echo "SNAPSHOT: the patch looks like this" 19 | cat patches/left-pad+1.1.3.patch 20 | echo "END SNAPSHOT" 21 | 22 | echo "reinstall node_modules" 23 | npx rimraf node_modules 24 | yarn 25 | 26 | echo "patch-package didn't run" 27 | if grep yarn node_modules/left-pad/index.js ; then 28 | exit 1 29 | fi 30 | 31 | echo "add patch-package to postinstall hook" 32 | node ./add-postinstall.js 33 | 34 | echo "reinstall node_modules" 35 | npx rimraf node_modules 36 | yarn 37 | 38 | echo "patch-package did run" 39 | grep yarn node_modules/left-pad/index.js 40 | -------------------------------------------------------------------------------- /integration-tests/happy-path-yarn/happy-path-yarn.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "happy-path-yarn", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/happy-path-yarn/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "happy-path-yarn", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "replace": "^1.0.0", 10 | "rimraf": "^2.6.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/__snapshots__/ignore-whitespace.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test ignore-whitespace: 00: empty changeset when adding whitespace 1`] = ` 4 | "SNAPSHOT: empty changeset when adding whitespace 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing alphabet@1.0.0 with yarn 8 | • Diffing your files with clean files 9 | ⁉️ Not creating patch file for package 'alphabet' 10 | ⁉️ There don't appear to be any changes. 11 | END SNAPSHOT" 12 | `; 13 | 14 | exports[`Test ignore-whitespace: 01: line a changed 1`] = ` 15 | "SNAPSHOT: line a changed 16 | diff --git a/node_modules/alphabet/index.js b/node_modules/alphabet/index.js 17 | index 7811d3b..454414b 100644 18 | --- a/node_modules/alphabet/index.js 19 | +++ b/node_modules/alphabet/index.js 20 | @@ -1,4 +1,4 @@ 21 | -// a 22 | +// patch-package 23 | // b 24 | // c 25 | // d 26 | END SNAPSHOT" 27 | `; 28 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/add-whitespace.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs") 2 | const file = "node_modules/alphabet/index.js" 3 | 4 | const offset = Number(require("process").argv[2] || 0) 5 | 6 | const eolWhitespace = [" ", " \r", "\r"] 7 | 8 | const lines = fs.readFileSync(file).toString().trim().split("\n") 9 | const withWhitespace = lines 10 | .map( 11 | (line, i) => 12 | line.trim() + eolWhitespace[(i + offset) % eolWhitespace.length] 13 | ) 14 | .join("\n") 15 | 16 | const buf = Buffer.from(withWhitespace) 17 | 18 | fs.writeFileSync(file, buf) 19 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/alphabet/index.js: -------------------------------------------------------------------------------- 1 | // a 2 | // b 3 | // c 4 | // d 5 | // e 6 | // f 7 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/alphabet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alphabet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/ignore-whitespace.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "add random bits of whitespace" 9 | node add-whitespace.js 10 | 11 | echo "try to make patch file (should be empty)" 12 | echo "SNAPSHOT: empty changeset when adding whitespace" 13 | if patch-package alphabet 14 | then 15 | exit 1 16 | fi 17 | echo "END SNAPSHOT" 18 | 19 | echo "make a change to line a" 20 | node strip-whitespace.js 21 | npx replace 'a' 'patch-package' node_modules/alphabet/index.js 22 | node add-whitespace.js 2 23 | 24 | echo "make patch file for line a" 25 | patch-package alphabet 26 | 27 | echo "SNAPSHOT: line a changed" 28 | cat patches/alphabet*.patch 29 | echo "END SNAPSHOT" 30 | 31 | echo "make sure the patch can be applied to clean files" 32 | rm -rf node_modules 33 | yarn 34 | patch-package 35 | grep patch-package node_modules/alphabet/index.js 36 | 37 | echo "make sure the patch can be applied to dirty files" 38 | rm -rf node_modules 39 | yarn 40 | node add-whitespace.js 41 | patch-package 42 | grep patch-package node_modules/alphabet/index.js 43 | 44 | echo "make sure the patch can be applied to dirty files with different whitespace" 45 | rm -rf node_modules 46 | yarn 47 | node add-whitespace.js 1 48 | patch-package 49 | grep patch-package node_modules/alphabet/index.js 50 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/ignore-whitespace.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | 3 | runIntegrationTest({ 4 | projectName: "ignore-whitespace", 5 | shouldProduceSnapshots: true, 6 | }) 7 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ignore-whitespace", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "alphabet": "file:./alphabet", 13 | "replace": "^0.3.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/strip-whitespace.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs") 2 | const file = "node_modules/alphabet/index.js" 3 | 4 | fs.writeFileSync( 5 | file, 6 | fs.readFileSync(file).toString().split("\n").map(s => s.trim()).join("\n") + 7 | "\n", 8 | ) 9 | -------------------------------------------------------------------------------- /integration-tests/ignore-whitespace/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "alphabet@file:./alphabet": 6 | version "1.0.0" 7 | 8 | colors@0.5.x: 9 | version "0.5.1" 10 | resolved "https://registry.yarnpkg.com/colors/-/colors-0.5.1.tgz#7d0023eaeb154e8ee9fce75dcb923d0ed1667774" 11 | 12 | lru-cache@2: 13 | version "2.7.3" 14 | resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" 15 | 16 | minimatch@~0.2.9: 17 | version "0.2.14" 18 | resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a" 19 | dependencies: 20 | lru-cache "2" 21 | sigmund "~1.0.0" 22 | 23 | nomnom@1.6.x: 24 | version "1.6.2" 25 | resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.6.2.tgz#84a66a260174408fc5b77a18f888eccc44fb6971" 26 | dependencies: 27 | colors "0.5.x" 28 | underscore "~1.4.4" 29 | 30 | replace@^0.3.0: 31 | version "0.3.0" 32 | resolved "https://registry.yarnpkg.com/replace/-/replace-0.3.0.tgz#60081721188658595ab6a794eb7fedcb4c8d39c7" 33 | dependencies: 34 | colors "0.5.x" 35 | minimatch "~0.2.9" 36 | nomnom "1.6.x" 37 | 38 | sigmund@~1.0.0: 39 | version "1.0.1" 40 | resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" 41 | 42 | underscore@~1.4.4: 43 | version "1.4.4" 44 | resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.4.4.tgz#61a6a32010622afa07963bf325203cf12239d604" 45 | -------------------------------------------------------------------------------- /integration-tests/ignores-scripts-when-making-patch/__snapshots__/ignores-scripts-when-making-patch.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test ignores-scripts-when-making-patch: 00: the patch creation output should look normal 1`] = ` 4 | "SNAPSHOT: the patch creation output should look normal 5 | SNAPSHOT: there should be no stderr 6 | patch-package 0.0.0 7 | • Creating temporary folder 8 | • Installing naughty-package@1.0.0 with yarn 9 | • Diffing your files with clean files 10 | ✔ Created file patches/naughty-package+1.0.0.patch 11 | 12 | END SNAPSHOT" 13 | `; 14 | 15 | exports[`Test ignores-scripts-when-making-patch: 01: a patch file got produced 1`] = ` 16 | "SNAPSHOT: a patch file got produced 17 | diff --git a/node_modules/naughty-package/postinstall.sh b/node_modules/naughty-package/postinstall.sh 18 | index 3784520..c4af29c 100755 19 | --- a/node_modules/naughty-package/postinstall.sh 20 | +++ b/node_modules/naughty-package/postinstall.sh 21 | @@ -1,4 +1,4 @@ 22 | -# postinstall 23 | +# lol 24 | 25 | # if we're running in the main repo is ok 26 | if ls ../patch-package ; 27 | END SNAPSHOT" 28 | `; 29 | -------------------------------------------------------------------------------- /integration-tests/ignores-scripts-when-making-patch/ignores-scripts-when-making-patch.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | npx replace postinstall lol node_modules/naughty-package/postinstall.sh 9 | 10 | echo "SNAPSHOT: the patch creation output should look normal" 11 | echo "SNAPSHOT: there should be no stderr" 12 | patch-package naughty-package 13 | echo "END SNAPSHOT" 14 | echo "END SNAPSHOT" 15 | 16 | echo "SNAPSHOT: a patch file got produced" 17 | cat patches/naughty-package+1.0.0.patch 18 | echo "END SNAPSHOT" -------------------------------------------------------------------------------- /integration-tests/ignores-scripts-when-making-patch/ignores-scripts-when-making-patch.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "ignores-scripts-when-making-patch", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/ignores-scripts-when-making-patch/naughty-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "naughty-package", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "postinstall": "./postinstall.sh" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /integration-tests/ignores-scripts-when-making-patch/naughty-package/postinstall.sh: -------------------------------------------------------------------------------- 1 | # postinstall 2 | 3 | # if we're running in the main repo is ok 4 | if ls ../patch-package ; 5 | then 6 | exit 0 7 | fi 8 | # if we are installed alone then fail 9 | exit 1 -------------------------------------------------------------------------------- /integration-tests/ignores-scripts-when-making-patch/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ignores-scripts-when-making-patch", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "naughty-package": "file:./naughty-package", 10 | "replace": "^1.1.1" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-paths/__snapshots__/include-exclude-paths.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test include-exclude-paths: 00: only __.js being deleted 1`] = ` 4 | "SNAPSHOT: only __.js being deleted 5 | diff --git a/node_modules/lodash/fp/__.js b/node_modules/lodash/fp/__.js 6 | deleted file mode 100644 7 | index 4af98de..0000000 8 | --- a/node_modules/lodash/fp/__.js 9 | +++ /dev/null 10 | @@ -1 +0,0 @@ 11 | -module.exports = require('./placeholder'); 12 | END SNAPSHOT" 13 | `; 14 | 15 | exports[`Test include-exclude-paths: 01: no base files 1`] = ` 16 | "SNAPSHOT: no base files 17 | diff --git a/node_modules/lodash/flip.js b/node_modules/lodash/flip.js 18 | index c28dd78..584b377 100644 19 | --- a/node_modules/lodash/flip.js 20 | +++ b/node_modules/lodash/flip.js 21 | @@ -25,4 +25,4 @@ function flip(func) { 22 | return createWrap(func, WRAP_FLIP_FLAG); 23 | } 24 | 25 | -module.exports = flip; 26 | +module.patchPackage = flip; 27 | diff --git a/node_modules/lodash/fp/__.js b/node_modules/lodash/fp/__.js 28 | deleted file mode 100644 29 | index 4af98de..0000000 30 | --- a/node_modules/lodash/fp/__.js 31 | +++ /dev/null 32 | @@ -1 +0,0 @@ 33 | -module.exports = require('./placeholder'); 34 | diff --git a/node_modules/lodash/newFile.md b/node_modules/lodash/newFile.md 35 | new file mode 100644 36 | index 0000000..3b2aed8 37 | --- /dev/null 38 | +++ b/node_modules/lodash/newFile.md 39 | @@ -0,0 +1 @@ 40 | +this is a new file 41 | END SNAPSHOT" 42 | `; 43 | 44 | exports[`Test include-exclude-paths: 02: only base files, no clone files 1`] = ` 45 | "SNAPSHOT: only base files, no clone files 46 | diff --git a/node_modules/lodash/_baseClamp.js b/node_modules/lodash/_baseClamp.js 47 | index a1c5692..c52e38e 100644 48 | --- a/node_modules/lodash/_baseClamp.js 49 | +++ b/node_modules/lodash/_baseClamp.js 50 | @@ -19,4 +19,4 @@ function baseClamp(number, lower, upper) { 51 | return number; 52 | } 53 | 54 | -module.exports = baseClamp; 55 | +module.patchPackage = baseClamp; 56 | END SNAPSHOT" 57 | `; 58 | 59 | exports[`Test include-exclude-paths: 03: exclude all but flip 1`] = ` 60 | "SNAPSHOT: exclude all but flip 61 | diff --git a/node_modules/lodash/flip.js b/node_modules/lodash/flip.js 62 | index c28dd78..584b377 100644 63 | --- a/node_modules/lodash/flip.js 64 | +++ b/node_modules/lodash/flip.js 65 | @@ -25,4 +25,4 @@ function flip(func) { 66 | return createWrap(func, WRAP_FLIP_FLAG); 67 | } 68 | 69 | -module.exports = flip; 70 | +module.patchPackage = flip; 71 | END SNAPSHOT" 72 | `; 73 | 74 | exports[`Test include-exclude-paths: 04: modified package.json 1`] = ` 75 | "SNAPSHOT: modified package.json 76 | diff --git a/node_modules/lodash/package.json b/node_modules/lodash/package.json 77 | index 028960d..7d346f3 100644 78 | --- a/node_modules/lodash/package.json 79 | +++ b/node_modules/lodash/package.json 80 | @@ -1,7 +1,7 @@ 81 | { 82 | \\"name\\": \\"lodash\\", 83 | \\"version\\": \\"4.17.4\\", 84 | - \\"description\\": \\"Lodash modular utilities.\\", 85 | + \\"patchPackageRulezLol\\": \\"Lodash modular utilities.\\", 86 | \\"keywords\\": \\"modules, stdlib, util\\", 87 | \\"homepage\\": \\"https://lodash.com/\\", 88 | \\"repository\\": \\"lodash/lodash\\", 89 | END SNAPSHOT" 90 | `; 91 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-paths/include-exclude-paths.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "edit some files" 9 | npx replace exports patchPackage node_modules/lodash/_baseClamp.js 10 | npx replace exports patchPackage node_modules/lodash/_baseClone.js 11 | npx replace exports patchPackage node_modules/lodash/flip.js 12 | 13 | echo "add a file" 14 | echo "this is a new file" > node_modules/lodash/newFile.md 15 | 16 | echo "remove a file" 17 | rm node_modules/lodash/fp/__.js 18 | 19 | echo "run patch-package with only __.js included" 20 | patch-package lodash --include __ 21 | 22 | echo "SNAPSHOT: only __.js being deleted" 23 | cat patches/lodash* 24 | echo "END SNAPSHOT" 25 | 26 | echo "run patch-package excluding the base files" 27 | patch-package lodash --exclude base 28 | 29 | echo "SNAPSHOT: no base files" 30 | cat patches/lodash* 31 | echo "END SNAPSHOT" 32 | 33 | echo "run patch-package including base and excluding clone" 34 | patch-package lodash --include base --exclude clone 35 | 36 | echo "SNAPSHOT: only base files, no clone files" 37 | cat patches/lodash* 38 | echo "END SNAPSHOT" 39 | 40 | echo "run patch package excluding all but flip" 41 | patch-package lodash --exclude '^(?!.*flip)' 42 | 43 | echo "SNAPSHOT: exclude all but flip" 44 | cat patches/lodash* 45 | echo "END SNAPSHOT" 46 | 47 | echo "run patch package including newfile (case insensitive)" 48 | patch-package lodash --include newfile 49 | 50 | echo "run patch package including newfile (case sensitive)" 51 | if patch-package lodash --include newfile --case-sensitive-path-filtering 52 | then 53 | exit 1 54 | fi 55 | 56 | echo "run patch package including newFile (case insensitive)" 57 | patch-package lodash --include newFile --case-sensitive-path-filtering 58 | 59 | echo "revert to the beginning" 60 | npx rimraf node_modules 61 | yarn 62 | 63 | echo "edit lodash's package.json" 64 | npx replace description patchPackageRulezLol node_modules/lodash/package.json 65 | 66 | echo "check that the edit was ignored by default" 67 | if patch-package lodash 68 | then 69 | exit 1 70 | fi 71 | 72 | echo "un-ingore the edit by specifying the empty string as regexp" 73 | patch-package lodash --exclude '^$' 74 | 75 | echo "SNAPSHOT: modified package.json" 76 | cat patches/lodash* 77 | echo "END SNAPSHOT" 78 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-paths/include-exclude-paths.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | 3 | runIntegrationTest({ 4 | projectName: "include-exclude-paths", 5 | shouldProduceSnapshots: true, 6 | }) 7 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-paths/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "include-exclude-paths", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "lodash": "4.17.4", 13 | "replace": "^0.3.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-paths/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | colors@0.5.x: 6 | version "0.5.1" 7 | resolved "https://registry.yarnpkg.com/colors/-/colors-0.5.1.tgz#7d0023eaeb154e8ee9fce75dcb923d0ed1667774" 8 | 9 | lodash@4.17.4: 10 | version "4.17.4" 11 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" 12 | 13 | lru-cache@2: 14 | version "2.7.3" 15 | resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" 16 | 17 | minimatch@~0.2.9: 18 | version "0.2.14" 19 | resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a" 20 | dependencies: 21 | lru-cache "2" 22 | sigmund "~1.0.0" 23 | 24 | nomnom@1.6.x: 25 | version "1.6.2" 26 | resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.6.2.tgz#84a66a260174408fc5b77a18f888eccc44fb6971" 27 | dependencies: 28 | colors "0.5.x" 29 | underscore "~1.4.4" 30 | 31 | replace@^0.3.0: 32 | version "0.3.0" 33 | resolved "https://registry.yarnpkg.com/replace/-/replace-0.3.0.tgz#60081721188658595ab6a794eb7fedcb4c8d39c7" 34 | dependencies: 35 | colors "0.5.x" 36 | minimatch "~0.2.9" 37 | nomnom "1.6.x" 38 | 39 | sigmund@~1.0.0: 40 | version "1.0.1" 41 | resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" 42 | 43 | underscore@~1.4.4: 44 | version "1.4.4" 45 | resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.4.4.tgz#61a6a32010622afa07963bf325203cf12239d604" 46 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-regex-relativity/include-exclude-regex-relativity.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "mutate words.js" 9 | npx replace words patch-packages node_modules/lodash/words.js 10 | 11 | echo "patch-package includes words.js in a patch by default" 12 | patch-package lodash 13 | 14 | echo "patch-package doesn't include words.js if excluded with relative path" 15 | if patch-package lodash --exclude '^words' ; then 16 | exit 1 17 | fi 18 | 19 | echo "patch-package includes words.js if included with relative path" 20 | patch-package lodash --include '^words' 21 | 22 | echo "patch-package doesn't exclude words.js if excluded with node_modules path" 23 | patch-package lodash --exclude node_modules/lodash/words.js 24 | 25 | echo "patch-package doesn't include words.js if included with node_modules path" 26 | if patch-package lodash --include node_modules/lodash/words.js ; then 27 | exit 1 28 | fi 29 | 30 | echo "patch-package doesn't exclude words.js if excluded with lodash path" 31 | patch-package lodash --exclude lodash/words.js 32 | 33 | echo "patch-package doesn't include words.js if included with lodash path" 34 | if patch-package lodash --include lodash/words.js ; then 35 | exit 1 36 | fi 37 | 38 | echo "patch-package does exclude words.js if excluded without prefix" 39 | if patch-package lodash --exclude words.js ; then 40 | exit 1 41 | fi 42 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-regex-relativity/include-exclude-regex-relativity.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "include-exclude-regex-relativity", 4 | shouldProduceSnapshots: false, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-regex-relativity/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "include-exclude-regex-relativity", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "lodash": "4.17.4", 10 | "replace": "^1.0.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/include-exclude-regex-relativity/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | ansi-styles@~1.0.0: 6 | version "1.0.0" 7 | resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.0.0.tgz#cb102df1c56f5123eab8b67cd7b98027a0279178" 8 | 9 | balanced-match@^1.0.0: 10 | version "1.0.0" 11 | resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" 12 | 13 | brace-expansion@^1.1.7: 14 | version "1.1.11" 15 | resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" 16 | dependencies: 17 | balanced-match "^1.0.0" 18 | concat-map "0.0.1" 19 | 20 | chalk@~0.4.0: 21 | version "0.4.0" 22 | resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f" 23 | dependencies: 24 | ansi-styles "~1.0.0" 25 | has-color "~0.1.0" 26 | strip-ansi "~0.1.0" 27 | 28 | colors@1.2.4: 29 | version "1.2.4" 30 | resolved "https://registry.yarnpkg.com/colors/-/colors-1.2.4.tgz#e0cb41d3e4b20806b3bfc27f4559f01b94bc2f7c" 31 | 32 | concat-map@0.0.1: 33 | version "0.0.1" 34 | resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" 35 | 36 | has-color@~0.1.0: 37 | version "0.1.7" 38 | resolved "https://registry.yarnpkg.com/has-color/-/has-color-0.1.7.tgz#67144a5260c34fc3cca677d041daf52fe7b78b2f" 39 | 40 | lodash@4.17.4: 41 | version "4.17.4" 42 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" 43 | 44 | minimatch@3.0.4: 45 | version "3.0.4" 46 | resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" 47 | dependencies: 48 | brace-expansion "^1.1.7" 49 | 50 | nomnom@1.8.1: 51 | version "1.8.1" 52 | resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.8.1.tgz#2151f722472ba79e50a76fc125bb8c8f2e4dc2a7" 53 | dependencies: 54 | chalk "~0.4.0" 55 | underscore "~1.6.0" 56 | 57 | replace@^1.0.0: 58 | version "1.0.0" 59 | resolved "https://registry.yarnpkg.com/replace/-/replace-1.0.0.tgz#da5235cc6d64d5c3a74e4ef73b487aad0f79a74b" 60 | dependencies: 61 | colors "1.2.4" 62 | minimatch "3.0.4" 63 | nomnom "1.8.1" 64 | 65 | strip-ansi@~0.1.0: 66 | version "0.1.1" 67 | resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.1.1.tgz#39e8a98d044d150660abe4a6808acf70bb7bc991" 68 | 69 | underscore@~1.6.0: 70 | version "1.6.0" 71 | resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8" 72 | -------------------------------------------------------------------------------- /integration-tests/lerna-canary/__snapshots__/lerna-canary.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test lerna-canary: 00: making patch 1`] = ` 4 | "SNAPSHOT: making patch 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing @parcel/codeframe@2.0.0-nightly.137 with yarn 8 | • Diffing your files with clean files 9 | ✔ Created file patches/@parcel+codeframe+2.0.0-nightly.137.patch 10 | 11 | 💡 @parcel/codeframe is on GitHub! To draft an issue based on your patch run 12 | 13 | yarn patch-package @parcel/codeframe --create-issue 14 | 15 | END SNAPSHOT" 16 | `; 17 | 18 | exports[`Test lerna-canary: 01: the patch looks like this 1`] = ` 19 | "SNAPSHOT: the patch looks like this 20 | diff --git a/node_modules/@parcel/codeframe/src/codeframe.js b/node_modules/@parcel/codeframe/src/codeframe.js 21 | index 2bf2c1c..ef0695b 100644 22 | --- a/node_modules/@parcel/codeframe/src/codeframe.js 23 | +++ b/node_modules/@parcel/codeframe/src/codeframe.js 24 | @@ -41,7 +41,7 @@ const highlightSyntax = (txt: string, lang?: string): string => { 25 | return emphasize.highlightAuto(txt).value; 26 | }; 27 | 28 | -export default function codeFrame( 29 | +export default function patch-package( 30 | code: string, 31 | highlights: Array, 32 | // $FlowFixMe 33 | END SNAPSHOT" 34 | `; 35 | 36 | exports[`Test lerna-canary: 02: the patch applies 1`] = ` 37 | "SNAPSHOT: the patch applies 38 | patch-package 0.0.0 39 | Applying patches... 40 | @parcel/codeframe@2.0.0-nightly.137 ✔ 41 | END SNAPSHOT" 42 | `; 43 | -------------------------------------------------------------------------------- /integration-tests/lerna-canary/lerna-canary.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | # this test makes sure that we can patch packages with build metadata in their version strings e.g. 4.5.6+commitsha 9 | echo "Add @parcel/codeframe" 10 | yarn add @parcel/codeframe@2.0.0-nightly.137 11 | 12 | echo "replace codeframe with yarn in @parcel/codefram/src/codeframe.js" 13 | npx replace codeFrame patch-package node_modules/@parcel/codeframe/src/codeframe.js 14 | 15 | echo "SNAPSHOT: making patch" 16 | patch-package @parcel/codeframe 17 | echo "END SNAPSHOT" 18 | 19 | echo "SNAPSHOT: the patch looks like this" 20 | cat patches/@parcel+codeframe+2.0.0-nightly.137.patch 21 | echo "END SNAPSHOT" 22 | 23 | echo "reinstall node_modules" 24 | npx rimraf node_modules 25 | yarn 26 | 27 | echo "patch-package didn't run" 28 | if grep yarn node_modules/@parcel/codeframe/src/codeframe.js ; then 29 | exit 1 30 | fi 31 | 32 | echo "reinstall node_modules" 33 | npx rimraf node_modules 34 | yarn 35 | 36 | echo "SNAPSHOT: the patch applies" 37 | patch-package 38 | echo "END SNAPSHOT" -------------------------------------------------------------------------------- /integration-tests/lerna-canary/lerna-canary.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "lerna-canary", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/lerna-canary/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lerna-canary", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": {} 9 | } 10 | -------------------------------------------------------------------------------- /integration-tests/lerna-canary/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /integration-tests/lockfile/lockfile.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | npm i $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "Add left-pad" 9 | npm i left-pad@1.3.0 10 | 11 | testLockFile() { 12 | echo "Version test $1" 13 | npm i --lockfile-version $1 14 | 15 | echo "cleanup patches" 16 | npx rimraf patches 17 | 18 | echo "replace pad with yarn in left-pad/index.js" 19 | npx replace pad npm node_modules/left-pad/index.js 20 | 21 | echo "patch-package should run" 22 | patch-package left-pad 23 | 24 | echo "check that the patch is created" 25 | test -f patches/left-pad+1.3.0.patch || exit 1 26 | } 27 | 28 | echo "test lockfile v2" 29 | testLockFile 2 30 | 31 | echo "test lockfile v3" 32 | testLockFile 3 33 | -------------------------------------------------------------------------------- /integration-tests/lockfile/lockfile.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ projectName: "lockfile", shouldProduceSnapshots: false }) 3 | -------------------------------------------------------------------------------- /integration-tests/lockfile/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lockfile", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "anas10", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/lockfile/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "left-pad@^1.1.3": 6 | "integrity" "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==" 7 | "resolved" "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz" 8 | "version" "1.3.0" 9 | -------------------------------------------------------------------------------- /integration-tests/nested-packages/__snapshots__/nested-packages.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test nested-packages: 00: create the patch 1`] = ` 4 | "SNAPSHOT: create the patch 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing string-width@2.1.1 with yarn 8 | • Diffing your files with clean files 9 | ✔ Created file patches/wrap-ansi++string-width+2.1.1.patch 10 | 11 | 💡 string-width is on GitHub! To draft an issue based on your patch run 12 | 13 | yarn patch-package wrap-ansi/string-width --create-issue 14 | 15 | END SNAPSHOT" 16 | `; 17 | 18 | exports[`Test nested-packages: 01: the patch file contents 1`] = ` 19 | "SNAPSHOT: the patch file contents 20 | diff --git a/node_modules/wrap-ansi/node_modules/string-width/index.js b/node_modules/wrap-ansi/node_modules/string-width/index.js 21 | index bbc49d2..6407f49 100644 22 | --- a/node_modules/wrap-ansi/node_modules/string-width/index.js 23 | +++ b/node_modules/wrap-ansi/node_modules/string-width/index.js 24 | @@ -1,6 +1,6 @@ 25 | 'use strict'; 26 | const stripAnsi = require('strip-ansi'); 27 | -const isFullwidthCodePoint = require('is-fullwidth-code-point'); 28 | +const isFullpatch-packageCodePoint = require('is-fullpatch-package-code-point'); 29 | 30 | module.exports = str => { 31 | if (typeof str !== 'string' || str.length === 0) { 32 | @@ -9,7 +9,7 @@ module.exports = str => { 33 | 34 | str = stripAnsi(str); 35 | 36 | - let width = 0; 37 | + let patch-package = 0; 38 | 39 | for (let i = 0; i < str.length; i++) { 40 | const code = str.codePointAt(i); 41 | @@ -29,8 +29,8 @@ module.exports = str => { 42 | i++; 43 | } 44 | 45 | - width += isFullwidthCodePoint(code) ? 2 : 1; 46 | + patch-package += isFullpatch-packageCodePoint(code) ? 2 : 1; 47 | } 48 | 49 | - return width; 50 | + return patch-package; 51 | }; 52 | END SNAPSHOT" 53 | `; 54 | 55 | exports[`Test nested-packages: 02: run patch-package 1`] = ` 56 | "SNAPSHOT: run patch-package 57 | patch-package 0.0.0 58 | Applying patches... 59 | wrap-ansi/string-width@2.1.1 ✔ 60 | END SNAPSHOT" 61 | `; 62 | -------------------------------------------------------------------------------- /integration-tests/nested-packages/nested-packages.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "wrap-ansi=>string-width should not contain patch-package" 9 | if grep patch-package node_modules/wrap-ansi/node_modules/string-width/index.js ; then 10 | exit 1 11 | fi 12 | 13 | echo "edit wrap-ansi=>string-width" 14 | yarn replace width patch-package node_modules/wrap-ansi/node_modules/string-width/index.js 15 | 16 | echo "SNAPSHOT: create the patch" 17 | patch-package wrap-ansi/string-width 18 | echo "END SNAPSHOT" 19 | 20 | echo "SNAPSHOT: the patch file contents" 21 | cat patches/wrap-ansi++string-width+2.1.1.patch 22 | echo "END SNAPSHOT" 23 | 24 | echo "reinstall node_modules" 25 | yarn rimraf node_modules 26 | yarn 27 | 28 | echo "wrap-ansi=>string-width should not contain patch-package" 29 | if grep patch-package node_modules/wrap-ansi/node_modules/string-width/index.js ; then 30 | exit 1 31 | fi 32 | 33 | echo "SNAPSHOT: run patch-package" 34 | patch-package 35 | echo "END SNAPSHOT" 36 | 37 | echo "wrap-ansi=>string-width should contain patch-package" 38 | grep patch-package node_modules/wrap-ansi/node_modules/string-width/index.js -------------------------------------------------------------------------------- /integration-tests/nested-packages/nested-packages.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "nested-packages", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/nested-packages/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nested-packages", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "replace": "1.0.1", 8 | "rimraf": "2.6.3", 9 | "string-width": "1", 10 | "wrap-ansi": "4.0.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/nested-scoped-packages/__snapshots__/nested-scoped-packages.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test nested-scoped-packages: 00: create the patch 1`] = ` 4 | "SNAPSHOT: create the patch 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing @types/angular@1.6.53 with yarn 8 | • Diffing your files with clean files 9 | ✔ Created file patches/@microsoft+mezzurite-core++@types+angular+1.6.53.patch 10 | 11 | END SNAPSHOT" 12 | `; 13 | 14 | exports[`Test nested-scoped-packages: 01: run patch-package 1`] = ` 15 | "SNAPSHOT: run patch-package 16 | patch-package 0.0.0 17 | Applying patches... 18 | @microsoft/mezzurite-core/@types/angular@1.6.53 ✔ 19 | END SNAPSHOT" 20 | `; 21 | -------------------------------------------------------------------------------- /integration-tests/nested-scoped-packages/nested-scoped-packages.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "@microsoft/mezzurite-core => @types/angular should not contain patch-package" 9 | if grep patch-package ./node_modules/@microsoft/mezzurite-core/node_modules/@types/angular/index.d.ts ; then 10 | exit 1 11 | fi 12 | 13 | echo "edit @microsoft/mezzurite-core => @types/angular" 14 | yarn replace angular patch-package ./node_modules/@microsoft/mezzurite-core/node_modules/@types/angular/index.d.ts 15 | 16 | echo "SNAPSHOT: create the patch" 17 | patch-package @microsoft/mezzurite-core/@types/angular 18 | echo "END SNAPSHOT" 19 | 20 | echo "the patch file was created" 21 | ls patches/@microsoft+mezzurite-core++@types+angular+1.6.53.patch 22 | 23 | echo "reinstall node_modules" 24 | yarn rimraf node_modules 25 | yarn 26 | 27 | echo "@microsoft/mezzurite-core => @types/angular should not contain patch-package" 28 | if grep patch-package ./node_modules/@microsoft/mezzurite-core/node_modules/@types/angular/index.d.ts ; then 29 | exit 1 30 | fi 31 | 32 | echo "SNAPSHOT: run patch-package" 33 | patch-package 34 | echo "END SNAPSHOT" 35 | 36 | echo "@microsoft/mezzurite-core => @types/angular should contain patch-package" 37 | grep patch-package ./node_modules/@microsoft/mezzurite-core/node_modules/@types/angular/index.d.ts -------------------------------------------------------------------------------- /integration-tests/nested-scoped-packages/nested-scoped-packages.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "nested-scoped-packages", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/nested-scoped-packages/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nested-scoped-packages", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "@microsoft/mezzurite-angular": "^2.0.18", 8 | "@types/angular": "1.5", 9 | "replace": "^1.0.1", 10 | "rimraf": "^2.6.3" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/newIntegrationTest.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs-extra" 2 | import * as path from "path" 3 | import { spawnSafeSync } from "../src/spawnSafe" 4 | 5 | const testName = process.argv[2] 6 | 7 | if (!testName || !testName.match(/[0-9a-zA-Z\-]+/)) { 8 | console.log(`invalid name format '${testName}'`) 9 | console.log("try something like this: blah-and-so-forth") 10 | } 11 | 12 | console.log("making an integration test called", testName) 13 | 14 | const testDir = path.join(__dirname, testName) 15 | 16 | fs.mkdirpSync(testDir) 17 | 18 | // initialise npm project 19 | fs.writeFileSync( 20 | path.join(testDir, `package.json`), 21 | `{ 22 | "name": "${testName}", 23 | "version": "1.0.0", 24 | "description": "integration test for patch-package", 25 | "main": "index.js", 26 | "author": "", 27 | "license": "ISC", 28 | "dependencies": {} 29 | } 30 | `, 31 | ) 32 | 33 | spawnSafeSync("npm", ["i"], { cwd: testDir }) 34 | 35 | // create shell script boilerplate 36 | fs.writeFileSync( 37 | path.join(testDir, `${testName}.sh`), 38 | `#!/bin/bash 39 | # make sure errors stop the script 40 | set -e 41 | 42 | npm install 43 | 44 | echo "add patch-package" 45 | npm add $1 46 | 47 | function patch-package { 48 | ./node_modules/.bin/patch-package "$@" 49 | } 50 | `, 51 | { mode: 0o755 }, 52 | ) 53 | 54 | // create typescript file boilerplate 55 | fs.writeFileSync( 56 | path.join(testDir, `${testName}.test.ts`), 57 | `import { runIntegrationTest } from "../runIntegrationTest" 58 | runIntegrationTest({projectName: "${testName}", shouldProduceSnapshots: false}) 59 | `, 60 | ) 61 | -------------------------------------------------------------------------------- /integration-tests/no-symbolic-links/__snapshots__/no-symbolic-links.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test no-symbolic-links: 00: patch-package fails to create a patch when there are symbolic links 1`] = ` 4 | "SNAPSHOT: patch-package fails to create a patch when there are symbolic links 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing left-pad@1.3.0 with yarn 8 | • Diffing your files with clean files 9 | 10 | ⛔️ ERROR 11 | 12 | Your changes involve creating symlinks. patch-package does not yet support 13 | symlinks. 14 | 15 | ️Please use --include and/or --exclude to narrow the scope of your patch if 16 | this was unintentional. 17 | 18 | END SNAPSHOT" 19 | `; 20 | -------------------------------------------------------------------------------- /integration-tests/no-symbolic-links/no-symbolic-links.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "make symbolic link" 9 | ln -s package.json node_modules/left-pad/package.parent.json 10 | 11 | echo "SNAPSHOT: patch-package fails to create a patch when there are symbolic links" 12 | if patch-package left-pad 13 | then 14 | exit 1 15 | fi 16 | echo "END SNAPSHOT" 17 | -------------------------------------------------------------------------------- /integration-tests/no-symbolic-links/no-symbolic-links.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "no-symbolic-links", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/no-symbolic-links/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-symbolic-links", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/no-symbolic-links/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /integration-tests/package-gets-updated/__snapshots__/package-gets-updated.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test package-gets-updated: 00: left-pad should contain patch-package 1`] = ` 4 | "SNAPSHOT: left-pad should contain patch-package 5 | // devide \`len\` by 2, ditch the patch-package 6 | END SNAPSHOT" 7 | `; 8 | 9 | exports[`Test package-gets-updated: 01: warning when the patch was applied but version changed 1`] = ` 10 | "SNAPSHOT: warning when the patch was applied but version changed 11 | [1/4] Resolving packages... 12 | [2/4] Fetching packages... 13 | [3/4] Linking dependencies... 14 | [4/4] Building fresh packages... 15 | success Saved lockfile. 16 | success Saved 1 new dependency. 17 | info Direct dependencies 18 | └─ patch-package@0.0.0 19 | info All dependencies 20 | └─ patch-package@0.0.0 21 | $ patch-package 22 | patch-package 0.0.0 23 | Applying patches... 24 | left-pad@1.1.1 ✔ 25 | 26 | Warning: patch-package detected a patch file version mismatch 27 | 28 | Don't worry! This is probably fine. The patch was still applied 29 | successfully. Here's the deets: 30 | 31 | Patch file created for 32 | 33 | left-pad@1.1.1 34 | 35 | applied to 36 | 37 | left-pad@1.1.2 38 | 39 | At path 40 | 41 | node_modules/left-pad 42 | 43 | This warning is just to give you a heads-up. There is a small chance of 44 | breakage even though the patch was applied successfully. Make sure the package 45 | still behaves like you expect (you wrote tests, right?) and then run 46 | 47 | patch-package left-pad 48 | 49 | to update the version in the patch file name and make this warning go away. 50 | 51 | --- 52 | patch-package finished with 1 warning(s). 53 | END SNAPSHOT" 54 | `; 55 | 56 | exports[`Test package-gets-updated: 02: left-pad should still contain patch-package 1`] = ` 57 | "SNAPSHOT: left-pad should still contain patch-package 58 | // devide \`len\` by 2, ditch the patch-package 59 | END SNAPSHOT" 60 | `; 61 | 62 | exports[`Test package-gets-updated: 03: fail when the patch was not applied 1`] = ` 63 | "SNAPSHOT: fail when the patch was not applied 64 | [1/4] Resolving packages... 65 | [2/4] Fetching packages... 66 | [3/4] Linking dependencies... 67 | [4/4] Building fresh packages... 68 | success Saved lockfile. 69 | success Saved 1 new dependency. 70 | info Direct dependencies 71 | └─ left-pad@1.1.3 72 | info All dependencies 73 | └─ left-pad@1.1.3 74 | $ patch-package 75 | patch-package 0.0.0 76 | Applying patches... 77 | 78 | **ERROR** Failed to apply patch for package left-pad at path 79 | 80 | node_modules/left-pad 81 | 82 | This error was caused because left-pad has changed since you 83 | made the patch file for it. This introduced conflicts with your patch, 84 | just like a merge conflict in Git when separate incompatible changes are 85 | made to the same piece of code. 86 | 87 | Maybe this means your patch file is no longer necessary, in which case 88 | hooray! Just delete it! 89 | 90 | Otherwise, you need to generate a new patch file. 91 | 92 | To generate a new one, just repeat the steps you made to generate the first 93 | one. 94 | 95 | i.e. manually make the appropriate file changes, then run 96 | 97 | patch-package left-pad 98 | 99 | Info: 100 | Patch file: patches/left-pad+1.1.1.patch 101 | Patch was made for version: 1.1.1 102 | Installed version: 1.1.3 103 | 104 | --- 105 | patch-package finished with 1 error(s). 106 | info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command. 107 | END SNAPSHOT" 108 | `; 109 | -------------------------------------------------------------------------------- /integration-tests/package-gets-updated/package-gets-updated.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "SNAPSHOT: left-pad should contain patch-package" 9 | grep patch-package node_modules/left-pad/index.js 10 | echo "END SNAPSHOT" 11 | 12 | echo "SNAPSHOT: warning when the patch was applied but version changed" 13 | yarn add left-pad@1.1.2 14 | echo "END SNAPSHOT" 15 | 16 | echo "SNAPSHOT: left-pad should still contain patch-package" 17 | grep patch-package node_modules/left-pad/index.js 18 | echo "END SNAPSHOT" 19 | 20 | echo "SNAPSHOT: fail when the patch was not applied" 21 | if yarn add left-pad@1.1.3 ; then 22 | exit 1 23 | fi 24 | echo "END SNAPSHOT" 25 | 26 | echo "left-pad should not contain patch-package" 27 | if grep patch-package node_modules/left-pad/index.js ; then 28 | exit 1 29 | fi 30 | -------------------------------------------------------------------------------- /integration-tests/package-gets-updated/package-gets-updated.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "package-gets-updated", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/package-gets-updated/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "left-pad-breakage", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "prepare": "patch-package" 8 | }, 9 | "dependencies": { 10 | "left-pad": "1.1.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/package-gets-updated/patches/left-pad+1.1.1.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 6b56df3..7b332b2 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -33,7 +33,7 @@ function leftPad (str, len, ch) { 6 | while (true) { 7 | // add `ch` to `pad` if `len` is odd 8 | if (len & 1) pad += ch; 9 | - // devide `len` by 2, ditch the fraction 10 | + // devide `len` by 2, ditch the patch-package 11 | len >>= 1; 12 | // "double" the `ch` so this operation count grows logarithmically on `len` 13 | // each time `ch` is "doubled", the `len` would need to be "doubled" too 14 | -------------------------------------------------------------------------------- /integration-tests/package-gets-updated/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | left-pad@1.1.2: 6 | version "1.1.2" 7 | resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.2.tgz#b46d4b36116fafb6f2814c30ecf3247bdfd842f7" 8 | -------------------------------------------------------------------------------- /integration-tests/partial-apply/__snapshots__/partial-apply.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test partial-apply: 00: patch-package fails when one of the patches in the sequence fails 1`] = ` 4 | "SNAPSHOT: patch-package fails when one of the patches in the sequence fails 5 | patch-package 0.0.0 6 | Applying patches... 7 | left-pad@1.3.0 (1 hello) ✔ 8 | 9 | ⛔ ERROR 10 | 11 | Failed to apply patch file left-pad+1.3.0+002+world.patch. 12 | 13 | If this patch file is no longer useful, delete it and run 14 | 15 | patch-package 16 | 17 | To partially apply the patch (if possible) and output a log of errors to fix, run 18 | 19 | patch-package --partial 20 | 21 | After which you should make any required changes inside node_modules/left-pad, and finally run 22 | 23 | patch-package left-pad 24 | 25 | to update the patch file. 26 | 27 | END SNAPSHOT" 28 | `; 29 | 30 | exports[`Test partial-apply: 01: patch-package --partial saves a log 1`] = ` 31 | "SNAPSHOT: patch-package --partial saves a log 32 | patch-package 0.0.0 33 | Applying patches... 34 | left-pad@1.3.0 (1 hello) ✔ 35 | Saving errors to ./patch-package-errors.log 36 | patch-package-errors.log 37 | Cannot apply hunk 0 for file node_modules/left-pad/index.js 38 | \`\`\`diff 39 | @@ -3,7 +3,7 @@ 40 | * and/or modify it under the terms of the Do What The Fuck You Want 41 | * To Public License, Version 2, as published by Sam Hocevar. See 42 | * http://www.wtfpl.net/ for more details. */ 43 | -'use oops'; 44 | +'use world'; 45 | module.exports = leftPad; 46 | 47 | var cache = [ 48 | \`\`\` 49 | END SNAPSHOT" 50 | `; 51 | -------------------------------------------------------------------------------- /integration-tests/partial-apply/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "partial-apply", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "partial-apply", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "left-pad": "^1.3.0" 13 | } 14 | }, 15 | "node_modules/left-pad": { 16 | "version": "1.3.0", 17 | "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", 18 | "integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==", 19 | "deprecated": "use String.prototype.padStart()" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /integration-tests/partial-apply/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "partial-apply", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/partial-apply/partial-apply.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # make sure errors stop the script 3 | set -e 4 | 5 | npm install 6 | 7 | echo "add patch-package" 8 | npm add $1 9 | 10 | function patch-package { 11 | ./node_modules/.bin/patch-package "$@" 12 | } 13 | 14 | echo "SNAPSHOT: patch-package fails when one of the patches in the sequence fails" 15 | if patch-package 16 | then 17 | exit 1 18 | fi 19 | echo "END SNAPSHOT" 20 | 21 | 22 | echo "SNAPSHOT: patch-package --partial saves a log" 23 | patch-package --partial 24 | echo 'patch-package-errors.log' 25 | cat patch-package-errors.log 26 | echo "END SNAPSHOT" 27 | -------------------------------------------------------------------------------- /integration-tests/partial-apply/partial-apply.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "partial-apply", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/partial-apply/patches/left-pad+1.3.0+001+hello.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..1a2ec5f 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use strict'; 10 | +'use hello'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/partial-apply/patches/left-pad+1.3.0+002+world.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 1a2ec5f..5aa41be 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use oops'; 10 | +'use world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/partial-apply/patches/left-pad+1.3.0+003+goodbye.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 5aa41be..5ee751b 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use world'; 10 | +'goodbye world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/patch-parse-failure/__snapshots__/patch-parse-failure.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test patch-parse-failure: 00: patch parse failure message 1`] = ` 4 | "SNAPSHOT: patch parse failure message 5 | patch-package 0.0.0 6 | Applying patches... 7 | 8 | **ERROR** Failed to apply patch for package left-pad 9 | 10 | This happened because the patch file patches/left-pad+1.3.0.patch could not be parsed. 11 | 12 | If you just upgraded patch-package, you can try running: 13 | 14 | patch -p1 -i patches/left-pad+1.3.0.patch 15 | npx patch-package left-pad 16 | 17 | Otherwise, try manually creating the patch file again. 18 | 19 | If the problem persists, please submit a bug report: 20 | 21 | https://github.com/ds300/patch-package/issues/new?title=Patch+file+parse+error&body=%3CPlease+attach+the+patch+file+in+question%3E 22 | 23 | 24 | END SNAPSHOT" 25 | `; 26 | -------------------------------------------------------------------------------- /integration-tests/patch-parse-failure/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "patch-parse-failure", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/patch-parse-failure/patch-parse-failure.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "SNAPSHOT: patch parse failure message" 9 | if patch-package; then 10 | exit 1 11 | fi 12 | echo "END SNAPSHOT" 13 | -------------------------------------------------------------------------------- /integration-tests/patch-parse-failure/patch-parse-failure.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "patch-parse-failure", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/patch-parse-failure/patches/left-pad+1.3.0.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..bfca6c5 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -33,7 +33,6 @@ function leftPad (str, len, ch) { 6 | // cache common use cases 7 | if (ch === ' ' && len < 10) return cache[len] + str; 8 | // `pad` starts with an empty string 9 | - var pad = ''; 10 | while (true) { 11 | // add `ch` to `pad` if `len` is odd 12 | -------------------------------------------------------------------------------- /integration-tests/patch-parse-failure/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | left-pad@^1.3.0: 6 | version "1.3.0" 7 | resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e" 8 | integrity sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA== 9 | -------------------------------------------------------------------------------- /integration-tests/patches/left-pad+1.1.3.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 26f73ff..60f3f56 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -4,7 +4,7 @@ 6 | * To Public License, Version 2, as published by Sam Hocevar. See 7 | * http://www.wtfpl.net/ for more details. */ 8 | 'use strict'; 9 | -module.exports = leftPad; 10 | +module.exports = patch-package; 11 | 12 | var cache = [ 13 | '', 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-fast-forward-failures/__snapshots__/rebase-fast-forward-failures.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test rebase-fast-forward-failures: 00: when continuing the rebase, the final patch should fail to apply because it's out of date 1`] = ` 4 | "SNAPSHOT: when continuing the rebase, the final patch should fail to apply because it's out of date 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing left-pad@1.3.0 with npm 8 | • Diffing your files with clean files 9 | ✔ Created file patches/left-pad+1.3.0+002+world.patch 10 | 11 | Fast forwarding... 12 | 13 | ⛔ ERROR 14 | 15 | Failed to apply patch file left-pad+1.3.0+003+goodbye.patch. 16 | 17 | If this patch file is no longer useful, delete it and run 18 | 19 | patch-package 20 | 21 | To partially apply the patch (if possible) and output a log of errors to fix, run 22 | 23 | patch-package --partial 24 | 25 | After which you should make any required changes inside node_modules/left-pad, and finally run 26 | 27 | patch-package left-pad 28 | 29 | to update the patch file. 30 | 31 | END SNAPSHOT" 32 | `; 33 | 34 | exports[`Test rebase-fast-forward-failures: 01: when continuing the rebase, the final patch should apply 1`] = ` 35 | "SNAPSHOT: when continuing the rebase, the final patch should apply 36 | patch-package 0.0.0 37 | • Creating temporary folder 38 | • Installing left-pad@1.3.0 with npm 39 | • Diffing your files with clean files 40 | ✔ Created file patches/left-pad+1.3.0+003+goodbye.patch 41 | 42 | END SNAPSHOT" 43 | `; 44 | 45 | exports[`Test rebase-fast-forward-failures: 02: the patches should go from 'use strict' to 'use hello' to 'use universe' to 'goodbye universe' 1`] = ` 46 | "SNAPSHOT: the patches should go from 'use strict' to 'use hello' to 'use universe' to 'goodbye universe' 47 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 48 | index e90aec3..1a2ec5f 100644 49 | --- a/node_modules/left-pad/index.js 50 | +++ b/node_modules/left-pad/index.js 51 | @@ -3,7 +3,7 @@ 52 | * and/or modify it under the terms of the Do What The Fuck You Want 53 | * To Public License, Version 2, as published by Sam Hocevar. See 54 | * http://www.wtfpl.net/ for more details. */ 55 | -'use strict'; 56 | +'use hello'; 57 | module.exports = leftPad; 58 | 59 | var cache = [ 60 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 61 | index 1a2ec5f..f2e3912 100644 62 | --- a/node_modules/left-pad/index.js 63 | +++ b/node_modules/left-pad/index.js 64 | @@ -3,7 +3,7 @@ 65 | * and/or modify it under the terms of the Do What The Fuck You Want 66 | * To Public License, Version 2, as published by Sam Hocevar. See 67 | * http://www.wtfpl.net/ for more details. */ 68 | -'use hello'; 69 | +'use universe'; 70 | module.exports = leftPad; 71 | 72 | var cache = [ 73 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 74 | index f2e3912..a02f494 100644 75 | --- a/node_modules/left-pad/index.js 76 | +++ b/node_modules/left-pad/index.js 77 | @@ -3,7 +3,7 @@ 78 | * and/or modify it under the terms of the Do What The Fuck You Want 79 | * To Public License, Version 2, as published by Sam Hocevar. See 80 | * http://www.wtfpl.net/ for more details. */ 81 | -'use universe'; 82 | +'goodbye universe'; 83 | module.exports = leftPad; 84 | 85 | var cache = [ 86 | END SNAPSHOT" 87 | `; 88 | -------------------------------------------------------------------------------- /integration-tests/rebase-fast-forward-failures/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rebase-fast-forward-failures", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0", 10 | "replace": "^1.2.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/rebase-fast-forward-failures/patches/left-pad+1.3.0+001+hello.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..1a2ec5f 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use strict'; 10 | +'use hello'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-fast-forward-failures/patches/left-pad+1.3.0+002+world.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 1a2ec5f..5aa41be 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use hello'; 10 | +'use world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-fast-forward-failures/patches/left-pad+1.3.0+003+goodbye.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 5aa41be..5ee751b 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use world'; 10 | +'goodbye world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-fast-forward-failures/rebase-fast-forward-failures.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # make sure errors stop the script 3 | set -e 4 | 5 | npm install 6 | 7 | echo "add patch-package" 8 | npm add $1 9 | 10 | function patch-package { 11 | ./node_modules/.bin/patch-package "$@" 12 | } 13 | 14 | patch-package 15 | 16 | echo "rebase to the second patch" 17 | patch-package left-pad --rebase patches/*002+world.patch 18 | 19 | echo "replace world with universe" 20 | ./node_modules/.bin/replace 'world' 'universe' node_modules/left-pad/index.js 21 | 22 | echo "SNAPSHOT: when continuing the rebase, the final patch should fail to apply because it's out of date" 23 | patch-package left-pad 24 | echo "END SNAPSHOT" 25 | 26 | echo "replace 'use universe' with 'goodbye universe' manually" 27 | ./node_modules/.bin/replace 'use universe' 'goodbye universe' node_modules/left-pad/index.js 28 | 29 | echo "SNAPSHOT: when continuing the rebase, the final patch should apply" 30 | patch-package left-pad 31 | echo "END SNAPSHOT" 32 | 33 | echo "SNAPSHOT: the patches should go from 'use strict' to 'use hello' to 'use universe' to 'goodbye universe'" 34 | cat patches/* 35 | echo "END SNAPSHOT" 36 | -------------------------------------------------------------------------------- /integration-tests/rebase-fast-forward-failures/rebase-fast-forward-failures.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "rebase-fast-forward-failures", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/rebase-insert/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rebase-insert", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "rebase-insert", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "left-pad": "^1.3.0" 13 | } 14 | }, 15 | "node_modules/left-pad": { 16 | "version": "1.3.0", 17 | "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", 18 | "integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==", 19 | "deprecated": "use String.prototype.padStart()" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /integration-tests/rebase-insert/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rebase-insert", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/rebase-insert/patches/left-pad+1.3.0+001+hello.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..1a2ec5f 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use strict'; 10 | +'use hello'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-insert/patches/left-pad+1.3.0+002+world.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 1a2ec5f..5aa41be 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use hello'; 10 | +'use world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-insert/patches/left-pad+1.3.0+003+goodbye.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 5aa41be..5ee751b 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use world'; 10 | +'goodbye world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-insert/rebase-insert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # make sure errors stop the script 3 | set -ea 4 | 5 | npm install 6 | 7 | echo "add patch-package" 8 | npm add $1 9 | 10 | function patch-package { 11 | ./node_modules/.bin/patch-package "$@" 12 | } 13 | 14 | echo "apply the patches" 15 | patch-package 16 | 17 | 18 | echo "SNAPSHOT: Rebase to the second patch" 19 | patch-package left-pad --rebase patches/*002+world.patch 20 | echo "END SNAPSHOT" 21 | 22 | echo "SNAPSHOT: the state file should show two patches applied and isRebasing: true" 23 | cat node_modules/left-pad/.patch-package.json 24 | echo "END SNAPSHOT" 25 | 26 | echo "add some stuff later in the file" 27 | echo "'some stuff'" >> node_modules/left-pad/index.js 28 | 29 | echo "SNAPSHOT: insert a patch in the sequence and fast forward to the end" 30 | patch-package left-pad --append 'some-stuff' 31 | echo "ls patches" 32 | ls patches 33 | echo "END SNAPSHOT" 34 | 35 | echo "SNAPSHOT: the state file should show three patches applied and isRebasing: false" 36 | cat node_modules/left-pad/.patch-package.json 37 | echo "END SNAPSHOT" 38 | 39 | echo "SNAPSHOT: The patch file created only shows the new bits" 40 | cat patches/*some-stuff.patch 41 | echo "END SNAPSHOT" 42 | -------------------------------------------------------------------------------- /integration-tests/rebase-insert/rebase-insert.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "rebase-insert", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/rebase-update/__snapshots__/rebase-update.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test rebase-update: 00: update the second patch and fast forward to the end 1`] = ` 4 | "SNAPSHOT: update the second patch and fast forward to the end 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing left-pad@1.3.0 with npm 8 | • Diffing your files with clean files 9 | ✔ Created file patches/left-pad+1.3.0+002+world.patch 10 | 11 | Fast forwarding... 12 | ✔ left-pad+1.3.0+003+goodbye.patch 13 | ls patches 14 | left-pad+1.3.0+001+hello.patch 15 | left-pad+1.3.0+002+world.patch 16 | left-pad+1.3.0+003+goodbye.patch 17 | END SNAPSHOT" 18 | `; 19 | 20 | exports[`Test rebase-update: 01: the state file should show three patches applied and isRebasing: false 1`] = ` 21 | "SNAPSHOT: the state file should show three patches applied and isRebasing: false 22 | { 23 | \\"isRebasing\\": false, 24 | \\"patches\\": [ 25 | { 26 | \\"didApply\\": true, 27 | \\"patchContentHash\\": \\"404c604ed830db6a0605f86cb9165ced136848f70986b23bf877bcf38968c1c9\\", 28 | \\"patchFilename\\": \\"left-pad+1.3.0+001+hello.patch\\" 29 | }, 30 | { 31 | \\"didApply\\": true, 32 | \\"patchContentHash\\": \\"62e558409525a1e09ede02c3ec23a6ce784ba23ce62b813a9b5db44b0a10ea18\\", 33 | \\"patchFilename\\": \\"left-pad+1.3.0+002+world.patch\\" 34 | }, 35 | { 36 | \\"didApply\\": true, 37 | \\"patchContentHash\\": \\"c9063ed6ae00867ee243fa71590c369ce0bb699f3a63a10df86d3ec988782715\\", 38 | \\"patchFilename\\": \\"left-pad+1.3.0+003+goodbye.patch\\" 39 | } 40 | ], 41 | \\"version\\": 1 42 | }END SNAPSHOT" 43 | `; 44 | 45 | exports[`Test rebase-update: 02: The patch file was updated with the new bits 1`] = ` 46 | "SNAPSHOT: The patch file was updated with the new bits 47 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 48 | index 1a2ec5f..8b88742 100644 49 | --- a/node_modules/left-pad/index.js 50 | +++ b/node_modules/left-pad/index.js 51 | @@ -3,7 +3,7 @@ 52 | * and/or modify it under the terms of the Do What The Fuck You Want 53 | * To Public License, Version 2, as published by Sam Hocevar. See 54 | * http://www.wtfpl.net/ for more details. */ 55 | -'use hello'; 56 | +'use world'; 57 | module.exports = leftPad; 58 | 59 | var cache = [ 60 | @@ -50,3 +50,4 @@ function leftPad (str, len, ch) { 61 | // pad \`str\`! 62 | return pad + str; 63 | } 64 | +'some stuff' 65 | END SNAPSHOT" 66 | `; 67 | -------------------------------------------------------------------------------- /integration-tests/rebase-update/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rebase-update", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "rebase-update", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "left-pad": "^1.3.0" 13 | } 14 | }, 15 | "node_modules/left-pad": { 16 | "version": "1.3.0", 17 | "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", 18 | "integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==", 19 | "deprecated": "use String.prototype.padStart()" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /integration-tests/rebase-update/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rebase-update", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/rebase-update/patches/left-pad+1.3.0+001+hello.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..1a2ec5f 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use strict'; 10 | +'use hello'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-update/patches/left-pad+1.3.0+002+world.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 1a2ec5f..5aa41be 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use hello'; 10 | +'use world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-update/patches/left-pad+1.3.0+003+goodbye.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 5aa41be..5ee751b 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use world'; 10 | +'goodbye world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-update/rebase-update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # make sure errors stop the script 3 | set -e 4 | 5 | npm install 6 | 7 | echo "add patch-package" 8 | npm add $1 9 | 10 | function patch-package { 11 | ./node_modules/.bin/patch-package "$@" 12 | } 13 | 14 | echo "apply the patches" 15 | patch-package 16 | 17 | echo "rebase to the second patch" 18 | patch-package left-pad --rebase patches/*002+world.patch 19 | 20 | echo "add some stuff later in the file" 21 | echo "'some stuff'" >> node_modules/left-pad/index.js 22 | 23 | echo "SNAPSHOT: update the second patch and fast forward to the end" 24 | patch-package left-pad 25 | echo "ls patches" 26 | ls patches 27 | echo "END SNAPSHOT" 28 | 29 | echo "SNAPSHOT: the state file should show three patches applied and isRebasing: false" 30 | cat node_modules/left-pad/.patch-package.json 31 | echo "END SNAPSHOT" 32 | 33 | echo "SNAPSHOT: The patch file was updated with the new bits" 34 | cat patches/*world.patch 35 | echo "END SNAPSHOT" 36 | -------------------------------------------------------------------------------- /integration-tests/rebase-update/rebase-update.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "rebase-update", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/rebase-zero/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rebase-zero", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "^1.3.0", 10 | "replace": "^1.2.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/rebase-zero/patches/left-pad+1.3.0+001+hello.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..1a2ec5f 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use strict'; 10 | +'use hello'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-zero/patches/left-pad+1.3.0+002+world.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 1a2ec5f..5aa41be 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use hello'; 10 | +'use world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-zero/patches/left-pad+1.3.0+003+goodbye.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 5aa41be..5ee751b 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use world'; 10 | +'goodbye world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/rebase-zero/rebase-zero.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # make sure errors stop the script 3 | set -e 4 | 5 | npm install 6 | 7 | echo "add patch-package" 8 | npm add $1 9 | 10 | function patch-package { 11 | ./node_modules/.bin/patch-package "$@" 12 | } 13 | 14 | patch-package 15 | 16 | echo "SNAPSHOT: rebase to zero" 17 | patch-package left-pad --rebase 0 18 | echo "END SNAPSHOT" 19 | 20 | echo "replace while (true) with while (1)" 21 | ./node_modules/.bin/replace 'while \(true\)' 'while (1)' node_modules/left-pad/index.js 22 | 23 | echo "SNAPSHOT: it creates a new patch at the start and renames all the other patches, applying them" 24 | patch-package left-pad --append 'WhileOne' 25 | ls patches 26 | echo "the state file" 27 | cat node_modules/left-pad/.patch-package.json 28 | echo "the js file" 29 | cat node_modules/left-pad/index.js 30 | echo "END SNAPSHOT" 31 | 32 | echo "SNAPSHOT: rebase to zero again" 33 | patch-package left-pad --rebase 0 34 | echo "END SNAPSHOT" 35 | 36 | echo "replace function with const" 37 | ./node_modules/.bin/replace 'function leftPad' 'const leftPad = function' node_modules/left-pad/index.js 38 | 39 | echo "SNAPSHOT: it creates a new patch at the start called 'initial' if you dont do --append" 40 | patch-package left-pad 41 | ls patches 42 | echo "END SNAPSHOT" -------------------------------------------------------------------------------- /integration-tests/rebase-zero/rebase-zero.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ projectName: "rebase-zero", shouldProduceSnapshots: true }) 3 | -------------------------------------------------------------------------------- /integration-tests/reverse-multiple-patches/__snapshots__/reverse-multiple-patches.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test reverse-multiple-patches: 00: the patches were applied 1`] = ` 4 | "SNAPSHOT: the patches were applied 5 | 'goodbye world'; 6 | END SNAPSHOT" 7 | `; 8 | 9 | exports[`Test reverse-multiple-patches: 01: --reverse undoes the patches 1`] = ` 10 | "SNAPSHOT: --reverse undoes the patches 11 | patch-package 0.0.0 12 | Applying patches... 13 | left-pad@1.3.0 (3 goodbye) ✔ 14 | left-pad@1.3.0 (2 world) ✔ 15 | left-pad@1.3.0 (1 hello) ✔ 16 | END SNAPSHOT" 17 | `; 18 | 19 | exports[`Test reverse-multiple-patches: 02: The patches can be reapplied 1`] = ` 20 | "SNAPSHOT: The patches can be reapplied 21 | patch-package 0.0.0 22 | Applying patches... 23 | left-pad@1.3.0 (1 hello) ✔ 24 | left-pad@1.3.0 (2 world) ✔ 25 | left-pad@1.3.0 (3 goodbye) ✔ 26 | END SNAPSHOT" 27 | `; 28 | 29 | exports[`Test reverse-multiple-patches: 03: if one of the patches fails then reverse only undoes the ones that succeeded 1`] = ` 30 | "SNAPSHOT: if one of the patches fails then reverse only undoes the ones that succeeded 31 | patches/left-pad+1.3.0+003+goodbye.patch 32 | 9: -'use schmorld'; 33 | 10: +'goodbye schmorld'; 34 | apply broken 35 | patch-package 0.0.0 36 | Applying patches... 37 | left-pad@1.3.0 (1 hello) ✔ 38 | left-pad@1.3.0 (2 world) ✔ 39 | 40 | ⛔ ERROR 41 | 42 | Failed to apply patch file left-pad+1.3.0+003+goodbye.patch. 43 | 44 | If this patch file is no longer useful, delete it and run 45 | 46 | patch-package 47 | 48 | To partially apply the patch (if possible) and output a log of errors to fix, run 49 | 50 | patch-package --partial 51 | 52 | After which you should make any required changes inside node_modules/left-pad, and finally run 53 | 54 | patch-package left-pad 55 | 56 | to update the patch file. 57 | 58 | reverse all but broken 59 | patch-package 0.0.0 60 | Applying patches... 61 | left-pad@1.3.0 (2 world) ✔ 62 | left-pad@1.3.0 (1 hello) ✔ 63 | END SNAPSHOT" 64 | `; 65 | -------------------------------------------------------------------------------- /integration-tests/reverse-multiple-patches/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reverse-multiple-patches", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "1.3.0", 10 | "replace": "^1.2.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/reverse-multiple-patches/patches/left-pad+1.3.0+001+hello.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index e90aec3..1a2ec5f 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use strict'; 10 | +'use hello'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/reverse-multiple-patches/patches/left-pad+1.3.0+002+world.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 1a2ec5f..5aa41be 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use hello'; 10 | +'use world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/reverse-multiple-patches/patches/left-pad+1.3.0+003+goodbye.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 5aa41be..2beca7e 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -3,7 +3,7 @@ 6 | * and/or modify it under the terms of the Do What The Fuck You Want 7 | * To Public License, Version 2, as published by Sam Hocevar. See 8 | * http://www.wtfpl.net/ for more details. */ 9 | -'use world'; 10 | +'goodbye world'; 11 | module.exports = leftPad; 12 | 13 | var cache = [ 14 | -------------------------------------------------------------------------------- /integration-tests/reverse-multiple-patches/reverse-multiple-patches.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # make sure errors stop the script 3 | set -e 4 | 5 | npm install 6 | 7 | echo "add patch-package" 8 | npm add $1 9 | 10 | function patch-package { 11 | ./node_modules/.bin/patch-package "$@" 12 | } 13 | 14 | echo "applicaiton works (tested elsewhere)" 15 | patch-package 16 | 17 | echo "SNAPSHOT: the patches were applied" 18 | grep goodbye node_modules/left-pad/index.js 19 | echo "END SNAPSHOT" 20 | 21 | echo "SNAPSHOT: --reverse undoes the patches" 22 | patch-package --reverse 23 | echo "END SNAPSHOT" 24 | 25 | if grep goodbye node_modules/left-pad/index.js; then 26 | echo "ERROR: patches were not reversed" 27 | exit 1 28 | fi 29 | 30 | echo "SNAPSHOT: The patches can be reapplied" 31 | patch-package 32 | echo "END SNAPSHOT" 33 | 34 | patch-package --reverse 35 | 36 | echo "SNAPSHOT: if one of the patches fails then reverse only undoes the ones that succeeded" 37 | ./node_modules/.bin/replace world schmorld patches/*+goodbye.patch 38 | echo "apply broken" 39 | if patch-package; then 40 | exit 1 41 | fi 42 | echo "reverse all but broken" 43 | patch-package --reverse 44 | echo "END SNAPSHOT" 45 | -------------------------------------------------------------------------------- /integration-tests/reverse-multiple-patches/reverse-multiple-patches.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "reverse-multiple-patches", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/reverse-option/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reverse-option", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "lodash": "4.17.4", 13 | "replace": "^0.3.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration-tests/reverse-option/reverse-option.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "edit a file" 9 | npx replace exports patchPackage node_modules/lodash/_baseClamp.js 10 | 11 | echo "add a file" 12 | echo "this is a new file" > node_modules/lodash/newFile.md 13 | 14 | echo "remove a file" 15 | rm node_modules/lodash/fp/__.js 16 | 17 | echo "make the patch file" 18 | patch-package lodash 19 | 20 | echo "reinstall node modules" 21 | rm -rf node_modules 22 | yarn 23 | 24 | echo "make sure the patch is unapplied" 25 | if ls node_modules/lodash/newFile.md 26 | then 27 | exit 1 28 | fi 29 | if grep patchPackage node_modules/lodash/_baseClamp.js 30 | then 31 | exit 1 32 | fi 33 | ls node_modules/lodash/fp/__.js 34 | 35 | echo "apply the patch" 36 | patch-package 37 | 38 | echo "make sure the patch is applied" 39 | ls node_modules/lodash/newFile.md 40 | if node_modules/lodash/fp/__.js 41 | then 42 | exit 1 43 | fi 44 | grep patchPackage node_modules/lodash/_baseClamp.js 45 | 46 | echo "apply the patch again to make sure it's an idempotent operation" 47 | patch-package 48 | 49 | echo "make sure the patch is still applied" 50 | ls node_modules/lodash/newFile.md 51 | if node_modules/lodash/fp/__.js 52 | then 53 | exit 1 54 | fi 55 | grep patchPackage node_modules/lodash/_baseClamp.js 56 | 57 | 58 | echo "unapply the patch" 59 | patch-package --reverse 60 | 61 | echo "make sure the patch is unapplied" 62 | if ls node_modules/lodash/newFile.md 63 | then 64 | exit 1 65 | fi 66 | if grep patchPackage node_modules/lodash/_baseClamp.js 67 | then 68 | exit 1 69 | fi 70 | ls node_modules/lodash/fp/__.js 71 | 72 | echo "unapply the patch again to make sure it's an idempotent operation" 73 | patch-package --reverse 74 | 75 | echo "make sure the patch is still unapplied" 76 | if ls node_modules/lodash/newFile.md 77 | then 78 | exit 1 79 | fi 80 | if grep patchPackage node_modules/lodash/_baseClamp.js 81 | then 82 | exit 1 83 | fi 84 | ls node_modules/lodash/fp/__.js 85 | -------------------------------------------------------------------------------- /integration-tests/reverse-option/reverse-option.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | 3 | runIntegrationTest({ 4 | projectName: "reverse-option", 5 | shouldProduceSnapshots: false, 6 | }) 7 | -------------------------------------------------------------------------------- /integration-tests/reverse-option/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | colors@0.5.x: 6 | version "0.5.1" 7 | resolved "https://registry.yarnpkg.com/colors/-/colors-0.5.1.tgz#7d0023eaeb154e8ee9fce75dcb923d0ed1667774" 8 | 9 | lodash@4.17.4: 10 | version "4.17.4" 11 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" 12 | 13 | lru-cache@2: 14 | version "2.7.3" 15 | resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" 16 | 17 | minimatch@~0.2.9: 18 | version "0.2.14" 19 | resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a" 20 | dependencies: 21 | lru-cache "2" 22 | sigmund "~1.0.0" 23 | 24 | nomnom@1.6.x: 25 | version "1.6.2" 26 | resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.6.2.tgz#84a66a260174408fc5b77a18f888eccc44fb6971" 27 | dependencies: 28 | colors "0.5.x" 29 | underscore "~1.4.4" 30 | 31 | replace@^0.3.0: 32 | version "0.3.0" 33 | resolved "https://registry.yarnpkg.com/replace/-/replace-0.3.0.tgz#60081721188658595ab6a794eb7fedcb4c8d39c7" 34 | dependencies: 35 | colors "0.5.x" 36 | minimatch "~0.2.9" 37 | nomnom "1.6.x" 38 | 39 | sigmund@~1.0.0: 40 | version "1.0.1" 41 | resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" 42 | 43 | underscore@~1.4.4: 44 | version "1.4.4" 45 | resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.4.4.tgz#61a6a32010622afa07963bf325203cf12239d604" 46 | -------------------------------------------------------------------------------- /integration-tests/runIntegrationTest.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs-extra" 2 | import { join, resolve } from "../src/path" 3 | import * as tmp from "tmp" 4 | import { spawnSafeSync } from "../src/spawnSafe" 5 | import { resolveRelativeFileDependencies } from "../src/resolveRelativeFileDependencies" 6 | import rimraf from "rimraf" 7 | 8 | export const patchPackageTarballPath = resolve( 9 | fs 10 | .readdirSync(".") 11 | .filter((nm) => nm.match(/^patch-package\.test\.\d+\.tgz$/))[0], 12 | ) 13 | 14 | export function runIntegrationTest({ 15 | projectName, 16 | shouldProduceSnapshots, 17 | }: { 18 | projectName: string 19 | shouldProduceSnapshots: boolean 20 | }) { 21 | describe(`Test ${projectName}:`, () => { 22 | const tmpDir = tmp.dirSync({ unsafeCleanup: true }) 23 | fs.copySync(join(__dirname, projectName), tmpDir.name, { 24 | recursive: true, 25 | }) 26 | 27 | // remove node_modules folder when running locally, to avoid leaking state from source dir 28 | rimraf.sync(join(tmpDir.name, "node_modules")) 29 | 30 | const packageJson = require(join(tmpDir.name, "package.json")) 31 | packageJson.dependencies = resolveRelativeFileDependencies( 32 | join(__dirname, projectName), 33 | packageJson.dependencies, 34 | ) 35 | 36 | fs.writeFileSync( 37 | join(tmpDir.name, "package.json"), 38 | JSON.stringify(packageJson), 39 | ) 40 | 41 | const result = spawnSafeSync( 42 | `./${projectName}.sh`, 43 | [patchPackageTarballPath], 44 | { 45 | cwd: tmpDir.name, 46 | throwOnError: false, 47 | env: { 48 | ...process.env, 49 | PATCH_PACKAGE_INTEGRATION_TEST: "1", 50 | }, 51 | shell: true, 52 | }, 53 | ) 54 | 55 | it("should exit with 0 status", () => { 56 | expect(result.status).toBe(0) 57 | }) 58 | 59 | const output = result.stdout.toString() + "\n" + result.stderr.toString() 60 | 61 | if (result.status !== 0) { 62 | console.log(output) 63 | } 64 | 65 | it("should produce output", () => { 66 | expect(output.trim()).toBeTruthy() 67 | }) 68 | 69 | const snapshots = output.match(/SNAPSHOT: ?([\s\S]*?)END SNAPSHOT/g) 70 | 71 | if (shouldProduceSnapshots) { 72 | it("should produce some snapshots", () => { 73 | expect(snapshots && snapshots.length).toBeTruthy() 74 | }) 75 | if (snapshots) { 76 | snapshots.forEach((snapshot, i) => { 77 | const snapshotDescriptionMatch = snapshot.match(/SNAPSHOT: (.*)/) 78 | if (snapshotDescriptionMatch) { 79 | it( 80 | `${i.toString().padStart(2, "0")}: ` + 81 | snapshotDescriptionMatch[1], 82 | () => { 83 | expect(snapshot).toMatchSnapshot() 84 | }, 85 | ) 86 | } else { 87 | throw new Error("bad snapshot format") 88 | } 89 | }) 90 | } 91 | } else { 92 | it("should not produce any snapshots", () => { 93 | expect(snapshots && snapshots.length).toBeFalsy() 94 | }) 95 | } 96 | }) 97 | } 98 | -------------------------------------------------------------------------------- /integration-tests/scoped-package/__snapshots__/scoped-package.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test scoped-package: 00: left-pad typings should contain patch-package 1`] = ` 4 | "SNAPSHOT: left-pad typings should contain patch-package 5 | // Definitions by: Zlatko patch-package 6 | END SNAPSHOT" 7 | `; 8 | 9 | exports[`Test scoped-package: 01: add.d.ts should contain patch-package 1`] = ` 10 | "SNAPSHOT: add.d.ts should contain patch-package 11 | import { patch-package } from \\"./index\\"; 12 | export = patch-package; 13 | END SNAPSHOT" 14 | `; 15 | -------------------------------------------------------------------------------- /integration-tests/scoped-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scoped-package", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "prepare": "patch-package" 8 | }, 9 | "dependencies": { 10 | "@types/left-pad": "1.1.1", 11 | "@types/lodash": "4.14.72", 12 | "replace": "^1.0.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /integration-tests/scoped-package/patches/@types/left-pad+1.1.1.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/@types/left-pad/index.d.ts b/node_modules/@types/left-pad/index.d.ts 2 | index b6cb310..bf077e7 100644 3 | --- a/node_modules/@types/left-pad/index.d.ts 4 | +++ b/node_modules/@types/left-pad/index.d.ts 5 | @@ -1,6 +1,6 @@ 6 | // Type definitions for left-pad 1.1 7 | // Project: https://github.com/stevemao/left-pad 8 | -// Definitions by: Zlatko Andonovski 9 | +// Definitions by: Zlatko patch-package 10 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 11 | 12 | declare function leftPad(str: string|number, len: number, ch?: string|number): string; 13 | -------------------------------------------------------------------------------- /integration-tests/scoped-package/scoped-package.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "SNAPSHOT: left-pad typings should contain patch-package" 9 | grep patch-package node_modules/@types/left-pad/index.d.ts 10 | echo "END SNAPSHOT" 11 | 12 | echo "modify add.d.t.s" 13 | npx replace add patch-package node_modules/@types/lodash/add.d.ts 14 | 15 | echo "patch-package can make patches for scoped packages" 16 | patch-package @types/lodash 17 | 18 | echo "remove node_modules" 19 | npx rimraf node_modules 20 | 21 | echo "reinstall node_modules" 22 | yarn 23 | 24 | echo "SNAPSHOT: add.d.ts should contain patch-package" 25 | grep patch-package node_modules/@types/lodash/add.d.ts 26 | echo "END SNAPSHOT" -------------------------------------------------------------------------------- /integration-tests/scoped-package/scoped-package.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "scoped-package", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/scoped-package/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@types/left-pad@1.1.1": 6 | version "1.1.1" 7 | resolved "https://registry.yarnpkg.com/@types/left-pad/-/left-pad-1.1.1.tgz#29ab68a1a10e849140c9ba3e71a412534dfa0c7b" 8 | 9 | "@types/lodash@4.14.72": 10 | version "4.14.72" 11 | resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.72.tgz#f090cf6eb1fee1647a0efa1ebe18b0b78ed551c6" 12 | 13 | ansi-styles@~1.0.0: 14 | version "1.0.0" 15 | resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.0.0.tgz#cb102df1c56f5123eab8b67cd7b98027a0279178" 16 | 17 | balanced-match@^1.0.0: 18 | version "1.0.0" 19 | resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" 20 | 21 | brace-expansion@^1.1.7: 22 | version "1.1.11" 23 | resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" 24 | dependencies: 25 | balanced-match "^1.0.0" 26 | concat-map "0.0.1" 27 | 28 | chalk@~0.4.0: 29 | version "0.4.0" 30 | resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f" 31 | dependencies: 32 | ansi-styles "~1.0.0" 33 | has-color "~0.1.0" 34 | strip-ansi "~0.1.0" 35 | 36 | colors@1.2.4: 37 | version "1.2.4" 38 | resolved "https://registry.yarnpkg.com/colors/-/colors-1.2.4.tgz#e0cb41d3e4b20806b3bfc27f4559f01b94bc2f7c" 39 | 40 | concat-map@0.0.1: 41 | version "0.0.1" 42 | resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" 43 | 44 | has-color@~0.1.0: 45 | version "0.1.7" 46 | resolved "https://registry.yarnpkg.com/has-color/-/has-color-0.1.7.tgz#67144a5260c34fc3cca677d041daf52fe7b78b2f" 47 | 48 | minimatch@3.0.4: 49 | version "3.0.4" 50 | resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" 51 | dependencies: 52 | brace-expansion "^1.1.7" 53 | 54 | nomnom@1.8.1: 55 | version "1.8.1" 56 | resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.8.1.tgz#2151f722472ba79e50a76fc125bb8c8f2e4dc2a7" 57 | dependencies: 58 | chalk "~0.4.0" 59 | underscore "~1.6.0" 60 | 61 | replace@^1.0.0: 62 | version "1.0.0" 63 | resolved "https://registry.yarnpkg.com/replace/-/replace-1.0.0.tgz#da5235cc6d64d5c3a74e4ef73b487aad0f79a74b" 64 | dependencies: 65 | colors "1.2.4" 66 | minimatch "3.0.4" 67 | nomnom "1.8.1" 68 | 69 | strip-ansi@~0.1.0: 70 | version "0.1.1" 71 | resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.1.1.tgz#39e8a98d044d150660abe4a6808acf70bb7bc991" 72 | 73 | underscore@~1.6.0: 74 | version "1.6.0" 75 | resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8" 76 | -------------------------------------------------------------------------------- /integration-tests/shrinkwrap/__snapshots__/shrinkwrap.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test shrinkwrap: 00: left pad should contain patch-package 1`] = ` 4 | "SNAPSHOT: left pad should contain patch-package 5 | module.exports = patch-package; 6 | END SNAPSHOT" 7 | `; 8 | -------------------------------------------------------------------------------- /integration-tests/shrinkwrap/npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shrinkwrap", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "balanced-match": { 8 | "version": "1.0.0", 9 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 10 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" 11 | }, 12 | "brace-expansion": { 13 | "version": "1.1.11", 14 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", 15 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", 16 | "requires": { 17 | "balanced-match": "1.0.0", 18 | "concat-map": "0.0.1" 19 | } 20 | }, 21 | "concat-map": { 22 | "version": "0.0.1", 23 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 24 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" 25 | }, 26 | "fs.realpath": { 27 | "version": "1.0.0", 28 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 29 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" 30 | }, 31 | "glob": { 32 | "version": "7.1.2", 33 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", 34 | "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", 35 | "requires": { 36 | "fs.realpath": "1.0.0", 37 | "inflight": "1.0.6", 38 | "inherits": "2.0.3", 39 | "minimatch": "3.0.4", 40 | "once": "1.4.0", 41 | "path-is-absolute": "1.0.1" 42 | } 43 | }, 44 | "inflight": { 45 | "version": "1.0.6", 46 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 47 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 48 | "requires": { 49 | "once": "1.4.0", 50 | "wrappy": "1.0.2" 51 | } 52 | }, 53 | "inherits": { 54 | "version": "2.0.3", 55 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 56 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 57 | }, 58 | "left-pad": { 59 | "version": "1.1.3", 60 | "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.1.3.tgz", 61 | "integrity": "sha1-YS9hwDPzqeCOk58crr7qQbbzGZo=" 62 | }, 63 | "minimatch": { 64 | "version": "3.0.4", 65 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 66 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 67 | "requires": { 68 | "brace-expansion": "1.1.11" 69 | } 70 | }, 71 | "once": { 72 | "version": "1.4.0", 73 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 74 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 75 | "requires": { 76 | "wrappy": "1.0.2" 77 | } 78 | }, 79 | "path-is-absolute": { 80 | "version": "1.0.1", 81 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 82 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" 83 | }, 84 | "rimraf": { 85 | "version": "2.6.2", 86 | "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", 87 | "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", 88 | "requires": { 89 | "glob": "7.1.2" 90 | } 91 | }, 92 | "wrappy": { 93 | "version": "1.0.2", 94 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 95 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /integration-tests/shrinkwrap/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shrinkwrap", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "prepare": "patch-package" 7 | }, 8 | "author": "", 9 | "license": "ISC", 10 | "dependencies": { 11 | "left-pad": "^1.1.3", 12 | "rimraf": "^2.6.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /integration-tests/shrinkwrap/patches/left-pad+1.1.3.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js 2 | index 26f73ff..60f3f56 100644 3 | --- a/node_modules/left-pad/index.js 4 | +++ b/node_modules/left-pad/index.js 5 | @@ -4,7 +4,7 @@ 6 | * To Public License, Version 2, as published by Sam Hocevar. See 7 | * http://www.wtfpl.net/ for more details. */ 8 | 'use strict'; 9 | -module.exports = leftPad; 10 | +module.exports = patch-package; 11 | 12 | var cache = [ 13 | '', 14 | -------------------------------------------------------------------------------- /integration-tests/shrinkwrap/shrinkwrap.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | npm i $1 6 | 7 | npx rimraf node_modules 8 | 9 | npm i 10 | 11 | echo "SNAPSHOT: left pad should contain patch-package" 12 | grep patch-package node_modules/left-pad/index.js 13 | echo "END SNAPSHOT" 14 | -------------------------------------------------------------------------------- /integration-tests/shrinkwrap/shrinkwrap.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ projectName: "shrinkwrap", shouldProduceSnapshots: true }) 3 | -------------------------------------------------------------------------------- /integration-tests/unexpected-patch-creation-failure/__snapshots__/unexpected-patch-creation-failure.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Test unexpected-patch-creation-failure: 00: patch-package fails to parse a patch it created 1`] = ` 4 | "SNAPSHOT: patch-package fails to parse a patch it created 5 | patch-package 0.0.0 6 | • Creating temporary folder 7 | • Installing left-pad@1.3.0 with yarn 8 | • Diffing your files with clean files 9 | 10 | ⛔️ ERROR 11 | 12 | patch-package was unable to read the patch-file made by git. This should not 13 | happen. 14 | 15 | A diagnostic file was written to 16 | 17 | ./patch-package-error.json.gz 18 | 19 | Please attach it to a github issue 20 | 21 | https://github.com/ds300/patch-package/issues/new?title=New+patch+parse+failed&body=Please+attach+the+diagnostic+file+by+dragging+it+into+here+🙏 22 | 23 | Note that this diagnostic file will contain code from the package you were 24 | attempting to patch. 25 | 26 | 27 | END SNAPSHOT" 28 | `; 29 | -------------------------------------------------------------------------------- /integration-tests/unexpected-patch-creation-failure/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unexpected-patch-creation-failure", 3 | "version": "1.0.0", 4 | "description": "integration test for patch-package", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "left-pad": "1.3.0", 10 | "replace": "^1.1.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration-tests/unexpected-patch-creation-failure/unexpected-patch-creation-failure.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "add patch-package" 5 | yarn add $1 6 | alias patch-package=./node_modules/.bin/patch-package 7 | 8 | echo "modify left-pad" 9 | npx replace leftPad patchPackage node_modules/left-pad/index.js 10 | 11 | echo "force patch-package to fail" 12 | npx replace 'parsePatchFile\(' 'blarseBlatchBlile(' node_modules/patch-package/dist/makePatch.js 13 | 14 | echo "there is no error log file" 15 | if ls ./patch-package-error.json.gz 16 | then 17 | exit 1 18 | fi 19 | 20 | echo "SNAPSHOT: patch-package fails to parse a patch it created" 21 | if patch-package left-pad 22 | then 23 | exit 1 24 | fi 25 | echo "END SNAPSHOT" 26 | 27 | echo "there is now an error log file" 28 | ls ./patch-package-error.json.gz 29 | 30 | echo "and it can be unzipped" 31 | gzip -d ./patch-package-error.json.gz 32 | 33 | echo "the json file is valid json" 34 | node -e 'JSON.parse(fs.readFileSync("./patch-package-error.json").toString())' -------------------------------------------------------------------------------- /integration-tests/unexpected-patch-creation-failure/unexpected-patch-creation-failure.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "unexpected-patch-creation-failure", 4 | shouldProduceSnapshots: true, 5 | }) 6 | -------------------------------------------------------------------------------- /integration-tests/yarn-workspaces/add-postinstall-commands.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs") 2 | 3 | function addPostinstall(packageJsonPath) { 4 | const json = JSON.parse(fs.readFileSync(packageJsonPath)) 5 | fs.writeFileSync( 6 | packageJsonPath, 7 | JSON.stringify( 8 | { 9 | ...json, 10 | scripts: { 11 | ...json.scripts, 12 | postinstall: "yarn patch-package", 13 | }, 14 | }, 15 | null, 16 | " ", 17 | ), 18 | ) 19 | } 20 | 21 | Array.prototype.slice 22 | .call(process.argv, 2) 23 | .filter(x => !x.match(/node_modules/)) 24 | .map(addPostinstall) 25 | -------------------------------------------------------------------------------- /integration-tests/yarn-workspaces/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yarn-workspaces", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "integration test for patch-package", 6 | "main": "index.js", 7 | "author": "", 8 | "license": "ISC", 9 | "workspaces": { 10 | "packages": [ 11 | "packages/*" 12 | ] 13 | }, 14 | "dependencies": { 15 | "left-pad": "1.2.0", 16 | "postinstall-postinstall": "^2.0.0", 17 | "replace": "^1.1.0", 18 | "rimraf": "^2.6.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /integration-tests/yarn-workspaces/packages/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "patch-package": "../../node_modules/.bin/patch-package" 8 | }, 9 | "dependencies": { 10 | "left-pad": "1.3.0", 11 | "postinstall-postinstall": "^2.0.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /integration-tests/yarn-workspaces/packages/b/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "b", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "patch-package": "../../node_modules/.bin/patch-package" 8 | }, 9 | "dependencies": { 10 | "left-pad": "1.2.0", 11 | "postinstall-postinstall": "^2.0.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /integration-tests/yarn-workspaces/yarn-workspaces.sh: -------------------------------------------------------------------------------- 1 | # make sure errors stop the script 2 | set -e 3 | 4 | echo "tarball $1" 5 | echo "add patch-package to root" 6 | yarn add $1 --ignore-workspace-root-check 7 | 8 | echo "set up postinstall scripts" 9 | node ./add-postinstall-commands.js package.json packages/a/package.json packages/b/package.json 10 | 11 | echo "modify hoisted left-pad" 12 | npx replace leftPad patch-package node_modules/left-pad/index.js 13 | 14 | echo "create patch file" 15 | yarn patch-package left-pad 16 | 17 | echo "modify unhoisted left-pad" 18 | npx replace leftPad patch-package packages/a/node_modules/left-pad/index.js 19 | 20 | echo "create patch file" 21 | cd packages/a 22 | yarn patch-package left-pad 23 | 24 | echo "go back to root" 25 | cd ../../ 26 | 27 | echo "delete all node modules" 28 | rimraf **/node_modules 29 | 30 | echo "execute yarn from root" 31 | yarn 32 | 33 | echo "hoisted left-pad was patched" 34 | grep patch-package node_modules/left-pad/index.js 35 | 36 | echo "unhoisted left-pad was patched" 37 | grep patch-package packages/a/node_modules/left-pad/index.js 38 | 39 | echo "delete all node modules" 40 | rimraf **/node_modules 41 | 42 | echo "execute yarn from a" 43 | cd packages/a 44 | yarn 45 | cd ../../ 46 | 47 | echo "hoisted left-pad was patched" 48 | grep patch-package node_modules/left-pad/index.js 49 | 50 | echo "unhoisted left-pad was patched" 51 | grep patch-package packages/a/node_modules/left-pad/index.js 52 | -------------------------------------------------------------------------------- /integration-tests/yarn-workspaces/yarn-workspaces.test.ts: -------------------------------------------------------------------------------- 1 | import { runIntegrationTest } from "../runIntegrationTest" 2 | runIntegrationTest({ 3 | projectName: "yarn-workspaces", 4 | shouldProduceSnapshots: false, 5 | }) 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "patch-package", 3 | "version": "8.0.0", 4 | "description": "Fix broken node modules with no fuss", 5 | "main": "dist/index.js", 6 | "repository": "github:ds300/patch-package", 7 | "author": "David Sheldrick", 8 | "license": "MIT", 9 | "engines": { 10 | "node": ">=14", 11 | "npm": ">5" 12 | }, 13 | "bin": "./index.js", 14 | "scripts": { 15 | "prepublishOnly": "yarn run clean && yarn run build", 16 | "build": "tsc --project tsconfig.build.json", 17 | "new-integration-test": "ts-node integration-tests/newIntegrationTest.ts", 18 | "clean": "rimraf dist patch-package.test*.tgz", 19 | "format": "prettier --no-semi --write --trailing-comma=all src{/**,}/*.ts integration-tests{/**,}/*.ts property-based-tests{/**,}/*.ts", 20 | "prepack": "rimraf dist/**/*.test.js", 21 | "test": "./run-tests.sh --runInBand" 22 | }, 23 | "husky": { 24 | "hooks": { 25 | "pre-commit": "tsc --noEmit && lint-staged" 26 | } 27 | }, 28 | "lint-staged": { 29 | "*.ts": [ 30 | "tslint -c tslint.json -p tsconfig.json", 31 | "prettier --no-semi --trailing-comma=all --list-different" 32 | ] 33 | }, 34 | "jest": { 35 | "globals": { 36 | "ts-jest": { 37 | "diagnostics": false 38 | } 39 | }, 40 | "transform": { 41 | ".(ts|tsx)": "ts-jest" 42 | }, 43 | "testRegex": "/(src|integration-tests|property-based-tests)/.+\\.test\\.ts$", 44 | "moduleFileExtensions": [ 45 | "ts", 46 | "tsx", 47 | "js" 48 | ] 49 | }, 50 | "devDependencies": { 51 | "@types/app-root-path": "^1.2.4", 52 | "@types/cross-spawn": "^6.0.0", 53 | "@types/fs-extra": "^9.0.0", 54 | "@types/jest": "^24.0.11", 55 | "@types/json-stable-stringify": "^1.0.34", 56 | "@types/minimist": "^1.2.2", 57 | "@types/node": "^12.0.0", 58 | "@types/rimraf": "^2.0.2", 59 | "@types/semver": "^7.5.0", 60 | "@types/tmp": "^0.0.34", 61 | "husky": "^1.3.1", 62 | "jest": "^24.5.0", 63 | "lint-staged": "^8.1.5", 64 | "np": "^7.4.0", 65 | "prettier": "^2.2.1", 66 | "randomstring": "^1.1.5", 67 | "rimraf": "^2.6.3", 68 | "ts-jest": "^24.0.0", 69 | "ts-node": "8.0.3", 70 | "tslint": "^5.14.0", 71 | "typescript": "^4.2.2" 72 | }, 73 | "dependencies": { 74 | "@yarnpkg/lockfile": "^1.1.0", 75 | "chalk": "^4.1.2", 76 | "ci-info": "^3.7.0", 77 | "cross-spawn": "^7.0.3", 78 | "find-yarn-workspace-root": "^2.0.0", 79 | "fs-extra": "^10.0.0", 80 | "json-stable-stringify": "^1.0.2", 81 | "klaw-sync": "^6.0.0", 82 | "minimist": "^1.2.6", 83 | "open": "^7.4.2", 84 | "semver": "^7.5.3", 85 | "slash": "^2.0.0", 86 | "tmp": "^0.0.33", 87 | "yaml": "^2.2.2" 88 | }, 89 | "files": [ 90 | "index.js", 91 | "dist/**/*.js", 92 | "CHANGELOG.md", 93 | "LICENSE", 94 | "patch-package-banner.png", 95 | "README.md" 96 | ], 97 | "packageManager": "yarn@1.22.19" 98 | } 99 | -------------------------------------------------------------------------------- /property-based-tests/generativeTests.test.ts: -------------------------------------------------------------------------------- 1 | import { generateTestCase } from "./testCases" 2 | import { executeTestCase } from "./executeTestCase" 3 | 4 | describe("property based tests", () => { 5 | for (let i = 0; i < 200; i++) { 6 | describe(`${i}`, () => { 7 | executeTestCase(generateTestCase()) 8 | }) 9 | } 10 | }) 11 | -------------------------------------------------------------------------------- /run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | export CI=true 5 | 6 | yarn clean 7 | yarn build 8 | version=$(node -e 'console.log(require("./package.json").version)') 9 | yarn version --new-version 0.0.0 --no-git-tag-version --no-commit-hooks 10 | yarn pack --filename patch-package.test.$(date +%s).tgz 11 | yarn version --new-version $version --no-git-tag-version --no-commit-hooks 12 | yarn jest "$@" 13 | -------------------------------------------------------------------------------- /src/assertNever.ts: -------------------------------------------------------------------------------- 1 | export function assertNever(x: never): never { 2 | throw new Error("Unexpected object: " + x) 3 | } 4 | -------------------------------------------------------------------------------- /src/coerceSemVer.ts: -------------------------------------------------------------------------------- 1 | import semver from "semver" 2 | 3 | export function coerceSemVer(version: string): string | null { 4 | return semver.coerce(version)?.version || null 5 | } 6 | -------------------------------------------------------------------------------- /src/createIssue.test.ts: -------------------------------------------------------------------------------- 1 | import { shouldRecommendIssue } from "./createIssue" 2 | 3 | describe(shouldRecommendIssue, () => { 4 | it("Allows most repos", () => { 5 | const eigen = shouldRecommendIssue({ 6 | org: "artsy", 7 | repo: "eigen", 8 | provider: "GitHub", 9 | }) 10 | expect(eigen).toBeTruthy() 11 | 12 | const typescript = shouldRecommendIssue({ 13 | org: "Microsoft", 14 | repo: "TypeScript", 15 | provider: "GitHub", 16 | }) 17 | expect(typescript).toBeTruthy() 18 | }) 19 | 20 | it("does not recommend DefinitelyTyped", () => { 21 | const typescript = shouldRecommendIssue({ 22 | org: "DefinitelyTyped", 23 | repo: "DefinitelyTyped", 24 | provider: "GitHub", 25 | }) 26 | expect(typescript).toBeFalsy() 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /src/detectPackageManager.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs-extra" 2 | import { join } from "./path" 3 | import chalk from "chalk" 4 | import process from "process" 5 | import findWorkspaceRoot from "find-yarn-workspace-root" 6 | 7 | export type PackageManager = "yarn" | "npm" | "npm-shrinkwrap" 8 | 9 | function printNoYarnLockfileError() { 10 | console.log(` 11 | ${chalk.red.bold("**ERROR**")} ${chalk.red( 12 | `The --use-yarn option was specified but there is no yarn.lock file`, 13 | )} 14 | `) 15 | } 16 | 17 | function printNoLockfilesError() { 18 | console.log(` 19 | ${chalk.red.bold("**ERROR**")} ${chalk.red( 20 | `No package-lock.json, npm-shrinkwrap.json, or yarn.lock file. 21 | 22 | You must use either npm@>=5, yarn, or npm-shrinkwrap to manage this project's 23 | dependencies.`, 24 | )} 25 | `) 26 | } 27 | 28 | function printSelectingDefaultMessage() { 29 | console.info( 30 | `${chalk.bold( 31 | "patch-package", 32 | )}: you have both yarn.lock and package-lock.json 33 | Defaulting to using ${chalk.bold("npm")} 34 | You can override this setting by passing --use-yarn or deleting 35 | package-lock.json if you don't need it 36 | `, 37 | ) 38 | } 39 | 40 | export const detectPackageManager = ( 41 | appRootPath: string, 42 | overridePackageManager: PackageManager | null, 43 | ): PackageManager => { 44 | const packageLockExists = fs.existsSync( 45 | join(appRootPath, "package-lock.json"), 46 | ) 47 | const shrinkWrapExists = fs.existsSync( 48 | join(appRootPath, "npm-shrinkwrap.json"), 49 | ) 50 | const yarnLockExists = fs.existsSync(join(appRootPath, "yarn.lock")) 51 | if ((packageLockExists || shrinkWrapExists) && yarnLockExists) { 52 | if (overridePackageManager) { 53 | return overridePackageManager 54 | } else { 55 | printSelectingDefaultMessage() 56 | return shrinkWrapExists ? "npm-shrinkwrap" : "npm" 57 | } 58 | } else if (packageLockExists || shrinkWrapExists) { 59 | if (overridePackageManager === "yarn") { 60 | printNoYarnLockfileError() 61 | process.exit(1) 62 | } else { 63 | return shrinkWrapExists ? "npm-shrinkwrap" : "npm" 64 | } 65 | } else if (yarnLockExists || findWorkspaceRoot()) { 66 | return "yarn" 67 | } else { 68 | printNoLockfilesError() 69 | process.exit(1) 70 | } 71 | throw Error() 72 | } 73 | -------------------------------------------------------------------------------- /src/filterFiles.ts: -------------------------------------------------------------------------------- 1 | import { join } from "./path" 2 | import { removeSync } from "fs-extra" 3 | import klawSync from "klaw-sync" 4 | 5 | export function removeIgnoredFiles( 6 | dir: string, 7 | includePaths: RegExp, 8 | excludePaths: RegExp, 9 | ) { 10 | klawSync(dir, { nodir: true }) 11 | .map((item) => item.path.slice(`${dir}/`.length)) 12 | .filter( 13 | (relativePath) => 14 | !relativePath.match(includePaths) || relativePath.match(excludePaths), 15 | ) 16 | .forEach((relativePath) => removeSync(join(dir, relativePath))) 17 | } 18 | -------------------------------------------------------------------------------- /src/getAppRootPath.ts: -------------------------------------------------------------------------------- 1 | import { join, resolve } from "./path" 2 | import process from "process" 3 | import { existsSync } from "fs-extra" 4 | 5 | export const getAppRootPath = (): string => { 6 | let cwd = process.cwd() 7 | while (!existsSync(join(cwd, "package.json"))) { 8 | const up = resolve(cwd, "../") 9 | if (up === cwd) { 10 | throw new Error("no package.json found for this project") 11 | } 12 | cwd = up 13 | } 14 | return cwd 15 | } 16 | -------------------------------------------------------------------------------- /src/getPackageVersion.test.ts: -------------------------------------------------------------------------------- 1 | import { getPackageVersion } from "./getPackageVersion" 2 | 3 | describe("getPackageVersion", () => { 4 | beforeEach(() => { 5 | jest.resetModules() 6 | }) 7 | 8 | const packagePath = "../package.json" 9 | 10 | it("should return version without change when already valid", () => { 11 | const packageJSON = { 12 | version: "1.2.3", 13 | } 14 | jest.mock(packagePath, () => { 15 | return packageJSON 16 | }) 17 | 18 | const expected = "1.2.3" 19 | 20 | expect(getPackageVersion(packagePath)).toEqual(expected) 21 | }) 22 | 23 | it("should return version with prefix", () => { 24 | const packageJSON = { 25 | version: "v1.2.3", 26 | } 27 | jest.mock(packagePath, () => { 28 | return packageJSON 29 | }) 30 | 31 | const expected = "v1.2.3" 32 | 33 | expect(getPackageVersion(packagePath)).toEqual(expected) 34 | }) 35 | 36 | it("should return invalid version without change", () => { 37 | const packageJSON = { 38 | version: "a.b.c", 39 | } 40 | jest.mock(packagePath, () => { 41 | return packageJSON 42 | }) 43 | 44 | const expected = "a.b.c" 45 | 46 | expect(getPackageVersion(packagePath)).toEqual(expected) 47 | }) 48 | 49 | it("should return invalid version without build metadata", () => { 50 | const packageJSON = { 51 | version: "a.b.c+asd1234", 52 | } 53 | jest.mock(packagePath, () => { 54 | return packageJSON 55 | }) 56 | 57 | const expected = "a.b.c" 58 | 59 | expect(getPackageVersion(packagePath)).toEqual(expected) 60 | }) 61 | 62 | it("should return version without build metadata", () => { 63 | const packageJSON = { 64 | version: "1.2.3+asd1234", 65 | } 66 | jest.mock(packagePath, () => { 67 | return packageJSON 68 | }) 69 | 70 | const expected = "1.2.3" 71 | 72 | expect(getPackageVersion(packagePath)).toEqual(expected) 73 | }) 74 | 75 | it("should return version with prefix but without build metadata", () => { 76 | const packageJSON = { 77 | version: "v1.2.3+asd1234", 78 | } 79 | jest.mock(packagePath, () => { 80 | return packageJSON 81 | }) 82 | 83 | const expected = "v1.2.3" 84 | 85 | expect(getPackageVersion(packagePath)).toEqual(expected) 86 | }) 87 | }) 88 | -------------------------------------------------------------------------------- /src/getPackageVersion.ts: -------------------------------------------------------------------------------- 1 | export function getPackageVersion(packageJsonPath: string): string { 2 | // remove build metadata 3 | return require(packageJsonPath).version.replace(/\+.*$/, "") 4 | } 5 | -------------------------------------------------------------------------------- /src/hash.ts: -------------------------------------------------------------------------------- 1 | import { createHash } from "crypto" 2 | import { openSync, readSync, closeSync, statSync } from "fs" 3 | 4 | const bufferSize = 1024 5 | 6 | const buffer = Buffer.alloc(bufferSize) 7 | 8 | export function hashFile(filePath: string) { 9 | const sha = createHash("sha256") 10 | const fileDescriptor = openSync(filePath, "r") 11 | const size = statSync(filePath).size 12 | let totalBytesRead = 0 13 | while (totalBytesRead < size) { 14 | const bytesRead = readSync( 15 | fileDescriptor, 16 | buffer, 17 | 0, 18 | Math.min(size - totalBytesRead, bufferSize), 19 | totalBytesRead, 20 | ) 21 | if (bytesRead < bufferSize) { 22 | sha.update(buffer.slice(0, bytesRead)) 23 | } else { 24 | sha.update(buffer) 25 | } 26 | totalBytesRead += bytesRead 27 | } 28 | closeSync(fileDescriptor) 29 | return sha.digest("hex") 30 | } 31 | -------------------------------------------------------------------------------- /src/makeRegExp.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk" 2 | 3 | export const makeRegExp = ( 4 | reString: string, 5 | name: string, 6 | defaultValue: RegExp, 7 | caseSensitive: boolean, 8 | ): RegExp => { 9 | if (!reString) { 10 | return defaultValue 11 | } else { 12 | try { 13 | return new RegExp(reString, caseSensitive ? "" : "i") 14 | } catch (_) { 15 | console.log(`${chalk.red.bold("***ERROR***")} 16 | Invalid format for option --${name} 17 | 18 | Unable to convert the string ${JSON.stringify( 19 | reString, 20 | )} to a regular expression. 21 | `) 22 | 23 | process.exit(1) 24 | return /unreachable/ 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/packageIsDevDependency.test.ts: -------------------------------------------------------------------------------- 1 | import { packageIsDevDependency } from "./packageIsDevDependency" 2 | import { join } from "./path" 3 | import { normalize } from "path" 4 | import { getPackageDetailsFromPatchFilename } from "./PackageDetails" 5 | import { existsSync } from "fs" 6 | 7 | const appPath = normalize(join(__dirname, "../")) 8 | 9 | describe(packageIsDevDependency, () => { 10 | it("returns true if package is a dev dependency", () => { 11 | expect( 12 | packageIsDevDependency({ 13 | appPath, 14 | patchDetails: getPackageDetailsFromPatchFilename( 15 | "typescript+3.0.1.patch", 16 | )!, 17 | }), 18 | ).toBe(true) 19 | }) 20 | it("returns false if package is not a dev dependency", () => { 21 | expect( 22 | packageIsDevDependency({ 23 | appPath, 24 | patchDetails: getPackageDetailsFromPatchFilename("chalk+3.0.1.patch")!, 25 | }), 26 | ).toBe(false) 27 | }) 28 | it("returns false if package is a transitive dependency of a dev dependency", () => { 29 | expect(existsSync(join(appPath, "node_modules/cosmiconfig"))).toBe(true) 30 | expect( 31 | packageIsDevDependency({ 32 | appPath, 33 | patchDetails: getPackageDetailsFromPatchFilename( 34 | // cosmiconfig is a transitive dep of lint-staged 35 | "cosmiconfig+3.0.1.patch", 36 | )!, 37 | }), 38 | ).toBe(false) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /src/packageIsDevDependency.ts: -------------------------------------------------------------------------------- 1 | import { PatchedPackageDetails } from "./PackageDetails" 2 | import { join } from "./path" 3 | import { existsSync } from "fs" 4 | 5 | export function packageIsDevDependency({ 6 | appPath, 7 | patchDetails, 8 | }: { 9 | appPath: string 10 | patchDetails: PatchedPackageDetails 11 | }) { 12 | const packageJsonPath = join(appPath, "package.json") 13 | if (!existsSync(packageJsonPath)) { 14 | return false 15 | } 16 | const { devDependencies } = require(packageJsonPath) 17 | return Boolean( 18 | devDependencies && devDependencies[patchDetails.packageNames[0]], 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /src/patch/read.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk" 2 | import { readFileSync } from "fs-extra" 3 | import { relative, resolve } from "../path" 4 | import { normalize } from "path" 5 | import { PackageDetails } from "../PackageDetails" 6 | import { parsePatchFile, PatchFilePart } from "./parse" 7 | 8 | export function readPatch({ 9 | patchFilePath, 10 | patchDetails, 11 | patchDir, 12 | }: { 13 | patchFilePath: string 14 | patchDetails: PackageDetails 15 | patchDir: string 16 | }): PatchFilePart[] { 17 | try { 18 | return parsePatchFile(readFileSync(patchFilePath).toString()) 19 | } catch (e) { 20 | const fixupSteps: string[] = [] 21 | const relativePatchFilePath = normalize( 22 | relative(process.cwd(), patchFilePath), 23 | ) 24 | const patchBaseDir = relativePatchFilePath.slice( 25 | 0, 26 | relativePatchFilePath.indexOf(patchDir), 27 | ) 28 | if (patchBaseDir) { 29 | fixupSteps.push(`cd ${patchBaseDir}`) 30 | } 31 | fixupSteps.push( 32 | `patch -p1 -i ${relativePatchFilePath.slice( 33 | relativePatchFilePath.indexOf(patchDir), 34 | )}`, 35 | ) 36 | fixupSteps.push(`npx patch-package ${patchDetails.pathSpecifier}`) 37 | if (patchBaseDir) { 38 | fixupSteps.push( 39 | `cd ${relative(resolve(process.cwd(), patchBaseDir), process.cwd())}`, 40 | ) 41 | } 42 | 43 | console.log(` 44 | ${chalk.red.bold("**ERROR**")} ${chalk.red( 45 | `Failed to apply patch for package ${chalk.bold( 46 | patchDetails.humanReadablePathSpecifier, 47 | )}`, 48 | )} 49 | 50 | This happened because the patch file ${relativePatchFilePath} could not be parsed. 51 | 52 | If you just upgraded patch-package, you can try running: 53 | 54 | ${fixupSteps.join("\n ")} 55 | 56 | Otherwise, try manually creating the patch file again. 57 | 58 | If the problem persists, please submit a bug report: 59 | 60 | https://github.com/ds300/patch-package/issues/new?title=Patch+file+parse+error&body=%3CPlease+attach+the+patch+file+in+question%3E 61 | 62 | `) 63 | process.exit(1) 64 | } 65 | return [] 66 | } 67 | -------------------------------------------------------------------------------- /src/patch/reverse.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ParsedPatchFile, 3 | PatchFilePart, 4 | Hunk, 5 | HunkHeader, 6 | verifyHunkIntegrity, 7 | } from "./parse" 8 | import { assertNever } from "../assertNever" 9 | 10 | function reverseHunk(hunk: Hunk): Hunk { 11 | const header: HunkHeader = { 12 | original: hunk.header.patched, 13 | patched: hunk.header.original, 14 | } 15 | const parts: Hunk["parts"] = [] 16 | 17 | for (const part of hunk.parts) { 18 | switch (part.type) { 19 | case "context": 20 | parts.push(part) 21 | break 22 | case "deletion": 23 | parts.push({ 24 | type: "insertion", 25 | lines: part.lines, 26 | noNewlineAtEndOfFile: part.noNewlineAtEndOfFile, 27 | }) 28 | break 29 | case "insertion": 30 | parts.push({ 31 | type: "deletion", 32 | lines: part.lines, 33 | noNewlineAtEndOfFile: part.noNewlineAtEndOfFile, 34 | }) 35 | break 36 | default: 37 | assertNever(part.type) 38 | } 39 | } 40 | 41 | // swap insertions and deletions over so deletions always come first 42 | for (let i = 0; i < parts.length - 1; i++) { 43 | if (parts[i].type === "insertion" && parts[i + 1].type === "deletion") { 44 | const tmp = parts[i] 45 | parts[i] = parts[i + 1] 46 | parts[i + 1] = tmp 47 | i += 1 48 | } 49 | } 50 | 51 | const result: Hunk = { 52 | header, 53 | parts, 54 | source: hunk.source, 55 | } 56 | 57 | verifyHunkIntegrity(result) 58 | 59 | return result 60 | } 61 | 62 | function reversePatchPart(part: PatchFilePart): PatchFilePart { 63 | switch (part.type) { 64 | case "file creation": 65 | return { 66 | type: "file deletion", 67 | path: part.path, 68 | hash: part.hash, 69 | hunk: part.hunk && reverseHunk(part.hunk), 70 | mode: part.mode, 71 | } 72 | case "file deletion": 73 | return { 74 | type: "file creation", 75 | path: part.path, 76 | hunk: part.hunk && reverseHunk(part.hunk), 77 | mode: part.mode, 78 | hash: part.hash, 79 | } 80 | case "rename": 81 | return { 82 | type: "rename", 83 | fromPath: part.toPath, 84 | toPath: part.fromPath, 85 | } 86 | case "patch": 87 | return { 88 | type: "patch", 89 | path: part.path, 90 | hunks: part.hunks.map(reverseHunk), 91 | beforeHash: part.afterHash, 92 | afterHash: part.beforeHash, 93 | } 94 | case "mode change": 95 | return { 96 | type: "mode change", 97 | path: part.path, 98 | newMode: part.oldMode, 99 | oldMode: part.newMode, 100 | } 101 | } 102 | } 103 | 104 | export const reversePatch = (patch: ParsedPatchFile): ParsedPatchFile => { 105 | return patch.map(reversePatchPart).reverse() 106 | } 107 | -------------------------------------------------------------------------------- /src/patchFs.ts: -------------------------------------------------------------------------------- 1 | import { 2 | PatchedPackageDetails, 3 | getPackageDetailsFromPatchFilename, 4 | } from "./PackageDetails" 5 | import { relative } from "./path" 6 | import klawSync from "klaw-sync" 7 | 8 | export const getPatchFiles = (patchesDir: string) => { 9 | try { 10 | return klawSync(patchesDir, { nodir: true }) 11 | .map(({ path }) => relative(patchesDir, path)) 12 | .filter((path) => path.endsWith(".patch")) 13 | } catch (e) { 14 | return [] 15 | } 16 | } 17 | 18 | interface GroupedPatches { 19 | numPatchFiles: number 20 | pathSpecifierToPatchFiles: Record 21 | warnings: string[] 22 | } 23 | export const getGroupedPatches = (patchesDirectory: string): GroupedPatches => { 24 | const files = getPatchFiles(patchesDirectory) 25 | 26 | if (files.length === 0) { 27 | return { 28 | numPatchFiles: 0, 29 | pathSpecifierToPatchFiles: {}, 30 | warnings: [], 31 | } 32 | } 33 | 34 | const warnings: string[] = [] 35 | 36 | const pathSpecifierToPatchFiles: Record = {} 37 | for (const file of files) { 38 | const details = getPackageDetailsFromPatchFilename(file) 39 | if (!details) { 40 | warnings.push(`Unrecognized patch file in patches directory ${file}`) 41 | continue 42 | } 43 | if (!pathSpecifierToPatchFiles[details.pathSpecifier]) { 44 | pathSpecifierToPatchFiles[details.pathSpecifier] = [] 45 | } 46 | pathSpecifierToPatchFiles[details.pathSpecifier].push(details) 47 | } 48 | for (const arr of Object.values(pathSpecifierToPatchFiles)) { 49 | arr.sort((a, b) => { 50 | return (a.sequenceNumber ?? 0) - (b.sequenceNumber ?? 0) 51 | }) 52 | } 53 | 54 | return { 55 | numPatchFiles: files.length, 56 | pathSpecifierToPatchFiles, 57 | warnings, 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/path.ts: -------------------------------------------------------------------------------- 1 | import slash from "slash" 2 | import path from "path" 3 | 4 | export const join: typeof path.join = (...args) => slash(path.join(...args)) 5 | 6 | export { dirname } from "path" 7 | 8 | export const resolve: typeof path.resolve = (...args) => 9 | slash(path.resolve(...args)) 10 | 11 | export const relative: typeof path.relative = (...args) => 12 | slash(path.relative(...args)) 13 | -------------------------------------------------------------------------------- /src/resolveRelativeFileDependencies.test.ts: -------------------------------------------------------------------------------- 1 | import { resolveRelativeFileDependencies } from "./resolveRelativeFileDependencies" 2 | 3 | describe("resolveRelativeFileDependencies", () => { 4 | it("works for package.json", () => { 5 | const appRootPath = "/foo/bar" 6 | 7 | const resolutions = { 8 | absolute: "file:/not-foo/bar", 9 | relative: "file:../baz", 10 | remote: "git+https://blah.com/blah.git", 11 | version: "^434.34.34", 12 | } 13 | 14 | const expected = { 15 | absolute: "file:/not-foo/bar", 16 | relative: "file:/foo/baz", 17 | remote: "git+https://blah.com/blah.git", 18 | version: "^434.34.34", 19 | } 20 | 21 | expect( 22 | resolveRelativeFileDependencies( 23 | appRootPath, 24 | JSON.parse(JSON.stringify(resolutions)), 25 | ), 26 | ).toEqual(expected) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /src/resolveRelativeFileDependencies.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from "./path" 2 | 3 | function transformVersionString(version: string, appRootPath: string) { 4 | if (version.startsWith("file:") && version[5] !== "/") { 5 | return "file:" + resolve(appRootPath, version.slice(5)) 6 | } else { 7 | return version 8 | } 9 | } 10 | 11 | export function resolveRelativeFileDependencies( 12 | appRootPath: string, 13 | resolutions: { [packageName: string]: string }, 14 | ) { 15 | const result = {} as { [packageName: string]: string } 16 | for (const packageName of Object.keys(resolutions)) { 17 | result[packageName] = transformVersionString( 18 | resolutions[packageName], 19 | appRootPath, 20 | ) 21 | } 22 | return result 23 | } 24 | -------------------------------------------------------------------------------- /src/spawnSafe.ts: -------------------------------------------------------------------------------- 1 | import { sync as spawnSync } from "cross-spawn" 2 | import { SpawnOptions } from "child_process" 3 | 4 | export interface SpawnSafeOptions extends SpawnOptions { 5 | throwOnError?: boolean 6 | logStdErrOnError?: boolean 7 | maxBuffer?: number 8 | } 9 | 10 | const defaultOptions: SpawnSafeOptions = { 11 | logStdErrOnError: true, 12 | throwOnError: true, 13 | } 14 | 15 | export const spawnSafeSync = ( 16 | command: string, 17 | args?: string[], 18 | options?: SpawnSafeOptions, 19 | ) => { 20 | const mergedOptions = Object.assign({}, defaultOptions, options) 21 | const result = spawnSync(command, args, options) 22 | if (result.error || result.status !== 0) { 23 | if (mergedOptions.logStdErrOnError) { 24 | if (result.stderr) { 25 | console.log(result.stderr.toString()) 26 | } else if (result.error) { 27 | console.log(result.error) 28 | } 29 | } 30 | if (mergedOptions.throwOnError) { 31 | throw result 32 | } 33 | } 34 | return result 35 | } 36 | -------------------------------------------------------------------------------- /src/stateFile.ts: -------------------------------------------------------------------------------- 1 | import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs" 2 | import { join } from "path" 3 | import { PackageDetails } from "./PackageDetails" 4 | import stringify from "json-stable-stringify" 5 | import { hashFile } from "./hash" 6 | import chalk from "chalk" 7 | export interface PatchState { 8 | patchFilename: string 9 | patchContentHash: string 10 | didApply: boolean 11 | } 12 | 13 | const version = 1 14 | export interface PatchApplicationState { 15 | version: number 16 | patches: PatchState[] 17 | isRebasing: boolean 18 | } 19 | 20 | export const STATE_FILE_NAME = ".patch-package.json" 21 | 22 | export function getPatchApplicationState( 23 | packageDetails: PackageDetails, 24 | ): PatchApplicationState | null { 25 | const fileName = join(packageDetails.path, STATE_FILE_NAME) 26 | 27 | let state: null | PatchApplicationState = null 28 | try { 29 | state = JSON.parse(readFileSync(fileName, "utf8")) 30 | } catch (e) { 31 | // noop 32 | } 33 | if (!state) { 34 | return null 35 | } 36 | if (state.version !== version) { 37 | console.log( 38 | `You upgraded patch-package and need to fully reinstall node_modules to continue.`, 39 | ) 40 | process.exit(1) 41 | } 42 | return state 43 | } 44 | 45 | export function savePatchApplicationState({ 46 | packageDetails, 47 | patches, 48 | isRebasing, 49 | }: { 50 | packageDetails: PackageDetails 51 | patches: PatchState[] 52 | isRebasing: boolean 53 | }) { 54 | const fileName = join(packageDetails.path, STATE_FILE_NAME) 55 | 56 | const state: PatchApplicationState = { 57 | patches, 58 | version, 59 | isRebasing, 60 | } 61 | 62 | writeFileSync(fileName, stringify(state, { space: 4 }), "utf8") 63 | } 64 | 65 | export function clearPatchApplicationState(packageDetails: PackageDetails) { 66 | const fileName = join(packageDetails.path, STATE_FILE_NAME) 67 | 68 | try { 69 | unlinkSync(fileName) 70 | } catch (e) { 71 | // noop 72 | } 73 | } 74 | 75 | export function verifyAppliedPatches({ 76 | appPath, 77 | patchDir, 78 | state, 79 | }: { 80 | appPath: string 81 | patchDir: string 82 | state: PatchApplicationState 83 | }) { 84 | const patchesDirectory = join(appPath, patchDir) 85 | for (const patch of state.patches) { 86 | if (!patch.didApply) { 87 | break 88 | } 89 | const fullPatchPath = join(patchesDirectory, patch.patchFilename) 90 | if (!existsSync(fullPatchPath)) { 91 | console.log( 92 | chalk.blueBright("Expected patch file"), 93 | fullPatchPath, 94 | "to exist but it is missing. Try removing and reinstalling node_modules first.", 95 | ) 96 | process.exit(1) 97 | } 98 | if (patch.patchContentHash !== hashFile(fullPatchPath)) { 99 | console.log( 100 | chalk.blueBright("Patch file"), 101 | fullPatchPath, 102 | "has changed since it was applied. Try removing and reinstalling node_modules first.", 103 | ) 104 | process.exit(1) 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["./property-based-tests", "./integration-tests"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "module": "commonjs", 5 | "lib": ["es2015", "es2016", "es2017"], 6 | "strict": true, 7 | "esModuleInterop": true, 8 | "outDir": "dist", 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": true, 11 | "inlineSourceMap": true, 12 | "noEmitOnError": false, 13 | "inlineSources": true 14 | }, 15 | "include": ["typings/**/*.d.ts", "src/**/*.ts", "property-based-tests/**/*", "integration-tests/**/*"], 16 | "compileOnSave": true 17 | } 18 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": ["tslint:recommended"], 4 | "jsRules": {}, 5 | "rules": { 6 | "prefer-for-of": false, 7 | "trailing-comma": [false], 8 | "ordered-imports": [false], 9 | "no-string-literal": false, 10 | "arrow-parens": false, 11 | "no-console": [false], 12 | "semicolon": [false], 13 | "whitespace": [false], 14 | "interface-name": [false], 15 | "one-line": [false], 16 | "object-literal-sort-keys": [false], 17 | "no-trailing-whitespace": [false], 18 | "object-literal-key-quotes": [false], 19 | "max-line-length": false, 20 | "no-shadowed-variable": false, 21 | "no-default-export": true 22 | }, 23 | "rulesDirectory": [] 24 | } 25 | -------------------------------------------------------------------------------- /typings/@yarnpkg/lockfile.d.ts: -------------------------------------------------------------------------------- 1 | declare module "@yarnpkg/lockfile" { 2 | export function parse( 3 | s: string, 4 | ): { 5 | type: "success" | "error" 6 | object: { 7 | [identifier: string]: { 8 | resolved?: string 9 | version: string 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /typings/klaw-sync.d.ts: -------------------------------------------------------------------------------- 1 | interface Options { 2 | nodir?: boolean 3 | nofile?: boolean 4 | depthLimit?: number 5 | fs?: object 6 | filter?: (item: Item) => boolean 7 | } 8 | 9 | interface Item { 10 | path: string 11 | stats: object 12 | } 13 | 14 | declare module "klaw-sync" { 15 | const klawSync: (dir: string, opts?: Options, ls?: Item[]) => Item[] 16 | export = klawSync 17 | } 18 | -------------------------------------------------------------------------------- /typings/randomstring.d.ts: -------------------------------------------------------------------------------- 1 | declare module "randomstring" { 2 | export function generate( 3 | opts: 4 | | number 5 | | { 6 | charset?: string 7 | length?: number 8 | readable?: boolean 9 | }, 10 | ): string 11 | } 12 | -------------------------------------------------------------------------------- /typings/slash.d.ts: -------------------------------------------------------------------------------- 1 | declare module "slash" { 2 | const slash: (path: string) => string 3 | export = slash 4 | } 5 | --------------------------------------------------------------------------------