@unocss/config 0.1.0-beta.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ import { UserConfig } from 'unocss';
2
+
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>;
9
+
10
+ export { ConfigResult, loadConfig, readConfig };
package/dist/index.js ADDED
@@ -0,0 +1,258 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ 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
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
+ var __export = (target, all) => {
26
+ __markAsModule(target);
27
+ for (var name in all)
28
+ __defProp(target, name, { get: all[name], enumerable: true });
29
+ };
30
+ var __reExport = (target, module2, desc) => {
31
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
32
+ for (let key of __getOwnPropNames(module2))
33
+ if (!__hasOwnProp.call(target, key) && key !== "default")
34
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
35
+ }
36
+ return target;
37
+ };
38
+ var __toModule = (module2) => {
39
+ 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);
40
+ };
41
+ var __publicField = (obj, key, value) => {
42
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
43
+ return value;
44
+ };
45
+ var __accessCheck = (obj, member, msg) => {
46
+ if (!member.has(obj))
47
+ throw TypeError("Cannot " + msg);
48
+ };
49
+ var __privateGet = (obj, member, getter) => {
50
+ __accessCheck(obj, member, "read from private field");
51
+ return getter ? getter.call(obj) : member.get(obj);
52
+ };
53
+ var __privateAdd = (obj, member, value) => {
54
+ if (member.has(obj))
55
+ throw TypeError("Cannot add the same private member more than once");
56
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
57
+ };
58
+ var __privateSet = (obj, member, value, setter) => {
59
+ __accessCheck(obj, member, "write to private field");
60
+ setter ? setter.call(obj, value) : member.set(obj, value);
61
+ return value;
62
+ };
63
+ var __privateWrapper = (obj, member, setter, getter) => {
64
+ return {
65
+ set _(value) {
66
+ __privateSet(obj, member, value, setter);
67
+ },
68
+ get _() {
69
+ return __privateGet(obj, member, getter);
70
+ }
71
+ };
72
+ };
73
+
74
+ // src/index.ts
75
+ __export(exports, {
76
+ loadConfig: () => loadConfig,
77
+ readConfig: () => readConfig
78
+ });
79
+ var import_fs = __toModule(require("fs"));
80
+
81
+ // ../../node_modules/.pnpm/find-up@6.2.0/node_modules/find-up/index.js
82
+ var import_node_path2 = __toModule(require("node:path"));
83
+
84
+ // ../../node_modules/.pnpm/locate-path@7.0.0/node_modules/locate-path/index.js
85
+ var import_node_process = __toModule(require("node:process"));
86
+ var import_node_path = __toModule(require("node:path"));
87
+ var import_node_fs = __toModule(require("node:fs"));
88
+
89
+ // ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
90
+ var Node = class {
91
+ constructor(value) {
92
+ __publicField(this, "value");
93
+ __publicField(this, "next");
94
+ this.value = value;
95
+ }
96
+ };
97
+ var _head, _tail, _size;
98
+ var Queue = class {
99
+ constructor() {
100
+ __privateAdd(this, _head, void 0);
101
+ __privateAdd(this, _tail, void 0);
102
+ __privateAdd(this, _size, void 0);
103
+ this.clear();
104
+ }
105
+ enqueue(value) {
106
+ const node = new Node(value);
107
+ if (__privateGet(this, _head)) {
108
+ __privateGet(this, _tail).next = node;
109
+ __privateSet(this, _tail, node);
110
+ } else {
111
+ __privateSet(this, _head, node);
112
+ __privateSet(this, _tail, node);
113
+ }
114
+ __privateWrapper(this, _size)._++;
115
+ }
116
+ dequeue() {
117
+ const current = __privateGet(this, _head);
118
+ if (!current) {
119
+ return;
120
+ }
121
+ __privateSet(this, _head, __privateGet(this, _head).next);
122
+ __privateWrapper(this, _size)._--;
123
+ return current.value;
124
+ }
125
+ clear() {
126
+ __privateSet(this, _head, void 0);
127
+ __privateSet(this, _tail, void 0);
128
+ __privateSet(this, _size, 0);
129
+ }
130
+ get size() {
131
+ return __privateGet(this, _size);
132
+ }
133
+ *[Symbol.iterator]() {
134
+ let current = __privateGet(this, _head);
135
+ while (current) {
136
+ yield current.value;
137
+ current = current.next;
138
+ }
139
+ }
140
+ };
141
+ _head = new WeakMap();
142
+ _tail = new WeakMap();
143
+ _size = new WeakMap();
144
+
145
+ // ../../node_modules/.pnpm/locate-path@7.0.0/node_modules/locate-path/index.js
146
+ var typeMappings = {
147
+ directory: "isDirectory",
148
+ file: "isFile"
149
+ };
150
+ function checkType(type) {
151
+ if (type in typeMappings) {
152
+ return;
153
+ }
154
+ throw new Error(`Invalid type specified: ${type}`);
155
+ }
156
+ var matchType = (type, stat) => type === void 0 || stat[typeMappings[type]]();
157
+ function locatePathSync(paths, {
158
+ cwd = import_node_process.default.cwd(),
159
+ type = "file",
160
+ allowSymlinks = true
161
+ } = {}) {
162
+ checkType(type);
163
+ const statFunction = allowSymlinks ? import_node_fs.default.statSync : import_node_fs.default.lstatSync;
164
+ for (const path_ of paths) {
165
+ try {
166
+ const stat = statFunction(import_node_path.default.resolve(cwd, path_));
167
+ if (matchType(type, stat)) {
168
+ return path_;
169
+ }
170
+ } catch {
171
+ }
172
+ }
173
+ }
174
+
175
+ // ../../node_modules/.pnpm/path-exists@5.0.0/node_modules/path-exists/index.js
176
+ var import_node_fs2 = __toModule(require("node:fs"));
177
+
178
+ // ../../node_modules/.pnpm/find-up@6.2.0/node_modules/find-up/index.js
179
+ var findUpStop = Symbol("findUpStop");
180
+ function findUpMultipleSync(name, options = {}) {
181
+ let directory = import_node_path2.default.resolve(options.cwd || "");
182
+ const { root } = import_node_path2.default.parse(directory);
183
+ const stopAt = options.stopAt || root;
184
+ const limit = options.limit || Number.POSITIVE_INFINITY;
185
+ const paths = [name].flat();
186
+ const runMatcher = (locateOptions) => {
187
+ if (typeof name !== "function") {
188
+ return locatePathSync(paths, locateOptions);
189
+ }
190
+ const foundPath = name(locateOptions.cwd);
191
+ if (typeof foundPath === "string") {
192
+ return locatePathSync([foundPath], locateOptions);
193
+ }
194
+ return foundPath;
195
+ };
196
+ const matches = [];
197
+ while (true) {
198
+ const foundPath = runMatcher(__spreadProps(__spreadValues({}, options), { cwd: directory }));
199
+ if (foundPath === findUpStop) {
200
+ break;
201
+ }
202
+ if (foundPath) {
203
+ matches.push(import_node_path2.default.resolve(directory, foundPath));
204
+ }
205
+ if (directory === stopAt || matches.length >= limit) {
206
+ break;
207
+ }
208
+ directory = import_node_path2.default.dirname(directory);
209
+ }
210
+ return matches;
211
+ }
212
+ function findUpSync(name, options = {}) {
213
+ const matches = findUpMultipleSync(name, __spreadProps(__spreadValues({}, options), { limit: 1 }));
214
+ return matches[0];
215
+ }
216
+
217
+ // src/index.ts
218
+ var import_sucrase = __toModule(require("sucrase"));
219
+ function isDir(path3) {
220
+ try {
221
+ const stat = import_fs.default.lstatSync(path3);
222
+ return stat.isDirectory();
223
+ } catch (e) {
224
+ return false;
225
+ }
226
+ }
227
+ function loadConfig(dirOrPath = process.cwd()) {
228
+ if (typeof dirOrPath !== "string") {
229
+ return {
230
+ config: dirOrPath
231
+ };
232
+ }
233
+ const filepath = isDir(dirOrPath) ? findUpSync([
234
+ "unocss.config.js",
235
+ "unocss.config.cjs",
236
+ "unocss.config.mjs",
237
+ "unocss.config.ts",
238
+ "unocss.config.mts",
239
+ "unocss.config.cts"
240
+ ], { cwd: dirOrPath }) : dirOrPath;
241
+ if (!filepath || !import_fs.default.existsSync(filepath))
242
+ return {};
243
+ return readConfig(filepath);
244
+ }
245
+ function readConfig(filepath) {
246
+ const content = import_fs.default.readFileSync(filepath, "utf-8");
247
+ const transformed = (0, import_sucrase.transform)(content, { transforms: ["typescript", "imports"] }).code;
248
+ const result = new Function("require", `let exports = {};${transformed}; return exports.default;`)(require);
249
+ return {
250
+ filepath,
251
+ config: result
252
+ };
253
+ }
254
+ // Annotate the CommonJS export names for ESM import in node:
255
+ 0 && (module.exports = {
256
+ loadConfig,
257
+ readConfig
258
+ });
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@unocss/config",
3
+ "version": "0.1.0-beta.2",
4
+ "description": "Config loader for UnoCSS",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/antfu/unocss#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/antfu/unocss/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/antfu/unocss.git"
13
+ },
14
+ "funding": "https://github.com/sponsors/antfu",
15
+ "license": "MIT",
16
+ "author": "Anthony Fu <anthonyfu117@hotmail.com>",
17
+ "sideEffects": false,
18
+ "exports": {
19
+ ".": "./dist/index.js"
20
+ },
21
+ "main": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "dependencies": {
27
+ "@unocss/core": "0.1.0-beta.2",
28
+ "sucrase": "^3.20.3"
29
+ },
30
+ "devDependencies": {
31
+ "find-up": "^6.2.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "dev": "tsup --watch src"
36
+ }
37
+ }