kirbyup 3.3.0 → 3.4.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 +1 -1
- package/bin/kirbyup.mjs +1 -1
- package/dist/client/config.d.ts +4 -4
- package/dist/client/config.js +7 -0
- package/dist/client/plugin.d.ts +7 -12
- package/dist/client/plugin.js +14 -0
- package/dist/node/cli-start.js +42 -0
- package/dist/node/cli.d.ts +1 -2
- package/dist/node/cli.js +8 -0
- package/dist/node/config.js +22 -0
- package/dist/node/errors.js +18 -0
- package/dist/node/index.d.ts +6 -5
- package/dist/node/index.js +175 -0
- package/dist/node/plugins/build-cleanup.js +21 -0
- package/dist/node/plugins/glob-import.js +35 -0
- package/dist/node/plugins/hmr.js +57 -0
- package/dist/node/plugins/utils.js +113 -0
- package/dist/node/types.d.ts +44 -0
- package/dist/node/utils.js +26 -0
- package/dist/package.js +6 -0
- package/package.json +30 -29
- package/dist/client/config.d.mts +0 -6
- package/dist/client/config.mjs +0 -5
- package/dist/client/plugin.d.mts +0 -12
- package/dist/client/plugin.mjs +0 -24
- package/dist/node/cli.d.mts +0 -2
- package/dist/node/cli.mjs +0 -58
- package/dist/node/index.d.mts +0 -7
- package/dist/node/index.mjs +0 -25
- package/dist/shared/kirbyup.BtejYnwg.mjs +0 -928
- package/dist/shared/kirbyup.DNMktHWN.d.mts +0 -43
- package/dist/shared/kirbyup.DNMktHWN.d.ts +0 -43
|
@@ -1,928 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import * as fsp from 'node:fs/promises';
|
|
4
|
-
import { readFile } from 'node:fs/promises';
|
|
5
|
-
import vuePlugin from '@vitejs/plugin-vue2';
|
|
6
|
-
import vueJsxPlugin from '@vitejs/plugin-vue2-jsx';
|
|
7
|
-
import { consola } from 'consola';
|
|
8
|
-
import { colors } from 'consola/utils';
|
|
9
|
-
import { resolve, join, normalize, relative, dirname, basename } from 'pathe';
|
|
10
|
-
import { debounce } from 'perfect-debounce';
|
|
11
|
-
import externalGlobals from 'rollup-plugin-external-globals';
|
|
12
|
-
import { createLogger, createServer, build as build$1, mergeConfig } from 'vite';
|
|
13
|
-
import fullReloadPlugin from 'vite-plugin-full-reload';
|
|
14
|
-
import * as vueCompilerSfc from 'vue/compiler-sfc';
|
|
15
|
-
import { loadConfig as loadConfig$1 } from 'c12';
|
|
16
|
-
import postcssrc from 'postcss-load-config';
|
|
17
|
-
import MagicString from 'magic-string';
|
|
18
|
-
import { createRequire } from 'node:module';
|
|
19
|
-
import 'child_process';
|
|
20
|
-
import 'path';
|
|
21
|
-
import 'process';
|
|
22
|
-
import 'stream';
|
|
23
|
-
import 'readline';
|
|
24
|
-
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
25
|
-
import { promisify } from 'node:util';
|
|
26
|
-
import { gzip } from 'node:zlib';
|
|
27
|
-
|
|
28
|
-
const name = "kirbyup";
|
|
29
|
-
const version = "3.3.0";
|
|
30
|
-
|
|
31
|
-
function loadConfig(cwd = process.cwd()) {
|
|
32
|
-
return loadConfig$1({
|
|
33
|
-
cwd,
|
|
34
|
-
name: "kirbyup",
|
|
35
|
-
rcFile: false,
|
|
36
|
-
packageJson: false
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
async function resolvePostCSSConfig(cwd) {
|
|
40
|
-
try {
|
|
41
|
-
return await postcssrc(void 0, void 0, { stopDir: cwd });
|
|
42
|
-
} catch (error) {
|
|
43
|
-
if (!error.message.includes("No PostCSS Config found"))
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
class PrettyError extends Error {
|
|
49
|
-
constructor(message) {
|
|
50
|
-
super(message);
|
|
51
|
-
this.name = this.constructor.name;
|
|
52
|
-
if (typeof Error.captureStackTrace === "function")
|
|
53
|
-
Error.captureStackTrace(this, this.constructor);
|
|
54
|
-
else
|
|
55
|
-
this.stack = new Error(message).stack;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function handleError(error) {
|
|
59
|
-
consola.error(error.message);
|
|
60
|
-
process.exitCode = 1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function kirbyupBuildCleanupPlugin(options) {
|
|
64
|
-
let config;
|
|
65
|
-
let devIndexPath;
|
|
66
|
-
return {
|
|
67
|
-
name: "kirbyup:build-cleanup",
|
|
68
|
-
configResolved(resolvedConfig) {
|
|
69
|
-
config = resolvedConfig;
|
|
70
|
-
devIndexPath = resolve(config.root, options.outDir, "index.dev.mjs");
|
|
71
|
-
},
|
|
72
|
-
writeBundle() {
|
|
73
|
-
if (fs.existsSync(devIndexPath))
|
|
74
|
-
fs.unlinkSync(devIndexPath);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//g;
|
|
80
|
-
const singlelineCommentsRE = /\/\/.*/g;
|
|
81
|
-
const HMR_RUNTIME_ID = "\0plugin-vue2:hmr-runtime";
|
|
82
|
-
const JSX_HMR_RUNTIME_ID = "plugin-vue2-jsx:hmr-runtime";
|
|
83
|
-
function isHmrRuntimeId(id) {
|
|
84
|
-
return id === HMR_RUNTIME_ID || id === JSX_HMR_RUNTIME_ID;
|
|
85
|
-
}
|
|
86
|
-
const __INJECTED_HMR_CODE__ = `
|
|
87
|
-
/** - injected by kirbyup - */
|
|
88
|
-
for (const methodName of ['rerender', 'reload']) {
|
|
89
|
-
const original = __VUE_HMR_RUNTIME__[methodName]
|
|
90
|
-
|
|
91
|
-
__VUE_HMR_RUNTIME__[methodName] = function (id, updatedDef) {
|
|
92
|
-
const key = updatedDef?.__file ? '__file' : updatedDef?.__hmrId ? '__hmrId' : null
|
|
93
|
-
|
|
94
|
-
if (key) {
|
|
95
|
-
const pluginComponents = window.panel.plugins.components
|
|
96
|
-
// const usedComponentDefs = window.panel.app.$options.components
|
|
97
|
-
const usedComponentDefs = window.panel.app._vnode.componentInstance.$options.components // #33
|
|
98
|
-
|
|
99
|
-
for (const componentName in pluginComponents) {
|
|
100
|
-
if (updatedDef[key] === pluginComponents[componentName][key]) {
|
|
101
|
-
const usedDefinition = usedComponentDefs[componentName].options
|
|
102
|
-
|
|
103
|
-
if (map[id].options !== usedDefinition)
|
|
104
|
-
map[id].options = usedDefinition
|
|
105
|
-
|
|
106
|
-
if (typeof map[id].options.$_isSection !== 'boolean')
|
|
107
|
-
map[id].options.$_isSection = /^k-.*-section$/.test(componentName)
|
|
108
|
-
|
|
109
|
-
break
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return original.apply(this, arguments)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function $_applyKirbyModifications(activeDef, newDef) {
|
|
119
|
-
const usedComponentDefs = window.panel.app.$options.components
|
|
120
|
-
|
|
121
|
-
if (newDef.template)
|
|
122
|
-
newDef.render = null
|
|
123
|
-
|
|
124
|
-
if (activeDef.$_isSection)
|
|
125
|
-
newDef.$_isSection = true
|
|
126
|
-
if (newDef.$_isSection && !newDef.mixins?.[0]?.methods?.load)
|
|
127
|
-
newDef.mixins = [activeDef.mixins[0], ...(newDef.mixins || [])]
|
|
128
|
-
|
|
129
|
-
if (typeof newDef.extends === 'string') {
|
|
130
|
-
if (newDef.extends === activeDef.extends?.options?.name) {
|
|
131
|
-
newDef.extends = activeDef.extends
|
|
132
|
-
}
|
|
133
|
-
else if (usedComponentDefs[newDef.extends]) {
|
|
134
|
-
newDef.extends = usedComponentDefs[newDef.extends].extend({
|
|
135
|
-
options: newDef,
|
|
136
|
-
components: { ...usedComponentDefs, ...(newDef.components || {}) },
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
else { newDef.extends = null }
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/** -- */
|
|
143
|
-
`;
|
|
144
|
-
|
|
145
|
-
function kirbyupGlobImportPlugin() {
|
|
146
|
-
let config;
|
|
147
|
-
return {
|
|
148
|
-
name: "kirbyup:glob-import",
|
|
149
|
-
configResolved(resolvedConfig) {
|
|
150
|
-
config = resolvedConfig;
|
|
151
|
-
},
|
|
152
|
-
async transform(code) {
|
|
153
|
-
if (!code.includes("kirbyup.import"))
|
|
154
|
-
return;
|
|
155
|
-
const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
|
|
156
|
-
const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
|
|
157
|
-
let s;
|
|
158
|
-
let match;
|
|
159
|
-
while (match = kirbyupImportRE.exec(noCommentsCode)) {
|
|
160
|
-
const { 0: exp, 1: rawPath, index } = match;
|
|
161
|
-
if (!s)
|
|
162
|
-
s = new MagicString(code);
|
|
163
|
-
s.overwrite(
|
|
164
|
-
index,
|
|
165
|
-
index + exp.length,
|
|
166
|
-
`kirbyup.import(import.meta.glob(${rawPath}, { eager: true }))`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
if (s) {
|
|
170
|
-
return {
|
|
171
|
-
code: s.toString(),
|
|
172
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const require = createRequire(import.meta.url);
|
|
180
|
-
var St = Object.create;
|
|
181
|
-
var $ = Object.defineProperty;
|
|
182
|
-
var kt = Object.getOwnPropertyDescriptor;
|
|
183
|
-
var Tt = Object.getOwnPropertyNames;
|
|
184
|
-
var At = Object.getPrototypeOf, Rt = Object.prototype.hasOwnProperty;
|
|
185
|
-
var h = /* @__PURE__ */ ((t) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(t, {
|
|
186
|
-
get: (e, n) => (typeof require < "u" ? require : e)[n]
|
|
187
|
-
}) : t)(function(t) {
|
|
188
|
-
if (typeof require < "u") return require.apply(this, arguments);
|
|
189
|
-
throw Error('Dynamic require of "' + t + '" is not supported');
|
|
190
|
-
});
|
|
191
|
-
var l = (t, e) => () => (e || t((e = { exports: {} }).exports, e), e.exports);
|
|
192
|
-
var $t = (t, e, n, r) => {
|
|
193
|
-
if (e && typeof e == "object" || typeof e == "function")
|
|
194
|
-
for (let s of Tt(e))
|
|
195
|
-
!Rt.call(t, s) && s !== n && $(t, s, { get: () => e[s], enumerable: !(r = kt(e, s)) || r.enumerable });
|
|
196
|
-
return t;
|
|
197
|
-
};
|
|
198
|
-
var Nt = (t, e, n) => (n = t != null ? St(At(t)) : {}, $t(
|
|
199
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
200
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
201
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
202
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
203
|
-
$(n, "default", { value: t, enumerable: true }) ,
|
|
204
|
-
t
|
|
205
|
-
));
|
|
206
|
-
|
|
207
|
-
// node_modules/isexe/windows.js
|
|
208
|
-
var W = l((Se, H) => {
|
|
209
|
-
H.exports = z;
|
|
210
|
-
z.sync = Wt;
|
|
211
|
-
var j = h("fs");
|
|
212
|
-
function Ht(t, e) {
|
|
213
|
-
var n = e.pathExt !== void 0 ? e.pathExt : process.env.PATHEXT;
|
|
214
|
-
if (!n || (n = n.split(";"), n.indexOf("") !== -1))
|
|
215
|
-
return true;
|
|
216
|
-
for (var r = 0; r < n.length; r++) {
|
|
217
|
-
var s = n[r].toLowerCase();
|
|
218
|
-
if (s && t.substr(-s.length).toLowerCase() === s)
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
function F(t, e, n) {
|
|
224
|
-
return !t.isSymbolicLink() && !t.isFile() ? false : Ht(e, n);
|
|
225
|
-
}
|
|
226
|
-
function z(t, e, n) {
|
|
227
|
-
j.stat(t, function(r, s) {
|
|
228
|
-
n(r, r ? false : F(s, t, e));
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
function Wt(t, e) {
|
|
232
|
-
return F(j.statSync(t), t, e);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// node_modules/isexe/mode.js
|
|
237
|
-
var X = l((ke, B) => {
|
|
238
|
-
B.exports = K;
|
|
239
|
-
K.sync = Dt;
|
|
240
|
-
var D = h("fs");
|
|
241
|
-
function K(t, e, n) {
|
|
242
|
-
D.stat(t, function(r, s) {
|
|
243
|
-
n(r, r ? false : M(s, e));
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
function Dt(t, e) {
|
|
247
|
-
return M(D.statSync(t), e);
|
|
248
|
-
}
|
|
249
|
-
function M(t, e) {
|
|
250
|
-
return t.isFile() && Kt(t, e);
|
|
251
|
-
}
|
|
252
|
-
function Kt(t, e) {
|
|
253
|
-
var n = t.mode, r = t.uid, s = t.gid, o = e.uid !== void 0 ? e.uid : process.getuid && process.getuid(), i = e.gid !== void 0 ? e.gid : process.getgid && process.getgid(), a = parseInt("100", 8), c = parseInt("010", 8), u = parseInt("001", 8), f = a | c, p = n & u || n & c && s === i || n & a && r === o || n & f && o === 0;
|
|
254
|
-
return p;
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
// node_modules/isexe/index.js
|
|
259
|
-
var U = l((Ae, G) => {
|
|
260
|
-
h("fs"); var v;
|
|
261
|
-
process.platform === "win32" || global.TESTING_WINDOWS ? v = W() : v = X();
|
|
262
|
-
G.exports = y;
|
|
263
|
-
y.sync = Mt;
|
|
264
|
-
function y(t, e, n) {
|
|
265
|
-
if (typeof e == "function" && (n = e, e = {}), !n) {
|
|
266
|
-
if (typeof Promise != "function")
|
|
267
|
-
throw new TypeError("callback not provided");
|
|
268
|
-
return new Promise(function(r, s) {
|
|
269
|
-
y(t, e || {}, function(o, i) {
|
|
270
|
-
o ? s(o) : r(i);
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
v(t, e || {}, function(r, s) {
|
|
275
|
-
r && (r.code === "EACCES" || e && e.ignoreErrors) && (r = null, s = false), n(r, s);
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
function Mt(t, e) {
|
|
279
|
-
try {
|
|
280
|
-
return v.sync(t, e || {});
|
|
281
|
-
} catch (n) {
|
|
282
|
-
if (e && e.ignoreErrors || n.code === "EACCES")
|
|
283
|
-
return false;
|
|
284
|
-
throw n;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
// node_modules/which/which.js
|
|
290
|
-
var et = l((Re, tt) => {
|
|
291
|
-
var g = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys", Y = h("path"), Bt = g ? ";" : ":", V = U(), J = (t) => Object.assign(new Error(`not found: ${t}`), { code: "ENOENT" }), Q = (t, e) => {
|
|
292
|
-
let n = e.colon || Bt, r = t.match(/\//) || g && t.match(/\\/) ? [""] : [
|
|
293
|
-
// windows always checks the cwd first
|
|
294
|
-
...g ? [process.cwd()] : [],
|
|
295
|
-
...(e.path || process.env.PATH || /* istanbul ignore next: very unusual */
|
|
296
|
-
"").split(n)
|
|
297
|
-
], s = g ? e.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "", o = g ? s.split(n) : [""];
|
|
298
|
-
return g && t.indexOf(".") !== -1 && o[0] !== "" && o.unshift(""), {
|
|
299
|
-
pathEnv: r,
|
|
300
|
-
pathExt: o,
|
|
301
|
-
pathExtExe: s
|
|
302
|
-
};
|
|
303
|
-
}, Z = (t, e, n) => {
|
|
304
|
-
typeof e == "function" && (n = e, e = {}), e || (e = {});
|
|
305
|
-
let { pathEnv: r, pathExt: s, pathExtExe: o } = Q(t, e), i = [], a = (u) => new Promise((f, p) => {
|
|
306
|
-
if (u === r.length)
|
|
307
|
-
return e.all && i.length ? f(i) : p(J(t));
|
|
308
|
-
let d = r[u], w = /^".*"$/.test(d) ? d.slice(1, -1) : d, m = Y.join(w, t), b = !w && /^\.[\\\/]/.test(t) ? t.slice(0, 2) + m : m;
|
|
309
|
-
f(c(b, u, 0));
|
|
310
|
-
}), c = (u, f, p) => new Promise((d, w) => {
|
|
311
|
-
if (p === s.length)
|
|
312
|
-
return d(a(f + 1));
|
|
313
|
-
let m = s[p];
|
|
314
|
-
V(u + m, { pathExt: o }, (b, Ot) => {
|
|
315
|
-
if (!b && Ot)
|
|
316
|
-
if (e.all)
|
|
317
|
-
i.push(u + m);
|
|
318
|
-
else
|
|
319
|
-
return d(u + m);
|
|
320
|
-
return d(c(u, f, p + 1));
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
return n ? a(0).then((u) => n(null, u), n) : a(0);
|
|
324
|
-
}, Xt = (t, e) => {
|
|
325
|
-
e = e || {};
|
|
326
|
-
let { pathEnv: n, pathExt: r, pathExtExe: s } = Q(t, e), o = [];
|
|
327
|
-
for (let i = 0; i < n.length; i++) {
|
|
328
|
-
let a = n[i], c = /^".*"$/.test(a) ? a.slice(1, -1) : a, u = Y.join(c, t), f = !c && /^\.[\\\/]/.test(t) ? t.slice(0, 2) + u : u;
|
|
329
|
-
for (let p = 0; p < r.length; p++) {
|
|
330
|
-
let d = f + r[p];
|
|
331
|
-
try {
|
|
332
|
-
if (V.sync(d, { pathExt: s }))
|
|
333
|
-
if (e.all)
|
|
334
|
-
o.push(d);
|
|
335
|
-
else
|
|
336
|
-
return d;
|
|
337
|
-
} catch {
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
if (e.all && o.length)
|
|
342
|
-
return o;
|
|
343
|
-
if (e.nothrow)
|
|
344
|
-
return null;
|
|
345
|
-
throw J(t);
|
|
346
|
-
};
|
|
347
|
-
tt.exports = Z;
|
|
348
|
-
Z.sync = Xt;
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
// node_modules/path-key/index.js
|
|
352
|
-
var rt = l(($e, _) => {
|
|
353
|
-
var nt = (t = {}) => {
|
|
354
|
-
let e = t.env || process.env;
|
|
355
|
-
return (t.platform || process.platform) !== "win32" ? "PATH" : Object.keys(e).reverse().find((r) => r.toUpperCase() === "PATH") || "Path";
|
|
356
|
-
};
|
|
357
|
-
_.exports = nt;
|
|
358
|
-
_.exports.default = nt;
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
// node_modules/cross-spawn/lib/util/resolveCommand.js
|
|
362
|
-
var ct = l((Ne, it) => {
|
|
363
|
-
var st = h("path"), Gt = et(), Ut = rt();
|
|
364
|
-
function ot(t, e) {
|
|
365
|
-
let n = t.options.env || process.env, r = process.cwd(), s = t.options.cwd != null, o = s && process.chdir !== void 0 && !process.chdir.disabled;
|
|
366
|
-
if (o)
|
|
367
|
-
try {
|
|
368
|
-
process.chdir(t.options.cwd);
|
|
369
|
-
} catch {
|
|
370
|
-
}
|
|
371
|
-
let i;
|
|
372
|
-
try {
|
|
373
|
-
i = Gt.sync(t.command, {
|
|
374
|
-
path: n[Ut({ env: n })],
|
|
375
|
-
pathExt: e ? st.delimiter : void 0
|
|
376
|
-
});
|
|
377
|
-
} catch {
|
|
378
|
-
} finally {
|
|
379
|
-
o && process.chdir(r);
|
|
380
|
-
}
|
|
381
|
-
return i && (i = st.resolve(s ? t.options.cwd : "", i)), i;
|
|
382
|
-
}
|
|
383
|
-
function Yt(t) {
|
|
384
|
-
return ot(t) || ot(t, true);
|
|
385
|
-
}
|
|
386
|
-
it.exports = Yt;
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
// node_modules/cross-spawn/lib/util/escape.js
|
|
390
|
-
var ut = l((qe, P) => {
|
|
391
|
-
var C = /([()\][%!^"`<>&|;, *?])/g;
|
|
392
|
-
function Vt(t) {
|
|
393
|
-
return t = t.replace(C, "^$1"), t;
|
|
394
|
-
}
|
|
395
|
-
function Jt(t, e) {
|
|
396
|
-
return t = `${t}`, t = t.replace(/(\\*)"/g, '$1$1\\"'), t = t.replace(/(\\*)$/, "$1$1"), t = `"${t}"`, t = t.replace(C, "^$1"), e && (t = t.replace(C, "^$1")), t;
|
|
397
|
-
}
|
|
398
|
-
P.exports.command = Vt;
|
|
399
|
-
P.exports.argument = Jt;
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
// node_modules/shebang-regex/index.js
|
|
403
|
-
var lt = l((Ie, at) => {
|
|
404
|
-
at.exports = /^#!(.*)/;
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
// node_modules/shebang-command/index.js
|
|
408
|
-
var dt = l((Le, pt) => {
|
|
409
|
-
var Qt = lt();
|
|
410
|
-
pt.exports = (t = "") => {
|
|
411
|
-
let e = t.match(Qt);
|
|
412
|
-
if (!e)
|
|
413
|
-
return null;
|
|
414
|
-
let [n, r] = e[0].replace(/#! ?/, "").split(" "), s = n.split("/").pop();
|
|
415
|
-
return s === "env" ? r : r ? `${s} ${r}` : s;
|
|
416
|
-
};
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
// node_modules/cross-spawn/lib/util/readShebang.js
|
|
420
|
-
var ht = l((je, ft) => {
|
|
421
|
-
var O = h("fs"), Zt = dt();
|
|
422
|
-
function te(t) {
|
|
423
|
-
let n = Buffer.alloc(150), r;
|
|
424
|
-
try {
|
|
425
|
-
r = O.openSync(t, "r"), O.readSync(r, n, 0, 150, 0), O.closeSync(r);
|
|
426
|
-
} catch {
|
|
427
|
-
}
|
|
428
|
-
return Zt(n.toString());
|
|
429
|
-
}
|
|
430
|
-
ft.exports = te;
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
// node_modules/cross-spawn/lib/parse.js
|
|
434
|
-
var wt = l((Fe, Et) => {
|
|
435
|
-
var ee = h("path"), mt = ct(), gt = ut(), ne = ht(), re = process.platform === "win32", se = /\.(?:com|exe)$/i, oe = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
|
|
436
|
-
function ie(t) {
|
|
437
|
-
t.file = mt(t);
|
|
438
|
-
let e = t.file && ne(t.file);
|
|
439
|
-
return e ? (t.args.unshift(t.file), t.command = e, mt(t)) : t.file;
|
|
440
|
-
}
|
|
441
|
-
function ce(t) {
|
|
442
|
-
if (!re)
|
|
443
|
-
return t;
|
|
444
|
-
let e = ie(t), n = !se.test(e);
|
|
445
|
-
if (t.options.forceShell || n) {
|
|
446
|
-
let r = oe.test(e);
|
|
447
|
-
t.command = ee.normalize(t.command), t.command = gt.command(t.command), t.args = t.args.map((o) => gt.argument(o, r));
|
|
448
|
-
let s = [t.command].concat(t.args).join(" ");
|
|
449
|
-
t.args = ["/d", "/s", "/c", `"${s}"`], t.command = process.env.comspec || "cmd.exe", t.options.windowsVerbatimArguments = true;
|
|
450
|
-
}
|
|
451
|
-
return t;
|
|
452
|
-
}
|
|
453
|
-
function ue(t, e, n) {
|
|
454
|
-
e && !Array.isArray(e) && (n = e, e = null), e = e ? e.slice(0) : [], n = Object.assign({}, n);
|
|
455
|
-
let r = {
|
|
456
|
-
command: t,
|
|
457
|
-
args: e,
|
|
458
|
-
options: n,
|
|
459
|
-
file: void 0,
|
|
460
|
-
original: {
|
|
461
|
-
command: t,
|
|
462
|
-
args: e
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
return n.shell ? r : ce(r);
|
|
466
|
-
}
|
|
467
|
-
Et.exports = ue;
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
// node_modules/cross-spawn/lib/enoent.js
|
|
471
|
-
var bt = l((ze, vt) => {
|
|
472
|
-
var S = process.platform === "win32";
|
|
473
|
-
function k(t, e) {
|
|
474
|
-
return Object.assign(new Error(`${e} ${t.command} ENOENT`), {
|
|
475
|
-
code: "ENOENT",
|
|
476
|
-
errno: "ENOENT",
|
|
477
|
-
syscall: `${e} ${t.command}`,
|
|
478
|
-
path: t.command,
|
|
479
|
-
spawnargs: t.args
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
function ae(t, e) {
|
|
483
|
-
if (!S)
|
|
484
|
-
return;
|
|
485
|
-
let n = t.emit;
|
|
486
|
-
t.emit = function(r, s) {
|
|
487
|
-
if (r === "exit") {
|
|
488
|
-
let o = xt(s, e);
|
|
489
|
-
if (o)
|
|
490
|
-
return n.call(t, "error", o);
|
|
491
|
-
}
|
|
492
|
-
return n.apply(t, arguments);
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
function xt(t, e) {
|
|
496
|
-
return S && t === 1 && !e.file ? k(e.original, "spawn") : null;
|
|
497
|
-
}
|
|
498
|
-
function le(t, e) {
|
|
499
|
-
return S && t === 1 && !e.file ? k(e.original, "spawnSync") : null;
|
|
500
|
-
}
|
|
501
|
-
vt.exports = {
|
|
502
|
-
hookChildProcess: ae,
|
|
503
|
-
verifyENOENT: xt,
|
|
504
|
-
verifyENOENTSync: le,
|
|
505
|
-
notFoundError: k
|
|
506
|
-
};
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
// node_modules/cross-spawn/index.js
|
|
510
|
-
var Ct = l((He, E) => {
|
|
511
|
-
var yt = h("child_process"), T = wt(), A = bt();
|
|
512
|
-
function _t(t, e, n) {
|
|
513
|
-
let r = T(t, e, n), s = yt.spawn(r.command, r.args, r.options);
|
|
514
|
-
return A.hookChildProcess(s, r), s;
|
|
515
|
-
}
|
|
516
|
-
function pe(t, e, n) {
|
|
517
|
-
let r = T(t, e, n), s = yt.spawnSync(r.command, r.args, r.options);
|
|
518
|
-
return s.error = s.error || A.verifyENOENTSync(s.status, r), s;
|
|
519
|
-
}
|
|
520
|
-
E.exports = _t;
|
|
521
|
-
E.exports.spawn = _t;
|
|
522
|
-
E.exports.sync = pe;
|
|
523
|
-
E.exports._parse = T;
|
|
524
|
-
E.exports._enoent = A;
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
// src/main.ts
|
|
528
|
-
Nt(Ct());
|
|
529
|
-
|
|
530
|
-
async function findup(cwd, match, options = {}) {
|
|
531
|
-
const segments = normalize(cwd).split("/");
|
|
532
|
-
while (segments.length > 0) {
|
|
533
|
-
const path = segments.join("/") || "/";
|
|
534
|
-
const result = await match(path);
|
|
535
|
-
if (result || !options.includeParentDirs) {
|
|
536
|
-
return result;
|
|
537
|
-
}
|
|
538
|
-
segments.pop();
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
function parsePackageManagerField(packageManager) {
|
|
542
|
-
const [name, _version] = (packageManager || "").split("@");
|
|
543
|
-
const [version, buildMeta] = _version?.split("+") || [];
|
|
544
|
-
if (name && name !== "-" && /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name)) {
|
|
545
|
-
return { name, version, buildMeta };
|
|
546
|
-
}
|
|
547
|
-
const sanitized = name.replace(/\W+/g, "");
|
|
548
|
-
const warnings = [
|
|
549
|
-
`Abnormal characters found in \`packageManager\` field, sanitizing from \`${name}\` to \`${sanitized}\``
|
|
550
|
-
];
|
|
551
|
-
return {
|
|
552
|
-
name: sanitized,
|
|
553
|
-
version,
|
|
554
|
-
buildMeta,
|
|
555
|
-
warnings
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
const packageManagers = [
|
|
560
|
-
{
|
|
561
|
-
name: "npm",
|
|
562
|
-
command: "npm",
|
|
563
|
-
lockFile: "package-lock.json"
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
name: "pnpm",
|
|
567
|
-
command: "pnpm",
|
|
568
|
-
lockFile: "pnpm-lock.yaml",
|
|
569
|
-
files: ["pnpm-workspace.yaml"]
|
|
570
|
-
},
|
|
571
|
-
{
|
|
572
|
-
name: "bun",
|
|
573
|
-
command: "bun",
|
|
574
|
-
lockFile: ["bun.lockb", "bun.lock"]
|
|
575
|
-
},
|
|
576
|
-
{
|
|
577
|
-
name: "yarn",
|
|
578
|
-
command: "yarn",
|
|
579
|
-
lockFile: "yarn.lock",
|
|
580
|
-
files: [".yarnrc.yml"]
|
|
581
|
-
},
|
|
582
|
-
{
|
|
583
|
-
name: "deno",
|
|
584
|
-
command: "deno",
|
|
585
|
-
lockFile: "deno.lock",
|
|
586
|
-
files: ["deno.json"]
|
|
587
|
-
}
|
|
588
|
-
];
|
|
589
|
-
async function detectPackageManager(cwd, options = {}) {
|
|
590
|
-
const detected = await findup(
|
|
591
|
-
resolve(cwd || "."),
|
|
592
|
-
async (path) => {
|
|
593
|
-
if (!options.ignorePackageJSON) {
|
|
594
|
-
const packageJSONPath = join(path, "package.json");
|
|
595
|
-
if (existsSync(packageJSONPath)) {
|
|
596
|
-
const packageJSON = JSON.parse(
|
|
597
|
-
await readFile(packageJSONPath, "utf8")
|
|
598
|
-
);
|
|
599
|
-
if (packageJSON?.packageManager) {
|
|
600
|
-
const {
|
|
601
|
-
name,
|
|
602
|
-
version = "0.0.0",
|
|
603
|
-
buildMeta,
|
|
604
|
-
warnings
|
|
605
|
-
} = parsePackageManagerField(packageJSON.packageManager);
|
|
606
|
-
if (name) {
|
|
607
|
-
const majorVersion = version.split(".")[0];
|
|
608
|
-
const packageManager = packageManagers.find(
|
|
609
|
-
(pm) => pm.name === name && pm.majorVersion === majorVersion
|
|
610
|
-
) || packageManagers.find((pm) => pm.name === name);
|
|
611
|
-
return {
|
|
612
|
-
name,
|
|
613
|
-
command: name,
|
|
614
|
-
version,
|
|
615
|
-
majorVersion,
|
|
616
|
-
buildMeta,
|
|
617
|
-
warnings,
|
|
618
|
-
files: packageManager?.files,
|
|
619
|
-
lockFile: packageManager?.lockFile
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
const denoJSONPath = join(path, "deno.json");
|
|
625
|
-
if (existsSync(denoJSONPath)) {
|
|
626
|
-
return packageManagers.find((pm) => pm.name === "deno");
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
if (!options.ignoreLockFile) {
|
|
630
|
-
for (const packageManager of packageManagers) {
|
|
631
|
-
const detectionsFiles = [
|
|
632
|
-
packageManager.lockFile,
|
|
633
|
-
packageManager.files
|
|
634
|
-
].flat().filter(Boolean);
|
|
635
|
-
if (detectionsFiles.some((file) => existsSync(resolve(path, file)))) {
|
|
636
|
-
return {
|
|
637
|
-
...packageManager
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
},
|
|
643
|
-
{
|
|
644
|
-
includeParentDirs: options.includeParentDirs ?? true
|
|
645
|
-
}
|
|
646
|
-
);
|
|
647
|
-
if (!detected && !options.ignoreArgv) {
|
|
648
|
-
const scriptArg = process.argv[1];
|
|
649
|
-
if (scriptArg) {
|
|
650
|
-
for (const packageManager of packageManagers) {
|
|
651
|
-
const re = new RegExp(`[/\\\\]\\.?${packageManager.command}`);
|
|
652
|
-
if (re.test(scriptArg)) {
|
|
653
|
-
return packageManager;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
return detected;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
function kirbyupHmrPlugin(options) {
|
|
662
|
-
let config;
|
|
663
|
-
let entry;
|
|
664
|
-
let devIndexPath;
|
|
665
|
-
return {
|
|
666
|
-
name: "kirbyup:hmr",
|
|
667
|
-
apply: "serve",
|
|
668
|
-
configResolved(resolvedConfig) {
|
|
669
|
-
config = resolvedConfig;
|
|
670
|
-
entry = resolve(config.root, options.entry);
|
|
671
|
-
devIndexPath = resolve(config.root, options.outDir || "", "index.dev.mjs");
|
|
672
|
-
},
|
|
673
|
-
transform(code, id) {
|
|
674
|
-
if (isHmrRuntimeId(id)) {
|
|
675
|
-
return code.replace(
|
|
676
|
-
// https://github.com/vitejs/vite-plugin-vue2/blob/8de73ea6b8a1df4c14308da2885db195dacc2b14/src/utils/hmrRuntime.ts#L173
|
|
677
|
-
/^.*=\s*record\.Ctor\.super\.extend\(options\)/m,
|
|
678
|
-
"$_applyKirbyModifications(record.Ctor.options, options) // injected by kirbyup\n$&"
|
|
679
|
-
) + __INJECTED_HMR_CODE__;
|
|
680
|
-
}
|
|
681
|
-
},
|
|
682
|
-
configureServer(server) {
|
|
683
|
-
if (!server.httpServer)
|
|
684
|
-
return;
|
|
685
|
-
server.httpServer.once("listening", async () => {
|
|
686
|
-
const entryPath = entry.replace(`${config.root}/`, "");
|
|
687
|
-
const { address, family, port } = server.httpServer.address();
|
|
688
|
-
const hostname = family === "IPv6" ? `[${address}]` : address;
|
|
689
|
-
const baseUrl = `http://${hostname}:${port}${config.base}`;
|
|
690
|
-
const entryUrl = new URL(entryPath, baseUrl).href;
|
|
691
|
-
const pm = await detectPackageManager(config.root);
|
|
692
|
-
await fsp.writeFile(devIndexPath, getViteProxyModule(entryUrl, pm));
|
|
693
|
-
});
|
|
694
|
-
},
|
|
695
|
-
closeBundle() {
|
|
696
|
-
if (fs.existsSync(devIndexPath))
|
|
697
|
-
fs.unlinkSync(devIndexPath);
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
function getViteProxyModule(entryUrl, packageManager) {
|
|
702
|
-
const pm = packageManager?.name || "npm";
|
|
703
|
-
return `
|
|
704
|
-
try {
|
|
705
|
-
await import("${entryUrl}");
|
|
706
|
-
} catch (err) {
|
|
707
|
-
console.error(
|
|
708
|
-
"[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."
|
|
709
|
-
);
|
|
710
|
-
throw err;
|
|
711
|
-
}
|
|
712
|
-
`.trimStart();
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
function toArray(array) {
|
|
716
|
-
array ??= [];
|
|
717
|
-
return Array.isArray(array) ? array : [array];
|
|
718
|
-
}
|
|
719
|
-
const compress = promisify(gzip);
|
|
720
|
-
async function getCompressedSize(code) {
|
|
721
|
-
const size = (await compress(typeof code === "string" ? code : Buffer$1.from(code))).length / 1024;
|
|
722
|
-
return ` / gzip: ${size.toFixed(2)} KiB`;
|
|
723
|
-
}
|
|
724
|
-
async function printFileInfo(root, outDir, filePath, content, type, maxLength) {
|
|
725
|
-
const prettyOutDir = `${normalize(relative(root, resolve(root, outDir)))}/`;
|
|
726
|
-
const kibs = content.length / 1024;
|
|
727
|
-
const compressedSize = await getCompressedSize(content);
|
|
728
|
-
const writeColor = type === "chunk" ? colors.cyan : colors.magenta;
|
|
729
|
-
consola.log(
|
|
730
|
-
colors.white(colors.dim(prettyOutDir)) + writeColor(filePath.padEnd(maxLength + 2)) + colors.dim(`${kibs.toFixed(2)} kB${compressedSize}`)
|
|
731
|
-
);
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
let resolvedKirbyupConfig;
|
|
735
|
-
let resolvedPostCssConfig;
|
|
736
|
-
const logLevel = "warn";
|
|
737
|
-
const logger = createLogger(logLevel);
|
|
738
|
-
const loggerWarn = logger.warn;
|
|
739
|
-
logger.warn = (msg, options) => {
|
|
740
|
-
if (msg.includes("(!) build.outDir"))
|
|
741
|
-
return;
|
|
742
|
-
loggerWarn(msg, options);
|
|
743
|
-
};
|
|
744
|
-
function getViteConfig(command, options) {
|
|
745
|
-
const aliasDir = resolve(options.cwd, dirname(options.entry));
|
|
746
|
-
const { alias = {}, vite, extendViteConfig } = resolvedKirbyupConfig;
|
|
747
|
-
const userConfig = vite ?? extendViteConfig ?? {};
|
|
748
|
-
const sharedConfig = {
|
|
749
|
-
resolve: {
|
|
750
|
-
alias: {
|
|
751
|
-
"~/": `${aliasDir}/`,
|
|
752
|
-
"@/": `${aliasDir}/`,
|
|
753
|
-
...alias
|
|
754
|
-
}
|
|
755
|
-
},
|
|
756
|
-
plugins: [
|
|
757
|
-
// Explicitly pass the compiler, since the plugin's resolving of the compiler
|
|
758
|
-
// looks in the current directory and breaks `npx kirbyup`
|
|
759
|
-
vuePlugin({ compiler: vueCompilerSfc }),
|
|
760
|
-
vueJsxPlugin(),
|
|
761
|
-
kirbyupGlobImportPlugin(),
|
|
762
|
-
{ ...externalGlobals({ vue: "Vue" }), enforce: "post" }
|
|
763
|
-
],
|
|
764
|
-
build: {
|
|
765
|
-
copyPublicDir: false
|
|
766
|
-
},
|
|
767
|
-
...resolvedPostCssConfig && {
|
|
768
|
-
css: {
|
|
769
|
-
postcss: resolvedPostCssConfig
|
|
770
|
-
}
|
|
771
|
-
},
|
|
772
|
-
envDir: options.cwd,
|
|
773
|
-
envPrefix: ["VITE_", "KIRBYUP_"],
|
|
774
|
-
customLogger: logger,
|
|
775
|
-
logLevel
|
|
776
|
-
};
|
|
777
|
-
if (command === "serve") {
|
|
778
|
-
const { port, watch } = options;
|
|
779
|
-
const serveConfig = mergeConfig(sharedConfig, {
|
|
780
|
-
plugins: [
|
|
781
|
-
kirbyupHmrPlugin(options),
|
|
782
|
-
watch && fullReloadPlugin(watch)
|
|
783
|
-
].filter(Boolean),
|
|
784
|
-
// Input needs to be specified so dependency pre-bundling works
|
|
785
|
-
build: {
|
|
786
|
-
rollupOptions: {
|
|
787
|
-
input: resolve(options.cwd, options.entry)
|
|
788
|
-
}
|
|
789
|
-
},
|
|
790
|
-
// Specify origin so asset URLs include Vite server host
|
|
791
|
-
server: {
|
|
792
|
-
port,
|
|
793
|
-
strictPort: true,
|
|
794
|
-
origin: `http://localhost:${port}`
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
return mergeConfig(serveConfig, userConfig);
|
|
798
|
-
}
|
|
799
|
-
const mode = options.watch ? "development" : "production";
|
|
800
|
-
const buildConfig = mergeConfig(sharedConfig, {
|
|
801
|
-
mode,
|
|
802
|
-
plugins: [kirbyupBuildCleanupPlugin(options)],
|
|
803
|
-
build: {
|
|
804
|
-
lib: {
|
|
805
|
-
entry: resolve(options.cwd, options.entry),
|
|
806
|
-
formats: ["iife"],
|
|
807
|
-
name: "kirbyupExport",
|
|
808
|
-
fileName: () => "index.js"
|
|
809
|
-
},
|
|
810
|
-
minify: mode === "production",
|
|
811
|
-
outDir: options.outDir,
|
|
812
|
-
emptyOutDir: false,
|
|
813
|
-
rollupOptions: {
|
|
814
|
-
output: {
|
|
815
|
-
assetFileNames: "index.[ext]"
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
return mergeConfig(buildConfig, userConfig);
|
|
821
|
-
}
|
|
822
|
-
async function generate(options) {
|
|
823
|
-
const config = getViteConfig("build", options);
|
|
824
|
-
let result;
|
|
825
|
-
try {
|
|
826
|
-
result = await build$1(config);
|
|
827
|
-
} catch (error) {
|
|
828
|
-
consola.error("Build failed");
|
|
829
|
-
if (config.mode === "production")
|
|
830
|
-
throw error;
|
|
831
|
-
}
|
|
832
|
-
if (result && !options.watch) {
|
|
833
|
-
const { output } = toArray(result)[0];
|
|
834
|
-
let longest = 0;
|
|
835
|
-
for (const file in output) {
|
|
836
|
-
const l = output[file].fileName.length;
|
|
837
|
-
if (l > longest)
|
|
838
|
-
longest = l;
|
|
839
|
-
}
|
|
840
|
-
for (const { fileName, type, code } of output) {
|
|
841
|
-
await printFileInfo(
|
|
842
|
-
options.cwd,
|
|
843
|
-
options.outDir,
|
|
844
|
-
fileName,
|
|
845
|
-
code ?? await fsp.readFile(resolve(options.outDir, fileName), "utf8"),
|
|
846
|
-
type,
|
|
847
|
-
longest
|
|
848
|
-
);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
return result;
|
|
852
|
-
}
|
|
853
|
-
async function build(options) {
|
|
854
|
-
assertEntryExists(options);
|
|
855
|
-
const { cwd } = options;
|
|
856
|
-
const { config, configFile } = await loadConfig(cwd);
|
|
857
|
-
resolvedKirbyupConfig = config ?? {};
|
|
858
|
-
resolvedPostCssConfig = await resolvePostCSSConfig(cwd);
|
|
859
|
-
{
|
|
860
|
-
consola.log(colors.green(`${name} v${version}`));
|
|
861
|
-
consola.start(`Building ${colors.cyan(options.entry)}`);
|
|
862
|
-
}
|
|
863
|
-
if (options.watch)
|
|
864
|
-
consola.info("Running in watch mode");
|
|
865
|
-
const debouncedBuild = debounce(async () => {
|
|
866
|
-
generate(options).catch(handleError);
|
|
867
|
-
}, 100);
|
|
868
|
-
const startWatcher = async () => {
|
|
869
|
-
if (!options.watch)
|
|
870
|
-
return;
|
|
871
|
-
const { watch } = await import('chokidar');
|
|
872
|
-
const ignored = [
|
|
873
|
-
"**/{.git,node_modules}/**",
|
|
874
|
-
// Always ignore dist files
|
|
875
|
-
"index.{css,js}"
|
|
876
|
-
];
|
|
877
|
-
const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter(
|
|
878
|
-
(path) => typeof path === "string"
|
|
879
|
-
) : options.watch;
|
|
880
|
-
consola.info(
|
|
881
|
-
`Watching for changes in ${toArray(watchPaths).map((i) => colors.cyan(i)).join(", ")}`
|
|
882
|
-
);
|
|
883
|
-
const watcher = watch(watchPaths, {
|
|
884
|
-
ignoreInitial: true,
|
|
885
|
-
ignorePermissionErrors: true,
|
|
886
|
-
ignored,
|
|
887
|
-
cwd
|
|
888
|
-
});
|
|
889
|
-
if (configFile)
|
|
890
|
-
watcher.add(configFile);
|
|
891
|
-
watcher.on("all", async (type, file) => {
|
|
892
|
-
const absolutePath = resolve(cwd, file);
|
|
893
|
-
if (configFile === absolutePath) {
|
|
894
|
-
resolvedKirbyupConfig = (await loadConfig(cwd)).config ?? {};
|
|
895
|
-
consola.info(
|
|
896
|
-
`${colors.cyan(basename(file))} changed, setting new config`
|
|
897
|
-
);
|
|
898
|
-
} else {
|
|
899
|
-
consola.log(`${colors.green(type)} ${colors.white(colors.dim(file))}`);
|
|
900
|
-
}
|
|
901
|
-
debouncedBuild();
|
|
902
|
-
});
|
|
903
|
-
};
|
|
904
|
-
await generate(options);
|
|
905
|
-
consola.success("Build successful");
|
|
906
|
-
startWatcher();
|
|
907
|
-
}
|
|
908
|
-
async function serve(options) {
|
|
909
|
-
assertEntryExists(options);
|
|
910
|
-
const { cwd } = options;
|
|
911
|
-
const { config } = await loadConfig(cwd);
|
|
912
|
-
resolvedKirbyupConfig = config ?? {};
|
|
913
|
-
resolvedPostCssConfig = await resolvePostCSSConfig(cwd);
|
|
914
|
-
{
|
|
915
|
-
consola.log(colors.green(`${name} v${version}`));
|
|
916
|
-
consola.info("Starting development server...");
|
|
917
|
-
}
|
|
918
|
-
const server = await createServer(getViteConfig("serve", options));
|
|
919
|
-
await server.listen();
|
|
920
|
-
consola.success(`Server is listening on :${server.config.server.port}`);
|
|
921
|
-
return server;
|
|
922
|
-
}
|
|
923
|
-
function assertEntryExists(options) {
|
|
924
|
-
if (!fs.existsSync(resolve(options.cwd, options.entry)))
|
|
925
|
-
throw new PrettyError(`Cannot find "${options.entry}"`);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
export { build as b, handleError as h, name as n, serve as s, version as v };
|