Skip to content

Commit 84e027b

Browse files
authored
Merge pull request #111 from ds300/fix/error-if-no-patches
fail if no patches are present
2 parents c063ade + 2705c4f commit 84e027b

File tree

7 files changed

+23
-6
lines changed

7 files changed

+23
-6
lines changed

integration-tests/happy-path-npm/__snapshots__/happy-path-npm.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`Test happy-path-npm: making patch 1`] = `
44
"SNAPSHOT: making patch
5+
patch-package 0.0.0
56
✔ Creating temporary folder
67
✔ Making tmp package.json
78
✔ Installing [email protected] with npm

integration-tests/happy-path-yarn/__snapshots__/happy-path-yarn.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`Test happy-path-yarn: making patch 1`] = `
44
"SNAPSHOT: making patch
5+
patch-package 0.0.0
56
✔ Creating temporary folder
67
✔ Making tmp package.json
78
✔ Installing [email protected] with yarn

integration-tests/nested-packages/__snapshots__/nested-packages.test.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`Test nested-packages: create the patch 1`] = `
44
"SNAPSHOT: create the patch
5+
patch-package 0.0.0
56
✔ Creating temporary folder
67
✔ Making tmp package.json
78
✔ Installing [email protected] with yarn
@@ -12,7 +13,8 @@ END SNAPSHOT"
1213

1314
exports[`Test nested-packages: run patch-package 1`] = `
1415
"SNAPSHOT: run patch-package
15-
patch-package: Applying patches...
16+
patch-package 0.0.0
17+
Applying patches...
1618
wrap-ansi/[email protected]
1719
END SNAPSHOT"
1820
`;

integration-tests/nested-scoped-packages/__snapshots__/nested-scoped-packages.test.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`Test nested-scoped-packages: create the patch 1`] = `
44
"SNAPSHOT: create the patch
5+
patch-package 0.0.0
56
✔ Creating temporary folder
67
✔ Making tmp package.json
78
✔ Installing @types/[email protected] with yarn
@@ -12,7 +13,8 @@ END SNAPSHOT"
1213

1314
exports[`Test nested-scoped-packages: run patch-package 1`] = `
1415
"SNAPSHOT: run patch-package
15-
patch-package: Applying patches...
16+
patch-package 0.0.0
17+
Applying patches...
1618
@microsoft/mezzurite-core/@types/[email protected]
1719
END SNAPSHOT"
1820
`;

run-tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ export CI=true
55

66
yarn clean
77
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
810
yarn pack --filename patch-package.test.$(date +%s).tgz
9-
jest "$@"
11+
yarn version --new-version $version --no-git-tag-version --no-commit-hooks
12+
yarn jest "$@"

src/applyPatches.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold, cyan, green, red, yellow } from "chalk"
1+
import { bold, green, red, yellow } from "chalk"
22
import { getPatchFiles } from "./patchFs"
33
import { executeEffects } from "./patch/apply"
44
import { existsSync, readFileSync } from "fs-extra"
@@ -48,7 +48,8 @@ export const applyPatchesForApp = (
4848
const files = findPatchFiles(patchesDirectory)
4949

5050
if (files.length === 0) {
51-
console.log(cyan("No patch files found"))
51+
console.error(red("No patch files found"))
52+
process.exit(1)
5253
}
5354

5455
files.forEach(filename => {

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getAppRootPath } from "./getAppRootPath"
77
import { makePatch } from "./makePatch"
88
import { makeRegExp } from "./makeRegExp"
99
import { detectPackageManager } from "./detectPackageManager"
10+
import { join } from "./path"
1011

1112
const appPath = getAppRootPath()
1213
const argv = minimist(process.argv.slice(2), {
@@ -15,6 +16,12 @@ const argv = minimist(process.argv.slice(2), {
1516
})
1617
const packageNames = argv._
1718

19+
console.log(
20+
bold("patch-package"),
21+
// tslint:disable-next-line:no-var-requires
22+
require(join(__dirname, "../package.json")).version,
23+
)
24+
1825
if (argv.help || argv.h) {
1926
printHelp()
2027
} else {
@@ -42,7 +49,7 @@ if (argv.help || argv.h) {
4249
)
4350
})
4451
} else {
45-
console.log("patch-package: Applying patches...")
52+
console.log("Applying patches...")
4653
applyPatchesForApp(appPath, !!argv["reverse"], argv["patch-dir"])
4754
}
4855
}

0 commit comments

Comments
 (0)