@percy/core 1.30.6 → 1.30.7-beta.1

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/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/dist/discovery.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import logger from '@percy/logger';
2
2
  import Queue from './queue.js';
3
3
  import Page from './page.js';
4
- import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll, snapshotLogName, waitForTimeout, withRetries, waitForSelectorInsideBrowser } from './utils.js';
4
+ import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll, snapshotLogName, waitForTimeout, withRetries, waitForSelectorInsideBrowser, isGzipped } from './utils.js';
5
5
  import { sha256hash } from '@percy/client/utils';
6
6
  import Pako from 'pako';
7
7
 
@@ -222,8 +222,12 @@ function processSnapshotResources({
222
222
  })));
223
223
  if (process.env.PERCY_GZIP) {
224
224
  for (let index = 0; index < resources.length; index++) {
225
- resources[index].content = Pako.gzip(resources[index].content);
226
- resources[index].sha = sha256hash(resources[index].content);
225
+ const alreadyZipped = isGzipped(resources[index].content);
226
+ /* istanbul ignore next: very hard to mock true */
227
+ if (!alreadyZipped) {
228
+ resources[index].content = Pako.gzip(resources[index].content);
229
+ resources[index].sha = sha256hash(resources[index].content);
230
+ }
227
231
  }
228
232
  }
229
233
  return {
package/dist/utils.js CHANGED
@@ -389,6 +389,20 @@ export function redactSecrets(data) {
389
389
  export function base64encode(content) {
390
390
  return Buffer.from(content).toString('base64');
391
391
  }
392
+
393
+ // It checks if content is already gzipped or not.
394
+ // We don't want to gzip already gzipped content.
395
+ export function isGzipped(content) {
396
+ if (!(content instanceof Uint8Array || content instanceof ArrayBuffer)) {
397
+ return false;
398
+ }
399
+
400
+ // Ensure content is a Uint8Array
401
+ const data = content instanceof ArrayBuffer ? new Uint8Array(content) : content;
402
+
403
+ // Gzip magic number: 0x1f8b
404
+ return data.length > 2 && data[0] === 0x1f && data[1] === 0x8b;
405
+ }
392
406
  const RESERVED_CHARACTERS = {
393
407
  '%3A': ':',
394
408
  '%23': '#',
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.1",
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.1",
47
+ "@percy/config": "1.30.7-beta.1",
48
+ "@percy/dom": "1.30.7-beta.1",
49
+ "@percy/logger": "1.30.7-beta.1",
50
+ "@percy/webdriver-utils": "1.30.7-beta.1",
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": "b9a15ba7853ff350b7d7b7c3364700e70ca66643"
64
64
  }