@diegovelasquezweb/a11y-engine 0.2.1 → 0.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegovelasquezweb/a11y-engine",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "WCAG 2.2 AA accessibility audit engine — scanner, analyzer, and report builders",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,7 +16,8 @@
16
16
  ".": {
17
17
  "types": "./scripts/index.d.mts",
18
18
  "default": "./scripts/index.mjs"
19
- }
19
+ },
20
+ "./package.json": "./package.json"
20
21
  },
21
22
  "main": "scripts/index.mjs",
22
23
  "types": "scripts/index.d.mts",
@@ -6,9 +6,44 @@
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
+ import { createRequire } from "node:module";
9
10
 
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
- const ASSET_ROOT = path.join(__dirname, "..", "..", "assets");
11
+ /**
12
+ * Resolves the assets root directory. Uses import.meta.url when running from
13
+ * the original file location (CLI, direct node). Falls back to multiple
14
+ * strategies when running inside a bundler (e.g. Turbopack) where
15
+ * import.meta.url points to a generated chunk.
16
+ */
17
+ function resolveAssetRoot() {
18
+ // Primary: resolve relative to this file's location
19
+ try {
20
+ const selfDir = path.dirname(fileURLToPath(import.meta.url));
21
+ const candidate = path.join(selfDir, "..", "..", "assets");
22
+ if (fs.existsSync(candidate)) return candidate;
23
+ } catch { /* import.meta.url might be a virtual URL in bundlers */ }
24
+
25
+ // Fallback 1: require.resolve with createRequire from process.cwd()
26
+ try {
27
+ const req = createRequire(path.join(process.cwd(), "package.json"));
28
+ const pkgJson = req.resolve("@diegovelasquezweb/a11y-engine/package.json");
29
+ const fallback = path.join(path.dirname(pkgJson), "assets");
30
+ if (fs.existsSync(fallback)) return fallback;
31
+ } catch { /* package not installed or exports block it */ }
32
+
33
+ // Fallback 2: walk node_modules directly (handles pnpm symlinks)
34
+ try {
35
+ const nmBase = path.join(process.cwd(), "node_modules", "@diegovelasquezweb", "a11y-engine");
36
+ const realBase = fs.realpathSync(nmBase);
37
+ const fallback = path.join(realBase, "assets");
38
+ if (fs.existsSync(fallback)) return fallback;
39
+ } catch { /* not in node_modules */ }
40
+
41
+ // Last resort: relative to this file (will fail with a clear error at load time)
42
+ const selfDir = path.dirname(fileURLToPath(import.meta.url));
43
+ return path.join(selfDir, "..", "..", "assets");
44
+ }
45
+
46
+ const ASSET_ROOT = resolveAssetRoot();
12
47
 
13
48
  export const ASSET_PATHS = {
14
49
  discovery: {