@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 CHANGED
@@ -316,7 +316,12 @@ async function createCtx(options) {
316
316
  return { config: null, file: null };
317
317
  });
318
318
  ctx.resolvedConfigPath = file;
319
- ctx.engine = await core.createEngine(config ?? {});
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
- if (ctx.isReady === false || !needToTransform(id)) {
334
- return;
335
- }
336
- ctx.usages.delete(id);
337
- const functionCalls = findFunctionCalls(code, ctx.fnUtils.RE);
338
- if (functionCalls.length === 0)
339
- return;
340
- const usages = [];
341
- ctx.usages.set(id, usages);
342
- const transformed = new MagicString__default(code);
343
- for (const fnCall of functionCalls) {
344
- const functionCallStr = fnCall.snippet;
345
- const argsStr = `[${functionCallStr.slice(fnCall.fnName.length + 1, -1)}]`;
346
- const args = new Function(`return ${argsStr}`)();
347
- const usage = {
348
- params: args
349
- };
350
- usages.push(usage);
351
- const names = await ctx.engine.use(...args);
352
- ctx.hooks.tsCodegenUpdated.trigger();
353
- let transformedContent;
354
- if (ctx.fnUtils.isNormal(fnCall.fnName)) {
355
- transformedContent = ctx.transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : ctx.transformedFormat === "string" ? `'${names.join(" ")}'` : names.join(" ");
356
- } else if (ctx.fnUtils.isForceString(fnCall.fnName)) {
357
- transformedContent = `'${names.join(" ")}'`;
358
- } else if (ctx.fnUtils.isForceArray(fnCall.fnName)) {
359
- transformedContent = `[${names.map((n) => `'${n}'`).join(", ")}]`;
360
- } else if (ctx.fnUtils.isForceInline(fnCall.fnName)) {
361
- transformedContent = names.join(" ");
362
- } else {
363
- throw new Error(`Unexpected function name: ${fnCall.fnName}`);
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
- transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
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
- ctx.engine = await createEngine(config ?? {});
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
- if (ctx.isReady === false || !needToTransform(id)) {
315
- return;
316
- }
317
- ctx.usages.delete(id);
318
- const functionCalls = findFunctionCalls(code, ctx.fnUtils.RE);
319
- if (functionCalls.length === 0)
320
- return;
321
- const usages = [];
322
- ctx.usages.set(id, usages);
323
- const transformed = new MagicString(code);
324
- for (const fnCall of functionCalls) {
325
- const functionCallStr = fnCall.snippet;
326
- const argsStr = `[${functionCallStr.slice(fnCall.fnName.length + 1, -1)}]`;
327
- const args = new Function(`return ${argsStr}`)();
328
- const usage = {
329
- params: args
330
- };
331
- usages.push(usage);
332
- const names = await ctx.engine.use(...args);
333
- ctx.hooks.tsCodegenUpdated.trigger();
334
- let transformedContent;
335
- if (ctx.fnUtils.isNormal(fnCall.fnName)) {
336
- transformedContent = ctx.transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : ctx.transformedFormat === "string" ? `'${names.join(" ")}'` : names.join(" ");
337
- } else if (ctx.fnUtils.isForceString(fnCall.fnName)) {
338
- transformedContent = `'${names.join(" ")}'`;
339
- } else if (ctx.fnUtils.isForceArray(fnCall.fnName)) {
340
- transformedContent = `[${names.map((n) => `'${n}'`).join(", ")}]`;
341
- } else if (ctx.fnUtils.isForceInline(fnCall.fnName)) {
342
- transformedContent = names.join(" ");
343
- } else {
344
- throw new Error(`Unexpected function name: ${fnCall.fnName}`);
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
- transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
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.4",
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.4"
44
+ "@pikacss/core": "0.0.5"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/micromatch": "^4.0.9"