kirbyup 2.1.3 → 2.2.0-beta.1

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
@@ -17,7 +17,7 @@ The fastest and leanest way to bundle your Kirby Panel plugins. No configuration
17
17
 
18
18
  ## Requirements
19
19
 
20
- - Node 16 (active LTS) or newer
20
+ - Node 16 or newer
21
21
 
22
22
  ## Get Started Right Away
23
23
 
@@ -43,7 +43,7 @@ If you want to use kirbyup right away, there is no need to install it. Simply ca
43
43
 
44
44
  > If `npx` doesn't use the latest kirbyup version, although it is available, run `npx -y kirbyup@latest` instead or delete the `~/.npm/_npx` cache folder.
45
45
 
46
- While kirbyup will stay backwards compatible, exact build reproducibility may be of importance to you. If so, I recommend to target a specific package version, rather than using `npx`. Install kirbyup with a package manager of your choice locally to your project:
46
+ While kirbyup will stay backwards compatible, exact build reproducibility may be of importance to you. If so, I recommend targeting a specific package version, rather than using `npx`. Install kirbyup with a package manager of your choice locally to your project:
47
47
 
48
48
  ```bash
49
49
  npm i kirbyup --save-dev
@@ -184,7 +184,7 @@ Only `KIRBYUP_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to yo
184
184
  Create a `kirbyup.config.js` or `kirbyup.config.ts` configuration file the root-level of your project to customize kirbyup.
185
185
 
