Skip to content

Commit

Permalink
feat!: remove globalMutableWebpackConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Mar 8, 2024
1 parent d029100 commit ccaf14e
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 92 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Changes since the last non-beta release.

The usage of those has been deprecated in Shakapacker v7 and now fully removed in v8. See the [v7 Upgrade Guide](./docs/v7_upgrade.md) for more information if you are still yet to address this deprecation.

- Remove `globalMutableWebpackConfig` global [PR 439](https://github.com/shakacode/shakapacker/pull/439) by [G-Rath](https://github.com/g-rath).

Use `generateWebpackConfig` instead.

- Remove `yarn_install` rake task, and stop installing js packages automatically as part of `assets:precompile` [PR 412](https://github.com/shakacode/shakapacker/pull/412) by [G-Rath](https://github.com/g-rath).

Expand Down
25 changes: 0 additions & 25 deletions package/__tests__/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
19 changes: 0 additions & 19 deletions package/__tests__/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
})
})
})
20 changes: 0 additions & 20 deletions package/__tests__/staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
})
})
})
15 changes: 0 additions & 15 deletions package/__tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
1 change: 0 additions & 1 deletion package/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ declare module 'shakapacker' {
export const config: Config
export const devServer: Record<string, unknown>
export function generateWebpackConfig(extraConfig?: Configuration): Configuration
export const globalMutableWebpackConfig: Configuration
export const baseConfig: Configuration
export const env: Env
export const rules: Record<string, unknown>
Expand Down
16 changes: 5 additions & 11 deletions package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,24 @@ 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(
'Only one extra config may be passed here - use webpack-merge to merge configs before passing them to Shakapacker'
)
}

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,
Expand Down
1 change: 0 additions & 1 deletion spec/dummy/config/webpack/commonWebpackConfig.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down

0 comments on commit ccaf14e

Please sign in to comment.