@unocss/config 0.12.15 → 0.13.0

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/index.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { UserConfig } from '@unocss/core';
2
+ import { LoadConfigResult } from 'unconfig';
3
+ export { LoadConfigResult } from 'unconfig';
2
4
 
3
- interface ConfigResult<U> {
4
- filepath?: string;
5
- config?: U;
6
- }
7
- declare function loadConfig<U extends UserConfig>(dirOrPath?: string | U): ConfigResult<U>;
8
- declare function readConfig<U>(filepath: string): ConfigResult<U>;
5
+ declare function createConfigLoader<U extends UserConfig>(dirOrPath?: string | U): () => Promise<LoadConfigResult<U>>;
6
+ declare function loadConfig<U extends UserConfig>(dirOrPath: string | U): Promise<LoadConfigResult<U>>;
9
7
 
10
- export { ConfigResult, loadConfig, readConfig };
8
+ export { createConfigLoader, loadConfig };
package/dist/index.js CHANGED
@@ -1,33 +1,10 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __getProtoOf = Object.getPrototypeOf;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
7
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
- var __esm = (fn, res) => function __init() {
26
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
27
- };
28
- var __commonJS = (cb, mod) => function __require() {
29
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
30
- };
31
8
  var __export = (target, all) => {
32
9
  __markAsModule(target);
33
10
  for (var name in all)
@@ -45,376 +22,50 @@ var __toModule = (module2) => {
45
22
  return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
46
23
  };
47
24
 
48
- // ../../node_modules/.pnpm/tsup@5.5.0_typescript@4.4.4/node_modules/tsup/assets/cjs_shims.js
49
- var importMetaUrlShim;
50
- var init_cjs_shims = __esm({
51
- "../../node_modules/.pnpm/tsup@5.5.0_typescript@4.4.4/node_modules/tsup/assets/cjs_shims.js"() {
52
- importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
53
- }
54
- });
55
-
56
- // ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
57
- var require_yocto_queue = __commonJS({
58
- "../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module2) {
59
- init_cjs_shims();
60
- var Node = class {
61
- constructor(value) {
62
- this.value = value;
63
- this.next = void 0;
64
- }
65
- };
66
- var Queue = class {
67
- constructor() {
68
- this.clear();
69
- }
70
- enqueue(value) {
71
- const node = new Node(value);
72
- if (this._head) {
73
- this._tail.next = node;
74
- this._tail = node;
75
- } else {
76
- this._head = node;
77
- this._tail = node;
78
- }
79
- this._size++;
80
- }
81
- dequeue() {
82
- const current = this._head;
83
- if (!current) {
84
- return;
85
- }
86
- this._head = this._head.next;
87
- this._size--;
88
- return current.value;
89
- }
90
- clear() {
91
- this._head = void 0;
92
- this._tail = void 0;
93
- this._size = 0;
94
- }
95
- get size() {
96
- return this._size;
97
- }
98
- *[Symbol.iterator]() {
99
- let current = this._head;
100
- while (current) {
101
- yield current.value;
102
- current = current.next;
103
- }
104
- }
105
- };
106
- module2.exports = Queue;
107
- }
108
- });
109
-
110
- // ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
111
- var require_p_limit = __commonJS({
112
- "../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module2) {
113
- init_cjs_shims();
114
- "use strict";
115
- var Queue = require_yocto_queue();
116
- var pLimit = (concurrency) => {
117
- if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
118
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
119
- }
120
- const queue = new Queue();
121
- let activeCount = 0;
122
- const next = () => {
123
- activeCount--;
124
- if (queue.size > 0) {
125
- queue.dequeue()();
126
- }
127
- };
128
- const run = async (fn, resolve2, ...args) => {
129
- activeCount++;
130
- const result = (async () => fn(...args))();
131
- resolve2(result);
132
- try {
133
- await result;
134
- } catch {
135
- }
136
- next();
137
- };
138
- const enqueue = (fn, resolve2, ...args) => {
139
- queue.enqueue(run.bind(null, fn, resolve2, ...args));
140
- (async () => {
141
- await Promise.resolve();
142
- if (activeCount < concurrency && queue.size > 0) {
143
- queue.dequeue()();
144
- }
145
- })();
146
- };
147
- const generator = (fn, ...args) => new Promise((resolve2) => {
148
- enqueue(fn, resolve2, ...args);
149
- });
150
- Object.defineProperties(generator, {
151
- activeCount: {
152
- get: () => activeCount
153
- },
154
- pendingCount: {
155
- get: () => queue.size
156
- },
157
- clearQueue: {
158
- value: () => {
159
- queue.clear();
160
- }
161
- }
162
- });
163
- return generator;
164
- };
165
- module2.exports = pLimit;
166
- }
167
- });
168
-
169
- // ../../node_modules/.pnpm/p-locate@5.0.0/node_modules/p-locate/index.js
170
- var require_p_locate = __commonJS({
171
- "../../node_modules/.pnpm/p-locate@5.0.0/node_modules/p-locate/index.js"(exports, module2) {
172
- init_cjs_shims();
173
- "use strict";
174
- var pLimit = require_p_limit();
175
- var EndError = class extends Error {
176
- constructor(value) {
177
- super();
178
- this.value = value;
179
- }
180
- };
181
- var testElement = async (element, tester) => tester(await element);
182
- var finder = async (element) => {
183
- const values = await Promise.all(element);
184
- if (values[1] === true) {
185
- throw new EndError(values[0]);
186
- }
187
- return false;
188
- };
189
- var pLocate = async (iterable, tester, options) => {
190
- options = __spreadValues({
191
- concurrency: Infinity,
192
- preserveOrder: true
193
- }, options);
194
- const limit = pLimit(options.concurrency);
195
- const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
196
- const checkLimit = pLimit(options.preserveOrder ? 1 : Infinity);
197
- try {
198
- await Promise.all(items.map((element) => checkLimit(finder, element)));
199
- } catch (error) {
200
- if (error instanceof EndError) {
201
- return error.value;
202
- }
203
- throw error;
204
- }
205
- };
206
- module2.exports = pLocate;
207
- }
208
- });
209
-
210
- // ../../node_modules/.pnpm/locate-path@6.0.0/node_modules/locate-path/index.js
211
- var require_locate_path = __commonJS({
212
- "../../node_modules/.pnpm/locate-path@6.0.0/node_modules/locate-path/index.js"(exports, module2) {
213
- init_cjs_shims();
214
- "use strict";
215
- var path = require("path");
216
- var fs2 = require("fs");
217
- var { promisify } = require("util");
218
- var pLocate = require_p_locate();
219
- var fsStat = promisify(fs2.stat);
220
- var fsLStat = promisify(fs2.lstat);
221
- var typeMappings = {
222
- directory: "isDirectory",
223
- file: "isFile"
224
- };
225
- function checkType({ type }) {
226
- if (type in typeMappings) {
227
- return;
228
- }
229
- throw new Error(`Invalid type specified: ${type}`);
230
- }
231
- var matchType = (type, stat) => type === void 0 || stat[typeMappings[type]]();
232
- module2.exports = async (paths, options) => {
233
- options = __spreadValues({
234
- cwd: process.cwd(),
235
- type: "file",
236
- allowSymlinks: true
237
- }, options);
238
- checkType(options);
239
- const statFn = options.allowSymlinks ? fsStat : fsLStat;
240
- return pLocate(paths, async (path_) => {
241
- try {
242
- const stat = await statFn(path.resolve(options.cwd, path_));
243
- return matchType(options.type, stat);
244
- } catch {
245
- return false;
246
- }
247
- }, options);
248
- };
249
- module2.exports.sync = (paths, options) => {
250
- options = __spreadValues({
251
- cwd: process.cwd(),
252
- allowSymlinks: true,
253
- type: "file"
254
- }, options);
255
- checkType(options);
256
- const statFn = options.allowSymlinks ? fs2.statSync : fs2.lstatSync;
257
- for (const path_ of paths) {
258
- try {
259
- const stat = statFn(path.resolve(options.cwd, path_));
260
- if (matchType(options.type, stat)) {
261
- return path_;
262
- }
263
- } catch {
264
- }
265
- }
266
- };
267
- }
268
- });
269
-
270
- // ../../node_modules/.pnpm/path-exists@4.0.0/node_modules/path-exists/index.js
271
- var require_path_exists = __commonJS({
272
- "../../node_modules/.pnpm/path-exists@4.0.0/node_modules/path-exists/index.js"(exports, module2) {
273
- init_cjs_shims();
274
- "use strict";
275
- var fs2 = require("fs");
276
- var { promisify } = require("util");
277
- var pAccess = promisify(fs2.access);
278
- module2.exports = async (path) => {
279
- try {
280
- await pAccess(path);
281
- return true;
282
- } catch (_) {
283
- return false;
284
- }
285
- };
286
- module2.exports.sync = (path) => {
287
- try {
288
- fs2.accessSync(path);
289
- return true;
290
- } catch (_) {
291
- return false;
292
- }
293
- };
294
- }
295
- });
296
-
297
- // ../../node_modules/.pnpm/find-up@5.0.0/node_modules/find-up/index.js
298
- var require_find_up = __commonJS({
299
- "../../node_modules/.pnpm/find-up@5.0.0/node_modules/find-up/index.js"(exports, module2) {
300
- init_cjs_shims();
301
- "use strict";
302
- var path = require("path");
303
- var locatePath = require_locate_path();
304
- var pathExists = require_path_exists();
305
- var stop = Symbol("findUp.stop");
306
- module2.exports = async (name, options = {}) => {
307
- let directory = path.resolve(options.cwd || "");
308
- const { root } = path.parse(directory);
309
- const paths = [].concat(name);
310
- const runMatcher = async (locateOptions) => {
311
- if (typeof name !== "function") {
312
- return locatePath(paths, locateOptions);
313
- }
314
- const foundPath = await name(locateOptions.cwd);
315
- if (typeof foundPath === "string") {
316
- return locatePath([foundPath], locateOptions);
317
- }
318
- return foundPath;
319
- };
320
- while (true) {
321
- const foundPath = await runMatcher(__spreadProps(__spreadValues({}, options), { cwd: directory }));
322
- if (foundPath === stop) {
323
- return;
324
- }
325
- if (foundPath) {
326
- return path.resolve(directory, foundPath);
327
- }
328
- if (directory === root) {
329
- return;
330
- }
331
- directory = path.dirname(directory);
332
- }
333
- };
334
- module2.exports.sync = (name, options = {}) => {
335
- let directory = path.resolve(options.cwd || "");
336
- const { root } = path.parse(directory);
337
- const paths = [].concat(name);
338
- const runMatcher = (locateOptions) => {
339
- if (typeof name !== "function") {
340
- return locatePath.sync(paths, locateOptions);
341
- }
342
- const foundPath = name(locateOptions.cwd);
343
- if (typeof foundPath === "string") {
344
- return locatePath.sync([foundPath], locateOptions);
345
- }
346
- return foundPath;
347
- };
348
- while (true) {
349
- const foundPath = runMatcher(__spreadProps(__spreadValues({}, options), { cwd: directory }));
350
- if (foundPath === stop) {
351
- return;
352
- }
353
- if (foundPath) {
354
- return path.resolve(directory, foundPath);
355
- }
356
- if (directory === root) {
357
- return;
358
- }
359
- directory = path.dirname(directory);
360
- }
361
- };
362
- module2.exports.exists = pathExists;
363
- module2.exports.sync.exists = pathExists.sync;
364
- module2.exports.stop = stop;
365
- }
366
- });
367
-
368
25
  // src/index.ts
