Skip to content

Commit 23b3320

Browse files
Merge remote-tracking branch 'origin/master'
2 parents d4636e6 + 539326c commit 23b3320

File tree

8 files changed

+50
-7
lines changed

8 files changed

+50
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ options:
9191
9292
-h, --help Show usage information
9393
94+
--ignore-scripts Bypass version scripts
95+
9496
files...
9597
One or more files and/or globs to bump (ex: README.md *.txt docs/**/*).
9698
Defaults to package.json and package-lock.json.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli/help.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ options:
4343
4444
-h, --help Show usage information
4545
46+
--ignore-scripts Bypass version scripts
47+
4648
files...
4749
One or more files and/or globs to bump (ex: README.md *.txt docs/**/*).
4850
Defaults to package.json and package-lock.json.

src/cli/parse-args.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
3131
{ name: "quiet", alias: "q", type: Boolean },
3232
{ name: "version", alias: "v", type: Boolean },
3333
{ name: "help", alias: "h", type: Boolean },
34+
{ name: "ignore-scripts", type: Boolean },
3435
{ name: "files", type: String, multiple: true, defaultOption: true },
3536
],
3637
{ argv }
@@ -48,6 +49,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
4849
all: args.all as boolean,
4950
noVerify: args["no-verify"] as boolean,
5051
files: args.files as string[],
52+
ignoreScripts: args["ignore-scripts"] as boolean,
5153
}
5254
};
5355

src/normalize-options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface NormalizedOptions {
5555
files: string[];
5656
cwd: string;
5757
interface: Interface;
58+
ignoreScripts: boolean;
5859
}
5960

6061
/**
@@ -67,6 +68,7 @@ export async function normalizeOptions(raw: VersionBumpOptions): Promise<Normali
6768
let all = Boolean(raw.all);
6869
let noVerify = Boolean(raw.noVerify);
6970
let cwd = raw.cwd || process.cwd();
71+
let ignoreScripts = Boolean(raw.ignoreScripts);
7072

7173
let release: Release;
7274
if (!raw.release || raw.release === "prompt") {
@@ -131,7 +133,7 @@ export async function normalizeOptions(raw: VersionBumpOptions): Promise<Normali
131133
throw new Error("Cannot prompt for the version number because input or output has been disabled.");
132134
}
133135

134-
return { release, commit, tag, push, files, cwd, interface: ui };
136+
return { release, commit, tag, push, files, cwd, interface: ui, ignoreScripts };
135137
}
136138

137139
/**

src/run-npm-script.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { NpmScript, ProgressEvent } from "./types/version-bump-progress";
88
* Runs the specified NPM script in the package.json file.
99
*/
1010
export async function runNpmScript(script: NpmScript, operation: Operation): Promise<Operation> {
11-
let { cwd } = operation.options;
11+
let { cwd, ignoreScripts } = operation.options;
1212

13-
let { data: manifest } = await readJsonFile("package.json", cwd);
13+
if (!ignoreScripts) {
14+
let { data: manifest } = await readJsonFile("package.json", cwd);
1415

15-
if (isManifest(manifest) && hasScript(manifest, script)) {
16-
await ezSpawn.async("npm", ["run", script, "--silent"], { stdio: "inherit" });
17-
operation.update({ event: ProgressEvent.NpmScript, script });
16+
if (isManifest(manifest) && hasScript(manifest, script)) {
17+
await ezSpawn.async("npm", ["run", script, "--silent"], { stdio: "inherit" });
18+
operation.update({ event: ProgressEvent.NpmScript, script });
19+
}
1820
}
1921

2022
return operation;

src/types/version-bump-options.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ export interface VersionBumpOptions {
9292
*/
9393
interface?: boolean | InterfaceOptions;
9494

95+
/**
96+
* Indicates whether to ignore version scripts.
97+
*
98+
* Defaults to `false`.
99+
*/
100+
ignoreScripts?: boolean;
101+
95102
/**
96103
* A callback that is provides information about the progress of the `versionBump()` function.
97104
*/

test/specs/npm.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,30 @@ describe("npm version hooks", () => {
136136
expect(bin[6].version).to.equal("2.0.0");
137137
});
138138

139+
it("should skip all version scripts when --ignore-scripts is used", () => {
140+
files.create("package.json", {
141+
version: "1.2.3",
142+
scripts: {
143+
preversion: "echo preversion",
144+
version: "echo version",
145+
postversion: "echo postversion",
146+
}
147+
});
148+
files.create("package-lock.json", { version: "1.2.3" });
149+
150+
let cli = bump("major --ignore-scripts");
151+
152+
expect(cli).to.have.stderr("");
153+
expect(cli).to.have.exitCode(0);
154+
155+
expect(cli).to.have.stdout(
156+
`${check} Updated package.json to 2.0.0\n` +
157+
`${check} Updated package-lock.json to 2.0.0\n`
158+
);
159+
160+
// NPM should not have been run at all
161+
let npm = mocks.npm();
162+
expect(npm.length).to.equal(0);
163+
});
164+
139165
});

0 commit comments

Comments
 (0)