From 34948c417ae0466c4612d50541a7ac3450fb8258 Mon Sep 17 00:00:00 2001 From: "Xunnamius (Romulus)" Date: Thu, 5 Aug 2021 13:57:59 -0700 Subject: [PATCH] build: modernize build process --- .changelogrc.js | 1 + .eslintrc.js | 2 ++ babel.config.js | 1 + commitlint.config.js | 2 ++ expect-env.js | 1 + jest.config.js | 2 ++ lint-staged.config.js | 2 ++ next.config.js | 2 ++ prettier.config.js | 2 ++ release.config.js | 2 ++ spellcheck-commit.js | 2 ++ webpack.config.js | 20 +++++++++++++++----- 12 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.changelogrc.js b/.changelogrc.js index b4d16aa..b116ddc 100644 --- a/.changelogrc.js +++ b/.changelogrc.js @@ -1,3 +1,4 @@ +'use strict'; // ? See https://github.com/conventional-changelog/conventional-changelog const debug = require('debug')( diff --git a/.eslintrc.js b/.eslintrc.js index 77f98ae..19efc83 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,5 @@ +'use strict'; + const debug = require('debug')(`${require('./package.json').name}:eslint-config`); const restrictedGlobals = require('confusing-browser-globals'); diff --git a/babel.config.js b/babel.config.js index 20b64d9..0d13419 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,3 +1,4 @@ +'use strict'; // * Every now and then, we adopt best practices from CRA // * https://tinyurl.com/yakv4ggx diff --git a/commitlint.config.js b/commitlint.config.js index d2d81a7..2877826 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { extends: ['@commitlint/config-conventional'], rules: { diff --git a/expect-env.js b/expect-env.js index 16830d9..ba96299 100644 --- a/expect-env.js +++ b/expect-env.js @@ -1,3 +1,4 @@ +'use strict'; /* eslint-disable no-console */ const debug = require('debug')(`${require('./package.json').name}:expect-env`); diff --git a/jest.config.js b/jest.config.js index 7869b2a..f86250c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { restoreMocks: true, resetMocks: true, diff --git a/lint-staged.config.js b/lint-staged.config.js index 15e0faa..a022a6a 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { '*.md': 'remark -o --use reference-links --use gfm --use frontmatter', 'package.json': 'sort-package-json', diff --git a/next.config.js b/next.config.js index e4a3fab..6cac157 100644 --- a/next.config.js +++ b/next.config.js @@ -1,3 +1,5 @@ +'use strict'; + const withBundleAnalyzer = require('@next/bundle-analyzer'); const { verifyEnvironment } = require('./expect-env'); diff --git a/prettier.config.js b/prettier.config.js index c220b5c..b4d523f 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { endOfLine: 'lf', printWidth: 80, diff --git a/release.config.js b/release.config.js index 8a31b29..e2bac4f 100644 --- a/release.config.js +++ b/release.config.js @@ -1,3 +1,5 @@ +'use strict'; + const debug = require('debug')( `${require('./package.json').name}:semantic-release-config` ); diff --git a/spellcheck-commit.js b/spellcheck-commit.js index 6626539..86a9f30 100644 --- a/spellcheck-commit.js +++ b/spellcheck-commit.js @@ -1,4 +1,6 @@ +'use strict'; /* eslint-disable no-console */ + const spellcheck = require('spellchecker'); const pkg = require('./package.json'); const read = require('fs').promises.readFile; diff --git a/webpack.config.js b/webpack.config.js index bd949cb..db44c8d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + // This webpack config is used to transpile src to dist, compile externals, // compile executables, etc @@ -7,12 +9,14 @@ const { verifyEnvironment } = require('./expect-env'); const nodeExternals = require('webpack-node-externals'); const debug = require('debug')(`${require('./package.json').name}:webpack-config`); -let env = {}; +let sanitizedEnv = {}; +let { NODE_ENV, ...sanitizedProcessEnv } = { ...process.env, NODE_ENV: 'production' }; try { require('fs').accessSync('.env'); - env = require('dotenv').config().parsed; - debug('new env vars: %O', env); + ({ NODE_ENV, ...sanitizedEnv } = require('dotenv').config().parsed); + debug(`NODE_ENV: ${NODE_ENV}`); + debug('sanitized env: %O', sanitizedEnv); } catch (e) { debug(`env support disabled; reason: ${e}`); } @@ -20,9 +24,15 @@ try { verifyEnvironment(); const envPlugins = [ + // ? NODE_ENV is not a "default" (unlike below) but an explicit overwrite + new DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(NODE_ENV) + }), // ? Load our .env results as the defaults (overridden by process.env) - new EnvironmentPlugin({ ...env, ...process.env }), - // ? Create shim process.env for undefined vars (per my tastes!) + new EnvironmentPlugin({ ...sanitizedEnv, ...sanitizedProcessEnv }), + // ? Create shim process.env for undefined vars + // ! The above already replaces all process.env.X occurrences in the code + // ! first, so plugin order is important here new DefinePlugin({ 'process.env': '{}' }) ];