oxlint-react-compiler-experimental 0.0.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.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as defineConfig } from "./config.js";
2
+ export { defineConfig };
@@ -0,0 +1,66 @@
1
+ import { n as isDefineConfig } from "./config.js";
2
+ import { i as DateNow, o as JSONStringify, r as ArrayIsArray, t as getErrorMessage } from "./utils.js";
3
+ //#region src-js/js_config.ts
4
+ function validateConfigExtends(root) {
5
+ let visited = /* @__PURE__ */ new WeakSet(), inStack = /* @__PURE__ */ new WeakSet(), stackObjects = [], stackPaths = [], formatCycleError = (refPath, cycleStart, idx) => `\`extends\` contains a circular reference.
6
+
7
+ ${refPath} points back to ${cycleStart}\nCycle: ${idx === -1 ? `${cycleStart} -> ${cycleStart}` : [...stackPaths.slice(idx), cycleStart].join(" -> ")}`, visit = (config, path) => {
8
+ if (visited.has(config)) return;
9
+ if (inStack.has(config)) {
10
+ let idx = stackObjects.indexOf(config), cycleStart = idx === -1 ? "<unknown>" : stackPaths[idx];
11
+ throw Error(formatCycleError(path, cycleStart, idx));
12
+ }
13
+ inStack.add(config), stackObjects.push(config), stackPaths.push(path);
14
+ let maybeExtends = config.extends;
15
+ if (maybeExtends !== void 0) {
16
+ if (!ArrayIsArray(maybeExtends)) throw Error("`extends` must be an array of config objects (strings/paths are not supported).");
17
+ for (let i = 0; i < maybeExtends.length; i++) {
18
+ let item = maybeExtends[i];
19
+ if (typeof item != "object" || !item || ArrayIsArray(item)) throw Error(`\`extends[${i}]\` must be a config object (strings/paths are not supported).`);
20
+ let itemPath = `${path}.extends[${i}]`;
21
+ if (inStack.has(item)) {
22
+ let idx = stackObjects.indexOf(item), cycleStart = idx === -1 ? "<unknown>" : stackPaths[idx];
23
+ throw Error(formatCycleError(itemPath, cycleStart, idx));
24
+ }
25
+ visit(item, itemPath);
26
+ }
27
+ }
28
+ inStack.delete(config), stackObjects.pop(), stackPaths.pop(), visited.add(config);
29
+ };
30
+ visit(root, "<root>");
31
+ }
32
+ /**
33
+ * Load JavaScript config files in parallel.
34
+ *
35
+ * Uses native Node.js TypeScript support to import the config files.
36
+ * Each config file should have a default export containing the oxlint configuration.
37
+ *
38
+ * @param paths - Array of absolute paths to JavaScript/TypeScript config files
39
+ * @returns JSON-stringified result with all configs or error
40
+ */
41
+ async function loadJsConfigs(paths) {
42
+ try {
43
+ let cacheKey = DateNow(), results = await Promise.allSettled(paths.map(async (path) => {
44
+ let config = (await import(new URL(`file://${path}?cache=${cacheKey}`).href)).default;
45
+ if (config === void 0) throw Error("Configuration file has no default export.");
46
+ if (typeof config != "object" || !config || ArrayIsArray(config)) throw Error("Configuration file must have a default export that is an object.");
47
+ if (!isDefineConfig(config)) throw Error("Configuration file must wrap its default export with defineConfig() from \"oxlint\".");
48
+ return validateConfigExtends(config), {
49
+ path,
50
+ config
51
+ };
52
+ })), successes = [], errors = [];
53
+ for (let i = 0; i < results.length; i++) {
54
+ let result = results[i];
55
+ result.status === "fulfilled" ? successes.push(result.value) : errors.push({
56
+ path: paths[i],
57
+ error: getErrorMessage(result.reason)
58
+ });
59
+ }
60
+ return errors.length > 0 ? JSONStringify({ Failures: errors }) : JSONStringify({ Success: successes });
61
+ } catch (err) {
62
+ return JSONStringify({ Error: getErrorMessage(err) });
63
+ }
64
+ }
65
+ //#endregion
66
+ export { loadJsConfigs };