kirbyup 3.1.1 → 3.1.3

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 CHANGED
@@ -190,7 +190,7 @@ export default defineConfig({
190
190
  alias: {
191
191
  '#plugin/': `${resolve(currentDir, 'src/plugin')}/`
192
192
  },
193
- extendViteConfig: {
193
+ vite: {
194
194
  define: {
195
195
  __PLAYGROUND__: JSON.stringify(process.env.PLAYGROUND)
196
196
  }
@@ -202,7 +202,7 @@ export default defineConfig({
202
202
 
203
203
  When aliasing to file system paths, always use absolute paths. Relative alias values will be used as-is and will not be resolved into file system paths.
204
204
 
205
- #### `extendViteConfig`
205
+ #### `vite`
206
206
 
207
207
  You can build upon the defaults kirbup uses and extend the Vite configuration with custom plugins etc.
208
208
 
@@ -247,7 +247,6 @@ Disables the default behavior of watching all PHP files for changes.
247
247
  ## Credits
248
248
 
249
249
  - [Vite](https://vitejs.dev) by Evan You and all of its contributors.
250
- - [EGOIST](https://github.com/egoist) for his inspirational work on [tsup](https://github.com/egoist/tsup).
251
250
 
252
251
  ## License
253
252
 
@@ -1,4 +1,4 @@
1
- import { U as UserConfig } from '../shared/kirbyup.cf02d174.mjs';
1
+ import { U as UserConfig } from '../shared/kirbyup.bcda4592.mjs';
2
2
  import 'vite';
3
3
 
4
4
  declare function defineConfig(config: UserConfig): UserConfig;
@@ -1,4 +1,4 @@
1
- import { U as UserConfig } from '../shared/kirbyup.cf02d174.js';
1
+ import { U as UserConfig } from '../shared/kirbyup.bcda4592.js';
2
2
  import 'vite';
3
3
 
4
4
  declare function defineConfig(config: UserConfig): UserConfig;
@@ -1,7 +1,7 @@
1
1
  declare const kirbyup: Readonly<{
2
2
  /**
3
- * Auto-import Kirby Panel components, will be transformed by
4
- * kirbyup's auto import plugin for Vite
3
+ * Auto-import Kirby Panel components, transformed by
4
+ * kirbyup's glob-import plugin for Vite.
5
5
  *
6
6
  * @example
7
7
  * kirbyup.import('./components/blocks/*.vue')
@@ -1,7 +1,7 @@
1
1
  declare const kirbyup: Readonly<{
2
2
  /**
3
- * Auto-import Kirby Panel components, will be transformed by
4
- * kirbyup's auto import plugin for Vite
3
+ * Auto-import Kirby Panel components, transformed by
4
+ * kirbyup's glob-import plugin for Vite.
5
5
  *
6
6
  * @example
7
7
  * kirbyup.import('./components/blocks/*.vue')
@@ -1,7 +1,7 @@
1
1
  const kirbyup = Object.freeze({
2
2
  /**
3
- * Auto-import Kirby Panel components, will be transformed by
4
- * kirbyup's auto import plugin for Vite
3
+ * Auto-import Kirby Panel components, transformed by
4
+ * kirbyup's glob-import plugin for Vite.
5
5
  *
6
6
  * @example
7
7
  * kirbyup.import('./components/blocks/*.vue')
package/dist/node/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { cac } from 'cac';
2
- import { n as name, b as build, s as serve, v as version, h as handleError } from '../shared/kirbyup.90533c57.mjs';
2
+ import { n as name, b as build, s as serve, v as version, h as handleError } from '../shared/kirbyup.db20dc98.mjs';
3
3
  import 'node:fs';
4
4
  import 'node:fs/promises';
5
5
  import 'pathe';
@@ -12,13 +12,13 @@ import '@vitejs/plugin-vue2';
12
12
  import '@vitejs/plugin-vue2-jsx';
13
13
  import 'vite-plugin-full-reload';
14
14
  import 'rollup-plugin-external-globals';
15
- import 'postcss-load-config';
16
- import 'postcss-logical';
17
- import 'postcss-dir-pseudo-class';
18
15
  import 'node:zlib';
19
16
  import 'node:util';
20
17
  import 'node:buffer';
21
18
  import 'c12';
19
+ import 'postcss-load-config';
20
+ import 'postcss-logical';
21
+ import 'postcss-dir-pseudo-class';
22
22
  import 'magic-string';
23
23
  import 'node:module';
24
24
 
@@ -1,5 +1,5 @@
1
1
  import * as vite from 'vite';
2
- import { B as BuildOptions, S as ServeOptions } from '../shared/kirbyup.cf02d174.mjs';
2
+ import { B as BuildOptions, S as ServeOptions } from '../shared/kirbyup.bcda4592.mjs';
3
3
 
4
4
  declare function build(options: BuildOptions): Promise<void>;
5
5
  declare function serve(options: ServeOptions): Promise<vite.ViteDevServer>;
@@ -1,5 +1,5 @@
1
1
  import * as vite from 'vite';
2
- import { B as BuildOptions, S as ServeOptions } from '../shared/kirbyup.cf02d174.js';
2
+ import { B as BuildOptions, S as ServeOptions } from '../shared/kirbyup.bcda4592.js';
3
3
 
4
4
  declare function build(options: BuildOptions): Promise<void>;
5
5
  declare function serve(options: ServeOptions): Promise<vite.ViteDevServer>;
@@ -10,13 +10,13 @@ import '@vitejs/plugin-vue2';
10
10
  import '@vitejs/plugin-vue2-jsx';
11
11
  import 'vite-plugin-full-reload';
12
12
  import 'rollup-plugin-external-globals';
13
- import 'postcss-load-config';
14
- import 'postcss-logical';
15
- import 'postcss-dir-pseudo-class';
16
- export { b as build, s as serve } from '../shared/kirbyup.90533c57.mjs';
13
+ export { b as build, s as serve } from '../shared/kirbyup.db20dc98.mjs';
17
14
  import 'node:zlib';
18
15
  import 'node:util';
19
16
  import 'node:buffer';
20
17
  import 'c12';
18
+ import 'postcss-load-config';
19
+ import 'postcss-logical';
20
+ import 'postcss-dir-pseudo-class';
21
21
  import 'magic-string';
22
22
  import 'node:module';
@@ -15,20 +15,27 @@ interface BuildOptions extends BaseOptions {
15
15
  }
16
16
  interface UserConfig {
17
17
  /**
18
- * Load from config files
19
- * Set to `false` to disable
20
- */
21
- configFile?: string | false;
22
- /**
23
- * Specifies an `Object`, or an `Array` of `Object`,
24
- * which defines aliases used to replace values in `import` statements.
18
+ * Specifies an object or an array of objects, which defines aliases
19
+ * used to replace values in `import` statements.
25
20
  * With either format, the order of the entries is important,
26
21
  * in that the first defined rules are applied first.
27
22
  */
28
23
  alias?: AliasOptions;
29
24
  /**
30
25
  * Extends Vite's configuration. Will be merged with kirbyup's
31
- * default configuration. Be careful what to extend.
26
+ * default configuration. For example, you can define global constant replacements.
27
+ *
28
+ * @example
29
+ * export default defineConfig({
30
+ * vite: {
31
+ * define: {
32
+ * __TEST__: JSON.stringify(process.env.TEST === 'true'),
33
+ * },
34
+ * })
35
+ */
36
+ vite?: InlineConfig;
37
+ /**
38
+ * @deprecated Use `vite` instead.
32
39
  */
33
40
  extendViteConfig?: InlineConfig;
34
41
  }
@@ -15,20 +15,27 @@ interface BuildOptions extends BaseOptions {
15
15
  }
16
16
  interface UserConfig {
17
17
  /**
18
- * Load from config files
19
- * Set to `false` to disable
20
- */
21
- configFile?: string | false;
22
- /**
23
- * Specifies an `Object`, or an `Array` of `Object`,
24
- * which defines aliases used to replace values in `import` statements.
18
+ * Specifies an object or an array of objects, which defines aliases
19
+ * used to replace values in `import` statements.
25
20
  * With either format, the order of the entries is important,
26
21
  * in that the first defined rules are applied first.
27
22
  */
28
23
  alias?: AliasOptions;
29
24
  /**
30
25
  * Extends Vite's configuration. Will be merged with kirbyup's
31
- * default configuration. Be careful what to extend.
26
+ * default configuration. For example, you can define global constant replacements.
27
+ *
28
+ * @example
29
+ * export default defineConfig({
30
+ * vite: {
31
+ * define: {
32
+ * __TEST__: JSON.stringify(process.env.TEST === 'true'),
33
+ * },
34
+ * })
35
+ */
36
+ vite?: InlineConfig;
37
+ /**
38
+ * @deprecated Use `vite` instead.
32
39
  */
33
40
  extendViteConfig?: InlineConfig;
34
41
  }
@@ -10,18 +10,18 @@ import vuePlugin from '@vitejs/plugin-vue2';
10
10
  import vueJsxPlugin from '@vitejs/plugin-vue2-jsx';
11
11
  import fullReloadPlugin from 'vite-plugin-full-reload';
12
12
  import externalGlobals from 'rollup-plugin-external-globals';
13
- import postcssrc from 'postcss-load-config';
14
- import postcssLogical from 'postcss-logical';
15
- import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
16
13
  import { gzip } from 'node:zlib';
17
14
  import { promisify } from 'node:util';
18
15
  import { Buffer } from 'node:buffer';
19
16
  import { loadConfig as loadConfig$1 } from 'c12';
17
+ import postcssrc from 'postcss-load-config';
18
+ import postcssLogical from 'postcss-logical';
19
+ import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
20
20
  import MagicString from 'magic-string';
21
21
  import 'node:module';
22
22
 
23
23
  const name = "kirbyup";
24
- const version = "3.1.1";
24
+ const version = "3.1.3";
25
25
 
26
26
  class PrettyError extends Error {
27
27
  constructor(message) {
@@ -70,6 +70,18 @@ function loadConfig(cwd = process.cwd()) {
70
70
  }
71
71
  });
72
72
  }
73
+ async function resolvePostCSSConfig(cwd) {
74
+ try {
75
+ const config = await postcssrc(void 0, void 0, { stopDir: cwd });
76
+ return config;
77
+ } catch (error) {
78
+ if (!error.message.includes("No PostCSS Config found"))
79
+ throw error;
80
+ return {
81
+ plugins: [postcssLogical(), postcssDirPseudoClass()]
82
+ };
83
+ }
84
+ }
73
85
 
74
86
  const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
75
87
  const singlelineCommentsRE = /\/\/.*/g;
@@ -137,10 +149,10 @@ function $_applyKirbyModifications(activeDef, newDef) {
137
149
  /** -- */
138
150
  `;
139
151
 
140
- function kirbyupAutoImportPlugin() {
152
+ function kirbyupGlobImportPlugin() {
141
153
  let config;
142
154
  return {
143
- name: "kirbyup:auto-import",
155
+ name: "kirbyup:glob-import",
144
156
  configResolved(resolvedConfig) {
145
157
  config = resolvedConfig;
146
158
  },
@@ -260,19 +272,19 @@ async function detectPackageManager(cwd, options = {}) {
260
272
  function kirbyupHmrPlugin(options) {
261
273
  let config;
262
274
  let entry;
263
- let indexMjs;
275
+ let devIndexPath;
264
276
  return {
265
277
  name: "kirbyup:hmr",
266
278
  apply: "serve",
267
279
  configResolved(resolvedConfig) {
268
280
  config = resolvedConfig;
269
281
  entry = resolve(config.root, options.entry);
270
- indexMjs = resolve(config.root, options.outDir || "", "index.dev.mjs");
282
+ devIndexPath = resolve(config.root, options.outDir || "", "index.dev.mjs");
271
283
  },
272
284
  transform(code, id) {
273
285
  if (isHmrRuntimeId(id)) {
274
286
  return code.replace(
275
- // https://github.com/vitejs/vite-plugin-vue2/blob/06ede94/src/utils/hmrRuntime.ts#L173
287
+ // https://github.com/vitejs/vite-plugin-vue2/blob/8de73ea6b8a1df4c14308da2885db195dacc2b14/src/utils/hmrRuntime.ts#L173
276
288
  /^.*=\s*record\.Ctor\.super\.extend\(options\)/m,
277
289
  "$_applyKirbyModifications(record.Ctor.options, options) // injected by kirbyup\n$&"
278
290
  ) + __INJECTED_HMR_CODE__;
@@ -288,12 +300,12 @@ function kirbyupHmrPlugin(options) {
288
300
  const baseUrl = `http://${hostname}:${port}${config.base}`;
289
301
  const entryUrl = new URL(entryPath, baseUrl).href;
290
302
  const pm = await detectPackageManager(config.root);
291
- await writeFile(indexMjs, getViteProxyModule(entryUrl, pm));
303
+ await writeFile(devIndexPath, getViteProxyModule(entryUrl, pm));
292
304
  });
293
305
  },
294
306
  closeBundle() {
295
- if (existsSync(indexMjs))
296
- unlinkSync(indexMjs);
307
+ if (existsSync(devIndexPath))
308
+ unlinkSync(devIndexPath);
297
309
  }
298
310
  };
299
311
  }
@@ -307,21 +319,22 @@ try {
307
319
  "[kirbyup] Couldn't connect to the development server. Run \`${pm} run serve\` to start Vite or build the plugin with \`${pm} run build\` so Kirby uses the production version."
308
320
  );
309
321
  throw err;
310
- }`.trim();
322
+ }
323
+ `.trimStart();
311
324
  }
312
325
 
313
326
  function kirbyupBuildCleanupPlugin(options) {
314
327
  let config;
315
- let indexMjs;
328
+ let devIndexPath;
316
329
  return {
317
330
  name: "kirbyup:build-cleanup",
318
331
  configResolved(resolvedConfig) {
319
332
  config = resolvedConfig;
320
- indexMjs = resolve(config.root, options.outDir, "index.dev.mjs");
333
+ devIndexPath = resolve(config.root, options.outDir, "index.dev.mjs");
321
334
  },
322
335
  writeBundle() {
323
- if (existsSync(indexMjs))
324
- unlinkSync(indexMjs);
336
+ if (existsSync(devIndexPath))
337
+ unlinkSync(devIndexPath);
325
338
  }
326
339
  };
327
340
  }
@@ -330,7 +343,8 @@ let resolvedKirbyupConfig;
330
343
  let resolvedPostCssConfig;
331
344
  function getViteConfig(command, options) {
332
345
  const aliasDir = resolve(options.cwd, dirname(options.entry));
333
- const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
346
+ const { alias = {}, vite, extendViteConfig } = resolvedKirbyupConfig;
347
+ const userConfig = vite ?? extendViteConfig ?? {};
334
348
  const baseConfig = {
335
349
  resolve: {
336
350
  alias: {
@@ -344,7 +358,7 @@ function getViteConfig(command, options) {
344
358
  // looks in the current directory and breaks `npx kirbyup`
345
359
  vuePlugin({ compiler: vueCompilerSfc }),
346
360
  vueJsxPlugin(),
347
- kirbyupAutoImportPlugin(),
361
+ kirbyupGlobImportPlugin(),
348
362
  { ...externalGlobals({ vue: "Vue" }), enforce: "post" }
349
363
  ],
350
364
  css: { postcss: resolvedPostCssConfig },
@@ -357,13 +371,13 @@ function getViteConfig(command, options) {
357
371
  plugins: [
358
372
  kirbyupHmrPlugin(options),
359
373
  watch && fullReloadPlugin(watch)
360
- ],
361
- // Input needs to be specified so dep pre-bundling works
374
+ ].filter(Boolean),
375
+ // Input needs to be specified so dependency pre-bundling works
362
376
  build: { rollupOptions: { input: resolve(options.cwd, options.entry) } },
363
377
  // Specify origin so asset URLs include Vite server host
364
378
  server: { port, strictPort: true, origin: `http://localhost:${port}` }
365
379
  });
366
- return mergeConfig(serveConfig, extendViteConfig);
380
+ return mergeConfig(serveConfig, userConfig);
367
381
  }
368
382
  const mode = options.watch ? "development" : "production";
369
383
  const buildConfig = mergeConfig(baseConfig, {
@@ -386,7 +400,7 @@ function getViteConfig(command, options) {
386
400
  }
387
401
  }
388
402
  });
389
- return mergeConfig(buildConfig, extendViteConfig);
403
+ return mergeConfig(buildConfig, userConfig);
390
404
  }
