Skip to content

Commit

Permalink
Framework: Replace element-closest with registered vendor script (#9750)
Browse files Browse the repository at this point in the history
* Framework: Replace element-closest with registered vendor script

* Scripts: Add support for license ignore

* Framework: Re-pin to newer version of JSDOM

Newer version is SemVer-compatible with jest-environment-jsdom and includes support for Element#closest out of the box.

jsdom/jsdom#1555

Required to ignore license validation for abab because while it is a compatible license (BSD 3-clause), the package's `license` field is malformed for parse.

https://github.com/jsdom/abab/blob/4327de3aae348710094d9f3c1f0c1477d9feb865/package.json#L26
https://github.com/jsdom/abab/blob/master/LICENSE.md

* Testing: Add dummy testURL for Jest config

Avoids issues with localStorage in JSDOM 11.12

Can be removed when running Jest 23.5.0 or newer

See: jestjs/jest#6766
See: jestjs/jest#6792

* Licenses: Add BSD-3-Clause W3C variant as an allowed license

Also, check if the license defined in package.json is telling us to look in the license file, instead.

* Package: Scripts: Use String#includes for improved code clarity

* Package: Scripts: Add CHANGELOG notes for improved license file detection
  • Loading branch information
aduth authored Sep 17, 2018
1 parent cd6ae73 commit 45bc8e4
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 73 deletions.
5 changes: 5 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function gutenberg_register_scripts_and_styles() {
'\'fetch\' in window' => 'wp-polyfill-fetch',
'document.contains' => 'wp-polyfill-node-contains',
'window.FormData && window.FormData.prototype.keys' => 'wp-polyfill-formdata',
'Element.prototype.matches && Element.prototype.closest' => 'wp-polyfill-element-closest',
)
)
);
Expand Down Expand Up @@ -871,6 +872,10 @@ function gutenberg_register_vendor_scripts() {
'wp-polyfill-node-contains',
'https://unpkg.com/polyfill-library@3.26.0-0/polyfills/Node/prototype/contains/polyfill.js'
);
gutenberg_register_vendor_script(
'wp-polyfill-element-closest',
'https://unpkg.com/element-closest@2.0.2/element-closest.js'
);
gutenberg_register_vendor_script(
'wp-polyfill-ecmascript',
'https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.0.0/polyfill' . $suffix . '.js'
Expand Down
90 changes: 43 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@wordpress/i18n": "file:../i18n",
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
"@wordpress/shortcode": "file:../shortcode",
"element-closest": "^2.0.2",
"hpq": "^1.2.0",
"lodash": "^4.17.10",
"rememo": "^3.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/blocks/src/api/raw-handling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* External dependencies
*/
import { flatMap, filter, compact } from 'lodash';
// Also polyfills Element#matches.
import 'element-closest';

/**
* Internal dependencies
Expand Down
1 change: 0 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"clipboard": "^1.7.1",
"diff": "^3.5.0",
"dom-scroll-into-view": "^1.2.1",
"element-closest": "^2.0.2",
"lodash": "^4.17.10",
"memize": "^1.0.5",
"moment": "^2.22.1",
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/autocomplete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import classnames from 'classnames';
import { escapeRegExp, find, filter, map, debounce } from 'lodash';
import 'element-closest';

/**
* WordPress dependencies
Expand Down
1 change: 0 additions & 1 deletion packages/dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"module": "build-module/index.js",
"dependencies": {
"@babel/runtime": "^7.0.0",
"element-closest": "^2.0.2",
"lodash": "^4.17.10"
},
"publishConfig": {
Expand Down
5 changes: 0 additions & 5 deletions packages/dom/src/focusable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import 'element-closest';

/**
* References:
*
Expand Down
1 change: 0 additions & 1 deletion packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@wordpress/wordcount": "file:../wordcount",
"classnames": "^2.2.5",
"dom-scroll-into-view": "^1.2.1",
"element-closest": "^2.0.2",
"inherits": "^2.0.3",
"lodash": "^4.17.10",
"memize": "^1.0.5",
Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
last,
} from 'lodash';
import classnames from 'classnames';
import 'element-closest';

/**
* WordPress dependencies
Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
merge,
noop,
} from 'lodash';
import 'element-closest';

/**
* WordPress dependencies
Expand Down
5 changes: 0 additions & 5 deletions packages/editor/src/utils/dom.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import 'element-closest';

/**
* Given a block client ID, returns the corresponding DOM node for the block,
* if exists. As much as possible, this helper should be avoided, and used only
Expand Down
9 changes: 8 additions & 1 deletion packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.3.0 (Unreleased)

### Improvements

- New flag `--ignore` for `check-licenses` script
- Try deferring to LICENSE file for `license` fields which include filename
- Add "BSD-3-Clause-W3C" as GPL-compatible

## 2.2.1 (2018-09-05)

### Bug Fix
Expand All @@ -8,7 +16,6 @@

- Updated dependencies: `jest`, `npm-package-json-lint` and `read-pkg-up`


## 2.0.0 (2018-07-12)

### Breaking Change
Expand Down
21 changes: 21 additions & 0 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ This is how you execute those scripts using the presented setup:
* `npm run test:help` - prints all available options to configure unit tests runner.
* `npm run test:watch` - runs all unit tests in the watch mode.

### `wp-scripts check-licenses`

Validates that all dependencies of a project are compatible with the project's own license.

_Example:_

```json
{
"scripts": {
"check-licenses": "wp-scripts check-licenses --prod --gpl2 --ignore=abab",
}
}
```

_Flags_:

- `--prod` (or `--production`): When present, validates only `dependencies` and not `devDependencies`
- `--dev` (or `--development`): When present, validates both `dependencies` and `devDependencies`
- `--gpl2`: Validates against [GPLv2 license compatibility](https://www.gnu.org/licenses/license-list.en.html)
- `--ignore=a,b,c`: A comma-separated set of package names to ignore for validation. This is intended to be used primarily in cases where a dependency's `license` field is malformed. It's assumed that any `ignored` package argument would be manually vetted for compatibility by the project owner.

## Inspiration

This is inspired by [react-scripts](https://www.npmjs.com/package/react-scripts) and [kcd-scripts](https://www.npmjs.com/package/kcd-scripts).
Expand Down
Loading

0 comments on commit 45bc8e4

Please sign in to comment.