wcag-scanner 1.2.3 → 1.2.5

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/scanner.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare class WCAGScanner {
18
18
  * Load HTML content for scanning
19
19
  * @param html HTML content to scan
20
20
  * @param baseUrl Base URL for relative paths
21
- * @param Promise<boolean> True if loaded sucessfully
21
+ * @returns Promise<boolean> True if loaded successfully
22
22
  */
23
23
  loadHTML(html: string, baseUrl?: string): Promise<boolean>;
24
24
  /**
@@ -38,7 +38,7 @@ export declare class WCAGScanner {
38
38
  scan(): Promise<ScanResults>;
39
39
  /**
40
40
  * Get the scan results
41
- * @return ScanResults Current scan results
41
+ * @returns ScanResults Current scan results
42
42
  */
43
43
  getResults(): ScanResults;
44
44
  }
package/dist/scanner.js CHANGED
@@ -33,30 +33,41 @@ class WCAGScanner {
33
33
  * Load HTML content for scanning
34
34
  * @param html HTML content to scan
35
35
  * @param baseUrl Base URL for relative paths
36
- * @param Promise<boolean> True if loaded sucessfully
36
+ * @returns Promise<boolean> True if loaded successfully
37
37
  */
38
38
  async loadHTML(html, baseUrl = 'https://example.org') {
39
39
  try {
40
+ // Create virtual DOM with robust error handling
40
41
  this.dom = new jsdom_1.JSDOM(html, {
41
42
  url: baseUrl,
42
43
  resources: 'usable',
43
44
  runScripts: 'dangerously',
44
45
  beforeParse(window) {
46
+ // Silence script errors
45
47
  window.addEventListener('error', (event) => {
46
48
  console.log(`Ignored script error: ${event.message}`);
47
49
  event.preventDefault();
48
50
  });
49
- // Mock modern browser APIs if needed
51
+ // Mock modern browser APIs that may be missing in JSDOM
50
52
  if (!window.ReadableStream) {
51
53
  window.ReadableStream = class MockReadableStream {
52
54
  constructor() { }
53
- getReader() { return { read: () => { } }; }
55
+ getReader() { return { read: () => Promise.resolve({ done: true, value: undefined }) }; }
54
56
  };
55
57
  }
58
+ // Additional mock APIs that might be needed
59
+ if (!window.fetch) {
60
+ window.fetch = () => Promise.resolve({
61
+ ok: true,
62
+ json: () => Promise.resolve({}),
63
+ text: () => Promise.resolve("")
64
+ });
65
+ }
56
66
  }
57
67
  });
58
68
  this.document = this.dom.window.document;
59
69
  this.window = this.dom.window;
70
+ // Wait for resources to load
60
71
  await new Promise(resolve => setTimeout(resolve, 100));
61
72
  return true;
62
73
  }
@@ -82,34 +93,41 @@ class WCAGScanner {
82
93
  * Load built-in rules
83
94
  */
84
95
  async loadRules() {
85
- // Skip this process if running from the declaration files
86
- if (__filename.endsWith(".d.ts"))
87
- return;
88
96
  try {
89
97
  const rulesDir = path_1.default.join(__dirname, 'rules');
90
- // Skip in a test environment
98
+ // Skip if directory doesn't exist
91
99
  if (!fs_1.default.existsSync(rulesDir))
92
100
  return;
101
+ // IMPORTANT FIX: Only load JavaScript files, explicitly exclude declaration files
93
102
  const ruleFiles = fs_1.default.readdirSync(rulesDir)
94
- .filter(file => file.endsWith('.js') || file.endsWith('.d.ts'));
103
+ .filter(file => {
104
+ // Only include .js files that aren't declaration files
105
+ return file.endsWith('.js') &&
106
+ !file.endsWith('.d.js') &&
107
+ !file.includes('.d.ts');
108
+ });
95
109
  for (const file of ruleFiles) {
96
110
  try {
97
- const ruleName = path_1.default.basename(file, '.js');
111
+ const ruleName = path_1.default.basename(file, path_1.default.extname(file));
98
112
  const rulePath = path_1.default.join(rulesDir, file);
99
- // Import the rule module properly
113
+ // Import the rule module
100
114
  const ruleModule = require(rulePath);
101
115
  const rule = ruleModule.default || ruleModule;
102
116
  if (rule && typeof rule.check === 'function') {
103
117
  this.registerRule(ruleName, rule);
104
118
  }
119
+ else {
120
+ console.log(`Skipping rule ${ruleName}: Invalid format`);
121
+ }
105
122
  }
106
123
  catch (error) {
107
124
  console.error(`Error loading rule from ${file}:`, error);
125
+ // Continue with other rules
108
126
  }
109
127
  }
110
128
  }
111
129
  catch (error) {
112
- console.error('Error loading rules:', error);
130
+ console.error('Error loading rules directory:', error);
113
131
  }
114
132
  }
115
133
  /**
@@ -125,7 +143,7 @@ class WCAGScanner {
125
143
  violations: [],
126
144
  warnings: []
127
145
  };
128
- // Load rules if not already loaded.
146
+ // Load rules if not already loaded
129
147
  if (this.rules.size === 0) {
130
148
  await this.loadRules();
131
149
  }
@@ -137,9 +155,9 @@ class WCAGScanner {
137
155
  try {
138
156
  const ruleResults = await rule.check(this.document, this.window, this.options);
139
157
  // Merge results
140
- this.results.passes.push(...ruleResults.passes);
141
- this.results.violations.push(...ruleResults.violations);
142
- this.results.warnings.push(...ruleResults.warnings);
158
+ this.results.passes.push(...(ruleResults.passes || []));
159
+ this.results.violations.push(...(ruleResults.violations || []));
160
+ this.results.warnings.push(...(ruleResults.warnings || []));
143
161
  }
144
162
  catch (error) {
145
163
  console.error(`Error running rule ${ruleName}:`, error);
@@ -150,7 +168,7 @@ class WCAGScanner {
150
168
  }
151
169
  /**
152
170
  * Get the scan results
153
- * @return ScanResults Current scan results
171
+ * @returns ScanResults Current scan results
154
172
  */
155
173
  getResults() {
156
174
  return this.results;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wcag-scanner",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Scan HTML for WCAG accessibility violations with AI-powered fix suggestions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",