@unocss/cli 0.53.0 → 0.53.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/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cac } from 'cac';
|
|
2
2
|
import { loadConfig } from '@unocss/config';
|
|
3
3
|
import { toArray } from '@unocss/core';
|
|
4
|
-
import { b as build, v as version, h as handleError } from './shared/cli.
|
|
4
|
+
import { b as build, v as version, h as handleError } from './shared/cli.06279c51.mjs';
|
|
5
5
|
import 'node:fs';
|
|
6
6
|
import 'pathe';
|
|
7
7
|
import 'fast-glob';
|
|
@@ -11,6 +11,7 @@ import 'perfect-debounce';
|
|
|
11
11
|
import '@rollup/pluginutils';
|
|
12
12
|
import 'magic-string';
|
|
13
13
|
import '@ampproject/remapping';
|
|
14
|
+
import 'node:crypto';
|
|
14
15
|
import '@unocss/preset-uno';
|
|
15
16
|
|
|
16
17
|
async function startCli(cwd = process.cwd(), argv = process.argv, options = {}) {
|
|
@@ -19,6 +20,8 @@ async function startCli(cwd = process.cwd(), argv = process.argv, options = {})
|
|
|
19
20
|
ignoreOptionDefaultValue: true
|
|
20
21
|
}).option("-o, --out-file <file>", "Output file", {
|
|
21
22
|
default: cwd
|
|
23
|
+
}).option("--stdout", "Output to STDOUT", {
|
|
24
|
+
default: false
|
|
22
25
|
}).option("-c, --config [file]", "Config file").option("-w, --watch", "Watch for file changes").option("--preflights", "Enable preflights", { default: true }).option("-m, --minify", "Minify generated CSS", { default: false }).action(async (patterns, flags) => {
|
|
23
26
|
Object.assign(options, {
|
|
24
27
|
cwd,
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -5,9 +5,10 @@ import 'consola';
|
|
|
5
5
|
import 'colorette';
|
|
6
6
|
import 'perfect-debounce';
|
|
7
7
|
import '@unocss/core';
|
|
8
|
-
export { b as build, r as resolveOptions } from './shared/cli.
|
|
8
|
+
export { b as build, r as resolveOptions } from './shared/cli.06279c51.mjs';
|
|
9
9
|
import '@rollup/pluginutils';
|
|
10
10
|
import '@unocss/config';
|
|
11
11
|
import 'magic-string';
|
|
12
12
|
import '@ampproject/remapping';
|
|
13
|
+
import 'node:crypto';
|
|
13
14
|
import '@unocss/preset-uno';
|
|
@@ -9,11 +9,15 @@ import { createFilter } from '@rollup/pluginutils';
|
|
|
9
9
|
import { loadConfig } from '@unocss/config';
|
|
10
10
|
import MagicString from 'magic-string';
|
|
11
11
|
import remapping from '@ampproject/remapping';
|
|
12
|
+
import 'node:crypto';
|
|
12
13
|
import presetUno from '@unocss/preset-uno';
|
|
13
14
|
|
|
14
15
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
15
16
|
const IGNORE_COMMENT = "@unocss-ignore";
|
|
16
17
|
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
18
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
19
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
20
|
+
const SKIP_COMMENT_RE = new RegExp(`(//\\s*?${SKIP_START_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_START_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_START_COMMENT}\\s*?-->)[\\s\\S]*?(//\\s*?${SKIP_END_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_END_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_END_COMMENT}\\s*?-->)`, "g");
|
|
17
21
|
|
|
18
22
|
const defaultPipelineExclude = [cssIdRE];
|
|
19
23
|
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
@@ -63,7 +67,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
63
67
|
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude
|
|
64
68
|
);
|
|
65
69
|
tokens.clear();
|
|
66
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
70
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
67
71
|
invalidate();
|
|
68
72
|
dispatchReload();
|
|
69
73
|
const presets = /* @__PURE__ */ new Set();
|
|
@@ -94,7 +98,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
94
98
|
if (id)
|
|
95
99
|
modules.set(id, code);
|
|
96
100
|
const len = tokens.size;
|
|
97
|
-
await uno.applyExtractors(code, id, tokens);
|
|
101
|
+
await uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
98
102
|
if (tokens.size > len)
|
|
99
103
|
invalidate();
|
|
100
104
|
}
|
|
@@ -139,14 +143,26 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
139
143
|
};
|
|
140
144
|
}
|
|
141
145
|
|
|
146
|
+
function hash(str) {
|
|
147
|
+
let i;
|
|
148
|
+
let l;
|
|
149
|
+
let hval = 2166136261;
|
|
150
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
151
|
+
hval ^= str.charCodeAt(i);
|
|
152
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
153
|
+
}
|
|
154
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
155
|
+
}
|
|
156
|
+
|
|
142
157
|
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
143
158
|
if (original.includes(IGNORE_COMMENT))
|
|
144
159
|
return;
|
|
145
160
|
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
146
161
|
if (!transformers.length)
|
|
147
162
|
return;
|
|
163
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
148
164
|
let code = original;
|
|
149
|
-
let s = new MagicString(code);
|
|
165
|
+
let s = new MagicString(transformSkipCode(code, skipMap));
|
|
150
166
|
const maps = [];
|
|
151
167
|
for (const t of transformers) {
|
|
152
168
|
if (t.idFilter) {
|
|
@@ -157,7 +173,7 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
157
173
|
}
|
|
158
174
|
await t.transform(s, id, ctx);
|
|
159
175
|
if (s.hasChanged()) {
|
|
160
|
-
code = s.toString();
|
|
176
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
161
177
|
maps.push(s.generateMap({ hires: true, source: id }));
|
|
162
178
|
s = new MagicString(code);
|
|
163
179
|
}
|
|
@@ -170,8 +186,24 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
170
186
|
};
|
|
171
187
|
}
|
|
172
188
|
}
|
|
189
|
+
function transformSkipCode(code, map) {
|
|
190
|
+
for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
|
|
191
|
+
if (item != null) {
|
|
192
|
+
const matched = item[0];
|
|
193
|
+
const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
|
|
194
|
+
map.set(withHashKey, matched);
|
|
195
|
+
code = code.replace(matched, withHashKey);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return code;
|
|
199
|
+
}
|
|
200
|
+
function restoreSkipCode(code, map) {
|
|
201
|
+
for (const [withHashKey, matched] of map.entries())
|
|
202
|
+
code = code.replace(withHashKey, matched);
|
|
203
|
+
return code;
|
|
204
|
+
}
|
|
173
205
|
|
|
174
|
-
const version = "0.53.
|
|
206
|
+
const version = "0.53.3";
|
|
175
207
|
|
|
176
208
|
const defaultConfig = {
|
|
177
209
|
envMode: "build",
|
|
@@ -237,8 +269,10 @@ async function build(_options) {
|
|
|
237
269
|
fileCache.set(file, await promises.readFile(file, "utf8"));
|
|
238
270
|
})
|
|
239
271
|
);
|
|
240
|
-
|
|
241
|
-
|
|
272
|
+
if (!options.stdout) {
|
|
273
|
+
consola.log(green(`${name} v${version}`));
|
|
274
|
+
consola.start(`UnoCSS ${options.watch ? "in watch mode..." : "for production..."}`);
|
|
275
|
+
}
|
|
242
276
|
const debouncedBuild = debounce(
|
|
243
277
|
async () => {
|
|
244
278
|
generate(options).catch(handleError);
|
|
@@ -246,7 +280,7 @@ async function build(_options) {
|
|
|
246
280
|
100
|
|
247
281
|
);
|
|
248
282
|
const startWatcher = async () => {
|
|
249
|
-
if (!options.watch)
|
|
283
|
+
if (options.stdout || !options.watch)
|
|
250
284
|
return;
|
|
251
285
|
const { patterns } = options;
|
|
252
286
|
const watcher = await getWatcher(options);
|
|
@@ -283,7 +317,6 @@ async function build(_options) {
|
|
|
283
317
|
}
|
|
284
318
|
async function generate(options2) {
|
|
285
319
|
const sourceCache = Array.from(fileCache).map(([id, code]) => ({ id, code }));
|
|
286
|
-
const outFile = resolve(options2.cwd || process.cwd(), options2.outFile ?? "uno.css");
|
|
287
320
|
const preTransform = await transformFiles(sourceCache, "pre");
|
|
288
321
|
const defaultTransform = await transformFiles(preTransform);
|
|
289
322
|
const postTransform = await transformFiles(defaultTransform, "post");
|
|
@@ -300,6 +333,11 @@ async function build(_options) {
|
|
|
300
333
|
minify: options2.minify
|
|
301
334
|
}
|
|
302
335
|
);
|
|
336
|
+
if (options2.stdout) {
|
|
337
|
+
process.stdout.write(css);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const outFile = resolve(options2.cwd || process.cwd(), options2.outFile ?? "uno.css");
|
|
303
341
|
const dir = dirname(outFile);
|
|
304
342
|
if (!existsSync(dir))
|
|
305
343
|
await promises.mkdir(dir, { recursive: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/cli",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.3",
|
|
4
4
|
"description": "CLI for UnoCSS",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Johann Schopplich",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"magic-string": "^0.30.0",
|
|
50
50
|
"pathe": "^1.1.1",
|
|
51
51
|
"perfect-debounce": "^1.0.0",
|
|
52
|
-
"@unocss/config": "0.53.
|
|
53
|
-
"@unocss/core": "0.53.
|
|
54
|
-
"@unocss/preset-uno": "0.53.
|
|
52
|
+
"@unocss/config": "0.53.3",
|
|
53
|
+
"@unocss/core": "0.53.3",
|
|
54
|
+
"@unocss/preset-uno": "0.53.3"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "unbuild",
|