186
186
  ```js
187
- import { resolve } from 'path'
187
+ import { resolve } from 'node:path'
188
188
  import { defineConfig } from 'kirbyup/config'
189
189
 
190
190
  export default defineConfig({
package/dist/cli.d.ts CHANGED
@@ -1 +1,2 @@
1
1
 
2
+ export { }
package/dist/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.7be0137b.mjs';
2
+ import { n as name, b as build, s as serve, v as version, h as handleError } from './shared/kirbyup.6fa783f0.mjs';
3
3
  import 'node:fs';
4
4
  import 'node:fs/promises';
5
5
  import 'pathe';
@@ -14,9 +14,9 @@ import 'vite-plugin-full-reload';
14
14
  import 'postcss-load-config';
15
15
  import 'postcss-logical';
16
16
  import 'postcss-dir-pseudo-class';
17
- import 'zlib';
18
- import 'util';
19
- import 'fs';
17
+ import 'node:zlib';
18
+ import 'node:util';
19
+ import 'node:buffer';
20
20
  import 'unconfig';
21
21
  import 'magic-string';
22
22
  import 'detect-package-manager';
@@ -28,9 +28,13 @@ async function startCli(cwd = process.cwd(), argv = process.argv) {
28
28
  "Watch for file changes. If no path is specified, the folder of the input file will be watched",
29
29
  { default: false }
30
30
  ).example("kirbyup src/index.js").example("kirbyup src/index.js --out-dir ~/kirby-site/site/plugins/demo").example("kirbyup src/index.js --watch src/**/*.{js,css} --watch assets/*\n").action(async (file, options) => {
31
+ if (!process.env.NODE_ENV)
32
+ process.env.NODE_ENV = options.watch ? "development" : "production";
31
33
  await build({ cwd, entry: file, ...options });
32
34
  });
33
35
  cli.command("serve <file>", "Start development server with live reload").option("--no-watch", "Don't watch .php files for changes", { default: "\0" }).option("-w, --watch <path>", "Watch additional files", { default: "./**/*.php" }).option("-p, --port <number>", "Port for the development server", { default: 5177 }).option("-d, --out-dir <dir>", "Output directory").example("kirbyup serve src/index.js").example("kirbyup serve src/index.js --no-watch --port 3003").example("kirbyup serve src/index.js --watch snippets/*.php --watch templates/*.php\n").action(async (file, options) => {
36
+ if (!process.env.NODE_ENV)
37
+ process.env.NODE_ENV = "development";
34
38
  const server = await serve({ cwd, entry: file, ...options });
35
39
  const exitProcess = async () => {
36
40
  try {
package/dist/index.mjs CHANGED
@@ -12,10 +12,10 @@ import 'vite-plugin-full-reload';
12
12
  import 'postcss-load-config';
13
13
  import 'postcss-logical';
14
14
  import 'postcss-dir-pseudo-class';
15
- export { b as build, s as serve } from './shared/kirbyup.7be0137b.mjs';
16
- import 'zlib';
17
- import 'util';
18
- import 'fs';
15
+ export { b as build, s as serve } from './shared/kirbyup.6fa783f0.mjs';
16
+ import 'node:zlib';
17
+ import 'node:util';
18
+ import 'node:buffer';
19
19
  import 'unconfig';
20
20
  import 'magic-string';
21
21
  import 'detect-package-manager';
package/dist/plugin.mjs CHANGED
@@ -1,5 +1,11 @@
1
- const getComponentName = (path) => path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).toLowerCase();
2
1
  const kirbyup = Object.freeze({
2
+ /**
3
+ * Auto-import Kirby Panel components, will be transformed by
4
+ * kirbyup's auto import plugin for Vite
5
+ *
6
+ * @example
7
+ * kirbyup.import('./components/blocks/*.vue')
8
+ */
3
9
  import(glob) {
4
10
  const modules = glob;
5
11
  return Object.entries(modules).reduce(
@@ -11,5 +17,8 @@ const kirbyup = Object.freeze({
11
17
  );
12
18
  }
13
19
  });
20
+ function getComponentName(path) {
21
+ return path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).toLowerCase();
22
+ }
14
23
 
15
24
  export { kirbyup };
@@ -1,4 +1,4 @@
1
- import { existsSync as existsSync$1, unlinkSync } from 'node:fs';
1
+ import { existsSync, statSync, unlinkSync } from 'node:fs';
2
2
  import { writeFile, readFile } from 'node:fs/promises';
3
3
  import { normalize, relative, resolve, dirname, basename } from 'pathe';
4
4
  import consola from 'consola';
@@ -12,15 +12,15 @@ import fullReloadPlugin from 'vite-plugin-full-reload';
12
12
  import postcssrc from 'postcss-load-config';
13
13
  import postcssLogical from 'postcss-logical';
14
14
  import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
15
- import { gzip } from 'zlib';
16
- import { promisify } from 'util';
17
- import { existsSync, statSync } from 'fs';
15
+ import { gzip } from 'node:zlib';
16
+ import { promisify } from 'node:util';
17
+ import { Buffer } from 'node:buffer';
18
18
  import { createConfigLoader } from 'unconfig';
19
19
  import MagicString from 'magic-string';
20
20
  import { detect } from 'detect-package-manager';
21
21
 
22
22
  const name = "kirbyup";
23
- const version = "2.1.3";
23
+ const version = "2.2.0-beta.1";
24
24
 
25
25
  class PrettyError extends Error {
26
26
  constructor(message) {
@@ -101,7 +101,9 @@ const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
101
101
  const singlelineCommentsRE = /\/\/.*/g;
102
102
  const HMR_RUNTIME_ID = "\0plugin-vue2:hmr-runtime";
103
103
  const JSX_HMR_RUNTIME_ID = "plugin-vue2-jsx:hmr-runtime";
104
- const isHmrRuntimeId = (id) => id === HMR_RUNTIME_ID || id === JSX_HMR_RUNTIME_ID;
104
+ function isHmrRuntimeId(id) {
105
+ return id === HMR_RUNTIME_ID || id === JSX_HMR_RUNTIME_ID;
106
+ }
105
107
  const __INJECTED_HMR_CODE__ = `
106
108
  /** - injected by kirbyup - */
