newspack-scripts 1.0.1 → 1.2.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.
@@ -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,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.1",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "newspack-scripts": "./bin/newspack-scripts.js"
@@ -8,14 +8,18 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
- "@babel/core": "^7.16.0",
11
+ "@automattic/calypso-build": "^10.0.0",
12
+ "@babel/preset-env": "^7.16.4",
12
13
  "@testing-library/jest-dom": "^5.15.1",
13
14
  "@testing-library/react": "^12.1.2",
15
+ "autoprefixer": "^10.4.0",
14
16
  "babel-jest": "^27.4.2",
15
- "babel-loader": "^8.2.3",
16
17
  "cross-spawn": "^7.0.3",
17
18
  "jest": "^27.4.3",
18
- "jest-environment-jsdom": "^27.4.3"
19
+ "jest-environment-jsdom": "^27.4.3",
20
+ "postcss": "^8.4.4",
21
+ "postcss-focus-within": "^5.0.1",
22
+ "webpack": "^5.65.0"
19
23
  },
20
24
  "scripts": {
21
25
  "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,23 +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
  },
20
+ transformIgnorePatterns: ["/node_modules/(?!newspack-scripts/)"],
22
21
  moduleNameMapper: {
23
- "\\.(scss|css)$": "babel-jest"
22
+ "\\.(scss|css)$": path.resolve(__dirname, "utils/babelJestTransformer.js")
24
23
  },
25
24
  testEnvironment: "jsdom",
26
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
+ };