Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli bundling import fix #1785

Merged
merged 7 commits into from
Nov 20, 2024

Conversation

khushhalm
Copy link

Previously, we used createRequire(import.meta.url).resolve to resolve the path to the module.
This approach relied on createRequire, which is Node.js-specific and less compatible with modern ESM (ECMAScript Module) standards.
This was leading to hard coded paths when CLI is used as a dependency in another project.
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.

Old code:

export const PERCY_DOM = createRequire(import.meta.url).resolve('@percy/dom');

New code:

import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';

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

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

@khushhalm khushhalm requested a review from a team as a code owner November 20, 2024 03:42
@khushhalm khushhalm requested review from pankaj443 and ninadbstack and removed request for a team November 20, 2024 03:42
@prklm10 prklm10 merged commit cacd660 into percy:pac-file-support Nov 20, 2024
21 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants