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

Feature Request: Support {absWorkspaceRoot} and {absProjectRoot} token replacement for file paths #980

Open
JakeDern opened this issue Mar 22, 2024 · 3 comments

Comments

@JakeDern
Copy link

JakeDern commented Mar 22, 2024

I'll open a PR for this myself if you agree with the idea and will review it.

context and file settings seem to be relative to where you run the command from. This is a bit annoying because if you're jumping around in the terminal then all of the sudden your image builds will fail. Currently the repos for my team are set up to have everyone just run everything from the root always.

I've implemented a handful of executors and have started supporting replacement of {absWorkspaceRoot} and {absProjectRoot} tokens for any file paths. It's very simple to do, you can get the necessary information from the executor context. It's also consistent with how nx does it for executor inputs and outputs. Here's an example:

// You can get the root of any project like this and the context provides what the current project is
// Workspace root is available directly from `ctx.root`
function getProjectRoot(ctx: ExecutorContext): string {
    const projectRoot = ctx.projectsConfigurations?.projects[String(ctx.projectName)].root
    if (!projectRoot) {
        throw new Error(`Could not find project root for ${ctx.projectName}`)
    }

    return projectRoot;
}

Then you can just replace the tokens:

const finalContextPath = options.context.replaceAll('{absProjectRoot}', path.join(ctx.root, getProjectRoot(ctx))

Again I'm happy to do the work, just want to know if you agree with the idea first.

@JakeDern JakeDern changed the title Feature Request: Support {workspaceRoot} and {projectRoot} token replacement for file paths Feature Request: Support {absWorkspaceRoot} and {absProjectRoot} token replacement for file paths Mar 27, 2024
@JakeDern
Copy link
Author

Updated to clarify I'm looking for support for absolute paths rather than the default nx behavior of giving relative paths from root.

@coracuity
Copy link

Seconding that this is valuable!

@gperdomor
Copy link
Owner

@JakeDern can you send the PR for this?

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

No branches or pull requests

3 participants