@farris/cli 2.3.7 → 2.3.9
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/lib/commands/add-app.js +5 -5
- package/lib/commands/add-app.js.map +1 -1
- package/lib/commands/add-lib.js +5 -5
- package/lib/commands/add-lib.js.map +1 -1
- package/lib/commands/add-micro.js +12 -0
- package/lib/commands/add-micro.js.map +1 -0
- package/lib/commands/add-project.js +196 -194
- package/lib/commands/add-project.js.map +1 -1
- package/lib/commands/build-components.js +60 -60
- package/lib/commands/build-components.js.map +1 -1
- package/lib/commands/build-css.js +38 -38
- package/lib/commands/build-css.js.map +1 -1
- package/lib/commands/build-lib.js +30 -30
- package/lib/commands/build-lib.js.map +1 -1
- package/lib/commands/build.js +19 -19
- package/lib/commands/build.js.map +1 -1
- package/lib/commands/create-app-options.js +85 -74
- package/lib/commands/create-app-options.js.map +1 -1
- package/lib/commands/create-app.js +131 -131
- package/lib/commands/create-app.js.map +1 -1
- package/lib/commands/create-options.js +58 -32
- package/lib/commands/create-options.js.map +1 -1
- package/lib/commands/create.js +341 -331
- package/lib/commands/create.js.map +1 -1
- package/lib/commands/dev-serve.js +18 -18
- package/lib/commands/extract-i18n.js +74 -74
- package/lib/commands/extract-i18n.js.map +1 -1
- package/lib/commands/generate/api.js +124 -124
- package/lib/commands/generate/api.js.map +1 -1
- package/lib/commands/generate/common.js +101 -101
- package/lib/commands/generate/common.js.map +1 -1
- package/lib/commands/generate/component.js +156 -156
- package/lib/commands/generate/component.js.map +1 -1
- package/lib/commands/generate/view.js +168 -168
- package/lib/commands/generate/view.js.map +1 -1
- package/lib/commands/preview-serve.js +16 -16
- package/lib/commands/workspace/add-app.js +15 -15
- package/lib/commands/workspace/add-app.js.map +1 -1
- package/lib/commands/workspace/create.js +62 -62
- package/lib/commands/workspace/create.js.map +1 -1
- package/lib/commands/workspace/inspect.js +30 -30
- package/lib/commands/workspace/inspect.js.map +1 -1
- package/lib/commands/workspace/verify.js +38 -38
- package/lib/commands/workspace/verify.js.map +1 -1
- package/lib/common/agents-doc.js +33 -33
- package/lib/common/agents-doc.js.map +1 -1
- package/lib/common/apply-catalog-deps.js +15 -15
- package/lib/common/apply-catalog-deps.js.map +1 -1
- package/lib/common/component-file-name.js +3 -3
- package/lib/common/constant.js +85 -84
- package/lib/common/constant.js.map +1 -1
- package/lib/common/create-app-target.js +46 -46
- package/lib/common/create-app-target.js.map +1 -1
- package/lib/common/generate-app.js +106 -109
- package/lib/common/generate-app.js.map +1 -1
- package/lib/common/get-dependencies.js +9 -9
- package/lib/common/get-farris-config.js +25 -25
- package/lib/common/get-farris-config.js.map +1 -1
- package/lib/common/get-version.js +6 -6
- package/lib/common/get-vite-config.js +192 -192
- package/lib/common/get-vite-config.js.map +1 -1
- package/lib/common/lib-package-exports.js +24 -24
- package/lib/common/lib-package-exports.js.map +1 -1
- package/lib/common/list-lib-components.js +23 -23
- package/lib/common/list-lib-components.js.map +1 -1
- package/lib/common/output.js +164 -164
- package/lib/common/output.js.map +1 -1
- package/lib/common/project-layout.js +155 -183
- package/lib/common/project-layout.js.map +1 -1
- package/lib/common/safety.js +172 -173
- package/lib/common/safety.js.map +1 -1
- package/lib/common/template-manifest.js +18 -14
- package/lib/common/template-manifest.js.map +1 -1
- package/lib/common/template-renderer.js +114 -114
- package/lib/common/template-renderer.js.map +1 -1
- package/lib/common/transaction.js +83 -83
- package/lib/common/transaction.js.map +1 -1
- package/lib/common/verifier.js +187 -201
- package/lib/common/verifier.js.map +1 -1
- package/lib/common/workspace-contract.js +191 -157
- package/lib/common/workspace-contract.js.map +1 -1
- package/lib/config/vite-app.js +13 -13
- package/lib/config/vite-common.js +20 -20
- package/lib/config/vite-common.js.map +1 -1
- package/lib/config/vite-component.js +32 -32
- package/lib/config/vite-component.js.map +1 -1
- package/lib/config/vite-lib.js +26 -26
- package/lib/config/vite-lib.js.map +1 -1
- package/lib/index.js +261 -238
- package/lib/index.js.map +1 -1
- package/lib/plugins/create-app-package-json.js +23 -23
- package/lib/plugins/create-component-style.js +44 -44
- package/lib/plugins/create-package-json.js +48 -48
- package/lib/plugins/create-package-json.js.map +1 -1
- package/lib/plugins/dts.js +8 -8
- package/lib/plugins/html-system.js +9 -9
- package/lib/plugins/mock.js +240 -292
- package/lib/plugins/mock.js.map +1 -1
- package/lib/plugins/msw-adapter.js +141 -0
- package/lib/plugins/msw-adapter.js.map +1 -0
- package/lib/plugins/replace.js +17 -17
- package/lib/plugins/systemjs-bundle.js +15 -15
- package/lib/plugins/systemjs-bundle.js.map +1 -1
- package/package.json +6 -1
- package/templates/create/.gitignore.tpl +28 -8
- package/templates/create/AGENTS.md +76 -45
- package/templates/create/README.md +44 -11
- package/templates/create/package.json +2 -1
- package/templates/lib/.gitignore.tpl +31 -1
- package/templates/lib/.gitlab-ci.yml +2 -2
- package/templates/lib/README.md +24 -1
- package/templates/lib/{test → components/__tests__}/index.spec.ts +1 -1
- package/templates/lib/{test → components/__tests__}/index.spec.tsx +2 -2
- package/templates/lib/farris.config.mjs +2 -2
- package/templates/lib/package.json +1 -1
- package/templates/lib/tsconfig.json +1 -2
- package/templates/lib/vitest.config.ts +4 -2
- package/templates/micro/.eslintrc.cjs +15 -0
- package/templates/micro/.gitignore.tpl +33 -0
- package/templates/micro/.gitlab-ci.yml +59 -0
- package/templates/micro/.prettierrc.json +8 -0
- package/templates/micro/farris.config.mjs +34 -0
- package/templates/micro/index.html +12 -0
- package/templates/micro/mock/README.md +53 -0
- package/templates/micro/mock/tsconfig.json +10 -0
- package/templates/micro/package.json +47 -0
- package/templates/micro/src/App.tsx +25 -0
- package/templates/micro/src/locales/index.ts +5 -0
- package/templates/micro/src/locales/zh-CHS.json +1 -0
- package/templates/micro/src/main.ts +47 -0
- package/templates/micro/src/router/index.ts +24 -0
- package/templates/micro/src/views/AboutView.tsx +12 -0
- package/templates/micro/src/views/HomeView.tsx +13 -0
- package/templates/micro/src/views/__tests__/AboutView.spec.tsx +11 -0
- package/templates/micro/src/views/__tests__/HomeView.spec.tsx +11 -0
- package/templates/micro/tsconfig.json +18 -0
- package/templates/micro/vitest.config.ts +12 -0
- package/templates/mobile/.gitignore.tpl +25 -24
- package/templates/mobile/farris.config.mjs +2 -2
- package/templates/mobile/mock/README.md +39 -20
- package/templates/mobile/mock/tsconfig.json +10 -0
- package/templates/mobile/package.json +5 -2
- package/templates/mobile/src/main.ts +5 -40
- package/templates/mobile/src/views/HomeView.tsx +2 -2
- package/templates/mobile/src/views/__tests__/AboutView.spec.tsx +11 -0
- package/templates/mobile/src/views/__tests__/HomeView.spec.tsx +11 -0
- package/templates/mobile/tsconfig.json +1 -2
- package/templates/mobile/vitest.config.ts +4 -2
- package/templates/web/.gitignore.tpl +25 -24
- package/templates/web/farris.config.mjs +2 -2
- package/templates/web/mock/README.md +39 -20
- package/templates/web/mock/tsconfig.json +10 -0
- package/templates/web/package.json +5 -2
- package/templates/web/src/App.tsx +0 -4
- package/templates/web/src/main.ts +5 -40
- package/templates/web/src/views/HomeView.tsx +2 -2
- package/templates/web/src/views/__tests__/AboutView.spec.tsx +11 -0
- package/templates/web/src/views/__tests__/HomeView.spec.tsx +11 -0
- package/templates/web/tsconfig.json +1 -2
- package/templates/web/vitest.config.ts +4 -2
- package/templates/mobile/src/components/TheButton.tsx +0 -9
- package/templates/mobile/test/src/components/TheButton.spec.ts +0 -15
- package/templates/mobile/test/src/components/TheButton.spec.tsx +0 -15
- package/templates/web/src/components/TheButton.tsx +0 -9
- package/templates/web/src/micro-app.d.ts +0 -20
- package/templates/web/src/styles/index.css +0 -0
- package/templates/web/test/src/components/TheButton.spec.ts +0 -15
- package/templates/web/test/src/components/TheButton.spec.tsx +0 -15
- /package/templates/{web → micro}/src/micro/context.ts +0 -0
- /package/templates/{mobile → micro}/src/micro-app.d.ts +0 -0
- /package/templates/{mobile/src/styles/index.css → micro/src/styles/index.scss} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-renderer.js","sourceRoot":"","sources":["../../src/common/template-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAW,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAe7D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe,EAAE,SAA8B;IAClF,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,GAAG,QAAQ,EAAE,GAAG,CAAC,CAAC;QACtD,IAAI,QAAQ,GAAG,EAAE,CAAC;QAClB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"template-renderer.js","sourceRoot":"","sources":["../../src/common/template-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAW,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAe7D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe,EAAE,SAA8B;IAClF,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,GAAG,QAAQ,EAAE,GAAG,CAAC,C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AO,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1D,CAAC;gBAED,aAAa,CAAC,cAAc,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBACjD,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAE3B,OAAO;QACL,YAAY;QACZ,sBAAsB,EAAE,UAAU;KACnC,CAAC;AACJ,CAAC"}
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync, unlinkSync, rmdirSync, readdirSync } from 'node:fs';
|
|
2
|
-
export class Transaction {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.createdFiles = new Set();
|
|
5
|
-
this.modifiedFiles = new Map(); // path -> original content
|
|
6
|
-
this.createdDirs = new Set();
|
|
7
|
-
this.committed = false;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* 记录新建目录
|
|
11
|
-
*/
|
|
12
|
-
recordCreatedDir(dirPath) {
|
|
13
|
-
if (!this.createdDirs.has(dirPath)) {
|
|
14
|
-
this.createdDirs.add(dirPath);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 记录即将写入/修改的文件
|
|
19
|
-
*/
|
|
20
|
-
prepareWrite(filePath) {
|
|
21
|
-
if (this.createdFiles.has(filePath) || this.modifiedFiles.has(filePath)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (existsSync(filePath)) {
|
|
25
|
-
const original = readFileSync(filePath, 'utf-8');
|
|
26
|
-
this.modifiedFiles.set(filePath, original);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
this.createdFiles.add(filePath);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 提交事务
|
|
34
|
-
*/
|
|
35
|
-
commit() {
|
|
36
|
-
this.committed = true;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* 回滚事务
|
|
40
|
-
*/
|
|
41
|
-
rollback() {
|
|
42
|
-
if (this.committed) {
|
|
43
|
-
return { rolledBackFiles: [], errors: [] };
|
|
44
|
-
}
|
|
45
|
-
const rolledBackFiles = [];
|
|
46
|
-
const errors = [];
|
|
47
|
-
// 恢复修改的文件
|
|
48
|
-
for (const [filePath, originalContent] of this.modifiedFiles.entries()) {
|
|
49
|
-
try {
|
|
50
|
-
writeFileSync(filePath, originalContent, 'utf-8');
|
|
51
|
-
rolledBackFiles.push(filePath);
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
errors.push(`恢复文件失败: ${filePath}, 原因: ${err.message}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// 删除新建的文件
|
|
58
|
-
for (const filePath of this.createdFiles) {
|
|
59
|
-
try {
|
|
60
|
-
if (existsSync(filePath)) {
|
|
61
|
-
unlinkSync(filePath);
|
|
62
|
-
rolledBackFiles.push(filePath);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
errors.push(`删除新建文件失败: ${filePath}, 原因: ${err.message}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// 尝试清理新建的空目录(由深到浅排序)
|
|
70
|
-
const sortedDirs = Array.from(this.createdDirs).sort((a, b) => b.length - a.length);
|
|
71
|
-
for (const dir of sortedDirs) {
|
|
72
|
-
try {
|
|
73
|
-
if (existsSync(dir) && readdirSync(dir).length === 0) {
|
|
74
|
-
rmdirSync(dir);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
// 忽略非空目录清理异常
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return { rolledBackFiles, errors };
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, unlinkSync, rmdirSync, readdirSync } from 'node:fs';
|
|
2
|
+
export class Transaction {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.createdFiles = new Set();
|
|
5
|
+
this.modifiedFiles = new Map(); // path -> original content
|
|
6
|
+
this.createdDirs = new Set();
|
|
7
|
+
this.committed = false;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 记录新建目录
|
|
11
|
+
*/
|
|
12
|
+
recordCreatedDir(dirPath) {
|
|
13
|
+
if (!this.createdDirs.has(dirPath)) {
|
|
14
|
+
this.createdDirs.add(dirPath);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 记录即将写入/修改的文件
|
|
19
|
+
*/
|
|
20
|
+
prepareWrite(filePath) {
|
|
21
|
+
if (this.createdFiles.has(filePath) || this.modifiedFiles.has(filePath)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (existsSync(filePath)) {
|
|
25
|
+
const original = readFileSync(filePath, 'utf-8');
|
|
26
|
+
this.modifiedFiles.set(filePath, original);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.createdFiles.add(filePath);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 提交事务
|
|
34
|
+
*/
|
|
35
|
+
commit() {
|
|
36
|
+
this.committed = true;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 回滚事务
|
|
40
|
+
*/
|
|
41
|
+
rollback() {
|
|
42
|
+
if (this.committed) {
|
|
43
|
+
return { rolledBackFiles: [], errors: [] };
|
|
44
|
+
}
|
|
45
|
+
const rolledBackFiles = [];
|
|
46
|
+
const errors = [];
|
|
47
|
+
// 恢复修改的文件
|
|
48
|
+
for (const [filePath, originalContent] of this.modifiedFiles.entries()) {
|
|
49
|
+
try {
|
|
50
|
+
writeFileSync(filePath, originalContent, 'utf-8');
|
|
51
|
+
rolledBackFiles.push(filePath);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
errors.push(`恢复文件失败: ${filePath}, 原因: ${err.message}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// 删除新建的文件
|
|
58
|
+
for (const filePath of this.createdFiles) {
|
|
59
|
+
try {
|
|
60
|
+
if (existsSync(filePath)) {
|
|
61
|
+
unlinkSync(filePath);
|
|
62
|
+
rolledBackFiles.push(filePath);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
errors.push(`删除新建文件失败: ${filePath}, 原因: ${err.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// 尝试清理新建的空目录(由深到浅排序)
|
|
70
|
+
const sortedDirs = Array.from(this.createdDirs).sort((a, b) => b.length - a.length);
|
|
71
|
+
for (const dir of sortedDirs) {
|
|
72
|
+
try {
|
|
73
|
+
if (existsSync(dir) && readdirSync(dir).length === 0) {
|
|
74
|
+
rmdirSync(dir);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// 忽略非空目录清理异常
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { rolledBackFiles, errors };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
84
|
//# sourceMappingURL=transaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/common/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAQtG,MAAM,OAAO,WAAW;IAAxB;QACU,iBAAY,GAAgB,IAAI,GAAG,EAAE,CAAC;QACtC,kBAAa,GAAwB,IAAI,GAAG,EAAE,CAAC,CAAC,2BAA2B;QAC3E,gBAAW,GAAgB,IAAI,GAAG,EAAE,CAAC;QACrC,cAAS,GAAY,KAAK,CAAC;IAiFrC,CAAC;IA/EC;;OAEG;I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C,MAAM,CAAC,CAAC;QACpF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACrD,SAAS,CAAC,GAAG,CAAC,CAAC;gBACjB,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,aAAa;YACf,CAAC;QACH,CAAC;QAED,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;CACF"}
|
package/lib/common/verifier.js
CHANGED
|
@@ -1,202 +1,188 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { resolve, join, relative } from 'node:path';
|
|
3
|
-
import { findUnreplacedPlaceholders } from './template-renderer.js';
|
|
4
|
-
import {
|
|
5
|
-
import { CLI_COMMAND_REGISTRY, FORBIDDEN_ROOT_SCRIPTS, ROOT_SCRIPT_CONTRACT, expectedRootScriptValue } from './workspace-contract.js';
|
|
6
|
-
/** 任何布局都必须存在的根脚本。 */
|
|
7
|
-
const REQUIRED_ROOT_SCRIPTS = ['build', 'typecheck'];
|
|
8
|
-
/** 工程类型全集。容器命名一律经
|
|
9
|
-
const CONTAINER_TYPES = ['app', 'lib'];
|
|
10
|
-
function readJson(filePath) {
|
|
11
|
-
try {
|
|
12
|
-
return JSON.parse(readFileSync(filePath, 'utf-8'));
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function verifyAppProject(project, projectPath, pkg, label, addCheck) {
|
|
19
|
-
addCheck(`${label}_catalog_deps`, pkg.dependencies?.['@farris/ui-vue'] === 'catalog:', `工程 ${project.dir} 的 @farris/ui-vue 依赖必须使用 catalog: 协议`);
|
|
20
|
-
const indexHtmlPath = join(projectPath, 'index.html');
|
|
21
|
-
if (!existsSync(indexHtmlPath)) {
|
|
22
|
-
addCheck(`${label}_index_html`, false, `工程 ${project.dir} 缺少 index.html`);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const html = readFileSync(indexHtmlPath, 'utf-8');
|
|
26
|
-
const hasCorrectEntry = /<script\s+type="module"\s+src="\/src\/main\.ts">\s*<\/script>/.test(html);
|
|
27
|
-
const hasWrongEntry = /<script\s+type="module"\s+src="\.\/src\/main\.ts">\s*<\/script>/.test(html);
|
|
28
|
-
addCheck(`${label}_html_entry`, hasCorrectEntry && !hasWrongEntry, `工程 ${project.dir} 的 index.html 入口必须为 /src/main.ts,不得写为 ./src/main.ts`);
|
|
29
|
-
}
|
|
30
|
-
addCheck(`${label}_main_ts`, existsSync(join(projectPath, 'src', 'main.ts')), `工程 ${project.dir} 缺少 src/main.ts`);
|
|
31
|
-
const hasAppTsx = existsSync(join(projectPath, 'src', 'App.tsx'));
|
|
32
|
-
const hasAppVue = existsSync(join(projectPath, 'src', 'App.vue'));
|
|
33
|
-
addCheck(`${label}_app_entry`, hasAppTsx || hasAppVue, `工程 ${project.dir} 缺少 src/App.tsx(或历史兼容的 src/App.vue)`);
|
|
34
|
-
const farrisConfigPath = join(projectPath, 'farris.config.mjs');
|
|
35
|
-
const configContent = existsSync(farrisConfigPath) ? readFileSync(farrisConfigPath, 'utf-8') : '';
|
|
36
|
-
const hasRelativeBase = /base\s*:\s*['"]\.\/?['"]/.test(configContent);
|
|
37
|
-
const hasHistoryRouter = /routerMode\s*:\s*['"]history['"]/.test(configContent);
|
|
38
|
-
addCheck(`${label}_base_router_compatibility`, !(hasRelativeBase && hasHistoryRouter), `工程 ${project.dir} 配置冲突: 相对路径 base 与 history 路由模式不可同时使用`);
|
|
39
|
-
}
|
|
40
|
-
function verifyLibProject(project, projectPath, pkg, label, addCheck) {
|
|
41
|
-
addCheck(`${label}_components_entry`, existsSync(join(projectPath, 'components', 'index.ts')), `组件库 ${project.dir} 缺少 components/index.ts(发布物唯一入口)`);
|
|
42
|
-
addCheck(`${label}_files_whitelist`, Array.isArray(pkg.files) && pkg.files.length > 0, `组件库 ${project.dir} 的 package.json 缺少 files 白名单,误执行 npm publish 会把 src/ 推上去`);
|
|
43
|
-
addCheck(`${label}_publish_config`, !!pkg.publishConfig, `组件库 ${project.dir} 的 package.json 缺少 publishConfig`);
|
|
44
|
-
}
|
|
45
|
-
function verifyProject(wsRoot, project, addCheck) {
|
|
46
|
-
const label = `${project.type}_${project.dir.replace(/\//g, '_')}`;
|
|
47
|
-
const projectPath = join(wsRoot, project.dir);
|
|
48
|
-
const pkgPath = join(projectPath, 'package.json');
|
|
49
|
-
const farrisConfigPath = join(projectPath, 'farris.config.mjs');
|
|
50
|
-
const tsconfigPath = join(projectPath, 'tsconfig.json');
|
|
51
|
-
if (!existsSync(pkgPath)) {
|
|
52
|
-
addCheck(`${label}_package_json`, false, `工程 ${project.dir} 缺少 package.json`);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const pkg = readJson(pkgPath);
|
|
56
|
-
if (!pkg) {
|
|
57
|
-
addCheck(`${label}_package_json_valid`, false, `工程 ${project.dir} 的 package.json 解析失败`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
addCheck(`${label}_name`, !!pkg.name, `工程 ${project.dir} 的 package.json 缺少 name 字段`);
|
|
61
|
-
addCheck(`${label}_farris_config`, existsSync(farrisConfigPath), `工程 ${project.dir} 缺少 farris.config.mjs`);
|
|
62
|
-
addCheck(`${label}_tsconfig`, existsSync(tsconfigPath), `工程 ${project.dir} 缺少 tsconfig.json`);
|
|
63
|
-
addCheck(`${label}_typecheck_script`, !!pkg.scripts?.typecheck, `工程 ${project.dir} 缺少 typecheck 脚本,根 pnpm typecheck 会静默跳过它`);
|
|
64
|
-
if (project.type === '
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*/
|
|
84
|
-
export function verifyWorkspace(targetDir, preservedInputs = []) {
|
|
85
|
-
const checks = [];
|
|
86
|
-
const errors = [];
|
|
87
|
-
const addCheck = (name, passed, message) => {
|
|
88
|
-
checks.push({ name, passed, message });
|
|
89
|
-
if (!passed && message) {
|
|
90
|
-
errors.push(message);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const resolvedTarget = resolve(process.cwd(), targetDir);
|
|
94
|
-
if (!existsSync(resolvedTarget)) {
|
|
95
|
-
return {
|
|
96
|
-
ok: false,
|
|
97
|
-
target: resolvedTarget,
|
|
98
|
-
checks: [{ name: 'target_exists', passed: false, message: `目标路径不存在: ${resolvedTarget}` }],
|
|
99
|
-
errors: [`目标路径不存在: ${resolvedTarget}`]
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
addCheck('
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
addCheck('
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
addCheck('claude_pointer_thin', lines.length <= 3 && raw.includes('AGENTS.md'), 'CLAUDE.md 必须是不含规则正文的薄指针(≤ 3 行且包含 AGENTS.md 字样)');
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
// 6. 受保护输入是否依然完好
|
|
192
|
-
for (const entry of preservedInputs) {
|
|
193
|
-
addCheck(`preserved_input_${entry}`, existsSync(join(resolvedTarget, entry)), `受保护输入文件/目录丢失或被覆盖: ${entry}`);
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
ok: errors.length === 0,
|
|
197
|
-
target: resolvedTarget,
|
|
198
|
-
checks,
|
|
199
|
-
errors
|
|
200
|
-
};
|
|
201
|
-
}
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve, join, relative } from 'node:path';
|
|
3
|
+
import { findUnreplacedPlaceholders } from './template-renderer.js';
|
|
4
|
+
import { containerFor, listProjects } from './project-layout.js';
|
|
5
|
+
import { CLI_COMMAND_REGISTRY, FORBIDDEN_ROOT_SCRIPTS, ROOT_SCRIPT_CONTRACT, expectedRootScriptValue } from './workspace-contract.js';
|
|
6
|
+
/** 任何布局都必须存在的根脚本。 */
|
|
7
|
+
const REQUIRED_ROOT_SCRIPTS = ['build', 'typecheck'];
|
|
8
|
+
/** 工程类型全集。容器命名一律经 containerFor 取值。 */
|
|
9
|
+
const CONTAINER_TYPES = ['app', 'lib'];
|
|
10
|
+
function readJson(filePath) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(readFileSync(filePath, 'utf-8'));
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function verifyAppProject(project, projectPath, pkg, label, addCheck) {
|
|
19
|
+
addCheck(`${label}_catalog_deps`, pkg.dependencies?.['@farris/ui-vue'] === 'catalog:', `工程 ${project.dir} 的 @farris/ui-vue 依赖必须使用 catalog: 协议`);
|
|
20
|
+
const indexHtmlPath = join(projectPath, 'index.html');
|
|
21
|
+
if (!existsSync(indexHtmlPath)) {
|
|
22
|
+
addCheck(`${label}_index_html`, false, `工程 ${project.dir} 缺少 index.html`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const html = readFileSync(indexHtmlPath, 'utf-8');
|
|
26
|
+
const hasCorrectEntry = /<script\s+type="module"\s+src="\/src\/main\.ts">\s*<\/script>/.test(html);
|
|
27
|
+
const hasWrongEntry = /<script\s+type="module"\s+src="\.\/src\/main\.ts">\s*<\/script>/.test(html);
|
|
28
|
+
addCheck(`${label}_html_entry`, hasCorrectEntry && !hasWrongEntry, `工程 ${project.dir} 的 index.html 入口必须为 /src/main.ts,不得写为 ./src/main.ts`);
|
|
29
|
+
}
|
|
30
|
+
addCheck(`${label}_main_ts`, existsSync(join(projectPath, 'src', 'main.ts')), `工程 ${project.dir} 缺少 src/main.ts`);
|
|
31
|
+
const hasAppTsx = existsSync(join(projectPath, 'src', 'App.tsx'));
|
|
32
|
+
const hasAppVue = existsSync(join(projectPath, 'src', 'App.vue'));
|
|
33
|
+
addCheck(`${label}_app_entry`, hasAppTsx || hasAppVue, `工程 ${project.dir} 缺少 src/App.tsx(或历史兼容的 src/App.vue)`);
|
|
34
|
+
const farrisConfigPath = join(projectPath, 'farris.config.mjs');
|
|
35
|
+
const configContent = existsSync(farrisConfigPath) ? readFileSync(farrisConfigPath, 'utf-8') : '';
|
|
36
|
+
const hasRelativeBase = /base\s*:\s*['"]\.\/?['"]/.test(configContent);
|
|
37
|
+
const hasHistoryRouter = /routerMode\s*:\s*['"]history['"]/.test(configContent);
|
|
38
|
+
addCheck(`${label}_base_router_compatibility`, !(hasRelativeBase && hasHistoryRouter), `工程 ${project.dir} 配置冲突: 相对路径 base 与 history 路由模式不可同时使用`);
|
|
39
|
+
}
|
|
40
|
+
function verifyLibProject(project, projectPath, pkg, label, addCheck) {
|
|
41
|
+
addCheck(`${label}_components_entry`, existsSync(join(projectPath, 'components', 'index.ts')), `组件库 ${project.dir} 缺少 components/index.ts(发布物唯一入口)`);
|
|
42
|
+
addCheck(`${label}_files_whitelist`, Array.isArray(pkg.files) && pkg.files.length > 0, `组件库 ${project.dir} 的 package.json 缺少 files 白名单,误执行 npm publish 会把 src/ 推上去`);
|
|
43
|
+
addCheck(`${label}_publish_config`, !!pkg.publishConfig, `组件库 ${project.dir} 的 package.json 缺少 publishConfig`);
|
|
44
|
+
}
|
|
45
|
+
function verifyProject(wsRoot, project, addCheck) {
|
|
46
|
+
const label = `${project.type}_${project.dir.replace(/\//g, '_')}`;
|
|
47
|
+
const projectPath = join(wsRoot, project.dir);
|
|
48
|
+
const pkgPath = join(projectPath, 'package.json');
|
|
49
|
+
const farrisConfigPath = join(projectPath, 'farris.config.mjs');
|
|
50
|
+
const tsconfigPath = join(projectPath, 'tsconfig.json');
|
|
51
|
+
if (!existsSync(pkgPath)) {
|
|
52
|
+
addCheck(`${label}_package_json`, false, `工程 ${project.dir} 缺少 package.json`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const pkg = readJson(pkgPath);
|
|
56
|
+
if (!pkg) {
|
|
57
|
+
addCheck(`${label}_package_json_valid`, false, `工程 ${project.dir} 的 package.json 解析失败`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
addCheck(`${label}_name`, !!pkg.name, `工程 ${project.dir} 的 package.json 缺少 name 字段`);
|
|
61
|
+
addCheck(`${label}_farris_config`, existsSync(farrisConfigPath), `工程 ${project.dir} 缺少 farris.config.mjs`);
|
|
62
|
+
addCheck(`${label}_tsconfig`, existsSync(tsconfigPath), `工程 ${project.dir} 缺少 tsconfig.json`);
|
|
63
|
+
addCheck(`${label}_typecheck_script`, !!pkg.scripts?.typecheck, `工程 ${project.dir} 缺少 typecheck 脚本,根 pnpm typecheck 会静默跳过它`);
|
|
64
|
+
if (project.type === 'lib') {
|
|
65
|
+
verifyLibProject(project, projectPath, pkg, label, addCheck);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// app 与 micro 结构一致(micro 的微前端契约由模板守卫保证),都走应用校验
|
|
69
|
+
verifyAppProject(project, projectPath, pkg, label, addCheck);
|
|
70
|
+
}
|
|
71
|
+
for (const file of [pkgPath, farrisConfigPath, tsconfigPath]) {
|
|
72
|
+
if (!existsSync(file)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const unreplaced = findUnreplacedPlaceholders(readFileSync(file, 'utf-8'));
|
|
76
|
+
addCheck(`${label}_placeholders_${relative(wsRoot, file).replace(/\\/g, '/')}`, unreplaced.length === 0, `文件 ${relative(wsRoot, file)} 存在未替换占位符: ${unreplaced.join(', ')}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 校验 Workspace 完整性与规范合规性。
|
|
81
|
+
*
|
|
82
|
+
* 工作空间必须是 app/ + lib/ 分层结构(容器按需创建);旧平铺结构不再支持。
|
|
83
|
+
*/
|
|
84
|
+
export function verifyWorkspace(targetDir, preservedInputs = []) {
|
|
85
|
+
const checks = [];
|
|
86
|
+
const errors = [];
|
|
87
|
+
const addCheck = (name, passed, message) => {
|
|
88
|
+
checks.push({ name, passed, message });
|
|
89
|
+
if (!passed && message) {
|
|
90
|
+
errors.push(message);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const resolvedTarget = resolve(process.cwd(), targetDir);
|
|
94
|
+
if (!existsSync(resolvedTarget)) {
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
target: resolvedTarget,
|
|
98
|
+
checks: [{ name: 'target_exists', passed: false, message: `目标路径不存在: ${resolvedTarget}` }],
|
|
99
|
+
errors: [`目标路径不存在: ${resolvedTarget}`]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// 1. 根 package.json
|
|
103
|
+
const rootPkgPath = join(resolvedTarget, 'package.json');
|
|
104
|
+
if (!existsSync(rootPkgPath)) {
|
|
105
|
+
addCheck('root_package_json', false, '缺少根 package.json');
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const pkg = readJson(rootPkgPath);
|
|
109
|
+
if (!pkg) {
|
|
110
|
+
addCheck('root_package_json_valid', false, '根 package.json 解析失败');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
addCheck('root_package_private', pkg.private === true, '根 package.json 必须声明 "private": true');
|
|
114
|
+
addCheck('root_package_no_name', !pkg.name, '根 package.json 不应设置 name');
|
|
115
|
+
const scripts = (pkg.scripts ?? {});
|
|
116
|
+
const missingRootScripts = REQUIRED_ROOT_SCRIPTS.filter((script) => !scripts[script]);
|
|
117
|
+
addCheck('root_package_scripts', missingRootScripts.length === 0, `根 package.json 缺少必需脚本: ${missingRootScripts.join(', ')}`);
|
|
118
|
+
{
|
|
119
|
+
const wrongScripts = ROOT_SCRIPT_CONTRACT.filter((item) => scripts[item.script] !== expectedRootScriptValue(item.script));
|
|
120
|
+
addCheck('root_package_scripts_contract', wrongScripts.length === 0, `根脚本必须按契约声明: ${wrongScripts
|
|
121
|
+
.map((item) => `${item.script} → ${expectedRootScriptValue(item.script)}`)
|
|
122
|
+
.join('; ')}`);
|
|
123
|
+
const forbidden = FORBIDDEN_ROOT_SCRIPTS.filter((script) => scripts[script] !== undefined);
|
|
124
|
+
addCheck('root_package_no_forbidden_scripts', forbidden.length === 0, `根 package.json 不得声明长驻服务脚本: ${forbidden.join(', ')}`);
|
|
125
|
+
addCheck('root_package_cli_dependency', pkg.devDependencies?.['@farris/cli'] === 'catalog:', '根 package.json 必须声明 "@farris/cli": "catalog:",否则根脚本无法解析 farris-cli bin');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// 2. pnpm-workspace.yaml
|
|
130
|
+
const wsYamlPath = join(resolvedTarget, 'pnpm-workspace.yaml');
|
|
131
|
+
if (!existsSync(wsYamlPath)) {
|
|
132
|
+
addCheck('workspace_yaml', false, '缺少 pnpm-workspace.yaml');
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const yamlContent = readFileSync(wsYamlPath, 'utf-8');
|
|
136
|
+
const missingContainers = CONTAINER_TYPES.filter((type) => !yamlContent.includes(`${containerFor(type)}/*`));
|
|
137
|
+
addCheck('workspace_packages_glob', missingContainers.length === 0, `pnpm-workspace.yaml 必须包含容器 glob: ${missingContainers
|
|
138
|
+
.map((type) => `${containerFor(type)}/*`)
|
|
139
|
+
.join(', ')}`);
|
|
140
|
+
addCheck('workspace_catalog', yamlContent.includes('catalog:'), 'pnpm-workspace.yaml 必须声明 catalog 依赖版本');
|
|
141
|
+
}
|
|
142
|
+
// 3. 容器目录:懒创建 —— 容器按需生成,只有该类型真的存在工程时才要求容器目录存在
|
|
143
|
+
const projects = listProjects(resolvedTarget);
|
|
144
|
+
for (const type of CONTAINER_TYPES) {
|
|
145
|
+
const container = containerFor(type);
|
|
146
|
+
const hasProject = projects.some((project) => project.type === type);
|
|
147
|
+
const containerPresent = existsSync(join(resolvedTarget, container));
|
|
148
|
+
addCheck(`container_${container}`, !hasProject || containerPresent, `存在 ${container}/ 下的工程,但容器目录缺失: ${container}/`);
|
|
149
|
+
}
|
|
150
|
+
// 4. 逐个工程按类型校验
|
|
151
|
+
for (const project of projects) {
|
|
152
|
+
verifyProject(resolvedTarget, project, addCheck);
|
|
153
|
+
}
|
|
154
|
+
// 5. AGENTS.md 体系(设计文档 §8.3)
|
|
155
|
+
{
|
|
156
|
+
const agentsPath = join(resolvedTarget, 'AGENTS.md');
|
|
157
|
+
if (!existsSync(agentsPath)) {
|
|
158
|
+
addCheck('agents_doc_exists', false, '缺少根 AGENTS.md(AI 协作契约的唯一真源)');
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
addCheck('agents_doc_exists', true);
|
|
162
|
+
const content = readFileSync(agentsPath, 'utf-8');
|
|
163
|
+
const missingDeclaration = CONTAINER_TYPES.filter((type) => !content.includes(`${containerFor(type)}/`));
|
|
164
|
+
addCheck('agents_doc_containers', missingDeclaration.length === 0, `根 AGENTS.md 未声明容器目录: ${missingDeclaration
|
|
165
|
+
.map((type) => containerFor(type))
|
|
166
|
+
.join(', ')}`);
|
|
167
|
+
const missingCommands = CLI_COMMAND_REGISTRY.filter((command) => !content.includes(command));
|
|
168
|
+
addCheck('agents_doc_commands', missingCommands.length === 0, `根 AGENTS.md 未覆盖命令注册表中的命令: ${missingCommands.join(', ')}`);
|
|
169
|
+
}
|
|
170
|
+
const claudePath = join(resolvedTarget, 'CLAUDE.md');
|
|
171
|
+
if (existsSync(claudePath)) {
|
|
172
|
+
const raw = readFileSync(claudePath, 'utf-8');
|
|
173
|
+
const lines = raw.trimEnd().split(/\r?\n/);
|
|
174
|
+
addCheck('claude_pointer_thin', lines.length <= 3 && raw.includes('AGENTS.md'), 'CLAUDE.md 必须是不含规则正文的薄指针(≤ 3 行且包含 AGENTS.md 字样)');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// 6. 受保护输入是否依然完好
|
|
178
|
+
for (const entry of preservedInputs) {
|
|
179
|
+
addCheck(`preserved_input_${entry}`, existsSync(join(resolvedTarget, entry)), `受保护输入文件/目录丢失或被覆盖: ${entry}`);
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
ok: errors.length === 0,
|
|
183
|
+
target: resolvedTarget,
|
|
184
|
+
checks,
|
|
185
|
+
errors
|
|
186
|
+
};
|
|
187
|
+
}
|
|
202
188
|
//# sourceMappingURL=verifier.js.map
|