@ductape/cli 0.5.7 → 0.5.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.
@@ -0,0 +1,445 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { spawnSync } from 'node:child_process';
5
+ import { builtinModules, createRequire } from 'node:module';
6
+ import { parse } from '@babel/parser';
7
+ import { FRAMEWORK_PEER, UI_MANIFEST_FILE, validateManifest } from './manifest.js';
8
+ import { buildPack, MAX_FILE_BYTES, MAX_FILES, MAX_TOTAL_BYTES } from './pack.js';
9
+ import { isSafeRelativePath } from './paths.js';
10
+ const CODE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];
11
+ const ALLOWED_EXTENSIONS = new Set([...CODE_EXTENSIONS, '.vue', '.css', '.json', '.md']);
12
+ const SKIPPED_DIRS = new Set(['node_modules', 'dist', 'build', 'coverage', '__tests__']);
13
+ const TEST_FILE = /\.(test|spec|stories)\.[jt]sx?$/;
14
+ const NODE_BUILTINS = new Set(builtinModules.map((name) => name.replace(/^node:/, '')));
15
+ /** Text that should never ship to a browser. Configuration reaches a UI piece through props, not baked-in values. */
16
+ const SECRET_PATTERNS = [
17
+ [/-----BEGIN [A-Z ]*PRIVATE KEY-----/, 'a private key'],
18
+ [/\bsk_live_[0-9A-Za-z]{10,}/, 'a live Stripe secret key'],
19
+ [/\bAKIA[0-9A-Z]{16}\b/, 'an AWS access key id'],
20
+ [/\bgh[pousr]_[0-9A-Za-z]{30,}/, 'a GitHub token'],
21
+ [/\bxox[abprs]-[0-9A-Za-z-]{10,}/, 'a Slack token'],
22
+ ];
23
+ const isCode = (file) => (CODE_EXTENSIONS.some((ext) => file.endsWith(ext)) || file.endsWith('.vue')) && !file.endsWith('.d.ts');
24
+ /** The package an import names: "react" for "react/jsx-runtime", "@ductape/react" for "@ductape/react/x". */
25
+ export function packageOf(specifier) {
26
+ const parts = specifier.split('/');
27
+ return specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
28
+ }
29
+ /** Reads every file that would be published, refusing links, binaries and anything over the size limits. */
30
+ export function collectUiFiles(dir) {
31
+ const files = [];
32
+ const diagnostics = [];
33
+ let total = 0;
34
+ const walk = (absolute, relative) => {
35
+ for (const entry of fs.readdirSync(absolute, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
36
+ if (entry.name.startsWith('.'))
37
+ continue;
38
+ const rel = relative ? `${relative}/${entry.name}` : entry.name;
39
+ const abs = path.join(absolute, entry.name);
40
+ if (entry.isSymbolicLink()) {
41
+ diagnostics.push({ severity: 'error', code: 'UI_SYMLINK', message: 'Links are not published; copy the file in instead', file: rel });
42
+ continue;
43
+ }
44
+ if (entry.isDirectory()) {
45
+ if (!SKIPPED_DIRS.has(entry.name))
46
+ walk(abs, rel);
47
+ continue;
48
+ }
49
+ if (!entry.isFile() || rel === UI_MANIFEST_FILE || TEST_FILE.test(entry.name))
50
+ continue;
51
+ if (!isSafeRelativePath(rel)) {
52
+ diagnostics.push({ severity: 'error', code: 'UI_FILE_PATH', message: 'This file name cannot be published', file: rel });
53
+ continue;
54
+ }
55
+ if (!ALLOWED_EXTENSIONS.has(path.extname(entry.name))) {
56
+ diagnostics.push({ severity: 'error', code: 'UI_FILE_TYPE', message: `Only ${[...ALLOWED_EXTENSIONS].join(', ')} files are published`, file: rel });
57
+ continue;
58
+ }
59
+ const buffer = fs.readFileSync(abs);
60
+ if (buffer.length > MAX_FILE_BYTES) {
61
+ diagnostics.push({ severity: 'error', code: 'UI_FILE_SIZE', message: `File is ${buffer.length} bytes; at most ${MAX_FILE_BYTES} are allowed`, file: rel });
62
+ continue;
63
+ }
64
+ const content = buffer.toString('utf8');
65
+ if (!Buffer.from(content, 'utf8').equals(buffer)) {
66
+ diagnostics.push({ severity: 'error', code: 'UI_FILE_TEXT', message: 'File is not UTF-8 text', file: rel });
67
+ continue;
68
+ }
69
+ total += buffer.length;
70
+ files.push({ path: rel, content });
71
+ }
72
+ };
73
+ walk(dir, '');
74
+ if (files.length > MAX_FILES)
75
+ diagnostics.push({ severity: 'error', code: 'UI_FILE_COUNT', message: `${files.length} files; at most ${MAX_FILES} are allowed` });
76
+ if (total > MAX_TOTAL_BYTES)
77
+ diagnostics.push({ severity: 'error', code: 'UI_FILE_SIZE', message: `${total} bytes in total; at most ${MAX_TOTAL_BYTES} are allowed` });
78
+ return { files, diagnostics };
79
+ }
80
+ /** Every place a module reaches for another one, plus reads of environment variables. */
81
+ function scanModule(source, file, lang = path.extname(file).slice(1), startLine = 1) {
82
+ const imports = [];
83
+ const envReads = [];
84
+ const dynamicNonLiteral = [];
85
+ let ast;
86
+ try {
87
+ ast = parse(source, {
88
+ sourceType: 'module',
89
+ plugins: lang === 'ts' ? ['typescript'] : ['typescript', 'jsx'],
90
+ errorRecovery: false,
91
+ startLine,
92
+ });
93
+ }
94
+ catch (error) {
95
+ const loc = error.loc;
96
+ return { imports, envReads, dynamicNonLiteral, error: { severity: 'error', code: 'UI_PARSE', message: error.message, file, line: loc?.line } };
97
+ }
98
+ const visit = (node) => {
99
+ if (!node || typeof node !== 'object')
100
+ return;
101
+ if (Array.isArray(node)) {
102
+ node.forEach(visit);
103
+ return;
104
+ }
105
+ const n = node;
106
+ const line = n.loc?.start?.line ?? 0;
107
+ switch (n.type) {
108
+ case 'ImportDeclaration':
109
+ case 'ExportAllDeclaration':
110
+ case 'ExportNamedDeclaration':
111
+ if (n.source?.value !== undefined)
112
+ imports.push({ specifier: String(n.source.value), line, kind: 'static' });
113
+ break;
114
+ case 'TSImportType':
115
+ if (n.argument?.literal?.value !== undefined)
116
+ imports.push({ specifier: String(n.argument.literal.value), line, kind: 'static' });
117
+ else if (n.argument?.value !== undefined)
118
+ imports.push({ specifier: String(n.argument.value), line, kind: 'static' });
119
+ break;
120
+ case 'CallExpression':
121
+ if (n.callee?.type === 'Import') {
122
+ const arg = n.arguments?.[0];
123
+ if (arg?.type === 'StringLiteral')
124
+ imports.push({ specifier: arg.value, line, kind: 'dynamic' });
125
+ else
126
+ dynamicNonLiteral.push(line);
127
+ }
128
+ else if (n.callee?.type === 'Identifier' && n.callee.name === 'require') {
129
+ const arg = n.arguments?.[0];
130
+ imports.push({ specifier: arg?.type === 'StringLiteral' ? arg.value : '<expression>', line, kind: 'require' });
131
+ }
132
+ break;
133
+ case 'ImportExpression':
134
+ if (n.source?.type === 'StringLiteral')
135
+ imports.push({ specifier: n.source.value, line, kind: 'dynamic' });
136
+ else
137
+ dynamicNonLiteral.push(line);
138
+ break;
139
+ case 'MemberExpression': {
140
+ const obj = n.object;
141
+ const prop = n.property;
142
+ const propName = prop?.type === 'Identifier' ? prop.name : prop?.type === 'StringLiteral' ? prop.value : undefined;
143
+ if (propName === 'env' && ((obj?.type === 'Identifier' && obj.name === 'process') || obj?.type === 'MetaProperty'))
144
+ envReads.push(line);
145
+ break;
146
+ }
147
+ }
148
+ for (const [key, value] of Object.entries(n)) {
149
+ if (key === 'loc' || key === 'start' || key === 'end' || key === 'leadingComments' || key === 'trailingComments')
150
+ continue;
151
+ if (value && typeof value === 'object')
152
+ visit(value);
153
+ }
154
+ };
155
+ visit(ast.program);
156
+ return { imports, envReads, dynamicNonLiteral };
157
+ }
158
+ /**
159
+ * A Vue single-file component: its <script> blocks are checked like any module, with lines counted from the top of the file.
160
+ * Blocks that pull their content from elsewhere (src="...") are refused, so everything published is checked.
161
+ */
162
+ function scanVue(source, file) {
163
+ const result = { imports: [], envReads: [], dynamicNonLiteral: [], errors: [] };
164
+ const lineAt = (index) => source.slice(0, index).split('\n').length;
165
+ for (const block of source.matchAll(/<(script|template|style)\b([^>]*)>/gi)) {
166
+ if (/\bsrc\s*=/.test(block[2])) {
167
+ result.errors.push({ severity: 'error', code: 'UI_VUE_SRC', message: `<${block[1]} src> pulls content from outside the file; put it in the component`, file, line: lineAt(block.index ?? 0) });
168
+ }
169
+ }
170
+ for (const block of source.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)) {
171
+ const lang = /\blang\s*=\s*["']?([a-z]+)/i.exec(block[1])?.[1]?.toLowerCase() ?? 'js';
172
+ if (!['ts', 'tsx', 'js', 'jsx'].includes(lang)) {
173
+ result.errors.push({ severity: 'error', code: 'UI_VUE_LANG', message: `<script lang="${lang}"> is not supported; use ts or js`, file, line: lineAt(block.index ?? 0) });
174
+ continue;
175
+ }
176
+ const contentStart = (block.index ?? 0) + block[0].indexOf('>') + 1;
177
+ const scan = scanModule(block[2], file, lang, lineAt(contentStart));
178
+ if (scan.error)
179
+ result.errors.push(scan.error);
180
+ result.imports.push(...scan.imports);
181
+ result.envReads.push(...scan.envReads);
182
+ result.dynamicNonLiteral.push(...scan.dynamicNonLiteral);
183
+ }
184
+ return result;
185
+ }
186
+ function scanFile(content, file) {
187
+ if (file.endsWith('.vue'))
188
+ return scanVue(content, file);
189
+ const scan = scanModule(content, file);
190
+ return { ...scan, errors: scan.error ? [scan.error] : [] };
191
+ }
192
+ /** The packed file a relative import lands on, the way bundlers resolve it, or undefined. */
193
+ function resolveRelative(from, specifier, published) {
194
+ const joined = path.posix.normalize(path.posix.join(path.posix.dirname(from), specifier));
195
+ if (joined.startsWith('..') || path.posix.isAbsolute(joined))
196
+ return null;
197
+ const candidates = [joined, ...CODE_EXTENSIONS.map((ext) => joined + ext), ...CODE_EXTENSIONS.map((ext) => `${joined}/index${ext}`)];
198
+ // A .js specifier may name a .ts/.tsx source, as TypeScript's NodeNext style writes it.
199
+ if (/\.jsx?$/.test(joined))
200
+ candidates.push(joined.replace(/\.jsx?$/, '.ts'), joined.replace(/\.jsx?$/, '.tsx'));
201
+ return candidates.find((candidate) => published.has(candidate));
202
+ }
203
+ /** Checks one UI piece's directory: its manifest, the files that would be published and what its code imports. */
204
+ export function validateUiDirectory(dir) {
205
+ const diagnostics = [];
206
+ const manifestPath = path.join(dir, UI_MANIFEST_FILE);
207
+ if (!fs.existsSync(manifestPath)) {
208
+ return { ok: false, dir, files: [], diagnostics: [{ severity: 'error', code: 'UI_MANIFEST_MISSING', message: `No ${UI_MANIFEST_FILE} in ${dir}` }] };
209
+ }
210
+ let raw;
211
+ try {
212
+ raw = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
213
+ }
214
+ catch (error) {
215
+ return { ok: false, dir, files: [], diagnostics: [{ severity: 'error', code: 'UI_MANIFEST_JSON', message: `ui.json is not valid JSON: ${error.message}`, file: UI_MANIFEST_FILE }] };
216
+ }
217
+ const { manifest, diagnostics: manifestDiagnostics } = validateManifest(raw);
218
+ diagnostics.push(...manifestDiagnostics);
219
+ const collected = collectUiFiles(dir);
220
+ diagnostics.push(...collected.diagnostics);
221
+ const published = new Set(collected.files.map((file) => file.path));
222
+ if (manifest && !published.has(manifest.entry)) {
223
+ diagnostics.push({ severity: 'error', code: 'UI_ENTRY_MISSING', message: `The entry "${manifest.entry}" is not a published file`, file: UI_MANIFEST_FILE });
224
+ }
225
+ else if (manifest && !isCode(manifest.entry)) {
226
+ diagnostics.push({ severity: 'error', code: 'UI_ENTRY_TYPE', message: 'The entry must be a .ts, .tsx, .js, .jsx or .vue module', file: UI_MANIFEST_FILE });
227
+ }
228
+ const peers = new Set(Object.keys(manifest?.peerDependencies ?? raw?.peerDependencies ?? {}));
229
+ const uses = new Set(Object.keys(manifest?.uses ?? {}));
230
+ const usedPeers = new Set();
231
+ const usedPieces = new Set();
232
+ for (const file of collected.files) {
233
+ for (const [pattern, what] of SECRET_PATTERNS) {
234
+ const index = file.content.search(pattern);
235
+ if (index >= 0) {
236
+ diagnostics.push({ severity: 'error', code: 'UI_SECRET', message: `Looks like ${what}. Pass credentials through props or the Ductape session, never in source`, file: file.path, line: file.content.slice(0, index).split('\n').length });
237
+ }
238
+ }
239
+ if (!isCode(file.path))
240
+ continue;
241
+ if (/\.[jt]sx$/.test(file.path) && manifest?.framework === 'javascript') {
242
+ diagnostics.push({ severity: 'error', code: 'UI_FILE_TYPE', message: 'A javascript piece is plain DOM code; JSX needs a framework. Use .ts or .js', file: file.path });
243
+ continue;
244
+ }
245
+ if (file.path.endsWith('.vue') && manifest && manifest.framework !== 'vue') {
246
+ diagnostics.push({ severity: 'error', code: 'UI_FILE_TYPE', message: `.vue files belong in a vue piece; this one is ${manifest.framework}`, file: file.path });
247
+ continue;
248
+ }
249
+ const scan = scanFile(file.content, file.path);
250
+ if (scan.errors.length > 0) {
251
+ diagnostics.push(...scan.errors);
252
+ continue;
253
+ }
254
+ for (const line of scan.envReads) {
255
+ diagnostics.push({ severity: 'error', code: 'UI_ENV_ACCESS', message: 'A UI piece must not read environment variables; take the value as a prop', file: file.path, line });
256
+ }
257
+ for (const line of scan.dynamicNonLiteral) {
258
+ diagnostics.push({ severity: 'error', code: 'UI_DYNAMIC_IMPORT', message: 'Dynamic imports must name a fixed module so they can be checked', file: file.path, line });
259
+ }
260
+ for (const use of scan.imports) {
261
+ const at = { file: file.path, line: use.line };
262
+ const { specifier } = use;
263
+ if (use.kind === 'require') {
264
+ diagnostics.push({ severity: 'error', code: 'UI_REQUIRE', message: 'Use import, not require: UI pieces are ES modules', ...at });
265
+ continue;
266
+ }
267
+ if (specifier.startsWith('./') || specifier.startsWith('../')) {
268
+ const target = resolveRelative(file.path, specifier, published);
269
+ if (target === null)
270
+ diagnostics.push({ severity: 'error', code: 'UI_IMPORT_OUTSIDE', message: `"${specifier}" reaches outside the UI piece`, ...at });
271
+ else if (target === undefined)
272
+ diagnostics.push({ severity: 'error', code: 'UI_IMPORT_MISSING', message: `"${specifier}" is not a published file of this UI piece`, ...at });
273
+ continue;
274
+ }
275
+ if (specifier.startsWith('/') || /^[a-zA-Z]+:/.test(specifier) && !specifier.startsWith('node:')) {
276
+ diagnostics.push({ severity: 'error', code: 'UI_IMPORT_ABSOLUTE', message: `"${specifier}" is an absolute path or URL; UI pieces import packages and their own files only`, ...at });
277
+ continue;
278
+ }
279
+ if (specifier.startsWith('#ui/')) {
280
+ const name = specifier.slice(4).split('/')[0];
281
+ usedPieces.add(name);
282
+ if (!uses.has(name))
283
+ diagnostics.push({ severity: 'error', code: 'UI_IMPORT_UNDECLARED_UI', message: `"${specifier}" imports the UI piece "${name}", which is not listed in uses`, ...at });
284
+ continue;
285
+ }
286
+ if (specifier.startsWith('#')) {
287
+ diagnostics.push({ severity: 'error', code: 'UI_IMPORT_ALIAS', message: `"${specifier}" is an alias of the authoring project; the consuming application will not have it`, ...at });
288
+ continue;
289
+ }
290
+ if (specifier.startsWith('node:') || NODE_BUILTINS.has(packageOf(specifier))) {
291
+ diagnostics.push({ severity: 'error', code: 'UI_IMPORT_NODE', message: `"${specifier}" is a Node.js module and does not exist in the browser`, ...at });
292
+ continue;
293
+ }
294
+ const pkg = packageOf(specifier);
295
+ usedPeers.add(pkg);
296
+ if (!peers.has(pkg)) {
297
+ diagnostics.push({ severity: 'error', code: 'UI_IMPORT_UNDECLARED', message: `"${pkg}" is imported but not listed in peerDependencies; the consuming application must install it`, ...at });
298
+ }
299
+ }
300
+ }
301
+ if (manifest) {
302
+ for (const peer of peers) {
303
+ if (!usedPeers.has(peer) && !Object.values(FRAMEWORK_PEER).includes(peer)) {
304
+ diagnostics.push({ severity: 'warning', code: 'UI_PEER_UNUSED', message: `"${peer}" is listed in peerDependencies but never imported`, file: UI_MANIFEST_FILE });
305
+ }
306
+ }
307
+ for (const piece of uses) {
308
+ if (!usedPieces.has(piece))
309
+ diagnostics.push({ severity: 'warning', code: 'UI_USES_UNUSED', message: `"${piece}" is listed in uses but never imported`, file: UI_MANIFEST_FILE });
310
+ }
311
+ }
312
+ return {
313
+ ok: !diagnostics.some((d) => d.severity === 'error'),
314
+ dir,
315
+ ...(manifest ? { manifest } : {}),
316
+ files: collected.files.map((file) => file.path),
317
+ diagnostics,
318
+ };
319
+ }
320
+ /** Validates and, only when there is nothing wrong, packs. */
321
+ export function packUiDirectory(dir) {
322
+ const validation = validateUiDirectory(dir);
323
+ if (!validation.ok || !validation.manifest)
324
+ return { validation };
325
+ const { files } = collectUiFiles(dir);
326
+ return { validation, pack: buildPack(validation.manifest, files) };
327
+ }
328
+ /**
329
+ * Type-checks a UI piece with the TypeScript and type packages of the project it is written in, so it compiles against
330
+ * the React and Ductape SDK versions that project has. Other UI pieces it uses resolve from ductape/ui.
331
+ */
332
+ export function typecheckUiDirectory(dir, projectRoot) {
333
+ let framework;
334
+ try {
335
+ framework = JSON.parse(fs.readFileSync(path.join(dir, UI_MANIFEST_FILE), 'utf8')).framework;
336
+ }
337
+ catch {
338
+ framework = undefined;
339
+ }
340
+ if (framework === 'vue')
341
+ return typecheckVue(dir, projectRoot);
342
+ let ts;
343
+ try {
344
+ const loaded = createRequire(path.join(projectRoot, 'package.json'))('typescript');
345
+ // Some loaders hand back the CommonJS module under `default`.
346
+ ts = typeof loaded?.createProgram === 'function' ? loaded : loaded?.default;
347
+ }
348
+ catch {
349
+ ts = undefined;
350
+ }
351
+ if (typeof ts?.createProgram !== 'function') {
352
+ return [{ severity: 'error', code: 'UI_TYPECHECK_UNAVAILABLE', message: `TypeScript is not installed in ${projectRoot}; install it to use --typecheck` }];
353
+ }
354
+ const { files } = collectUiFiles(dir);
355
+ const shim = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'ductape-ui-')), 'assets.d.ts');
356
+ fs.writeFileSync(shim, "declare module '*.module.css' { const classes: Record<string, string>; export default classes; }\ndeclare module '*.css';\n");
357
+ try {
358
+ const roots = files.filter((file) => isCode(file.path) || file.path.endsWith('.d.ts')).map((file) => path.join(dir, file.path));
359
+ const program = ts.createProgram([...roots, shim], {
360
+ strict: true,
361
+ noEmit: true,
362
+ skipLibCheck: true,
363
+ isolatedModules: true,
364
+ esModuleInterop: true,
365
+ resolveJsonModule: true,
366
+ jsx: ts.JsxEmit.ReactJSX,
367
+ target: ts.ScriptTarget.ES2020,
368
+ module: ts.ModuleKind.ESNext,
369
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
370
+ lib: ['lib.es2020.d.ts', 'lib.dom.d.ts', 'lib.dom.iterable.d.ts'],
371
+ baseUrl: projectRoot,
372
+ paths: { '#ui/*': [path.join(projectRoot, 'ductape/ui/installed/*'), path.join(projectRoot, 'ductape/ui/*')] },
373
+ });
374
+ return ts.getPreEmitDiagnostics(program)
375
+ .filter((d) => d.category === ts.DiagnosticCategory.Error)
376
+ .map((d) => {
377
+ const position = d.file && d.start !== undefined ? d.file.getLineAndCharacterOfPosition(d.start) : undefined;
378
+ return {
379
+ severity: 'error',
380
+ code: 'UI_TYPE_ERROR',
381
+ message: ts.flattenDiagnosticMessageText(d.messageText, '\n'),
382
+ ...(d.file && d.file.fileName !== shim ? { file: path.relative(dir, d.file.fileName).split(path.sep).join('/') } : {}),
383
+ ...(position ? { line: position.line + 1 } : {}),
384
+ };
385
+ });
386
+ }
387
+ finally {
388
+ fs.rmSync(path.dirname(shim), { recursive: true, force: true });
389
+ }
390
+ }
391
+ const TS_ERROR = /^(.+?)\((\d+),\d+\): error (TS\d+): (.*)$/;
392
+ /**
393
+ * Vue pieces are checked by the project's own vue-tsc, which understands .vue files. It runs on a throwaway tsconfig that
394
+ * holds just this piece, with the same strict settings as React pieces.
395
+ */
396
+ function typecheckVue(dir, projectRoot) {
397
+ let bin;
398
+ try {
399
+ const require = createRequire(path.join(projectRoot, 'package.json'));
400
+ const pkgPath = require.resolve('vue-tsc/package.json');
401
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
402
+ const relative = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.['vue-tsc'];
403
+ if (!relative)
404
+ throw new Error('no bin');
405
+ bin = path.join(path.dirname(pkgPath), relative);
406
+ }
407
+ catch {
408
+ return [{ severity: 'error', code: 'UI_TYPECHECK_UNAVAILABLE', message: `vue-tsc is not installed in ${projectRoot}; install it to type-check Vue pieces` }];
409
+ }
410
+ const { files } = collectUiFiles(dir);
411
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ductape-ui-vue-'));
412
+ try {
413
+ fs.writeFileSync(path.join(temp, 'assets.d.ts'), "declare module '*.module.css' { const classes: Record<string, string>; export default classes; }\ndeclare module '*.css';\n");
414
+ fs.writeFileSync(path.join(temp, 'tsconfig.json'), JSON.stringify({
415
+ compilerOptions: {
416
+ strict: true, noEmit: true, skipLibCheck: true, isolatedModules: true, esModuleInterop: true, resolveJsonModule: true,
417
+ jsx: 'preserve', target: 'ES2020', module: 'ESNext', moduleResolution: 'Bundler', lib: ['ES2020', 'DOM', 'DOM.Iterable'], types: [],
418
+ baseUrl: projectRoot,
419
+ paths: { '#ui/*': [path.join(projectRoot, 'ductape/ui/installed/*'), path.join(projectRoot, 'ductape/ui/*')] },
420
+ },
421
+ files: [path.join(temp, 'assets.d.ts'), ...files.filter((f) => isCode(f.path) || f.path.endsWith('.d.ts')).map((f) => path.join(dir, f.path))],
422
+ }));
423
+ const run = spawnSync(process.execPath, [bin, '--noEmit', '-p', path.join(temp, 'tsconfig.json')], { cwd: projectRoot, encoding: 'utf8', timeout: 120_000 });
424
+ if (run.error)
425
+ return [{ severity: 'error', code: 'UI_TYPECHECK_UNAVAILABLE', message: `vue-tsc could not run: ${run.error.message}` }];
426
+ const diagnostics = [];
427
+ for (const line of `${run.stdout}\n${run.stderr}`.split('\n')) {
428
+ const m = TS_ERROR.exec(line.trim());
429
+ if (!m)
430
+ continue;
431
+ const absolute = path.resolve(projectRoot, m[1]);
432
+ diagnostics.push({
433
+ severity: 'error', code: 'UI_TYPE_ERROR', message: `${m[3]}: ${m[4]}`, line: Number(m[2]),
434
+ ...(absolute.startsWith(path.resolve(dir) + path.sep) ? { file: path.relative(dir, absolute).split(path.sep).join('/') } : { file: m[1] }),
435
+ });
436
+ }
437
+ if (run.status !== 0 && diagnostics.length === 0) {
438
+ diagnostics.push({ severity: 'error', code: 'UI_TYPE_ERROR', message: `vue-tsc failed: ${(run.stderr || run.stdout).trim().slice(0, 500)}` });
439
+ }
440
+ return diagnostics;
441
+ }
442
+ finally {
443
+ fs.rmSync(temp, { recursive: true, force: true });
444
+ }
445
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ductape/cli",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "description": "Ductape CLI — local platform, login, link projects, and manage resources via the proxy (Workbench-compatible)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -18,7 +18,8 @@
18
18
  "build": "tsc",
19
19
  "dev": "tsx src/index.ts",
20
20
  "test": "npm run build && node --import tsx --test test/**/*.test.ts",
21
- "prepublishOnly": "npm run build"
21
+ "prepublishOnly": "npm run build",
22
+ "test:ui:e2e": "node --import tsx test/e2e/ui-slice.ts"
22
23
  },
23
24
  "keywords": [
24
25
  "ductape",