Skip to content

Commit

Permalink
Cli bundling import fix (#1794)
Browse files Browse the repository at this point in the history
* Fix import in ternary statement

* Added comment

* Typo fix in comment

Co-authored-by: ninadbstack <60422475+ninadbstack@users.noreply.github.com>

* Removed trailing space

* Fix import of PERCY_DOM in line w ESM req

* made a minor comment change

* Added PERCY_FORCE_DIRNAME flag in getPackageJSON util method

* Env var name updated to PERCY_FORCE_EXECUTABLE_DIRNAME

Co-authored-by: ninadbstack <60422475+ninadbstack@users.noreply.github.com>

---------

Co-authored-by: ninadbstack <60422475+ninadbstack@users.noreply.github.com>
  • Loading branch information
khushhalm and ninadbstack authored Nov 26, 2024
1 parent aeaba47 commit 3b4c0a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/client/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ 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_EXECUTABLE_DIRNAME) rel = __dirname;

/* istanbul ignore else: sanity check */
if (rel.startsWith('file:')) rel = url.fileURLToPath(rel);

Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import path from 'path';
import path, { dirname, resolve } from 'path';
import logger from '@percy/logger';
import { normalize } from '@percy/config/utils';
import { getPackageJSON, Server, percyAutomateRequestHandler, percyBuildEventHandler } from './utils.js';
Expand All @@ -11,7 +11,6 @@ import { handleSyncJob } from './snapshot.js';
// Now, we use `fileURLToPath` and `path.resolve` to determine the absolute path in a way that's more aligned with ESM conventions.
// This change ensures better compatibility and avoids relying on Node.js-specific APIs that might cause issues in ESM environments.
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down

0 comments on commit 3b4c0a5

Please sign in to comment.