@pikacss/integration 0.0.4 → 0.0.5
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 +47 -37
- package/dist/index.mjs +47 -37
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -316,7 +316,12 @@ async function createCtx(options) {
|
|
|
316
316
|
return { config: null, file: null };
|
|
317
317
|
});
|
|
318
318
|
ctx.resolvedConfigPath = file;
|
|
319
|
-
|
|
319
|
+
try {
|
|
320
|
+
ctx.engine = await core.createEngine(config ?? {});
|
|
321
|
+
} catch (error) {
|
|
322
|
+
console.warn(`[${ctx.currentPackageName}] Failed to create engine: ${error}. Maybe the config file is invalid, falling back to default config.`);
|
|
323
|
+
ctx.engine = await core.createEngine({});
|
|
324
|
+
}
|
|
320
325
|
ctx.engine.config.plugins.unshift({
|
|
321
326
|
name: "@pikacss/integration:dev",
|
|
322
327
|
preflightUpdated: () => ctx.hooks.styleUpdated.trigger(),
|
|
@@ -330,44 +335,49 @@ async function createCtx(options) {
|
|
|
330
335
|
resolvedConfigPath: null,
|
|
331
336
|
engine: null,
|
|
332
337
|
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
|
-
|
|
338
|
+
try {
|
|
339
|
+
if (ctx.isReady === false || !needToTransform(id)) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
ctx.usages.delete(id);
|
|
343
|
+
const functionCalls = findFunctionCalls(code, ctx.fnUtils.RE);
|
|
344
|
+
if (functionCalls.length === 0)
|
|
345
|
+
return;
|
|
346
|
+
const usages = [];
|
|
347
|
+
ctx.usages.set(id, usages);
|
|
348
|
+
const transformed = new MagicString__default(code);
|
|
349
|
+
for (const fnCall of functionCalls) {
|
|
350
|
+
const functionCallStr = fnCall.snippet;
|
|
351
|
+
const argsStr = `[${functionCallStr.slice(fnCall.fnName.length + 1, -1)}]`;
|
|
352
|
+
const args = new Function(`return ${argsStr}`)();
|
|
353
|
+
const usage = {
|
|
354
|
+
params: args
|
|
355
|
+
};
|
|
356
|
+
usages.push(usage);
|
|
357
|
+
const names = await ctx.engine.use(...args);
|
|
358
|
+
ctx.hooks.tsCodegenUpdated.trigger();
|
|
359
|
+
let transformedContent;
|
|
360
|
+
if (ctx.fnUtils.isNormal(fnCall.fnName)) {
|
|
361
|
+
transformedContent = ctx.transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : ctx.transformedFormat === "string" ? `'${names.join(" ")}'` : names.join(" ");
|
|
362
|
+
} else if (ctx.fnUtils.isForceString(fnCall.fnName)) {
|
|
363
|
+
transformedContent = `'${names.join(" ")}'`;
|
|
364
|
+
} else if (ctx.fnUtils.isForceArray(fnCall.fnName)) {
|
|
365
|
+
transformedContent = `[${names.map((n) => `'${n}'`).join(", ")}]`;
|
|
366
|
+
} else if (ctx.fnUtils.isForceInline(fnCall.fnName)) {
|
|
367
|
+
transformedContent = names.join(" ");
|
|
368
|
+
} else {
|
|
369
|
+
throw new Error(`Unexpected function name: ${fnCall.fnName}`);
|
|
370
|
+
}
|
|
371
|
+
transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
|
|
364
372
|
}
|
|
365
|
-
|
|
373
|
+
return {
|
|
374
|
+
code: transformed.toString(),
|
|
375
|
+
map: transformed.generateMap({ hires: true })
|
|
376
|
+
};
|
|
377
|
+
} catch (error) {
|
|
378
|
+
console.warn(`[${ctx.currentPackageName}] Failed to transform code: ${error}`);
|
|
379
|
+
return void 0;
|
|
366
380
|
}
|
|
367
|
-
return {
|
|
368
|
-
code: transformed.toString(),
|
|
369
|
-
map: transformed.generateMap({ hires: true })
|
|
370
|
-
};
|
|
371
381
|
},
|
|
372
382
|
writeDevCssFile: async () => {
|
|
373
383
|
if (ctx.isReady === false)
|
package/dist/index.mjs
CHANGED
|
@@ -297,7 +297,12 @@ async function createCtx(options) {
|
|
|
297
297
|
return { config: null, file: null };
|
|
298
298
|
});
|
|
299
299
|
ctx.resolvedConfigPath = file;
|
|
300
|
-
|
|
300
|
+
try {
|
|
301
|
+
ctx.engine = await createEngine(config ?? {});
|
|
302
|
+
} catch (error) {
|
|
303
|
+
console.warn(`[${ctx.currentPackageName}] Failed to create engine: ${error}. Maybe the config file is invalid, falling back to default config.`);
|
|
304
|
+
ctx.engine = await createEngine({});
|
|
305
|
+
}
|
|
301
306
|
ctx.engine.config.plugins.unshift({
|
|
302
307
|
name: "@pikacss/integration:dev",
|
|
303
308
|
preflightUpdated: () => ctx.hooks.styleUpdated.trigger(),
|
|
@@ -311,44 +316,49 @@ async function createCtx(options) {
|
|
|
311
316
|
resolvedConfigPath: null,
|
|
312
317
|
engine: null,
|
|
313
318
|
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
|
-
|
|
319
|
+
try {
|
|
320
|
+
if (ctx.isReady === false || !needToTransform(id)) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
ctx.usages.delete(id);
|
|
324
|
+
const functionCalls = findFunctionCalls(code, ctx.fnUtils.RE);
|
|
325
|
+
if (functionCalls.length === 0)
|
|
326
|
+
return;
|
|
327
|
+
const usages = [];
|
|
328
|
+
ctx.usages.set(id, usages);
|
|
329
|
+
const transformed = new MagicString(code);
|
|
330
|
+
for (const fnCall of functionCalls) {
|
|
331
|
+
const functionCallStr = fnCall.snippet;
|
|
332
|
+
const argsStr = `[${functionCallStr.slice(fnCall.fnName.length + 1, -1)}]`;
|
|
333
|
+
const args = new Function(`return ${argsStr}`)();
|
|
334
|
+
const usage = {
|
|
335
|
+
params: args
|
|
336
|
+
};
|
|
337
|
+
usages.push(usage);
|
|
338
|
+
const names = await ctx.engine.use(...args);
|
|
339
|
+
ctx.hooks.tsCodegenUpdated.trigger();
|
|
340
|
+
let transformedContent;
|
|
341
|
+
if (ctx.fnUtils.isNormal(fnCall.fnName)) {
|
|
342
|
+
transformedContent = ctx.transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : ctx.transformedFormat === "string" ? `'${names.join(" ")}'` : names.join(" ");
|
|
343
|
+
} else if (ctx.fnUtils.isForceString(fnCall.fnName)) {
|
|
344
|
+
transformedContent = `'${names.join(" ")}'`;
|
|
345
|
+
} else if (ctx.fnUtils.isForceArray(fnCall.fnName)) {
|
|
346
|
+
transformedContent = `[${names.map((n) => `'${n}'`).join(", ")}]`;
|
|
347
|
+
} else if (ctx.fnUtils.isForceInline(fnCall.fnName)) {
|
|
348
|
+
transformedContent = names.join(" ");
|
|
349
|
+
} else {
|
|
350
|
+
throw new Error(`Unexpected function name: ${fnCall.fnName}`);
|
|
351
|
+
}
|
|
352
|
+
transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
|
|
345
353
|
}
|
|
346
|
-
|
|
354
|
+
return {
|
|
355
|
+
code: transformed.toString(),
|
|
356
|
+
map: transformed.generateMap({ hires: true })
|
|
357
|
+
};
|
|
358
|
+
} catch (error) {
|
|
359
|
+
console.warn(`[${ctx.currentPackageName}] Failed to transform code: ${error}`);
|
|
360
|
+
return void 0;
|
|
347
361
|
}
|
|
348
|
-
return {
|
|
349
|
-
code: transformed.toString(),
|
|
350
|
-
map: transformed.generateMap({ hires: true })
|
|
351
|
-
};
|
|
352
362
|
},
|
|
353
363
|
writeDevCssFile: async () => {
|
|
354
364
|
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.5",
|
|
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.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/micromatch": "^4.0.9"
|