polymer: Yarn Flat Mode Attribute in Package.json breaks projects
I fully understand the desire for flat dependencies and I think Polymer can be opinionated about requiring flat mode for apps. However, when a dependency has the flat: true in it’s package.json, it forces any project which uses it into flat mode. This breaks all my existing projects.
my-app
|- dep-1
|- dep-2 // flat: true here forces the entire project into flat mode
|- dep-3
This parameter is already ignored by npm so effectively what this parameter does is prevent developers from using yarn unless they use it exactly how the Polymer Project intends. And since flat mode and separate client/server dep folders is extremely non-standard, the end result is this may very well fracture the development space and be every bit as divisive as bower was.
With flat: true specified in Polymer core or in any other dependency, my choices are:
1 . Abandon yarn and go back to npm so that my projects can bypass the flat mode requirement. 2. Republish every dependency I use to an internal npm repository. This is a maintenance nightmare.
As I understand it the problems flat is attempting to solve are:
- Attempting to register a custom-element which is always defined throws an exception. Define calls can be guarded by an
ifto work around this. - Being able to properly calculate paths to other components which nesting breaks. This is solved by the node module resolution algorithm but would require a build step.
I recommend documenting the flat mode requirement and having the Polymer provided build tooling check for it, but removing the flat: true property from any npm-published library intended to be used as a dependency.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 7
- Comments: 16 (9 by maintainers)
hi~
we’ve got a thread going over at https://github.com/package-community/discussions/issues/2 about this issue.
For those who don’t want to read through the Dostoyevsky book that thread’s become, here’s the tl;dr of what my team’s planning on implementing:
assets/directory, distinct fromnode_modulespackage.jsonso you can force a package into a versionpackage-lock.json, so you’ll have reproducible buildstl;dr:
Note: I’ve popped into the polymer slack if anyone wants more back-and-forth questions, and we’ve also got conversations going on about this in the Discord for https://package.community. I probably won’t say much more in this thread, specifically, but I figured this’d be useful. ❤️
But aren’t peer dependencies essentially what Polymer 3 elements are trying to accomplish in the npm ecosystem? Elements don’t
import '@polymer/paper-button', theyimport '../@polymer/paper-button'To me that’s the element asserting that it’s requesting a dependency that it does not have control of. It’s expecting a sibling dependency and not a child dependency right?
For all front-end polymer elements, yes their dependencies should be peer dependencies since the convention is to require by path up to a sibling folder. However, this doesn’t mean that all dependencies in the node_modules tree have to be peer. We can still get the benefit of nested dependency trees for other modules that are not importing each other by path.
Say for example, we have build tool that uses moment for dates, and our element is also using moment, but a different version. The packages would be
build-tool package.json
build-tool.js
my-element package.json
my-element.js
The node_modules tree would be
Using yarn with
--flatis essentially forcing the entire node_modules tree to be “peer dependencies” instead of nested dependencies, so what’s the real difference?@FredKSchott could you give an update about the status of
yarn --flat? I found https://github.com/Polymer/polymer-modulizer/issues/254 but not sure what the latest status is.I’m all for discussions on this type of front, but in the short term the
flatattribute still needs removed from any package designed to be a dependency. It’s breaking yarn today.