@secret-momo/toolchain-config 0.0.0-stage → 0.0.1

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 secretmomo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # @secret-momo/toolchain-config
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 跨项目共享 TypeScript、ESLint、Prettier 和 Stylelint 配置。按需安装工具,再从项目现有配置引用相应预设。路径别名、输出目录、文件范围和项目特有规则在项目里设置。
4
+
5
+ ```bash
6
+ pnpm add -D @secret-momo/toolchain-config
7
+ ```
8
+
9
+ 需要 Node.js 26+。按使用的入口安装对应的工具。
10
+
11
+ | 工具 | 版本范围 |
12
+ | ---------- | ---------- |
13
+ | TypeScript | `~6.0.3` |
14
+ | ESLint | `^10.15.0` |
15
+ | Prettier | `^3.10.1` |
16
+ | Stylelint | `^18.0.0` |
17
+
18
+ ## TypeScript
19
+
20
+ 在项目的 `tsconfig.json` 中引用预设。以下是一个 Node.js 项目的例子,`types` 中的 `node` 需要项目安装 `@types/node`。
21
+
22
+ ```json
23
+ {
24
+ "extends": "@secret-momo/toolchain-config/tsconfig/node.json",
25
+ "compilerOptions": {
26
+ "target": "ES2022",
27
+ "lib": ["ES2022"],
28
+ "types": ["node"],
29
+ "noEmit": true
30
+ },
31
+ "include": ["src"]
32
+ }
33
+ ```
34
+
35
+ | 入口 | 内容 |
36
+ | ----------------------- | ------------------------------------------ |
37
+ | `tsconfig/base.json` | 通用严格检查和模块语法 |
38
+ | `tsconfig/node.json` | 基础配置加 NodeNext 模块及解析策略 |
39
+ | `tsconfig/browser.json` | 基础配置加 ES2023、DOM 类型和 Bundler 解析 |
40
+ | `tsconfig/react.json` | 浏览器配置加 `react-jsx` |
41
+
42
+ ## ESLint
43
+
44
+ 在 `eslint.config.mjs` 中组合规则和运行环境。将配置文件所在项目的绝对路径传给 `base`,让类型感知规则查找消费项目的 TSConfig。`internalImportPattern` 可用于识别项目内部导入。
45
+
46
+ ```js
47
+ import { defineConfig, globalIgnores } from 'eslint/config';
48
+
49
+ import base from '@secret-momo/toolchain-config/eslint/base';
50
+ import browser from '@secret-momo/toolchain-config/eslint/browser';
51
+ import node from '@secret-momo/toolchain-config/eslint/node';
52
+ import react from '@secret-momo/toolchain-config/eslint/react';
53
+
54
+ export default defineConfig(globalIgnores(['**/dist/**']), base({ tsconfigRootDir: import.meta.dirname, internalImportPattern: '^@example/' }), { files: ['apps/server/**', '**/*.config.mjs'], extends: [node] }, { files: ['apps/web/src/**'], extends: [browser, react] });
55
+ ```
56
+
57
+ 纯 Node.js 项目可以直接把 `node` 传给 `defineConfig`。普通浏览器项目使用 `browser`,React 项目额外叠加 `react` 启用 JSX 和 React Hooks 规则。共享包提供预设所需的插件。
58
+
59
+ ## Prettier
60
+
61
+ 在项目的 `package.json` 中引用共享配置。
62
+
63
+ ```json
64
+ {
65
+ "prettier": "@secret-momo/toolchain-config/prettier"
66
+ }
67
+ ```
68
+
69
+ 需要覆盖时,可以在 `prettier.config.mjs` 中导入该入口,展开配置并追加本地选项。追加 `overrides` 时一并展开共享配置的 `overrides`,即可保留 JSONC 的尾逗号设置。
70
+
71
+ ## Stylelint
72
+
73
+ 在 `stylelint.config.mjs` 中继承 CSS 预设,可用于普通 CSS 和 `.module.css` 文件。
74
+
75
+ ```js
76
+ export default {
77
+ extends: ['@secret-momo/toolchain-config/stylelint/css'],
78
+ };
79
+ ```
80
+
81
+ 项目可以继续配置扫描范围、忽略路径和设计变量规则。
@@ -0,0 +1,8 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ export interface BaseOptions {
4
+ tsconfigRootDir: string;
5
+ internalImportPattern?: string;
6
+ }
7
+
8
+ export default function base(options: BaseOptions): Linter.Config[];
@@ -0,0 +1,65 @@
1
+ import js from '@eslint/js';
2
+ import { defineConfig } from 'eslint/config';
3
+ import prettier from 'eslint-config-prettier/flat';
4
+ import { importX } from 'eslint-plugin-import-x';
5
+ import unusedImports from 'eslint-plugin-unused-imports';
6
+ import tseslint from 'typescript-eslint';
7
+
8
+ import { javascriptFiles, sourceFiles, typescriptFiles } from './files.mjs';
9
+
10
+ /**
11
+ * @param {{ tsconfigRootDir: string, internalImportPattern?: string }} options
12
+ * @returns {import('eslint').Linter.Config[]}
13
+ */
14
+ export default function base({ tsconfigRootDir, internalImportPattern }) {
15
+ return defineConfig(
16
+ {
17
+ files: javascriptFiles,
18
+ extends: [js.configs.recommended],
19
+ },
20
+ {
21
+ files: typescriptFiles,
22
+ extends: [js.configs.recommended, tseslint.configs.recommended],
23
+ languageOptions: { parserOptions: { projectService: true, tsconfigRootDir } },
24
+ rules: {
25
+ '@typescript-eslint/consistent-type-imports': [
26
+ 'error',
27
+ { fixStyle: 'inline-type-imports' },
28
+ ],
29
+ '@typescript-eslint/no-deprecated': 'error',
30
+ '@typescript-eslint/no-floating-promises': 'error',
31
+ '@typescript-eslint/no-misused-promises': 'error',
32
+ },
33
+ },
34
+ {
35
+ files: sourceFiles,
36
+ plugins: { 'import-x': importX, 'unused-imports': unusedImports },
37
+ settings:
38
+ internalImportPattern === undefined
39
+ ? {}
40
+ : { 'import-x/internal-regex': internalImportPattern },
41
+ rules: {
42
+ 'no-unused-vars': 'off',
43
+ '@typescript-eslint/no-unused-vars': 'off',
44
+ 'unused-imports/no-unused-imports': 'error',
45
+ 'unused-imports/no-unused-vars': [
46
+ 'error',
47
+ {
48
+ args: 'after-used',
49
+ argsIgnorePattern: '^_',
50
+ varsIgnorePattern: '^_',
51
+ caughtErrorsIgnorePattern: '^_',
52
+ },
53
+ ],
54
+ 'import-x/order': [
55
+ 'error',
56
+ {
57
+ groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index']],
58
+ 'newlines-between': 'always',
59
+ },
60
+ ],
61
+ },
62
+ },
63
+ prettier,
64
+ );
65
+ }
@@ -0,0 +1,4 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ declare const config: Linter.Config;
4
+ export default config;
@@ -0,0 +1,11 @@
1
+ import globals from 'globals';
2
+
3
+ import { sourceFiles } from './files.mjs';
4
+
5
+ /** @type {import('eslint').Linter.Config} */
6
+ const config = {
7
+ files: sourceFiles,
8
+ languageOptions: { globals: globals.browser },
9
+ };
10
+
11
+ export default config;
@@ -0,0 +1,3 @@
1
+ export const javascriptFiles = ['**/*.{js,mjs,cjs,jsx}'];
2
+ export const typescriptFiles = ['**/*.{ts,tsx,mts,cts}'];
3
+ export const sourceFiles = ['**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}'];
@@ -0,0 +1,4 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ declare const config: Linter.Config;
4
+ export default config;
@@ -0,0 +1,11 @@
1
+ import globals from 'globals';
2
+
3
+ import { sourceFiles } from './files.mjs';
4
+
5
+ /** @type {import('eslint').Linter.Config} */
6
+ const config = {
7
+ files: sourceFiles,
8
+ languageOptions: { globals: globals.node },
9
+ };
10
+
11
+ export default config;
@@ -0,0 +1,4 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ declare const config: Linter.Config[];
4
+ export default config;
@@ -0,0 +1,19 @@
1
+ import reactHooks from 'eslint-plugin-react-hooks';
2
+
3
+ import { javascriptFiles, sourceFiles } from './files.mjs';
4
+
5
+ /** @type {import('eslint').Linter.Config[]} */
6
+ const config = [
7
+ {
8
+ files: javascriptFiles,
9
+ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
10
+ },
11
+ {
12
+ files: sourceFiles,
13
+ // 这里只注册规则,保留调用方对 React 文件范围的控制。
14
+ plugins: { 'react-hooks': { meta: reactHooks.meta, rules: reactHooks.rules } },
15
+ rules: reactHooks.configs.recommended.rules,
16
+ },
17
+ ];
18
+
19
+ export default config;
package/package.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
2
  "name": "@secret-momo/toolchain-config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "description": "跨项目共享的 TypeScript、ESLint、Prettier 和 Stylelint 配置。",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/secretmomo/npm-packages.git",
10
+ "directory": "packages/toolchain-config"
11
+ },
12
+ "exports": {
13
+ "./tsconfig/base.json": "./tsconfig/base.json",
14
+ "./tsconfig/node.json": "./tsconfig/node.json",
15
+ "./tsconfig/browser.json": "./tsconfig/browser.json",
16
+ "./tsconfig/react.json": "./tsconfig/react.json",
17
+ "./eslint/base": "./eslint/base.mjs",
18
+ "./eslint/node": "./eslint/node.mjs",
19
+ "./eslint/browser": "./eslint/browser.mjs",
20
+ "./eslint/react": "./eslint/react.mjs",
21
+ "./prettier": "./prettier/index.mjs",
22
+ "./stylelint/css": "./stylelint/css.mjs"
23
+ },
24
+ "files": [
25
+ "eslint",
26
+ "prettier",
27
+ "stylelint",
28
+ "tsconfig"
29
+ ],
30
+ "engines": {
31
+ "node": ">=26"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "registry": "https://registry.npmjs.org/"
36
+ },
37
+ "dependencies": {
38
+ "@eslint/js": "10.0.1",
39
+ "@typescript-eslint/eslint-plugin": "8.73.0",
40
+ "eslint-config-prettier": "10.1.8",
41
+ "eslint-plugin-import-x": "4.18.1",
42
+ "eslint-plugin-react-hooks": "7.1.1",
43
+ "eslint-plugin-unused-imports": "4.4.1",
44
+ "globals": "17.14.0",
45
+ "stylelint-config-standard": "41.0.0",
46
+ "typescript-eslint": "8.73.0"
47
+ },
48
+ "peerDependencies": {
49
+ "eslint": "^10.15.0",
50
+ "prettier": "^3.10.1",
51
+ "stylelint": "^18.0.0",
52
+ "typescript": "~6.0.3"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "eslint": {
56
+ "optional": true
57
+ },
58
+ "prettier": {
59
+ "optional": true
60
+ },
61
+ "stylelint": {
62
+ "optional": true
63
+ },
64
+ "typescript": {
65
+ "optional": true
66
+ }
67
+ },
68
+ "devDependencies": {
69
+ "eslint": "10.15.0",
70
+ "prettier": "3.10.1",
71
+ "stylelint": "18.0.0",
72
+ "typescript": "6.0.3"
73
+ },
74
+ "scripts": {
75
+ "typecheck": "tsc -p tsconfig.json"
76
+ }
6
77
  }
