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: generated tsconfig path mapping for publishable libs (when generated in nested folders) #2840

Merged
merged 5 commits into from
Jul 22, 2020

Conversation

juristr
Copy link
Member

@juristr juristr commented Apr 9, 2020

Current Behavior (This is the behavior we have today, before the PR is merged)

Right now the generated path mappings for nested libraries get generated as follows:

"@my-org/platform/core": ["libs/platform/core/src/index.ts"],
"@my-org/platform/common": ["libs/platform/common/src/index.ts"]

The above works fine as long as the library isn't a buildable one. Buildable libraries have their own package.json where the package name would look like @my-org/platform-core. NPM package names cannot have multiple nestings, but rather just <scope>/<package-name>. As a result the Nx generated path mapping would differ from the one when the package gets published, which is a problem.

Expected Behavior (This is the new behavior we can expect after the PR is merged)

The path mappings generated in the tsconfig.json should match the one of the published package.

Issue

#2794

@juristr juristr requested a review from FrozenPandaz April 9, 2020 10:57
@Hotell
Copy link
Contributor

Hotell commented Apr 18, 2020

  • this should be added to react plugin as well 👌

@vsavkin vsavkin force-pushed the master branch 3 times, most recently from 738e12c to d1679ce Compare May 29, 2020 18:43
@juristr juristr force-pushed the fix-buildablelibs-nested-folders branch 2 times, most recently from bdcc10b to 71ce75f Compare June 5, 2020 22:07
@juristr juristr changed the title fix(angular): generated tsconfig path mapping for publishable libs fix: generated tsconfig path mapping for publishable libs (when generated in nested folders) Jun 5, 2020
@vsavkin
Copy link
Member

vsavkin commented Jun 11, 2020

I like having importPath as an option. I'd add it to all types of libs that we have. We also need to make sure we use the same value in the name of package.json generated.

I'd pull out the npm check form this PR. I feel like the whole publishable thing is a lot trickier, and I'd tackle when we implement a liteweight build builder. Then we would have an actual disctinction between merely buildable and buildable+publishable.

@juristr juristr force-pushed the fix-buildablelibs-nested-folders branch 3 times, most recently from 38fd2d2 to 363a2e2 Compare June 12, 2020 12:19
@juristr juristr marked this pull request as ready for review June 12, 2020 19:55
@juristr juristr requested review from vsavkin and removed request for FrozenPandaz June 12, 2020 19:55
@vsavkin
Copy link
Member

vsavkin commented Jun 18, 2020

I feel uneasy about us adding more functionality into Nx. Publishing is more custom than building. For instance, the issue with import path isn't just that it cannot contain more than 1 slash, often the scope outside of monorepo is different as well.

We could make the PR smaller.

If we use --buildable, everything works as is. If you use --publishable, we require you to provision --importPath. We don't validate anything. The user knows the path they want to use, they know the scope they use in their org, etc..

In this case, we won't have to have a new default.

  let importPath = options.importPath;
  if (!importPath) {
    importPath = options.publishable
      ? `@${getNpmScope(host)}/${projectName}`
      : `@${getNpmScope(host)}/${projectDirectory}`;
  }

If it's publishable, they have to provision the import path. If not, they can still provision it, but we use the current one by default. I know we went back and forth on it. Sorry about it.

What do you think?

@juristr juristr force-pushed the fix-buildablelibs-nested-folders branch 6 times, most recently from eaf2c59 to 6291062 Compare June 29, 2020 14:23
@juristr juristr force-pushed the fix-buildablelibs-nested-folders branch 2 times, most recently from 83a150b to 428ac8c Compare July 3, 2020 21:57
@vsavkin vsavkin self-assigned this Jul 10, 2020
@llwt
Copy link
Contributor

llwt commented Jul 10, 2020

Not sure if the implementation here resolves the issue (I haven't had a chance to check) but we do something similar to this in a custom schematic at the moment and it breaks @nrwl/workspace:move and @nrwl/workspace:remove. We had to wrap them with a custom schematic so it doesn't choke on the tsconfig paths changes.

Just figured I'd leave a friendly heads up just in case :)

@juristr
Copy link
Member Author

juristr commented Jul 13, 2020

@llwt oh thank you!! I've been in vacation last week, so I'm gonna wrap this up this week and test the move schematics as well. Thanks a lot!

I'll let you know once this is out. Would be cool if you'd be willing to test it :)

@juristr juristr force-pushed the fix-buildablelibs-nested-folders branch 2 times, most recently from bfe3c25 to 98a2482 Compare July 17, 2020 12:56
@juristr juristr force-pushed the fix-buildablelibs-nested-folders branch from 98a2482 to 029bb13 Compare July 19, 2020 11:40
@llwt
Copy link
Contributor

llwt commented Jul 20, 2020

Hey @juristr, sorry for the delayed response, I've been a bit backed up on notifications 😅

I'd love to test things out once ready, just lmk!

@juristr juristr force-pushed the fix-buildablelibs-nested-folders branch 2 times, most recently from 8b6185f to e55a758 Compare July 21, 2020 09:33
@juristr juristr force-pushed the fix-buildablelibs-nested-folders branch from e55a758 to 1e4e681 Compare July 21, 2020 09:53
@vsavkin vsavkin merged commit ed0a9a7 into master Jul 22, 2020
@juristr
Copy link
Member Author

juristr commented Jul 24, 2020

@llwt it's in master. so feel free to give it a try :)

@llwt
Copy link
Contributor

llwt commented Jul 31, 2020

Thanks @juristr. The --importPath option works great and we were able to remove our custom impl from our schematics.

@nrwl/workspace:move however still errors with Cannot read property 'map' of undefined when run on a module that was generated using that flag.

Our custom schematic temporarily updates the tsconfig to the directory path before moving, then reverts it:

export default function (schema: Schema): Rule {
  return chain([
    revertPathInTsConfig(schema),
    moveWorkspace(schema),
    updateRootTsConfig(schema),
  ]);
}

Should I open an issue for this?

@juristr
Copy link
Member Author

juristr commented Aug 1, 2020

Hey, yeah please open a new issue for that & reference me there s.t. I can keep track of it.

Thx a lot

@llwt
Copy link
Contributor

llwt commented Aug 5, 2020

Done: #3476

@vsavkin vsavkin deleted the fix-buildablelibs-nested-folders branch September 11, 2020 14:53
Doginal pushed a commit to Doginal/nx that referenced this pull request Nov 25, 2020
…ated in nested folders) (nrwl#2840)

fix(core): require importPath for publishable libs
@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 21, 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.

4 participants