From b353ff9f47e7e20091749b258213b3b743f17e19 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 9 Mar 2024 11:32:57 +1300 Subject: [PATCH] feat!: remove `globalMutableWebpackConfig` --- package/__tests__/development.js | 25 ------------------- package/__tests__/production.js | 19 -------------- package/__tests__/staging.js | 20 --------------- package/__tests__/test.js | 15 ----------- package/index.d.ts | 1 - package/index.js | 16 ++++-------- .../config/webpack/commonWebpackConfig.js | 1 - 7 files changed, 5 insertions(+), 92 deletions(-) diff --git a/package/__tests__/development.js b/package/__tests__/development.js index 92110df47..b39f30a9e 100644 --- a/package/__tests__/development.js +++ b/package/__tests__/development.js @@ -38,29 +38,4 @@ describe('Development environment', () => { expect(webpackConfig.devServer).toEqual(undefined) }) }) - - describe('globalMutableWebpackConfig', () => { - beforeEach(() => jest.resetModules()) - - test('should use development config and environment including devServer if WEBPACK_SERVE', () => { - process.env.RAILS_ENV = 'development' - process.env.NODE_ENV = 'development' - process.env.WEBPACK_SERVE = 'true' - const { globalMutableWebpackConfig: webpackConfig } = require('../index') - - expect(webpackConfig.output.path).toEqual(resolve('public', 'packs')) - expect(webpackConfig.output.publicPath).toEqual('/packs/') - }) - - test('should use development config and environment if WEBPACK_SERVE', () => { - process.env.RAILS_ENV = 'development' - process.env.NODE_ENV = 'development' - process.env.WEBPACK_SERVE = undefined - const { globalMutableWebpackConfig: webpackConfig } = require('../index') - - expect(webpackConfig.output.path).toEqual(resolve('public', 'packs')) - expect(webpackConfig.output.publicPath).toEqual('/packs/') - expect(webpackConfig.devServer).toEqual(undefined) - }) - }) }) diff --git a/package/__tests__/production.js b/package/__tests__/production.js index 20ceadf02..bc1b60355 100644 --- a/package/__tests__/production.js +++ b/package/__tests__/production.js @@ -29,23 +29,4 @@ describe('Production environment', () => { }) }) }) - - describe('globalMutableWebpackConfig', () => { - beforeEach(() => jest.resetModules()) - - test('should use production config and environment', () => { - process.env.RAILS_ENV = 'production' - process.env.NODE_ENV = 'production' - - const { globalMutableWebpackConfig: webpackConfig } = require('../index') - - expect(webpackConfig.output.path).toEqual(resolve('public', 'packs')) - expect(webpackConfig.output.publicPath).toEqual('/packs/') - - expect(webpackConfig).toMatchObject({ - devtool: 'source-map', - stats: 'normal' - }) - }) - }) }) diff --git a/package/__tests__/staging.js b/package/__tests__/staging.js index 4c397691d..ad1cd36e8 100644 --- a/package/__tests__/staging.js +++ b/package/__tests__/staging.js @@ -30,24 +30,4 @@ describe('Custom environment', () => { }) }) }) - - describe('globalMutableWebpackConfig', () => { - beforeEach(() => jest.resetModules()) - - test('should use staging config and default production environment', () => { - process.env.RAILS_ENV = 'staging' - delete process.env.NODE_ENV - - const { globalMutableWebpackConfig: webpackConfig } = require('../index') - - expect(webpackConfig.output.path).toEqual( - resolve('public', 'packs-staging') - ) - expect(webpackConfig.output.publicPath).toEqual('/packs-staging/') - expect(webpackConfig).toMatchObject({ - devtool: 'source-map', - stats: 'normal' - }) - }) - }) }) diff --git a/package/__tests__/test.js b/package/__tests__/test.js index 757da2c62..794516132 100644 --- a/package/__tests__/test.js +++ b/package/__tests__/test.js @@ -25,19 +25,4 @@ describe('Test environment', () => { expect(webpackConfig.devServer).toEqual(undefined) }) }) - - describe('globalMutableWebpackConfig', () => { - beforeEach(() => jest.resetModules()) - - test('should use test config and production environment', () => { - process.env.RAILS_ENV = 'test' - process.env.NODE_ENV = 'test' - - const { globalMutableWebpackConfig: webpackConfig } = require('../index') - - expect(webpackConfig.output.path).toEqual(resolve('public', 'packs-test')) - expect(webpackConfig.output.publicPath).toEqual('/packs-test/') - expect(webpackConfig.devServer).toEqual(undefined) - }) - }) }) diff --git a/package/index.d.ts b/package/index.d.ts index ff6a446d0..7cd277735 100644 --- a/package/index.d.ts +++ b/package/index.d.ts @@ -35,7 +35,6 @@ declare module 'shakapacker' { export const config: Config export const devServer: Record export function generateWebpackConfig(extraConfig?: Configuration): Configuration - export const globalMutableWebpackConfig: Configuration export const baseConfig: Configuration export const env: Env export const rules: Record diff --git a/package/index.js b/package/index.js index a1fec30a3..a08e90789 100644 --- a/package/index.js +++ b/package/index.js @@ -12,13 +12,6 @@ const env = require('./env') const { moduleExists, canProcess } = require('./utils/helpers') const inliningCss = require('./utils/inliningCss') -const globalMutableWebpackConfig = () => { - const { nodeEnv } = env - const path = resolve(__dirname, 'environments', `${nodeEnv}.js`) - const environmentConfig = existsSync(path) ? require(path) : baseConfig - return environmentConfig -} - const generateWebpackConfig = (extraConfig = {}, ...extraArgs) => { if (extraArgs.length > 0) { throw new Error( @@ -26,16 +19,17 @@ const generateWebpackConfig = (extraConfig = {}, ...extraArgs) => { ) } - const environmentConfig = globalMutableWebpackConfig() - const immutable = webpackMerge.merge({}, environmentConfig, extraConfig) - return immutable + const { nodeEnv } = env + const path = resolve(__dirname, 'environments', `${nodeEnv}.js`) + const environmentConfig = existsSync(path) ? require(path) : baseConfig + + return webpackMerge.merge({}, environmentConfig, extraConfig) } module.exports = { config, // shakapacker.yml devServer, generateWebpackConfig, - globalMutableWebpackConfig: globalMutableWebpackConfig(), baseConfig, env, rules, diff --git a/spec/dummy/config/webpack/commonWebpackConfig.js b/spec/dummy/config/webpack/commonWebpackConfig.js index dccbaa7b6..bf14bc6a7 100644 --- a/spec/dummy/config/webpack/commonWebpackConfig.js +++ b/spec/dummy/config/webpack/commonWebpackConfig.js @@ -1,6 +1,5 @@ // Common configuration applying to client and server configuration -// const { globalMutableWebpackConfig: baseClientWebpackConfig, merge } = require('shakapacker') const { generateWebpackConfig, merge } = require('shakapacker') const commonOptions = { resolve: {