diff --git a/integration-tests/lerna-canary/lerna-canary.sh b/integration-tests/lerna-canary/lerna-canary.sh new file mode 100755 index 00000000..aed51d2c --- /dev/null +++ b/integration-tests/lerna-canary/lerna-canary.sh @@ -0,0 +1,38 @@ +# make sure errors stop the script +set -e + +echo "add patch-package" +yarn add $1 + +echo "Add @parcel/codeframe" +yarn add @parcel/codeframe@2.0.0-nightly.137 + +echo "replace codeframe with yarn in @parcel/codefram/src/codeframe.js" +npx replace codeframe yarn node_modules/@parcel/codeframe/src/codeframe.js + +echo "SNAPSHOT: making patch" +npx patch-package @parcel/codeframe +echo "END SNAPSHOT" + +echo "SNAPSHOT: the patch looks like this" +cat patches/@parcel/codeframe+2.0.0-nightly.137.patch +echo "END SNAPSHOT" + +echo "reinstall node_modules" +npx rimraf node_modules +yarn + +echo "patch-package didn't run" +if grep yarn node_modules/@parcel/codeframe/src/codeframe.js ; then + exit 1 +fi + +echo "add patch-package to postinstall hook" +node ./add-postinstall.js + +echo "reinstall node_modules" +npx rimraf node_modules +yarn + +echo "patch-package did run" +grep yarn node_modules/@parcel/codeframe/src/codeframe.js diff --git a/integration-tests/lerna-canary/lerna-canary.test.ts b/integration-tests/lerna-canary/lerna-canary.test.ts new file mode 100644 index 00000000..0f55db35 --- /dev/null +++ b/integration-tests/lerna-canary/lerna-canary.test.ts @@ -0,0 +1,2 @@ +import { runIntegrationTest } from "../runIntegrationTest" +runIntegrationTest({projectName: "lerna-canary", shouldProduceSnapshots: false}) diff --git a/integration-tests/lerna-canary/package.json b/integration-tests/lerna-canary/package.json new file mode 100644 index 00000000..cfd3ae7e --- /dev/null +++ b/integration-tests/lerna-canary/package.json @@ -0,0 +1,9 @@ +{ + "name": "lerna-canary", + "version": "1.0.0", + "description": "integration test for patch-package", + "main": "index.js", + "author": "", + "license": "ISC", + "dependencies": {} +} diff --git a/integration-tests/lerna-canary/yarn.lock b/integration-tests/lerna-canary/yarn.lock new file mode 100644 index 00000000..fb57ccd1 --- /dev/null +++ b/integration-tests/lerna-canary/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + diff --git a/src/getPackageResolution.ts b/src/getPackageResolution.ts index 08a952e6..e33bf3cf 100644 --- a/src/getPackageResolution.ts +++ b/src/getPackageResolution.ts @@ -31,10 +31,12 @@ export function getPackageResolution({ throw new Error("Can't parse lock file") } - const installedVersion = require(join( + const installedVersionLong = require(join( resolve(appPath, packageDetails.path), "package.json", )).version as string + const indexOfPlus = installedVersionLong.indexOf('+'); + const installedVersion = indexOfPlus === -1 ? installedVersionLong : installedVersionLong.substring(0, indexOfPlus) const entries = Object.entries(appLockFile.object).filter( ([k, v]) =>