@lark-apaas/fullstack-cli 1.1.59 → 1.1.60

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.59",
3
+ "version": "1.1.60",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -85,10 +85,25 @@ const STYLELINT_CONFIG_FILES = [
85
85
  ];
86
86
 
87
87
  /**
88
- * 老模板(fullstack-nestjs-template 1.x 时代)的应用没有 stylelint 配置,跑 stylelint 会以
89
- * "ConfigurationError: No configuration provided" 挂掉、把 pre-commit 卡死。没配置就跳过。
88
+ * 老模板(fullstack-nestjs-template 1.x 时代)的应用跑不了 stylelint,跑了就挂、把 pre-commit
89
+ * 卡死。两种形态都实测过:
90
+ *
91
+ * - 缺 scripts.stylelint → `npm error Missing script: "stylelint"`
92
+ * - 缺 .stylelintrc.* → `ConfigurationError: No configuration provided`
93
+ *
94
+ * 注意光判断 stylelint 装没装拦不住:@lark-apaas/fullstack-presets 的 dependencies 里有
95
+ * stylelint,只要 dep 了 presets 二进制就在。缺任一件就跳过这一步。
90
96
  */
91
- function hasStylelintConfig() {
97
+ function canRunStylelint() {
98
+ let pkg;
99
+ try {
100
+ pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
101
+ } catch {
102
+ return false;
103
+ }
104
+
105
+ if (!pkg.scripts || !pkg.scripts.stylelint) return false;
106
+
92
107
  return STYLELINT_CONFIG_FILES.some(file => fs.existsSync(path.join(cwd, file)));
93
108
  }
94
109
 
@@ -98,10 +113,10 @@ async function runDefaultLint() {
98
113
  [getBinName('npm'), ['run', 'type:check']],
99
114
  ];
100
115
 
101
- if (hasStylelintConfig()) {
116
+ if (canRunStylelint()) {
102
117
  taskSpecs.push([getBinName('npm'), ['run', 'stylelint']]);
103
118
  } else {
104
- console.warn('[lint] Skip stylelint: no stylelint config found');
119
+ console.warn('[lint] Skip stylelint: missing scripts.stylelint or stylelint config');
105
120
  }
106
121
 
107
122
  process.exit(await runTasksSerially(taskSpecs));
@@ -141,8 +156,8 @@ async function runSelectiveLint(inputFiles) {
141
156
  taskSpecs.push([getBinName('npx'), ['eslint', '--quiet', ...eslintFiles]]);
142
157
  }
143
158
 
144
- if (stylelintFiles.length > 0 && !hasStylelintConfig()) {
145
- console.warn('[lint] Skip stylelint: no stylelint config found');
159
+ if (stylelintFiles.length > 0 && !canRunStylelint()) {
160
+ console.warn('[lint] Skip stylelint: missing scripts.stylelint or stylelint config');
146
161
  } else if (stylelintFiles.length > 0) {
147
162
  taskSpecs.push([getBinName('npx'), ['stylelint', '--quiet', ...stylelintFiles]]);
148
163
  }