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

fix(core): add globPatternforDependencies support nx:run-commands wi… #12786

Merged
merged 1 commit into from
Nov 9, 2022
Merged

fix(core): add globPatternforDependencies support nx:run-commands wi… #12786

merged 1 commit into from
Nov 9, 2022

Conversation

ViktorPontinen
Copy link
Contributor

@ViktorPontinen ViktorPontinen commented Oct 24, 2022

…th cwd option

As globPatternforDependencies expects cwd to be in workspaceRoot, it will fail if it's used in a script that is called via nx:run-commands with cwd option pointing to project. This "fix" resolves paths to allow the script to run even from project dir.

Closes issues: #12721

Current Behavior

When running a script that utilises globPatternforDependencies from workspace package in a target that uses nx:run-commands executor together with cwd option pointing to project root then that script will fail because it can not resolve the paths correctly.
An example would be a migrated CRA application that should run craco start from project root and contains a tailwind config per documentation.

Expected Behavior

Running target with nx:run-commands with cwd option should not break globPatternforDependencies.

Related Issue(s)

Fixes #12721

EDIT(26/10/2022): Edited due to changed fix implementation

@vercel
Copy link

vercel bot commented Oct 24, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nx-dev ✅ Ready (Inspect) Visit Preview Oct 26, 2022 at 8:33AM (UTC)

Comment on lines 56 to 57
const initialCwd = process.cwd();
if (initialCwd !== workspaceRoot) process.chdir(workspaceRoot);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than changing process.cwd, we should be able to resolve the paths relative to workspaceRoot. The changeset would probably be a bit larger, but I think it would be preferred.

Copy link
Contributor Author

@ViktorPontinen ViktorPontinen Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I initially went on that track but stumbled across issues that seemed to go deeper than the scope of globPatternforDependencies, possibly in the ignore library. But i'll revisit!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC ignore requires that the paths are relative. Might need to resolve, and then make relative rather than just going w/ the fully resolved paths.

Copy link
Contributor Author

@ViktorPontinen ViktorPontinen Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed implementation as suggested.
I was able to solve my original issue with the ignore lib which stemmed from the 5.0.0 update to the library.
See: kaelzhang/node-ignore#20 for context.
I was trying to pass relative paths as ../foo/bar which it does not accept and the thrown error was a bit misguiding:
path should be a path.relative()d string, but got "../foo/bar" and in my world ../foo/bar is a "relative()d" string :)

…th cwd option

As globPatternforDependencies expects cwd to be in workspaceRoot, it will fail if it's used in a
script that is called via nx:run-commands with `cwd` option pointing to project. This \"fix\" changes
the process cwd to workspaceRoot while running the globPatternforDependencies script, then changes
back.

ISSUES CLOSED: #12721
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nx tailwind util (globPatternforDependencies) behavior changed after Nx 14.6.2
2 participants