Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment Feature]: TypeScript config files support - Node.js v22 #192

Closed
2 tasks done
Mister-Hope opened this issue Oct 12, 2024 · 8 comments
Closed
2 tasks done
Assignees
Labels
enhancement New feature or request

Comments

@Mister-Hope
Copy link

βœ… Checklist

  • I am using the latest version
  • I have searched FAQ

πŸ“„ System Info

not needed

πŸ”Ž Description

See https://commitlint.js.org/reference/configuration.html

So https://cz-git.qbb.sh/config/#typescript-template should be fixed

πŸ”— Reproduction link / repo:

No response

@Mister-Hope Mister-Hope added the bug Something isn't working label Oct 12, 2024
@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Oct 12, 2024

commitlint Replace ts-node with cosmiconfig-typescript-loader package conventional-changelog/commitlint#3722

Although the speed has improved, The cosmiconfig-typescript-loader package added ,cz-git and czg will double the size, and I am still considering it. πŸ˜Άβ€πŸŒ«οΈ
This makes me wonder the TypeScript support is important. If it's just type support, the issue #193 also can do this

image

@Mister-Hope
Copy link
Author

  1. commitlint.config.ts is supported by commitlint directly, so the docs need to be corrected, there is nothing to do with your pacakge
  2. Even if you want to have cz.config.ts supported, you should externalize cosmiconfig-typescript-loader, tools like rollup and tsup can do that easily

@Mister-Hope
Copy link
Author

Mister-Hope commented Oct 12, 2024

Besides, I think you have misunderstood my original issue complaining about the deps number.

Since your package is strongly relying on commitlint, so you should try to reuse package that is required by it as much as possible while keeping the same major, this way you can externalize them safely as they are supposed to be installed to workspace anyway. (e.g.: cosmiconfig-typescript-loader)

The main target for tool package like this is trying to avoid requiring any new package that is heavy. A package is heavy means that it has too many deps or a lot of unused features for your usage. You can try to bundle packages with cz-git, only if they:

  • are large, treeshakable and unpopular, so you can greatly reduce code size by bundling them

@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Oct 12, 2024

Thank you for your reply.

  1. However, I don't understand with my documentation not supporting commitlint.config.ts Please feel free to point it out.

Since your package is strongly relying on commitlint, so you should try to reuse package

  1. Like @commitlint/load package have too many dep package.json. I have try but cjs project treeshakable effect is not well
  2. Although I don't agree that a lightweight CLI tool, which requires the fastest startup speed (Include npx bunx usage), should resolve the ts configuration file at this time, I will keep an open opinion and will not add it in the short term.

@Mister-Hope
Copy link
Author

However, I don't understand with my documentation not supporting commitlint.config.ts Please feel free to point it out.

image
image

No offense, but as I am pointing out the link in issue body, it should not be hard to find these.

Zhengqbbb added a commit that referenced this issue Oct 12, 2024
@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Oct 12, 2024

Done
Btw, I will try to configure loading for TypeScript using node > 22 LTS (2024-10-29), instead of adding extra dependencies.

@Zhengqbbb Zhengqbbb added enhancement New feature or request and removed bug Something isn't working labels Oct 12, 2024
@Zhengqbbb Zhengqbbb changed the title [Bug report] Typescript config files are still supported upstream by commitlint Typescript config files support Oct 12, 2024
@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Nov 1, 2024

Hi there.
Node.js LTS v22 has been released, and in v1.11.0, I will add the loading of ESM configuration and TS configuration.
Regarding the loading of TS configuration, it is using the native Node loading method, but it is currently an experimental feature that requires additional environment injection.
Recommended to first use the ESM JS method for transition.

Docs preview: https://deploy-preview-197--cz-git.netlify.app/


I have released a next pre-release version 🌟(v1.11.0-beta.1)🌟 for testing.
I expect to officially release v1.11.0 next weekend.
Welcome to try it out! πŸ‘€ Let me know if there are still any issues. πŸŽ‰


I am testing in the repository https://github.com/vuepress-theme-hope/vuepress-theme-hope

Suggestion (ESM js)

  1. rename commitlint.config.ts => commitlint.config.js
import { execSync } from "node:child_process";
import { readdirSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

import { defineConfig } from "cz-git";

const packages = readdirSync(
  join(dirname(fileURLToPath(import.meta.url)), "./packages/"),
);

const scopeComplete = execSync("git status --porcelain || true")
  .toString()
  .trim()
  .split("\n")
  .find((r) => ~r.indexOf("M  packages"))
  ?.replace(/\//g, "%%")
  ?.match(/packages%%((\w|-)*)/)?.[1];

export default defineConfig({
  extends: ["@commitlint/config-conventional"],
  rules: {
    "scope-enum": [2, "always", ["demo", "release", ...packages]],
  },
  prompt: {
    defaultScope: scopeComplete,
    customScopesAlign: !scopeComplete ? "top" : "bottom",
    allowCustomIssuePrefix: false,
    allowEmptyIssuePrefix: false,
  },
});

CleanShot 2024-11-01 at 21 51 25@2x

(TypeScript configure)

-     "commit": "pnpm git-cz",
+     "commit": "cross-env NODE_OPTIONS=\"--experimental-transform-types --disable-warning ExperimentalWarning\" pnpm git-cz",

CleanShot 2024-11-01 at 21 53 34@2x

@Zhengqbbb Zhengqbbb changed the title Typescript config files support [Experiment Feature]: TypeScript config files support - Node.js v22 Nov 1, 2024
@Zhengqbbb
Copy link
Owner

The latest version 🌟(v1.11.0)🌟 released and can use Node v22 to loading ts configure, But it is recommended to use ESM js configure as a transition for the future TypeScript configuration file, and switch to it after Node.js runs TypeScript stably.

Docs Link: https://cz-git.qbb.sh/config/#typescript-template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants