@pikacss/unplugin-pikacss 0.0.50 → 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 CHANGED
@@ -36,7 +36,7 @@ import pikacss from '@pikacss/unplugin-pikacss/webpack'
36
36
 
37
37
  ## Documentation
38
38
 
39
- See the [full documentation](https://pikacss.com/guide/integrations/vite).
39
+ See the [full documentation](https://pikacss.com/integrations/unplugin).
40
40
 
41
41
  ## License
42
42
 
package/dist/index.mjs CHANGED
@@ -65,17 +65,52 @@ const unpluginFactory = (options, meta) => {
65
65
  const debouncedWriteTsCodegenFile = debounce(async () => {
66
66
  await ctx.writeTsCodegenFile();
67
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
+ }
68
103
  let hooksBound = false;
69
104
  function bindHooks() {
70
105
  if (hooksBound) return;
71
106
  hooksBound = true;
72
107
  ctx.hooks.styleUpdated.on(() => {
73
108
  log.debug(`Style updated, ${ctx.engine.store.atomicStyleIds.size} atomic styles generated`);
74
- debouncedWriteCssCodegenFile();
109
+ return queueCssWrite();
75
110
  });
76
111
  ctx.hooks.tsCodegenUpdated.on(() => {
77
112
  log.debug("TypeScript code generation updated");
78
- debouncedWriteTsCodegenFile();
113
+ return queueTsWrite();
79
114
  });
80
115
  }
81
116
  let setupPromise = Promise.resolve();
@@ -86,6 +121,9 @@ const unpluginFactory = (options, meta) => {
86
121
  setupPromise = setupPromise.then(async () => {
87
122
  log.debug("Setting up integration context...");
88
123
  const moduleIds = Array.from(ctx.usages.keys());
124
+ activeTransforms = 0;
125
+ pendingCssWrite = false;
126
+ pendingTsWrite = false;
89
127
  hooksBound = false;
90
128
  await ctx.setup();
91
129
  lastSetupCwd = ctx.cwd;
@@ -177,11 +215,17 @@ const unpluginFactory = (options, meta) => {
177
215
  } },
178
216
  async handler(code, id) {
179
217
  await ensureSetup();
218
+ activeTransforms++;
180
219
  if (meta.framework === "webpack" && ctx.resolvedConfigPath != null) {
181
220
  this.addWatchFile(ctx.resolvedConfigPath);
182
221
  log.debug(`Added watch file: ${ctx.resolvedConfigPath}`);
183
222
  }
184
- return ctx.transform(code, id);
223
+ try {
224
+ return await ctx.transform(code, id);
225
+ } finally {
226
+ if (activeTransforms > 0) activeTransforms--;
227
+ if (activeTransforms === 0) await flushPendingGeneratedWrites();
228
+ }
185
229
  }
186
230
  },
187
231
  watchChange(id) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pikacss/unplugin-pikacss",
3
3
  "type": "module",
4
- "version": "0.0.50",
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.50"
97
+ "@pikacss/integration": "0.0.51"
98
98
  },
99
99
  "devDependencies": {
100
100
  "esbuild": "^0.27.4",