oxlint-react-compiler-experimental 0.0.6 → 0.1.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 CHANGED
@@ -1,2 +1,12 @@
1
- import { t as defineConfig } from "./config.js";
1
+ //#region src-js/package/config.ts
2
+ /**
3
+ * Define an Oxlint configuration with type inference.
4
+ *
5
+ * @param config - Oxlint configuration
6
+ * @returns Config unchanged
7
+ */
8
+ function defineConfig(config) {
9
+ return config;
10
+ }
11
+ //#endregion
2
12
  export { defineConfig };
package/dist/js_config.js CHANGED
@@ -1,6 +1,36 @@
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";
1
+ import { a as JSONStringify, n as ArrayIsArray, r as DateNow } from "./globals.js";
2
+ import { t as getErrorMessage } from "./utils.js";
3
+ import { extname } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ //#region src-js/utils/node_version.ts
6
+ const TS_MODULE_EXTENSIONS = new Set([
7
+ ".ts",
8
+ ".mts",
9
+ ".cts"
10
+ ]);
11
+ function normalizeModuleSpecifierPath(specifier) {
12
+ if (!specifier.startsWith("file:")) return specifier;
13
+ try {
14
+ return fileURLToPath(specifier);
15
+ } catch {
16
+ return specifier;
17
+ }
18
+ }
19
+ function isTypeScriptModuleSpecifier(specifier) {
20
+ let ext = extname(normalizeModuleSpecifierPath(specifier)).toLowerCase();
21
+ return TS_MODULE_EXTENSIONS.has(ext);
22
+ }
23
+ function isUnknownFileExtensionError(err) {
24
+ if (err?.code === "ERR_UNKNOWN_FILE_EXTENSION") return !0;
25
+ let message = err?.message;
26
+ return typeof message == "string" && /unknown(?: or unsupported)? file extension/i.test(message);
27
+ }
28
+ function getUnsupportedTypeScriptModuleLoadHintForError(err, specifier, nodeVersion = process.version) {
29
+ return !isTypeScriptModuleSpecifier(specifier) || !isUnknownFileExtensionError(err) ? null : `${getErrorMessage(err)}\n\nTypeScript config files require Node.js ^20.19.0 || >=22.18.0.\nDetected Node.js ${nodeVersion}.\nPlease upgrade Node.js or use a JSON config file instead.`;
30
+ }
31
+ //#endregion
3
32
  //#region src-js/js_config.ts
33
+ const isObject = (v) => typeof v == "object" && !!v && !ArrayIsArray(v);
4
34
  function validateConfigExtends(root) {
5
35
  let visited = /* @__PURE__ */ new WeakSet(), inStack = /* @__PURE__ */ new WeakSet(), stackObjects = [], stackPaths = [], formatCycleError = (refPath, cycleStart, idx) => `\`extends\` contains a circular reference.
6
36
 
@@ -16,7 +46,7 @@ ${refPath} points back to ${cycleStart}\nCycle: ${idx === -1 ? `${cycleStart} ->
16
46
  if (!ArrayIsArray(maybeExtends)) throw Error("`extends` must be an array of config objects (strings/paths are not supported).");
17
47
  for (let i = 0; i < maybeExtends.length; i++) {
18
48
  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).`);
49
+ if (!isObject(item)) throw Error(`\`extends[${i}]\` must be a config object (strings/paths are not supported).`);
20
50
  let itemPath = `${path}.extends[${i}]`;
21
51
  if (inStack.has(item)) {
22
52
  let idx = stackObjects.indexOf(item), cycleStart = idx === -1 ? "<unknown>" : stackPaths[idx];
@@ -30,37 +60,72 @@ ${refPath} points back to ${cycleStart}\nCycle: ${idx === -1 ? `${cycleStart} ->
30
60
  visit(root, "<root>");
31
61
  }
32
62
  /**
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
63
+ * Import a JS/TS config file and return its default export.
64
+ */
65
+ async function importConfig(path, cacheKey) {
66
+ let config = (await import(new URL(`file://${path}?cache=${cacheKey}`).href)).default;
67
+ if (config === void 0) throw Error("Configuration file has no default export.");
68
+ return config;
69
+ }
70
+ /**
71
+ * Resolve a single config path to a `JsConfigResult`.
72
+ * Standard mode: default export must be a plain object.
40
73
  */
41
- async function loadJsConfigs(paths) {
74
+ async function resolveJsConfig(path, cacheKey) {
75
+ let config = await importConfig(path, cacheKey);
76
+ if (!isObject(config)) throw Error("Configuration file must have a default export that is an object.");
77
+ return validateConfigExtends(config), {
78
+ path,
79
+ config
80
+ };
81
+ }
82
+ const VITE_OXLINT_CONFIG_FIELD = "lint";
83
+ /**
84
+ * Resolve a single Vite+ config path to a `JsConfigResult`.
85
+ * Extracts the `.lint` field. Returns `null` config when missing (signals "skip").
86
+ */
87
+ async function resolveVitePlusConfig(path, cacheKey) {
88
+ let config = await importConfig(path, cacheKey);
89
+ if (!isObject(config)) return {
90
+ path,
91
+ config: null
92
+ };
93
+ let lintConfig = config[VITE_OXLINT_CONFIG_FIELD];
94
+ if (lintConfig === void 0) return {
95
+ path,
96
+ config: null
97
+ };
98
+ if (!isObject(lintConfig)) throw Error(`The \`${VITE_OXLINT_CONFIG_FIELD}\` field in the default export must be an object.`);
99
+ return validateConfigExtends(lintConfig), {
100
+ path,
101
+ config: lintConfig
102
+ };
103
+ }
104
+ /**
105
+ * Load config files in parallel using the given resolver, and return JSON-stringified result.
106
+ */
107
+ async function loadConfigs(paths, resolver) {
42
108
  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 = [];
109
+ let cacheKey = DateNow(), results = await Promise.allSettled(paths.map((path) => resolver(path, cacheKey))), successes = [], errors = [];
53
110
  for (let i = 0; i < results.length; i++) {
54
111
  let result = results[i];
55
- result.status === "fulfilled" ? successes.push(result.value) : errors.push({
56
- path: paths[i],
57
- error: getErrorMessage(result.reason)
58
- });
112
+ if (result.status === "fulfilled") successes.push(result.value);
113
+ else {
114
+ let path = paths[i], unsupportedNodeHint = getUnsupportedTypeScriptModuleLoadHintForError(result.reason, path);
115
+ errors.push({
116
+ path,
117
+ error: unsupportedNodeHint ?? getErrorMessage(result.reason)
118
+ });
119
+ }
59
120
  }
60
121
  return errors.length > 0 ? JSONStringify({ Failures: errors }) : JSONStringify({ Success: successes });
61
122
  } catch (err) {
62
123
  return JSONStringify({ Error: getErrorMessage(err) });
63
124
  }
64
125
  }
126
+ /**
127
+ * Load standard oxlint JS/TS config files in parallel.
128
+ */
129
+ const loadJsConfigs = (paths) => loadConfigs(paths, resolveJsConfig), loadVitePlusConfigs = (paths) => loadConfigs(paths, resolveVitePlusConfig);
65
130
  //#endregion
66
- export { loadJsConfigs };
131
+ export { loadJsConfigs, loadVitePlusConfigs };