@pikacss/integration 0.0.37 → 0.0.39
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 +55 -0
- package/dist/index.cjs +74 -37
- package/dist/index.mjs +44 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1 +1,56 @@
|
|
|
1
1
|
# @pikacss/integration
|
|
2
|
+
|
|
3
|
+
Internal integration utilities for PikaCSS build tool plugins.
|
|
4
|
+
|
|
5
|
+
## ⚠️ Internal Package
|
|
6
|
+
|
|
7
|
+
**This is an internal package** used by official PikaCSS integration plugins.
|
|
8
|
+
|
|
9
|
+
**Most users should use these instead:**
|
|
10
|
+
- **[`@pikacss/unplugin-pikacss`](../unplugin/)** - Universal plugin for multiple bundlers
|
|
11
|
+
- **[`@pikacss/nuxt-pikacss`](../nuxt/)** - Nuxt module
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Only needed for plugin development:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @pikacss/integration
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What This Package Provides
|
|
22
|
+
|
|
23
|
+
Low-level utilities for building PikaCSS integrations:
|
|
24
|
+
|
|
25
|
+
- 🔧 Core integration context management
|
|
26
|
+
- 📁 File scanning and code transformation
|
|
27
|
+
- 🎯 Config file loading and resolution
|
|
28
|
+
- 📦 Code generation (TypeScript and CSS)
|
|
29
|
+
- ⚡ Build-time optimizations
|
|
30
|
+
|
|
31
|
+
## Exports
|
|
32
|
+
|
|
33
|
+
This package exports utilities from `@pikacss/core` and provides integration-specific functionality:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// Main exports
|
|
37
|
+
export * from './ctx' // Integration context system
|
|
38
|
+
export * from './types' // TypeScript type definitions
|
|
39
|
+
export * from '@pikacss/core' // Re-exports all core exports
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## For Plugin Authors
|
|
43
|
+
|
|
44
|
+
If you're building a new integration for a bundler or framework, this package provides the foundation.
|
|
45
|
+
|
|
46
|
+
See how it's used in existing integrations:
|
|
47
|
+
- [`@pikacss/unplugin-pikacss`](../unplugin/) - Universal plugin implementation
|
|
48
|
+
- [`@pikacss/nuxt-pikacss`](../nuxt/) - Nuxt module implementation
|
|
49
|
+
|
|
50
|
+
## Documentation
|
|
51
|
+
|
|
52
|
+
For complete documentation, visit: [PikaCSS Documentation](https://pikacss.github.io/pikacss/)
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT © DevilTea
|
package/dist/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
//#endregion
|
|
28
28
|
let node_fs = require("node:fs");
|
|
29
29
|
let node_fs_promises = require("node:fs/promises");
|
|
30
|
-
let
|
|
30
|
+
let _pikacss_core = require("@pikacss/core");
|
|
31
31
|
let alien_signals = require("alien-signals");
|
|
32
32
|
let globby = require("globby");
|
|
33
33
|
let klona = require("klona");
|
|
@@ -129,11 +129,11 @@ function generateVueDeclaration(ctx) {
|
|
|
129
129
|
];
|
|
130
130
|
}
|
|
131
131
|
async function generateOverloadContent(ctx) {
|
|
132
|
-
|
|
132
|
+
_pikacss_core.log.debug("Generating TypeScript overload content");
|
|
133
133
|
const paramsLines = [];
|
|
134
134
|
const fnsLines = [];
|
|
135
135
|
const usages = [...ctx.usages.values()].flat();
|
|
136
|
-
|
|
136
|
+
_pikacss_core.log.debug(`Processing ${usages.length} style usages for overload generation`);
|
|
137
137
|
for (let i = 0; i < usages.length; i++) {
|
|
138
138
|
const usage = usages[i];
|
|
139
139
|
try {
|
|
@@ -167,15 +167,15 @@ async function generateOverloadContent(ctx) {
|
|
|
167
167
|
];
|
|
168
168
|
}
|
|
169
169
|
async function generateTsCodegenContent(ctx) {
|
|
170
|
-
|
|
170
|
+
_pikacss_core.log.debug("Generating TypeScript code generation content");
|
|
171
171
|
const lines = [
|
|
172
172
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
173
|
-
`import type { CSSProperty,
|
|
173
|
+
`import type { CSSProperty, CSSSelector, DefineAutocomplete, Properties, StyleDefinition, StyleItem } from \'${ctx.currentPackageName}\'`,
|
|
174
174
|
"",
|
|
175
175
|
`declare module \'${ctx.currentPackageName}\' {`,
|
|
176
176
|
" interface PikaAugment {",
|
|
177
177
|
" Autocomplete: Autocomplete",
|
|
178
|
-
" Selector: Autocomplete['Selector'] |
|
|
178
|
+
" Selector: Autocomplete['Selector'] | CSSSelector",
|
|
179
179
|
" CSSProperty: Autocomplete['ExtraCssProperty'] | CSSProperty",
|
|
180
180
|
" Properties: Properties",
|
|
181
181
|
" StyleDefinition: StyleDefinition",
|
|
@@ -189,7 +189,7 @@ async function generateTsCodegenContent(ctx) {
|
|
|
189
189
|
lines.push(...generateGlobalDeclaration(ctx));
|
|
190
190
|
lines.push(...generateVueDeclaration(ctx));
|
|
191
191
|
lines.push(...await generateOverloadContent(ctx));
|
|
192
|
-
|
|
192
|
+
_pikacss_core.log.debug("TypeScript code generation content completed");
|
|
193
193
|
return lines.join("\n");
|
|
194
194
|
}
|
|
195
195
|
|
|
@@ -220,9 +220,9 @@ function useConfig({ cwd, tsCodegenFilepath, currentPackageName, autoCreateConfi
|
|
|
220
220
|
const inlineConfig = typeof configOrPath === "object" ? configOrPath : null;
|
|
221
221
|
async function _loadConfig() {
|
|
222
222
|
try {
|
|
223
|
-
|
|
223
|
+
_pikacss_core.log.debug("Loading engine config");
|
|
224
224
|
if (inlineConfig != null) {
|
|
225
|
-
|
|
225
|
+
_pikacss_core.log.debug("Using inline config");
|
|
226
226
|
return {
|
|
227
227
|
config: (0, klona.klona)(inlineConfig),
|
|
228
228
|
file: null,
|
|
@@ -233,7 +233,7 @@ function useConfig({ cwd, tsCodegenFilepath, currentPackageName, autoCreateConfi
|
|
|
233
233
|
const _cwd = cwd();
|
|
234
234
|
if (resolvedConfigPath$1 == null) {
|
|
235
235
|
if (autoCreateConfig === false) {
|
|
236
|
-
|
|
236
|
+
_pikacss_core.log.warn("Config file not found and autoCreateConfig is false");
|
|
237
237
|
return {
|
|
238
238
|
config: null,
|
|
239
239
|
file: null,
|
|
@@ -253,7 +253,7 @@ function useConfig({ cwd, tsCodegenFilepath, currentPackageName, autoCreateConfi
|
|
|
253
253
|
"})"
|
|
254
254
|
].join("\n"));
|
|
255
255
|
}
|
|
256
|
-
|
|
256
|
+
_pikacss_core.log.info(`Using config file: ${resolvedConfigPath$1}`);
|
|
257
257
|
const { createJiti } = await import("jiti");
|
|
258
258
|
const jiti = createJiti(require("url").pathToFileURL(__filename).href, { interopDefault: true });
|
|
259
259
|
const content = await (0, node_fs_promises.readFile)(resolvedConfigPath$1, "utf-8");
|
|
@@ -267,7 +267,7 @@ function useConfig({ cwd, tsCodegenFilepath, currentPackageName, autoCreateConfi
|
|
|
267
267
|
content
|
|
268
268
|
};
|
|
269
269
|
} catch (error) {
|
|
270
|
-
|
|
270
|
+
_pikacss_core.log.error(`Failed to load config file: ${error.message}`, error);
|
|
271
271
|
return {
|
|
272
272
|
config: null,
|
|
273
273
|
file: null,
|
|
@@ -355,12 +355,49 @@ function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName
|
|
|
355
355
|
let end = start + fnName$1.length;
|
|
356
356
|
let depth = 1;
|
|
357
357
|
let inString = false;
|
|
358
|
-
|
|
358
|
+
let isEscaped = false;
|
|
359
|
+
while (depth > 0 && end < code.length) {
|
|
359
360
|
end++;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
361
|
+
const char = code[end];
|
|
362
|
+
if (isEscaped) {
|
|
363
|
+
isEscaped = false;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (char === "\\") {
|
|
367
|
+
isEscaped = true;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (inString !== false) {
|
|
371
|
+
if (char === inString) inString = false;
|
|
372
|
+
else if (inString === "`" && char === "$" && code[end + 1] === "{") {
|
|
373
|
+
end++;
|
|
374
|
+
depth++;
|
|
375
|
+
}
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (char === "(") depth++;
|
|
379
|
+
else if (char === ")") depth--;
|
|
380
|
+
else if (char === "'" || char === "\"" || char === "`") inString = char;
|
|
381
|
+
else if (char === "/" && code[end + 1] === "/") {
|
|
382
|
+
const lineEnd = code.indexOf("\n", end);
|
|
383
|
+
if (lineEnd === -1) {
|
|
384
|
+
_pikacss_core.log.warn(`Unclosed function call at position ${start}`);
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
end = lineEnd;
|
|
388
|
+
} else if (char === "/" && code[end + 1] === "*") {
|
|
389
|
+
const commentEnd = code.indexOf("*/", end + 2);
|
|
390
|
+
if (commentEnd === -1) {
|
|
391
|
+
_pikacss_core.log.warn(`Unclosed comment in function call at position ${start}`);
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
end = commentEnd + 1;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (depth !== 0) {
|
|
398
|
+
_pikacss_core.log.warn(`Malformed function call at position ${start}, skipping`);
|
|
399
|
+
matched = RE.exec(code);
|
|
400
|
+
continue;
|
|
364
401
|
}
|
|
365
402
|
const snippet = code.slice(start, end + 1);
|
|
366
403
|
result.push({
|
|
@@ -377,11 +414,11 @@ function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName
|
|
|
377
414
|
const _engine = engine();
|
|
378
415
|
if (_engine == null) return null;
|
|
379
416
|
try {
|
|
380
|
-
|
|
417
|
+
_pikacss_core.log.debug(`Transforming file: ${id}`);
|
|
381
418
|
usages.delete(id);
|
|
382
419
|
const functionCalls = findFunctionCalls(code);
|
|
383
420
|
if (functionCalls.length === 0) return;
|
|
384
|
-
|
|
421
|
+
_pikacss_core.log.debug(`Found ${functionCalls.length} style function calls in ${id}`);
|
|
385
422
|
const usageList = [];
|
|
386
423
|
const transformed = new magic_string.default(code);
|
|
387
424
|
for (const fnCall of functionCalls) {
|
|
@@ -404,13 +441,13 @@ function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName
|
|
|
404
441
|
usages.set(id, usageList);
|
|
405
442
|
triggerStyleUpdated();
|
|
406
443
|
triggerTsCodegenUpdated();
|
|
407
|
-
|
|
444
|
+
_pikacss_core.log.debug(`Transformed ${usageList.length} style usages in ${id}`);
|
|
408
445
|
return {
|
|
409
446
|
code: transformed.toString(),
|
|
410
447
|
map: transformed.generateMap({ hires: true })
|
|
411
448
|
};
|
|
412
449
|
} catch (error) {
|
|
413
|
-
|
|
450
|
+
_pikacss_core.log.error(`Failed to transform code (${(0, pathe.join)(cwd(), id)}): ${error.message}`, error);
|
|
414
451
|
return;
|
|
415
452
|
}
|
|
416
453
|
}
|
|
@@ -492,9 +529,9 @@ function createCtx(options) {
|
|
|
492
529
|
},
|
|
493
530
|
getCssCodegenContent: async () => {
|
|
494
531
|
await ctx.setupPromise;
|
|
495
|
-
|
|
532
|
+
_pikacss_core.log.debug("Generating CSS code");
|
|
496
533
|
const atomicStyleIds = [...new Set([...ctx.usages.values()].flatMap((i) => [...new Set(i.flatMap((i$1) => i$1.atomicStyleIds))]))];
|
|
497
|
-
|
|
534
|
+
_pikacss_core.log.debug(`Collecting ${atomicStyleIds.length} atomic style IDs`);
|
|
498
535
|
return [
|
|
499
536
|
`/* Auto-generated by ${ctx.currentPackageName} */`,
|
|
500
537
|
await ctx.engine.renderPreflights(true),
|
|
@@ -511,7 +548,7 @@ function createCtx(options) {
|
|
|
511
548
|
const content = await ctx.getCssCodegenContent();
|
|
512
549
|
if (content == null) return;
|
|
513
550
|
await (0, node_fs_promises.mkdir)((0, pathe.dirname)(ctx.cssCodegenFilepath), { recursive: true }).catch(() => {});
|
|
514
|
-
|
|
551
|
+
_pikacss_core.log.debug(`Writing CSS code generation file: ${ctx.cssCodegenFilepath}`);
|
|
515
552
|
await (0, node_fs_promises.writeFile)(ctx.cssCodegenFilepath, content);
|
|
516
553
|
},
|
|
517
554
|
writeTsCodegenFile: async () => {
|
|
@@ -520,12 +557,12 @@ function createCtx(options) {
|
|
|
520
557
|
const content = await ctx.getTsCodegenContent();
|
|
521
558
|
if (content == null) return;
|
|
522
559
|
await (0, node_fs_promises.mkdir)((0, pathe.dirname)(ctx.tsCodegenFilepath), { recursive: true }).catch(() => {});
|
|
523
|
-
|
|
560
|
+
_pikacss_core.log.debug(`Writing TypeScript code generation file: ${ctx.tsCodegenFilepath}`);
|
|
524
561
|
await (0, node_fs_promises.writeFile)(ctx.tsCodegenFilepath, content);
|
|
525
562
|
},
|
|
526
563
|
fullyCssCodegen: async () => {
|
|
527
564
|
await ctx.setupPromise;
|
|
528
|
-
|
|
565
|
+
_pikacss_core.log.debug("Starting full CSS code generation scan");
|
|
529
566
|
const stream = (0, globby.globbyStream)(options.scan.include, { ignore: options.scan.exclude });
|
|
530
567
|
let fileCount = 0;
|
|
531
568
|
const _cwd = cwd();
|
|
@@ -534,13 +571,13 @@ function createCtx(options) {
|
|
|
534
571
|
await ctx.transform(code, entry);
|
|
535
572
|
fileCount++;
|
|
536
573
|
}
|
|
537
|
-
|
|
574
|
+
_pikacss_core.log.debug(`Scanned ${fileCount} files for style collection`);
|
|
538
575
|
await ctx.writeCssCodegenFile();
|
|
539
576
|
},
|
|
540
577
|
setupPromise: null,
|
|
541
578
|
setup: () => {
|
|
542
579
|
ctx.setupPromise = setup().catch((error) => {
|
|
543
|
-
|
|
580
|
+
_pikacss_core.log.error(`Failed to setup integration context: ${error.message}`, error);
|
|
544
581
|
}).then(() => {
|
|
545
582
|
ctx.setupPromise = null;
|
|
546
583
|
});
|
|
@@ -548,13 +585,13 @@ function createCtx(options) {
|
|
|
548
585
|
}
|
|
549
586
|
};
|
|
550
587
|
async function setup() {
|
|
551
|
-
|
|
588
|
+
_pikacss_core.log.debug("Setting up integration context");
|
|
552
589
|
usages.clear();
|
|
553
590
|
hooks.styleUpdated.listeners.clear();
|
|
554
591
|
hooks.tsCodegenUpdated.listeners.clear();
|
|
555
592
|
engine(null);
|
|
556
593
|
await loadConfig();
|
|
557
|
-
const devPlugin = (0,
|
|
594
|
+
const devPlugin = (0, _pikacss_core.defineEnginePlugin)({
|
|
558
595
|
name: "@pikacss/integration:dev",
|
|
559
596
|
preflightUpdated: () => hooks.styleUpdated.trigger(),
|
|
560
597
|
atomicStyleAdded: () => hooks.styleUpdated.trigger(),
|
|
@@ -564,22 +601,22 @@ function createCtx(options) {
|
|
|
564
601
|
const config = resolvedConfig() ?? {};
|
|
565
602
|
config.plugins = config.plugins ?? [];
|
|
566
603
|
config.plugins.unshift(devPlugin);
|
|
567
|
-
|
|
568
|
-
engine(await (0,
|
|
604
|
+
_pikacss_core.log.debug("Creating engine with loaded/default config");
|
|
605
|
+
engine(await (0, _pikacss_core.createEngine)(config));
|
|
569
606
|
} catch (error) {
|
|
570
|
-
|
|
571
|
-
engine(await (0,
|
|
607
|
+
_pikacss_core.log.error(`Failed to create engine: ${error.message}. Falling back to default config.`, error);
|
|
608
|
+
engine(await (0, _pikacss_core.createEngine)({ plugins: [devPlugin] }));
|
|
572
609
|
}
|
|
573
|
-
|
|
610
|
+
_pikacss_core.log.debug("Integration context setup successfully");
|
|
574
611
|
}
|
|
575
612
|
return ctx;
|
|
576
613
|
}
|
|
577
614
|
|
|
578
615
|
//#endregion
|
|
579
616
|
exports.createCtx = createCtx;
|
|
580
|
-
Object.keys(
|
|
617
|
+
Object.keys(_pikacss_core).forEach(function (k) {
|
|
581
618
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
582
619
|
enumerable: true,
|
|
583
|
-
get: function () { return
|
|
620
|
+
get: function () { return _pikacss_core[k]; }
|
|
584
621
|
});
|
|
585
622
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -144,12 +144,12 @@ async function generateTsCodegenContent(ctx) {
|
|
|
144
144
|
log.debug("Generating TypeScript code generation content");
|
|
145
145
|
const lines = [
|
|
146
146
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
147
|
-
`import type { CSSProperty,
|
|
147
|
+
`import type { CSSProperty, CSSSelector, DefineAutocomplete, Properties, StyleDefinition, StyleItem } from \'${ctx.currentPackageName}\'`,
|
|
148
148
|
"",
|
|
149
149
|
`declare module \'${ctx.currentPackageName}\' {`,
|
|
150
150
|
" interface PikaAugment {",
|
|
151
151
|
" Autocomplete: Autocomplete",
|
|
152
|
-
" Selector: Autocomplete['Selector'] |
|
|
152
|
+
" Selector: Autocomplete['Selector'] | CSSSelector",
|
|
153
153
|
" CSSProperty: Autocomplete['ExtraCssProperty'] | CSSProperty",
|
|
154
154
|
" Properties: Properties",
|
|
155
155
|
" StyleDefinition: StyleDefinition",
|
|
@@ -329,12 +329,49 @@ function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName
|
|
|
329
329
|
let end = start + fnName$1.length;
|
|
330
330
|
let depth = 1;
|
|
331
331
|
let inString = false;
|
|
332
|
-
|
|
332
|
+
let isEscaped = false;
|
|
333
|
+
while (depth > 0 && end < code.length) {
|
|
333
334
|
end++;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
const char = code[end];
|
|
336
|
+
if (isEscaped) {
|
|
337
|
+
isEscaped = false;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (char === "\\") {
|
|
341
|
+
isEscaped = true;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (inString !== false) {
|
|
345
|
+
if (char === inString) inString = false;
|
|
346
|
+
else if (inString === "`" && char === "$" && code[end + 1] === "{") {
|
|
347
|
+
end++;
|
|
348
|
+
depth++;
|
|
349
|
+
}
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (char === "(") depth++;
|
|
353
|
+
else if (char === ")") depth--;
|
|
354
|
+
else if (char === "'" || char === "\"" || char === "`") inString = char;
|
|
355
|
+
else if (char === "/" && code[end + 1] === "/") {
|
|
356
|
+
const lineEnd = code.indexOf("\n", end);
|
|
357
|
+
if (lineEnd === -1) {
|
|
358
|
+
log.warn(`Unclosed function call at position ${start}`);
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
end = lineEnd;
|
|
362
|
+
} else if (char === "/" && code[end + 1] === "*") {
|
|
363
|
+
const commentEnd = code.indexOf("*/", end + 2);
|
|
364
|
+
if (commentEnd === -1) {
|
|
365
|
+
log.warn(`Unclosed comment in function call at position ${start}`);
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
end = commentEnd + 1;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (depth !== 0) {
|
|
372
|
+
log.warn(`Malformed function call at position ${start}, skipping`);
|
|
373
|
+
matched = RE.exec(code);
|
|
374
|
+
continue;
|
|
338
375
|
}
|
|
339
376
|
const snippet = code.slice(start, end + 1);
|
|
340
377
|
result.push({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikacss/integration",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.39",
|
|
5
5
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"micromatch": "^4.0.8",
|
|
50
50
|
"pathe": "^2.0.3",
|
|
51
51
|
"perfect-debounce": "^2.0.0",
|
|
52
|
-
"@pikacss/core": "0.0.
|
|
52
|
+
"@pikacss/core": "0.0.39"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/micromatch": "^4.0.10"
|