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

Create-package fixes and related updates #10212

Merged
merged 4 commits into from
Aug 23, 2019

Conversation

ecraig12345
Copy link
Member

@ecraig12345 ecraig12345 commented Aug 20, 2019

Pull request checklist

  • Include a change request file using $ yarn change

Description of changes

Fix some issues with create-package:

  • For some reason it was creating two Jest setup files, config/tests.js and src/common/tests.js. Only config/tests.js ever seems to be referenced, so delete the other one various places and delete the line in create-package that creates it.

  • Don't create empty .vscode directories

  • Use the correct version ranges for react/react-dom peer deps, and add the corresponding types as peer deps

  • Update the npmignore to be consistent across packages (with a couple exceptions)

Microsoft Reviewers: Open in CodeFlow

@size-auditor
Copy link

size-auditor bot commented Aug 20, 2019

Size Auditor did not detect a change in bundle size for any component!

@msft-github-bot
Copy link
Contributor

Component Perf Analysis:

Scenario Master Samples * PR Samples *
BaseButton 748 698
BaseButton (experiments) 1042 1014
DefaultButton 1000 988
DefaultButton (experiments) 1909 1942
DetailsRow 3358 3216
DetailsRow (fast icons) 3241 3280
DetailsRow without styles 2970 2957
DocumentCardTitle with truncation 32045 31228
MenuButton 1822 1815
MenuButton (experiments) 3993 3958
PrimaryButton 1145 1136
PrimaryButton (experiments) 1991 1957
SplitButton 3358 3365
SplitButton (experiments) 7333 7386
Stack 470 474
Stack with Intrinsic children 1079 1139
Stack with Text children 4216 4279
Text 379 357
Toggle 835 843
Toggle (experiments) 2298 2216
button 69 59
* Sample counts can vary by up to 30% and shouldn't be used solely for determining regression. For more information please see the Perf Testing wiki.

"react-dom": "{{{reactDom}}}"
"@types/react": "{{{typesReactPeerDep}}}",
"@types/react-dom": "{{{typesReactDomPeerDep}}}",
"react": "{{{reactPeerDep}}}",
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we really need to do the @types/* peer deps anymore. I think that was related to a rush update fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay so should I revert them all now? Change was made in #9798 for reference. It actually seems like a reasonable change since if people want to use OUFR with TS, they'll need React typings.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is a Rush related fix, but rather a Fabric + TypeScript related fix that we should keep. Assuming new packages spun up leverage React (likely) then including them in the package.json template seems reasonable.

Choose a reason for hiding this comment

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

@kenotron As explained in #9720 (comment), if your package imports stuff from another package, you need to declare that dependency in your package.json. If you don't declare it, then complex installations /will/ malfunction.

Rush users tend to encounter these problems more often, because Rush's audience tends to be running serious production monorepos with complex installations. Also, Rush supports validation checks to proactively detect some of these problems. Nonetheless, the problem applies to every package manager: No package manager can perform a correct side-by-side installation for dependencies that were undeclared.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ken pointed out an interesting case, what about our consumers who don't use TypeScript? It's not ideal to make them either depend on @types/react and @types/react-dom or have unmet peer dependencies. But I also see the value of enforcing the correct typing versions for those consumers who do use TypeScript.

Choose a reason for hiding this comment

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

The rush update fixed everything because it inadvertently upgraded to office-ui-fabric-react 5.135.3 with the peer dependencies added. 😁

Copy link
Member

@kenotron kenotron Aug 22, 2019

Choose a reason for hiding this comment

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

Okay, I have locked the version to that original versions... Still builds fine...

Copy link

@octogonz octogonz Aug 22, 2019

Choose a reason for hiding this comment

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

This fix works because although you locked the direct dependency on office-ui-fabric-react to "5.113.1", the indirect dependencies still got upgraded. For example, @uifabric/utilities was solved as 5.34.3 which has the @types/react peer. Because office-ui-fabric-react does not satisfy this peer, it gets determined by the parent project test-15. This induces an implicit peer dependency for office-ui-fabric-react@5.113.1 which is recorded in the lockfile like this:

  /office-ui-fabric-react/5.113.1_ee63188b739fb4d6a436db584e63e7a3:
    dependencies:
      '@microsoft/load-themed-styles': 1.9.19
      '@uifabric/icons': 5.8.0_ee63188b739fb4d6a436db584e63e7a3
      '@uifabric/merge-styles': 5.17.1
      '@uifabric/styling': 5.37.0_ee63188b739fb4d6a436db584e63e7a3
      '@uifabric/utilities': 5.34.3_ee63188b739fb4d6a436db584e63e7a3
      prop-types: 15.7.2
      react: 15.6.2
      react-dom: 15.6.2_react@15.6.2
      tslib: 1.10.0
    dev: false
    peerDependencies:
      '@types/react': '*'
      '@types/react-dom': '*'
      react: ^0.14.9 || ^15.0.1-0 || ^16.0.0-0
      react-dom: ^0.14.9 || ^15.0.1-0 || ^16.0.0-0

In order to really test your theory, a reliable way would be to add some code like this to common/config/rush/pnpmfile.js:

/**
 * This hook is invoked during installation before a package's dependencies
 * are selected.
 * The `packageJson` parameter is the deserialized package.json
 * contents for the package that is about to be installed.
 * The `context` parameter provides a log() function.
 * The return value is the updated object.
 */
