@pikacss/unplugin-pikacss 0.0.47 → 0.0.49

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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @pikacss/unplugin-pikacss
2
+
3
+ Universal bundler plugin for PikaCSS. Supports Vite, Webpack, Rspack, Rollup, Rolldown, and esbuild.
4
+
5
+ The Vite entry supports Vite 7 and 8 only.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add -D @pikacss/unplugin-pikacss
11
+ ```
12
+
13
+ When using the `@pikacss/unplugin-pikacss/vite` entry, install Vite 7 or 8.
14
+
15
+ ## Usage
16
+
17
+ ### Vite
18
+
19
+ ```ts
20
+ // vite.config.ts
21
+ import pikacss from '@pikacss/unplugin-pikacss/vite'
22
+ import { defineConfig } from 'vite'
23
+
24
+ export default defineConfig({
25
+ plugins: [pikacss()],
26
+ })
27
+ ```
28
+
29
+ ### Other bundlers
30
+
31
+ ```ts
32
+ import pikacss from '@pikacss/unplugin-pikacss/rollup'
33
+ import pikacss from '@pikacss/unplugin-pikacss/rspack'
34
+ import pikacss from '@pikacss/unplugin-pikacss/webpack'
35
+ ```
36
+
37
+ ## Documentation
38
+
39
+ See the [full documentation](https://pikacss.com/guide/integrations/vite).
40
+
41
+ ## License
42
+
43
+ MIT
@@ -1,8 +1,24 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
- import * as unplugin from "unplugin";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-237J7YdE.mjs";
2
+ import * as _$unplugin from "unplugin";
3
3
  export * from "@pikacss/integration";
4
4
 
5
5
  //#region src/esbuild.d.ts
6
- declare const _default: (options?: PluginOptions | undefined) => unplugin.EsbuildPlugin;
6
+ /**
7
+ * PikaCSS plugin factory for esbuild.
8
+ *
9
+ * Wraps the shared PikaCSS unplugin factory into an esbuild-compatible
10
+ * plugin. Accepts optional {@link PluginOptions} to configure scanning,
11
+ * code generation, and engine settings.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import pikacss from '@pikacss/unplugin-pikacss/esbuild'
16
+ *
17
+ * await esbuild.build({
18
+ * plugins: [pikacss()],
19
+ * })
20
+ * ```
21
+ */
22
+ declare const _default: (options?: PluginOptions | undefined) => _$unplugin.EsbuildPlugin;
7
23
  //#endregion
8
24
  export { PluginOptions, ResolvedPluginOptions, _default as default };
package/dist/esbuild.mjs CHANGED
@@ -1,10 +1,23 @@
1
1
  import { unpluginFactory } from "./index.mjs";
2
2
  import { createEsbuildPlugin } from "unplugin";
3
-
4
- export * from "@pikacss/integration"
5
-
3
+ export * from "@pikacss/integration";
6
4
  //#region src/esbuild.ts
5
+ /**
6
+ * PikaCSS plugin factory for esbuild.
7
+ *
8
+ * Wraps the shared PikaCSS unplugin factory into an esbuild-compatible
9
+ * plugin. Accepts optional {@link PluginOptions} to configure scanning,
10
+ * code generation, and engine settings.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import pikacss from '@pikacss/unplugin-pikacss/esbuild'
15
+ *
16
+ * await esbuild.build({
17
+ * plugins: [pikacss()],
18
+ * })
19
+ * ```
20
+ */
7
21
  var esbuild_default = createEsbuildPlugin(unpluginFactory);
8
-
9
22
  //#endregion
10
- export { esbuild_default as default };
23
+ export { esbuild_default as default };
package/dist/index.d.mts CHANGED
@@ -1,10 +1,47 @@
1
- import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-CnxVmogs.mjs";
2
- import * as unplugin from "unplugin";
1
+ import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-237J7YdE.mjs";
2
+ import * as _$unplugin from "unplugin";
3
3
  import { UnpluginFactory } from "unplugin";
4
4
  export * from "@pikacss/integration";
5
5
 
6
6
  //#region src/index.d.ts
7
+ /**
8
+ * Factory function that produces the bundler-agnostic PikaCSS plugin hooks.
9
+ *
10
+ * @param options - User-supplied plugin configuration. When `undefined`, all defaults apply.
11
+ * @param meta - Unplugin metadata providing the target bundler framework name.
12
+ * @returns An unplugin hooks object consumed by Vite, webpack, Rollup, esbuild, and Rspack.
13
+ *
14
+ * @remarks
15
+ * This is the core entry-point called by `createUnplugin`. It resolves user options,
16
+ * creates an integration context via `createCtx`, and wires bundler-specific lifecycle
17
+ * hooks (config resolution, dev-server HMR, build transforms, and config file watching).
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { unpluginFactory } from '@pikacss/unplugin-pikacss'
22
+ * import { createUnplugin } from 'unplugin'
23
+ *
24
+ * const plugin = createUnplugin(unpluginFactory)
25
+ * ```
26
+ */
7
27
  declare const unpluginFactory: UnpluginFactory<PluginOptions | undefined>;
