From d0cb647bf6edab370b838bad26fb00dd90f802d7 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 12 Sep 2018 09:41:32 -0400 Subject: [PATCH 1/7] Framework: Replace element-closest with registered vendor script --- lib/client-assets.php | 5 +++++ package-lock.json | 8 +++----- packages/blocks/package.json | 1 - packages/blocks/src/api/raw-handling/index.js | 2 -- packages/components/package.json | 1 - packages/components/src/autocomplete/index.js | 1 - packages/dom/package.json | 1 - packages/dom/src/focusable.js | 5 ----- packages/editor/package.json | 1 - packages/editor/src/components/block-list/index.js | 1 - packages/editor/src/components/rich-text/index.js | 1 - packages/editor/src/utils/dom.js | 5 ----- packages/jest-preset-default/CHANGELOG.md | 6 ++++++ packages/jest-preset-default/package.json | 1 + packages/jest-preset-default/scripts/setup-globals.js | 2 ++ 15 files changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index ccb15197caada..81bfb9eae8946 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -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', ) ) ); @@ -846,6 +847,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' diff --git a/package-lock.json b/package-lock.json index 012364cd9a18b..ec6fe5a4e2b20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2105,7 +2105,6 @@ "@wordpress/i18n": "file:packages/i18n", "@wordpress/is-shallow-equal": "file:packages/is-shallow-equal", "@wordpress/shortcode": "file:packages/shortcode", - "element-closest": "^2.0.2", "hpq": "^1.2.0", "lodash": "^4.17.10", "rememo": "^3.0.0", @@ -2138,7 +2137,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", @@ -2211,7 +2209,6 @@ "version": "file:packages/dom", "requires": { "@babel/runtime": "^7.0.0", - "element-closest": "^2.0.2", "lodash": "^4.17.10" } }, @@ -2249,7 +2246,6 @@ "@wordpress/wordcount": "file:packages/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", @@ -2317,6 +2313,7 @@ "requires": { "@wordpress/jest-console": "file:packages/jest-console", "babel-jest": "^23.4.2", + "element-closest": "^2.0.2", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", "jest-enzyme": "^6.0.2" @@ -6609,7 +6606,8 @@ "element-closest": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/element-closest/-/element-closest-2.0.2.tgz", - "integrity": "sha1-cqdAoQdFM4LijfnOXbtajfD5Zuw=" + "integrity": "sha1-cqdAoQdFM4LijfnOXbtajfD5Zuw=", + "dev": true }, "elliptic": { "version": "6.4.0", diff --git a/packages/blocks/package.json b/packages/blocks/package.json index c3018a510f15b..40a671343ae88 100644 --- a/packages/blocks/package.json +++ b/packages/blocks/package.json @@ -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", diff --git a/packages/blocks/src/api/raw-handling/index.js b/packages/blocks/src/api/raw-handling/index.js index 557cafac2db16..97216530a6ef2 100644 --- a/packages/blocks/src/api/raw-handling/index.js +++ b/packages/blocks/src/api/raw-handling/index.js @@ -2,8 +2,6 @@ * External dependencies */ import { flatMap, filter, compact } from 'lodash'; -// Also polyfills Element#matches. -import 'element-closest'; /** * Internal dependencies diff --git a/packages/components/package.json b/packages/components/package.json index 2bcfd1c128571..24db55b0e32f3 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -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", diff --git a/packages/components/src/autocomplete/index.js b/packages/components/src/autocomplete/index.js index 17a2d29aeab0c..dff2c8bc5eeb4 100644 --- a/packages/components/src/autocomplete/index.js +++ b/packages/components/src/autocomplete/index.js @@ -3,7 +3,6 @@ */ import classnames from 'classnames'; import { escapeRegExp, find, filter, map, debounce } from 'lodash'; -import 'element-closest'; /** * WordPress dependencies diff --git a/packages/dom/package.json b/packages/dom/package.json index c24b1b954bf5b..08ff20d5db4f2 100644 --- a/packages/dom/package.json +++ b/packages/dom/package.json @@ -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": { diff --git a/packages/dom/src/focusable.js b/packages/dom/src/focusable.js index c94de3d6544e0..133b89d366974 100644 --- a/packages/dom/src/focusable.js +++ b/packages/dom/src/focusable.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import 'element-closest'; - /** * References: * diff --git a/packages/editor/package.json b/packages/editor/package.json index 0304122ead29a..3f19226c7ab4c 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -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", diff --git a/packages/editor/src/components/block-list/index.js b/packages/editor/src/components/block-list/index.js index a1f69889e0c00..695f5f318d1e3 100644 --- a/packages/editor/src/components/block-list/index.js +++ b/packages/editor/src/components/block-list/index.js @@ -11,7 +11,6 @@ import { last, } from 'lodash'; import classnames from 'classnames'; -import 'element-closest'; /** * WordPress dependencies diff --git a/packages/editor/src/components/rich-text/index.js b/packages/editor/src/components/rich-text/index.js index a96f2e525ecc0..6ba993227004f 100644 --- a/packages/editor/src/components/rich-text/index.js +++ b/packages/editor/src/components/rich-text/index.js @@ -12,7 +12,6 @@ import { merge, noop, } from 'lodash'; -import 'element-closest'; /** * WordPress dependencies diff --git a/packages/editor/src/utils/dom.js b/packages/editor/src/utils/dom.js index ccd8c88dc4327..1e3400f2a2f8f 100644 --- a/packages/editor/src/utils/dom.js +++ b/packages/editor/src/utils/dom.js @@ -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 diff --git a/packages/jest-preset-default/CHANGELOG.md b/packages/jest-preset-default/CHANGELOG.md index fcac125602407..c88405e6652b0 100644 --- a/packages/jest-preset-default/CHANGELOG.md +++ b/packages/jest-preset-default/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.1.0 (Unreleased) + +### New Features + +- Browser globals setup now includes polyfill for [`Element#closest`](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest) + ## 2.0.0 (2018-07-12) ### Breaking Change diff --git a/packages/jest-preset-default/package.json b/packages/jest-preset-default/package.json index c7f86252bac18..d61b0ec16f34f 100644 --- a/packages/jest-preset-default/package.json +++ b/packages/jest-preset-default/package.json @@ -28,6 +28,7 @@ "dependencies": { "@wordpress/jest-console": "file:../jest-console", "babel-jest": "^23.4.2", + "element-closest": "^2.0.2", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", "jest-enzyme": "^6.0.2" diff --git a/packages/jest-preset-default/scripts/setup-globals.js b/packages/jest-preset-default/scripts/setup-globals.js index e03f036a0029b..b87de77bbf18c 100644 --- a/packages/jest-preset-default/scripts/setup-globals.js +++ b/packages/jest-preset-default/scripts/setup-globals.js @@ -1,3 +1,5 @@ +require( 'element-closest' ); + // These are necessary to load TinyMCE successfully global.URL = window.URL; global.window.tinyMCEPreInit = { From 68bc9e7f4029f71211e600e9a5613d405c5b0129 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 12 Sep 2018 10:41:57 -0400 Subject: [PATCH 2/7] Scripts: Add support for license ignore --- packages/scripts/CHANGELOG.md | 7 ++++- packages/scripts/README.md | 21 ++++++++++++++ packages/scripts/scripts/check-licenses.js | 32 ++++++++++++++++++++-- packages/scripts/utils/index.js | 13 +++++++-- 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 5b7529e603019..927d71ffa13e0 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.3.0 (Unreleased) + +### Improvements + +- New flag `--ignore` for `check-licenses` script + ## 2.2.1 (2018-09-05) ### Bug Fix @@ -8,7 +14,6 @@ - Updated dependencies: `jest`, `npm-package-json-lint` and `read-pkg-up` - ## 2.0.0 (2018-07-12) ### Breaking Change diff --git a/packages/scripts/README.md b/packages/scripts/README.md index c8620ab3e8ad8..f0981b79ee344 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -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). diff --git a/packages/scripts/scripts/check-licenses.js b/packages/scripts/scripts/check-licenses.js index 649f9646dde33..706cfd405eb27 100644 --- a/packages/scripts/scripts/check-licenses.js +++ b/packages/scripts/scripts/check-licenses.js @@ -3,12 +3,13 @@ */ const spawn = require( 'cross-spawn' ); const { existsSync, readFileSync } = require( 'fs' ); +const { sep } = require( 'path' ); const chalk = require( 'chalk' ); /** * Internal dependencies */ -const { hasCliArg } = require( '../utils' ); +const { getCliArg, hasCliArg } = require( '../utils' ); /* * WARNING: Changes to this file may inadvertently cause us to distribute code that @@ -24,6 +25,13 @@ const ERROR = chalk.reset.inverse.bold.red( ' ERROR ' ); const prod = hasCliArg( '--prod' ) || hasCliArg( '--production' ); const dev = hasCliArg( '--dev' ) || hasCliArg( '--development' ); const gpl2 = hasCliArg( '--gpl2' ); +const ignored = hasCliArg( '--ignore' ) ? + getCliArg( '--ignore' ) + // "--ignore=a, b" -> "[ 'a', ' b' ]" + .split( ',' ) + // "[ 'a', ' b' ]" -> "[ 'a', 'b' ]" + .map( ( moduleName ) => moduleName.trim() ) : + []; /* * A list of license strings that we've found to be GPL2 compatible. @@ -155,6 +163,23 @@ const checkLicense = ( allowedLicense, licenseType ) => { return undefined !== subLicenseTypes.find( ( subLicenseType ) => checkLicense( allowedLicense, subLicenseType ) ); }; +/** + * Returns true if the given module path is not to be ignored for consideration + * in license validation, or false otherwise. + * + * @param {string} moduleName Module path. + * + * @return {boolean} Whether module path is not to be ignored. + */ +const isNotIgnoredModule = ( moduleName ) => ( + ! ignored.some( ( ignoredItem ) => ( + // `moduleName` is a file path to the module directory. Assume CLI arg + // is passed as basename of package (directory(s) after node_modules). + // Prefix with sep to avoid false-positives on prefixing variations. + moduleName.endsWith( sep + ignoredItem ) + ) ) +); + // Use `npm ls` to grab a list of all the packages. const child = spawn.sync( 'npm', [ 'ls', @@ -163,7 +188,10 @@ const child = spawn.sync( 'npm', [ ...( dev ? [ '--dev' ] : [] ), ] ); -const modules = child.stdout.toString().split( '\n' ); +const modules = child.stdout + .toString() + .split( '\n' ) + .filter( isNotIgnoredModule ); modules.forEach( ( path ) => { if ( ! path ) { diff --git a/packages/scripts/utils/index.js b/packages/scripts/utils/index.js index 8607f547052a0..cda8dc66ddaf6 100644 --- a/packages/scripts/utils/index.js +++ b/packages/scripts/utils/index.js @@ -11,10 +11,16 @@ const path = require( 'path' ); const { getPackagePath, hasPackageProp } = require( './package' ); const { exit, getCliArgs } = require( './process' ); -const first = ( list ) => list[ 0 ]; +const getCliArg = ( arg ) => { + for ( const cliArg of getCliArgs() ) { + const [ name, value ] = cliArg.split( '=' ); + if ( name === arg ) { + return value || null; + } + } +}; -const hasCliArg = ( arg ) => getCliArgs() - .some( ( value ) => first( value.split( '=' ) ) === arg ); +const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined; const fromProjectRoot = ( fileName ) => path.join( path.dirname( getPackagePath() ), fileName ); @@ -86,6 +92,7 @@ module.exports = { fromConfigRoot, getCliArgs, hasCliArg, + getCliArg, hasProjectFile, hasPackageProp, spawnScript, From 92bc67d8e8f9360e8e8a7cff40c86cd5aa01bd57 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 12 Sep 2018 10:44:41 -0400 Subject: [PATCH 3/7] 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. https://github.com/jsdom/jsdom/issues/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 --- package-lock.json | 88 +++++++++---------- package.json | 2 +- packages/jest-preset-default/CHANGELOG.md | 6 -- packages/jest-preset-default/package.json | 1 - .../scripts/setup-globals.js | 2 - 5 files changed, 44 insertions(+), 55 deletions(-) diff --git a/package-lock.json b/package-lock.json index ec6fe5a4e2b20..fd9ede4f6ed6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2313,7 +2313,6 @@ "requires": { "@wordpress/jest-console": "file:packages/jest-console", "babel-jest": "^23.4.2", - "element-closest": "^2.0.2", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", "jest-enzyme": "^6.0.2" @@ -6093,15 +6092,6 @@ "integrity": "sha512-+7prCSORpXNeR4/fUP3rL+TzqtiFfhMvTd7uEqMdgPvLPt4+uzFUeufx5RHjGTACCargg/DiEt/moMQmvnfkog==", "dev": true }, - "cssstyle": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-0.3.1.tgz", - "integrity": "sha512-tNvaxM5blOnxanyxI6panOsnfiyLRj3HV4qjqqS45WPNS1usdYWRUQjqTEEELK73lpeP/1KoIGYUwrBn/VcECA==", - "dev": true, - "requires": { - "cssom": "0.3.x" - } - }, "currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", @@ -6603,12 +6593,6 @@ "integrity": "sha1-2wQ1IcldfjA/2PNFvtwzSc+wcp4=", "dev": true }, - "element-closest": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/element-closest/-/element-closest-2.0.2.tgz", - "integrity": "sha1-cqdAoQdFM4LijfnOXbtajfD5Zuw=", - "dev": true - }, "elliptic": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz", @@ -12233,44 +12217,74 @@ } }, "jsdom": { - "version": "11.11.0", - "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-11.11.0.tgz", - "integrity": "sha512-ou1VyfjwsSuWkudGxb03FotDajxAto6USAlmMZjE2lc0jCznt7sBWkhfRBRaWwbnmDqdMSTKTLT5d9sBFkkM7A==", + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-11.12.0.tgz", + "integrity": "sha512-y8Px43oyiBM13Zc1z780FrfNLJCXTL40EWlty/LXUtcjykRBNgLlCjWXpfSPBl2iv+N7koQN+dvqszHZgT/Fjw==", "dev": true, "requires": { - "abab": "^1.0.4", - "acorn": "^5.3.0", + "abab": "^2.0.0", + "acorn": "^5.5.3", "acorn-globals": "^4.1.0", "array-equal": "^1.0.0", "cssom": ">= 0.3.2 < 0.4.0", - "cssstyle": ">= 0.3.1 < 0.4.0", + "cssstyle": "^1.0.0", "data-urls": "^1.0.0", - "domexception": "^1.0.0", - "escodegen": "^1.9.0", + "domexception": "^1.0.1", + "escodegen": "^1.9.1", "html-encoding-sniffer": "^1.0.2", - "left-pad": "^1.2.0", - "nwsapi": "^2.0.0", + "left-pad": "^1.3.0", + "nwsapi": "^2.0.7", "parse5": "4.0.0", "pn": "^1.1.0", - "request": "^2.83.0", + "request": "^2.87.0", "request-promise-native": "^1.0.5", "sax": "^1.2.4", "symbol-tree": "^3.2.2", - "tough-cookie": "^2.3.3", + "tough-cookie": "^2.3.4", "w3c-hr-time": "^1.0.1", "webidl-conversions": "^4.0.2", "whatwg-encoding": "^1.0.3", "whatwg-mimetype": "^2.1.0", "whatwg-url": "^6.4.1", - "ws": "^4.0.0", + "ws": "^5.2.0", "xml-name-validator": "^3.0.0" }, "dependencies": { + "abab": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.0.tgz", + "integrity": "sha512-sY5AXXVZv4Y1VACTtR11UJCPHHudgY5i26Qj5TypE6DKlIApbwb5uqhXcJ5UUGbvZNRh7EeIoW+LrJumBsKp7w==", + "dev": true + }, + "cssstyle": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-1.1.1.tgz", + "integrity": "sha512-364AI1l/M5TYcFH83JnOH/pSqgaNnKmYgKrm0didZMGKWjQB60dymwWy1rKUgL3J1ffdq9xVi2yGLHdSjjSNog==", + "dev": true, + "requires": { + "cssom": "0.3.x" + } + }, + "nwsapi": { + "version": "2.0.9", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.0.9.tgz", + "integrity": "sha512-nlWFSCTYQcHk/6A9FFnfhKc14c3aFhfdNBXgo8Qgi9QTBu/qg3Ww+Uiz9wMzXd1T8GFxPc2QIHB6Qtf2XFryFQ==", + "dev": true + }, "parse5": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse5/-/parse5-4.0.0.tgz", "integrity": "sha512-VrZ7eOd3T1Fk4XWNXMgiGBK/z0MG48BWG2uQNU4I72fkQuKUTZpl+u9k+CxEG0twMVzSmXEEz12z5Fnw1jIQFA==", "dev": true + }, + "ws": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", + "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", + "dev": true, + "requires": { + "async-limiter": "~1.0.0" + } } } }, @@ -14291,12 +14305,6 @@ "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, - "nwsapi": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.0.4.tgz", - "integrity": "sha512-Zt6HRR6RcJkuj5/N9zeE7FN6YitRW//hK2wTOwX274IBphbY3Zf5+yn5mZ9v/SzAOTMjQNxZf9KkmPLWn0cV4g==", - "dev": true - }, "oauth-sign": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", @@ -21232,16 +21240,6 @@ "write-json-file": "^2.2.0" } }, - "ws": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz", - "integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==", - "dev": true, - "requires": { - "async-limiter": "~1.0.0", - "safe-buffer": "~5.1.0" - } - }, "x-is-string": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/x-is-string/-/x-is-string-0.1.0.tgz", diff --git a/package.json b/package.json index 1e65d03a2d1ef..faf487d0c7738 100644 --- a/package.json +++ b/package.json @@ -157,7 +157,7 @@ "build:packages": "cross-env EXCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,jest-console,postcss-themes node ./bin/packages/build.js", "build": "npm run build:packages && cross-env NODE_ENV=production webpack", "check-engines": "check-node-version --package", - "check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2\" \"wp-scripts check-licenses --dev\"", + "check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2 --ignore=abab\" \"wp-scripts check-licenses --dev --ignore=abab\"", "ci": "concurrently \"npm run lint\" \"npm run test-unit:coverage-ci\"", "predev": "npm run check-engines", "dev": "npm run build:packages && concurrently \"cross-env webpack --watch\" \"npm run dev:packages\"", diff --git a/packages/jest-preset-default/CHANGELOG.md b/packages/jest-preset-default/CHANGELOG.md index c88405e6652b0..fcac125602407 100644 --- a/packages/jest-preset-default/CHANGELOG.md +++ b/packages/jest-preset-default/CHANGELOG.md @@ -1,9 +1,3 @@ -## 2.1.0 (Unreleased) - -### New Features - -- Browser globals setup now includes polyfill for [`Element#closest`](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest) - ## 2.0.0 (2018-07-12) ### Breaking Change diff --git a/packages/jest-preset-default/package.json b/packages/jest-preset-default/package.json index d61b0ec16f34f..c7f86252bac18 100644 --- a/packages/jest-preset-default/package.json +++ b/packages/jest-preset-default/package.json @@ -28,7 +28,6 @@ "dependencies": { "@wordpress/jest-console": "file:../jest-console", "babel-jest": "^23.4.2", - "element-closest": "^2.0.2", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", "jest-enzyme": "^6.0.2" diff --git a/packages/jest-preset-default/scripts/setup-globals.js b/packages/jest-preset-default/scripts/setup-globals.js index b87de77bbf18c..e03f036a0029b 100644 --- a/packages/jest-preset-default/scripts/setup-globals.js +++ b/packages/jest-preset-default/scripts/setup-globals.js @@ -1,5 +1,3 @@ -require( 'element-closest' ); - // These are necessary to load TinyMCE successfully global.URL = window.URL; global.window.tinyMCEPreInit = { From 02abe3fcb3b502590b52268274940525fbe28c0c Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 12 Sep 2018 11:26:32 -0400 Subject: [PATCH 4/7] 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: https://github.com/facebook/jest/issues/6766 See: https://github.com/facebook/jest/pull/6792 --- test/unit/jest.config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/jest.config.json b/test/unit/jest.config.json index fec5aad1e2bc8..833b60e421ae1 100644 --- a/test/unit/jest.config.json +++ b/test/unit/jest.config.json @@ -20,6 +20,7 @@ "setupFiles": [ "core-js/fn/symbol/async-iterator" ], + "testURL": "http://localhost", "testPathIgnorePatterns": [ "/node_modules/", "/test/e2e", From 437b39b309cd74101d31d38e2e40cb6a1512ed9a Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 13 Sep 2018 17:37:53 +1000 Subject: [PATCH 5/7] 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.json | 2 +- packages/scripts/scripts/check-licenses.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index faf487d0c7738..1e65d03a2d1ef 100644 --- a/package.json +++ b/package.json @@ -157,7 +157,7 @@ "build:packages": "cross-env EXCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,jest-console,postcss-themes node ./bin/packages/build.js", "build": "npm run build:packages && cross-env NODE_ENV=production webpack", "check-engines": "check-node-version --package", - "check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2 --ignore=abab\" \"wp-scripts check-licenses --dev --ignore=abab\"", + "check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2\" \"wp-scripts check-licenses --dev\"", "ci": "concurrently \"npm run lint\" \"npm run test-unit:coverage-ci\"", "predev": "npm run check-engines", "dev": "npm run build:packages && concurrently \"cross-env webpack --watch\" \"npm run dev:packages\"", diff --git a/packages/scripts/scripts/check-licenses.js b/packages/scripts/scripts/check-licenses.js index 706cfd405eb27..b8b27828d63ff 100644 --- a/packages/scripts/scripts/check-licenses.js +++ b/packages/scripts/scripts/check-licenses.js @@ -45,6 +45,7 @@ const gpl2CompatibleLicenses = [ 'BSD', 'BSD-2-Clause', 'BSD-3-Clause', + 'BSD-3-Clause-W3C', 'BSD-like', 'CC-BY-3.0', 'CC-BY-4.0', @@ -111,6 +112,9 @@ const licenseFileStrings = { BSD: [ 'Redistributions in binary form must reproduce the above copyright notice,', ], + 'BSD-3-Clause-W3C': [ + 'W3C 3-clause BSD License', + ], MIT: [ 'Permission is hereby granted, free of charge,', '## License\n\nMIT', @@ -221,6 +225,11 @@ modules.forEach( ( path ) => { ); let licenseType = typeof license === 'object' ? license.type : license; + // Check if the license we've detected is telling us to look in the license file, instead. + if ( licenseType && licenseFiles.find( ( licenseFile ) => licenseType.indexOf( licenseFile ) >= 0 ) ) { + licenseType = undefined; + } + /* * If we haven't been able to detect a license in the package.json file, try reading * it from the files defined in licenseFiles, instead. From 2cc72cc6824056c37635de94b9260ebce4b46f7e Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 17 Sep 2018 11:08:44 -0400 Subject: [PATCH 6/7] Package: Scripts: Use String#includes for improved code clarity --- packages/scripts/scripts/check-licenses.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/scripts/scripts/check-licenses.js b/packages/scripts/scripts/check-licenses.js index b8b27828d63ff..cbd291d4dd109 100644 --- a/packages/scripts/scripts/check-licenses.js +++ b/packages/scripts/scripts/check-licenses.js @@ -147,7 +147,7 @@ const checkLicense = ( allowedLicense, licenseType ) => { } // We can skip the parsing below if there isn't an 'OR' in the license. - if ( licenseType.indexOf( 'OR' ) < 0 ) { + if ( ! licenseType.includes( 'OR' ) ) { return false; } @@ -226,7 +226,7 @@ modules.forEach( ( path ) => { let licenseType = typeof license === 'object' ? license.type : license; // Check if the license we've detected is telling us to look in the license file, instead. - if ( licenseType && licenseFiles.find( ( licenseFile ) => licenseType.indexOf( licenseFile ) >= 0 ) ) { + if ( licenseType && licenseFiles.find( ( licenseFile ) => licenseType.includes( licenseFile ) ) ) { licenseType = undefined; } From 4376ae266a0f5bb5de4563227b2ce5fd29eb598c Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 17 Sep 2018 11:09:08 -0400 Subject: [PATCH 7/7] Package: Scripts: Add CHANGELOG notes for improved license file detection --- packages/scripts/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 927d71ffa13e0..24e55d021243d 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -3,6 +3,8 @@ ### 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)