Skip to content

Conversation

@gziolo
Copy link
Member

@gziolo gziolo commented May 29, 2019

Description

An alternative to #15841 where I tried:

This allows us to use a more predictable way to filter out packages which don't need to be processed with Babel. It will also make it possible to use src subfolder in packages which don't need to transpiled.

It turned out that we can't use implementation based on new type field:

I can confirm based on http://2ality.com/2019/04/nodejs-esm-impl.html#filename-extensions that commonjs is the default type. This makes this proposal not viable. I figured out that we can reason about the package type based on the “module” field. Only those transpiled with Babel have this field defined. I will open another PR where I will move some of the logic which this PR adds.

This PR use module field to achieve the same goal.

In addition, it does some chores:

  • adds files, main and react-native fields where applicable
  • enforces order for react-native and type fields if defined in package.json file

How has this been tested?

npm run lint & npm run build

I also confirmed that only packages which use Babel are listed in those which are built with npm run build:packages.

@gziolo gziolo self-assigned this May 29, 2019
@gziolo gziolo requested review from hypest and koke May 29, 2019 08:44
@gziolo gziolo added [Type] Code Quality Issues or PRs that relate to code quality [Type] Build Tooling Issues or PRs related to build tooling labels May 29, 2019
Copy link
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

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

Looks good from native mobile's point of view 👍 .

},
"files": [
"arrays.js",
"index.js",
Copy link
Member

Choose a reason for hiding this comment

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

Is this module totally broken from NPM ? This seems like it would be necessary for it to work 😯

Sometimes I wonder if it's worthwhile to use a files whitelist, vs. the (apparently real) risk of neglecting to include files.

Edit:

At least on unpkg, it seems to be intact? https://unpkg.com/@wordpress/is-shallow-equal@1.3.0/index.js

How does that work?

There are some always-included files, but index.js is not one of them:

https://docs.npmjs.com/files/package.json#files

And I don't think we'd want to cherry-pick individual "always included"; either consistently assume the inherited always-included, or consistently list them all explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are some always-included files, but index.js is not one of them:

https://docs.npmjs.com/files/package.json#files

It is included, not because of the name, but because it's the file in the “main” field.

Copy link
Member Author

Choose a reason for hiding this comment

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

Certain files are always included, regardless of settings:

  • package.json
  • README
  • CHANGES / CHANGELOG / HISTORY
  • LICENSE / LICENCE
  • NOTICE
  • The file in the “main” field

I can remove all files listed in main. I assumed it can be confusing for those who don't know how it exactly works and it's better to whitelist all code related files. I'd be also fine with using lib folder for those packages which use CommonJS syntax.

Copy link
Member

Choose a reason for hiding this comment

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

There are some always-included files, but index.js is not one of them:
https://docs.npmjs.com/files/package.json#files

It is included, not because of the name, but because it's the file in the “main” field.

Ah! I searched the page for the literal term "index", and admittedly did not read the list in detail this time around 😅 That makes sense now.

I'm on the fence about whether we include it, or allow it to be implied from main, or include it and avoid main, or include all implicit files. I agree it can be confusing for those unfamiliar with the default files (me, apparently 😆). Since generally I'm expecting these to be "the files required for runtime execution", seems reasonable to expect index.js here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'm fine with whatever people prefer here. I can keep it as is, remove main from files. Both work for me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I merged this PR, we can revisit this later :)

Copy link
Member

Choose a reason for hiding this comment

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

I merged this PR, we can revisit this later :)

Yeah, I'm not really sure what the best option is, since they all seem to have some downside. It's fine enough to move forward with.

@gziolo gziolo force-pushed the update/module-package-json branch from f56ef5e to 8b48a13 Compare May 30, 2019 13:18
@gziolo gziolo added this to the 5.9 (Gutenberg) milestone May 30, 2019
@gziolo gziolo merged commit dbc155c into master Jun 3, 2019
@gziolo gziolo deleted the update/module-package-json branch June 3, 2019 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Build Tooling Issues or PRs related to build tooling [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants