@pikacss/integration 0.0.15 → 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 +35 -19
- package/dist/index.d.cts +4 -2
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +38 -22
- 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
|
|
|
@@ -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,
|
|
@@ -383,23 +387,35 @@ async function createCtx(options) {
|
|
|
383
387
|
return void 0;
|
|
384
388
|
}
|
|
385
389
|
},
|
|
386
|
-
|
|
390
|
+
getCssContent: (isDev) => {
|
|
387
391
|
if (ctx.isReady === false)
|
|
388
|
-
return;
|
|
392
|
+
return null;
|
|
389
393
|
const atomicStyleIds = [...new Set([...ctx.usages.values()].flatMap((i) => [...new Set(i.flatMap((i2) => i2.atomicStyleIds))]))];
|
|
390
394
|
const css = [
|
|
391
395
|
`/* Auto-generated by ${ctx.currentPackageName} */`,
|
|
392
|
-
ctx.engine.renderPreflights(
|
|
393
|
-
ctx.engine.renderAtomicStyles(
|
|
396
|
+
ctx.engine.renderPreflights(isDev),
|
|
397
|
+
ctx.engine.renderAtomicStyles(isDev, { atomicStyleIds })
|
|
394
398
|
].join("\n").trim();
|
|
395
|
-
|
|
399
|
+
return css;
|
|
396
400
|
},
|
|
397
|
-
|
|
401
|
+
getTsCodegenContent: () => {
|
|
398
402
|
if (ctx.isReady === false || ctx.tsCodegenFilepath == null)
|
|
399
|
-
return;
|
|
403
|
+
return null;
|
|
400
404
|
const content = generateTsCodegenContent(ctx);
|
|
401
|
-
|
|
402
|
-
}
|
|
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)
|
|
416
|
+
return;
|
|
417
|
+
await promises.writeFile(ctx.tsCodegenFilepath, content);
|
|
418
|
+
}, 300)
|
|
403
419
|
};
|
|
404
420
|
await ctx.init();
|
|
405
421
|
return ctx;
|
package/dist/index.d.cts
CHANGED
|
@@ -56,8 +56,10 @@ interface IntegrationContext {
|
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
58
|
} | Nullish>;
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
getCssContent: (isDev: boolean) => string | Nullish;
|
|
60
|
+
getTsCodegenContent: () => string | Nullish;
|
|
61
|
+
writeDevCssFile: () => Promise<void>;
|
|
62
|
+
writeTsCodegenFile: () => Promise<void>;
|
|
61
63
|
}
|
|
62
64
|
interface IntegrationContextOptions {
|
|
63
65
|
cwd: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -56,8 +56,10 @@ interface IntegrationContext {
|
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
58
|
} | Nullish>;
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
getCssContent: (isDev: boolean) => string | Nullish;
|
|
60
|
+
getTsCodegenContent: () => string | Nullish;
|
|
61
|
+
writeDevCssFile: () => Promise<void>;
|
|
62
|
+
writeTsCodegenFile: () => Promise<void>;
|
|
61
63
|
}
|
|
62
64
|
interface IntegrationContextOptions {
|
|
63
65
|
cwd: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -56,8 +56,10 @@ interface IntegrationContext {
|
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
58
|
} | Nullish>;
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
getCssContent: (isDev: boolean) => string | Nullish;
|
|
60
|
+
getTsCodegenContent: () => string | Nullish;
|
|
61
|
+
writeDevCssFile: () => Promise<void>;
|
|
62
|
+
writeTsCodegenFile: () => Promise<void>;
|
|
61
63
|
}
|
|
62
64
|
interface IntegrationContextOptions {
|
|
63
65
|
cwd: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { mkdir, stat
|
|
3
|
-
import { setWarnFn, warn, createEngine } from '@pikacss/core';
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { writeFile, mkdir, stat } from 'node:fs/promises';
|
|
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();
|
|
@@ -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,
|
|
@@ -377,23 +381,35 @@ async function createCtx(options) {
|
|
|
377
381
|
return void 0;
|
|
378
382
|
}
|
|
379
383
|
},
|
|
380
|
-
|
|
384
|
+
getCssContent: (isDev) => {
|
|
381
385
|
if (ctx.isReady === false)
|
|
382
|
-
return;
|
|
386
|
+
return null;
|
|
383
387
|
const atomicStyleIds = [...new Set([...ctx.usages.values()].flatMap((i) => [...new Set(i.flatMap((i2) => i2.atomicStyleIds))]))];
|
|
384
388
|
const css = [
|
|
385
389
|
`/* Auto-generated by ${ctx.currentPackageName} */`,
|
|
386
|
-
ctx.engine.renderPreflights(
|
|
387
|
-
ctx.engine.renderAtomicStyles(
|
|
390
|
+
ctx.engine.renderPreflights(isDev),
|
|
391
|
+
ctx.engine.renderAtomicStyles(isDev, { atomicStyleIds })
|
|
388
392
|
].join("\n").trim();
|
|
389
|
-
|
|
393
|
+
return css;
|
|
390
394
|
},
|
|
391
|
-
|
|
395
|
+
getTsCodegenContent: () => {
|
|
392
396
|
if (ctx.isReady === false || ctx.tsCodegenFilepath == null)
|
|
393
|
-
return;
|
|
397
|
+
return null;
|
|
394
398
|
const content = generateTsCodegenContent(ctx);
|
|
395
|
-
|
|
396
|
-
}
|
|
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)
|
|
410
|
+
return;
|
|
411
|
+
await writeFile(ctx.tsCodegenFilepath, content);
|
|
412
|
+
}, 300)
|
|
397
413
|
};
|
|
398
414
|
await ctx.init();
|
|
399
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"
|