kirbyup 3.3.0 → 3.4.0

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
@@ -46,7 +46,7 @@ Having installed kirbyup, you can add the following scripts as shortcuts to the
46
46
  "build": "kirbyup src/index.js"
47
47
  },
48
48
  "devDependencies": {
49
- "kirbyup": "^3.1.3"
49
+ "kirbyup": "^3.4.0"
50
50
  }
51
51
  }
52
52
  ```
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.BtejYnwg.mjs';
2
+ import { n as name, b as build, s as serve, v as version, h as handleError } from '../shared/kirbyup.Bxmi3UeO.mjs';
3
3
  import 'node:fs';
4
4
  import 'node:fs/promises';
5
5
  import '@vitejs/plugin-vue2';
@@ -15,12 +15,7 @@ import 'vue/compiler-sfc';
15
15
  import 'c12';
16
16
  import 'postcss-load-config';
17
17
  import 'magic-string';
18
- import 'node:module';
19
- import 'child_process';
20
- import 'path';
21
- import 'process';
22
- import 'stream';
23
- import 'readline';
18
+ import 'nypm';
24
19
  import 'node:buffer';
25
20
  import 'node:util';
26
21
  import 'node:zlib';
@@ -10,16 +10,11 @@ import 'rollup-plugin-external-globals';
10
10
  import 'vite';
11
11
  import 'vite-plugin-full-reload';
12
12
  import 'vue/compiler-sfc';
13
- export { b as build, s as serve } from '../shared/kirbyup.BtejYnwg.mjs';
13
+ export { b as build, s as serve } from '../shared/kirbyup.Bxmi3UeO.mjs';
14
14
  import 'c12';
15
15
  import 'postcss-load-config';
16
16
  import 'magic-string';
17
- import 'node:module';
18
- import 'child_process';
19
- import 'path';
20
- import 'process';
21
- import 'stream';
22
- import 'readline';
17
+ import 'nypm';
23
18
  import 'node:buffer';
24
19
  import 'node:util';
25
20
  import 'node:zlib';
@@ -0,0 +1,449 @@
1
+ import * as fs from 'node:fs';
2
+ import * as fsp from 'node:fs/promises';
3
+ import vuePlugin from '@vitejs/plugin-vue2';
4
+ import vueJsxPlugin from '@vitejs/plugin-vue2-jsx';
5
+ import { consola } from 'consola';
6
+ import { colors } from 'consola/utils';
7
+ import { resolve, normalize, relative, dirname, basename } from 'pathe';
8
+ import { debounce } from 'perfect-debounce';
9
+ import externalGlobals from 'rollup-plugin-external-globals';
10
+ import { createLogger, createServer, build as build$1, mergeConfig } from 'vite';
11
+ import fullReloadPlugin from 'vite-plugin-full-reload';
12
+ import * as vueCompilerSfc from 'vue/compiler-sfc';
13
+ import { loadConfig as loadConfig$1 } from 'c12';
14
+ import postcssrc from 'postcss-load-config';
15
+ import MagicString from 'magic-string';
16
+ import { detectPackageManager } from 'nypm';
17
+ import { Buffer } from 'node:buffer';
18
+ import { promisify } from 'node:util';
19
+ import { gzip } from 'node:zlib';
20
+
21
+ const name = "kirbyup";
22
+ const version = "3.4.0";
23
+
24
+ function loadConfig(cwd = process.cwd()) {
25
+ return loadConfig$1({
26
+ cwd,
27
+ name: "kirbyup",
28
+ rcFile: false,
29
+ packageJson: false
30
+ });
31
+ }
32
+ async function resolvePostCSSConfig(cwd) {
33
+ try {
34
+ return await postcssrc(void 0, void 0, { stopDir: cwd });
35
+ } catch (error) {
36
+ if (!error.message.includes("No PostCSS Config found"))
37
+ throw error;
38
+ }
39
+ }
40
+
41
+ class PrettyError extends Error {
42
+ constructor(message) {
43
+ super(message);
44
+ this.name = this.constructor.name;
45
+ if (typeof Error.captureStackTrace === "function")
46
+ Error.captureStackTrace(this, this.constructor);
47
+ else
48
+ this.stack = new Error(message).stack;
49
+ }
50
+ }
51
+ function handleError(error) {
52
+ consola.error(error.message);
53
+ process.exitCode = 1;
54
+ }
55
+
56
+ function kirbyupBuildCleanupPlugin(options) {
57
+ let config;
58
+ let devIndexPath;
59
+ return {
60
+ name: "kirbyup:build-cleanup",
61
+ configResolved(resolvedConfig) {
62
+ config = resolvedConfig;
63
+ devIndexPath = resolve(config.root, options.outDir, "index.dev.mjs");
64
+ },
65
+ writeBundle() {
66
+ if (fs.existsSync(devIndexPath))
67
+ fs.unlinkSync(devIndexPath);
68
+ }
69
+ };
70
+ }
71
+
72
+ const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//g;
73
+ const singlelineCommentsRE = /\/\/.*/g;
74
+ const HMR_RUNTIME_ID = "\0plugin-vue2:hmr-runtime";
75
+ const JSX_HMR_RUNTIME_ID = "plugin-vue2-jsx:hmr-runtime";
76
+ function isHmrRuntimeId(id) {
77
+ return id === HMR_RUNTIME_ID || id === JSX_HMR_RUNTIME_ID;
78
+ }
79
+ const __INJECTED_HMR_CODE__ = `
80
+ /** - injected by kirbyup - */
81
+ for (const methodName of ['rerender', 'reload']) {
82
+ const original = __VUE_HMR_RUNTIME__[methodName]
83
+
84
+ __VUE_HMR_RUNTIME__[methodName] = function (id, updatedDef) {
85
+ const key = updatedDef?.__file ? '__file' : updatedDef?.__hmrId ? '__hmrId' : null
86
+
87
+ if (key) {
88
+ const pluginComponents = window.panel.plugins.components
89
+ // const usedComponentDefs = window.panel.app.$options.components
90
+ const usedComponentDefs = window.panel.app._vnode.componentInstance.$options.components // #33
91
+
92
+ for (const componentName in pluginComponents) {
93
+ if (updatedDef[key] === pluginComponents[componentName][key]) {
94
+ const usedDefinition = usedComponentDefs[componentName].options
95
+
96
+ if (map[id].options !== usedDefinition)
97
+ map[id].options = usedDefinition
98
+
99
+ if (typeof map[id].options.$_isSection !== 'boolean')
100
+ map[id].options.$_isSection = /^k-.*-section$/.test(componentName)
101
+
102
+ break
103
+ }
104
+ }
105
+ }
106
+
107
+ return original.apply(this, arguments)
108
+ }
109
+ }
110
+
111
+ function $_applyKirbyModifications(activeDef, newDef) {
112
+ const usedComponentDefs = window.panel.app.$options.components
113
+
114
+ if (newDef.template)
115
+ newDef.render = null
116
+
117
+ if (activeDef.$_isSection)
118
+ newDef.$_isSection = true
119
+ if (newDef.$_isSection && !newDef.mixins?.[0]?.methods?.load)
120
+ newDef.mixins = [activeDef.mixins[0], ...(newDef.mixins || [])]
121
+
122
+ if (typeof newDef.extends === 'string') {
123
+ if (newDef.extends === activeDef.extends?.options?.name) {
124
+ newDef.extends = activeDef.extends
125
+ }
126
+ else if (usedComponentDefs[newDef.extends]) {
127
+ newDef.extends = usedComponentDefs[newDef.extends].extend({
128
+ options: newDef,
129
+ components: { ...usedComponentDefs, ...(newDef.components || {}) },
130
+ })
131
+ }
132
+ else { newDef.extends = null }
133
+ }
134
+ }
135
+ /** -- */
136
+ `;
137
+
138
+ function kirbyupGlobImportPlugin() {
139
+ let config;
140
+ return {
141
+ name: "kirbyup:glob-import",
142
+ configResolved(resolvedConfig) {
143
+ config = resolvedConfig;
144
+ },
145
+ async transform(code) {
146
+ if (!code.includes("kirbyup.import"))
147
+ return;
148
+ const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
149
+ const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
150
+ let s;
151
+ let match;
152
+ while (match = kirbyupImportRE.exec(noCommentsCode)) {
153
+ const { 0: exp, 1: rawPath, index } = match;
154
+ if (!s)
155
+ s = new MagicString(code);
156
+ s.overwrite(
157
+ index,
158
+ index + exp.length,
159
+ `kirbyup.import(import.meta.glob(${rawPath}, { eager: true }))`
160
+ );
161
+ }
162
+ if (s) {
163
+ return {
164
+ code: s.toString(),
165
+ map: config.build.sourcemap ? s.generateMap({ hires: true }) : void 0
166
+ };
167
+ }
168
+ }
169
+ };
170
+ }
171
+
172
+ function kirbyupHmrPlugin(options) {
173
+ let config;
174
+ let entry;
175
+ let devIndexPath;
176
+ return {
177
+ name: "kirbyup:hmr",
178
+ apply: "serve",
179
+ configResolved(resolvedConfig) {
180
+ config = resolvedConfig;
181
+ entry = resolve(config.root, options.entry);
182
+ devIndexPath = resolve(config.root, options.outDir || "", "index.dev.mjs");
183
+ },
184
+ transform(code, id) {
185
+ if (isHmrRuntimeId(id)) {
186
+ return code.replace(
187
+ // https://github.com/vitejs/vite-plugin-vue2/blob/8de73ea6b8a1df4c14308da2885db195dacc2b14/src/utils/hmrRuntime.ts#L173
188
+ /^.*=\s*record\.Ctor\.super\.extend\(options\)/m,
189
+ "$_applyKirbyModifications(record.Ctor.options, options) // injected by kirbyup\n$&"
190
+ ) + __INJECTED_HMR_CODE__;
191
+ }
192
+ },
193
+ configureServer(server) {
194
+ if (!server.httpServer)
195
+ return;
196
+ server.httpServer.once("listening", async () => {
197
+ const entryPath = entry.replace(`${config.root}/`, "");
198
+ const { address, family, port } = server.httpServer.address();
199
+ const hostname = family === "IPv6" ? `[${address}]` : address;
200
+ const baseUrl = `http://${hostname}:${port}${config.base}`;
201
+ const entryUrl = new URL(entryPath, baseUrl).href;
202
+ const pm = await detectPackageManager(config.root);
203
+ await fsp.writeFile(devIndexPath, getViteProxyModule(entryUrl, pm));
204
+ });
205
+ },
206
+ closeBundle() {
207
+ if (fs.existsSync(devIndexPath))
208
+ fs.unlinkSync(devIndexPath);
209
+ }
210
+ };
211
+ }
212
+ function getViteProxyModule(entryUrl, packageManager) {
213
+ const pm = packageManager?.name || "npm";
214
+ return `
215
+ try {
216
+ await import("${entryUrl}");
217
+ } catch (err) {
218
+ console.error(
219
+ "[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."
220
+ );
221
+ throw err;
222
+ }
223
+ `.trimStart();
224
+ }
225
+
226
+ function toArray(array) {
227
+ array ??= [];
228
+ return Array.isArray(array) ? array : [array];
229
+ }
230
+ const compress = promisify(gzip);
231
+ async function getCompressedSize(code) {
232
+ const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
233
+ return ` / gzip: ${size.toFixed(2)} KiB`;
234
+ }
235
+ async function printFileInfo({
236
+ root,
237
+ outDir,
238
+ filePath,
239
+ content,
240
+ type,
241
+ maxLength
242
+ }) {
243
+ const prettyOutDir = `${normalize(relative(root, resolve(root, outDir)))}/`;
244
+ const kibs = content.length / 1024;
245
+ const compressedSize = await getCompressedSize(content);
246
+ const writeColor = type === "chunk" ? colors.cyan : colors.magenta;
247
+ consola.log(
248
+ colors.white(colors.dim(prettyOutDir)) + writeColor(filePath.padEnd(maxLength + 2)) + colors.dim(`${kibs.toFixed(2)} kB${compressedSize}`)
249
+ );
250
+ }
251
+
252
+ let resolvedKirbyupConfig;
253
+ let resolvedPostCssConfig;
254
+ const logLevel = "warn";
255
+ const logger = createLogger(logLevel);
256
+ const loggerWarn = logger.warn;
257
+ logger.warn = (msg, options) => {
258
+ if (msg.includes("(!) build.outDir"))
259
+ return;
260
+ loggerWarn(msg, options);
261
+ };
262
+ function getViteConfig(command, options) {
263
+ const aliasDir = resolve(options.cwd, dirname(options.entry));
264
+ const { alias = {}, vite, extendViteConfig } = resolvedKirbyupConfig;
265
+ const userConfig = vite ?? extendViteConfig ?? {};
266
+ const sharedConfig = {
267
+ resolve: {
268
+ alias: {
269
+ "~/": `${aliasDir}/`,
270
+ "@/": `${aliasDir}/`,
271
+ ...alias
272
+ }
273
+ },
274
+ plugins: [
275
+ // Explicitly pass the compiler, since the plugin's resolving of the compiler
276
+ // looks in the current directory and breaks `npx kirbyup`
277
+ vuePlugin({ compiler: vueCompilerSfc }),
278
+ vueJsxPlugin(),
279
+ kirbyupGlobImportPlugin(),
280
+ { ...externalGlobals({ vue: "Vue" }), enforce: "post" }
281
+ ],
282
+ build: {
283
+ copyPublicDir: false
284
+ },
285
+ ...resolvedPostCssConfig && {
286
+ css: {
287
+ postcss: resolvedPostCssConfig
288
+ }
289
+ },
290
+ envDir: options.cwd,
291
+ envPrefix: ["VITE_", "KIRBYUP_"],
292
+ customLogger: logger,
293
+ logLevel
294
+ };
295
+ if (command === "serve") {
296
+ const { port, watch } = options;
297
+ const serveConfig = mergeConfig(sharedConfig, {
298
+ plugins: [
299
+ kirbyupHmrPlugin(options),
300
+ watch && fullReloadPlugin(watch)
301
+ ].filter(Boolean),
302
+ // Input needs to be specified so dependency pre-bundling works
303
+ build: {
304
+ rollupOptions: {
305
+ input: resolve(options.cwd, options.entry)
306
+ }
307
+ },
308
+ // Specify origin so asset URLs include Vite server host
309
+ server: {
310
+ port,
311
+ strictPort: true,
312
+ origin: `http://localhost:${port}`
313
+ }
314
+ });
315
+ return mergeConfig(serveConfig, userConfig);
316
+ }
317
+ const mode = options.watch ? "development" : "production";
318
+ const buildConfig = mergeConfig(sharedConfig, {
319
+ mode,
320
+ plugins: [kirbyupBuildCleanupPlugin(options)],
321
+ build: {
322
+ lib: {
323
+ entry: resolve(options.cwd, options.entry),
324
+ formats: ["iife"],
325
+ name: "kirbyupExport",
326
+ fileName: () => "index.js"
327
+ },
328
+ minify: mode === "production",
329
+ outDir: options.outDir,
330
+ emptyOutDir: false,
331
+ rollupOptions: {
332
+ output: {
333
+ assetFileNames: "index.[ext]"
334
+ }
335
+ }
336
+ }
337
+ });
338
+ return mergeConfig(buildConfig, userConfig);
339
+ }
340
+ async function generate(options) {
341
+ const config = getViteConfig("build", options);
342
+ let result;
343
+ try {
344
+ result = await build$1(config);
345
+ } catch (error) {
346
+ consola.error("Build failed");
347
+ if (config.mode === "production")
348
+ throw error;
349
+ }
350
+ if (result && !options.watch) {
351
+ const { output } = toArray(result)[0];
352
+ let maxLength = 0;
353
+ for (const chunkFile in output) {
354
+ const fileNameLength = output[chunkFile].fileName.length;
355
+ if (fileNameLength > maxLength)
356
+ maxLength = fileNameLength;
357
+ }
358
+ for (const { fileName, type, code } of output) {
359
+ const content = code || await fsp.readFile(resolve(options.outDir, fileName), "utf8");
360
+ await printFileInfo(
361
+ {
362
+ root: options.cwd,
363
+ outDir: options.outDir,
364
+ filePath: fileName,
365
+ content,
366
+ type,
367
+ maxLength
368
+ }
369
+ );
370
+ }
371
+ }
372
+ return result;
373
+ }
374
+ async function build(options) {
375
+ assertEntryExists(options);
376
+ const { cwd } = options;
377
+ const { config, configFile } = await loadConfig(cwd);
378
+ resolvedKirbyupConfig = config ?? {};
379
+ resolvedPostCssConfig = await resolvePostCSSConfig(cwd);
380
+ {
381
+ consola.log(colors.green(`${name} v${version}`));
382
+ consola.start(`Building ${colors.cyan(options.entry)}`);
383
+ }
384
+ if (options.watch)
385
+ consola.info("Running in watch mode");
386
+ const debouncedBuild = debounce(async () => {
387
+ generate(options).catch(handleError);
388
+ }, 100);
389
+ const startWatcher = async () => {
390
+ if (!options.watch)
391
+ return;
392
+ const { watch } = await import('chokidar');
393
+ const ignored = [
394
+ "**/{.git,node_modules}/**",
395
+ // Always ignore dist files
396
+ "index.{css,js}"
397
+ ];
398
+ const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter(
399
+ (path) => typeof path === "string"
400
+ ) : options.watch;
401
+ consola.info(
402
+ `Watching for changes in ${toArray(watchPaths).map((i) => colors.cyan(i)).join(", ")}`
403
+ );
404
+ const watcher = watch(watchPaths, {
405
+ ignoreInitial: true,
406
+ ignorePermissionErrors: true,
407
+ ignored,
408
+ cwd
409
+ });
410
+ if (configFile)
411
+ watcher.add(configFile);
412
+ watcher.on("all", async (type, file) => {
413
+ const absolutePath = resolve(cwd, file);
414
+ if (configFile === absolutePath) {
415
+ resolvedKirbyupConfig = (await loadConfig(cwd)).config ?? {};
416
+ consola.info(
417
+ `${colors.cyan(basename(file))} changed, setting new config`
418
+ );
419
+ } else {
420
+ consola.log(`${colors.green(type)} ${colors.white(colors.dim(file))}`);
421
+ }
422
+ debouncedBuild();
423
+ });
424
+ };
425
+ await generate(options);
426
+ consola.success("Build successful");
427
+ startWatcher();
428
+ }
429
+ async function serve(options) {
430
+ assertEntryExists(options);
431
+ const { cwd } = options;
432
+ const { config } = await loadConfig(cwd);
433
+ resolvedKirbyupConfig = config ?? {};
434
+ resolvedPostCssConfig = await resolvePostCSSConfig(cwd);
435
+ {
436
+ consola.log(colors.green(`${name} v${version}`));
437
+ consola.info("Starting development server...");
438
+ }
439
+ const server = await createServer(getViteConfig("serve", options));
440
+ await server.listen();
441
+ consola.success(`Server is listening on :${server.config.server.port}`);
442
+ return server;
443
+ }
444
+ function assertEntryExists(options) {
445
+ if (!fs.existsSync(resolve(options.cwd, options.entry)))
446
+ throw new PrettyError(`Cannot find "${options.entry}"`);
447
+ }
448
+
449
+ export { build as b, handleError as h, name as n, serve as s, version as v };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "kirbyup",
3
3
  "type": "module",
