@pikacss/unplugin-pikacss 0.0.49 → 0.0.51
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/README.md +1 -1
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +51 -3
- package/dist/vite.d.mts +2 -0
- package/dist/vite.mjs +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -15,6 +15,9 @@ export * from "@pikacss/integration";
|
|
|
15
15
|
* This is the core entry-point called by `createUnplugin`. It resolves user options,
|
|
16
16
|
* creates an integration context via `createCtx`, and wires bundler-specific lifecycle
|
|
17
17
|
* hooks (config resolution, dev-server HMR, build transforms, and config file watching).
|
|
18
|
+
* When consumed through the Vite entry, the plugin also declares `enforce: 'pre'`
|
|
19
|
+
* so PikaCSS transforms run before framework compiler plugins even if the user's
|
|
20
|
+
* Vite `plugins` array lists `vue()` before `pikacss()`.
|
|
18
21
|
*
|
|
19
22
|
* @example
|
|
20
23
|
* ```ts
|
package/dist/index.mjs
CHANGED
|
@@ -19,6 +19,9 @@ const PLUGIN_NAME = "unplugin-pikacss";
|
|
|
19
19
|
* This is the core entry-point called by `createUnplugin`. It resolves user options,
|
|
20
20
|
* creates an integration context via `createCtx`, and wires bundler-specific lifecycle
|
|
21
21
|
* hooks (config resolution, dev-server HMR, build transforms, and config file watching).
|
|
22
|
+
* When consumed through the Vite entry, the plugin also declares `enforce: 'pre'`
|
|
23
|
+
* so PikaCSS transforms run before framework compiler plugins even if the user's
|
|
24
|
+
* Vite `plugins` array lists `vue()` before `pikacss()`.
|
|
22
25
|
*
|
|
23
26
|
* @example
|
|
24
27
|
* ```ts
|
|
@@ -62,17 +65,52 @@ const unpluginFactory = (options, meta) => {
|
|
|
62
65
|
const debouncedWriteTsCodegenFile = debounce(async () => {
|
|
63
66
|
await ctx.writeTsCodegenFile();
|
|
64
67
|
}, 300);
|
|
68
|
+
let activeTransforms = 0;
|
|
69
|
+
let pendingCssWrite = false;
|
|
70
|
+
let pendingTsWrite = false;
|
|
71
|
+
let generatedWritePromise = Promise.resolve();
|
|
72
|
+
function flushPendingGeneratedWrites() {
|
|
73
|
+
generatedWritePromise = generatedWritePromise.catch(() => {}).then(async () => {
|
|
74
|
+
if (activeTransforms > 0) return;
|
|
75
|
+
const shouldWriteCss = pendingCssWrite;
|
|
76
|
+
const shouldWriteTs = pendingTsWrite;
|
|
77
|
+
pendingCssWrite = false;
|
|
78
|
+
pendingTsWrite = false;
|
|
79
|
+
if (shouldWriteCss) try {
|
|
80
|
+
await debouncedWriteCssCodegenFile();
|
|
81
|
+
} catch (error) {
|
|
82
|
+
pendingCssWrite = true;
|
|
83
|
+
if (shouldWriteTs) pendingTsWrite = true;
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
if (shouldWriteTs) try {
|
|
87
|
+
await debouncedWriteTsCodegenFile();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
pendingTsWrite = true;
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return generatedWritePromise;
|
|
94
|
+
}
|
|
95
|
+
function queueCssWrite() {
|
|
96
|
+
pendingCssWrite = true;
|
|
97
|
+
return flushPendingGeneratedWrites();
|
|
98
|
+
}
|
|
99
|
+
function queueTsWrite() {
|
|
100
|
+
pendingTsWrite = true;
|
|
101
|
+
return flushPendingGeneratedWrites();
|
|
102
|
+
}
|
|
65
103
|
let hooksBound = false;
|
|
66
104
|
function bindHooks() {
|
|
67
105
|
if (hooksBound) return;
|
|
68
106
|
hooksBound = true;
|
|
69
107
|
ctx.hooks.styleUpdated.on(() => {
|
|
70
108
|
log.debug(`Style updated, ${ctx.engine.store.atomicStyleIds.size} atomic styles generated`);
|
|
71
|
-
|
|
109
|
+
return queueCssWrite();
|
|
72
110
|
});
|
|
73
111
|
ctx.hooks.tsCodegenUpdated.on(() => {
|
|
74
112
|
log.debug("TypeScript code generation updated");
|
|
75
|
-
|
|
113
|
+
return queueTsWrite();
|
|
76
114
|
});
|
|
77
115
|
}
|
|
78
116
|
let setupPromise = Promise.resolve();
|
|
@@ -83,6 +121,9 @@ const unpluginFactory = (options, meta) => {
|
|
|
83
121
|
setupPromise = setupPromise.then(async () => {
|
|
84
122
|
log.debug("Setting up integration context...");
|
|
85
123
|
const moduleIds = Array.from(ctx.usages.keys());
|
|
124
|
+
activeTransforms = 0;
|
|
125
|
+
pendingCssWrite = false;
|
|
126
|
+
pendingTsWrite = false;
|
|
86
127
|
hooksBound = false;
|
|
87
128
|
await ctx.setup();
|
|
88
129
|
lastSetupCwd = ctx.cwd;
|
|
@@ -121,6 +162,7 @@ const unpluginFactory = (options, meta) => {
|
|
|
121
162
|
const debouncedSetup = debounce(setup);
|
|
122
163
|
return {
|
|
123
164
|
name: PLUGIN_NAME,
|
|
165
|
+
enforce: "pre",
|
|
124
166
|
vite: {
|
|
125
167
|
configResolved: (config) => {
|
|
126
168
|
applyRuntimeContext(config.root, config.command === "serve" ? "serve" : "build");
|
|
@@ -173,11 +215,17 @@ const unpluginFactory = (options, meta) => {
|
|
|
173
215
|
} },
|
|
174
216
|
async handler(code, id) {
|
|
175
217
|
await ensureSetup();
|
|
218
|
+
activeTransforms++;
|
|
176
219
|
if (meta.framework === "webpack" && ctx.resolvedConfigPath != null) {
|
|
177
220
|
this.addWatchFile(ctx.resolvedConfigPath);
|
|
178
221
|
log.debug(`Added watch file: ${ctx.resolvedConfigPath}`);
|
|
179
222
|
}
|
|
180
|
-
|
|
223
|
+
try {
|
|
224
|
+
return await ctx.transform(code, id);
|
|
225
|
+
} finally {
|
|
226
|
+
if (activeTransforms > 0) activeTransforms--;
|
|
227
|
+
if (activeTransforms === 0) await flushPendingGeneratedWrites();
|
|
228
|
+
}
|
|
181
229
|
}
|
|
182
230
|
},
|
|
183
231
|
watchChange(id) {
|
package/dist/vite.d.mts
CHANGED
|
@@ -9,6 +9,8 @@ export * from "@pikacss/integration";
|
|
|
9
9
|
* Wraps the shared PikaCSS unplugin factory into a Vite-compatible plugin.
|
|
10
10
|
* Accepts optional {@link PluginOptions} to configure scanning, code
|
|
11
11
|
* generation, and engine settings. Returns a standard Vite `Plugin`.
|
|
12
|
+
* The plugin declares `enforce: 'pre'`, so PikaCSS template transforms run
|
|
13
|
+
* before framework compiler plugins regardless of the user's `plugins` order.
|
|
12
14
|
*
|
|
13
15
|
* @example
|
|
14
16
|
* ```ts
|
package/dist/vite.mjs
CHANGED
|
@@ -8,6 +8,8 @@ export * from "@pikacss/integration";
|
|
|
8
8
|
* Wraps the shared PikaCSS unplugin factory into a Vite-compatible plugin.
|
|
9
9
|
* Accepts optional {@link PluginOptions} to configure scanning, code
|
|
10
10
|
* generation, and engine settings. Returns a standard Vite `Plugin`.
|
|
11
|
+
* The plugin declares `enforce: 'pre'`, so PikaCSS template transforms run
|
|
12
|
+
* before framework compiler plugins regardless of the user's `plugins` order.
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
13
15
|
* ```ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikacss/unplugin-pikacss",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.51",
|
|
5
5
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://pikacss.com",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"pathe": "^2.0.3",
|
|
95
95
|
"perfect-debounce": "^2.1.0",
|
|
96
96
|
"unplugin": "^3.0.0",
|
|
97
|
-
"@pikacss/integration": "0.0.
|
|
97
|
+
"@pikacss/integration": "0.0.51"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"esbuild": "^0.27.4",
|