@pikacss/vite-plugin-pikacss 0.0.3 → 0.0.4

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
@@ -2,16 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const vite = require('vite');
6
5
  const integration = require('@pikacss/integration');
6
+ const vite = require('vite');
7
7
  const pathe = require('pathe');
8
8
  const perfectDebounce = require('perfect-debounce');
9
9
 
10
10
  const VIRTUAL_PIKA_CSS_ID = "virtual:pika.css";
11
+ const SHARED_PLUGIN_NAME = "pikacss:shared";
11
12
  const DEV_PLUGIN_NAME = "pikacss:dev";
12
13
  const BUILD_PLUGIN_NAME = "pikacss:build";
13
14
 
14
- function build(options) {
15
+ function build(getCtx) {
15
16
  const cssPostPlugins = /* @__PURE__ */ new Map();
16
17
  const cssPlugins = /* @__PURE__ */ new Map();
17
18
  async function applyCssTransform(css, id, dir, rollupCtx) {
@@ -33,10 +34,7 @@ function build(options) {
33
34
  enforce: "pre",
34
35
  apply: "build",
35
36
  async configResolved(config) {
36
- ctx = await integration.createCtx({
37
- cwd: config.root,
38
- ...options
39
- });
37
+ ctx = await getCtx();
40
38
  const distDirs = [
41
39
  pathe.resolve(config.root, config.build.outDir)
42
40
  ];
@@ -60,10 +58,10 @@ function build(options) {
60
58
  transform: (code, id) => {
61
59
  return ctx.transform(code, id);
62
60
  },
63
- async renderChunk(_, chunk, options2) {
61
+ async renderChunk(_, chunk, options) {
64
62
  if (!Object.keys(chunk.modules).some((i) => i.includes(VIRTUAL_PIKA_CSS_ID)))
65
63
  return null;
66
- const cssPost = cssPostPlugins.get(options2.dir);
64
+ const cssPost = cssPostPlugins.get(options.dir);
67
65
  if (!cssPost) {
68
66
  this.warn("[pikacss] failed to find vite:css-post plugin. It might be an internal bug of PikaCSS");
69
67
  return null;
@@ -73,7 +71,7 @@ function build(options) {
73
71
  const css = await applyCssTransform(
74
72
  ctx.engine.renderStyles(),
75
73
  fakeCssId,
76
- options2.dir,
74
+ options.dir,
77
75
  this
78
76
  );
79
77
  const transformHandler = "handler" in cssPost.transform ? cssPost.transform.handler : cssPost.transform;
@@ -91,7 +89,7 @@ function build(options) {
91
89
  };
92
90
  }
93
91
 
94
- function dev(options) {
92
+ function dev(getCtx) {
95
93
  let ctx = null;
96
94
  const updateDevCssFile = perfectDebounce.debounce(async () => {
97
95
  await ctx.writeDevCssFile();
@@ -106,11 +104,8 @@ function dev(options) {
106
104
  name: DEV_PLUGIN_NAME,
107
105
  enforce: "pre",
108
106
  apply: "serve",
109
- async configResolved(config) {
110
- ctx = await integration.createCtx({
111
- cwd: config.root,
112
- ...options
113
- });
107
+ async configResolved() {
108
+ ctx = await getCtx();
114
109
  },
115
110
  configureServer(server) {
116
111
  server.watcher.add(ctx.configSources);
@@ -148,10 +143,19 @@ function dev(options) {
148
143
  };
149
144
  }
150
145
 
146
+ function createPromise() {
147
+ let resolve;
148
+ let reject;
149
+ const promise = new Promise((res, rej) => {
150
+ resolve = res;
151
+ reject = rej;
152
+ });
153
+ return { promise, resolve, reject };
154
+ }
151
155
  function PikaCSSPlugin({
152
156
  currentPackageName = "@pikacss/vite-plugin-pikacss",
153
157
  config: configOrPath,
154
- tsCodegen = false,
158
+ tsCodegen = true,
155
159
  devCss = "pika.dev.css",
156
160
  target = ["**/*.vue", "**/*.tsx", "**/*.jsx"],
157
161
  fnName = "pika",
@@ -169,10 +173,26 @@ function PikaCSSPlugin({
169
173
  transformTsToJs: (code) => vite.transformWithEsbuild(code, "pikacss.ts").then((result) => result.code),
170
174
  autoCreateConfig
171
175
  };
172
- return [
173
- dev(resolvedOptions),
174
- build(resolvedOptions)
176
+ const { promise, resolve } = createPromise();
177
+ function getCtx() {
178
+ return promise;
179
+ }
180
+ const plugin = [
181
+ {
182
+ name: SHARED_PLUGIN_NAME,
183
+ enforce: "pre",
184
+ async configResolved(config) {
185
+ resolve(await integration.createCtx({
186
+ cwd: config.root,
187
+ ...resolvedOptions
188
+ }));
189
+ }
190
+ },
191
+ dev(getCtx),
192
+ build(getCtx)
175
193
  ];
194
+ plugin.getCtx = getCtx;
195
+ return plugin;
176
196
  }
177
197
 
178
198
  exports.default = PikaCSSPlugin;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { EngineConfig } from '@pikacss/integration';
1
+ import { EngineConfig, IntegrationContext } from '@pikacss/integration';
2
2
  export * from '@pikacss/integration';
3
3
  import { Plugin } from 'vite';
4
4
 
@@ -49,7 +49,9 @@ interface PluginOptions {
49
49
  currentPackageName?: string;
50
50
  }
51
51
 
52
- declare function PikaCSSPlugin({ currentPackageName, config: configOrPath, tsCodegen, devCss, target, fnName, transformedFormat, autoCreateConfig, }?: PluginOptions): Plugin[];
52
+ declare function PikaCSSPlugin({ currentPackageName, config: configOrPath, tsCodegen, devCss, target, fnName, transformedFormat, autoCreateConfig, }?: PluginOptions): Plugin[] & {
53
+ getCtx: () => Promise<IntegrationContext>;
54
+ };
53
55
 
54
56
  // @ts-ignore
55
57
  export = PikaCSSPlugin;
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { EngineConfig } from '@pikacss/integration';
1
+ import { EngineConfig, IntegrationContext } from '@pikacss/integration';
2
2
  export * from '@pikacss/integration';
3
3
  import { Plugin } from 'vite';
4
4
 
@@ -49,6 +49,8 @@ interface PluginOptions {
49
49
  currentPackageName?: string;
50
50
  }
51
51
 
52
- declare function PikaCSSPlugin({ currentPackageName, config: configOrPath, tsCodegen, devCss, target, fnName, transformedFormat, autoCreateConfig, }?: PluginOptions): Plugin[];
52
+ declare function PikaCSSPlugin({ currentPackageName, config: configOrPath, tsCodegen, devCss, target, fnName, transformedFormat, autoCreateConfig, }?: PluginOptions): Plugin[] & {
53
+ getCtx: () => Promise<IntegrationContext>;
54
+ };
53
55
 
54
56
  export { type PluginOptions, PikaCSSPlugin as default };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EngineConfig } from '@pikacss/integration';
1
+ import { EngineConfig, IntegrationContext } from '@pikacss/integration';
2
2
  export * from '@pikacss/integration';
3
3
  import { Plugin } from 'vite';
4
4
 
@@ -49,7 +49,9 @@ interface PluginOptions {
49
49
  currentPackageName?: string;
50
50
  }
51
51
 
52
- declare function PikaCSSPlugin({ currentPackageName, config: configOrPath, tsCodegen, devCss, target, fnName, transformedFormat, autoCreateConfig, }?: PluginOptions): Plugin[];
52
+ declare function PikaCSSPlugin({ currentPackageName, config: configOrPath, tsCodegen, devCss, target, fnName, transformedFormat, autoCreateConfig, }?: PluginOptions): Plugin[] & {
53
+ getCtx: () => Promise<IntegrationContext>;
54
+ };
53
55
 
54
56
  // @ts-ignore
55
57
  export = PikaCSSPlugin;
package/dist/index.mjs CHANGED
@@ -1,14 +1,15 @@
1
- import { transformWithEsbuild } from 'vite';
2
1
  import { createCtx } from '@pikacss/integration';
3
2
  export * from '@pikacss/integration';
3
+ import { transformWithEsbuild } from 'vite';
4
4
  import { resolve } from 'pathe';
5
5
  import { debounce } from 'perfect-debounce';
6
6
 
7
7
  const VIRTUAL_PIKA_CSS_ID = "virtual:pika.css";
8
+ const SHARED_PLUGIN_NAME = "pikacss:shared";
8
9
  const DEV_PLUGIN_NAME = "pikacss:dev";
9
10
  const BUILD_PLUGIN_NAME = "pikacss:build";
10
11
 
11
- function build(options) {
12
+ function build(getCtx) {
12
13
  const cssPostPlugins = /* @__PURE__ */ new Map();
13
14
  const cssPlugins = /* @__PURE__ */ new Map();
14
15
  async function applyCssTransform(css, id, dir, rollupCtx) {
@@ -30,10 +31,7 @@ function build(options) {
30
31
  enforce: "pre",
31
32
  apply: "build",
32
33
  async configResolved(config) {
33
- ctx = await createCtx({
34
- cwd: config.root,
35
- ...options
36
- });
34
+ ctx = await getCtx();
37
35
  const distDirs = [
38
36
  resolve(config.root, config.build.outDir)
39
37
  ];
@@ -57,10 +55,10 @@ function build(options) {
57
55
  transform: (code, id) => {
58
56
  return ctx.transform(code, id);
59
57
  },
60
- async renderChunk(_, chunk, options2) {
58
+ async renderChunk(_, chunk, options) {
61
59
  if (!Object.keys(chunk.modules).some((i) => i.includes(VIRTUAL_PIKA_CSS_ID)))
62
60
  return null;
63
- const cssPost = cssPostPlugins.get(options2.dir);
61
+ const cssPost = cssPostPlugins.get(options.dir);
64
62
  if (!cssPost) {
65
63
  this.warn("[pikacss] failed to find vite:css-post plugin. It might be an internal bug of PikaCSS");
66
64
  return null;
@@ -70,7 +68,7 @@ function build(options) {
70
68
  const css = await applyCssTransform(
71
69
  ctx.engine.renderStyles(),
72
70
  fakeCssId,
73
- options2.dir,
71
+ options.dir,
74
72
  this
75
73
  );
76
74
  const transformHandler = "handler" in cssPost.transform ? cssPost.transform.handler : cssPost.transform;
@@ -88,7 +86,7 @@ function build(options) {
88
86
  };
89
87
  }
90
88
 
91
- function dev(options) {
89
+ function dev(getCtx) {
92
90
  let ctx = null;
93
91
  const updateDevCssFile = debounce(async () => {
94
92
  await ctx.writeDevCssFile();
@@ -103,11 +101,8 @@ function dev(options) {
103
101
  name: DEV_PLUGIN_NAME,
104
102
  enforce: "pre",
105
103
  apply: "serve",
106
- async configResolved(config) {
107
- ctx = await createCtx({
108
- cwd: config.root,
109
- ...options
110
- });
104
+ async configResolved() {
105
+ ctx = await getCtx();
111
106
  },
112
107
  configureServer(server) {
113
108
  server.watcher.add(ctx.configSources);
@@ -145,10 +140,19 @@ function dev(options) {
145
140
  };
146
141
  }
147
142
 
143
+ function createPromise() {
144
+ let resolve;
145
+ let reject;
146
+ const promise = new Promise((res, rej) => {
147
+ resolve = res;
148
+ reject = rej;
149
+ });
150
+ return { promise, resolve, reject };
151
+ }
148
152
  function PikaCSSPlugin({
149
153
  currentPackageName = "@pikacss/vite-plugin-pikacss",
150
154
  config: configOrPath,
151
- tsCodegen = false,
155
+ tsCodegen = true,
152
156
  devCss = "pika.dev.css",
153
157
  target = ["**/*.vue", "**/*.tsx", "**/*.jsx"],
154
158
  fnName = "pika",
@@ -166,10 +170,26 @@ function PikaCSSPlugin({
166
170
  transformTsToJs: (code) => transformWithEsbuild(code, "pikacss.ts").then((result) => result.code),
167
171
  autoCreateConfig
168
172
  };
169
- return [
170
- dev(resolvedOptions),
171
- build(resolvedOptions)
173
+ const { promise, resolve } = createPromise();
174
+ function getCtx() {
175
+ return promise;
176
+ }
177
+ const plugin = [
178
+ {
179
+ name: SHARED_PLUGIN_NAME,
180
+ enforce: "pre",
181
+ async configResolved(config) {
182
+ resolve(await createCtx({
183
+ cwd: config.root,
184
+ ...resolvedOptions
185
+ }));
186
+ }
187
+ },
188
+ dev(getCtx),
189
+ build(getCtx)
172
190
  ];
191
+ plugin.getCtx = getCtx;
192
+ return plugin;
173
193
  }
174
194
 
175
195
  export { PikaCSSPlugin as default };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.0.3",
7
+ "version": "0.0.4",
8
8
  "author": "DevilTea <ch19980814@gmail.com>",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "pathe": "^2.0.3",
41
41
  "perfect-debounce": "^1.0.0",
42
- "@pikacss/integration": "0.0.3"
42
+ "@pikacss/integration": "0.0.4"
43
43
  },
44
44
  "devDependencies": {
45
45
  "vite": "^6.1.1"