8
- declare const unpluginPika: unplugin.UnpluginInstance<PluginOptions | undefined, boolean>;
28
+ /**
29
+ * Pre-built universal bundler plugin for PikaCSS.
30
+ *
31
+ * @remarks
32
+ * Created by passing `unpluginFactory` to `createUnplugin`. Import the bundler-specific
33
+ * sub-path (e.g., `@pikacss/unplugin-pikacss/vite`) for a ready-to-use plugin instance.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * // vite.config.ts
38
+ * import pika from '@pikacss/unplugin-pikacss/vite'
39
+ *
40
+ * export default defineConfig({
41
+ * plugins: [pika()],
42
+ * })
43
+ * ```
44
+ */
45
+ declare const unpluginPika: _$unplugin.UnpluginInstance<PluginOptions | undefined, boolean>;
9
46
  //#endregion
10
47
  export { PluginOptions, ResolvedPluginOptions, unpluginPika as default, unpluginPika, unpluginFactory };
package/dist/index.mjs CHANGED
@@ -4,14 +4,32 @@ import { createCtx, log } from "@pikacss/integration";
4
4
  import { resolve } from "pathe";
5
5
  import { debounce } from "perfect-debounce";
6
6
  import { createUnplugin } from "unplugin";
7
-
8
- export * from "@pikacss/integration"
9
-
7
+ export * from "@pikacss/integration";
10
8
  //#region src/index.ts
11
9
  const RE_VIRTUAL_PIKA_CSS_ID = /^pika\.css$/;
12
10
  const PLUGIN_NAME = "unplugin-pikacss";
