@percy/core 1.30.6 → 1.30.7-beta.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.
Files changed (2) hide show
  1. package/dist/api.js +21 -4
  2. package/package.json +8 -8
package/dist/api.js CHANGED
@@ -1,13 +1,30 @@
1
1
  import fs from 'fs';
2
- import path from 'path';
3
- import { createRequire } from 'module';
2
+ import path, { dirname, resolve } from 'path';
4
3
  import logger from '@percy/logger';
5
4
  import { normalize } from '@percy/config/utils';
6
5
  import { getPackageJSON, Server, percyAutomateRequestHandler, percyBuildEventHandler } from './utils.js';
7
6
  import WebdriverUtils from '@percy/webdriver-utils';
8
7
  import { handleSyncJob } from './snapshot.js';
9
- // need require.resolve until import.meta.resolve can be transpiled
10
- export const PERCY_DOM = createRequire(import.meta.url).resolve('@percy/dom');
8
+ // Previously, we used `createRequire(import.meta.url).resolve` to resolve the path to the module.
9
+ // This approach relied on `createRequire`, which is Node.js-specific and less compatible with modern ESM (ECMAScript Module) standards.
10
+ // This was leading to hard coded paths when CLI is used as a dependency in another project.
11
+ // Now, we use `fileURLToPath` and `path.resolve` to determine the absolute path in a way that's more aligned with ESM conventions.
12
+ // This change ensures better compatibility and avoids relying on Node.js-specific APIs that might cause issues in ESM environments.
13
+ import { fileURLToPath } from 'url';
14
+ import { createRequire } from 'module';
15
+ export const getPercyDomPath = url => {
16
+ try {
17
+ return createRequire(url).resolve('@percy/dom');
18
+ } catch (error) {
19
+ logger('core:server').warn(['Failed to resolve @percy/dom path using createRequire.', 'Falling back to using fileURLToPath and path.resolve.'].join(' '));
20
+ }
21
+ const __filename = fileURLToPath(import.meta.url);
22
+ const __dirname = dirname(__filename);
23
+ return resolve(__dirname, 'node_modules/@percy/dom');
24
+ };
25
+
26
+ // Resolved path for PERCY_DOM
27
+ export const PERCY_DOM = getPercyDomPath(import.meta.url);
11
28
 
12
29
  // Returns a URL encoded string of nested query params
13
30
  function encodeURLSearchParams(subj, prefix) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.30.6",
3
+ "version": "1.30.7-beta.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public",
12
- "tag": "latest"
12
+ "tag": "beta"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=14"
@@ -43,11 +43,11 @@
43
43
  "test:types": "tsd"
44
44
  },
45
45
  "dependencies": {
46
- "@percy/client": "1.30.6",
47
- "@percy/config": "1.30.6",
48
- "@percy/dom": "1.30.6",
49
- "@percy/logger": "1.30.6",
50
- "@percy/webdriver-utils": "1.30.6",
46
+ "@percy/client": "1.30.7-beta.0",
47
+ "@percy/config": "1.30.7-beta.0",
48
+ "@percy/dom": "1.30.7-beta.0",
49
+ "@percy/logger": "1.30.7-beta.0",
50
+ "@percy/webdriver-utils": "1.30.7-beta.0",
51
51
  "content-disposition": "^0.5.4",
52
52
  "cross-spawn": "^7.0.3",
53
53
  "extract-zip": "^2.0.1",
@@ -60,5 +60,5 @@
60
60
  "ws": "^8.17.1",
61
61
  "yaml": "^2.4.1"
62
62
  },
63
- "gitHead": "4f08c2841c452d1d445077a8e465641100b712de"
63
+ "gitHead": "4d589cecf982efeab69ea82881844447369a2af4"
64
64
  }