391
405
  async function generate(options) {
392
406
  const config = getViteConfig("build", options);
@@ -429,15 +443,7 @@ async function build(options) {
429
443
  const { cwd } = options;
430
444
  const { config, configFile } = await loadConfig(cwd);
431
445
  resolvedKirbyupConfig = config ?? {};
432
- try {
433
- resolvedPostCssConfig = await postcssrc(void 0, void 0, { stopDir: cwd });
434
- } catch (err) {
435
- if (!/No PostCSS Config found/.test(err.message))
436
- throw err;
437
- resolvedPostCssConfig = {
438
- plugins: [postcssLogical(), postcssDirPseudoClass()]
439
- };
440
- }
446
+ resolvedPostCssConfig = await resolvePostCSSConfig(cwd);
441
447
  {
442
448
  consola.log(colors.green(`${name} v${version}`));
443
449
  consola.start(`Building ${colors.cyan(options.entry)}`);
@@ -453,7 +459,7 @@ async function build(options) {
453
459
  const { watch } = await import('chokidar');
454
460
  const ignored = [
455
461
  "**/{.git,node_modules}/**",
456
- // Always ignore out files
462
+ // Always ignore dist files
457
463
  "index.{css,js}"
458
464
  ];
459
465
  const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter(
@@ -471,7 +477,8 @@ async function build(options) {
471
477
  if (configFile)
472
478
  watcher.add(configFile);
473
479
  watcher.on("all", async (type, file) => {
474
- if (configFile === file) {
480
+ const absolutePath = resolve(cwd, file);
481
+ if (configFile === absolutePath) {
475
482
  resolvedKirbyupConfig = (await loadConfig(cwd)).config ?? {};
476
483
  consola.info(
477
484
  `${colors.cyan(basename(file))} changed, setting new config`
@@ -491,15 +498,7 @@ async function serve(options) {
491
498
  const { cwd } = options;
492
499
  const { config } = await loadConfig(cwd);
493
500
  resolvedKirbyupConfig = config ?? {};
494
- try {
495
- resolvedPostCssConfig = await postcssrc(void 0, void 0, { stopDir: cwd });
496
- } catch (err) {
497
- if (!/No PostCSS Config found/.test(err.message))
498
- throw err;
499
- resolvedPostCssConfig = {
500
- plugins: [postcssLogical(), postcssDirPseudoClass()]
501
- };
502
- }
501
+ resolvedPostCssConfig = await resolvePostCSSConfig(cwd);
503
502
  {
504
503
  consola.log(colors.green(`${name} v${version}`));
505
504
  consola.info("Starting development server...");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kirbyup",
3
3
  "type": "module",
4
- "version": "3.1.1",
4
+ "version": "3.1.3",
5
5
  "packageManager": "pnpm@8.15.1",
6
6
  "description": "Zero-config bundler for Kirby Panel plugins",
7
7
  "author": {