@pikacss/integration 0.0.4 → 0.0.6
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 +51 -40
- package/dist/index.mjs +52 -41
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -275,8 +275,8 @@ async function createCtx(options) {
|
|
|
275
275
|
if (inlineConfig != null)
|
|
276
276
|
return { config: inlineConfig, file: null };
|
|
277
277
|
let resolvedConfigPath = configSources.find((path) => {
|
|
278
|
-
const
|
|
279
|
-
return
|
|
278
|
+
const stat2 = node_fs.statSync(path, { throwIfNoEntry: false });
|
|
279
|
+
return stat2 != null && stat2.isFile();
|
|
280
280
|
});
|
|
281
281
|
if (resolvedConfigPath == null) {
|
|
282
282
|
if (autoCreateConfig === false)
|
|
@@ -304,7 +304,8 @@ async function createCtx(options) {
|
|
|
304
304
|
ctx.isReady = false;
|
|
305
305
|
await promises.mkdir(pathe.dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
306
306
|
});
|
|
307
|
-
await promises.
|
|
307
|
+
if ((await promises.stat(devCssFilepath)).isFile() === false)
|
|
308
|
+
await promises.writeFile(devCssFilepath, "");
|
|
308
309
|
if (tsCodegenFilepath != null) {
|
|
309
310
|
await promises.mkdir(pathe.dirname(tsCodegenFilepath), { recursive: true }).catch(() => {
|
|
310
311
|
});
|
|
@@ -316,7 +317,12 @@ async function createCtx(options) {
|
|
|
316
317
|
return { config: null, file: null };
|
|
317
318
|
});
|
|
318
319
|
ctx.resolvedConfigPath = file;
|
|
319
|
-
|
|
320
|
+
try {
|
|
321
|
+
ctx.engine = await core.createEngine(config ?? {});
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.warn(`[${ctx.currentPackageName}] Failed to create engine: ${error}. Maybe the config file is invalid, falling back to default config.`);
|
|
324
|
+
ctx.engine = await core.createEngine({});
|
|
325
|
+
}
|
|
320
326
|
ctx.engine.config.plugins.unshift({
|
|
321
327
|
name: "@pikacss/integration:dev",
|
|
322
328
|
preflightUpdated: () => ctx.hooks.styleUpdated.trigger(),
|
|
@@ -330,44 +336,49 @@ async function createCtx(options) {
|
|
|
330
336
|
resolvedConfigPath: null,
|
|
331
337
|
engine: null,
|
|
332
338
|
transform: async (code, id) => {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
339
|
+
try {
|
|
340
|
+
if (ctx.isReady === false || !needToTransform(id)) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
ctx.usages.delete(id);
|
|
344
|
+
const functionCalls = findFunctionCalls(code, ctx.fnUtils.RE);
|
|
345
|
+
if (functionCalls.length === 0)
|
|
346
|
+
return;
|
|
347
|
+
const usages = [];
|
|
348
|
+
ctx.usages.set(id, usages);
|
|
349
|
+
const transformed = new MagicString__default(code);
|
|
350
|
+
for (const fnCall of functionCalls) {
|
|
351
|
+
const functionCallStr = fnCall.snippet;
|
|
352
|
+
const argsStr = `[${functionCallStr.slice(fnCall.fnName.length + 1, -1)}]`;
|
|
353
|
+
const args = new Function(`return ${argsStr}`)();
|
|
354
|
+
const usage = {
|
|
355
|
+
params: args
|
|
356
|
+
};
|
|
357
|
+
usages.push(usage);
|
|
358
|
+
const names = await ctx.engine.use(...args);
|
|
359
|
+
ctx.hooks.tsCodegenUpdated.trigger();
|
|
360
|
+
let transformedContent;
|
|
361
|
+
if (ctx.fnUtils.isNormal(fnCall.fnName)) {
|
|
362
|
+
transformedContent = ctx.transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : ctx.transformedFormat === "string" ? `'${names.join(" ")}'` : names.join(" ");
|
|
363
|
+
} else if (ctx.fnUtils.isForceString(fnCall.fnName)) {
|
|
364
|
+
transformedContent = `'${names.join(" ")}'`;
|
|
365
|
+
} else if (ctx.fnUtils.isForceArray(fnCall.fnName)) {
|
|
366
|
+
transformedContent = `[${names.map((n) => `'${n}'`).join(", ")}]`;
|
|
367
|
+
} else if (ctx.fnUtils.isForceInline(fnCall.fnName)) {
|
|
368
|
+
transformedContent = names.join(" ");
|
|
369
|
+
} else {
|
|
370
|
+
throw new Error(`Unexpected function name: ${fnCall.fnName}`);
|
|
371
|
+
}
|
|
372
|
+
transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
|
|
364
373
|
}
|
|
365
|
-
|
|
374
|
+
return {
|
|
375
|
+
code: transformed.toString(),
|
|
376
|
+
map: transformed.generateMap({ hires: true })
|
|
377
|
+
};
|
|
378
|
+
} catch (error) {
|
|
379
|
+
console.warn(`[${ctx.currentPackageName}] Failed to transform code: ${error}`);
|
|
380
|
+
return void 0;
|
|
366
381
|
}
|
|
367
|
-
return {
|
|
368
|
-
code: transformed.toString(),
|
|
369
|
-
map: transformed.generateMap({ hires: true })
|
|
370
|
-
};
|
|
371
382
|
},
|
|
372
383
|
writeDevCssFile: async () => {
|
|
373
384
|
if (ctx.isReady === false)
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
|
-
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { writeFile, mkdir, stat } from 'node:fs/promises';
|
|
3
3
|
import { createEngine } from '@pikacss/core';
|
|
4
4
|
export * from '@pikacss/core';
|
|
5
5
|
import { createJiti } from 'jiti';
|
|
@@ -256,8 +256,8 @@ async function createCtx(options) {
|
|
|
256
256
|
if (inlineConfig != null)
|
|
257
257
|
return { config: inlineConfig, file: null };
|
|
258
258
|
let resolvedConfigPath = configSources.find((path) => {
|
|
259
|
-
const
|
|
260
|
-
return
|
|
259
|
+
const stat2 = statSync(path, { throwIfNoEntry: false });
|
|
260
|
+
return stat2 != null && stat2.isFile();
|
|
261
261
|
});
|
|
262
262
|
if (resolvedConfigPath == null) {
|
|
263
263
|
if (autoCreateConfig === false)
|
|
@@ -285,7 +285,8 @@ async function createCtx(options) {
|
|
|
285
285
|
ctx.isReady = false;
|
|
286
286
|
await mkdir(dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
287
287
|
});
|
|
288
|
-
await
|
|
288
|
+
if ((await stat(devCssFilepath)).isFile() === false)
|
|
289
|
+
await writeFile(devCssFilepath, "");
|
|
289
290
|
if (tsCodegenFilepath != null) {
|
|
290
291
|
await mkdir(dirname(tsCodegenFilepath), { recursive: true }).catch(() => {
|
|
291
292
|
});
|
|
@@ -297,7 +298,12 @@ async function createCtx(options) {
|
|
|
297
298
|
return { config: null, file: null };
|
|
298
299
|
});
|
|
299
300
|
ctx.resolvedConfigPath = file;
|
|
300
|
-
|
|
301
|
+
try {
|
|
302
|
+
ctx.engine = await createEngine(config ?? {});
|
|
303
|
+
} catch (error) {
|
|
304
|
+
console.warn(`[${ctx.currentPackageName}] Failed to create engine: ${error}. Maybe the config file is invalid, falling back to default config.`);
|
|
305
|
+
ctx.engine = await createEngine({});
|
|
306
|
+
}
|
|
301
307
|
ctx.engine.config.plugins.unshift({
|
|
302
308
|
name: "@pikacss/integration:dev",
|
|
303
309
|
preflightUpdated: () => ctx.hooks.styleUpdated.trigger(),
|
|
@@ -311,44 +317,49 @@ async function createCtx(options) {
|
|
|
311
317
|
resolvedConfigPath: null,
|
|
312
318
|
engine: null,
|
|
313
319
|
transform: async (code, id) => {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
320
|
+
try {
|
|
321
|
+
if (ctx.isReady === false || !needToTransform(id)) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
ctx.usages.delete(id);
|
|
325
|
+
const functionCalls = findFunctionCalls(code, ctx.fnUtils.RE);
|
|
326
|
+
if (functionCalls.length === 0)
|
|
327
|
+
return;
|
|
328
|
+
const usages = [];
|
|
329
|
+
ctx.usages.set(id, usages);
|
|
330
|
+
const transformed = new MagicString(code);
|
|
331
|
+
for (const fnCall of functionCalls) {
|
|
332
|
+
const functionCallStr = fnCall.snippet;
|
|
333
|
+
const argsStr = `[${functionCallStr.slice(fnCall.fnName.length + 1, -1)}]`;
|
|
334
|
+
const args = new Function(`return ${argsStr}`)();
|
|
335
|
+
const usage = {
|
|
336
|
+
params: args
|
|
337
|
+
};
|
|
338
|
+
usages.push(usage);
|
|
339
|
+
const names = await ctx.engine.use(...args);
|
|
340
|
+
ctx.hooks.tsCodegenUpdated.trigger();
|
|
341
|
+
let transformedContent;
|
|
342
|
+
if (ctx.fnUtils.isNormal(fnCall.fnName)) {
|
|
343
|
+
transformedContent = ctx.transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : ctx.transformedFormat === "string" ? `'${names.join(" ")}'` : names.join(" ");
|
|
344
|
+
} else if (ctx.fnUtils.isForceString(fnCall.fnName)) {
|
|
345
|
+
transformedContent = `'${names.join(" ")}'`;
|
|
346
|
+
} else if (ctx.fnUtils.isForceArray(fnCall.fnName)) {
|
|
347
|
+
transformedContent = `[${names.map((n) => `'${n}'`).join(", ")}]`;
|
|
348
|
+
} else if (ctx.fnUtils.isForceInline(fnCall.fnName)) {
|
|
349
|
+
transformedContent = names.join(" ");
|
|
350
|
+
} else {
|
|
351
|
+
throw new Error(`Unexpected function name: ${fnCall.fnName}`);
|
|
352
|
+
}
|
|
353
|
+
transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
|
|
345
354
|
}
|
|
346
|
-
|
|
355
|
+
return {
|
|
356
|
+
code: transformed.toString(),
|
|
357
|
+
map: transformed.generateMap({ hires: true })
|
|
358
|
+
};
|
|
359
|
+
} catch (error) {
|
|
360
|
+
console.warn(`[${ctx.currentPackageName}] Failed to transform code: ${error}`);
|
|
361
|
+
return void 0;
|
|
347
362
|
}
|
|
348
|
-
return {
|
|
349
|
-
code: transformed.toString(),
|
|
350
|
-
map: transformed.generateMap({ hires: true })
|
|
351
|
-
};
|
|
352
363
|
},
|
|
353
364
|
writeDevCssFile: async () => {
|
|
354
365
|
if (ctx.isReady === false)
|
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.6",
|
|
8
8
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"micromatch": "^4.0.8",
|
|
42
42
|
"pathe": "^2.0.3",
|
|
43
43
|
"prettier": "^3.2.5",
|
|
44
|
-
"@pikacss/core": "0.0.
|
|
44
|
+
"@pikacss/core": "0.0.6"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/micromatch": "^4.0.9"
|