@pikacss/integration 0.0.14 → 0.0.16
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 +40 -23
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +41 -24
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const localPkg = require('local-pkg');
|
|
|
8
8
|
const MagicString = require('magic-string');
|
|
9
9
|
const micromatch = require('micromatch');
|
|
10
10
|
const pathe = require('pathe');
|
|
11
|
+
const perfectDebounce = require('perfect-debounce');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
13
14
|
|
|
@@ -118,7 +119,7 @@ function generateVueDeclaration(ctx) {
|
|
|
118
119
|
""
|
|
119
120
|
];
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
+
function generateOverloadContent(ctx) {
|
|
122
123
|
const paramsLines = [];
|
|
123
124
|
const fnsLines = [];
|
|
124
125
|
const usages = [...ctx.usages.values()].flat();
|
|
@@ -153,7 +154,7 @@ async function generateOverloadContent(ctx) {
|
|
|
153
154
|
...paramsLines
|
|
154
155
|
];
|
|
155
156
|
}
|
|
156
|
-
|
|
157
|
+
function generateTsCodegenContent(ctx) {
|
|
157
158
|
const lines = [
|
|
158
159
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
159
160
|
`import type { CSSProperty, CSSSelectors, DefineAutocomplete, Properties, StyleDefinition, StyleItem } from '${ctx.currentPackageName}'`,
|
|
@@ -174,7 +175,7 @@ async function generateTsCodegenContent(ctx) {
|
|
|
174
175
|
lines.push(...generateStyleFn(ctx));
|
|
175
176
|
lines.push(...generateGlobalDeclaration(ctx));
|
|
176
177
|
lines.push(...generateVueDeclaration(ctx));
|
|
177
|
-
lines.push(...
|
|
178
|
+
lines.push(...generateOverloadContent(ctx));
|
|
178
179
|
return lines.join("\n");
|
|
179
180
|
}
|
|
180
181
|
|
|
@@ -296,7 +297,7 @@ async function createCtx(options) {
|
|
|
296
297
|
const config = await jiti$1.import(resolvedConfigPath, { default: true });
|
|
297
298
|
return { config, file: resolvedConfigPath };
|
|
298
299
|
},
|
|
299
|
-
init: async () => {
|
|
300
|
+
init: perfectDebounce.debounce(async () => {
|
|
300
301
|
ctx.isReady = false;
|
|
301
302
|
ctx.usages.clear();
|
|
302
303
|
const { config, file } = await ctx.loadConfig().catch((error) => {
|
|
@@ -304,18 +305,21 @@ async function createCtx(options) {
|
|
|
304
305
|
return { config: null, file: null };
|
|
305
306
|
});
|
|
306
307
|
ctx.resolvedConfigPath = file;
|
|
307
|
-
|
|
308
|
-
ctx.engine = await core.createEngine(config ?? {});
|
|
309
|
-
} catch (error) {
|
|
310
|
-
core.warn(`Failed to create engine: ${error.message}. Maybe the config file is invalid, falling back to default config.`, error);
|
|
311
|
-
ctx.engine = await core.createEngine({});
|
|
312
|
-
}
|
|
313
|
-
ctx.engine.config.plugins.unshift({
|
|
308
|
+
const devPlugin = core.defineEnginePlugin({
|
|
314
309
|
name: "@pikacss/integration:dev",
|
|
315
310
|
preflightUpdated: () => ctx.hooks.styleUpdated.trigger(),
|
|
316
311
|
atomicStyleAdded: () => ctx.hooks.styleUpdated.trigger(),
|
|
317
312
|
autocompleteConfigUpdated: () => ctx.hooks.tsCodegenUpdated.trigger()
|
|
318
313
|
});
|
|
314
|
+
try {
|
|
315
|
+
const _config = config ?? {};
|
|
316
|
+
_config.plugins = _config.plugins ?? [];
|
|
317
|
+
_config.plugins.unshift(devPlugin);
|
|
318
|
+
ctx.engine = await core.createEngine(_config);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
core.warn(`Failed to create engine: ${error.message}. Maybe the config file is invalid, falling back to default config.`, error);
|
|
321
|
+
ctx.engine = await core.createEngine({ plugins: [devPlugin] });
|
|
322
|
+
}
|
|
319
323
|
await promises.mkdir(pathe.dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
320
324
|
});
|
|
321
325
|
const isDevCssFileExists = await promises.stat(devCssFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
@@ -326,12 +330,12 @@ async function createCtx(options) {
|
|
|
326
330
|
});
|
|
327
331
|
const isGenTsFileExists = await promises.stat(tsCodegenFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
328
332
|
if (isGenTsFileExists === false) {
|
|
329
|
-
const content =
|
|
333
|
+
const content = generateTsCodegenContent(ctx);
|
|
330
334
|
await promises.writeFile(tsCodegenFilepath, content);
|
|
331
335
|
}
|
|
332
336
|
}
|
|
333
337
|
ctx.isReady = true;
|
|
334
|
-
},
|
|
338
|
+
}, 300),
|
|
335
339
|
isReady: false,
|
|
336
340
|
configSources,
|
|
337
341
|
resolvedConfigPath: null,
|
|
@@ -346,7 +350,6 @@ async function createCtx(options) {
|
|
|
346
350
|
if (functionCalls.length === 0)
|
|
347
351
|
return;
|
|
348
352
|
const usages = [];
|
|
349
|
-
ctx.usages.set(id, usages);
|
|
350
353
|
const transformed = new MagicString__default(code);
|
|
351
354
|
for (const fnCall of functionCalls) {
|
|
352
355
|
const functionCallStr = fnCall.snippet;
|
|
@@ -358,7 +361,6 @@ async function createCtx(options) {
|
|
|
358
361
|
params: args
|
|
359
362
|
};
|
|
360
363
|
usages.push(usage);
|
|
361
|
-
ctx.hooks.tsCodegenUpdated.trigger();
|
|
362
364
|
let transformedContent;
|
|
363
365
|
if (ctx.fnUtils.isNormal(fnCall.fnName)) {
|
|
364
366
|
transformedContent = ctx.transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : ctx.transformedFormat === "string" ? `'${names.join(" ")}'` : names.join(" ");
|
|
@@ -373,6 +375,9 @@ async function createCtx(options) {
|
|
|
373
375
|
}
|
|
374
376
|
transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
|
|
375
377
|
}
|
|
378
|
+
ctx.usages.set(id, usages);
|
|
379
|
+
ctx.hooks.styleUpdated.trigger();
|
|
380
|
+
ctx.hooks.tsCodegenUpdated.trigger();
|
|
376
381
|
return {
|
|
377
382
|
code: transformed.toString(),
|
|
378
383
|
map: transformed.generateMap({ hires: true })
|
|
@@ -382,23 +387,35 @@ async function createCtx(options) {
|
|
|
382
387
|
return void 0;
|
|
383
388
|
}
|
|
384
389
|
},
|
|
385
|
-
|
|
390
|
+
getCssContent: (isDev) => {
|
|
386
391
|
if (ctx.isReady === false)
|
|
387
|
-
return;
|
|
392
|
+
return null;
|
|
388
393
|
const atomicStyleIds = [...new Set([...ctx.usages.values()].flatMap((i) => [...new Set(i.flatMap((i2) => i2.atomicStyleIds))]))];
|
|
389
394
|
const css = [
|
|
390
395
|
`/* Auto-generated by ${ctx.currentPackageName} */`,
|
|
391
|
-
ctx.engine.renderPreflights(
|
|
392
|
-
ctx.engine.renderAtomicStyles(
|
|
396
|
+
ctx.engine.renderPreflights(isDev),
|
|
397
|
+
ctx.engine.renderAtomicStyles(isDev, { atomicStyleIds })
|
|
393
398
|
].join("\n").trim();
|
|
394
|
-
|
|
399
|
+
return css;
|
|
395
400
|
},
|
|
396
|
-
|
|
401
|
+
getTsCodegenContent: () => {
|
|
397
402
|
if (ctx.isReady === false || ctx.tsCodegenFilepath == null)
|
|
403
|
+
return null;
|
|
404
|
+
const content = generateTsCodegenContent(ctx);
|
|
405
|
+
return content;
|
|
406
|
+
},
|
|
407
|
+
writeDevCssFile: perfectDebounce.debounce(async () => {
|
|
408
|
+
const content = ctx.getCssContent(true);
|
|
409
|
+
if (content == null)
|
|
410
|
+
return;
|
|
411
|
+
await promises.writeFile(ctx.devCssFilepath, content);
|
|
412
|
+
}, 300),
|
|
413
|
+
writeTsCodegenFile: perfectDebounce.debounce(async () => {
|
|
414
|
+
const content = ctx.getTsCodegenContent();
|
|
415
|
+
if (ctx.tsCodegenFilepath == null || content == null)
|
|
398
416
|
return;
|
|
399
|
-
const content = await generateTsCodegenContent(ctx);
|
|
400
417
|
await promises.writeFile(ctx.tsCodegenFilepath, content);
|
|
401
|
-
}
|
|
418
|
+
}, 300)
|
|
402
419
|
};
|
|
403
420
|
await ctx.init();
|
|
404
421
|
return ctx;
|
package/dist/index.d.cts
CHANGED
|
@@ -56,6 +56,8 @@ interface IntegrationContext {
|
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
58
|
} | Nullish>;
|
|
59
|
+
getCssContent: (isDev: boolean) => string | Nullish;
|
|
60
|
+
getTsCodegenContent: () => string | Nullish;
|
|
59
61
|
writeDevCssFile: () => Promise<void>;
|
|
60
62
|
writeTsCodegenFile: () => Promise<void>;
|
|
61
63
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -56,6 +56,8 @@ interface IntegrationContext {
|
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
58
|
} | Nullish>;
|
|
59
|
+
getCssContent: (isDev: boolean) => string | Nullish;
|
|
60
|
+
getTsCodegenContent: () => string | Nullish;
|
|
59
61
|
writeDevCssFile: () => Promise<void>;
|
|
60
62
|
writeTsCodegenFile: () => Promise<void>;
|
|
61
63
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,8 @@ interface IntegrationContext {
|
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
58
|
} | Nullish>;
|
|
59
|
+
getCssContent: (isDev: boolean) => string | Nullish;
|
|
60
|
+
getTsCodegenContent: () => string | Nullish;
|
|
59
61
|
writeDevCssFile: () => Promise<void>;
|
|
60
62
|
writeTsCodegenFile: () => Promise<void>;
|
|
61
63
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
2
|
import { writeFile, mkdir, stat } from 'node:fs/promises';
|
|
3
|
-
import { setWarnFn, warn, createEngine } from '@pikacss/core';
|
|
3
|
+
import { setWarnFn, warn, defineEnginePlugin, createEngine } from '@pikacss/core';
|
|
4
4
|
export * from '@pikacss/core';
|
|
5
5
|
import { createJiti } from 'jiti';
|
|
6
6
|
import { isPackageExists } from 'local-pkg';
|
|
7
7
|
import MagicString from 'magic-string';
|
|
8
8
|
import micromatch from 'micromatch';
|
|
9
9
|
import { isAbsolute, resolve, join, dirname, relative } from 'pathe';
|
|
10
|
+
import { debounce } from 'perfect-debounce';
|
|
10
11
|
|
|
11
12
|
function createEventHook() {
|
|
12
13
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -112,7 +113,7 @@ function generateVueDeclaration(ctx) {
|
|
|
112
113
|
""
|
|
113
114
|
];
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
+
function generateOverloadContent(ctx) {
|
|
116
117
|
const paramsLines = [];
|
|
117
118
|
const fnsLines = [];
|
|
118
119
|
const usages = [...ctx.usages.values()].flat();
|
|
@@ -147,7 +148,7 @@ async function generateOverloadContent(ctx) {
|
|
|
147
148
|
...paramsLines
|
|
148
149
|
];
|
|
149
150
|
}
|
|
150
|
-
|
|
151
|
+
function generateTsCodegenContent(ctx) {
|
|
151
152
|
const lines = [
|
|
152
153
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
153
154
|
`import type { CSSProperty, CSSSelectors, DefineAutocomplete, Properties, StyleDefinition, StyleItem } from '${ctx.currentPackageName}'`,
|
|
@@ -168,7 +169,7 @@ async function generateTsCodegenContent(ctx) {
|
|
|
168
169
|
lines.push(...generateStyleFn(ctx));
|
|
169
170
|
lines.push(...generateGlobalDeclaration(ctx));
|
|
170
171
|
lines.push(...generateVueDeclaration(ctx));
|
|
171
|
-
lines.push(...
|
|
172
|
+
lines.push(...generateOverloadContent(ctx));
|
|
172
173
|
return lines.join("\n");
|
|
173
174
|
}
|
|
174
175
|
|
|
@@ -290,7 +291,7 @@ async function createCtx(options) {
|
|
|
290
291
|
const config = await jiti.import(resolvedConfigPath, { default: true });
|
|
291
292
|
return { config, file: resolvedConfigPath };
|
|
292
293
|
},
|
|
293
|
-
init: async () => {
|
|
294
|
+
init: debounce(async () => {
|
|
294
295
|
ctx.isReady = false;
|
|
295
296
|
ctx.usages.clear();
|
|
296
297
|
const { config, file } = await ctx.loadConfig().catch((error) => {
|
|
@@ -298,18 +299,21 @@ async function createCtx(options) {
|
|
|
298
299
|
return { config: null, file: null };
|
|
299
300
|
});
|
|
300
301
|
ctx.resolvedConfigPath = file;
|
|
301
|
-
|
|
302
|
-
ctx.engine = await createEngine(config ?? {});
|
|
303
|
-
} catch (error) {
|
|
304
|
-
warn(`Failed to create engine: ${error.message}. Maybe the config file is invalid, falling back to default config.`, error);
|
|
305
|
-
ctx.engine = await createEngine({});
|
|
306
|
-
}
|
|
307
|
-
ctx.engine.config.plugins.unshift({
|
|
302
|
+
const devPlugin = defineEnginePlugin({
|
|
308
303
|
name: "@pikacss/integration:dev",
|
|
309
304
|
preflightUpdated: () => ctx.hooks.styleUpdated.trigger(),
|
|
310
305
|
atomicStyleAdded: () => ctx.hooks.styleUpdated.trigger(),
|
|
311
306
|
autocompleteConfigUpdated: () => ctx.hooks.tsCodegenUpdated.trigger()
|
|
312
307
|
});
|
|
308
|
+
try {
|
|
309
|
+
const _config = config ?? {};
|
|
310
|
+
_config.plugins = _config.plugins ?? [];
|
|
311
|
+
_config.plugins.unshift(devPlugin);
|
|
312
|
+
ctx.engine = await createEngine(_config);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
warn(`Failed to create engine: ${error.message}. Maybe the config file is invalid, falling back to default config.`, error);
|
|
315
|
+
ctx.engine = await createEngine({ plugins: [devPlugin] });
|
|
316
|
+
}
|
|
313
317
|
await mkdir(dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
314
318
|
});
|
|
315
319
|
const isDevCssFileExists = await stat(devCssFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
@@ -320,12 +324,12 @@ async function createCtx(options) {
|
|
|
320
324
|
});
|
|
321
325
|
const isGenTsFileExists = await stat(tsCodegenFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
322
326
|
if (isGenTsFileExists === false) {
|
|
323
|
-
const content =
|
|
327
|
+
const content = generateTsCodegenContent(ctx);
|
|
324
328
|
await writeFile(tsCodegenFilepath, content);
|
|
325
329
|
}
|
|
326
330
|
}
|
|
327
331
|
ctx.isReady = true;
|
|
328
|
-
},
|
|
332
|
+
}, 300),
|
|
329
333
|
isReady: false,
|
|
330
334
|
configSources,
|
|
331
335
|
resolvedConfigPath: null,
|
|
@@ -340,7 +344,6 @@ async function createCtx(options) {
|
|
|
340
344
|
if (functionCalls.length === 0)
|
|
341
345
|
return;
|
|
342
346
|
const usages = [];
|
|
343
|
-
ctx.usages.set(id, usages);
|
|
344
347
|
const transformed = new MagicString(code);
|
|
345
348
|
for (const fnCall of functionCalls) {
|
|
346
349
|
const functionCallStr = fnCall.snippet;
|
|
@@ -352,7 +355,6 @@ async function createCtx(options) {
|
|
|
352
355
|
params: args
|
|
353
356
|
};
|
|
354
357
|
usages.push(usage);
|
|
355
|
-
ctx.hooks.tsCodegenUpdated.trigger();
|
|
356
358
|
let transformedContent;
|
|
357
359
|
if (ctx.fnUtils.isNormal(fnCall.fnName)) {
|
|
358
360
|
transformedContent = ctx.transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : ctx.transformedFormat === "string" ? `'${names.join(" ")}'` : names.join(" ");
|
|
@@ -367,6 +369,9 @@ async function createCtx(options) {
|
|
|
367
369
|
}
|
|
368
370
|
transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
|
|
369
371
|
}
|
|
372
|
+
ctx.usages.set(id, usages);
|
|
373
|
+
ctx.hooks.styleUpdated.trigger();
|
|
374
|
+
ctx.hooks.tsCodegenUpdated.trigger();
|
|
370
375
|
return {
|
|
371
376
|
code: transformed.toString(),
|
|
372
377
|
map: transformed.generateMap({ hires: true })
|
|
@@ -376,23 +381,35 @@ async function createCtx(options) {
|
|
|
376
381
|
return void 0;
|
|
377
382
|
}
|
|
378
383
|
},
|
|
379
|
-
|
|
384
|
+
getCssContent: (isDev) => {
|
|
380
385
|
if (ctx.isReady === false)
|
|
381
|
-
return;
|
|
386
|
+
return null;
|
|
382
387
|
const atomicStyleIds = [...new Set([...ctx.usages.values()].flatMap((i) => [...new Set(i.flatMap((i2) => i2.atomicStyleIds))]))];
|
|
383
388
|
const css = [
|
|
384
389
|
`/* Auto-generated by ${ctx.currentPackageName} */`,
|
|
385
|
-
ctx.engine.renderPreflights(
|
|
386
|
-
ctx.engine.renderAtomicStyles(
|
|
390
|
+
ctx.engine.renderPreflights(isDev),
|
|
391
|
+
ctx.engine.renderAtomicStyles(isDev, { atomicStyleIds })
|
|
387
392
|
].join("\n").trim();
|
|
388
|
-
|
|
393
|
+
return css;
|
|
389
394
|
},
|
|
390
|
-
|
|
395
|
+
getTsCodegenContent: () => {
|
|
391
396
|
if (ctx.isReady === false || ctx.tsCodegenFilepath == null)
|
|
397
|
+
return null;
|
|
398
|
+
const content = generateTsCodegenContent(ctx);
|
|
399
|
+
return content;
|
|
400
|
+
},
|
|
401
|
+
writeDevCssFile: debounce(async () => {
|
|
402
|
+
const content = ctx.getCssContent(true);
|
|
403
|
+
if (content == null)
|
|
404
|
+
return;
|
|
405
|
+
await writeFile(ctx.devCssFilepath, content);
|
|
406
|
+
}, 300),
|
|
407
|
+
writeTsCodegenFile: debounce(async () => {
|
|
408
|
+
const content = ctx.getTsCodegenContent();
|
|
409
|
+
if (ctx.tsCodegenFilepath == null || content == null)
|
|
392
410
|
return;
|
|
393
|
-
const content = await generateTsCodegenContent(ctx);
|
|
394
411
|
await writeFile(ctx.tsCodegenFilepath, content);
|
|
395
|
-
}
|
|
412
|
+
}, 300)
|
|
396
413
|
};
|
|
397
414
|
await ctx.init();
|
|
398
415
|
return ctx;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.16",
|
|
8
8
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"magic-string": "^0.30.12",
|
|
41
41
|
"micromatch": "^4.0.8",
|
|
42
42
|
"pathe": "^2.0.3",
|
|
43
|
-
"
|
|
43
|
+
"perfect-debounce": "^1.0.0",
|
|
44
|
+
"@pikacss/core": "0.0.16"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/micromatch": "^4.0.9"
|