function readPackage(packageJson, context) {
  if (packageJson.peerDependencies) {
    delete packageJson.peerDependencies['@types/react'];
    delete packageJson.peerDependencies['@types/react-dom'];
  }
  return packageJson;
}

During rush install, this will revert the fix where we added peerDependencies, for all packages including indirect dependencies. When I tried that and ran rush update --full, the build failure repros again.

Copy link
Member

@kenotron kenotron Aug 22, 2019

Choose a reason for hiding this comment

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

I see now the issue isn't OUFR, it's actually the internal deps of OUFR from our own repo that needs @types/react. When I did tsc, it gives this sort of result:

../../common/temp/node_modules/.registry.npmjs.org/@uifabric/utilities/5.34.2_react-dom@15.6.2+react@15.6.2/node_modules/@uifabric/utilities/lib-es2015/BaseComponent.d.ts:1:24 - error TS7016: Could not find a declaration file for module 'react'. '/Users/ken/workspace/harry/common/temp/node_modules/.registry.npmjs.org/react/15.6.2/node_modules/react/react.js' implicitly has an 'any' type.
  If the 'react' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react`

1 import * as React from 'react';

So pnpm resolves these really specific dirs for its npm 2 style directories. I just realized that pnpm actually CHANGES the shape of this by the peer dependency hints that we give when a conflict arises in a side-by-side environment (strange, but not unheard of in a more complex repo). Inspired by your last proposal, I took a stab at solving the OP's issue with a pnpmfile.js change like this:

/**
 * This hook is invoked during installation before a package's dependencies
 * are selected.
 * The `packageJson` parameter is the deserialized package.json
 * contents for the package that is about to be installed.
 * The `context` parameter provides a log() function.
 * The return value is the updated object.
 */
function readPackage(packageJson, context) {
  if (packageJson.name === 'office-ui-fabric-react' || packageJson.name.startsWith('@uifabric')) {
    packageJson.peerDependencies['@types/react'] = '*';
    packageJson.peerDependencies['@types/react-dom'] = '*';
  }

  return packageJson;
}

I'm not sure how often we have UI Fabric deps installed side-by-side by our consumers. This might be acceptable as a workaround for them, but I think if all it takes is put some hints in our package.json, it's not too bad. This has been a pretty interesting education for me on pnpm and how it treats things - kudos to the fact that you can programmatically change how it sees package.json.

Conclusion - keep this in the create-package script. It's a good change.

Copy link

@octogonz octogonz Aug 22, 2019

Choose a reason for hiding this comment

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

"Hints" isn't best term for these peer dependencies. It's better to think of them as fixes for real bugs in package.json. Side-by-side OUIFR versions seems like an esoteric edge case, but it was just an easy example. It's the tip of an iceberg. Wherever package.json bugs are found, this same problem arises over and over and over again in a myriad of variations. It's a real headache for developers. As participants in the NPM ecosystem, we all can work together and do our part to eliminate these bugs.

Although this investigation focused on PNPM, the same thing will repro easily with Yarn or NPM or even Yarn Plug'n'Play. Their lockfiles are radically different, but the fix is always the same: Declare the missing deps.

So pnpm resolves these really specific dirs for its npm 2 style directories.

Heh, I suppose the deep node_modules paths are a bit reminiscent of "NPM 2". It's only a superficial similarity, though. PNPM invented a completely novel installation plan that solves the same important problems that Yarn recently tackled with their Plug'n'Play feature. Whereas Plug'n'Play relies on redefining NodeJS's module resolution behavior, PNPM instead installs a node_modules folder with lots of nesting symlinks. This weird symlinking strategy enabled PNPM to be backwards-compatible with existing NodeJS module resolution, which is how it was able to predate Plug'n'Play by a couple years.

Likening it to NPM 2 suggests that PNPM is old fashioned, but NPM 6 doesn't solve these problems at all. (The specific problems I'm referring to are doppelgangers and phantom dependencies.)

Conclusion - keep this in the create-package script. It's a good change.

Yay, thanks! 😊

@dzearing dzearing assigned joschect and unassigned JasonGore Aug 22, 2019
@ecraig12345 ecraig12345 merged commit 280a7b1 into microsoft:master Aug 23, 2019
@ecraig12345 ecraig12345 deleted the tests-fix branch August 23, 2019 00:54
@msft-github-bot
Copy link
Contributor

🎉@uifabric/utilities@v7.0.8 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/tsx-editor@v0.3.1 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/variants@v7.0.4 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/tslint-rules@v7.0.5 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/theme-samples@v7.0.4 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/test-utilities@v7.0.5 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/styling@v7.6.1 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/webpack-utils@v7.0.4 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/set-version@v7.0.2 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/react-cards@v0.107.9 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/prettier-rules@v7.0.4 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/migration@v7.0.5 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/merge-styles@v7.4.1 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉office-ui-fabric-react@v7.27.1 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/mdl2-theme@v0.1.4 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/jest-serializer-merge-styles@v7.0.5 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/icons@v7.1.2 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/file-type-icons@v7.0.7 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/foundation@v7.0.4 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/foundation-scenarios@v0.102.3 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/fabric-website-resources@v7.2.5 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/experiments@v7.13.1 has been released which incorporates this pull request.:tada:

Handy links:

@msft-github-bot
Copy link
Contributor

🎉@uifabric/fluent-theme@v7.1.3 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants