newspack-scripts 5.5.0 → 5.5.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ jobs:
24
24
  command: node --version
25
25
  - run:
26
26
  name: install
27
- command: npm install
27
+ command: npm install --legacy-peer-deps
28
28
  - run:
29
29
  name: release
30
30
  command: npm run semantic-release || true
package/.eslintrc.js ADDED
@@ -0,0 +1,9 @@
1
+ require( '@rushstack/eslint-patch/modern-module-resolution' );
2
+
3
+ module.exports = {
4
+ extends: [ './config/eslintrc.js' ],
5
+ ignorePatterns: [ 'node_modules' ],
6
+ rules: {
7
+ '@typescript-eslint/no-var-requires': 'off',
8
+ },
9
+ };
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- 16.11.1
1
+ lts/*
package/README.md CHANGED
@@ -15,11 +15,11 @@ Will run `jest` tests. Useful flags:
15
15
 
16
16
  ### build
17
17
 
18
- Will run `calypso-build`, creating optimised production builds.
18
+ Will run `wp-scripts build` to create optimised production builds.
19
19
 
20
20
  ### watch
21
21
 
22
- Will run `calypso-build` in watch mode.
22
+ Will run `wp-scripts start` to start a development build in devserver/watch mode.
23
23
 
24
24
  ### commit
25
25
 
@@ -47,6 +47,15 @@ Will validate TypeScript code in the project. This requires a `tsconfig.json` fi
47
47
  }
48
48
  ```
49
49
 
50
+ ### proxy
51
+
52
+ Allows you to proxy NPM CLI commands through this repository's dependencies, so if a repository consumes the `newspack-scripts` NPM package, it can access any executables installed as a dependency in [package.json](https://github.com/Automattic/newspack-scripts/blob/trunk/package.json). e.g. `newspack-scripts proxy semantic-release --dry-run` will run `semantic-release --dry-run` but using the executable from `newspack-scripts` instead of whatever repository you're running the command from. This allows for more flexible use of NPM commands where the prefab configs and scripts this repo provides are too opinionated or aren't sufficient.
53
+
54
+ Other examples:
55
+
56
+ - `newspack-scripts proxy eslint 'src/**/*.{js,jsx,ts,tsx}'` will lint all JS/JSX/TS/TSX files inside the `./src` directory.
57
+ - `newspack-scripts proxy stylelint 'src/**/*.scss'` will lint all SCSS files inside the `./src` directory.
58
+
50
59
  ---
51
60
 
52
61
  ## Semantic Release
