Skip to content

Commit

Permalink
Added PERCY_FORCE_PKG_VALUE in env file and using from there (#1800)
Browse files Browse the repository at this point in the history
* Added PERCY_FORCE_PKG_VALUE in place of PERCY_FORCE_DIRNAME

* Bumped the percy tag to 1.30.3-alpha.4

* Added PERCY_FORCE_PKG_VALUE in env file and using from there

* Bumped the percy tag to 1.30.3-alpha.5

* fixed linting
  • Loading branch information
khushhalm authored Nov 27, 2024
1 parent c524e28 commit b996f30
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 53 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"packages": [
"packages/*"
],
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-app",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.30.3-alpha.4",
"@percy/cli-exec": "1.30.3-alpha.4"
"@percy/cli-command": "1.30.3-alpha.5",
"@percy/cli-exec": "1.30.3-alpha.5"
}
}
4 changes: 2 additions & 2 deletions packages/cli-build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-build",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,6 +33,6 @@
]
},
"dependencies": {
"@percy/cli-command": "1.30.3-alpha.4"
"@percy/cli-command": "1.30.3-alpha.5"
}
}
8 changes: 4 additions & 4 deletions packages/cli-command/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-command",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,8 +36,8 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@percy/config": "1.30.3-alpha.4",
"@percy/core": "1.30.3-alpha.4",
"@percy/logger": "1.30.3-alpha.4"
"@percy/config": "1.30.3-alpha.5",
"@percy/core": "1.30.3-alpha.5",
"@percy/logger": "1.30.3-alpha.5"
}
}
4 changes: 2 additions & 2 deletions packages/cli-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-config",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,6 +33,6 @@
]
},
"dependencies": {
"@percy/cli-command": "1.30.3-alpha.4"
"@percy/cli-command": "1.30.3-alpha.5"
}
}
6 changes: 3 additions & 3 deletions packages/cli-exec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-exec",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,8 +33,8 @@
]
},
"dependencies": {
"@percy/cli-command": "1.30.3-alpha.4",
"@percy/logger": "1.30.3-alpha.4",
"@percy/cli-command": "1.30.3-alpha.5",
"@percy/logger": "1.30.3-alpha.5",
"cross-spawn": "^7.0.3",
"which": "^2.0.2"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-snapshot",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.30.3-alpha.4",
"@percy/cli-command": "1.30.3-alpha.5",
"yaml": "^2.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/cli-upload/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-upload",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.30.3-alpha.4",
"@percy/cli-command": "1.30.3-alpha.5",
"fast-glob": "^3.2.11",
"image-size": "^1.0.0"
}
Expand Down
20 changes: 10 additions & 10 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -31,14 +31,14 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@percy/cli-app": "1.30.3-alpha.4",
"@percy/cli-build": "1.30.3-alpha.4",
"@percy/cli-command": "1.30.3-alpha.4",
"@percy/cli-config": "1.30.3-alpha.4",
"@percy/cli-exec": "1.30.3-alpha.4",
"@percy/cli-snapshot": "1.30.3-alpha.4",
"@percy/cli-upload": "1.30.3-alpha.4",
"@percy/client": "1.30.3-alpha.4",
"@percy/logger": "1.30.3-alpha.4"
"@percy/cli-app": "1.30.3-alpha.5",
"@percy/cli-build": "1.30.3-alpha.5",
"@percy/cli-command": "1.30.3-alpha.5",
"@percy/cli-config": "1.30.3-alpha.5",
"@percy/cli-exec": "1.30.3-alpha.5",
"@percy/cli-snapshot": "1.30.3-alpha.5",
"@percy/cli-upload": "1.30.3-alpha.5",
"@percy/client": "1.30.3-alpha.5",
"@percy/logger": "1.30.3-alpha.5"
}
}
6 changes: 3 additions & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/client",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,8 +33,8 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@percy/env": "1.30.3-alpha.4",
"@percy/logger": "1.30.3-alpha.4",
"@percy/env": "1.30.3-alpha.5",
"@percy/logger": "1.30.3-alpha.5",
"pac-proxy-agent": "^7.0.2",
"pako": "^2.1.0"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {

// Default client API URL can be set with an env var for API development
const { PERCY_CLIENT_API_URL = 'https://percy.io/api/v1' } = process.env;
const pkg = getPackageJSON(import.meta.url);
let pkg = getPackageJSON(import.meta.url);
// minimum polling interval milliseconds
const MIN_POLLING_INTERVAL = 1_000;
const INVALID_TOKEN_ERROR_MESSAGE = 'Unable to retrieve snapshot details with write access token. Kindly use a full access token for retrieving snapshot details with Synchronous CLI.';
Expand Down Expand Up @@ -83,6 +83,8 @@ export class PercyClient {

// Stringifies client and environment info.
userAgent() {
if (this.env.forcedPkgValue) pkg = this.env.forcedPkgValue;

let client = new Set([`Percy/${/\w+$/.exec(this.apiUrl)}`]
.concat(`${pkg.name}/${pkg.version}`, ...this.clientInfo)
.filter(Boolean));
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function waitForTimeout() {
// Returns the package.json content at the package path.
export function getPackageJSON(rel) {
/* istanbul ignore else: sanity check */
if (process.env.PERCY_FORCE_PKG_VALUE) return JSON.parse(process.env.PERCY_FORCE_PKG_VALUE);
if (rel.startsWith('file:')) rel = url.fileURLToPath(rel);

/* istanbul ignore else: sanity check */
if (rel.startsWith('file:')) rel = url.fileURLToPath(rel);
Expand Down
4 changes: 2 additions & 2 deletions packages/config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/config",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -38,7 +38,7 @@
"test:types": "tsd"
},
"dependencies": {
"@percy/logger": "1.30.3-alpha.4",
"@percy/logger": "1.30.3-alpha.5",
"ajv": "^8.6.2",
"cosmiconfig": "^8.0.0",
"yaml": "^2.0.0"
Expand Down
12 changes: 6 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/core",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,11 +43,11 @@
"test:types": "tsd"
},
"dependencies": {
"@percy/client": "1.30.3-alpha.4",
"@percy/config": "1.30.3-alpha.4",
"@percy/dom": "1.30.3-alpha.4",
"@percy/logger": "1.30.3-alpha.4",
"@percy/webdriver-utils": "1.30.3-alpha.4",
"@percy/client": "1.30.3-alpha.5",
"@percy/config": "1.30.3-alpha.5",
"@percy/dom": "1.30.3-alpha.5",
"@percy/logger": "1.30.3-alpha.5",
"@percy/webdriver-utils": "1.30.3-alpha.5",
"content-disposition": "^0.5.4",
"cross-spawn": "^7.0.3",
"extract-zip": "^2.0.1",
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ import { handleSyncJob } from './snapshot.js';
// This change ensures better compatibility and avoids relying on Node.js-specific APIs that might cause issues in ESM environments.
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const getPercyDomPath = () => {
try {
const { createRequire } = require('module');
return createRequire(import.meta.url).resolve('@percy/dom');
} catch (error) {
logger('core:server').warn([
'Failed to resolve @percy/dom path using createRequire.',
'Falling back to using fileURLToPath and path.resolve.'
].join(' '));
}
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
return resolve(__dirname, 'node_modules/@percy/dom');
};

export const PERCY_DOM = resolve(__dirname, 'node_modules/@percy/dom');
// Resolved path for PERCY_DOM
export const PERCY_DOM = getPercyDomPath();

// Returns a URL encoded string of nested query params
function encodeURLSearchParams(subj, prefix) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/dom",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions packages/env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/env",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -32,6 +32,6 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@percy/logger": "1.30.3-alpha.4"
"@percy/logger": "1.30.3-alpha.5"
}
}
7 changes: 7 additions & 0 deletions packages/env/src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ export class PercyEnv {
get token() {
return this.vars.PERCY_TOKEN || null;
}

// PERCY_FORCE_PKG_VALUE for forcing package.json values
// to be used as the current environment values in client
get forcedPkgValue() {
let pkg = this.vars.PERCY_FORCE_PKG_VALUE;
return JSON.parse(pkg) || null;
}
}

// cache getters on initial call so subsequent calls are not re-computed
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/logger",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/sdk-utils",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions packages/webdriver-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/webdriver-utils",
"version": "1.30.3-alpha.4",
"version": "1.30.3-alpha.5",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -29,7 +29,7 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@percy/config": "1.30.3-alpha.4",
"@percy/sdk-utils": "1.30.3-alpha.4"
"@percy/config": "1.30.3-alpha.5",
"@percy/sdk-utils": "1.30.3-alpha.5"
}
}

0 comments on commit b996f30

Please sign in to comment.