newspack-scripts 1.0.2 → 1.3.0

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.
package/README.md CHANGED
@@ -10,3 +10,11 @@ Will run `jest` tests. Useful flags:
10
10
 
11
11
  - `--watch` to run in file watch mode,
12
12
  - `--coverage` to collect test coverage
13
+
14
+ ### build
15
+
16
+ Will run `calypso-build`, creating optimised production builds.
17
+
18
+ ### start
19
+
20
+ Will run `calypso-build` in watch mode.
@@ -4,7 +4,7 @@ const spawn = require("cross-spawn");
4
4
 
5
5
  const [scriptName, ...nodeArgs] = process.argv.slice(2);
6
6
 
7
- if (["test"].includes(scriptName)) {
7
+ if (["test", "build", "start"].includes(scriptName)) {
8
8
  const result = spawn.sync(
9
9
  process.execPath,
10
10
  [require.resolve("../scripts/" + scriptName), ...nodeArgs],
@@ -0,0 +1,9 @@
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
+ };
9
+ };
@@ -0,0 +1,32 @@
1
+ module.exports = {
2
+ extends: [
3
+ "plugin:@wordpress/eslint-plugin/recommended",
4
+ "plugin:react/recommended",
5
+ "plugin:import/errors",
6
+ "plugin:import/warnings",
7
+ ],
8
+ env: {
9
+ browser: true,
10
+ jest: true,
11
+ },
12
+ ignorePatterns: ["dist/", "node_modules/"],
13
+ parser: "@babel/eslint-parser",
14
+ rules: {
15
+ "no-console": "off",
16
+ camelcase: "off",
17
+ // Disallow importing or requiring packages that are not listed in package.json
18
+ // This prevents us from depending on transitive dependencies, which could break in unexpected ways.
19
+ "import/no-extraneous-dependencies": ["error", { packageDir: "." }],
20
+ // There's a conflict with prettier here:
21
+ "react/jsx-curly-spacing": "off",
22
+ // Skip prop types validation for now
23
+ "react/prop-types": "off",
24
+ "react/react-in-jsx-scope": "off",
25
+ "react/self-closing-comp": "error",
26
+ // JSDoc rules overrides
27
+ "jsdoc/require-returns": "off",
28
+ "jsdoc/require-param": "off",
29
+ // Deprecated rules
30
+ "jsx-a11y/no-onchange": "off",
31
+ },
32
+ };
@@ -0,0 +1,27 @@
1
+ const path = require("path");
2
+
3
+ const getWebpackConfig = require("@automattic/calypso-build/webpack.config.js");
4
+
5
+ module.exports = (...args) => {
6
+ const config = getWebpackConfig(...args);
7
+
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;
27
+ };
@@ -0,0 +1,6 @@
1
+ const postcssFocusWithin = require("postcss-focus-within");
2
+ const autoprefixer = require("autoprefixer");
3
+
4
+ module.exports = {
5
+ plugins: [autoprefixer(), postcssFocusWithin()]
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newspack-scripts",
3
- "version": "1.0.2",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "newspack-scripts": "./bin/newspack-scripts.js"
@@ -8,12 +8,25 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
+ "@automattic/calypso-build": "^10.0.0",
12
+ "@babel/eslint-parser": "^7.16.3",
13
+ "@babel/preset-env": "^7.16.4",
11
14
  "@testing-library/jest-dom": "^5.15.1",
12
15
  "@testing-library/react": "^12.1.2",
16
+ "@wordpress/eslint-plugin": "^9.3.0",
17
+ "autoprefixer": "^10.4.0",
13
18
  "babel-jest": "^27.4.2",
14
19
  "cross-spawn": "^7.0.3",
20
+ "eslint": "^7.32.0",
21
+ "eslint-config-prettier": "^8.3.0",
22
+ "eslint-plugin-import": "^2.25.3",
23
+ "eslint-plugin-jest": "^25.3.0",
24
+ "eslint-plugin-react": "^7.27.1",
15
25
  "jest": "^27.4.3",
16
- "jest-environment-jsdom": "^27.4.3"
26
+ "jest-environment-jsdom": "^27.4.3",
27
+ "postcss": "^8.4.4",
28
+ "postcss-focus-within": "^5.0.1",
29
+ "webpack": "^5.65.0"
17
30
  },
18
31
  "scripts": {
19
32
  "semantic-release": "semantic-release"
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ const spawn = require("cross-spawn");
4
+ const modules = require("./utils/modules");
5
+
6
+ spawn.sync(process.execPath, [modules.calypsoBuild], {
7
+ cwd: modules.rootDirectory,
8
+ stdio: "inherit",
9
+ env: { ...process.env, NODE_ENV: "production" }
10
+ });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ const spawn = require("cross-spawn");
4
+ const modules = require("./utils/modules");
5
+
6
+ spawn.sync(process.execPath, [modules.calypsoBuild, "--watch"], {
7
+ cwd: modules.rootDirectory,
8
+ stdio: "inherit",
9
+ env: { ...process.env, NODE_ENV: "development" }
10
+ });
package/scripts/test.js CHANGED
@@ -4,24 +4,22 @@ process.env.BABEL_ENV = "test";
4
4
  process.env.NODE_ENV = "test";
5
5
 
6
6
  const jest = require("jest");
7
- const fs = require("fs");
8
7
  const path = require("path");
9
- const execSync = require("child_process").execSync;
10
8
 
11
- let argv = process.argv.slice(2);
9
+ const modules = require("./utils/modules");
12
10
 
13
- const appDirectory = fs.realpathSync(process.cwd());
11
+ let argv = process.argv.slice(2);
14
12
 
15
13
  const JEST_CONFIG = {
16
- rootDir: path.resolve(appDirectory),
17
- setupFilesAfterEnv: [path.resolve(__dirname, "utils/jest-setup.js")],
14
+ rootDir: modules.rootDirectory,
15
+ setupFilesAfterEnv: [path.resolve(__dirname, "utils/jestSetup.js")],
18
16
  testMatch: ["<rootDir>/**/*test.js?(x)"],
19
17
  transform: {
20
- "^.+\\.js?$": "babel-jest"
18
+ "^.+\\.js?$": path.resolve(__dirname, "utils/babelJestTransformer.js")
21
19
  },
22
20
  transformIgnorePatterns: ["/node_modules/(?!newspack-scripts/)"],
23
21
  moduleNameMapper: {
24
- "\\.(scss|css)$": "babel-jest"
22
+ "\\.(scss|css)$": path.resolve(__dirname, "utils/babelJestTransformer.js")
25
23
  },
26
24
  testEnvironment: "jsdom",
27
25
  collectCoverageFrom: [
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ const babelJest = require("babel-jest").default;
4
+
5
+ module.exports = babelJest.createTransformer({
6
+ presets: [
7
+ require.resolve("@babel/preset-env"),
8
+ require.resolve("@automattic/calypso-build/babel/default"),
9
+ require.resolve("@automattic/calypso-build/babel/wordpress-element")
10
+ ],
11
+ babelrc: false,
12
+ configFile: false
13
+ });
File without changes
@@ -0,0 +1,7 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ module.exports = {
5
+ rootDirectory: fs.realpathSync(process.cwd()),
6
+ calypsoBuild: require.resolve("@automattic/calypso-build/bin/calypso-build")
7
+ };