Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions bin/packages/get-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const fs = require( 'fs' );
const path = require( 'path' );
const { overEvery } = require( 'lodash' );
const { isEmpty, overEvery } = require( 'lodash' );

/**
* Absolute path to packages directory.
Expand All @@ -24,6 +24,19 @@ function isDirectory( file ) {
return fs.lstatSync( path.resolve( PACKAGES_DIR, file ) ).isDirectory();
}

/**
* Returns true if the given packages has "module" field.
*
* @param {string} file Packages directory file.
*
* @return {boolean} Whether file is a directory.
*/
function hasModuleField( file ) {
const { module } = require( path.resolve( PACKAGES_DIR, file, 'package.json' ) );

return ! isEmpty( module );
}

/**
* Filter predicate, returning true if the given base file name is to be
* included in the build.
Expand All @@ -32,7 +45,7 @@ function isDirectory( file ) {
*
* @return {boolean} Whether to include file in build.
*/
const filterPackages = overEvery( isDirectory );
const filterPackages = overEvery( isDirectory, hasModuleField );

/**
* Returns the absolute path of all WordPress packages
Expand Down
3 changes: 3 additions & 0 deletions packages/browserslist-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"engines": {
"node": ">=8"
},
"files": [
"index.js"
],
"main": "index.js",
"publishConfig": {
"access": "public"
Expand Down
1 change: 1 addition & 0 deletions packages/custom-templated-path-webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"files": [
"index.js"
],
"main": "index.js",
"dependencies": {
"escape-string-regexp": "^1.0.5"
},
Expand Down
1 change: 1 addition & 0 deletions packages/dom-ready/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.4.4"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"files": [
"configs",
"rules",
"index.js"
],
"main": "index.js",
"dependencies": {
"babel-eslint": "^10.0.1",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/html-entities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "HTML entity utilities for WordPress.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"react-native": "src/index",
"keywords": [
"wordpress",
"html",
Expand All @@ -21,6 +20,7 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.4.4"
},
Expand Down
1 change: 1 addition & 0 deletions packages/is-shallow-equal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"files": [
"arrays.js",
"index.js",
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

"objects.js"
],
"main": "index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/jest-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"files": [
"scripts",
"index.js",
"jest-preset.json"
],
"main": "index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"files": [
"index.js"
],
"main": "index.js",
Comment thread
gziolo marked this conversation as resolved.
"dependencies": {
"lodash": "^4.17.11",
"webpack-sources": "^1.1.0"
Expand Down
6 changes: 6 additions & 0 deletions packages/npm-package-json-lint-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Master

### Braking Change

- Added `type` and `react-native` to the order of preferred properties.
Comment thread
gziolo marked this conversation as resolved.

## 1.2.0 (2019-03-06)

### Internal
Expand Down
2 changes: 2 additions & 0 deletions packages/npm-package-json-lint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ const defaultConfig = {
'engines',
'directories',
'files',
'type',
'main',
'module',
'react-native',
'bin',
'dependencies',
'devDependencies',
Expand Down
3 changes: 3 additions & 0 deletions packages/npm-package-json-lint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"engines": {
"node": ">=8"
},
"files": [
"index.js"
],
"main": "index.js",
"peerDependencies": {
"npm-package-json-lint": ">=3.6.0"
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.4.4",
"@wordpress/compose": "file:../compose",
Expand Down
1 change: 1 addition & 0 deletions packages/token-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.4.4",
"lodash": "^4.17.11"
Expand Down
1 change: 1 addition & 0 deletions packages/wordcount/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.4.4",
"lodash": "^4.17.11"
Expand Down