@@ -0,0 +1,4 @@
1
+ import type { Config } from 'prettier';
2
+
3
+ declare const config: Config;
4
+ export default config;
@@ -0,0 +1,9 @@
1
+ /** @type {import('prettier').Config} */
2
+ const config = {
3
+ singleQuote: true,
4
+ trailingComma: 'all',
5
+ printWidth: 100,
6
+ overrides: [{ files: '*.jsonc', options: { trailingComma: 'none' } }],
7
+ };
8
+
9
+ export default config;
@@ -0,0 +1,4 @@
1
+ import type { Config } from 'stylelint';
2
+
3
+ declare const config: Config;
4
+ export default config;
@@ -0,0 +1,6 @@
1
+ /** @type {import('stylelint').Config} */
2
+ const config = {
3
+ extends: ['stylelint-config-standard'],
4
+ };
5
+
6
+ export default config;
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "noFallthroughCasesInSwitch": true,
5
+ "noUnusedLocals": true,
6
+ "noUnusedParameters": true,
7
+ "verbatimModuleSyntax": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "skipLibCheck": true
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./base.json",
3
+ "compilerOptions": {
4
+ "lib": ["ES2023", "DOM", "DOM.Iterable"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler"
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./base.json",
3
+ "compilerOptions": {
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext"
6
+ }
7
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "./browser.json",
3
+ "compilerOptions": {
4
+ "jsx": "react-jsx"
5
+ }
6
+ }