@nubisco/ui 5.47.0 → 5.47.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/dist/plugins/vite/imports.d.ts +15 -0
- package/dist/plugins/vite/imports.d.ts.map +1 -1
- package/dist/plugins/vite/imports.js +77 -4
- package/dist/plugins/vite/index.d.ts.map +1 -1
- package/dist/plugins/vite/index.js +2 -1
- package/package.json +1 -1
- package/src/plugins/vite/imports.ts +64 -4
- package/src/plugins/vite/index.ts +2 -1
|
@@ -30,6 +30,15 @@ import type { Rollup } from 'vite';
|
|
|
30
30
|
* alone entirely, since there is no way to tell from it which components the
|
|
31
31
|
* file actually uses.
|
|
32
32
|
*/
|
|
33
|
+
/**
|
|
34
|
+
* Exports that mount a library component at runtime instead of rendering it
|
|
35
|
+
* from a template. `useConfirm()` creates its own app around NbConfirm, so no
|
|
36
|
+
* template ever names NbConfirm and, before this map, no build linked
|
|
37
|
+
* `Confirm.css`: every confirm dialog rendered unstyled. A spec in
|
|
38
|
+
* `tests/import-plugin.test.ts` reads the composables' own imports and fails
|
|
39
|
+
* if one mounts a component this map does not name.
|
|
40
|
+
*/
|
|
41
|
+
export declare const PROGRAMMATIC_MOUNTS: Record<string, string[]>;
|
|
33
42
|
interface INubiscoImportOptions {
|
|
34
43
|
/** `Nb*` name to entry file, from the component manifest. */
|
|
35
44
|
manifest: Map<string, string>;
|
|
@@ -37,6 +46,12 @@ interface INubiscoImportOptions {
|
|
|
37
46
|
styleManifest: Record<string, string[]>;
|
|
38
47
|
/** Inject stylesheets. When false this plugin only rewrites imports. */
|
|
39
48
|
styles: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Exports that mount a component at runtime, mapped to the entries they
|
|
51
|
+
* mount. No template names that component, so neither the resolver nor the
|
|
52
|
+
* rewrite below would otherwise link its stylesheets.
|
|
53
|
+
*/
|
|
54
|
+
mounts?: Record<string, string[]>;
|
|
40
55
|
packageName: string;
|
|
41
56
|
/** Called with the number of components resolved in a file. */
|
|
42
57
|
onResolve: (count: number) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../../src/plugins/vite/imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,UAAU,qBAAqB;IAC7B,6DAA6D;IAC7D,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACvC,wEAAwE;IACxE,MAAM,EAAE,OAAO,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC;AAyBD,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB;;;
|
|
1
|
+
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../../src/plugins/vite/imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAExD,CAAA;AAED,UAAU,qBAAqB;IAC7B,6DAA6D;IAC7D,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACvC,wEAAwE;IACxE,MAAM,EAAE,OAAO,CAAA;IACf;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC;AAyBD,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB;;;oBAgBzC,MAAM,MAAM,MAAM;;aAoJxB,MAAM,CAAC,cAAc;;EAIlC"}
|
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
import { MagicString } from './vendor.js';
|
|
2
2
|
import { parse, babelParse } from 'vue/compiler-sfc';
|
|
3
|
+
/**
|
|
4
|
+
* Makes a hand-written component import behave like an auto-imported one.
|
|
5
|
+
*
|
|
6
|
+
* The library ships one stylesheet per chunk, and the auto-import resolver
|
|
7
|
+
* declares each component's sheets as side effects so the bundler links them
|
|
8
|
+
* next to the component. That only happens for tags the resolver saw. An app
|
|
9
|
+
* that writes its imports by hand:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { NbButton, NbPanel } from '@nubisco/ui'
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* never went through the resolver, so it got no stylesheets at all. With
|
|
16
|
+
* `styles: true` (the default) and the `@nubisco/ui/css` import dropped, as
|
|
17
|
+
* the upgrade guide said to, that shipped an app with no component CSS: every
|
|
18
|
+
* page rendered unstyled, and nothing failed. The CSS bundle still looked
|
|
19
|
+
* plausible, because the app's own styles and the design tokens were still in
|
|
20
|
+
* it.
|
|
21
|
+
*
|
|
22
|
+
* So this plugin gives the same treatment to imports the app wrote itself:
|
|
23
|
+
*
|
|
24
|
+
* 1. A named component imported from the barrel is rewritten to its own entry
|
|
25
|
+
* point, which is what the resolver would have emitted, and which also
|
|
26
|
+
* stops the barrel from pulling in every other component.
|
|
27
|
+
* 2. Either way, that component's stylesheets are imported alongside it.
|
|
28
|
+
*
|
|
29
|
+
* Names the manifest does not know (composables, types, `registerIcons`) stay
|
|
30
|
+
* on the barrel import untouched, and a namespace or default import is left
|
|
31
|
+
* alone entirely, since there is no way to tell from it which components the
|
|
32
|
+
* file actually uses.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Exports that mount a library component at runtime instead of rendering it
|
|
36
|
+
* from a template. `useConfirm()` creates its own app around NbConfirm, so no
|
|
37
|
+
* template ever names NbConfirm and, before this map, no build linked
|
|
38
|
+
* `Confirm.css`: every confirm dialog rendered unstyled. A spec in
|
|
39
|
+
* `tests/import-plugin.test.ts` reads the composables' own imports and fails
|
|
40
|
+
* if one mounts a component this map does not name.
|
|
41
|
+
*/
|
|
42
|
+
export const PROGRAMMATIC_MOUNTS = {
|
|
43
|
+
useConfirm: ['Confirm'],
|
|
44
|
+
};
|
|
3
45
|
/** The script of a `.vue` file, or the whole module for a plain script. */
|
|
4
46
|
function scriptBlocks(code, file) {
|
|
5
47
|
if (!file.endsWith('.vue'))
|
|
@@ -15,8 +57,9 @@ function scriptBlocks(code, file) {
|
|
|
15
57
|
}));
|
|
16
58
|
}
|
|
17
59
|
export function nubiscoImports(options) {
|
|
18
|
-
const { manifest, styleManifest, styles, packageName, onResolve } = options;
|
|
60
|
+
const { manifest, styleManifest, styles, mounts = {}, packageName, onResolve, } = options;
|
|
19
61
|
const componentPrefix = `${packageName}/components/`;
|
|
62
|
+
const composablePrefix = `${packageName}/composables/`;
|
|
20
63
|
return {
|
|
21
64
|
name: 'nubisco-ui:imports',
|
|
22
65
|
enforce: 'pre',
|
|
@@ -77,8 +120,33 @@ export function nubiscoImports(options) {
|
|
|
77
120
|
}
|
|
78
121
|
continue;
|
|
79
122
|
}
|
|
80
|
-
|
|
123
|
+
/*
|
|
124
|
+
* A composable that mounts a component itself (`useConfirm` creates
|
|
125
|
+
* its own NbConfirm app) links that component's stylesheets, since
|
|
126
|
+
* no template ever names it. Only named value imports can say which
|
|
127
|
+
* export the file uses.
|
|
128
|
+
*/
|
|
129
|
+
let mounted = '';
|
|
130
|
+
if (source === packageName || source.startsWith(composablePrefix)) {
|
|
131
|
+
for (const specifier of node.specifiers) {
|
|
132
|
+
if (specifier.type !== 'ImportSpecifier')
|
|
133
|
+
continue;
|
|
134
|
+
if (specifier.importKind === 'type')
|
|
135
|
+
continue;
|
|
136
|
+
const imported = specifier.imported.name ?? specifier.imported.value;
|
|
137
|
+
for (const entry of mounts[imported] ?? []) {
|
|
138
|
+
resolved += 1;
|
|
139
|
+
mounted += sheetsFor(entry);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (source !== packageName) {
|
|
144
|
+
if (mounted) {
|
|
145
|
+
magic.appendRight(end, mounted);
|
|
146
|
+
changed = true;
|
|
147
|
+
}
|
|
81
148
|
continue;
|
|
149
|
+
}
|
|
82
150
|
const components = [];
|
|
83
151
|
const rest = [];
|
|
84
152
|
let splittable = true;
|
|
@@ -97,8 +165,13 @@ export function nubiscoImports(options) {
|
|
|
97
165
|
}
|
|
98
166
|
components.push({ imported, local });
|
|
99
167
|
}
|
|
100
|
-
if (!splittable || !components.length)
|
|
168
|
+
if (!splittable || !components.length) {
|
|
169
|
+
if (mounted) {
|
|
170
|
+
magic.appendRight(end, mounted);
|
|
171
|
+
changed = true;
|
|
172
|
+
}
|
|
101
173
|
continue;
|
|
174
|
+
}
|
|
102
175
|
const lines = components.map(({ imported, local }) => {
|
|
103
176
|
const entry = manifest.get(imported);
|
|
104
177
|
const binding = imported === local ? imported : `${imported} as ${local}`;
|
|
@@ -106,7 +179,7 @@ export function nubiscoImports(options) {
|
|
|
106
179
|
sheetsFor(entry));
|
|
107
180
|
});
|
|
108
181
|
if (rest.length) {
|
|
109
|
-
lines.push(`import { ${rest.join(', ')} } from '${source}'`);
|
|
182
|
+
lines.push(`import { ${rest.join(', ')} } from '${source}'` + mounted);
|
|
110
183
|
}
|
|
111
184
|
resolved += components.length;
|
|
112
185
|
magic.overwrite(start, end, lines.join('\n'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/vite/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAGlC,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAG/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,UAAU,CAAC,EACP,OAAO,GACP;QACE;;;;WAIG;QACH,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;QACtB,yEAAyE;QACzE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAChB,CAAA;IACL,4EAA4E;IAC5E,MAAM,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AA4BD,wBAAgB,SAAS,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/vite/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAGlC,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAG/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,UAAU,CAAC,EACP,OAAO,GACP;QACE;;;;WAIG;QACH,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;QACtB,yEAAyE;QACzE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAChB,CAAA;IACL,4EAA4E;IAC5E,MAAM,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AA4BD,wBAAgB,SAAS,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,EAAE,CAiInE;AAED,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,YAAY,EAAE,aAAa,EAAE,CAAA;AAC7B,eAAe,SAAS,CAAA"}
|
|
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
4
4
|
import { Components } from './vendor.js';
|
|
5
5
|
import { COMPONENT_MANIFEST } from '../../components/manifest.js';
|
|
6
6
|
import { nubiscoGlyphs } from './glyphs.js';
|
|
7
|
-
import { nubiscoImports } from './imports.js';
|
|
7
|
+
import { nubiscoImports, PROGRAMMATIC_MOUNTS } from './imports.js';
|
|
8
8
|
/** dist/plugins/vite/index.js → dist */
|
|
9
9
|
const defaultDistRoot = () => path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
10
10
|
/** Which stylesheets each component needs, recorded by the library's build. */
|
|
@@ -42,6 +42,7 @@ export function nubiscoUI(options = {}) {
|
|
|
42
42
|
manifest: lookup,
|
|
43
43
|
styleManifest,
|
|
44
44
|
styles,
|
|
45
|
+
mounts: PROGRAMMATIC_MOUNTS,
|
|
45
46
|
packageName: '@nubisco/ui',
|
|
46
47
|
onResolve: (count) => {
|
|
47
48
|
resolvedComponents += count;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubisco/ui",
|
|
3
|
-
"version": "5.47.
|
|
3
|
+
"version": "5.47.1",
|
|
4
4
|
"description": "Vue 3 UI component library",
|
|
5
5
|
"packageManager": "pnpm@12.3.4+sha512.961aa41fb077da3a04a441d9f8e15ebc0c96da8ef710b2eb67bf9ee7cb0610eabd48f1fd85f51cffe73846785fa0f87c56a3a872a1d893f8446741b5cce45457",
|
|
6
6
|
"repository": {
|
|
@@ -34,6 +34,18 @@ import { parse, babelParse } from 'vue/compiler-sfc'
|
|
|
34
34
|
* file actually uses.
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Exports that mount a library component at runtime instead of rendering it
|
|
39
|
+
* from a template. `useConfirm()` creates its own app around NbConfirm, so no
|
|
40
|
+
* template ever names NbConfirm and, before this map, no build linked
|
|
41
|
+
* `Confirm.css`: every confirm dialog rendered unstyled. A spec in
|
|
42
|
+
* `tests/import-plugin.test.ts` reads the composables' own imports and fails
|
|
43
|
+
* if one mounts a component this map does not name.
|
|
44
|
+
*/
|
|
45
|
+
export const PROGRAMMATIC_MOUNTS: Record<string, string[]> = {
|
|
46
|
+
useConfirm: ['Confirm'],
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
interface INubiscoImportOptions {
|
|
38
50
|
/** `Nb*` name to entry file, from the component manifest. */
|
|
39
51
|
manifest: Map<string, string>
|
|
@@ -41,6 +53,12 @@ interface INubiscoImportOptions {
|
|
|
41
53
|
styleManifest: Record<string, string[]>
|
|
42
54
|
/** Inject stylesheets. When false this plugin only rewrites imports. */
|
|
43
55
|
styles: boolean
|
|
56
|
+
/**
|
|
57
|
+
* Exports that mount a component at runtime, mapped to the entries they
|
|
58
|
+
* mount. No template names that component, so neither the resolver nor the
|
|
59
|
+
* rewrite below would otherwise link its stylesheets.
|
|
60
|
+
*/
|
|
61
|
+
mounts?: Record<string, string[]>
|
|
44
62
|
packageName: string
|
|
45
63
|
/** Called with the number of components resolved in a file. */
|
|
46
64
|
onResolve: (count: number) => void
|
|
@@ -70,8 +88,16 @@ interface ISpecifier {
|
|
|
70
88
|
}
|
|
71
89
|
|
|
72
90
|
export function nubiscoImports(options: INubiscoImportOptions) {
|
|
73
|
-
const {
|
|
91
|
+
const {
|
|
92
|
+
manifest,
|
|
93
|
+
styleManifest,
|
|
94
|
+
styles,
|
|
95
|
+
mounts = {},
|
|
96
|
+
packageName,
|
|
97
|
+
onResolve,
|
|
98
|
+
} = options
|
|
74
99
|
const componentPrefix = `${packageName}/components/`
|
|
100
|
+
const composablePrefix = `${packageName}/composables/`
|
|
75
101
|
|
|
76
102
|
return {
|
|
77
103
|
name: 'nubisco-ui:imports',
|
|
@@ -135,7 +161,33 @@ export function nubiscoImports(options: INubiscoImportOptions) {
|
|
|
135
161
|
continue
|
|
136
162
|
}
|
|
137
163
|
|
|
138
|
-
|
|
164
|
+
/*
|
|
165
|
+
* A composable that mounts a component itself (`useConfirm` creates
|
|
166
|
+
* its own NbConfirm app) links that component's stylesheets, since
|
|
167
|
+
* no template ever names it. Only named value imports can say which
|
|
168
|
+
* export the file uses.
|
|
169
|
+
*/
|
|
170
|
+
let mounted = ''
|
|
171
|
+
if (source === packageName || source.startsWith(composablePrefix)) {
|
|
172
|
+
for (const specifier of node.specifiers as any[]) {
|
|
173
|
+
if (specifier.type !== 'ImportSpecifier') continue
|
|
174
|
+
if (specifier.importKind === 'type') continue
|
|
175
|
+
const imported: string =
|
|
176
|
+
specifier.imported.name ?? specifier.imported.value
|
|
177
|
+
for (const entry of mounts[imported] ?? []) {
|
|
178
|
+
resolved += 1
|
|
179
|
+
mounted += sheetsFor(entry)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (source !== packageName) {
|
|
185
|
+
if (mounted) {
|
|
186
|
+
magic.appendRight(end, mounted)
|
|
187
|
+
changed = true
|
|
188
|
+
}
|
|
189
|
+
continue
|
|
190
|
+
}
|
|
139
191
|
|
|
140
192
|
const components: ISpecifier[] = []
|
|
141
193
|
const rest: string[] = []
|
|
@@ -160,7 +212,13 @@ export function nubiscoImports(options: INubiscoImportOptions) {
|
|
|
160
212
|
components.push({ imported, local })
|
|
161
213
|
}
|
|
162
214
|
|
|
163
|
-
if (!splittable || !components.length)
|
|
215
|
+
if (!splittable || !components.length) {
|
|
216
|
+
if (mounted) {
|
|
217
|
+
magic.appendRight(end, mounted)
|
|
218
|
+
changed = true
|
|
219
|
+
}
|
|
220
|
+
continue
|
|
221
|
+
}
|
|
164
222
|
|
|
165
223
|
const lines = components.map(({ imported, local }) => {
|
|
166
224
|
const entry = manifest.get(imported) as string
|
|
@@ -172,7 +230,9 @@ export function nubiscoImports(options: INubiscoImportOptions) {
|
|
|
172
230
|
)
|
|
173
231
|
})
|
|
174
232
|
if (rest.length) {
|
|
175
|
-
lines.push(
|
|
233
|
+
lines.push(
|
|
234
|
+
`import { ${rest.join(', ')} } from '${source}'` + mounted,
|
|
235
|
+
)
|
|
176
236
|
}
|
|
177
237
|
|
|
178
238
|
resolved += components.length
|
|
@@ -5,7 +5,7 @@ import type { Plugin } from 'vite'
|
|
|
5
5
|
import { Components } from './vendor.js'
|
|
6
6
|
import { COMPONENT_MANIFEST } from '../../components/manifest.js'
|
|
7
7
|
import { nubiscoGlyphs, type IGlyphOptions } from './glyphs.js'
|
|
8
|
-
import { nubiscoImports } from './imports.js'
|
|
8
|
+
import { nubiscoImports, PROGRAMMATIC_MOUNTS } from './imports.js'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Compile-time resolution for `@nubisco/ui`.
|
|
@@ -123,6 +123,7 @@ export function nubiscoUI(options: INubiscoUIOptions = {}): Plugin[] {
|
|
|
123
123
|
manifest: lookup,
|
|
124
124
|
styleManifest,
|
|
125
125
|
styles,
|
|
126
|
+
mounts: PROGRAMMATIC_MOUNTS,
|
|
126
127
|
packageName: '@nubisco/ui',
|
|
127
128
|
onResolve: (count) => {
|
|
128
129
|
resolvedComponents += count
|