kirbyup 0.24.0 → 1.0.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/dist/chunks/index.mjs +77 -84
- package/dist/cli.mjs +5 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +4 -4
- package/dist/plugin.d.ts +2 -2
- package/package.json +23 -25
package/dist/chunks/index.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { resolve, dirname, normalize, relative, basename } from 'pathe';
|
|
2
1
|
import { existsSync, statSync } from 'fs';
|
|
2
|
+
import { resolve, normalize, relative, dirname, basename } from 'pathe';
|
|
3
3
|
import { build as build$1, mergeConfig } from 'vite';
|
|
4
4
|
import { createVuePlugin } from 'vite-plugin-vue2';
|
|
5
|
-
import MagicString from 'magic-string';
|
|
6
|
-
import { createConfigLoader } from 'unconfig';
|
|
7
5
|
import postcssrc from 'postcss-load-config';
|
|
8
6
|
import postcssLogical from 'postcss-logical';
|
|
9
7
|
import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
|
|
@@ -13,39 +11,45 @@ import colors from 'picocolors';
|
|
|
13
11
|
import { readFile } from 'fs/promises';
|
|
14
12
|
import { gzip } from 'zlib';
|
|
15
13
|
import { promisify } from 'util';
|
|
14
|
+
import { createConfigLoader } from 'unconfig';
|
|
15
|
+
import MagicString from 'magic-string';
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
const
|
|
17
|
+
const name = "kirbyup";
|
|
18
|
+
const version = "1.0.1";
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
name
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
20
|
+
class PrettyError extends Error {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = this.constructor.name;
|
|
24
|
+
if (typeof Error.captureStackTrace === "function")
|
|
25
|
+
Error.captureStackTrace(this, this.constructor);
|
|
26
|
+
else
|
|
27
|
+
this.stack = new Error(message).stack;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function handleError(error) {
|
|
31
|
+
consola.error(error.message);
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toArray(array) {
|
|
36
|
+
array = array || [];
|
|
37
|
+
if (Array.isArray(array))
|
|
38
|
+
return array;
|
|
39
|
+
return [array];
|
|
40
|
+
}
|
|
41
|
+
const compress = promisify(gzip);
|
|
42
|
+
async function getCompressedSize(code) {
|
|
43
|
+
const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
|
|
44
|
+
return ` / gzip: ${size.toFixed(2)} KiB`;
|
|
45
|
+
}
|
|
46
|
+
async function printFileInfo(root, outDir, filePath, type, content) {
|
|
47
|
+
content ?? (content = await readFile(resolve(outDir, filePath), "utf8"));
|
|
48
|
+
const prettyOutDir = `${normalize(relative(root, resolve(root, outDir)))}/`;
|
|
49
|
+
const kibs = content.length / 1024;
|
|
50
|
+
const compressedSize = await getCompressedSize(content);
|
|
51
|
+
const writeColor = type === "chunk" ? colors.cyan : colors.magenta;
|
|
52
|
+
consola.log(`${colors.white(colors.dim(prettyOutDir)) + writeColor(filePath)} ${colors.dim(`${kibs.toFixed(2)} KiB${compressedSize}`)}`);
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
function defineConfig(config) {
|
|
@@ -90,45 +94,40 @@ async function loadConfig(cwd = process.cwd(), configOrPath = cwd, extraConfigSo
|
|
|
90
94
|
return result;
|
|
91
95
|
}
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
super(message);
|
|
96
|
-
this.name = this.constructor.name;
|
|
97
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
98
|
-
Error.captureStackTrace(this, this.constructor);
|
|
99
|
-
} else {
|
|
100
|
-
this.stack = new Error(message).stack;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function handleError(error) {
|
|
105
|
-
consola.error(error.message);
|
|
106
|
-
process.exitCode = 1;
|
|
107
|
-
}
|
|
97
|
+
const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
|
|
98
|
+
const singlelineCommentsRE = /\/\/.*/g;
|
|
108
99
|
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
async
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
100
|
+
function kirbyupAutoImportPlugin() {
|
|
101
|
+
let config;
|
|
102
|
+
return {
|
|
103
|
+
name: "kirbyup:auto-import",
|
|
104
|
+
configResolved(resolvedConfig) {
|
|
105
|
+
config = resolvedConfig;
|
|
106
|
+
},
|
|
107
|
+
async transform(code) {
|
|
108
|
+
if (code.includes("kirbyup.import")) {
|
|
109
|
+
const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
|
|
110
|
+
const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
|
|
111
|
+
let s = null;
|
|
112
|
+
let match;
|
|
113
|
+
while (match = kirbyupImportRE.exec(noCommentsCode)) {
|
|
114
|
+
const { 0: exp, 1: rawPath, index } = match;
|
|
115
|
+
if (!s)
|
|
116
|
+
s = new MagicString(code);
|
|
117
|
+
s.overwrite(index, index + exp.length, `kirbyup.import(import.meta.globEager(${rawPath}))`);
|
|
118
|
+
}
|
|
119
|
+
if (s) {
|
|
120
|
+
return {
|
|
121
|
+
code: s.toString(),
|
|
122
|
+
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
const name = "kirbyup";
|
|
130
|
-
const version = "0.24.0";
|
|
131
|
-
|
|
132
131
|
let resolvedKirbyupConfig;
|
|
133
132
|
let resolvedPostCssConfig;
|
|
134
133
|
async function viteBuild(options) {
|
|
@@ -178,15 +177,13 @@ async function viteBuild(options) {
|
|
|
178
177
|
result = await build$1(mergeConfig(defaultConfig, extendViteConfig));
|
|
179
178
|
} catch (error) {
|
|
180
179
|
consola.error("Build failed");
|
|
181
|
-
if (mode === "production")
|
|
180
|
+
if (mode === "production")
|
|
182
181
|
throw error;
|
|
183
|
-
}
|
|
184
182
|
}
|
|
185
183
|
if (result && !options.watch) {
|
|
186
184
|
const { output } = toArray(result)[0];
|
|
187
|
-
for (const { fileName, type, code } of output)
|
|
185
|
+
for (const { fileName, type, code } of output)
|
|
188
186
|
printFileInfo(root, outDir, fileName, type, code);
|
|
189
|
-
}
|
|
190
187
|
}
|
|
191
188
|
return result;
|
|
192
189
|
}
|
|
@@ -194,9 +191,8 @@ async function resolveOptions(options) {
|
|
|
194
191
|
if (!options.entry) {
|
|
195
192
|
throw new PrettyError(`No input file, try ${colors.cyan(`${name} <path/to/file.js>`)}`);
|
|
196
193
|
}
|
|
197
|
-
if (!existsSync(options.entry))
|
|
194
|
+
if (!existsSync(options.entry))
|
|
198
195
|
throw new PrettyError(`Cannot find ${options.entry}`);
|
|
199
|
-
}
|
|
200
196
|
return options;
|
|
201
197
|
}
|
|
202
198
|
async function build(_options) {
|
|
@@ -206,18 +202,16 @@ async function build(_options) {
|
|
|
206
202
|
try {
|
|
207
203
|
resolvedPostCssConfig = await postcssrc({});
|
|
208
204
|
} catch (err) {
|
|
209
|
-
if (!/No PostCSS Config found/.test(err.message))
|
|
205
|
+
if (!/No PostCSS Config found/.test(err.message))
|
|
210
206
|
throw err;
|
|
211
|
-
}
|
|
212
207
|
resolvedPostCssConfig = {
|
|
213
208
|
plugins: [postcssLogical(), postcssDirPseudoClass()]
|
|
214
209
|
};
|
|
215
210
|
}
|
|
216
211
|
consola.log(colors.green(`${name} v${version}`));
|
|
217
212
|
consola.start(`Building ${colors.cyan(options.entry)}`);
|
|
218
|
-
if (options.watch)
|
|
213
|
+
if (options.watch)
|
|
219
214
|
consola.info("Running in watch mode");
|
|
220
|
-
}
|
|
221
215
|
const debouncedBuild = debounce(async () => {
|
|
222
216
|
viteBuild(options).catch(handleError);
|
|
223
217
|
}, 100);
|
|
@@ -230,21 +224,20 @@ async function build(_options) {
|
|
|
230
224
|
"index.{css,js}"
|
|
231
225
|
];
|
|
232
226
|
const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
|
|
233
|
-
consola.info(
|
|
227
|
+
consola.info(`Watching for changes in ${toArray(watchPaths).map((i) => colors.cyan(i)).join(", ")}`);
|
|
234
228
|
const watcher = watch(watchPaths, {
|
|
235
229
|
ignoreInitial: true,
|
|
236
230
|
ignorePermissionErrors: true,
|
|
237
231
|
ignored
|
|
238
232
|
});
|
|
239
|
-
if (configSources.length)
|
|
233
|
+
if (configSources.length)
|
|
240
234
|
watcher.add(configSources);
|
|
241
|
-
}
|
|
242
235
|
watcher.on("all", async (type, file) => {
|
|
243
236
|
if (configSources.includes(file)) {
|
|
244
237
|
resolvedKirbyupConfig = (await loadConfig()).config;
|
|
245
238
|
consola.info(`${colors.cyan(basename(file))} changed, setting new config`);
|
|
246
239
|
} else {
|
|
247
|
-
consola.log(colors.green(type)
|
|
240
|
+
consola.log(`${colors.green(type)} ${colors.white(colors.dim(file))}`);
|
|
248
241
|
}
|
|
249
242
|
debouncedBuild();
|
|
250
243
|
});
|
package/dist/cli.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { cac } from 'cac';
|
|
2
2
|
import { h as handleError, n as name, b as build, v as version } from './chunks/index.mjs';
|
|
3
|
-
import 'pathe';
|
|
4
3
|
import 'fs';
|
|
4
|
+
import 'pathe';
|
|
5
5
|
import 'vite';
|
|
6
6
|
import 'vite-plugin-vue2';
|
|
7
|
-
import 'magic-string';
|
|
8
|
-
import 'unconfig';
|
|
9
7
|
import 'postcss-load-config';
|
|
10
8
|
import 'postcss-logical';
|
|
11
9
|
import 'postcss-dir-pseudo-class';
|
|
@@ -15,6 +13,8 @@ import 'picocolors';
|
|
|
15
13
|
import 'fs/promises';
|
|
16
14
|
import 'zlib';
|
|
17
15
|
import 'util';
|
|
16
|
+
import 'unconfig';
|
|
17
|
+
import 'magic-string';
|
|
18
18
|
|
|
19
19
|
async function main(options = {}) {
|
|
20
20
|
const cli = cac(name);
|
|
@@ -22,13 +22,12 @@ async function main(options = {}) {
|
|
|
22
22
|
ignoreOptionDefaultValue: true
|
|
23
23
|
}).option("-d, --out-dir <dir>", "Output directory", {
|
|
24
24
|
default: process.cwd()
|
|
25
|
-
}).option("-w
|
|
25
|
+
}).option("-w, --watch [path]", 'Watch mode. If no path is specified, the folder of the input file will be watched. Repeat "--watch" for multiple paths.').action(async (file, flags) => {
|
|
26
26
|
Object.assign(options, {
|
|
27
27
|
...flags
|
|
28
28
|
});
|
|
29
|
-
if (file)
|
|
29
|
+
if (file)
|
|
30
30
|
options.entry = file;
|
|
31
|
-
}
|
|
32
31
|
await build(options);
|
|
33
32
|
});
|
|
34
33
|
cli.help();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AliasOptions, InlineConfig } from 'vite';
|
|
2
2
|
|
|
3
3
|
declare type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>;
|
|
4
|
-
|
|
4
|
+
interface CliOptions {
|
|
5
5
|
entry?: string;
|
|
6
6
|
outDir?: string;
|
|
7
7
|
watch?: boolean | string | Array<boolean | string>;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
declare type ResolvedCliOptions = MarkRequired<CliOptions, 'entry'>;
|
|
10
10
|
interface UserConfig {
|
|
11
11
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import 'pathe';
|
|
2
1
|
import 'fs';
|
|
2
|
+
import 'pathe';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'vite-plugin-vue2';
|
|
5
|
-
export { b as build, d as defineConfig, r as resolveOptions } from './chunks/index.mjs';
|
|
6
5
|
import 'postcss-load-config';
|
|
7
6
|
import 'postcss-logical';
|
|
8
7
|
import 'postcss-dir-pseudo-class';
|
|
9
8
|
import 'consola';
|
|
10
9
|
import 'perfect-debounce';
|
|
11
10
|
import 'picocolors';
|
|
12
|
-
|
|
13
|
-
import 'unconfig';
|
|
11
|
+
export { b as build, d as defineConfig, r as resolveOptions } from './chunks/index.mjs';
|
|
14
12
|
import 'fs/promises';
|
|
15
13
|
import 'zlib';
|
|
16
14
|
import 'util';
|
|
15
|
+
import 'unconfig';
|
|
16
|
+
import 'magic-string';
|
package/dist/plugin.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kirbyup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"packageManager": "pnpm@7.1.9",
|
|
4
5
|
"description": "Zero-config bundler for Kirby Panel plugins",
|
|
5
6
|
"author": {
|
|
6
7
|
"name": "Johann Schopplich",
|
|
@@ -25,15 +26,14 @@
|
|
|
25
26
|
],
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs"
|
|
30
31
|
},
|
|
31
32
|
"./plugin": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
33
|
+
"types": "./dist/plugin.d.ts",
|
|
34
|
+
"import": "./dist/plugin.mjs"
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
|
-
"main": "./dist/index.mjs",
|
|
37
37
|
"module": "./dist/index.mjs",
|
|
38
38
|
"types": "./dist/index.d.ts",
|
|
39
39
|
"bin": {
|
|
@@ -49,21 +49,17 @@
|
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "unbuild",
|
|
51
51
|
"stub": "unbuild --stub",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
52
|
+
"lint": "eslint .",
|
|
53
|
+
"lint:fix": "eslint . --fix",
|
|
54
|
+
"release": "bumpp --commit --push --tag",
|
|
55
|
+
"test": "vitest",
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
57
|
"prepare": "pnpm exec simple-git-hooks"
|
|
58
58
|
},
|
|
59
|
-
"simple-git-hooks": {
|
|
60
|
-
"commit-msg": "node scripts/verifyCommit.mjs $1"
|
|
61
|
-
},
|
|
62
59
|
"dependencies": {
|
|
63
60
|
"cac": "^6.7.12",
|
|
64
61
|
"chokidar": "^3.5.3",
|
|
65
62
|
"consola": "^2.15.3",
|
|
66
|
-
"execa": "6.1.0",
|
|
67
63
|
"pathe": "^0.3.0",
|
|
68
64
|
"perfect-debounce": "^0.1.3",
|
|
69
65
|
"picocolors": "^1.0.0",
|
|
@@ -71,28 +67,30 @@
|
|
|
71
67
|
"postcss-dir-pseudo-class": "^6.0.4",
|
|
72
68
|
"postcss-load-config": "^4.0.1",
|
|
73
69
|
"postcss-logical": "^5.0.4",
|
|
74
|
-
"sass": "^1.52.
|
|
70
|
+
"sass": "^1.52.2",
|
|
75
71
|
"unconfig": "^0.3.4",
|
|
76
|
-
"vite": "
|
|
72
|
+
"vite": "2.9.9",
|
|
77
73
|
"vite-plugin-vue2": "^2.0.1",
|
|
78
74
|
"vue": "^2.6.14",
|
|
79
75
|
"vue-template-compiler": "^2.6.14"
|
|
80
76
|
},
|
|
81
77
|
"devDependencies": {
|
|
78
|
+
"@antfu/eslint-config": "^0.25.1",
|
|
82
79
|
"@types/fs-extra": "^9.0.13",
|
|
83
|
-
"@types/node": "^17.0.
|
|
80
|
+
"@types/node": "^17.0.41",
|
|
84
81
|
"@types/prompts": "^2.4.0",
|
|
85
|
-
"
|
|
86
|
-
"
|
|
82
|
+
"bumpp": "^7.1.1",
|
|
83
|
+
"eslint": "^8.17.0",
|
|
84
|
+
"execa": "^6.1.0",
|
|
87
85
|
"fast-glob": "^3.2.11",
|
|
88
86
|
"fs-extra": "^10.1.0",
|
|
89
|
-
"minimist": "^1.2.6",
|
|
90
|
-
"prettier": "^2.6.2",
|
|
91
|
-
"prompts": "^2.4.2",
|
|
92
87
|
"simple-git-hooks": "^2.8.0",
|
|
93
88
|
"tsx": "^3.4.2",
|
|
94
|
-
"typescript": "^4.7.
|
|
89
|
+
"typescript": "^4.7.3",
|
|
95
90
|
"unbuild": "^0.7.4",
|
|
96
|
-
"vitest": "^0.
|
|
91
|
+
"vitest": "^0.14.1"
|
|
92
|
+
},
|
|
93
|
+
"simple-git-hooks": {
|
|
94
|
+
"commit-msg": "node scripts/verifyCommit.mjs $1"
|
|
97
95
|
}
|
|
98
96
|
}
|