@pikacss/unplugin-pikacss 0.0.45 → 0.0.47

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.
@@ -1,4 +1,4 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-B2IGqPK6.mjs";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
2
  import * as unplugin from "unplugin";
3
3
  export * from "@pikacss/integration";
4
4
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-B2IGqPK6.mjs";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
2
  import * as unplugin from "unplugin";
3
3
  import { UnpluginFactory } from "unplugin";
4
4
  export * from "@pikacss/integration";
package/dist/index.mjs CHANGED
@@ -36,6 +36,14 @@ const unpluginFactory = (options, meta) => {
36
36
  cwd,
37
37
  ...resolvedOptions
38
38
  });
39
+ function syncCtxCwd() {
40
+ if (ctx.cwd !== cwd) ctx.cwd = cwd;
41
+ }
42
+ function applyRuntimeContext(nextCwd, nextMode) {
43
+ cwd = resolve(nextCwd);
44
+ mode = nextMode;
45
+ syncCtxCwd();
46
+ }
39
47
  const debouncedWriteCssCodegenFile = debounce(async () => {
40
48
  await ctx.writeCssCodegenFile();
41
49
  }, 300);
@@ -54,12 +62,19 @@ const unpluginFactory = (options, meta) => {
54
62
  }
55
63
  let setupPromise = Promise.resolve();
56
64
  let setupCounter = 0;
65
+ let lastSetupCwd = null;
66
+ let pendingSetupCwd = null;
57
67
  function setup(reload = false) {
68
+ syncCtxCwd();
69
+ pendingSetupCwd = ctx.cwd;
58
70
  setupPromise = setupPromise.then(async () => {
59
71
  log.debug("Setting up integration context...");
60
72
  const currentSetup = ++setupCounter;
61
73
  const moduleIds = Array.from(ctx.usages.keys());
74
+ syncCtxCwd();
62
75
  await ctx.setup();
76
+ lastSetupCwd = ctx.cwd;
77
+ pendingSetupCwd = null;
63
78
  if (currentSetup !== setupCounter) {
64
79
  log.debug("Setup outdated, skipping...");
65
80
  return;
@@ -97,39 +112,40 @@ const unpluginFactory = (options, meta) => {
97
112
  }
98
113
  }
99
114
  });
115
+ return setupPromise;
116
+ }
117
+ function ensureSetup(reload = false) {
118
+ syncCtxCwd();
119
+ if (!reload && (lastSetupCwd === ctx.cwd || pendingSetupCwd === ctx.cwd)) return setupPromise;
120
+ return setup(reload);
100
121
  }
101
122
  const debouncedSetup = debounce(setup);
