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

Angular: Use Nx function to read non-angularCli configs #13558

Merged

Conversation

mandarini
Copy link
Contributor

@mandarini mandarini commented Jan 5, 2021

Issue: #12232

What I did

This is a fix for a behavior described here and here.

A new function is created in the @nrwl/workspace package, which will take care of reading/parsing the workspace configuration, and returning it to Storybook in the angularCli format, which it expects.

The new functionality will work after this Nx PR is successfully merged.

@shilman
Copy link
Member

shilman commented Jan 5, 2021

@ThibaudAV @Marklb can you guys do a quick sanity check. LGTM

@gaetanmaisse @merceyz should @nrwl/workspace be an optional peer dependency for yarn2 compat?

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

LGTM @mandarini and thanks so much for the contribution. i'm OK with it except for the comments above. will get a few more eyes on it and then merge/release if nobody objects. after you've tested the alpha, we can patch it back into 6.1.x!

@shilman shilman added angular maintenance User-facing maintenance tasks labels Jan 5, 2021
@merceyz
Copy link
Contributor

merceyz commented Jan 5, 2021

@gaetanmaisse @merceyz should @nrwl/workspace be an optional peer dependency for yarn2 compat?

Based on its usage, yes, though not just for Yarn PnP (Yarn 2 != pnp as Yarn 2 also supports node_modules) it must be declared so package managers can account for it when they do hoisting

@mandarini mandarini force-pushed the fix/nx-non-angularcli-workspace branch from b0feb1d to 6acb5d0 Compare January 5, 2021 14:17
@mandarini
Copy link
Contributor Author

I just updated my PR, added @nrwl/workspace as an optional peer dependency!

@mandarini mandarini force-pushed the fix/nx-non-angularcli-workspace branch from 6acb5d0 to 3df7a34 Compare January 5, 2021 15:14
app/angular/package.json Outdated Show resolved Hide resolved
@gaetanmaisse
Copy link
Member

The failing unit test looks related to a caching/hoisting issue in the node_modules, I did an ssh connection to the CI container, yarn install, reran the tests and everything was ok. Maybe updating the yarn.lock will fix that.

try {
/**
* Apologies for the following line
* If there's a better way to do it, let's do it
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if it's better (or if it's possible)🙈 . but an alternative without try/catch would be to let storybook choose if it should use nx or not 🤷‍♂️

Something like this:
const isNxWorkspace = fs.existsSync(path.join(dirToSearch, 'nx.json'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is that it will need to access the readWorkspaceConfig() from @nrwl/workspace, so I apologized for using the eslint-disable to let me require it... :)

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@ThibaudAV ThibaudAV Jan 8, 2021

Choose a reason for hiding this comment

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

okay,
my point is more about the try/catch. I find the way we handle the nominal case (without nx) in a Catch is not pretty. :/
and I propose this solution if it works and suits you of course :)

const isNxWorkspace = fs.existsSync(path.join(dirToSearch, 'nx.json'))
if(isNxWorkspace) {
 return require('@nrwl/workspace').readWorkspaceConfig({
      format: 'angularCli',
    });
}
... 

Copy link
Member

Choose a reason for hiding this comment

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

@ThibaudAV are you ok to go with the current state?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes 🚀 , I have plans to improve this part. I will do it with a dedicated PR ;)

@mandarini mandarini force-pushed the fix/nx-non-angularcli-workspace branch from 3df7a34 to 6369a62 Compare January 8, 2021 10:40
@mandarini mandarini force-pushed the fix/nx-non-angularcli-workspace branch from 6369a62 to 0009e69 Compare January 8, 2021 10:45
@mandarini mandarini requested a review from gaetanmaisse January 8, 2021 10:48
Copy link

@Hasbiallah210012 Hasbiallah210012 left a comment

Choose a reason for hiding this comment

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

@gaetanmaisse gaetanmaisse self-assigned this Jan 8, 2021
@mandarini
Copy link
Contributor Author

Hi @gaetanmaisse ! Let me know if I need to make any further changes! I see that the tests are still failing :(

@gaetanmaisse
Copy link
Member

We are currently working on fixing the tests (they are failing on next too), I will update your branch as soon as the fix will be merged 😉

@mandarini
Copy link
Contributor Author

Thank you very much! :)

@gaetanmaisse gaetanmaisse changed the title (fix) reference nx function to read non-angularCli configs Angular: Use Nx function to read non-angularCli configs Jan 12, 2021
This was referenced Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
angular maintenance User-facing maintenance tasks patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants