@sparknest/ui-build-vue 1.4.3 → 1.4.4
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": "@sparknest/ui-build-vue",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Shared Vue component-library build core for Cedar and Maple",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"bin": {
|
|
20
|
-
"ui-build": "./bin/ui-build.mjs"
|
|
20
|
+
"ui-build": "./bin/ui-build.mjs",
|
|
21
|
+
"ui-compat-declarations": "./bin/ui-compat-declarations.mjs"
|
|
21
22
|
},
|
|
22
23
|
"files": [
|
|
23
24
|
"bin",
|
|
@@ -26,20 +27,21 @@
|
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@vitejs/plugin-vue": "^6.0.11",
|
|
28
29
|
"@vitejs/plugin-vue-jsx": "^5.1.6",
|
|
29
|
-
"less": "^4.
|
|
30
|
+
"less": "^4.9.1",
|
|
30
31
|
"vite": "^8.3.8",
|
|
31
|
-
"vue-compat-legacy": "npm:vue@3.2.0"
|
|
32
|
+
"vue-compat-legacy": "npm:vue@3.2.0",
|
|
33
|
+
"typescript-js": "npm:typescript@6.0.3"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
|
-
"typescript": "
|
|
36
|
+
"typescript": "7.1.0-beta",
|
|
37
|
+
"vue": "3.5.46"
|
|
35
38
|
},
|
|
36
39
|
"peerDependencies": {
|
|
37
|
-
"typescript": ">=
|
|
38
|
-
"vue": ">=3.2"
|
|
39
|
-
"vue-tsc": ">=2"
|
|
40
|
+
"typescript": ">=7.1.0-beta",
|
|
41
|
+
"vue": ">=3.2"
|
|
40
42
|
},
|
|
41
43
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
44
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
43
45
|
},
|
|
44
46
|
"publishConfig": {
|
|
45
47
|
"access": "public",
|
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSy
|
|
|
2
2
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
3
3
|
|
|
4
4
|
// Keep each module format's declaration graph in the corresponding TS module mode.
|
|
5
|
-
// The caller provides its TypeScript instance,
|
|
5
|
+
// The caller provides its TypeScript instance, for transforming the generated declarations.
|
|
6
6
|
export function writeDualDeclarations(root, ts) {
|
|
7
7
|
if (!ts || typeof ts.createSourceFile !== 'function') {
|
|
8
8
|
throw new Error('TypeScript compiler API is required to generate dual declarations')
|
package/src/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process'
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { normalizeVueTypeFiles } from './normalize-vue-type-files.mjs'
|
|
4
5
|
import { createRequire } from 'node:module'
|
|
5
6
|
import { basename, dirname, relative, resolve } from 'node:path'
|
|
6
7
|
import vue from '@vitejs/plugin-vue'
|
|
@@ -12,6 +13,7 @@ import { libraryDefines } from './environment.mjs'
|
|
|
12
13
|
import { collectModuleEntries } from './module-entries.mjs'
|
|
13
14
|
import { downlevelVueDeclarations } from './vue-declarations.mjs'
|
|
14
15
|
|
|
16
|
+
export { writeDualDeclarations } from './dual-declarations.mjs'
|
|
15
17
|
export { browserTargets } from './browser-targets.mjs'
|
|
16
18
|
export { downlevelVueDeclarations } from './vue-declarations.mjs'
|
|
17
19
|
|
|
@@ -33,7 +35,10 @@ async function walk(root) {
|
|
|
33
35
|
|
|
34
36
|
function run(binary, args, cwd) {
|
|
35
37
|
return new Promise((resolvePromise, reject) => {
|
|
36
|
-
const child = spawn(binary, args, {
|
|
38
|
+
const child = spawn(binary, args, {
|
|
39
|
+
cwd, stdio: 'inherit',
|
|
40
|
+
env: { ...process.env, VUE_CONTENT_MAPPER_WORKERS: process.env.VUE_CONTENT_MAPPER_WORKERS ?? '1' },
|
|
41
|
+
})
|
|
37
42
|
child.on('error', reject)
|
|
38
43
|
child.on('exit', (code) =>
|
|
39
44
|
code === 0 ? resolvePromise() : reject(new Error(`${binary} exited with code ${code}`)),
|
|
@@ -324,7 +329,7 @@ function vitePlugins(config) {
|
|
|
324
329
|
return [vue(), vueJsx(), styleImportPlugin(), ...(config.vueSfcStyles ? [ignoreVueStylePlugin()] : [])]
|
|
325
330
|
}
|
|
326
331
|
|
|
327
|
-
async function buildModules(config, format, outDir, extension) {
|
|
332
|
+
async function buildModules(config, entries, format, outDir, extension) {
|
|
328
333
|
const root = resolve(config.root)
|
|
329
334
|
await build({
|
|
330
335
|
root,
|
|
@@ -339,8 +344,8 @@ async function buildModules(config, format, outDir, extension) {
|
|
|
339
344
|
emptyOutDir: false,
|
|
340
345
|
minify: false,
|
|
341
346
|
outDir,
|
|
342
|
-
|
|
343
|
-
input:
|
|
347
|
+
rolldownOptions: {
|
|
348
|
+
input: entries,
|
|
344
349
|
external: externalMatcher(config.external),
|
|
345
350
|
preserveEntrySignatures: 'strict',
|
|
346
351
|
output: {
|
|
@@ -414,7 +419,7 @@ async function buildBundle(config, format, outDir, fileName) {
|
|
|
414
419
|
formats: [format],
|
|
415
420
|
fileName: () => fileName,
|
|
416
421
|
},
|
|
417
|
-
|
|
422
|
+
rolldownOptions: {
|
|
418
423
|
external: externalMatcher(format === 'umd' ? config.umdExternal : config.external),
|
|
419
424
|
output: { exports: 'named', globals: config.globals },
|
|
420
425
|
},
|
|
@@ -479,19 +484,23 @@ export async function buildLibrary(userConfig) {
|
|
|
479
484
|
})
|
|
480
485
|
}
|
|
481
486
|
|
|
482
|
-
await
|
|
483
|
-
await buildModules(config, '
|
|
487
|
+
const entries = await collectModuleEntries(config.root, config.sourceDir, config.entry)
|
|
488
|
+
await buildModules(config, entries, 'es', 'es', 'mjs')
|
|
489
|
+
await buildModules(config, entries, 'cjs', 'lib', 'js')
|
|
484
490
|
await assertNoBundlerHelpers(config)
|
|
485
491
|
await buildBundle(config, 'es', 'es', `${config.bundleName}.esm.js`)
|
|
486
492
|
await buildBundle(config, 'cjs', 'lib', `${config.bundleName}.cjs.js`)
|
|
487
493
|
await buildBundle(config, 'umd', 'umd', `${config.bundleName}.js`)
|
|
488
494
|
await compileStyles({ ...config, outputs: ['es', 'lib', 'umd'] })
|
|
489
495
|
if (config.emitTypes !== false) {
|
|
490
|
-
await run('
|
|
496
|
+
await run('tsc', ['--runExternalCode', '-p', config.tsconfig], config.root)
|
|
497
|
+
await normalizeVueTypeFiles(resolve(config.root, 'types'))
|
|
491
498
|
if (existsSync(resolve(config.root, '../../node_modules/vue-compat-min/package.json'))) {
|
|
492
|
-
downlevelVueDeclarations(config.root, 'types', createRequire(
|
|
499
|
+
downlevelVueDeclarations(config.root, 'types', createRequire(import.meta.url)('typescript-js'))
|
|
493
500
|
}
|
|
494
501
|
}
|
|
495
502
|
|
|
496
503
|
await assertOutputs(config)
|
|
497
504
|
}
|
|
505
|
+
|
|
506
|
+
export { normalizeVueTypeFiles }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readdir, rename } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
// TypeScript 7 emits Component.d.vue.ts for arbitrary extensions. Keep the
|
|
5
|
+
// package's existing Component.vue.d.ts paths for older TypeScript consumers.
|
|
6
|
+
export async function normalizeVueTypeFiles(directory) {
|
|
7
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
8
|
+
const path = join(directory, entry.name)
|
|
9
|
+
if (entry.isDirectory()) await normalizeVueTypeFiles(path)
|
|
10
|
+
else if (entry.name.endsWith('.d.vue.ts')) await rename(path, path.replace(/\.d\.vue\.ts$/, '.vue.d.ts'))
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/vue-declarations.mjs
CHANGED
|
@@ -46,6 +46,9 @@ const conveniences = new Set([
|
|
|
46
46
|
'Reactive',
|
|
47
47
|
'ClassValue',
|
|
48
48
|
'Attrs',
|
|
49
|
+
'InputAutoCompleteAttribute',
|
|
50
|
+
'InputTypeHTMLAttribute',
|
|
51
|
+
'ReservedProps',
|
|
49
52
|
])
|
|
50
53
|
const convenienceSource = `import type { AllowedComponentProps, ComponentCustomProps, HTMLAttributes, Ref, VNodeProps } from 'vue'
|
|
51
54
|
export type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps
|
|
@@ -56,6 +59,9 @@ export type MaybeRef<T = any> = T | Ref<T>
|
|
|
56
59
|
export type MaybeRefOrGetter<T = any> = MaybeRef<T> | (() => T)
|
|
57
60
|
export type Reactive<T> = T extends object ? ReturnType<typeof import('vue').reactive<T>> : T
|
|
58
61
|
export type ClassValue = false | null | undefined | string | Record<string, any> | Array<ClassValue>
|
|
62
|
+
export type InputAutoCompleteAttribute = NonNullable<import('vue').InputHTMLAttributes['autocomplete']>
|
|
63
|
+
export type InputTypeHTMLAttribute = NonNullable<import('vue').InputHTMLAttributes['type']>
|
|
64
|
+
export type ReservedProps = Pick<VNodeProps, 'key' | 'ref'> & { ref_for?: boolean; ref_key?: string }
|
|
59
65
|
export type Attrs = import('vue').ComponentPublicInstance['$attrs']
|
|
60
66
|
export type ComponentProvideOptions = Record<string | symbol, unknown> | (() => Record<string | symbol, unknown>)
|
|
61
67
|
export interface GlobalDirectives {}
|
|
@@ -78,6 +84,22 @@ export function downlevelVueDeclarations(packageDirectory, outputDirectory, ts)
|
|
|
78
84
|
const text = readFileSync(file, 'utf8')
|
|
79
85
|
if (!/['"]vue['"]/.test(text)) continue
|
|
80
86
|
const ast = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true)
|
|
87
|
+
// Vue language tools can append an empty synthetic component to a
|
|
88
|
+
// script-only SFC which already forwards its implementation's default.
|
|
89
|
+
// The forwarded declaration is the component's full public contract.
|
|
90
|
+
if (file.endsWith('.vue.d.ts') && ast.statements.length === 4) {
|
|
91
|
+
const [forward, component, alias, assignment] = ast.statements
|
|
92
|
+
if (
|
|
93
|
+
ts.isExportDeclaration(forward) && forward.moduleSpecifier && forward.exportClause &&
|
|
94
|
+
ts.isNamedExports(forward.exportClause) && forward.exportClause.elements.some(item => item.name.text === 'default') &&
|
|
95
|
+
ts.isVariableStatement(component) && component.declarationList.declarations[0]?.name.getText(ast) === '__VLS_export' &&
|
|
96
|
+
ts.isVariableStatement(alias) && alias.declarationList.declarations[0]?.type?.getText(ast) === 'typeof __VLS_export' &&
|
|
97
|
+
ts.isExportAssignment(assignment) && assignment.expression.getText(ast) === alias.declarationList.declarations[0].name.getText(ast)
|
|
98
|
+
) {
|
|
99
|
+
writeFileSync(file, forward.getText(ast) + '\n')
|
|
100
|
+
continue
|
|
101
|
+
}
|
|
102
|
+
}
|
|
81
103
|
const imports = new Map()
|
|
82
104
|
const namespaces = new Set()
|
|
83
105
|
for (const node of ast.statements)
|