commitizen 5.0.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ name: Publish approved releases
2
+ # The release workflow stages each version on npm and creates a draft GitHub
3
+ # release. A staged version can't be installed until a maintainer runs
4
+ # `npm stage approve`. npm doesn't notify GitHub when that happens, so this
5
+ # checks npm on a schedule and publishes each draft release whose version is
6
+ # now on npm. Run it by hand to publish right after approving:
7
+ # gh workflow run publish-approved-releases.yml
8
+ # A rejected stage never reaches npm, so its draft stays a draft. Delete that
9
+ # draft and its tag by hand.
10
+ "on":
11
+ schedule:
12
+ - cron: "*/15 * * * *"
13
+ workflow_dispatch:
14
+ permissions:
15
+ contents: write
16
+ concurrency:
17
+ group: publish-approved-releases
18
+ jobs:
19
+ publish:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v7
23
+ with:
24
+ sparse-checkout: package.json
25
+ sparse-checkout-cone-mode: false
26
+ - name: Publish drafts whose version is on npm
27
+ env:
28
+ GH_TOKEN: ${{ github.token }}
29
+ run: |
30
+ package=$(jq -r .name package.json)
31
+ # Oldest first, so the newest release ends up marked "Latest".
32
+ gh release list --limit 50 --json tagName,isDraft \
33
+ --jq '[.[] | select(.isDraft)] | reverse | .[].tagName' |
34
+ while read -r tag; do
35
+ version=${tag#v}
36
+ if [ "$(npm view "$package@$version" version 2>/dev/null)" = "$version" ]; then
37
+ echo "$package@$version is on npm: publishing release $tag"
38
+ gh release edit "$tag" --draft=false
39
+ else
40
+ echo "$package@$version is not on npm yet: leaving $tag as a draft"
41
+ fi
42
+ done
package/CONTRIBUTING.md CHANGED
@@ -70,8 +70,10 @@ npm stage download <stage-id> # optional: inspect the tarball
70
70
  npm stage approve <stage-id>
71
71
  ```
72
72
 
73
- Then publish the draft release at
74
- https://github.com/commitizen/cz-cli/releases.
73
+ You don't need to publish the draft GitHub release yourself. The "Publish
74
+ approved releases" workflow checks npm every 15 minutes and publishes the draft
75
+ once its version is on npm. To publish it right away, run
76
+ `gh workflow run publish-approved-releases.yml -R commitizen/cz-cli`.
75
77
 
76
78
  To abandon a staged version instead, run `npm stage reject <stage-id>`,
77
79
  delete the draft release, and delete its tag (`git push origin :refs/tags/vX.Y.Z`)
@@ -85,3 +87,12 @@ Some tests deliberately contain lines with only whitespace, to check how
85
87
  multiline commit messages behave across operating systems. If your editor
86
88
  strips trailing whitespace on save, turn that off for `test/` before editing
87
89
  those files, or the tests will change in ways you didn't intend.
90
+
91
+ ### A commitizen config in your home directory can change test results
92
+
93
+ Config loading comes from `@commitizen/config`, which falls back to `.czrc`,
94
+ `.cz.json` or `package.json` in your home directory when a project has none.
95
+ Unlike commitizen's old built-in loader, it doesn't skip that step while tests
96
+ run. If you have one of those files in your home directory, the `init` tests
97
+ may see an adapter as already configured. Rename the file while you run the
98
+ tests.
package/README.md CHANGED
@@ -26,9 +26,11 @@ Simply use `git cz` or just `cz` instead of `git commit` when committing. You ca
26
26
  _Alternatively_, if you are using **npm 5.2+** you can [use `npx`](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) instead of installing globally:
27
27
 
28
28
  ```sh
29
- npx cz
29
+ npx --no -- cz
30
30
  ```
31
31
 
32
+ `--no` stops npx from downloading anything when commitizen isn't installed in the project. Without it, npx would fetch an unrelated npm package that is also named `cz`. With pnpm, use `pnpm exec cz`.
33
+
32
34
  or as an npm script:
33
35
 
34
36
  ```json
@@ -44,7 +46,7 @@ When you're working in a Commitizen-friendly repository, you'll be prompted to f
44
46
 
45
47
  ### If your repo is NOT Commitizen friendly:
46
48
 
47
- If you're **not** working in a Commitizen-friendly repository, then `git cz` will work just the same as `git commit`, but `npx cz` will use the [streamich/git-cz](https://github.com/streamich/git-cz) adapter. To fix this, you need to first [make your repo Commitizen friendly](#making-your-repo-commitizen-friendly)
49
+ If you're **not** working in a Commitizen-friendly repository, then `git cz` will work just the same as `git commit`. To fix this, you need to first [make your repo Commitizen friendly](#making-your-repo-commitizen-friendly)
48
50
 
49
51
  ## Making your repo Commitizen friendly
50
52
 
@@ -157,12 +159,21 @@ exec < /dev/tty && node_modules/.bin/cz --hook || true
157
159
 
158
160
  ##### Husky
159
161
 
160
- For `husky` users, add the following configuration to the project's `package.json` file:
162
+ With [Husky](https://typicode.github.io/husky/) 9, create `.husky/prepare-commit-msg` containing:
163
+
164
+ ```sh
165
+ exec < /dev/tty && npx --no -- cz --hook || true
166
+ ```
167
+
168
+ If you haven't set up Husky yet, run `npx husky init` first. With Husky 5 to 8,
169
+ use the same file and make it executable (`chmod +x .husky/prepare-commit-msg`).
170
+
171
+ Husky 4 and earlier read hooks from `package.json` instead:
161
172
 
162
173
  ```json
163
174
  "husky": {
164
175
  "hooks": {
165
- "prepare-commit-msg": "exec < /dev/tty && npx cz --hook || true"
176
+ "prepare-commit-msg": "exec < /dev/tty && npx --no -- cz --hook || true"
166
177
  }
167
178
  }
168
179
  ```
@@ -283,7 +294,87 @@ We know that every project and build process has different requirements, so we'v
283
294
  - [cz-vinyl](https://github.com/Exlint/cz-vinyl)
284
295
  - [commit-jazzer](https://github.com/Zilero232/commit-jazzer)
285
296
 
286
- To create an adapter, just fork one of these great adapters and modify it to suit your needs. We pass you an instance of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/), but you can capture input using whatever means necessary. Just call the `commit` callback with a string and we'll be happy. Publish it to npm, and you'll be all set!
297
+ ### Writing an adapter
298
+
299
+ An adapter can work in one of two ways.
300
+
301
+ **As a program (adapter protocol).** Commitizen runs your adapter as its own
302
+ Node.js program, so you can use any prompt library, ES modules and top-level
303
+ `await`, and you don't need to depend on `commitizen`. Declare it in the
304
+ adapter's `package.json`:
305
+
306
+ ```json
307
+ {
308
+ "main": "./bin.js",
309
+ "commitizenAdapter": {
310
+ "protocol": [1],
311
+ "bin": "./bin.js"
312
+ }
313
+ }
314
+ ```
315
+
316
+ Commitizen runs `bin` with the same Node.js and your terminal, and sets:
317
+
318
+ | Variable | Meaning |
319
+ |---|---|
320
+ | `CZ_PROTOCOL` | The protocol version, currently `1`. |
321
+ | `CZ_MESSAGE_FILE` | An empty file. Write the commit message to it. |
322
+ | `CZ_CONFIG_FILE` | A JSON file with the project's commitizen config (`config.commitizen`, `.czrc` or `.cz.json`). |
323
+ | `CZ_GIT_ROOT` | The repository root. |
324
+
325
+ Exit with 0 after writing the message and commitizen commits it, including
326
+ `--hook` and `--retry` support. Exit with 0 without writing anything to cancel,
327
+ or exit non-zero to abort; commitizen exits with the same status. `main` must
328
+ point at a file that exists, because commitizen resolves the adapter path the
329
+ same way for every adapter. See [examples/protocol-adapter](examples/protocol-adapter)
330
+ for a complete adapter with no dependencies.
331
+
332
+ **As a module (original API).** Export a `prompter(cz, commit)` function.
333
+ Commitizen loads the module with `require()` and passes an instance of
334
+ [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) 8, though you can
335
+ capture input using whatever means necessary. Call the `commit` callback with a
336
+ string and we'll be happy. Existing adapters keep working this way.
337
+
338
+ Publish your adapter to npm, and you'll be all set!
339
+
340
+ Maintain an adapter already? [Migration guide for adapter maintainers](docs/migrating-adapters.md)
341
+ covers what changed in commitizen 5 and 6 and how to adopt the protocol.
342
+
343
+ ## Security: risks and how to reduce them
344
+
345
+ Commitizen runs code from your project's dependencies, and sometimes from the repository itself. Plain `git commit` doesn't. This section explains the risks and what you can do about each.
346
+
347
+ ### Risks
348
+
349
+ - **An adapter runs with your full permissions.** Commitizen runs the adapter named in `config.commitizen.path`, either inside its own process (a `prompter` adapter) or as a separate program (a protocol adapter). Either way it runs as you. It can read your files, SSH keys and environment variables (including tokens), change your working tree and staged files, and run git. Commitizen can't limit what an adapter does.
350
+ - **A repository can bring its own adapter.** `config.commitizen.path` can name a file inside the repository, such as `./tools/adapter.js`. Running `git cz` in a repository you've just cloned can then run that repository's code, just as `npm test` would.
351
+ - **An adapter can change what gets committed.** Commitizen commits whatever is staged when the adapter finishes.
352
+ - **Some adapters send data elsewhere.** Adapters that integrate with issue trackers or AI services may send your branch name, staged changes or message to that service.
353
+ - **Commit messages are kept for `--retry`.** Commitizen saves the last message for each repository in `commitizen.json` in your user cache directory (for example `~/Library/Caches/commitizen` on macOS or `~/.cache/commitizen` on Linux).
354
+ - **Installing runs code.** Depending on your package manager, installing an adapter can run install scripts from the adapter and any of its dependencies. A compromised release of any of them runs on your machine before you ever use commitizen.
355
+ - **`npx cz` can download an unrelated package.** If commitizen isn't installed in the project, `npx cz` looks for an npm package named `cz`, which isn't commitizen.
356
+
357
+ ### Reducing the risk
358
+
359
+ - **Choose adapters as carefully as any dev dependency you run**, such as a test runner or linter. Prefer widely used, maintained adapters, and read what an adapter sends to other services before giving it tokens.
360
+ - **Check a repository before running `git cz` in it.** Look at `config.commitizen` in its `package.json`, `.czrc` or `.cz.json`. A path starting with `./` runs code from the repository.
361
+ - **Check your commit** with `git show --stat HEAD` when trying out an adapter you haven't reviewed.
362
+ - **Keep secrets out of commit messages.** They end up in git history anyway.
363
+ - **Run the commitizen installed in your project**, not one npx downloads: `npx --no -- cz`, `pnpm exec cz` or `node_modules/.bin/cz`. `--no` makes npx fail instead of downloading.
364
+ - **Commit your lockfile and install exact versions** (`--save-exact`, as in the examples above), so everyone runs the versions you reviewed.
365
+ - **Delay new releases.** Most attacks through npm are found and removed within days. A minimum release age makes your package manager ignore versions newer than that, and avoid install scripts where you can:
366
+
367
+ | Package manager | `commitizen init` | Install scripts from dependencies | Minimum release age |
368
+ |---|---|---|---|
369
+ | npm | default | Run by default. Use `--ignore-scripts` or `ignore-scripts=true` in `.npmrc`. | [`min-release-age`](https://docs.npmjs.com/cli/v11/using-npm/config#min-release-age) (days), npm 11.10+ |
370
+ | Yarn 1 | `--yarn` | Run by default. Use `--ignore-scripts`. | Not available |
371
+ | Yarn 2+ | `--yarn` | Run by default. Set `enableScripts: false` in `.yarnrc.yml`. | [`npmMinimalAgeGate`](https://yarnpkg.com/configuration/yarnrc#npmMinimalAgeGate), Yarn 4.10+ |
372
+ | pnpm | `--pnpm` | Not run: commitizen passes `--ignore-scripts`, and pnpm 10+ runs dependency scripts only for packages you allow. | [`minimumReleaseAge`](https://pnpm.io/settings#minimumreleaseage) (minutes); on by default (1 day) in pnpm 11 |
373
+ | Bun | Not supported; install the adapter yourself and set `config.commitizen.path` | Run only for packages in `trustedDependencies` (and Bun's built-in list). | [`minimumReleaseAge`](https://bun.com/docs/pm/cli/install) in `bunfig.toml` (seconds) |
374
+
375
+ Commitizen itself passes the commit message to git as a single argument, never through a shell, so a message can't run commands.
376
+
377
+ To report a security problem in commitizen itself, use [GitHub's private vulnerability reporting](https://github.com/commitizen/cz-cli/security/advisories/new) rather than a public issue.
287
378
 
288
379
  ## Retrying failed commits
289
380
 
@@ -294,7 +385,7 @@ Please note that the retry cache may be cleared when upgrading Commitizen versio
294
385
  It is important to note that if you are running `cz` from an npm script (let's say it is called `commit`) you will need to do one of the following:
295
386
 
296
387
  - Pass `-- --retry` as an argument for your script. i.e: `npm run commit -- --retry`
297
- - Use [npx](https://www.npmjs.com/package/npx) to find and call the `cz` executable directly. i.e: `npx cz --retry`
388
+ - Use [npx](https://www.npmjs.com/package/npx) to find and call the `cz` executable directly. i.e: `npx --no -- cz --retry`
298
389
 
299
390
  Note that the last two options **do not** require you to pass `--` before the args but the first **does**.
300
391
 
package/SECURITY.md ADDED
@@ -0,0 +1,17 @@
1
+ # Security policy
2
+
3
+ ## Reporting a vulnerability
4
+
5
+ Please report security problems privately through [GitHub's private vulnerability reporting](https://github.com/commitizen/cz-cli/security/advisories/new), not in a public issue or pull request.
6
+
7
+ Include what you found, the commitizen version, and steps to reproduce it if you can. We'll reply in the advisory, and credit you when the fix is published unless you'd rather not be named.
8
+
9
+ ## Supported versions
10
+
11
+ Fixes are released for the latest major version only. Please upgrade before reporting a problem in an older version.
12
+
13
+ ## What counts as a vulnerability
14
+
15
+ Commitizen runs the adapter your project configures, with your permissions, so an adapter doing something harmful isn't a vulnerability in commitizen itself. Report those to the adapter's maintainers. See [Security: risks and how to reduce them](README.md#security-risks-and-how-to-reduce-them) for what commitizen does and doesn't protect against.
16
+
17
+ Problems in commitizen's own code, such as running code or commands it shouldn't, are in scope.
package/bin/git-cz.js CHANGED
@@ -5,12 +5,15 @@ process.on('uncaughtException', function (err) {
5
5
  process.exit(1);
6
6
  });
7
7
 
8
- // catch SIGINT signal
9
- process.stdin.on('data', function (key) {
10
- if (key == '\u0003') {
11
- process.exit(130); // 128 + SIGINT
12
- }
13
- });
8
+ // catch SIGINT signal. Only a terminal can send Ctrl-C as data; listening on a
9
+ // pipe would read input meant for the adapter.
10
+ if (process.stdin.isTTY) {
11
+ process.stdin.on('data', function (key) {
12
+ if (key == '\u0003') {
13
+ process.exit(130); // 128 + SIGINT
14
+ }
15
+ });
16
+ }
14
17
 
15
18
  require('../dist/cli/git-cz.js').bootstrap({
16
19
  cliPath: path.join(__dirname, '../')
@@ -49,7 +49,7 @@ function gitCz(rawGitArgs, environment, adapterConfig) {
49
49
  let hookMode = !(typeof parsedCommitizenArgs.hook === 'undefined');
50
50
  let resolvedAdapterConfigPath = resolveAdapterPath(adapterConfig.path);
51
51
  let resolvedAdapterRootPath = (0, _util.findPackageRoot)(resolvedAdapterConfigPath);
52
- let prompter = getPrompter(adapterConfig.path);
52
+ let prompter = getPrompter(adapterConfig.path, adapterConfig);
53
53
  let shouldStageAllFiles = rawGitArgs.includes('-a') || rawGitArgs.includes('--all');
54
54
  isClean(process.cwd(), function (error, stagingIsClean) {
55
55
  if (error) {
@@ -16,6 +16,7 @@ var _nodePath = _interopRequireDefault(require("node:path"));
16
16
  var _nodeFs = _interopRequireDefault(require("node:fs"));
17
17
  var _detectIndent = _interopRequireDefault(require("detect-indent"));
18
18
  var _util = require("../common/util");
19
+ var _protocol = require("./protocol");
19
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
21
  /**
21
22
  * ADAPTER
@@ -141,11 +142,19 @@ function getInstallStringMappings({
141
142
  }
142
143
 
143
144
  /**
144
- * Gets the prompter from an adapter given an adapter path
145
+ * Gets the prompter from an adapter given an adapter path.
146
+ *
147
+ * For an adapter that declares the adapter protocol in its package.json, the
148
+ * prompter runs the adapter's program and `config` (the commitizen config) is
149
+ * passed to it. Other adapters are loaded with require(), as always.
145
150
  */
146
- function getPrompter(adapterPath) {
151
+ function getPrompter(adapterPath, config) {
147
152
  // Resolve the adapter path
148
153
  let resolvedAdapterPath = resolveAdapterPath(adapterPath);
154
+ let declaration = (0, _protocol.getProtocolDeclaration)(resolvedAdapterPath);
155
+ if (declaration) {
156
+ return (0, _protocol.createProtocolPrompter)(declaration, config, getGitRootPath());
157
+ }
149
158
 
150
159
  // Load the adapter
151
160
  let adapter = require(resolvedAdapterPath);
@@ -175,10 +184,24 @@ function resolveAdapterPath(inboundAdapterPath) {
175
184
  // try to resolve the given path
176
185
  return require.resolve(absoluteAdapterPath);
177
186
  } catch (error) {
178
- error.message = "Could not resolve " + absoluteAdapterPath + ". " + error.message;
187
+ error.message = "Could not resolve " + absoluteAdapterPath + ". " + installHint(inboundAdapterPath, isPath) + error.message;
179
188
  throw error;
180
189
  }
181
190
  }
191
+
192
+ /**
193
+ * Suggests installing the adapter's package when the configured path points
194
+ * into node_modules or is a package name. Since commitizen 6,
195
+ * installing commitizen no longer installs cz-conventional-changelog.
196
+ */
197
+ function installHint(adapterPath, isPath) {
198
+ let normalized = adapterPath.split(_nodePath.default.sep).join('/');
199
+ let match = isPath ? /(?:^|\/)node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(normalized) : /^((?:@[^/]+\/)?[^/]+)/.exec(normalized);
200
+ if (!match) {
201
+ return '';
202
+ }
203
+ return `Is ${match[1]} installed? Install it in your project with: npm install --save-dev ${match[1]}\n`;
204
+ }
182
205
  function getGitRootPath() {
183
206
  return _nodeChild_process.default.spawnSync('git', ['rev-parse', '--show-toplevel'], {
184
207
  encoding: 'utf8'
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.load = load;
7
- var _configLoader = require("../configLoader");
8
- // Configuration sources in priority order.
9
- var configs = ['.czrc', '.cz.json', 'package.json'];
10
- function load(config, cwd) {
11
- return (0, _configLoader.loader)(configs, config, cwd);
12
- }
6
+ Object.defineProperty(exports, "load", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _config.load;
10
+ }
11
+ });
12
+ var _config = require("@commitizen/config");
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SUPPORTED_PROTOCOLS = void 0;
7
+ exports.chooseProtocol = chooseProtocol;
8
+ exports.createProtocolPrompter = createProtocolPrompter;
9
+ exports.getProtocolDeclaration = getProtocolDeclaration;
10
+ var _nodeChild_process = _interopRequireDefault(require("node:child_process"));
11
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
12
+ var _nodeOs = _interopRequireDefault(require("node:os"));
13
+ var _nodePath = _interopRequireDefault(require("node:path"));
14
+ var _util = require("../common/util");
15
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ /**
17
+ * ADAPTER PROTOCOL
18
+ *
19
+ * A protocol adapter is a program, not a module commitizen loads. Its
20
+ * package.json declares:
21
+ *
22
+ * "commitizenAdapter": { "protocol": [1], "bin": "./bin.js" }
23
+ *
24
+ * commitizen runs `bin` with the same Node.js, with the terminal inherited, and
25
+ * these environment variables:
26
+ *
27
+ * CZ_PROTOCOL the protocol version commitizen chose
28
+ * CZ_MESSAGE_FILE an empty file; the adapter writes the commit message here
29
+ * CZ_CONFIG_FILE JSON of the commitizen config (what configLoader.load() returns)
30
+ * CZ_GIT_ROOT the repository root
31
+ *
32
+ * Exit 0 with a message commits it. Exit 0 with an empty message cancels.
33
+ * Any other exit aborts with that exit status.
34
+ *
35
+ * Adapters without the declaration are loaded with require() and called as
36
+ * prompter(inquirer, commit), exactly as before.
37
+ */
38
+
39
+ // Protocol versions this version of commitizen can run, oldest first.
40
+ const SUPPORTED_PROTOCOLS = exports.SUPPORTED_PROTOCOLS = [1];
41
+
42
+ /**
43
+ * Returns the adapter's protocol declaration ({ protocol, bin, root }), or
44
+ * undefined for a legacy adapter. `resolvedAdapterPath` is the file that
45
+ * resolveAdapterPath() found.
46
+ */
47
+ function getProtocolDeclaration(resolvedAdapterPath) {
48
+ let root;
49
+ let packageJson;
50
+ try {
51
+ root = (0, _util.findPackageRoot)(_nodePath.default.dirname(resolvedAdapterPath));
52
+ packageJson = JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(root, 'package.json'), 'utf8'));
53
+ } catch (error) {
54
+ // No readable package.json: a legacy adapter such as a single local file.
55
+ return undefined;
56
+ }
57
+ let declaration = packageJson.commitizenAdapter;
58
+ if (!declaration || typeof declaration !== 'object') {
59
+ return undefined;
60
+ }
61
+ let name = packageJson.name || root;
62
+ if (!Array.isArray(declaration.protocol) || typeof declaration.bin !== 'string') {
63
+ throw new Error(`The adapter ${name} has an invalid "commitizenAdapter" field in its package.json. ` + 'It needs "protocol" (an array of versions) and "bin" (a path to the adapter program).');
64
+ }
65
+ return {
66
+ name,
67
+ root,
68
+ protocol: declaration.protocol,
69
+ bin: declaration.bin
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Picks the highest protocol version both commitizen and the adapter support,
75
+ * or throws if there is none.
76
+ */
77
+ function chooseProtocol(declaration) {
78
+ let shared = SUPPORTED_PROTOCOLS.filter(function (version) {
79
+ return declaration.protocol.includes(version);
80
+ });
81
+ if (shared.length === 0) {
82
+ throw new Error(`The adapter ${declaration.name} speaks protocol version(s) ${declaration.protocol.join(', ')}, ` + `but this version of commitizen supports ${SUPPORTED_PROTOCOLS.join(', ')}. ` + 'Upgrade whichever of the two is older.');
83
+ }
84
+ return shared[shared.length - 1];
85
+ }
86
+
87
+ /**
88
+ * Returns a prompter(inquirer, commit) that runs a protocol adapter's program.
89
+ * Because it has the legacy prompter shape, commit, --hook and --retry work the
90
+ * same for both kinds of adapter. The prompter returns a promise that resolves
91
+ * once the adapter has finished (commitizen itself ignores it).
92
+ */
93
+ function createProtocolPrompter(declaration, config, gitRootPath) {
94
+ let version = chooseProtocol(declaration);
95
+ let binPath = _nodePath.default.resolve(declaration.root, declaration.bin);
96
+ function prompter(inquirer, commit) {
97
+ return new Promise(function (resolve) {
98
+ run(commit, resolve);
99
+ });
100
+ }
101
+ function run(commit, resolve) {
102
+ let workDirectory = _nodeFs.default.mkdtempSync(_nodePath.default.join(_nodeOs.default.tmpdir(), 'commitizen-'));
103
+ let messageFile = _nodePath.default.join(workDirectory, 'COMMIT_MESSAGE');
104
+ let configFile = _nodePath.default.join(workDirectory, 'config.json');
105
+ _nodeFs.default.writeFileSync(messageFile, '');
106
+ _nodeFs.default.writeFileSync(configFile, JSON.stringify(config || {}));
107
+
108
+ // The adapter owns the terminal while it runs. Stop this process reading
109
+ // stdin (bin/git-cz listens for Ctrl-C) so it doesn't take the input.
110
+ process.stdin.pause();
111
+ let child = _nodeChild_process.default.spawn(process.execPath, [binPath], {
112
+ stdio: 'inherit',
113
+ env: {
114
+ ...process.env,
115
+ CZ_PROTOCOL: String(version),
116
+ CZ_MESSAGE_FILE: messageFile,
117
+ CZ_CONFIG_FILE: configFile,
118
+ CZ_GIT_ROOT: gitRootPath
119
+ }
120
+ });
121
+ let finished = false;
122
+ function finish(status, message) {
123
+ finished = true;
124
+ _nodeFs.default.rmSync(workDirectory, {
125
+ recursive: true,
126
+ force: true
127
+ });
128
+ if (status !== 0) {
129
+ // The adapter has already reported its own error.
130
+ process.exitCode = status;
131
+ } else if (message.trim() === '') {
132
+ console.log('No commit message from the adapter; nothing was committed.');
133
+ } else {
134
+ commit(message);
135
+ }
136
+ resolve();
137
+ }
138
+ child.on('error', function (error) {
139
+ console.error(`Could not run the adapter ${declaration.name} (${binPath}): ${error.message}`);
140
+ finish(1);
141
+ });
142
+ child.on('close', function (code, signal) {
143
+ // A child that fails to start emits 'error' and may then emit 'close'.
144
+ if (finished) {
145
+ return;
146
+ }
147
+ if (signal || code !== 0) {
148
+ finish(code || 1);
149
+ } else {
150
+ finish(0, _nodeFs.default.readFileSync(messageFile, 'utf8'));
151
+ }
152
+ });
153
+ }
154
+ prompter.protocol = version;
155
+ return prompter;
156
+ }
@@ -8,7 +8,6 @@ exports.findPackageRoot = findPackageRoot;
8
8
  exports.getParsedJsonFromFile = getParsedJsonFromFile;
9
9
  exports.getParsedPackageJsonFromPath = getParsedPackageJsonFromPath;
10
10
  exports.isFunction = isFunction;
11
- exports.isInTest = isInTest;
12
11
  var _nodeFs = _interopRequireDefault(require("node:fs"));
13
12
  var _nodePath = _interopRequireDefault(require("node:path"));
14
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -45,9 +44,6 @@ function isFunction(functionToCheck) {
45
44
  return functionToCheck && (functionType === '[object Function]' || functionType === '[object AsyncFunction]');
46
45
  }
47
46
  }
48
- function isInTest() {
49
- return typeof global.it === 'function';
50
- }
51
47
 
52
48
  /**
53
49
  * Walks up from `start` (inclusive) to the nearest directory containing a