From b195b15f80c665842fe6a16cd10b70da35a5503a Mon Sep 17 00:00:00 2001 From: Jamie Rolfs Date: Mon, 27 Feb 2023 13:43:08 -0800 Subject: [PATCH] fix(scripts/commit-msg): prevent commitlint from ever type-checking configuration **@commitlint/cli** added support for TypeScript-based configurations via `ts-node`, and that has caused a good deal of grief: https://github.com/conventional-changelog/commitlint/issues/3420 https://github.com/conventional-changelog/commitlint/pull/3351 https://github.com/conventional-changelog/commitlint/issues/3218 https://github.com/conventional-changelog/commitlint/issues/3256 https://github.com/hoverinc/web-react/pull/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. --- .../__tests__/__snapshots__/commit-msg.js.snap | 12 ++++++------ src/scripts/commit-msg.js | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/scripts/__tests__/__snapshots__/commit-msg.js.snap b/src/scripts/__tests__/__snapshots__/commit-msg.js.snap index 53b0029d..fc8f185d 100644 --- a/src/scripts/__tests__/__snapshots__/commit-msg.js.snap +++ b/src/scripts/__tests__/__snapshots__/commit-msg.js.snap @@ -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`; diff --git a/src/scripts/commit-msg.js b/src/scripts/commit-msg.js index 2558f6ee..9b027fe2 100644 --- a/src/scripts/commit-msg.js +++ b/src/scripts/commit-msg.js @@ -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',