uilint 0.2.145 → 0.2.146

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.
@@ -4161,9 +4161,10 @@ function Spinner() {
4161
4161
 
4162
4162
  export {
4163
4163
  Spinner,
4164
+ registerInstaller,
4164
4165
  getAllInstallers,
4165
4166
  analyze,
4166
4167
  execute,
4167
4168
  getInjectionPoints
4168
4169
  };
4169
- //# sourceMappingURL=chunk-ZUOFUPGT.js.map
4170
+ //# sourceMappingURL=chunk-5EDE3J6O.js.map
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ logInfo
4
+ } from "./chunk-CZNPG4UI.js";
5
+
6
+ // src/utils/plugin-loader.ts
7
+ import { createRequire } from "module";
8
+ import { existsSync, readFileSync } from "fs";
9
+ import { join } from "path";
10
+ import { pathToFileURL } from "url";
11
+ var KNOWN_PLUGIN_PACKAGES = ["uilint-vision", "uilint-semantic", "uilint-duplicates"];
12
+ async function importFromProject(specifier, projectPath) {
13
+ try {
14
+ const req = createRequire(join(projectPath, "package.json"));
15
+ const resolved = req.resolve(specifier);
16
+ return await import(resolved);
17
+ } catch {
18
+ }
19
+ const slashIdx = specifier.indexOf("/");
20
+ if (slashIdx === -1) return void 0;
21
+ const pkgName = specifier.slice(0, slashIdx);
22
+ const subpath = `./${specifier.slice(slashIdx + 1)}`;
23
+ const pkgDir = join(projectPath, "node_modules", pkgName);
24
+ const pkgJsonPath = join(pkgDir, "package.json");
25
+ if (!existsSync(pkgJsonPath)) return void 0;
26
+ const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
27
+ const exportEntry = pkgJson.exports?.[subpath];
28
+ if (!exportEntry) return void 0;
29
+ const importPath = typeof exportEntry === "string" ? exportEntry : exportEntry.import ?? exportEntry.default;
30
+ if (!importPath) return void 0;
31
+ const fullPath = join(pkgDir, importPath);
32
+ if (!existsSync(fullPath)) return void 0;
33
+ return await import(pathToFileURL(fullPath).href);
34
+ }
35
+ async function discoverPlugins(resolveFrom) {
36
+ const manifests = [];
37
+ for (const pkg of KNOWN_PLUGIN_PACKAGES) {
38
+ const specifier = `${pkg}/cli-manifest`;
39
+ try {
40
+ let mod;
41
+ if (resolveFrom) {
42
+ mod = await importFromProject(specifier, resolveFrom);
43
+ } else {
44
+ mod = await import(specifier);
45
+ }
46
+ if (mod?.cliManifest) {
47
+ manifests.push(mod.cliManifest);
48
+ }
49
+ } catch {
50
+ }
51
+ }
52
+ return manifests;
53
+ }
54
+ async function loadPluginESLintRules(manifests, resolveFrom) {
55
+ const loaded = [];
56
+ for (const manifest of manifests) {
57
+ try {
58
+ await import(manifest.registerSpecifier);
59
+ loaded.push(manifest.packageName);
60
+ } catch {
61
+ if (resolveFrom) {
62
+ try {
63
+ await importFromProject(manifest.registerSpecifier, resolveFrom);
64
+ loaded.push(manifest.packageName);
65
+ } catch {
66
+ }
67
+ }
68
+ }
69
+ }
70
+ if (loaded.length > 0) {
71
+ logInfo(`Loaded plugin rules: ${loaded.join(", ")}`);
72
+ }
73
+ return loaded;
74
+ }
75
+
76
+ export {
77
+ discoverPlugins,
78
+ loadPluginESLintRules
79
+ };
80
+ //# sourceMappingURL=chunk-5QUW7BNW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/plugin-loader.ts"],"sourcesContent":["/**\n * Dynamic plugin loader for the CLI.\n *\n * Probes known plugin package names for a `cli-manifest` subpath export.\n * Each manifest describes the CLI flag, help text, and registration entry\n * point, keeping the core CLI free of plugin-specific knowledge.\n */\n\nimport { createRequire } from \"module\";\nimport { existsSync, readFileSync } from \"fs\";\nimport { join } from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { logInfo } from \"./prompts.js\";\n\n/**\n * Metadata a plugin exposes via its `<pkg>/cli-manifest` subpath export.\n * Plugins define a plain object matching this shape — no shared type import needed.\n */\nexport interface PluginCLIManifest {\n /** npm package name, e.g. \"uilint-vision\" */\n packageName: string;\n /** CLI flag name (without --), e.g. \"vision\" */\n cliFlag: string;\n /** Description shown in --help */\n cliDescription: string;\n /** Import specifier for the register module, e.g. \"uilint-vision/eslint-rules/register\" */\n registerSpecifier: string;\n /** Display name shown in the interactive install UI, e.g. \"Vision Analysis\" */\n displayName: string;\n /** Description shown in the interactive install UI */\n displayDescription: string;\n /** Emoji icon for the interactive install UI, e.g. \"👁️\" */\n displayIcon: string;\n}\n\n/** Package names to probe for CLI manifests */\nconst KNOWN_PLUGIN_PACKAGES = [\"uilint-vision\", \"uilint-semantic\", \"uilint-duplicates\"];\n\n/**\n * Resolve and import a package subpath specifier from a given project directory.\n *\n * First tries CJS `createRequire().resolve()`, which works for packages with\n * a `\"require\"` export condition. If that fails (e.g. the package only defines\n * `\"import\"`), falls back to manually reading the package's `exports` map and\n * constructing a file URL.\n */\nasync function importFromProject(\n specifier: string,\n projectPath: string,\n): Promise<unknown> {\n // Try CJS resolution first (fast path)\n try {\n const req = createRequire(join(projectPath, \"package.json\"));\n const resolved = req.resolve(specifier);\n return await import(resolved);\n } catch {\n // CJS resolution failed — try ESM-only export resolution\n }\n\n // Parse \"pkg/subpath\" → [\"pkg\", \"./subpath\"]\n const slashIdx = specifier.indexOf(\"/\");\n if (slashIdx === -1) return undefined;\n const pkgName = specifier.slice(0, slashIdx);\n const subpath = `./${specifier.slice(slashIdx + 1)}`;\n\n const pkgDir = join(projectPath, \"node_modules\", pkgName);\n const pkgJsonPath = join(pkgDir, \"package.json\");\n if (!existsSync(pkgJsonPath)) return undefined;\n\n const pkgJson = JSON.parse(readFileSync(pkgJsonPath, \"utf8\"));\n const exportEntry = pkgJson.exports?.[subpath];\n if (!exportEntry) return undefined;\n\n const importPath =\n typeof exportEntry === \"string\"\n ? exportEntry\n : exportEntry.import ?? exportEntry.default;\n if (!importPath) return undefined;\n\n const fullPath = join(pkgDir, importPath);\n if (!existsSync(fullPath)) return undefined;\n\n return await import(pathToFileURL(fullPath).href);\n}\n\n/**\n * Discover available plugin manifests by probing `<pkg>/cli-manifest`.\n *\n * @param resolveFrom - Optional project path to resolve plugins from.\n * When provided, resolves plugins from the project's node_modules\n * so plugins installed in the project can be found.\n * @returns Array of discovered plugin manifests\n */\nexport async function discoverPlugins(\n resolveFrom?: string,\n): Promise<PluginCLIManifest[]> {\n const manifests: PluginCLIManifest[] = [];\n\n for (const pkg of KNOWN_PLUGIN_PACKAGES) {\n const specifier = `${pkg}/cli-manifest`;\n try {\n let mod: { cliManifest?: PluginCLIManifest } | undefined;\n if (resolveFrom) {\n mod = (await importFromProject(specifier, resolveFrom)) as typeof mod;\n } else {\n mod = (await import(specifier)) as typeof mod;\n }\n if (mod?.cliManifest) {\n manifests.push(mod.cliManifest);\n }\n } catch {\n // Plugin not installed — skip silently\n }\n }\n\n return manifests;\n}\n\n/**\n * Load ESLint rules from discovered plugins by importing their register modules.\n *\n * The register modules call `registerRuleMeta()` from `uilint-eslint`, which\n * mutates the shared `ruleRegistry` array. To avoid the dual-package problem\n * (project-resolved plugin getting a different `uilint-eslint` instance), we\n * always try a bare `import()` first — this resolves from the CLI's own\n * context so both the CLI and the plugin share the same `ruleRegistry`.\n * Only falls back to project-scoped resolution when the bare import fails\n * (e.g. when running via `npx` where plugins aren't alongside the CLI).\n *\n * @param manifests - Plugin manifests (from discoverPlugins)\n * @param resolveFrom - Optional project path to resolve plugins from.\n * @returns Array of loaded plugin package names\n */\nexport async function loadPluginESLintRules(\n manifests: PluginCLIManifest[],\n resolveFrom?: string,\n): Promise<string[]> {\n const loaded: string[] = [];\n\n for (const manifest of manifests) {\n try {\n // Prefer bare import so the register module shares the CLI's uilint-eslint\n await import(manifest.registerSpecifier);\n loaded.push(manifest.packageName);\n } catch {\n // Bare import failed — try from consumer project if a path was provided\n if (resolveFrom) {\n try {\n await importFromProject(manifest.registerSpecifier, resolveFrom);\n loaded.push(manifest.packageName);\n } catch {\n // Plugin register module not available — skip silently\n }\n }\n }\n }\n\n if (loaded.length > 0) {\n logInfo(`Loaded plugin rules: ${loaded.join(\", \")}`);\n }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