newspack-scripts 5.5.1 → 5.5.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.
@@ -1,18 +1,17 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- const spawn = require("cross-spawn");
4
- const path = require("path");
5
- const modules = require("./utils/modules");
6
- const utils = require("./utils/index.js");
3
+ const spawn = require( 'cross-spawn' );
4
+ const utils = require( './utils/index.js' );
5
+ const tsc = require.resolve( 'typescript/bin/tsc' );
7
6
 
8
- utils.log("Starting TypeScript check…");
7
+ utils.log( 'Starting TypeScript check…' );
9
8
 
10
- const result = spawn.sync(`${process.cwd()}/node_modules/.bin/tsc`, [], {
11
- stdio: "inherit",
12
- });
9
+ const result = spawn.sync( tsc, [], {
10
+ stdio: 'inherit',
11
+ } );
13
12
 
14
- if (result.status === 0) {
15
- utils.log("All good!");
13
+ if ( result.status === 0 ) {
14
+ utils.log( 'All good!' );
16
15
  }
17
16
 
18
- process.exit(result.status);
17
+ process.exit( result.status );
@@ -1,14 +1,13 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- const babelJest = require("babel-jest").default;
3
+ const babelJest = require( 'babel-jest' ).default;
4
4
 
5
- module.exports = babelJest.createTransformer({
6
- presets: [
7
- require.resolve("@babel/preset-env"),
8
- require.resolve("@babel/preset-typescript"),
9
- require.resolve("@automattic/calypso-build/babel/default"),
10
- require.resolve("@automattic/calypso-build/babel/wordpress-element"),
11
- ],
12
- babelrc: false,
13
- configFile: false,
14
- });
5
+ module.exports = babelJest.createTransformer( {
6
+ presets: [
7
+ require.resolve( '@babel/preset-env' ),
8
+ require.resolve( '@babel/preset-typescript' ),
9
+ require.resolve( '@wordpress/babel-preset-default' ),
10
+ ],
11
+ babelrc: false,
12
+ configFile: false,
13
+ } );
@@ -1,25 +1,25 @@
1
- const { exec } = require("child_process");
1
+ const { exec } = require( 'child_process' );
2
2
 
3
- const { version } = require("../../package.json");
3
+ const { version } = require( '../../package.json' );
4
4
 
5
- const log = (content, type) => {
6
- console.log(
7
- `[newspack-scripts@${version}]${type ? `[${type}]` : ""} ${content}`
8
- );
5
+ const log = ( content, type ) => {
6
+ console.log(
7
+ `[newspack-scripts@${ version }]${ type ? `[${ type }]` : '' } ${ content }`
8
+ );
9
9
  };
10
10
 
11
11
  const getGitBranch = () =>
12
- new Promise((resolve, reject) => {
13
- return exec("git rev-parse --abbrev-ref HEAD", (err, stdout) => {
14
- if (err) {
15
- reject(`getGitBranch Error: ${err}`);
16
- } else if (typeof stdout === "string") {
17
- resolve(stdout.trim());
18
- }
19
- });
20
- });
12
+ new Promise( ( resolve, reject ) => {
13
+ return exec( 'git rev-parse --abbrev-ref HEAD', ( err, stdout ) => {
14
+ if ( err ) {
15
+ reject( `getGitBranch Error: ${ err }` );
16
+ } else if ( typeof stdout === 'string' ) {
17
+ resolve( stdout.trim() );
18
+ }
19
+ } );
20
+ } );
21
21
 
22
22
  module.exports = {
23
- log,
24
- getGitBranch,
23
+ log,
24
+ getGitBranch,
25
25
  };
@@ -1,45 +1,45 @@
1
- import "@testing-library/jest-dom";
1
+ import '@testing-library/jest-dom';
2
2
 
3
3
  // matchMedia does not exist in JSDOM, see https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
4
- Object.defineProperty(window, "matchMedia", {
5
- writable: true,
6
- value: jest.fn().mockImplementation((query) => ({
7
- matches: false,
8
- media: query,
9
- onchange: null,
10
- addListener: jest.fn(), // deprecated
11
- removeListener: jest.fn(), // deprecated
12
- addEventListener: jest.fn(),
13
- removeEventListener: jest.fn(),
14
- dispatchEvent: jest.fn(),
15
- })),
16
- });
4
+ Object.defineProperty( window, 'matchMedia', {
5
+ writable: true,
6
+ value: jest.fn().mockImplementation( ( query ) => ( {
7
+ matches: false,
8
+ media: query,
9
+ onchange: null,
10
+ addListener: jest.fn(), // deprecated
11
+ removeListener: jest.fn(), // deprecated
12
+ addEventListener: jest.fn(),
13
+ removeEventListener: jest.fn(),
14
+ dispatchEvent: jest.fn(),
15
+ } ) ),
16
+ } );
17
17
 
18
18
  // IntersectionObserver does not exist in JSDOM.
19
19
  // https://stackoverflow.com/a/58651649/3772847
20
20
  class MockIntersectionObserver {
21
- constructor(fn) {
22
- this.root = null;
23
- this.rootMargin = "";
24
- this.thresholds = [];
25
- this.disconnect = () => null;
26
- this.observe = () => null;
27
- this.takeRecords = () => [];
28
- this.unobserve = () => null;
21
+ constructor( fn ) {
22
+ this.root = null;
23
+ this.rootMargin = '';
24
+ this.thresholds = [];
25
+ this.disconnect = () => null;
26
+ this.observe = () => null;
27
+ this.takeRecords = () => [];
28
+ this.unobserve = () => null;
29
29
 
30
- // Pass a single entry, which is intersecting.
31
- fn([{ isIntersecting: true }]);
32
- }
30
+ // Pass a single entry, which is intersecting.
31
+ fn( [ { isIntersecting: true } ] );
32
+ }
33
33
  }
34
34
 
35
- Object.defineProperty(window, "IntersectionObserver", {
36
- writable: true,
37
- configurable: true,
38
- value: MockIntersectionObserver,
39
- });
35
+ Object.defineProperty( window, 'IntersectionObserver', {
36
+ writable: true,
37
+ configurable: true,
38
+ value: MockIntersectionObserver,
39
+ } );
40
40
 
41
- Object.defineProperty(global, "IntersectionObserver", {
42
- writable: true,
43
- configurable: true,
44
- value: MockIntersectionObserver,
45
- });
41
+ Object.defineProperty( global, 'IntersectionObserver', {
42
+ writable: true,
43
+ configurable: true,
44
+ value: MockIntersectionObserver,
45
+ } );
@@ -1,6 +1,25 @@
1
- const fs = require("fs");
1
+ const fs = require( 'fs' );
2
+
3
+ const rootDirectory = fs.realpathSync( process.cwd() );
2
4
 
3
5
  module.exports = {
4
- rootDirectory: fs.realpathSync(process.cwd()),
5
- calypsoBuild: require.resolve("@automattic/calypso-build/bin/calypso-build"),
6
+ rootDirectory,
7
+ // Get webpack bundle args for `build` and `start` commands.
8
+ buildArgs: ( cmd, args = [] ) => {
9
+ if ( 'build' !== cmd && 'start' !== cmd ) {
10
+ return [ cmd, ...args ];
11
+ }
12
+
13
+ const defaults = [
14
+ '--config',
15
+ 'webpack.config.js',
16
+ ];
17
+
18
+ // Default build path: ./dist
19
+ if ( ! args.includes( '--output-path' ) ) {
20
+ defaults.push( '--output-path', 'dist' );
21
+ }
22
+
23
+ return [ cmd, ...defaults, ...args ];
24
+ },
6
25
  };
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const spawn = require( 'cross-spawn' );
4
+ const modules = require( './utils/modules' );
5
+ const utils = require( './utils/index.js' );
6
+ const wpScripts = require.resolve( '@wordpress/scripts/bin/wp-scripts' );
7
+
8
+ const args = process.argv.slice( 2 );
9
+ const cmd = args.shift();
10
+
11
+ utils.log( `Running ${ cmd }...` );
12
+
13
+ const result = spawn.sync( wpScripts, modules.buildArgs( cmd, args ), {
14
+ cwd: modules.rootDirectory,
15
+ stdio: 'inherit',
16
+ env: { ...process.env, NODE_ENV: 'build' === cmd ? 'production' : 'development' },
17
+ } );
18
+
19
+ if ( result.status === 0 ) {
20
+ utils.log( `${ cmd } complete!` );
21
+ }
22
+
23
+ process.exit( result.status );
@@ -1,5 +1,5 @@
1
1
  description: >
2
- Lint the JS & SCSS files.
2
+ Lint the JS & SCSS (temporarily skipped) files.
3
3
 
4
4
  executor: default
5
5
 
@@ -8,4 +8,4 @@ steps:
8
8
  - set_node_version
9
9
  - run:
10
10
  name: Run Linter
11
- command: npm run lint
11
+ command: npm run lint:js # Temporarily skip linting SCSS due to stylelint config updates. Remove :js when ready to re-enable linting of SCSS.
package/scripts/build.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- const spawn = require("cross-spawn");
4
- const modules = require("./utils/modules");
5
- const utils = require("./utils/index.js");
6
-
7
- utils.log("Starting to build…");
8
-
9
- const buildResult = spawn.sync(process.execPath, [modules.calypsoBuild], {
10
- cwd: modules.rootDirectory,
11
- stdio: "inherit",
12
- env: { ...process.env, NODE_ENV: "production" },
13
- });
14
-
15
- if (buildResult.status === 0) {
16
- utils.log("Build succeeded!");
17
- }
18
-
19
- process.exit(buildResult.status);
package/scripts/watch.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- const spawn = require("cross-spawn");
4
- const modules = require("./utils/modules");
5
- const utils = require("./utils/index.js");
6
-
7
- utils.log("Starting to watch…");
8
-
9
- spawn.sync(process.execPath, [modules.calypsoBuild, "--watch"], {
10
- cwd: modules.rootDirectory,
11
- stdio: "inherit",
12
- env: { ...process.env, NODE_ENV: "development" },
13
- });