11
+ /**
12
+ * Factory function that produces the bundler-agnostic PikaCSS plugin hooks.
13
+ *
14
+ * @param options - User-supplied plugin configuration. When `undefined`, all defaults apply.
15
+ * @param meta - Unplugin metadata providing the target bundler framework name.
16
+ * @returns An unplugin hooks object consumed by Vite, webpack, Rollup, esbuild, and Rspack.
17
+ *
18
+ * @remarks
19
+ * This is the core entry-point called by `createUnplugin`. It resolves user options,
20
+ * creates an integration context via `createCtx`, and wires bundler-specific lifecycle
21
+ * hooks (config resolution, dev-server HMR, build transforms, and config file watching).
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { unpluginFactory } from '@pikacss/unplugin-pikacss'
26
+ * import { createUnplugin } from 'unplugin'
27
+ *
28
+ * const plugin = createUnplugin(unpluginFactory)
29
+ * ```
30
+ */
13
31
  const unpluginFactory = (options, meta) => {
14
- const { currentPackageName = "@pikacss/unplugin-pikacss", config: configOrPath, tsCodegen = true, cssCodegen = true, scan = {}, fnName = "pika", transformedFormat = "string", autoCreateConfig = true } = options ?? {};
32
+ const { cwd: userCwd, currentPackageName = "@pikacss/unplugin-pikacss", config: configOrPath, tsCodegen = true, cssCodegen = true, scan = {}, fnName = "pika", transformedFormat = "string", autoCreateConfig = true } = options ?? {};
15
33
  log.debug("Creating unplugin factory with options:", options);
16
34
  const resolvedOptions = {
17
35
  currentPackageName,
@@ -27,22 +45,16 @@ const unpluginFactory = (options, meta) => {
27
45
  autoCreateConfig
28
46
  };
29
47
  log.debug("Resolved plugin options:", resolvedOptions);
30
- let cwd = resolve(process.cwd());
31
48
  let mode = "build";
32
49
  const viteServers = [];
33
50
  const rspackCompilers = [];
34
- const farmServers = [];
35
51
  const ctx = createCtx({
36
- cwd,
52
+ cwd: resolve(userCwd ?? process.cwd()),
37
53
  ...resolvedOptions
38
54
  });
39
- function syncCtxCwd() {
40
- if (ctx.cwd !== cwd) ctx.cwd = cwd;
41
- }
42
55
  function applyRuntimeContext(nextCwd, nextMode) {
43
- cwd = resolve(nextCwd);
56
+ if (userCwd == null) ctx.cwd = resolve(nextCwd);
44
57
  mode = nextMode;
45
- syncCtxCwd();
46
58
  }
47
59
  const debouncedWriteCssCodegenFile = debounce(async () => {
48
60
  await ctx.writeCssCodegenFile();
@@ -50,7 +62,10 @@ const unpluginFactory = (options, meta) => {
50
62
  const debouncedWriteTsCodegenFile = debounce(async () => {
51
63
  await ctx.writeTsCodegenFile();
52
64
  }, 300);
65
+ let hooksBound = false;
53
66
  function bindHooks() {
67
+ if (hooksBound) return;
68
+ hooksBound = true;
54
69
  ctx.hooks.styleUpdated.on(() => {
55
70
  log.debug(`Style updated, ${ctx.engine.store.atomicStyleIds.size} atomic styles generated`);
56
71
  debouncedWriteCssCodegenFile();
@@ -61,24 +76,17 @@ const unpluginFactory = (options, meta) => {
61
76
  });
62
77
  }
63
78
  let setupPromise = Promise.resolve();
64
- let setupCounter = 0;
65
79
  let lastSetupCwd = null;
66
80
  let pendingSetupCwd = null;
67
81
  function setup(reload = false) {
68
- syncCtxCwd();
69
82
  pendingSetupCwd = ctx.cwd;
70
83
  setupPromise = setupPromise.then(async () => {
71
84
  log.debug("Setting up integration context...");
72
- const currentSetup = ++setupCounter;
73
85
  const moduleIds = Array.from(ctx.usages.keys());
74
- syncCtxCwd();
86
+ hooksBound = false;
75
87
  await ctx.setup();
76
88
  lastSetupCwd = ctx.cwd;
77
89
  pendingSetupCwd = null;
78
- if (currentSetup !== setupCounter) {
79
- log.debug("Setup outdated, skipping...");
80
- return;
81
- }
82
90
  await debouncedWriteCssCodegenFile();
83
91
  await debouncedWriteTsCodegenFile();
84
92
  bindHooks();
@@ -102,20 +110,11 @@ const unpluginFactory = (options, meta) => {
102
110
  compiler.watching.invalidateWithChangesAndRemovals(new Set(moduleIds));
103
111
  compiler.watching.invalidate();
104
112
  });
105
- else if (meta.framework === "farm") {
106
- const promises = [];
107
- farmServers.forEach((server) => {
108
- if (server.hmrEngine == null) return;
109
- promises.push(server.hmrEngine.recompileAndSendResult());
110
- });
111
- await Promise.all(promises);
112
- }
113
113
  }
114
114
  });
115
115
  return setupPromise;
116
116
  }
117
117
  function ensureSetup(reload = false) {
118
- syncCtxCwd();
119
118
  if (!reload && (lastSetupCwd === ctx.cwd || pendingSetupCwd === ctx.cwd)) return setupPromise;
120
119
  return setup(reload);
121
120
  }
@@ -134,16 +133,9 @@ const unpluginFactory = (options, meta) => {
134
133
  applyRuntimeContext(compiler.options.context || process.cwd(), compiler.options.mode === "development" ? "serve" : "build");
135
134
  },
136
135
  rspack: (compiler) => {
136
+ rspackCompilers.push(compiler);
137
137
  applyRuntimeContext(compiler.options.context || process.cwd(), compiler.options.mode === "development" ? "serve" : "build");
138
138
  },
139
- farm: {
140
- configResolved: (config) => {
141
- applyRuntimeContext(config.root || process.cwd(), config.envMode === "development" ? "serve" : "build");
142
- },
143
- configureDevServer(server) {
144
- farmServers.push(server);
145
- }
146
- },
147
139
  esbuild: { async setup(build) {
148
140
  applyRuntimeContext(build.initialOptions.absWorkingDir || process.cwd(), mode);
149
141
  build.onResolve({ filter: RE_VIRTUAL_PIKA_CSS_ID }, (args) => {
@@ -156,7 +148,7 @@ const unpluginFactory = (options, meta) => {
156
148
  } },
157
149
  async buildStart() {
158
150
  log.debug("Plugin buildStart hook triggered");
159
- log.debug(`Current mode: ${mode}, cwd: ${cwd}`);
151
+ log.debug(`Current mode: ${mode}, cwd: ${ctx.cwd}`);
160
152
  await ensureSetup();
161
153
  if (mode === "build") {
162
154
  log.debug("Running full CSS code generation in build mode");
@@ -196,7 +188,23 @@ const unpluginFactory = (options, meta) => {
196
188
  }
197
189
  };
198
190
  };
191
+ /**
192
+ * Pre-built universal bundler plugin for PikaCSS.
193
+ *
194
+ * @remarks
195
+ * Created by passing `unpluginFactory` to `createUnplugin`. Import the bundler-specific
196
+ * sub-path (e.g., `@pikacss/unplugin-pikacss/vite`) for a ready-to-use plugin instance.
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * // vite.config.ts
201
+ * import pika from '@pikacss/unplugin-pikacss/vite'
202
+ *
203
+ * export default defineConfig({
204
+ * plugins: [pika()],
205
+ * })
206
+ * ```
207
+ */
199
208
  const unpluginPika = /* @__PURE__ */ createUnplugin(unpluginFactory);
200
-
201
209
  //#endregion
202
- export { unpluginPika as default, unpluginPika, unpluginFactory };
210
+ export { unpluginPika as default, unpluginPika, unpluginFactory };