369
26
  __export(exports, {
370
- loadConfig: () => loadConfig,
371
- readConfig: () => readConfig
27
+ LoadConfigResult: () => import_unconfig.LoadConfigResult,
28
+ createConfigLoader: () => createConfigLoader,
29
+ loadConfig: () => loadConfig
372
30
  });
373
- init_cjs_shims();
374
- var import_fs = __toModule(require("fs"));
375
31
  var import_path = __toModule(require("path"));
376
- var import_find_up = __toModule(require_find_up());
377
- var import_sucrase = __toModule(require("sucrase"));
378
- function isDir(path) {
379
- try {
380
- const stat = import_fs.default.lstatSync(path);
381
- return stat.isDirectory();
382
- } catch (e) {
383
- return false;
384
- }
385
- }
386
- function loadConfig(dirOrPath = process.cwd()) {
32
+ var import_unconfig = __toModule(require("unconfig"));
33
+ var import_presets = __toModule(require("unconfig/presets"));
34
+ function createConfigLoader(dirOrPath = process.cwd()) {
387
35
  if (typeof dirOrPath !== "string") {
388
- return {
389
- config: dirOrPath
390
- };
36
+ return async () => ({
37
+ config: dirOrPath,
38
+ sources: []
39
+ });
391
40
  }
392
41
  dirOrPath = (0, import_path.resolve)(dirOrPath);
393
- let filepath = isDir(dirOrPath) ? import_find_up.default.sync([
394
- "unocss.config.js",
395
- "unocss.config.cjs",
396
- "unocss.config.mjs",
397
- "unocss.config.ts",
398
- "unocss.config.mts",
399
- "unocss.config.cts"
400
- ], { cwd: dirOrPath }) : dirOrPath;
401
- if (filepath && dirOrPath !== filepath)
402
- filepath = (0, import_path.resolve)(dirOrPath, filepath);
403
- if (!filepath || !import_fs.default.existsSync(filepath))
404
- return {};
405
- return readConfig(filepath);
42
+ const loader = (0, import_unconfig.createConfigLoader)({
43
+ sources: [
44
+ {
45
+ files: [
46
+ "unocss.config",
47
+ "uno.config"
48
+ ]
49
+ },
50
+ (0, import_presets.sourcePluginFactory)({
51
+ files: "vite.config",
52
+ targetModule: "unocss/vite"
53
+ }),
54
+ (0, import_presets.sourceObjectFields)({
55
+ files: "nuxt.config",
56
+ fields: "unocss"
57
+ })
58
+ ],
59
+ cwd: dirOrPath
60
+ });
61
+ return loader.load;
406
62
  }
407
- function readConfig(filepath) {
408
- const content = import_fs.default.readFileSync(filepath, "utf-8");
409
- const transformed = (0, import_sucrase.transform)(content, { transforms: ["typescript", "imports"] }).code;
410
- const result = new Function("require", `let exports = {};${transformed}; return exports.default;`)(require);
411
- return {
412
- filepath,
413
- config: result
414
- };
63
+ function loadConfig(dirOrPath) {
64
+ return createConfigLoader(dirOrPath)();
415
65
  }
416
66
  // Annotate the CommonJS export names for ESM import in node:
417
67
  0 && (module.exports = {
418
- loadConfig,
419
- readConfig
68
+ LoadConfigResult,
69
+ createConfigLoader,
70
+ loadConfig
420
71
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/config",
3
- "version": "0.12.15",
3
+ "version": "0.13.0",
4
4
  "description": "Config loader for UnoCSS",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/antfu/unocss/tree/main/packages/config#readme",
@@ -28,11 +28,8 @@
28
28
  "node": ">=14"
29
29
  },
30
30
  "dependencies": {
31
- "@unocss/core": "0.12.15",
32
- "sucrase": "^3.20.3"
33
- },
34
- "devDependencies": {
35
- "find-up": "^5"
31
+ "@unocss/core": "0.13.0",
32
+ "unconfig": "^0.2.1"
36
33
  },
37
34
  "scripts": {
38
35
  "build": "tsup",