Skip to content

Commit

Permalink
fix(scripts/commit-msg): prevent commitlint from ever type-checking c…
Browse files Browse the repository at this point in the history
…onfiguration

**@commitlint/cli** added support for TypeScript-based configurations via `ts-node`, and that has caused a good deal of grief:

conventional-changelog/commitlint#3420
conventional-changelog/commitlint#3351
conventional-changelog/commitlint#3218
conventional-changelog/commitlint#3256

hoverinc/web-react#1792

Both because it's a heavy-ass dependency and because it requires configuration to
work properly. It seems like project-local configuration can affect it's invocation
of ts-node, which happens even JavaScript configuration files now?... lame.

Anyways, this ensures we avoid any type-checking that happens in it's ts-node
invocation until we get a better solution upstream (or contribute one). Ideally,
installing ts-node would be opt-in etc.
  • Loading branch information
jrolfs committed Feb 27, 2023
1 parent 33c2fcd commit b195b15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/scripts/__tests__/__snapshots__/commit-msg.js.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`commit-msg adds env flag with HUSKY_GIT_PARAMS when available 1`] = `commitlint --env HUSKY_GIT_PARAMS --config ./src/config/commitlint.config.js`;
exports[`commit-msg adds env flag with HUSKY_GIT_PARAMS when available 1`] = `TS_NODE_TRANSPILE_ONLY=true commitlint --env HUSKY_GIT_PARAMS --config ./src/config/commitlint.config.js`;

exports[`commit-msg calls @commitlint/cli with default args 1`] = `commitlint --config ./src/config/commitlint.config.js --edit`;
exports[`commit-msg calls @commitlint/cli with default args 1`] = `TS_NODE_TRANSPILE_ONLY=true commitlint --config ./src/config/commitlint.config.js --edit`;

exports[`commit-msg defaults to \`--edit\` when no args are passed and HUSKY_GIT_PARAMS is not available 1`] = `commitlint --config ./src/config/commitlint.config.js --edit`;
exports[`commit-msg defaults to \`--edit\` when no args are passed and HUSKY_GIT_PARAMS is not available 1`] = `TS_NODE_TRANSPILE_ONLY=true commitlint --config ./src/config/commitlint.config.js --edit`;

exports[`commit-msg does not use built-in config with --config 1`] = `commitlint --config ./custom-config.js`;
exports[`commit-msg does not use built-in config with --config 1`] = `TS_NODE_TRANSPILE_ONLY=true commitlint --config ./custom-config.js`;

exports[`commit-msg does not use built-in config with commitlint.config.js file 1`] = `commitlint --edit`;
exports[`commit-msg does not use built-in config with commitlint.config.js file 1`] = `TS_NODE_TRANSPILE_ONLY=true commitlint --edit`;

exports[`commit-msg forwards args 1`] = `commitlint --config ./src/config/commitlint.config.js --edit .git/COMMIT_EDITMSG`;
exports[`commit-msg forwards args 1`] = `TS_NODE_TRANSPILE_ONLY=true commitlint --config ./src/config/commitlint.config.js --edit .git/COMMIT_EDITMSG`;
4 changes: 3 additions & 1 deletion src/scripts/commit-msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const config = useBuiltinConfig
: []

const result = spawn.sync(
resolveBin('@commitlint/cli', {executable: 'commitlint'}),
`TS_NODE_TRANSPILE_ONLY=true ${resolveBin('@commitlint/cli', {
executable: 'commitlint',
})}`,
[...env, ...config, ...args, ...defaultEdit],
{
stdio: 'inherit',
Expand Down

0 comments on commit b195b15

Please sign in to comment.