@axe-core/puppeteer 4.7.1-alpha.383 → 4.7.1-alpha.384

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
@@ -76,6 +76,47 @@ function chunkResultString(chunk) {
76
76
 
77
77
  // src/legacy.ts
78
78
  var fs = __toESM(require("fs"));
79
+
80
+ // node_modules/cross-dirname/dist/esm/index.mjs
81
+ var EXTRACT_PATH_REGEX = /@?(?<path>[file:\/\/]?[^\(\s]+):[0-9]+:[0-9]+/;
82
+ var WIN_POSIX_DRIVE_REGEX = /^\/[A-Z]:\/*/;
83
+ var getPathFromErrorStack = () => {
84
+ let path = "";
85
+ const stack = new Error().stack;
86
+ if (!stack) {
87
+ console.warn("Error has no stack!");
88
+ return path;
89
+ }
90
+ let initiator = stack.split("\n").slice(4, 5)[0];
91
+ if (!initiator) {
92
+ initiator = stack.split("\n").slice(3, 4)[0];
93
+ }
94
+ if (initiator) {
95
+ path = EXTRACT_PATH_REGEX.exec(initiator)?.groups?.path || "";
96
+ }
97
+ if (!initiator || !path) {
98
+ console.warn("Can't get path from error stack!");
99
+ }
100
+ return path;
101
+ };
102
+ var getPath = () => {
103
+ let path = getPathFromErrorStack();
104
+ const protocol = "file://";
105
+ if (path.indexOf(protocol) >= 0) {
106
+ path = path.slice(protocol.length);
107
+ }
108
+ if (WIN_POSIX_DRIVE_REGEX.test(path)) {
109
+ path = path.slice(1).replace(/\//g, "\\");
110
+ }
111
+ return path;
112
+ };
113
+ var getFilename = () => {
114
+ let filename = getPath();
115
+ return filename;
116
+ };
117
+
118
+ // src/legacy.ts
119
+ var import_url = require("url");
79
120
  async function injectJS(frame, { source, selector, logOnError, args }) {
80
121
  if (!frame) {
81
122
  return;
@@ -108,7 +149,16 @@ async function injectJS(frame, { source, selector, logOnError, args }) {
108
149
  return Promise.all(injections).then(() => void 0);
109
150
  }
110
151
  async function injectJSModule(frame) {
111
- const source = fs.readFileSync(require.resolve("axe-core"), "utf8");
152
+ let axeCorePath = "";
153
+ if (typeof require === "function" && typeof require.resolve === "function") {
154
+ axeCorePath = require.resolve("axe-core");
155
+ } else {
156
+ const { createRequire } = await import("module");
157
+ const filename = (0, import_url.pathToFileURL)(getFilename()).toString();
158
+ const require2 = createRequire(filename);
159
+ axeCorePath = require2.resolve("axe-core");
160
+ }
161
+ const source = fs.readFileSync(axeCorePath, "utf8");
112
162
  await injectJSSource(frame, source);
113
163
  }
114
164
  function injectJSSource(frame, source, args = []) {
@@ -156,11 +206,20 @@ var caught = ((f) => {
156
206
 
157
207
  // src/utils.ts
158
208
  var fs2 = __toESM(require("fs"));
209
+ var import_url2 = require("url");
159
210
  async function frameSourceInject(frame, source, config) {
160
211
  await assertFrameReady(frame);
161
212
  if (!source) {
162
- const pathFile = require.resolve("axe-core");
163
- source = fs2.readFileSync(pathFile, "utf8");
213
+ let axeCorePath = "";
214
+ if (typeof require === "function" && typeof require.resolve === "function") {
215
+ axeCorePath = require.resolve("axe-core");
216
+ } else {
217
+ const { createRequire } = await import("module");
218
+ const filename = (0, import_url2.pathToFileURL)(getFilename()).toString();
219
+ const require2 = createRequire(filename);
220
+ axeCorePath = require2.resolve("axe-core");
221
+ }
222
+ source = fs2.readFileSync(axeCorePath, "utf8");
164
223
  }
165
224
  await frame.evaluate(source);
166
225
  await frame.evaluate(axeConfigure, config);
package/dist/index.mjs CHANGED
@@ -46,6 +46,47 @@ function chunkResultString(chunk) {
46
46
 
47
47
  // src/legacy.ts
48
48
  import * as fs from "fs";
49
+
50
+ // node_modules/cross-dirname/dist/esm/index.mjs
51
+ var EXTRACT_PATH_REGEX = /@?(?<path>[file:\/\/]?[^\(\s]+):[0-9]+:[0-9]+/;
52
+ var WIN_POSIX_DRIVE_REGEX = /^\/[A-Z]:\/*/;
53
+ var getPathFromErrorStack = () => {
54
+ let path = "";
55
+ const stack = new Error().stack;
56
+ if (!stack) {
57
+ console.warn("Error has no stack!");
58
+ return path;
59
+ }
60
+ let initiator = stack.split("\n").slice(4, 5)[0];
61
+ if (!initiator) {
62
+ initiator = stack.split("\n").slice(3, 4)[0];
63
+ }
64
+ if (initiator) {
65
+ path = EXTRACT_PATH_REGEX.exec(initiator)?.groups?.path || "";
66
+ }
67
+ if (!initiator || !path) {
68
+ console.warn("Can't get path from error stack!");
69
+ }
70
+ return path;
71
+ };
72
+ var getPath = () => {
73
+ let path = getPathFromErrorStack();
74
+ const protocol = "file://";
75
+ if (path.indexOf(protocol) >= 0) {
76
+ path = path.slice(protocol.length);
77
+ }
78
+ if (WIN_POSIX_DRIVE_REGEX.test(path)) {
79
+ path = path.slice(1).replace(/\//g, "\\");
80
+ }
81
+ return path;
82
+ };
83
+ var getFilename = () => {
84
+ let filename = getPath();
85
+ return filename;
86
+ };
87
+
88
+ // src/legacy.ts
89
+ import { pathToFileURL } from "url";
49
90
  async function injectJS(frame, { source, selector, logOnError, args }) {
50
91
  if (!frame) {
51
92
  return;
@@ -78,7 +119,16 @@ async function injectJS(frame, { source, selector, logOnError, args }) {
78
119
  return Promise.all(injections).then(() => void 0);
79
120
  }
80
121
  async function injectJSModule(frame) {
81
- const source = fs.readFileSync(__require.resolve("axe-core"), "utf8");
122
+ let axeCorePath = "";
123
+ if (typeof __require === "function" && typeof __require.resolve === "function") {
124
+ axeCorePath = __require.resolve("axe-core");
125
+ } else {
126
+ const { createRequire } = await import("node:module");
127
+ const filename = pathToFileURL(getFilename()).toString();
128
+ const require2 = createRequire(filename);
129
+ axeCorePath = require2.resolve("axe-core");
130
+ }
131
+ const source = fs.readFileSync(axeCorePath, "utf8");
82
132
  await injectJSSource(frame, source);
83
133
  }
84
134
  function injectJSSource(frame, source, args = []) {
@@ -126,11 +176,20 @@ var caught = ((f) => {
126
176
 
127
177
  // src/utils.ts
128
178
  import * as fs2 from "fs";
179
+ import { pathToFileURL as pathToFileURL2 } from "url";
129
180
  async function frameSourceInject(frame, source, config) {
130
181
  await assertFrameReady(frame);
131
182
  if (!source) {
132
- const pathFile = __require.resolve("axe-core");
133
- source = fs2.readFileSync(pathFile, "utf8");
183
+ let axeCorePath = "";
184
+ if (typeof __require === "function" && typeof __require.resolve === "function") {
185
+ axeCorePath = __require.resolve("axe-core");
186
+ } else {
187
+ const { createRequire } = await import("node:module");
188
+ const filename = pathToFileURL2(getFilename()).toString();
189
+ const require2 = createRequire(filename);
190
+ axeCorePath = require2.resolve("axe-core");
191
+ }
192
+ source = fs2.readFileSync(axeCorePath, "utf8");
134
193
  }
135
194
  await frame.evaluate(source);
136
195
  await frame.evaluate(axeConfigure, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axe-core/puppeteer",
3
- "version": "4.7.1-alpha.383+aa12d43",
3
+ "version": "4.7.1-alpha.384+f2a41bc",
4
4
  "description": "Provides a chainable axe API for Puppeteer and automatically injects into all frames",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,6 +40,7 @@
40
40
  "@types/test-listen": "^1.1.0",
41
41
  "axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1",
42
42
  "chai": "^4.3.6",
43
+ "cross-dirname": "^0.1.0",
43
44
  "express": "^4.18.2",
44
45
  "mocha": "^10.0.0",
45
46
  "nyc": "^15.1.0",
@@ -87,5 +88,5 @@
87
88
  "functions": 85,
88
89
  "lines": 85
89
90
  },
90
- "gitHead": "aa12d43cc3670b9aa9b4db80f4bb5251a032c171"
91
+ "gitHead": "f2a41bcaf33f5000fa1cd08f1a3e184b5d6360be"
91
92
  }