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

Advice or Re-allow path segments in --newProjectName option of mv generator. #22966

Closed
plutotv-aaa opened this issue Apr 23, 2024 · 3 comments
Closed
Assignees
Labels
scope: misc Misc issues

Comments

@plutotv-aaa
Copy link

plutotv-aaa commented Apr 23, 2024

Hi, our team is currently using directory pathing for our project names. This change may either create or expose a massive problem in our mono-repo.

Originally posted by @github-actions[bot] in #20768 (comment)

We hope to understand better the bugs claimed by @leosvelperez so we can design a solution to pivot if necessary.

Are there a couple of areas of code we can use as examples that will better inform us? Only one place in the repo seems to use the name property from project.json: the README.md. Every other use case we can see uses directory pathing, which doesn't inform us that they need to be aligned with the project name.

if (
    options.newProjectName &&
    options.newProjectName.includes('/') &&
    !options.newProjectName.startsWith('@')
  ) {
    throw new Error(
      `You can't specify a new project name with a directory path (${options.newProjectName}). ` +
        `Please provide a valid name without path segments and the full destination with the "--destination" option.`
    );
  }

In 18, with this command:

nx g mv --projectName=packages/boots-sdk --destination=packages/cats-sdk --newProjectName=cats-sdk
  1. We notice that package.json is updated from "name": "packages/boots-sdk" to include our workspace scope @xx/cats-sdk, but also removes prefix packages/.
  2. We notice that "name": "packages/boots-sdk" is updated to "name": "cats-sdk" in project.json
  3. One of our alias's in tsconfig.json didn't change as expected:
"@xx/boots/types": [
  "packages/boots/src/boots.types.ts"
],

changed to

"@xx/cats-sdk": ["packages/cats/src/cats.types.ts"],

In 17.1.3, with the same command:

nx g mv --projectName=packages/boots-sdk --destination=packages/cats-sdk --newProjectName=packages/cats-sdk
  1. We notice that package.json maintains updated with our workspace scope @xx/cats-sdk.
  2. We notice that "name": "packages/boots-sdk" is updated to "name": "packages/cats-sdk" and directory paths are updated as expected.
  3. tsconfig and alias's maintain packages/ prefix.

Your work and help is appreciated.

@plutotv-aaa
Copy link
Author

plutotv-aaa commented Apr 24, 2024

I wanted to post a follow-up to this. Since the original ticket allows the use of the scoped package, I tried the following cli cmd.

nx g mv --projectName=packages/boots-sdk --destination=packages/boots-sdk --newProjectName=@xp/lboots-sdk 

The expected result was almost obtained. We still have one issue where a tsconfig alias still gets changed improperly.

 "@xp/boots/types": [
        "packages/boots/src/sdk.types.ts"
      ],

Changes to :

"@xp/cats-sdk": ["packages/cats/src/sdk.types.ts"],

We end up losing the /types from the original alias. Please advise

Thank you!

@leosvelperez
Copy link
Member

Thanks for reporting this!

As you've discovered, you can use scoped package names as your Nx project names. This would match more closely to your package names (in their package.json).

To achieve what you want, you can provide the --importPath option:

nx g mv --projectName=packages/boots-sdk --destination=packages/cats-sdk --newProjectName=@xp/cats-sdk --importPath=@xp/cats-sdk/types

This will result in:

"@xp/cats-sdk/types": ["packages/cats-sdk/src/index.ts"]

When importPath is not provided, the move generator uses the new project name as the new alias.

@plutotv-aaa
Copy link
Author

@leosvelperez, thank you for your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: misc Misc issues
Projects
None yet
Development

No branches or pull requests

3 participants