@finedesign/cli 0.5.0 → 0.5.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/CHANGELOG.md +9 -1
- package/README.md +6 -5
- package/data/1.25.0/catalog.json +1 -1
- package/data/1.25.0/manifest.json +3 -3
- package/package.json +1 -1
- package/src/cli.mjs +4 -1
- package/src/core/lint.mjs +49 -11
- package/src/core/runtime.mjs +6 -1
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"version": "1.25.0",
|
|
4
4
|
"sourceKind": "repository-snapshot",
|
|
5
|
-
"sourceRevision": "
|
|
5
|
+
"sourceRevision": "a88c1a76dc006929aa6ab9ce4f9de4ad0e926d0c",
|
|
6
6
|
"sourceDirty": false,
|
|
7
|
-
"contentHash": "
|
|
8
|
-
"catalogSha256": "
|
|
7
|
+
"contentHash": "c2edf1d31c61e83fa7996dca770a5e9ef87a5e67ce5fd55ccd4922a6e6bfe450",
|
|
8
|
+
"catalogSha256": "4b911bc129ea5a13070e2fcfac3a2f8d61087beb2758d2ae50b46e99180bba18",
|
|
9
9
|
"skillFiles": {
|
|
10
10
|
"references/component-guide.md": "612948840948e65f250998231eaa16fc41e8e27b9c03b19af32571422ca8185a",
|
|
11
11
|
"references/docs-slug-map.md": "440ce5cf137fd22eabfcc5b51c3f55b85174aa643773ef0cedd5df542e77bbc2",
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -60,7 +60,10 @@ function runDoctor(values) {
|
|
|
60
60
|
}
|
|
61
61
|
} catch (error) {
|
|
62
62
|
if (error instanceof ToolError && error.code === 'VERSION_NOT_DETECTED') {
|
|
63
|
-
suggestions =
|
|
63
|
+
suggestions = [
|
|
64
|
+
'For standalone HTML or an online preview, run "fine-design runtime list --format json" first and use the hosted version for component lookups. Verify rendering in the target preview separately.',
|
|
65
|
+
...(error.context?.suggestions || [])
|
|
66
|
+
];
|
|
64
67
|
} else {
|
|
65
68
|
throw error;
|
|
66
69
|
}
|
package/src/core/lint.mjs
CHANGED
|
@@ -138,6 +138,9 @@ function collectScopes(program) {
|
|
|
138
138
|
const targetScope = node.kind === 'var' ? scope.varScope : scope;
|
|
139
139
|
for (const declaration of node.declarations) {
|
|
140
140
|
bindPattern(declaration.id, targetScope);
|
|
141
|
+
if (declaration.id.type === 'Identifier' && declaration.init) {
|
|
142
|
+
targetScope.bindings.set(declaration.id.name, { initializer: declaration.init, scope });
|
|
143
|
+
}
|
|
141
144
|
if (declaration.id.type !== 'ObjectPattern') continue;
|
|
142
145
|
for (const prop of declaration.id.properties) {
|
|
143
146
|
if (prop.type !== 'ObjectProperty' || prop.computed) continue;
|
|
@@ -161,26 +164,47 @@ function findBinding(scope, name) {
|
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
|
|
167
|
+
function isGlobalMember(node, scope, object, property) {
|
|
168
|
+
return ['MemberExpression', 'JSXMemberExpression'].includes(node?.type) && !node.computed &&
|
|
169
|
+
node.object.name === object && node.property.name === property && findBinding(scope, object) === undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
164
172
|
function isFineDesignNamespace(node, scope) {
|
|
165
|
-
if (
|
|
166
|
-
if (node.type === 'Identifier' || node.type === 'JSXIdentifier') {
|
|
173
|
+
if (node?.type === 'Identifier' || node?.type === 'JSXIdentifier') {
|
|
167
174
|
const binding = findBinding(scope, node.name);
|
|
168
|
-
return Boolean(binding?.namespace || (node.name === 'FineDesign' && binding === undefined)
|
|
175
|
+
return Boolean(binding?.namespace || (node.name === 'FineDesign' && binding === undefined) ||
|
|
176
|
+
isGlobalMember(binding?.initializer, binding?.scope, 'window', 'FineDesign'));
|
|
169
177
|
}
|
|
170
|
-
return
|
|
171
|
-
node.object.name === 'window' && node.property.name === 'FineDesign' && findBinding(scope, 'window') === undefined;
|
|
178
|
+
return isGlobalMember(node, scope, 'window', 'FineDesign');
|
|
172
179
|
}
|
|
173
180
|
|
|
174
|
-
// shortcut: resolve direct
|
|
181
|
+
// shortcut: resolve imports and direct initializers in the same script, add data-flow analysis if reassigned or cross-script aliases need checking.
|
|
175
182
|
function componentName(node, scope) {
|
|
176
|
-
if (node
|
|
183
|
+
if (node?.type === 'JSXIdentifier' || node?.type === 'Identifier') {
|
|
177
184
|
const binding = findBinding(scope, node.name);
|
|
178
185
|
if (binding?.component && (!Object.hasOwn(binding, 'source') || isFineDesignNamespace(binding.source, binding.scope))) return binding.component;
|
|
179
|
-
|
|
186
|
+
node = binding?.initializer;
|
|
187
|
+
scope = binding?.scope;
|
|
188
|
+
}
|
|
189
|
+
if (['MemberExpression', 'JSXMemberExpression'].includes(node?.type) && !node.computed && isFineDesignNamespace(node.object, scope)) {
|
|
180
190
|
return node.property.name;
|
|
181
191
|
}
|
|
182
192
|
}
|
|
183
193
|
|
|
194
|
+
function isReactCreateElement(node, scope) {
|
|
195
|
+
if (node.type === 'Identifier') {
|
|
196
|
+
const binding = findBinding(scope, node.name);
|
|
197
|
+
node = binding?.initializer;
|
|
198
|
+
scope = binding?.scope;
|
|
199
|
+
}
|
|
200
|
+
if (node?.type !== 'MemberExpression' || node.computed || node.property.name !== 'createElement') return false;
|
|
201
|
+
if (isGlobalMember(node.object, scope, 'window', 'React')) return true;
|
|
202
|
+
if (node.object.type !== 'Identifier') return false;
|
|
203
|
+
const binding = findBinding(scope, node.object.name);
|
|
204
|
+
return (node.object.name === 'React' && binding === undefined) ||
|
|
205
|
+
isGlobalMember(binding?.initializer, binding?.scope, 'window', 'React');
|
|
206
|
+
}
|
|
207
|
+
|
|
184
208
|
export function lintFiles(catalog, targets = ['.']) {
|
|
185
209
|
const files = [...new Set(targets.flatMap((t) => collectFiles(t)))];
|
|
186
210
|
const validValueExports = new Set(EXTRA_VALUE_EXPORTS);
|
|
@@ -206,6 +230,12 @@ export function lintFiles(catalog, targets = ['.']) {
|
|
|
206
230
|
const report = (node, rule, severity, message, suggestion) => diagnostics.push({
|
|
207
231
|
file, line: node.loc.start.line, rule, severity, message, suggestion
|
|
208
232
|
});
|
|
233
|
+
const checkButtonType = (node, value) => {
|
|
234
|
+
if (typeof value === 'string' && !BUTTON_TYPES.has(value)) {
|
|
235
|
+
report(node, 'invalid-button-type', 'error', `Invalid Button type="${value}".`,
|
|
236
|
+
'Use type="primary" / "secondary" / "normal" / "negative" / "link" / "text" / "text-normal" / "bare", with the boolean danger prop for destructive actions.');
|
|
237
|
+
}
|
|
238
|
+
};
|
|
209
239
|
const checkExport = (name, node, allowTypes = false, typeOnly = false) => {
|
|
210
240
|
if (validValueExports.has(name) || (allowTypes && KNOWN_TYPE_EXPORTS.has(name))) return;
|
|
211
241
|
if (typeOnly && name.endsWith('Props')) return;
|
|
@@ -232,6 +262,10 @@ export function lintFiles(catalog, targets = ['.']) {
|
|
|
232
262
|
report(node, 'deep-or-foreign-icon-import', 'error', `Avoid importing icons from "${source}".`,
|
|
233
263
|
'Import the 56 built-in icons or SvgIcon directly from "@fx-ui/fine-design".');
|
|
234
264
|
}
|
|
265
|
+
if (source === '@fx-ui/fine-design/dist/fine-design.min.css') {
|
|
266
|
+
report(node, 'invalid-package-stylesheet', 'error', `"${source}" uses the hosted UMD filename as a package import.`,
|
|
267
|
+
'Import "@fx-ui/fine-design/dist/fine_design.css" in React projects. For standalone HTML, load the stylesheet URL from the runtime manifest.');
|
|
268
|
+
}
|
|
235
269
|
if (source === '@fx-ui/fine-design') {
|
|
236
270
|
for (const spec of node.specifiers.filter((item) => item.type === 'ImportSpecifier')) {
|
|
237
271
|
const typeOnly = node.importKind === 'type' || spec.importKind === 'type';
|
|
@@ -245,14 +279,18 @@ export function lintFiles(catalog, targets = ['.']) {
|
|
|
245
279
|
if (prop.type === 'ObjectProperty' && !prop.computed) checkExport(String(prop.key.name ?? prop.key.value), prop);
|
|
246
280
|
}
|
|
247
281
|
}
|
|
282
|
+
} else if (node.type === 'CallExpression' && node.arguments[1]?.type === 'ObjectExpression' &&
|
|
283
|
+
isReactCreateElement(node.callee, scope) && componentName(node.arguments[0], scope) === 'Button') {
|
|
284
|
+
const type = node.arguments[1].properties.findLast((prop) =>
|
|
285
|
+
prop.type === 'SpreadElement' || prop.computed || (prop.key.name ?? prop.key.value) === 'type');
|
|
286
|
+
if (type?.type === 'ObjectProperty' && !type.computed) checkButtonType(type, type.value.value);
|
|
248
287
|
} else if (node.type === 'JSXOpeningElement') {
|
|
249
288
|
const component = componentName(node.name, scope);
|
|
250
289
|
for (const attr of node.attributes.filter((item) => item.type === 'JSXAttribute')) {
|
|
251
290
|
const name = attr.name.name;
|
|
252
291
|
const value = (attr.value?.expression || attr.value)?.value;
|
|
253
|
-
if (component === 'Button' && name === 'type'
|
|
254
|
-
|
|
255
|
-
'Use type="primary" / "secondary" / "normal" / "negative" / "link" / "text" / "text-normal" / "bare", with the boolean danger prop for destructive actions.');
|
|
292
|
+
if (component === 'Button' && name === 'type') {
|
|
293
|
+
checkButtonType(attr, value);
|
|
256
294
|
} else if (component === 'NextTable' && name === 'columns') {
|
|
257
295
|
report(attr, 'next-table-columns-prop', 'error', 'NextTable does not accept a "columns" prop.',
|
|
258
296
|
'Declare <NextTable.Column>, <NextTable.HeaderCell>, and <NextTable.Cell dataKey="..."> children instead.');
|
package/src/core/runtime.mjs
CHANGED
|
@@ -40,7 +40,12 @@ async function readRuntime(value = defaultRuntimeURL) {
|
|
|
40
40
|
chunks.push(chunk);
|
|
41
41
|
}
|
|
42
42
|
manifest = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
43
|
-
} catch (error) {
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new ToolError('RUNTIME_UNAVAILABLE', `Cannot read ${manifestURL}: ${error.message}. No other version was selected.`, 1, {
|
|
45
|
+
manifestURL: manifestURL.href,
|
|
46
|
+
suggestions: ['Check access to the manifest from this environment or pass --runtime-url with a verified host.']
|
|
47
|
+
});
|
|
48
|
+
}
|
|
44
49
|
return { runtimeURL: base.href, manifestURL: manifestURL.href, manifest: validateRuntimeManifest(manifest) };
|
|
45
50
|
}
|
|
46
51
|
|