@typestyles/vite 0.1.1 → 0.2.0
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 +41 -1
- package/dist/index.d.cts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +41 -1
- package/package.json +7 -3
package/dist/index.cjs
CHANGED
|
@@ -24,6 +24,7 @@ __export(index_exports, {
|
|
|
24
24
|
extractNamespaces: () => extractNamespaces
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_build_runner = require("@typestyles/build-runner");
|
|
27
28
|
var STYLES_CREATE_RE = /styles\.create\(\s*['"]([^'"]+)['"]/g;
|
|
28
29
|
var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
|
|
29
30
|
var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
|
|
@@ -59,11 +60,27 @@ function extractNamespaces(code) {
|
|
|
59
60
|
return { keys, prefixes };
|
|
60
61
|
}
|
|
61
62
|
function typestylesPlugin(options = {}) {
|
|
62
|
-
const { warnDuplicates = true } = options;
|
|
63
|
+
const { warnDuplicates = true, mode = "runtime", extract } = options;
|
|
63
64
|
const moduleNamespaces = /* @__PURE__ */ new Map();
|
|
65
|
+
let resolvedConfig = null;
|
|
66
|
+
let isBuildCommand = false;
|
|
64
67
|
return {
|
|
65
68
|
name: "typestyles",
|
|
66
69
|
enforce: "pre",
|
|
70
|
+
config(config, env) {
|
|
71
|
+
isBuildCommand = env.command === "build";
|
|
72
|
+
if (env.command === "build" && (mode === "build" || mode === "hybrid")) {
|
|
73
|
+
config.define = {
|
|
74
|
+
...config.define ?? {},
|
|
75
|
+
// Inlined by the bundler so typestyles sheet skips creating <style> in production
|
|
76
|
+
__TYPESTYLES_RUNTIME_DISABLED__: JSON.stringify("true")
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return config;
|
|
80
|
+
},
|
|
81
|
+
configResolved(config) {
|
|
82
|
+
resolvedConfig = config;
|
|
83
|
+
},
|
|
67
84
|
transform(code, id) {
|
|
68
85
|
if (!/\.[jt]sx?$/.test(id)) return null;
|
|
69
86
|
if (id.includes("node_modules")) return null;
|
|
@@ -99,6 +116,29 @@ if (import.meta.hot) {
|
|
|
99
116
|
code: code + hmrCode,
|
|
100
117
|
map: null
|
|
101
118
|
};
|
|
119
|
+
},
|
|
120
|
+
async generateBundle() {
|
|
121
|
+
if (!isBuildCommand) return;
|
|
122
|
+
if (mode === "runtime") return;
|
|
123
|
+
if (!extract || !extract.modules.length) return;
|
|
124
|
+
if (!resolvedConfig) return;
|
|
125
|
+
const root = resolvedConfig.root ?? process.cwd();
|
|
126
|
+
const fileName = extract.fileName ?? "typestyles.css";
|
|
127
|
+
try {
|
|
128
|
+
const css = await (0, import_build_runner.runTypestylesBuild)({
|
|
129
|
+
root,
|
|
130
|
+
modules: extract.modules
|
|
131
|
+
});
|
|
132
|
+
this.emitFile({
|
|
133
|
+
type: "asset",
|
|
134
|
+
fileName,
|
|
135
|
+
source: css
|
|
136
|
+
});
|
|
137
|
+
} catch (err) {
|
|
138
|
+
this.error(
|
|
139
|
+
`[typestyles] Failed to extract CSS: ${err instanceof Error ? err.message : String(err)}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
102
142
|
}
|
|
103
143
|
};
|
|
104
144
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
+
interface TypestylesExtractOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Modules that should be imported during build to register styles.
|
|
6
|
+
* Paths are resolved relative to Vite's project root.
|
|
7
|
+
*/
|
|
8
|
+
modules: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Output CSS filename (in the build assets). Defaults to "typestyles.css".
|
|
11
|
+
*/
|
|
12
|
+
fileName?: string;
|
|
13
|
+
}
|
|
3
14
|
interface TypestylesPluginOptions {
|
|
4
15
|
/** Warn about duplicate namespaces across modules. Defaults to true. */
|
|
5
16
|
warnDuplicates?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Mode for typestyles integration:
|
|
19
|
+
* - "runtime" (default): HMR only, no build-time extraction.
|
|
20
|
+
* - "build": emit a static CSS asset during build using typestyles/build.
|
|
21
|
+
* - "hybrid": both runtime injection and build-time CSS asset.
|
|
22
|
+
*/
|
|
23
|
+
mode?: 'runtime' | 'build' | 'hybrid';
|
|
24
|
+
/**
|
|
25
|
+
* Options for build-time CSS extraction when mode is "build" or "hybrid".
|
|
26
|
+
*/
|
|
27
|
+
extract?: TypestylesExtractOptions;
|
|
6
28
|
}
|
|
7
29
|
/**
|
|
8
30
|
* Extract namespace information from source code.
|
|
@@ -21,4 +43,4 @@ declare function extractNamespaces(code: string): {
|
|
|
21
43
|
*/
|
|
22
44
|
declare function typestylesPlugin(options?: TypestylesPluginOptions): Plugin;
|
|
23
45
|
|
|
24
|
-
export { type TypestylesPluginOptions, typestylesPlugin as default, extractNamespaces };
|
|
46
|
+
export { type TypestylesExtractOptions, type TypestylesPluginOptions, typestylesPlugin as default, extractNamespaces };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
+
interface TypestylesExtractOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Modules that should be imported during build to register styles.
|
|
6
|
+
* Paths are resolved relative to Vite's project root.
|
|
7
|
+
*/
|
|
8
|
+
modules: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Output CSS filename (in the build assets). Defaults to "typestyles.css".
|
|
11
|
+
*/
|
|
12
|
+
fileName?: string;
|
|
13
|
+
}
|
|
3
14
|
interface TypestylesPluginOptions {
|
|
4
15
|
/** Warn about duplicate namespaces across modules. Defaults to true. */
|
|
5
16
|
warnDuplicates?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Mode for typestyles integration:
|
|
19
|
+
* - "runtime" (default): HMR only, no build-time extraction.
|
|
20
|
+
* - "build": emit a static CSS asset during build using typestyles/build.
|
|
21
|
+
* - "hybrid": both runtime injection and build-time CSS asset.
|
|
22
|
+
*/
|
|
23
|
+
mode?: 'runtime' | 'build' | 'hybrid';
|
|
24
|
+
/**
|
|
25
|
+
* Options for build-time CSS extraction when mode is "build" or "hybrid".
|
|
26
|
+
*/
|
|
27
|
+
extract?: TypestylesExtractOptions;
|
|
6
28
|
}
|
|
7
29
|
/**
|
|
8
30
|
* Extract namespace information from source code.
|
|
@@ -21,4 +43,4 @@ declare function extractNamespaces(code: string): {
|
|
|
21
43
|
*/
|
|
22
44
|
declare function typestylesPlugin(options?: TypestylesPluginOptions): Plugin;
|
|
23
45
|
|
|
24
|
-
export { type TypestylesPluginOptions, typestylesPlugin as default, extractNamespaces };
|
|
46
|
+
export { type TypestylesExtractOptions, type TypestylesPluginOptions, typestylesPlugin as default, extractNamespaces };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { runTypestylesBuild } from "@typestyles/build-runner";
|
|
2
3
|
var STYLES_CREATE_RE = /styles\.create\(\s*['"]([^'"]+)['"]/g;
|
|
3
4
|
var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
|
|
4
5
|
var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
|
|
@@ -34,11 +35,27 @@ function extractNamespaces(code) {
|
|
|
34
35
|
return { keys, prefixes };
|
|
35
36
|
}
|
|
36
37
|
function typestylesPlugin(options = {}) {
|
|
37
|
-
const { warnDuplicates = true } = options;
|
|
38
|
+
const { warnDuplicates = true, mode = "runtime", extract } = options;
|
|
38
39
|
const moduleNamespaces = /* @__PURE__ */ new Map();
|
|
40
|
+
let resolvedConfig = null;
|
|
41
|
+
let isBuildCommand = false;
|
|
39
42
|
return {
|
|
40
43
|
name: "typestyles",
|
|
41
44
|
enforce: "pre",
|
|
45
|
+
config(config, env) {
|
|
46
|
+
isBuildCommand = env.command === "build";
|
|
47
|
+
if (env.command === "build" && (mode === "build" || mode === "hybrid")) {
|
|
48
|
+
config.define = {
|
|
49
|
+
...config.define ?? {},
|
|
50
|
+
// Inlined by the bundler so typestyles sheet skips creating <style> in production
|
|
51
|
+
__TYPESTYLES_RUNTIME_DISABLED__: JSON.stringify("true")
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return config;
|
|
55
|
+
},
|
|
56
|
+
configResolved(config) {
|
|
57
|
+
resolvedConfig = config;
|
|
58
|
+
},
|
|
42
59
|
transform(code, id) {
|
|
43
60
|
if (!/\.[jt]sx?$/.test(id)) return null;
|
|
44
61
|
if (id.includes("node_modules")) return null;
|
|
@@ -74,6 +91,29 @@ if (import.meta.hot) {
|
|
|
74
91
|
code: code + hmrCode,
|
|
75
92
|
map: null
|
|
76
93
|
};
|
|
94
|
+
},
|
|
95
|
+
async generateBundle() {
|
|
96
|
+
if (!isBuildCommand) return;
|
|
97
|
+
if (mode === "runtime") return;
|
|
98
|
+
if (!extract || !extract.modules.length) return;
|
|
99
|
+
if (!resolvedConfig) return;
|
|
100
|
+
const root = resolvedConfig.root ?? process.cwd();
|
|
101
|
+
const fileName = extract.fileName ?? "typestyles.css";
|
|
102
|
+
try {
|
|
103
|
+
const css = await runTypestylesBuild({
|
|
104
|
+
root,
|
|
105
|
+
modules: extract.modules
|
|
106
|
+
});
|
|
107
|
+
this.emitFile({
|
|
108
|
+
type: "asset",
|
|
109
|
+
fileName,
|
|
110
|
+
source: css
|
|
111
|
+
});
|
|
112
|
+
} catch (err) {
|
|
113
|
+
this.error(
|
|
114
|
+
`[typestyles] Failed to extract CSS: ${err instanceof Error ? err.message : String(err)}`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
77
117
|
}
|
|
78
118
|
};
|
|
79
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Vite plugin for typestyles HMR support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -41,10 +41,14 @@
|
|
|
41
41
|
"tsup": "^8.0.0",
|
|
42
42
|
"typescript": "^5.4.0",
|
|
43
43
|
"vite": "^6.0.0",
|
|
44
|
-
"vitest": "^3.0.0"
|
|
44
|
+
"vitest": "^3.0.0",
|
|
45
|
+
"typestyles": "0.4.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@typestyles/build-runner": "0.2.0"
|
|
45
49
|
},
|
|
46
50
|
"scripts": {
|
|
47
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
51
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --external typestyles,@typestyles/build-runner",
|
|
48
52
|
"test": "vitest run",
|
|
49
53
|
"typecheck": "tsc --noEmit"
|
|
50
54
|
}
|