107
109
  for (const methodName of ['rerender', 'reload']) {
@@ -120,7 +122,7 @@ for (const methodName of ['rerender', 'reload']) {
120
122
 
121
123
  if (map[id].options !== usedDefinition)
122
124
  map[id].options = usedDefinition
123
-
125
+
124
126
  if (typeof map[id].options.$_isSection !== 'boolean')
125
127
  map[id].options.$_isSection = /^k-.*-section$/.test(componentName)
126
128
 
@@ -168,42 +170,32 @@ function kirbyupAutoImportPlugin() {
168
170
  config = resolvedConfig;
169
171
  },
170
172
  async transform(code) {
171
- if (code.includes("kirbyup.import")) {
172
- const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
173
- const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
174
- let s = null;
175
- let match;
176
- while (match = kirbyupImportRE.exec(noCommentsCode)) {
177
- const { 0: exp, 1: rawPath, index } = match;
178
- if (!s)
179
- s = new MagicString(code);
180
- s.overwrite(
181
- index,
182
- index + exp.length,
183
- `kirbyup.import(import.meta.glob(${rawPath}, { eager: true }))`
184
- );
185
- }
186
- if (s) {
187
- return {
188
- code: s.toString(),
189
- map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
190
- };
191
- }
173
+ if (!code.includes("kirbyup.import"))
174
+ return;
175
+ const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
176
+ const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
177
+ let s;
178
+ let match;
179
+ while (match = kirbyupImportRE.exec(noCommentsCode)) {
180
+ const { 0: exp, 1: rawPath, index } = match;
181
+ if (!s)
182
+ s = new MagicString(code);
183
+ s.overwrite(
184
+ index,
185
+ index + exp.length,
186
+ `kirbyup.import(import.meta.glob(${rawPath}, { eager: true }))`
187
+ );
188
+ }
189
+ if (s) {
190
+ return {
191
+ code: s.toString(),
192
+ map: config.build.sourcemap ? s.generateMap({ hires: true }) : void 0
193
+ };
192
194
  }
193
- return null;
194
195
  }
195
196
  };
196
197
  }
197
198
 
198
- const getViteProxyModule = (entryUrl, pm) => `
199
- try {
200
- await import("${entryUrl}");
201
- } catch (err) {
202
- console.error(
203
- "[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."
204
- );
205
- throw err;
206
- }`.trim();
207
199
  function kirbyupHmrPlugin(options) {
208
200
  let config;
209
201
  let entry;
@@ -219,6 +211,7 @@ function kirbyupHmrPlugin(options) {
219
211
  transform(code, id) {
220
212
  if (isHmrRuntimeId(id)) {
221
213
  return code.replace(
214
+ // https://github.com/vitejs/vite-plugin-vue2/blob/06ede94/src/utils/hmrRuntime.ts#L173
222
215
  /^.*=\s*record\.Ctor\.super\.extend\(options\)/m,
223
216
  "$_applyKirbyModifications(record.Ctor.options, options) // injected by kirbyup\n$&"
224
217
  ) + __INJECTED_HMR_CODE__;
@@ -238,11 +231,22 @@ function kirbyupHmrPlugin(options) {
238
231
  });
239
232
  },
240
233
  closeBundle() {
241
- if (existsSync$1(indexMjs))
234
+ if (existsSync(indexMjs))
242
235
  unlinkSync(indexMjs);
243
236
  }
244
237
  };
245
238
  }
239
+ function getViteProxyModule(entryUrl, pm) {
240
+ return `
241
+ try {
242
+ await import("${entryUrl}");
243
+ } catch (err) {
244
+ console.error(
245
+ "[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."
246
+ );
247
+ throw err;
248
+ }`.trim();
249
+ }
246
250
 
247
251
  function kirbyupBuildCleanupPlugin(options) {
248
252
  let config;
@@ -254,7 +258,7 @@ function kirbyupBuildCleanupPlugin(options) {
254
258
  indexMjs = resolve(config.root, options.outDir, "index.dev.mjs");
255
259
  },
256
260
  writeBundle() {
257
- if (existsSync$1(indexMjs))
261
+ if (existsSync(indexMjs))
258
262
  unlinkSync(indexMjs);
259
263
  }
260
264
  };
@@ -267,9 +271,15 @@ function getViteConfig(command, options) {
267
271
  const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
268
272
  const baseConfig = {
269
273
  resolve: {
270
- alias: { "~/": `${aliasDir}/`, "@/": `${aliasDir}/`, ...alias }
274
+ alias: {
275
+ "~/": `${aliasDir}/`,
276
+ "@/": `${aliasDir}/`,
277
+ ...alias
278
+ }
271
279
  },
272
280
  plugins: [
281
+ // Explicitly pass the compiler, since the plugin's resolving of the compiler
282
+ // looks in the current directory and breaks `npx kirbyup`
273
283
  vuePlugin({ compiler: vueCompilerSfc }),
274
284
  vueJsxPlugin(),
275
285
  kirbyupAutoImportPlugin()
@@ -285,7 +295,9 @@ function getViteConfig(command, options) {
285
295
  kirbyupHmrPlugin(options),
286
296
  watch && fullReloadPlugin(watch)
287
297
  ],
298
+ // Input needs to be specified so dep pre-bundling works
288
299
  build: { rollupOptions: { input: resolve(options.cwd, options.entry) } },
300
+ // Specify origin so asset URLs include Vite server host
289
301
  server: { port, strictPort: true, origin: `http://localhost:${port}` }
290
302
  });
291
303
  return mergeConfig(serveConfig, extendViteConfig);
@@ -336,6 +348,7 @@ async function generate(options) {
336
348
  for (const {
337
349
  fileName,
338
350
  type,
351
+ // @ts-expect-error: `code` not available in `OutputAsset`
339
352
  code
340
353
  } of output) {
341
354
  await printFileInfo(
@@ -361,6 +374,7 @@ async function build(options) {
361
374
  if (!/No PostCSS Config found/.test(err.message))
362
375
  throw err;
363
376
  resolvedPostCssConfig = {
377
+ // @ts-expect-error: types won't match
364
378
  plugins: [postcssLogical(), postcssDirPseudoClass()]
365
379
  };
366
380
  }
@@ -379,6 +393,7 @@ async function build(options) {
379
393
  const { watch } = await import('chokidar');
380
394
  const ignored = [
381
395
  "**/{.git,node_modules}/**",
396
+ // Always ignore out files
382
397
  "index.{css,js}"
383
398
  ];
384
399
  const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter(
@@ -422,6 +437,7 @@ async function serve(options) {
422
437
  if (!/No PostCSS Config found/.test(err.message))
423
438
  throw err;
424
439
  resolvedPostCssConfig = {
440
+ // @ts-expect-error: types won't match
425
441
  plugins: [postcssLogical(), postcssDirPseudoClass()]
426
442
  };
427
443
  }
@@ -435,7 +451,7 @@ async function serve(options) {
435
451
  return server;
436
452
  }
437
453
  function ensureEntry(options) {
438
- if (!existsSync$1(resolve(options.cwd, options.entry)))
454
+ if (!existsSync(resolve(options.cwd, options.entry)))
439
455
  throw new PrettyError(`Cannot find "${options.entry}"`);
440
456
  }
441
457
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kirbyup",
3
- "version": "2.1.3",
4
- "packageManager": "pnpm@7.24.3",
3
+ "version": "2.2.0-beta.1",
4
+ "packageManager": "pnpm@8.1.1",
5
5
  "description": "Zero-config bundler for Kirby Panel plugins",
6
6
  "author": {
7
7
  "name": "Johann Schopplich",
@@ -75,33 +75,33 @@
75
75
  "chokidar": "^3.5.3",
76
76
  "consola": "^2.15.3",
77
77
  "detect-package-manager": "^2.0.1",
78
- "magic-string": "^0.27.0",
79
- "pathe": "^1.0.0",
78
+ "magic-string": "^0.30.0",
79
+ "pathe": "^1.1.0",
80
80
  "perfect-debounce": "^0.1.3",
81
81
  "picocolors": "^1.0.0",
82
- "postcss": "^8.4.20",
83
- "postcss-dir-pseudo-class": "^6.0.5",
82
+ "postcss": "^8.4.21",
83
+ "postcss-dir-pseudo-class": "^7.0.2",
84
84
  "postcss-load-config": "^4.0.1",
85
- "postcss-logical": "^5.0.4",
86
- "sass": "^1.56.2",
85
+ "postcss-logical": "^6.1.0",
86
+ "sass": "^1.61.0",
87
87
  "unconfig": "^0.3.7",
88
- "vite": "^3.2.4",
88
+ "vite": "^4.2.1",
89
89
  "vite-plugin-full-reload": "^1.0.5",
90
90
  "vue": "^2.7.14"
91
91
  },
92
92
  "devDependencies": {
93
- "@antfu/eslint-config": "^0.33.1",
94
- "@types/fs-extra": "^9.0.13",
95
- "@types/node": "^18.11.13",
96
- "@types/prompts": "^2.4.2",
97
- "bumpp": "^8.2.1",
98
- "eslint": "^8.29.0",
93
+ "@antfu/eslint-config": "^0.38.4",
94
+ "@types/fs-extra": "^11.0.1",
95
+ "@types/node": "^18.15.11",
96
+ "@types/prompts": "^2.4.4",
97
+ "bumpp": "^9.1.0",
98
+ "eslint": "^8.37.0",
99
99
  "fast-glob": "^3.2.12",
100
- "fs-extra": "^11.1.0",
100
+ "fs-extra": "^11.1.1",
101
101
  "simple-git-hooks": "^2.8.1",
102
- "typescript": "^4.9.4",
103
- "unbuild": "^1.0.2",
104
- "vitest": "^0.25.6"
102
+ "typescript": "^5.0.3",
103
+ "unbuild": "^1.2.0",
104
+ "vitest": "^0.29.8"
105
105
  },
106
106
  "simple-git-hooks": {
107
107
  "commit-msg": "node scripts/verifyCommit.mjs $1"