@unocss/cli 0.31.6 → 0.31.10

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/bin/unocss.mjs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ 'use strict'
3
+ import('../dist/index.mjs')
@@ -3,11 +3,12 @@ import { resolve, dirname, relative, basename } from 'pathe';
3
3
  import fg from 'fast-glob';
4
4
  import consola from 'consola';
5
5
  import { cyan, green, dim } from 'colorette';
6
+ import { debounce } from 'perfect-debounce';
6
7
  import { createGenerator, toArray } from '@unocss/core';
7
8
  import { createConfigLoader } from '@unocss/config';
8
9
  import presetUno from '@unocss/preset-uno';
9
10
 
10
- const version = "0.31.6";
11
+ const version = "0.31.10";
11
12
 
12
13
  class PrettyError extends Error {
13
14
  constructor(message) {
@@ -25,31 +26,6 @@ function handleError(error) {
25
26
  process.exitCode = 1;
26
27
  }
27
28
 
28
- function debouncePromise(fn, delay, onError) {
29
- let timeout;
30
- let promiseInFly;
31
- let callbackPending;
32
- return function debounced(...args) {
33
- if (promiseInFly) {
34
- callbackPending = () => {
35
- debounced(...args);
36
- callbackPending = void 0;
37
- };
38
- } else {
39
- if (timeout)
40
- clearTimeout(timeout);
41
- timeout = setTimeout(() => {
42
- timeout = void 0;
43
- promiseInFly = fn(...args).catch(onError).finally(() => {
44
- promiseInFly = void 0;
45
- if (callbackPending)
46
- callbackPending();
47
- });
48
- }, delay);
49
- }
50
- };
51
- }
52
-
53
29
  const defaultConfig = {
54
30
  envMode: "build",
55
31
  presets: [
@@ -80,7 +56,7 @@ async function resolveOptions(options) {
80
56
  }
81
57
  async function build(_options) {
82
58
  const options = await resolveOptions(_options);
83
- const loadConfig = createConfigLoader();
59
+ const loadConfig = createConfigLoader(process.cwd());
84
60
  const { config, sources: configSources } = await loadConfig();
85
61
  uno = createGenerator(config, defaultConfig);
86
62
  const files = await fg(options.patterns);
@@ -89,9 +65,9 @@ async function build(_options) {
89
65
  }));
90
66
  consola.log(green(`${name} v${version}`));
91
67
  consola.start(`UnoCSS ${options.watch ? "in watch mode..." : "for production..."}`);
92
- const debouncedBuild = debouncePromise(async () => {
93
- generate(options);
94
- }, 100, handleError);
68
+ const debouncedBuild = debounce(async () => {
69
+ generate(options).catch(handleError);
70
+ }, 100);
95
71
  const startWatcher = async () => {
96
72
  if (!options.watch)
97
73
  return;
package/dist/cli.mjs CHANGED
@@ -5,6 +5,7 @@ import 'pathe';
5
5
  import 'fast-glob';
6
6
  import 'consola';
7
7
  import 'colorette';
8
+ import 'perfect-debounce';
8
9
  import '@unocss/core';
9
10
  import '@unocss/config';
10
11
  import '@unocss/preset-uno';
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import 'pathe';
3
3
  import 'fast-glob';
4
4
  import 'consola';
5
5
  import 'colorette';
6
+ import 'perfect-debounce';
6
7
  import '@unocss/core';
7
8
  import '@unocss/config';
8
9
  export { b as build, g as generate, r as resolveOptions } from './chunks/index.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/cli",
3
- "version": "0.31.6",
3
+ "version": "0.31.10",
4
4
  "description": "CLI for UnoCSS",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/unocss/unocss/tree/main/packages/cli#readme",
@@ -19,29 +19,36 @@
19
19
  "directory": "packages/cli"
20
20
  },
21
21
  "funding": "https://github.com/sponsors/antfu",
22
- "main": "./dist/index.cjs",
22
+ "main": "./dist/index.mjs",
23
+ "module": "./dist/index.mjs",
23
24
  "types": "./dist/index.d.ts",
24
- "exports": "./dist/index.cjs",
25
+ "exports": {
26
+ ".": {
27
+ "import": "./dist/index.mjs",
28
+ "types": "./dist/index.d.ts"
29
+ }
30
+ },
25
31
  "files": [
26
32
  "bin",
27
33
  "dist"
28
34
  ],
29
35
  "bin": {
30
- "unocss": "./bin/unocss.cjs"
36
+ "unocss": "./bin/unocss.mjs"
31
37
  },
32
38
  "engines": {
33
39
  "node": ">=14"
34
40
  },
35
41
  "dependencies": {
36
- "@unocss/config": "0.31.6",
37
- "@unocss/core": "0.31.6",
38
- "@unocss/preset-uno": "0.31.6",
42
+ "@unocss/config": "0.31.10",
43
+ "@unocss/core": "0.31.10",
44
+ "@unocss/preset-uno": "0.31.10",
39
45
  "cac": "^6.7.12",
40
46
  "chokidar": "^3.5.3",
41
47
  "colorette": "^2.0.16",
42
48
  "consola": "^2.15.3",
43
49
  "fast-glob": "^3.2.11",
44
- "pathe": "^0.2.0"
50
+ "pathe": "^0.2.0",
51
+ "perfect-debounce": "^0.1.3"
45
52
  },
46
53
  "scripts": {
47
54
  "build": "unbuild",
package/bin/unocss.cjs DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- require('../dist/cli.cjs')
@@ -1,140 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const pathe = require('pathe');
5
- const fg = require('fast-glob');
6
- const consola = require('consola');
7
- const colorette = require('colorette');
8
- const core = require('@unocss/core');
9
- const config = require('@unocss/config');
10
- const presetUno = require('@unocss/preset-uno');
11
-
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
13
-
14
- const fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
15
- const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
16
- const presetUno__default = /*#__PURE__*/_interopDefaultLegacy(presetUno);
17
-
18
- const version = "0.31.6";
19
-
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
- if (error instanceof PrettyError)
32
- consola__default.error(error.message);
33
- process.exitCode = 1;
34
- }
35
-
36
- function debouncePromise(fn, delay, onError) {
37
- let timeout;
38
- let promiseInFly;
39
- let callbackPending;
40
- return function debounced(...args) {
41
- if (promiseInFly) {
42
- callbackPending = () => {
43
- debounced(...args);
44
- callbackPending = void 0;
45
- };
46
- } else {
47
- if (timeout)
48
- clearTimeout(timeout);
49
- timeout = setTimeout(() => {
50
- timeout = void 0;
51
- promiseInFly = fn(...args).catch(onError).finally(() => {
52
- promiseInFly = void 0;
53
- if (callbackPending)
54
- callbackPending();
55
- });
56
- }, delay);
57
- }
58
- };
59
- }
60
-
61
- const defaultConfig = {
62
- envMode: "build",
63
- presets: [
64
- presetUno__default()
65
- ]
66
- };
67
-
68
- const name = "unocss";
69
- let uno;
70
- const fileCache = /* @__PURE__ */ new Map();
71
- async function generate(options) {
72
- const outFile = options.outFile ?? pathe.resolve(process.cwd(), "uno.css");
73
- const { css, matched } = await uno.generate([...fileCache].join("\n"));
74
- const dir = pathe.dirname(outFile);
75
- if (!fs.existsSync(dir))
76
- await fs.promises.mkdir(dir, { recursive: true });
77
- await fs.promises.writeFile(outFile, css, "utf-8");
78
- if (!options.watch) {
79
- consola__default.success(`${[...matched].length} utilities generated to ${colorette.cyan(pathe.relative(process.cwd(), outFile))}
80
- `);
81
- }
82
- }
83
- async function resolveOptions(options) {
84
- if (!options.patterns?.length) {
85
- throw new PrettyError(`No glob patterns, try ${colorette.cyan(`${name} <path/to/**/*>`)}`);
86
- }
87
- return options;
88
- }
89
- async function build(_options) {
90
- const options = await resolveOptions(_options);
91
- const loadConfig = config.createConfigLoader();
92
- const { config: config$1, sources: configSources } = await loadConfig();
93
- uno = core.createGenerator(config$1, defaultConfig);
94
- const files = await fg__default(options.patterns);
95
- await Promise.all(files.map(async (file) => {
96
- fileCache.set(file, await fs.promises.readFile(file, "utf8"));
97
- }));
98
- consola__default.log(colorette.green(`${name} v${version}`));
99
- consola__default.start(`UnoCSS ${options.watch ? "in watch mode..." : "for production..."}`);
100
- const debouncedBuild = debouncePromise(async () => {
101
- generate(options);
102
- }, 100, handleError);
103
- const startWatcher = async () => {
104
- if (!options.watch)
105
- return;
106
- const { watch } = await import('chokidar');
107
- const { patterns } = options;
108
- const ignored = ["**/{.git,node_modules}/**"];
109
- consola__default.info(`Watching for changes in ${core.toArray(patterns).map((i) => colorette.cyan(i)).join(", ")}`);
110
- const watcher = watch(patterns, {
111
- ignoreInitial: true,
112
- ignorePermissionErrors: true,
113
- ignored
114
- });
115
- if (configSources.length) {
116
- watcher.add(configSources);
117
- watcher.on("all", async (type, file) => {
118
- if (configSources.includes(file)) {
119
- uno.setConfig((await loadConfig()).config);
120
- consola__default.info(`${colorette.cyan(pathe.basename(file))} changed, setting new config`);
121
- } else {
122
- consola__default.log(`${colorette.green(type)} ${colorette.dim(file)}`);
123
- if (type.startsWith("unlink"))
124
- fileCache.delete(file);
125
- else
126
- fileCache.set(file, await fs.promises.readFile(file, "utf8"));
127
- }
128
- debouncedBuild();
129
- });
130
- }
131
- };
132
- await generate(options);
133
- startWatcher();
134
- }
135
-
136
- exports.build = build;
137
- exports.generate = generate;
138
- exports.handleError = handleError;
139
- exports.resolveOptions = resolveOptions;
140
- exports.version = version;
package/dist/cli.cjs DELETED
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- const cac = require('cac');
4
- const index = require('./chunks/index.cjs');
5
- require('fs');
6
- require('pathe');
7
- require('fast-glob');
8
- require('consola');
9
- require('colorette');
10
- require('@unocss/core');
11
- require('@unocss/config');
12
- require('@unocss/preset-uno');
13
-
14
- const name = "unocss";
15
- async function main(options = {}) {
16
- const cli = cac.cac(name);
17
- cli.command("[...patterns]", "Glob patterns", {
18
- ignoreOptionDefaultValue: true
19
- }).option("-o, --out-file <file>", "Output file", {
20
- default: process.cwd()
21
- }).option("-w, --watch", "Watch for file changes").action(async (patterns, flags) => {
22
- Object.assign(options, {
23
- ...flags
24
- });
25
- if (patterns)
26
- options.patterns = patterns;
27
- await index.build(options);
28
- });
29
- cli.help();
30
- cli.version(index.version);
31
- cli.parse(process.argv, { run: false });
32
- await cli.runMatchedCommand();
33
- }
34
- main().catch(index.handleError);
package/dist/index.cjs DELETED
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('fs');
6
- require('pathe');
7
- require('fast-glob');
8
- require('consola');
9
- require('colorette');
10
- require('@unocss/core');
11
- require('@unocss/config');
12
- const index = require('./chunks/index.cjs');
13
- require('@unocss/preset-uno');
14
-
15
-
16
-
17
- exports.build = index.build;
18
- exports.generate = index.generate;
19
- exports.resolveOptions = index.resolveOptions;