4
- "version": "3.3.0",
5
- "packageManager": "pnpm@10.7.1",
4
+ "version": "3.4.0",
5
+ "packageManager": "pnpm@10.15.1",
6
6
  "description": "Zero-config bundler for Kirby Panel plugins",
7
7
  "author": {
8
8
  "name": "Johann Schopplich",
@@ -75,32 +75,32 @@
75
75
  "@vitejs/plugin-vue2": "2.2.0",
76
76
  "@vitejs/plugin-vue2-jsx": "1.1.0",
77
77
  "@vue/compiler-sfc": "^2.7.16",
78
- "c12": "^3.0.3",
78
+ "c12": "^3.2.0",
79
79
  "cac": "^6.7.14",
80
- "chokidar": "~3.6.0",
80
+ "chokidar": "^4.0.3",
81
81
  "consola": "^3.4.2",
82
- "magic-string": "^0.30.17",
82
+ "magic-string": "^0.30.19",
83
+ "nypm": "^0.6.1",
83
84
  "pathe": "^2.0.3",
84
- "perfect-debounce": "^1.0.0",
85
- "postcss": "^8.5.3",
85
+ "perfect-debounce": "^2.0.0",
86
+ "postcss": "^8.5.6",
86
87
  "postcss-load-config": "^6.0.1",
87
88
  "rollup-plugin-external-globals": "^0.13.0",
88
- "sass": "^1.86.3",
89
- "vite": "~5.4.17",
89
+ "sass": "^1.92.1",
90
+ "vite": "~6.3.6",
90
91
  "vite-plugin-full-reload": "^1.2.0",
91
92
  "vue": "^2.7.16"
92
93
  },
93
94
  "devDependencies": {
94
- "@antfu/eslint-config": "^4.11.0",
95
- "@types/node": "^22.14.0",
95
+ "@antfu/eslint-config": "^5.3.0",
96
+ "@types/node": "^24.3.1",
96
97
  "@types/prompts": "^2.4.9",
97
- "bumpp": "^10.1.0",
98
- "eslint": "^9.24.0",
98
+ "bumpp": "^10.2.3",
99
+ "eslint": "^9.35.0",
99
100
  "fast-glob": "^3.3.3",
100
- "nypm": "^0.6.0",
101
- "typescript": "^5.8.3",
102
- "unbuild": "^3.5.0",
103
- "vitest": "^3.1.1"
101
+ "typescript": "^5.9.2",
102
+ "unbuild": "^3.6.1",
103
+ "vitest": "^3.2.4"
104
104
  },
105
105
  "pnpm": {
106
106
  "onlyBuiltDependencies": [