@typestyles/vite 0.6.0 → 0.7.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/index.cjs +55 -7
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +56 -8
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -87,7 +87,7 @@ function formatUnextractedRecipeError(missing, extractEntries) {
|
|
|
87
87
|
].join("\n");
|
|
88
88
|
}
|
|
89
89
|
function typestylesPlugin(options = {}) {
|
|
90
|
-
const { warnDuplicates = true, coverage = true, extract } = options;
|
|
90
|
+
const { warnDuplicates = true, coverage = true, extract, compile = false } = options;
|
|
91
91
|
let resolvedExtractModules = [];
|
|
92
92
|
let resolvedMode = "runtime";
|
|
93
93
|
const moduleNamespaces = new Map();
|
|
@@ -97,8 +97,19 @@ function typestylesPlugin(options = {}) {
|
|
|
97
97
|
const recipeModules = new Map();
|
|
98
98
|
let devExtractCss = null;
|
|
99
99
|
let devExtractInFlight = null;
|
|
100
|
+
let extraction = null;
|
|
101
|
+
let planIndex = null;
|
|
102
|
+
function extractOnce(root) {
|
|
103
|
+
extraction ??= (0, _typestyles_build_runner.runTypestylesExtract)({
|
|
104
|
+
root,
|
|
105
|
+
modules: resolvedExtractModules,
|
|
106
|
+
sourceComments: extract?.sourceComments
|
|
107
|
+
});
|
|
108
|
+
return extraction;
|
|
109
|
+
}
|
|
110
|
+
const compileEnabled = () => compile && isBuildCommand && resolvedMode === "build" && !resolvedConfig?.build?.ssr && resolvedExtractModules.length > 0;
|
|
100
111
|
let builtCssFileName = null;
|
|
101
|
-
|
|
112
|
+
const main = {
|
|
102
113
|
name: "typestyles",
|
|
103
114
|
enforce: "pre",
|
|
104
115
|
config(config, env) {
|
|
@@ -111,6 +122,25 @@ function typestylesPlugin(options = {}) {
|
|
|
111
122
|
};
|
|
112
123
|
return config;
|
|
113
124
|
},
|
|
125
|
+
async resolveId(source, importer, resolveOptions) {
|
|
126
|
+
if (!isBuildCommand || resolvedMode !== "build" || !(0, _typestyles_build_runner.isSheetRequest)(source)) return null;
|
|
127
|
+
if (resolveOptions?.ssr) return null;
|
|
128
|
+
const resolved = await this.resolve(source, importer, {
|
|
129
|
+
...resolveOptions,
|
|
130
|
+
skipSelf: true
|
|
131
|
+
});
|
|
132
|
+
if (!resolved) return null;
|
|
133
|
+
const noop = (0, _typestyles_build_runner.toZeroRuntimeSheetId)(resolved.id);
|
|
134
|
+
return noop ? {
|
|
135
|
+
...resolved,
|
|
136
|
+
id: noop
|
|
137
|
+
} : null;
|
|
138
|
+
},
|
|
139
|
+
async buildStart() {
|
|
140
|
+
extraction = null;
|
|
141
|
+
planIndex = null;
|
|
142
|
+
if (compileEnabled()) await extractOnce(resolvedConfig?.root ?? process.cwd());
|
|
143
|
+
},
|
|
114
144
|
configResolved(config) {
|
|
115
145
|
resolvedConfig = config;
|
|
116
146
|
isServe = config.command === "serve";
|
|
@@ -244,6 +274,14 @@ if (import.meta.hot) {
|
|
|
244
274
|
},
|
|
245
275
|
async generateBundle(_options, bundle) {
|
|
246
276
|
if (!isBuildCommand) return;
|
|
277
|
+
if (resolvedMode === "build" && !resolvedConfig?.build?.ssr) {
|
|
278
|
+
const leaked = (0, _typestyles_build_runner.findRealSheetModules)(Object.values(bundle ?? {}).flatMap((chunk) => chunk.type === "chunk" ? Object.keys(chunk.modules) : []));
|
|
279
|
+
if (leaked.length > 0) this.warn((0, _typestyles_build_runner.zeroRuntimeLeakMessage)(leaked));
|
|
280
|
+
if (compileEnabled()) {
|
|
281
|
+
const warning = (0, _typestyles_build_runner.lingeringRuntimeWarning)(bundle ?? {}, (id) => this.getModuleInfo(id)?.importers, resolvedConfig?.root ?? process.cwd());
|
|
282
|
+
if (warning) this.warn(warning);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
247
285
|
if (resolvedMode === "runtime") return;
|
|
248
286
|
if (!resolvedExtractModules.length) return;
|
|
249
287
|
if (!resolvedConfig) return;
|
|
@@ -270,11 +308,7 @@ if (import.meta.hot) {
|
|
|
270
308
|
}
|
|
271
309
|
}
|
|
272
310
|
try {
|
|
273
|
-
const css = await (
|
|
274
|
-
root,
|
|
275
|
-
modules: resolvedExtractModules,
|
|
276
|
-
sourceComments: extract?.sourceComments
|
|
277
|
-
});
|
|
311
|
+
const { css } = await extractOnce(root);
|
|
278
312
|
if (requestedFileName && cssFileNameHasPlaceholder(requestedFileName)) {
|
|
279
313
|
builtCssFileName = renderCssFileName(requestedFileName, css);
|
|
280
314
|
this.emitFile({
|
|
@@ -304,6 +338,20 @@ if (import.meta.hot) {
|
|
|
304
338
|
}
|
|
305
339
|
}
|
|
306
340
|
};
|
|
341
|
+
if (!compile) return main;
|
|
342
|
+
return [main, {
|
|
343
|
+
name: "typestyles:compile",
|
|
344
|
+
apply: "build",
|
|
345
|
+
enforce: "post",
|
|
346
|
+
async transform(code, id) {
|
|
347
|
+
if (!compileEnabled() || !(0, _typestyles_build_runner.isTransformableId)(id)) return null;
|
|
348
|
+
planIndex ??= (0, _typestyles_build_runner.indexPlans)((await extractOnce(resolvedConfig?.root ?? process.cwd())).plans);
|
|
349
|
+
return (0, _typestyles_build_runner.transformRecipeCalls)(code, planIndex, (source) => this.parse(source), id);
|
|
350
|
+
},
|
|
351
|
+
shouldTransformCachedModule({ code }) {
|
|
352
|
+
return compileEnabled() && (0, _typestyles_build_runner.mayNeedRecompile)(code);
|
|
353
|
+
}
|
|
354
|
+
}];
|
|
307
355
|
}
|
|
308
356
|
//#endregion
|
|
309
357
|
Object.defineProperty(exports, "DEFAULT_EXTRACT_MODULE_CANDIDATES", {
|
package/dist/index.d.cts
CHANGED
|
@@ -50,6 +50,14 @@ export interface TypestylesPluginOptions {
|
|
|
50
50
|
* {@link discoverDefaultExtractModules}); if none exist, stays in runtime-only mode.
|
|
51
51
|
*/
|
|
52
52
|
extract?: TypestylesExtractOptions;
|
|
53
|
+
/**
|
|
54
|
+
* Experimental. In `"build"` mode on client builds, replace `recipe()` definitions with
|
|
55
|
+
* the small call-behavior plans recorded during extraction, so the style configs, token
|
|
56
|
+
* tables and CSS machinery they reference tree-shake out of the client bundle. Class
|
|
57
|
+
* names and `data-*` attributes are unchanged. Calls whose behavior can't be planned keep
|
|
58
|
+
* the runtime. Returns an array of two plugins when `true`.
|
|
59
|
+
*/
|
|
60
|
+
compile?: boolean;
|
|
53
61
|
}
|
|
54
62
|
/** Public URL path for the extracted CSS asset (respects Vite `base`). */
|
|
55
63
|
export declare function resolveTypestylesCssHref(base: string, fileName: string,
|
|
@@ -65,6 +73,9 @@ export declare function htmlLinksTypestylesCss(html: string, cssHref: string, fi
|
|
|
65
73
|
* before re-execution. Files may import from a local re-export such as `./typestyles` rather
|
|
66
74
|
* than `from 'typestyles'` directly — we key off API call patterns in the source, not the import path.
|
|
67
75
|
*/
|
|
68
|
-
|
|
76
|
+
declare function typestylesPlugin(options: TypestylesPluginOptions & {
|
|
77
|
+
compile: true;
|
|
78
|
+
}): Plugin[];
|
|
79
|
+
declare function typestylesPlugin(options?: TypestylesPluginOptions): Plugin;
|
|
69
80
|
//#endregion
|
|
70
|
-
export { DEFAULT_EXTRACT_MODULE_CANDIDATES, type TypestylesExtractOptions, discoverDefaultExtractModules, extractNamespaces, moduleNeedsOverrideHmr };
|
|
81
|
+
export { DEFAULT_EXTRACT_MODULE_CANDIDATES, type TypestylesExtractOptions, typestylesPlugin as default, discoverDefaultExtractModules, extractNamespaces, moduleNeedsOverrideHmr };
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,14 @@ export interface TypestylesPluginOptions {
|
|
|
50
50
|
* {@link discoverDefaultExtractModules}); if none exist, stays in runtime-only mode.
|
|
51
51
|
*/
|
|
52
52
|
extract?: TypestylesExtractOptions;
|
|
53
|
+
/**
|
|
54
|
+
* Experimental. In `"build"` mode on client builds, replace `recipe()` definitions with
|
|
55
|
+
* the small call-behavior plans recorded during extraction, so the style configs, token
|
|
56
|
+
* tables and CSS machinery they reference tree-shake out of the client bundle. Class
|
|
57
|
+
* names and `data-*` attributes are unchanged. Calls whose behavior can't be planned keep
|
|
58
|
+
* the runtime. Returns an array of two plugins when `true`.
|
|
59
|
+
*/
|
|
60
|
+
compile?: boolean;
|
|
53
61
|
}
|
|
54
62
|
/** Public URL path for the extracted CSS asset (respects Vite `base`). */
|
|
55
63
|
export declare function resolveTypestylesCssHref(base: string, fileName: string,
|
|
@@ -65,6 +73,9 @@ export declare function htmlLinksTypestylesCss(html: string, cssHref: string, fi
|
|
|
65
73
|
* before re-execution. Files may import from a local re-export such as `./typestyles` rather
|
|
66
74
|
* than `from 'typestyles'` directly — we key off API call patterns in the source, not the import path.
|
|
67
75
|
*/
|
|
68
|
-
|
|
76
|
+
declare function typestylesPlugin(options: TypestylesPluginOptions & {
|
|
77
|
+
compile: true;
|
|
78
|
+
}): Plugin[];
|
|
79
|
+
declare function typestylesPlugin(options?: TypestylesPluginOptions): Plugin;
|
|
69
80
|
//#endregion
|
|
70
|
-
export { DEFAULT_EXTRACT_MODULE_CANDIDATES, type TypestylesExtractOptions, discoverDefaultExtractModules, extractNamespaces, moduleNeedsOverrideHmr };
|
|
81
|
+
export { DEFAULT_EXTRACT_MODULE_CANDIDATES, type TypestylesExtractOptions, typestylesPlugin as default, discoverDefaultExtractModules, extractNamespaces, moduleNeedsOverrideHmr };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { posix, resolve } from "node:path";
|
|
3
|
-
import { DEFAULT_EXTRACT_MODULE_CANDIDATES, discoverDefaultExtractModules, extractNamespaces, findUnextractedRecipes, moduleNeedsOverrideHmr, moduleNeedsOverrideHmr as moduleNeedsOverrideHmr$1, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild } from "@typestyles/build-runner";
|
|
3
|
+
import { DEFAULT_EXTRACT_MODULE_CANDIDATES, discoverDefaultExtractModules, extractNamespaces, findRealSheetModules, findUnextractedRecipes, indexPlans, isSheetRequest, isTransformableId, lingeringRuntimeWarning, mayNeedRecompile, moduleNeedsOverrideHmr, moduleNeedsOverrideHmr as moduleNeedsOverrideHmr$1, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild, runTypestylesExtract, toZeroRuntimeSheetId, transformRecipeCalls, zeroRuntimeLeakMessage } from "@typestyles/build-runner";
|
|
4
4
|
//#region src/index.ts
|
|
5
5
|
function resolveExtractModulesForVite(root, extract) {
|
|
6
6
|
return resolveExtractModules(root, extract);
|
|
@@ -83,7 +83,7 @@ function formatUnextractedRecipeError(missing, extractEntries) {
|
|
|
83
83
|
].join("\n");
|
|
84
84
|
}
|
|
85
85
|
function typestylesPlugin(options = {}) {
|
|
86
|
-
const { warnDuplicates = true, coverage = true, extract } = options;
|
|
86
|
+
const { warnDuplicates = true, coverage = true, extract, compile = false } = options;
|
|
87
87
|
let resolvedExtractModules = [];
|
|
88
88
|
let resolvedMode = "runtime";
|
|
89
89
|
const moduleNamespaces = new Map();
|
|
@@ -93,8 +93,19 @@ function typestylesPlugin(options = {}) {
|
|
|
93
93
|
const recipeModules = new Map();
|
|
94
94
|
let devExtractCss = null;
|
|
95
95
|
let devExtractInFlight = null;
|
|
96
|
+
let extraction = null;
|
|
97
|
+
let planIndex = null;
|
|
98
|
+
function extractOnce(root) {
|
|
99
|
+
extraction ??= runTypestylesExtract({
|
|
100
|
+
root,
|
|
101
|
+
modules: resolvedExtractModules,
|
|
102
|
+
sourceComments: extract?.sourceComments
|
|
103
|
+
});
|
|
104
|
+
return extraction;
|
|
105
|
+
}
|
|
106
|
+
const compileEnabled = () => compile && isBuildCommand && resolvedMode === "build" && !resolvedConfig?.build?.ssr && resolvedExtractModules.length > 0;
|
|
96
107
|
let builtCssFileName = null;
|
|
97
|
-
|
|
108
|
+
const main = {
|
|
98
109
|
name: "typestyles",
|
|
99
110
|
enforce: "pre",
|
|
100
111
|
config(config, env) {
|
|
@@ -107,6 +118,25 @@ function typestylesPlugin(options = {}) {
|
|
|
107
118
|
};
|
|
108
119
|
return config;
|
|
109
120
|
},
|
|
121
|
+
async resolveId(source, importer, resolveOptions) {
|
|
122
|
+
if (!isBuildCommand || resolvedMode !== "build" || !isSheetRequest(source)) return null;
|
|
123
|
+
if (resolveOptions?.ssr) return null;
|
|
124
|
+
const resolved = await this.resolve(source, importer, {
|
|
125
|
+
...resolveOptions,
|
|
126
|
+
skipSelf: true
|
|
127
|
+
});
|
|
128
|
+
if (!resolved) return null;
|
|
129
|
+
const noop = toZeroRuntimeSheetId(resolved.id);
|
|
130
|
+
return noop ? {
|
|
131
|
+
...resolved,
|
|
132
|
+
id: noop
|
|
133
|
+
} : null;
|
|
134
|
+
},
|
|
135
|
+
async buildStart() {
|
|
136
|
+
extraction = null;
|
|
137
|
+
planIndex = null;
|
|
138
|
+
if (compileEnabled()) await extractOnce(resolvedConfig?.root ?? process.cwd());
|
|
139
|
+
},
|
|
110
140
|
configResolved(config) {
|
|
111
141
|
resolvedConfig = config;
|
|
112
142
|
isServe = config.command === "serve";
|
|
@@ -240,6 +270,14 @@ if (import.meta.hot) {
|
|
|
240
270
|
},
|
|
241
271
|
async generateBundle(_options, bundle) {
|
|
242
272
|
if (!isBuildCommand) return;
|
|
273
|
+
if (resolvedMode === "build" && !resolvedConfig?.build?.ssr) {
|
|
274
|
+
const leaked = findRealSheetModules(Object.values(bundle ?? {}).flatMap((chunk) => chunk.type === "chunk" ? Object.keys(chunk.modules) : []));
|
|
275
|
+
if (leaked.length > 0) this.warn(zeroRuntimeLeakMessage(leaked));
|
|
276
|
+
if (compileEnabled()) {
|
|
277
|
+
const warning = lingeringRuntimeWarning(bundle ?? {}, (id) => this.getModuleInfo(id)?.importers, resolvedConfig?.root ?? process.cwd());
|
|
278
|
+
if (warning) this.warn(warning);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
243
281
|
if (resolvedMode === "runtime") return;
|
|
244
282
|
if (!resolvedExtractModules.length) return;
|
|
245
283
|
if (!resolvedConfig) return;
|
|
@@ -266,11 +304,7 @@ if (import.meta.hot) {
|
|
|
266
304
|
}
|
|
267
305
|
}
|
|
268
306
|
try {
|
|
269
|
-
const css = await
|
|
270
|
-
root,
|
|
271
|
-
modules: resolvedExtractModules,
|
|
272
|
-
sourceComments: extract?.sourceComments
|
|
273
|
-
});
|
|
307
|
+
const { css } = await extractOnce(root);
|
|
274
308
|
if (requestedFileName && cssFileNameHasPlaceholder(requestedFileName)) {
|
|
275
309
|
builtCssFileName = renderCssFileName(requestedFileName, css);
|
|
276
310
|
this.emitFile({
|
|
@@ -300,6 +334,20 @@ if (import.meta.hot) {
|
|
|
300
334
|
}
|
|
301
335
|
}
|
|
302
336
|
};
|
|
337
|
+
if (!compile) return main;
|
|
338
|
+
return [main, {
|
|
339
|
+
name: "typestyles:compile",
|
|
340
|
+
apply: "build",
|
|
341
|
+
enforce: "post",
|
|
342
|
+
async transform(code, id) {
|
|
343
|
+
if (!compileEnabled() || !isTransformableId(id)) return null;
|
|
344
|
+
planIndex ??= indexPlans((await extractOnce(resolvedConfig?.root ?? process.cwd())).plans);
|
|
345
|
+
return transformRecipeCalls(code, planIndex, (source) => this.parse(source), id);
|
|
346
|
+
},
|
|
347
|
+
shouldTransformCachedModule({ code }) {
|
|
348
|
+
return compileEnabled() && mayNeedRecompile(code);
|
|
349
|
+
}
|
|
350
|
+
}];
|
|
303
351
|
}
|
|
304
352
|
//#endregion
|
|
305
353
|
export { DEFAULT_EXTRACT_MODULE_CANDIDATES, typestylesPlugin as default, discoverDefaultExtractModules, extractNamespaces, htmlLinksTypestylesCss, moduleNeedsOverrideHmr, resolveTypestylesCssHref };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Vite plugin for typestyles HMR support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"typescript": "^6.0.0",
|
|
42
42
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
|
|
43
43
|
"vite-plus": "1.3.0",
|
|
44
|
-
"typestyles": "0.
|
|
44
|
+
"typestyles": "0.35.2"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@typestyles/build-runner": "0.
|
|
47
|
+
"@typestyles/build-runner": "0.8.1"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "vp pack",
|