102
- setup();
103
123
  return {
104
124
  name: PLUGIN_NAME,
105
125
  vite: {
106
126
  configResolved: (config) => {
107
- cwd = resolve(config.root);
108
- mode = config.command === "serve" ? "serve" : "build";
127
+ applyRuntimeContext(config.root, config.command === "serve" ? "serve" : "build");
109
128
  },
110
129
  configureServer(server) {
111
130
  viteServers.push(server);
112
131
  }
113
132
  },
114
133
  webpack: (compiler) => {
115
- cwd = resolve(compiler.options.context || process.cwd());
116
- mode = compiler.options.mode === "development" ? "serve" : "build";
134
+ applyRuntimeContext(compiler.options.context || process.cwd(), compiler.options.mode === "development" ? "serve" : "build");
117
135
  },
118
136
  rspack: (compiler) => {
119
- cwd = resolve(compiler.options.context || process.cwd());
120
- mode = compiler.options.mode === "development" ? "serve" : "build";
137
+ applyRuntimeContext(compiler.options.context || process.cwd(), compiler.options.mode === "development" ? "serve" : "build");
121
138
  },
122
139
  farm: {
123
140
  configResolved: (config) => {
124
- cwd = resolve(config.root || process.cwd());
125
- mode = config.envMode === "development" ? "serve" : "build";
141
+ applyRuntimeContext(config.root || process.cwd(), config.envMode === "development" ? "serve" : "build");
126
142
  },
127
143
  configureDevServer(server) {
128
144
  farmServers.push(server);
129
145
  }
130
146
  },
131
147
  esbuild: { async setup(build) {
132
- cwd = resolve(build.initialOptions.absWorkingDir || process.cwd());
148
+ applyRuntimeContext(build.initialOptions.absWorkingDir || process.cwd(), mode);
133
149
  build.onResolve({ filter: RE_VIRTUAL_PIKA_CSS_ID }, (args) => {
134
150
  log.debug(`Resolved virtual CSS module: ${args.path} -> ${ctx.cssCodegenFilepath}`);
135
151
  return {
@@ -141,7 +157,7 @@ const unpluginFactory = (options, meta) => {
141
157
  async buildStart() {
142
158
  log.debug("Plugin buildStart hook triggered");
143
159
  log.debug(`Current mode: ${mode}, cwd: ${cwd}`);
144
- await setupPromise;
160
+ await ensureSetup();
145
161
  if (mode === "build") {
146
162
  log.debug("Running full CSS code generation in build mode");
147
163
  await ctx.fullyCssCodegen();
@@ -153,7 +169,7 @@ const unpluginFactory = (options, meta) => {
153
169
  },
154
170
  resolveId: meta.framework === "esbuild" ? void 0 : async function(id) {
155
171
  if (RE_VIRTUAL_PIKA_CSS_ID.test(id)) {
156
- await setupPromise;
172
+ await ensureSetup();
157
173
  log.debug(`Resolved virtual CSS module: ${id} -> ${ctx.cssCodegenFilepath}`);
158
174
  return ctx.cssCodegenFilepath;
159
175
  }
@@ -163,7 +179,8 @@ const unpluginFactory = (options, meta) => {
163
179
  filter: { get id() {
164
180
  return ctx.transformFilter;
165
181
  } },
166
- handler(code, id) {
182
+ async handler(code, id) {
183
+ await ensureSetup();
167
184
  if (meta.framework === "webpack" && ctx.resolvedConfigPath != null) {
168
185
  this.addWatchFile(ctx.resolvedConfigPath);
169
186
  log.debug(`Added watch file: ${ctx.resolvedConfigPath}`);
@@ -1,4 +1,4 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-B2IGqPK6.mjs";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
2
  import * as unplugin from "unplugin";
3
3
  export * from "@pikacss/integration";
4
4
 
package/dist/rollup.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-B2IGqPK6.mjs";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
2
  import * as rollup from "rollup";
3
3
  export * from "@pikacss/integration";
4
4
 
package/dist/rspack.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-B2IGqPK6.mjs";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
2
  export * from "@pikacss/integration";
3
3
 
4
4
  //#region src/rspack.d.ts
@@ -7,7 +7,8 @@ interface PluginOptions {
7
7
  *
8
8
  * Default values:
9
9
  * - `include`: `['**\/*.{js,ts,jsx,tsx,vue}']` - Scans all JS/TS/Vue files by default
10
- * - `exclude`: `['node_modules/**']` - Excludes node_modules by default
10
+ * - `exclude`: `['node_modules/**', 'dist/**']` - Excludes dependency and build output folders by default
11
+ * Different wrappers may further narrow or extend these defaults before they reach unplugin.
11
12
  * @example
12
13
  * scan: {
13
14
  * include: ['src/**\/{*.ts,*.tsx,*.vue}'],
@@ -28,7 +29,7 @@ interface PluginOptions {
28
29
  };
29
30
  /**
30
31
  * Configuration object or path to a configuration file for the PikaCSS engine.
31
- * Can pass a config object directly to define engine options, or a config file path (e.g., 'pika.config.ts').
32
+ * Can pass a config object directly to define engine options, or a config file path (e.g., 'pika.config.js').
32
33
  *
33
34
  * Behavior:
34
35
  * - If a file path is specified but the file doesn't exist and autoCreateConfig is true, a config file will be generated at the specified path.
@@ -37,14 +38,14 @@ interface PluginOptions {
37
38
  * @example
38
39
  * config: { prefix: 'pika-', defaultSelector: '.%' }
39
40
  * // or
40
- * config: './pika.config.ts'
41
+ * config: './pika.config.js'
41
42
  */
42
43
  config?: EngineConfig | string;
43
44
  /**
44
45
  * Whether to automatically create a configuration file when needed.
45
46
  *
46
47
  * Behavior:
47
- * - If config is not provided: Creates a default 'pika.config.ts' in the project root.
48
+ * - If config is not provided: Creates a default 'pika.config.js' in the project root.
48
49
  * - If config is a file path that doesn't exist: Creates a config file at the specified path.
49
50
  * - If config is an inline config object: This option is ignored (no file will be created).
50
51
  * @default true
@@ -61,10 +62,9 @@ interface PluginOptions {
61
62
  * The format of the generated atomic style class names.
62
63
  * - `'string'`: Returns a space-separated string of class names (e.g., "a b c")
63
64
  * - `'array'`: Returns an array of class names (e.g., ['a', 'b', 'c'])
64
- * - `'inline'`: Returns an object format that can be directly used in style objects
65
65
  * @default 'string'
66
66
  */
67
- transformedFormat?: 'string' | 'array' | 'inline';
67
+ transformedFormat?: 'string' | 'array';
68
68
  /**
69
69
  * Configuration for TypeScript code generation file.
70
70
  * - `true`: Auto-generate as 'pika.gen.ts'
@@ -96,7 +96,7 @@ interface ResolvedPluginOptions {
96
96
  cssCodegen: string;
97
97
  scan: IntegrationContextOptions['scan'];
98
98
  fnName: string;
99
- transformedFormat: 'string' | 'array' | 'inline';
99
+ transformedFormat: 'string' | 'array';
100
100
  autoCreateConfig: boolean;
101
101
  }
102
102
  //#endregion
package/dist/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-B2IGqPK6.mjs";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
2
  import "./index.mjs";
3
3
  import { Plugin } from "vite";
4
4
  export * from "@pikacss/integration";
@@ -1,4 +1,4 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-B2IGqPK6.mjs";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
2
  export * from "@pikacss/integration";
3
3
 
4
4
  //#region src/webpack.d.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pikacss/unplugin-pikacss",
3
3
  "type": "module",
4
- "version": "0.0.45",
4
+ "version": "0.0.47",
5
5
  "author": "DevilTea <ch19980814@gmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -89,7 +89,7 @@
89
89
  "pathe": "^2.0.3",
90
90
  "perfect-debounce": "^2.1.0",
91
91
  "unplugin": "^3.0.0",
92
- "@pikacss/integration": "0.0.45"
92
+ "@pikacss/integration": "0.0.47"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@farmfe/core": "^1.7.11",