@@ -154,10 +163,10 @@ module.exports = {
154
163
 
155
164
  ### stylelint
156
165
 
157
- Install `stylelint` via npm and reference this package's config file when running it, e.g.:
166
+ Use this package's stylelint executable and config file when running it, e.g.:
158
167
 
159
168
  ```shell
160
- stylelint '**/*.scss' --syntax scss --config=./node_modules/newspack-scripts/config/stylelint.config.js
169
+ newspack-scripts proxy stylelint '**/*.scss' --customSyntax postcss-scss --config=./node_modules/newspack-scripts/config/stylelint.config.js
161
170
  ```
162
171
 
163
172
  _Note: Due to issue with dependency resolving, you might end up a different version of `prettier` in project's `node_modules` and `node_modules/newspack-scripts/node_modules`. See https://github.com/Automattic/newspack-scripts/issues/1 for more information._
@@ -207,4 +216,4 @@ Note that before the first time updating you'll need to set the API key for Circ
207
216
 
208
217
  ### `@wordpress/*` packages
209
218
 
210
- This project list [`@wordpress/*` packages](https://github.com/WordPress/gutenberg/tree/trunk/packages) as dependencies in order to provide them to consumers. In a project using `calypso-build` (e.g. a consumer of `newspack-scripts`), the `@wordpress/*` packages are sourced from WP Core, not `node_modules`. The packages should be included in `node_modules`, though, to be available in other environments – notably when running tests. See [Dependency Extraction Webpack Plugin](https://www.npmjs.com/package/@wordpress/dependency-extraction-webpack-plugin) for more information.
219
+ This project list [`@wordpress/*` packages](https://github.com/WordPress/gutenberg/tree/trunk/packages) as dependencies in order to provide them to consumers. In a project using `@wordpress/scripts` (e.g. a consumer of `newspack-scripts`), the `@wordpress/*` packages are sourced from WP Core, not `node_modules`. The packages should be included in `node_modules`, though, to be available in other environments – notably when running tests. See [Dependency Extraction Webpack Plugin](https://www.npmjs.com/package/@wordpress/dependency-extraction-webpack-plugin) for more information.
@@ -1,43 +1,46 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const spawn = require("cross-spawn");
4
- const utils = require("../scripts/utils/index.js");
3
+ const spawn = require( 'cross-spawn' );
4
+ const utils = require( '../scripts/utils/index.js' );
5
5
 
6
- const [scriptName, ...nodeArgs] = process.argv.slice(2);
6
+ const [ scriptName, ...nodeArgs ] = process.argv.slice( 2 );
7
7
 
8
8
  if (
9
- [
10
- "test",
11
- "build",
12
- "watch",
13
- "commit",
14
- "commitlint",
15
- "release",
16
- "typescript-check",
17
- ].includes(scriptName)
9
+ [
10
+ 'test',
11
+ 'build',
12
+ 'watch',
13
+ 'commit',
14
+ 'commitlint',
15
+ 'eslint',
16
+ 'proxy',
17
+ 'stylelint',
18
+ 'release',
19
+ 'typescript-check',
20
+ ].includes( scriptName )
18
21
  ) {
19
- const result = spawn.sync(
20
- process.execPath,
21
- [require.resolve("../scripts/" + scriptName), ...nodeArgs],
22
- { stdio: "inherit" }
23
- );
24
- if (result.signal) {
25
- if (result.signal === "SIGKILL") {
26
- utils.log(
27
- "The build failed because the process exited too early. " +
28
- "This probably means the system ran out of memory or someone called " +
29
- "`kill -9` on the process."
30
- );
31
- } else if (result.signal === "SIGTERM") {
32
- utils.log(
33
- "The build failed because the process exited too early. " +
34
- "Someone might have called `kill` or `killall`, or the system could " +
35
- "be shutting down."
36
- );
37
- }
38
- process.exit(1);
39
- }
40
- process.exit(result.status);
22
+ const result = spawn.sync(
23
+ process.execPath,
24
+ [ require.resolve( '../scripts/' + scriptName ), ...nodeArgs ],
25
+ { stdio: 'inherit' }
26
+ );
27
+ if ( result.signal ) {
28
+ if ( result.signal === 'SIGKILL' ) {
29
+ utils.log(
30
+ 'The build failed because the process exited too early. ' +
31
+ 'This probably means the system ran out of memory or someone called ' +
32
+ '`kill -9` on the process.'
33
+ );
34
+ } else if ( result.signal === 'SIGTERM' ) {
35
+ utils.log(
36
+ 'The build failed because the process exited too early. ' +
37
+ 'Someone might have called `kill` or `killall`, or the system could ' +
38
+ 'be shutting down.'
39
+ );
40
+ }
41
+ process.exit( 1 );
42
+ }
43
+ process.exit( result.status );
41
44
  } else {
42
- utils.log(`Unknown script "${scriptName}".`);
45
+ utils.log( `Unknown script "${ scriptName }".` );
43
46
  }
@@ -1,9 +1,8 @@
1
1
  module.exports = api => {
2
- api.cache(true);
3
- return {
4
- presets: [
5
- "@automattic/calypso-build/babel/default",
6
- "@automattic/calypso-build/babel/wordpress-element"
7
- ]
8
- };
2
+ api.cache( true );
3
+ return {
4
+ presets: [
5
+ '@wordpress/babel-preset-default',
6
+ ],
7
+ };
9
8
  };
@@ -1 +1 @@
1
- module.exports = { extends: ["@commitlint/config-conventional"] };
1
+ module.exports = { extends: [ '@commitlint/config-conventional' ] };
@@ -1,65 +1,74 @@
1
- // Assume `@wordpress/*` packages are available. This is because `calypso-build` is using
1
+ const wpRecommended = require.resolve( '@wordpress/eslint-plugin/configs/recommended' );
2
+ const reactRecommended = require.resolve( '@wordpress/eslint-plugin/configs/react' );
3
+
4
+ // Assume `@wordpress/*` packages are available. This is because `@wordpress/scripts` is using
2
5
  // Dependency Extraction Webpack Plugin to use core WP packages instead of those from
3
6
  // node_modules. The packages should still be part of the project (they are listed in this
4
7
  // project's package.json) so that they are available in testing environment.
5
8
  // More on this:
6
9
  // - https://www.npmjs.com/package/@wordpress/dependency-extraction-webpack-plugin
7
10
  // - https://github.com/WordPress/gutenberg/issues/35630
8
- const GLOBALLY_AVAILABLE_PACKAGES = ["@wordpress/.*"];
11
+ const GLOBALLY_AVAILABLE_PACKAGES = [ '@wordpress/.*' ];
9
12
 
10
13
  module.exports = {
11
- extends: [
12
- "plugin:@wordpress/eslint-plugin/recommended",
13
- "plugin:react/recommended",
14
- "plugin:import/errors",
15
- "plugin:import/warnings",
16
- "plugin:@typescript-eslint/eslint-recommended",
17
- "plugin:@typescript-eslint/recommended",
18
- ],
19
- env: {
20
- browser: true,
21
- jest: true,
22
- },
23
- parser: "@typescript-eslint/parser",
24
- plugins: ["@typescript-eslint"],
25
- settings: {
26
- "import/resolver": {
27
- node: {
28
- extensions: [".js", ".jsx", ".ts", ".tsx"],
29
- },
30
- },
31
- },
32
- ignorePatterns: ["dist/", "node_modules/"],
33
- parser: "@typescript-eslint/parser",
34
- rules: {
35
- "no-console": "off",
36
- camelcase: "off",
37
- // Some dependencies are injected by WP, and should not be declared in package.json (won't be used anyway).
38
- // See https://github.com/WordPress/gutenberg/blob/e035f71/packages/dependency-extraction-webpack-plugin/README.md#behavior-with-scripts
39
- // Unfortunately there's no "ignore" option for this rule, so it's disabled altogether.
40
- "import/no-extraneous-dependencies": "off",
41
- "import/no-unresolved": ["error", { ignore: GLOBALLY_AVAILABLE_PACKAGES }],
42
- // There's a conflict with prettier here:
43
- "react/jsx-curly-spacing": "off",
44
- // Skip prop types validation for now
45
- "react/prop-types": "off",
46
- "react/react-in-jsx-scope": "off",
47
- "react/self-closing-comp": "error",
48
- // JSDoc rules overrides
49
- "jsdoc/require-returns": "off",
50
- "jsdoc/require-param": "off",
51
- // Deprecated rules
52
- "jsx-a11y/no-onchange": "off",
53
- // For TypeScript type declarations.
54
- camelcase: "off",
55
- "@typescript-eslint/no-empty-function": "off",
56
- // Fail on unused vars.
57
- "@typescript-eslint/no-unused-vars": "error",
58
- // Disallow logging.
59
- "no-console": "error",
60
- // Handle the issue where no-shadow is a false positive when declaring TS enums.
61
- // See https://github.com/typescript-eslint/typescript-eslint/issues/2483
62
- "no-shadow": "off",
63
- "@typescript-eslint/no-shadow": "error",
64
- },
14
+ extends: [
15
+ 'plugin:import/errors',
16
+ 'plugin:import/warnings',
17
+ 'plugin:@typescript-eslint/eslint-recommended',
18
+ 'plugin:@typescript-eslint/recommended',
19
+ wpRecommended,
20
+ reactRecommended,
21
+ ],
22
+ env: {
23
+ browser: true,
24
+ jest: true,
25
+ },
26
+ parser: '@typescript-eslint/parser',
27
+ plugins: [ '@typescript-eslint' ],
28
+ settings: {
29
+ 'import/resolver': {
30
+ node: {
31
+ extensions: [ '.js', '.jsx', '.ts', '.tsx' ],
32
+ },
33
+ },
34
+ },
35
+ ignorePatterns: [ 'dist/', 'node_modules/', 'scripts/' ],
36
+ parser: '@typescript-eslint/parser',
37
+ rules: {
38
+ 'arrow-parens': 'off',
39
+ camelcase: 'off',
40
+ 'no-console': 'off',
41
+ 'no-mixed-operators': 'off',
42
+ 'space-before-function-paren': 'off',
43
+ 'wrap-iife': 'off',
44
+ // Some dependencies are injected by WP, and should not be declared in package.json (won't be used anyway).
45
+ // See https://github.com/WordPress/gutenberg/blob/e035f71/packages/dependency-extraction-webpack-plugin/README.md#behavior-with-scripts
46
+ // Unfortunately there's no "ignore" option for this rule, so it's disabled altogether.
47
+ 'import/no-extraneous-dependencies': 'off',
48
+ 'import/no-unresolved': [ 'error', { ignore: GLOBALLY_AVAILABLE_PACKAGES } ],
49
+ 'import/namespace': 'off',
50
+ // There's a conflict with prettier here:
51
+ 'react/jsx-curly-spacing': 'off',
52
+ // Skip prop types validation for now
53
+ 'react/prop-types': 'off',
54
+ 'react/react-in-jsx-scope': 'off',
55
+ 'react/self-closing-comp': 'error',
56
+ 'react-hooks/exhaustive-deps': 'off',
57
+ // JSDoc rules overrides
58
+ 'jsdoc/require-returns': 'off',
59
+ 'jsdoc/require-param': 'off',
60
+ // Deprecated rules
61
+ 'jsx-a11y/no-onchange': 'off',
62
+ '@typescript-eslint/no-empty-function': 'off',
63
+ // Fail on unused vars.
64
+ '@typescript-eslint/no-unused-vars': 'error',
65
+ // Disallow logging.
66
+ 'no-console': 'error',
67
+ // Handle the issue where no-shadow is a false positive when declaring TS enums.
68
+ // See https://github.com/typescript-eslint/typescript-eslint/issues/2483
69
+ 'no-shadow': 'off',
70
+ '@typescript-eslint/no-shadow': 'error',
71
+ '@typescript-eslint/ban-ts-comment': 'warn',
72
+ '@typescript-eslint/no-explicit-any': 'warn',
73
+ },
65
74
  };
@@ -1,27 +1,25 @@
1
- const path = require("path");
1
+ const path = require( 'path' );
2
+ require( '@wordpress/browserslist-config' );
3
+ const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
2
4
 
3
- const getWebpackConfig = require("@automattic/calypso-build/webpack.config.js");
5
+ module.exports = ( ...args ) => {
6
+ let config = { ...defaultConfig };
4
7
 
5
- module.exports = (...args) => {
6
- const config = getWebpackConfig(...args);
8
+ // Merge config extensions into default config.
9
+ args.forEach( extension => {
10
+ config = { ...config, ...extension };
11
+ } );
7
12
 
8
- const scssRuleIndex = config.module.rules.findIndex(rule =>
9
- rule.test.toString().match(/\(sc\|sa\|c\)ss/)
10
- );
11
- if (scssRuleIndex !== -1) {
12
- const scssRule = config.module.rules[scssRuleIndex];
13
- const postCssLoaderIndex = scssRule.use.findIndex(
14
- loader => loader.loader && loader.loader.indexOf("postcss") > 0
15
- );
16
- if (postCssLoaderIndex !== -1) {
17
- const postCssLoader = scssRule.use[postCssLoaderIndex];
18
- const postCssConfigPath = path.resolve(__dirname, "postcss.config.js");
19
- // Replace calypso-build's PostCSS config with this project's one.
20
- postCssLoader.options.postcssOptions.config = postCssConfigPath;
21
- config.module.rules[scssRuleIndex].use[
22
- postCssLoaderIndex
23
- ] = postCssLoader;
24
- }
25
- }
26
- return config;
13
+ // Ensure that webpack resolves modules from the Newspack Scripts node_modules as well as the root repo's node_modules.
14
+ config.resolve.modules = [
15
+ path.resolve( __dirname, '../node_modules' ),
16
+ 'node_modules',
17
+ ];
18
+
19
+ // Clear cacheGroups so that CSS files don't get the `style-` prefix.
20
+ if ( config?.optimization?.splitChunks?.cacheGroups?.style ) {
21
+ delete config.optimization.splitChunks.cacheGroups.style;
22
+ }
23
+
24
+ return config;
27
25
  };
@@ -1,6 +1,6 @@
1
- const postcssFocusWithin = require("postcss-focus-within");
2
- const autoprefixer = require("autoprefixer");
1
+ const postcssFocusWithin = require( 'postcss-focus-within' );
2
+ const autoprefixer = require( 'autoprefixer' );
3
3
 
4
4
  module.exports = {
5
- plugins: [autoprefixer(), postcssFocusWithin()]
5
+ plugins: [ autoprefixer(), postcssFocusWithin() ],
6
6
  };
@@ -1,30 +1,32 @@
1
1
  module.exports = {
2
- extends: ["stylelint-config-standard"],
3
- rules: {
4
- "rule-empty-line-before": null,
5
- "at-rule-empty-line-before": null,
6
- "comment-empty-line-before": null,
7
- "no-descending-specificity": null,
8
- "function-url-quotes": null,
9
- "font-weight-notation": null,
10
- "color-named": null,
11
- "selector-class-pattern": null,
12
- "custom-property-pattern": null,
13
- "at-rule-no-unknown": null,
14
- "alpha-value-notation": null,
15
- "color-function-notation": null,
16
- "selector-not-notation": null,
17
- "function-no-unknown": [
18
- true,
19
- {
20
- ignoreFunctions: ["/color/"],
21
- },
22
- ],
23
- "annotation-no-unknown": [
24
- true,
25
- {
26
- ignoreAnnotations: ["/default/"],
27
- },
28
- ],
29
- },
2
+ extends: [ 'stylelint-config-standard' ],
3
+ rules: {
4
+ 'rule-empty-line-before': null,
5
+ 'at-rule-empty-line-before': null,
6
+ 'comment-empty-line-before': null,
7
+ 'no-descending-specificity': null,
8
+ 'function-url-quotes': null,
9
+ 'font-weight-notation': null,
10
+ 'color-named': null,
11
+ 'selector-class-pattern': null,
12
+ 'custom-property-pattern': null,
13
+ 'at-rule-no-unknown': null,
14
+ 'alpha-value-notation': null,
15
+ 'color-function-notation': null,
16
+ 'selector-not-notation': null,
17
+ 'function-no-unknown': [
18
+ true,
19
+ {
20
+ ignoreFunctions: [ '/color/' ],
21
+ },
22
+ ],
23
+ 'annotation-no-unknown': [
24
+ true,
25
+ {
26
+ ignoreAnnotations: [ '/default/' ],
27
+ },
28
+ ],
29
+ 'media-query-no-invalid': null,
30
+ 'media-feature-range-notation': null,
31
+ },
30
32
  };
@@ -1,21 +1,25 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "compilerOptions": {
4
- "noEmit": true,
5
- "composite": true,
6
- "noEmitHelpers": true,
7
- "skipLibCheck": true,
8
- "lib": ["ESNext", "DOM", "DOM.Iterable"],
9
- "target": "es6",
10
- "module": "ESNext",
11
- "esModuleInterop": true,
12
- "jsx": "react-jsx",
13
- "strict": true,
14
- "isolatedModules": true,
15
- "moduleResolution": "node",
16
- "resolveJsonModule": true,
17
- "forceConsistentCasingInFileNames": true,
18
- "allowJs": true,
19
- "checkJs": false
20
- }
21
- }
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "composite": true,
6
+ "noEmitHelpers": true,
7
+ "skipLibCheck": true,
8
+ "lib": [
9
+ "ESNext",
10
+ "DOM",
11
+ "DOM.Iterable"
12
+ ],
13
+ "target": "es6",
14
+ "module": "ESNext",
15
+ "esModuleInterop": true,
16
+ "jsx": "react-jsx",
17
+ "strict": true,
18
+ "isolatedModules": true,
19
+ "moduleResolution": "node",
20
+ "resolveJsonModule": true,
21
+ "forceConsistentCasingInFileNames": true,
22
+ "allowJs": true,
23
+ "checkJs": false
24
+ }
25
+ }