webpacker 6.0.0.beta.5 → 6.0.0.rc.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/jest.yml +7 -15
- data/.github/workflows/js-lint.yml +7 -15
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +15 -40
- data/.node-version +1 -1
- data/.rubocop.yml +107 -1
- data/CHANGELOG.md +36 -13
- data/CONTRIBUTING.md +19 -0
- data/Gemfile.lock +105 -104
- data/README.md +197 -167
- data/config/webpacker.yml +1 -1
- data/docs/deployment.md +128 -0
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +57 -23
- data/docs/v6_upgrade.md +113 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/{packs/entrypoints/application.js → application.js} +4 -9
- data/lib/install/bin/webpack +4 -7
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpacker.yml +19 -20
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +48 -19
- data/lib/tasks/webpacker/binstubs.rake +2 -2
- data/lib/tasks/webpacker/check_node.rake +3 -0
- data/lib/tasks/webpacker/check_yarn.rake +4 -1
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/install.rake +2 -2
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -11
- data/lib/tasks/yarn.rake +38 -0
- data/lib/webpacker/commands.rb +19 -15
- data/lib/webpacker/configuration.rb +19 -8
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +6 -3
- data/lib/webpacker/env.rb +5 -1
- data/lib/webpacker/helper.rb +14 -8
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +1 -2
- data/lib/webpacker/railtie.rb +8 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +27 -7
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/development.js +4 -11
- data/package/__tests__/env.js +8 -4
- data/package/babel/preset.js +0 -1
- data/package/config.js +3 -3
- data/package/env.js +6 -3
- data/package/environments/__tests__/base.js +3 -3
- data/package/environments/base.js +13 -13
- data/package/environments/development.js +36 -36
- data/package/environments/production.js +1 -1
- data/package/index.js +2 -0
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +1 -1
- data/package/rules/file.js +1 -1
- data/package/rules/sass.js +1 -2
- data/package/rules/stylus.js +1 -1
- data/package/utils/get_style_rule.js +4 -2
- data/package.json +25 -29
- data/test/command_test.rb +76 -0
- data/test/configuration_test.rb +1 -1
- data/test/dev_server_runner_test.rb +5 -2
- data/test/helper_test.rb +48 -34
- data/test/manifest_test.rb +16 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +2 -2
- data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/test/test_app/config/webpacker.yml +2 -4
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/public/packs/manifest.json +12 -5
- data/test/webpacker_test.rb +21 -0
- data/webpacker.gemspec +2 -2
- data/yarn.lock +2357 -3262
- metadata +24 -12
- data/6_0_upgrade.md +0 -62
data/package/__tests__/env.js
CHANGED
@@ -15,7 +15,8 @@ describe('Env', () => {
|
|
15
15
|
railsEnv: 'development',
|
16
16
|
nodeEnv: 'development',
|
17
17
|
isProduction: false,
|
18
|
-
isDevelopment: true
|
18
|
+
isDevelopment: true,
|
19
|
+
runningWebpackDevServer: false
|
19
20
|
})
|
20
21
|
})
|
21
22
|
|
@@ -26,7 +27,8 @@ describe('Env', () => {
|
|
26
27
|
railsEnv: 'development',
|
27
28
|
nodeEnv: 'production',
|
28
29
|
isProduction: true,
|
29
|
-
isDevelopment: false
|
30
|
+
isDevelopment: false,
|
31
|
+
runningWebpackDevServer: false
|
30
32
|
})
|
31
33
|
})
|
32
34
|
|
@@ -37,7 +39,8 @@ describe('Env', () => {
|
|
37
39
|
railsEnv: 'production',
|
38
40
|
nodeEnv: 'production',
|
39
41
|
isProduction: true,
|
40
|
-
isDevelopment: false
|
42
|
+
isDevelopment: false,
|
43
|
+
runningWebpackDevServer: false
|
41
44
|
})
|
42
45
|
})
|
43
46
|
|
@@ -48,7 +51,8 @@ describe('Env', () => {
|
|
48
51
|
railsEnv: 'staging',
|
49
52
|
nodeEnv: 'production',
|
50
53
|
isProduction: true,
|
51
|
-
isDevelopment: false
|
54
|
+
isDevelopment: false,
|
55
|
+
runningWebpackDevServer: false
|
52
56
|
})
|
53
57
|
})
|
54
58
|
})
|
data/package/babel/preset.js
CHANGED
data/package/config.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
const { resolve } = require('path')
|
2
|
-
const {
|
2
|
+
const { load } = require('js-yaml')
|
3
3
|
const { readFileSync } = require('fs')
|
4
4
|
const { merge } = require('webpack-merge')
|
5
5
|
const { ensureTrailingSlash } = require('./utils/helpers')
|
@@ -9,12 +9,12 @@ const configPath = require('./configPath')
|
|
9
9
|
const defaultConfigPath = require.resolve('../lib/install/config/webpacker.yml')
|
10
10
|
|
11
11
|
const getDefaultConfig = () => {
|
12
|
-
const defaultConfig =
|
12
|
+
const defaultConfig = load(readFileSync(defaultConfigPath), 'utf8')
|
13
13
|
return defaultConfig[railsEnv] || defaultConfig.production
|
14
14
|
}
|
15
15
|
|
16
16
|
const defaults = getDefaultConfig()
|
17
|
-
const app =
|
17
|
+
const app = load(readFileSync(configPath), 'utf8')[railsEnv]
|
18
18
|
|
19
19
|
const config = merge(defaults, app)
|
20
20
|
config.outputPath = resolve(config.public_root_path, config.public_output_path)
|
data/package/env.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const {
|
1
|
+
const { load } = require('js-yaml')
|
2
2
|
const { readFileSync } = require('fs')
|
3
3
|
|
4
4
|
const NODE_ENVIRONMENTS = ['development', 'production', 'test']
|
@@ -12,13 +12,16 @@ const nodeEnv
|
|
12
12
|
const isProduction = nodeEnv === 'production'
|
13
13
|
const isDevelopment = nodeEnv === 'development'
|
14
14
|
|
15
|
-
const config =
|
15
|
+
const config = load(readFileSync(configPath), 'utf8')
|
16
16
|
const availableEnvironments = Object.keys(config).join('|')
|
17
17
|
const regex = new RegExp(`^(${availableEnvironments})$`, 'g')
|
18
18
|
|
19
|
+
const runningWebpackDevServer = process.env.WEBPACK_SERVE === 'true'
|
20
|
+
|
19
21
|
module.exports = {
|
20
22
|
railsEnv: railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT,
|
21
23
|
nodeEnv,
|
22
24
|
isProduction,
|
23
|
-
isDevelopment
|
25
|
+
isDevelopment,
|
26
|
+
runningWebpackDevServer
|
24
27
|
}
|
@@ -29,9 +29,9 @@ describe('Base config', () => {
|
|
29
29
|
})
|
30
30
|
|
31
31
|
test('should return output', () => {
|
32
|
-
expect(baseConfig.output.filename).toEqual('js/[name]
|
32
|
+
expect(baseConfig.output.filename).toEqual('js/[name].js')
|
33
33
|
expect(baseConfig.output.chunkFilename).toEqual(
|
34
|
-
'js/[name]
|
34
|
+
'js/[name].chunk.js'
|
35
35
|
)
|
36
36
|
})
|
37
37
|
|
@@ -44,7 +44,7 @@ describe('Base config', () => {
|
|
44
44
|
})
|
45
45
|
|
46
46
|
test('should return default plugins', () => {
|
47
|
-
expect(baseConfig.plugins.length).toEqual(
|
47
|
+
expect(baseConfig.plugins.length).toEqual(2)
|
48
48
|
})
|
49
49
|
|
50
50
|
test('should return default resolveLoader', () => {
|
@@ -5,19 +5,18 @@ const { basename, dirname, join, relative, resolve } = require('path')
|
|
5
5
|
const extname = require('path-complete-extname')
|
6
6
|
const PnpWebpackPlugin = require('pnp-webpack-plugin')
|
7
7
|
const { sync: globSync } = require('glob')
|
8
|
-
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
9
8
|
const WebpackAssetsManifest = require('webpack-assets-manifest')
|
10
9
|
const webpack = require('webpack')
|
11
10
|
const rules = require('../rules')
|
11
|
+
const { isProduction } = require('../env')
|
12
12
|
const config = require('../config')
|
13
|
-
const { isDevelopment } = require('../env')
|
14
13
|
const { moduleExists } = require('../utils/helpers')
|
15
14
|
|
16
15
|
const getEntryObject = () => {
|
17
16
|
const entries = {}
|
18
17
|
const rootPath = join(config.source_path, config.source_entry_path)
|
19
18
|
|
20
|
-
globSync(`${rootPath}
|
19
|
+
globSync(`${rootPath}/*.*`).forEach((path) => {
|
21
20
|
const namespace = relative(join(rootPath), dirname(path))
|
22
21
|
const name = join(namespace, basename(path, extname(path)))
|
23
22
|
let assetPaths = resolve(path)
|
@@ -53,7 +52,6 @@ const getModulePaths = () => {
|
|
53
52
|
const getPlugins = () => {
|
54
53
|
const plugins = [
|
55
54
|
new webpack.EnvironmentPlugin(process.env),
|
56
|
-
new CaseSensitivePathsPlugin(),
|
57
55
|
new WebpackAssetsManifest({
|
58
56
|
entrypoints: true,
|
59
57
|
writeToDisk: true,
|
@@ -64,15 +62,12 @@ const getPlugins = () => {
|
|
64
62
|
]
|
65
63
|
|
66
64
|
if (moduleExists('css-loader') && moduleExists('mini-css-extract-plugin')) {
|
65
|
+
const hash = isProduction ? '-[contenthash:8]' : ''
|
67
66
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
68
67
|
plugins.push(
|
69
68
|
new MiniCssExtractPlugin({
|
70
|
-
filename:
|
71
|
-
|
72
|
-
: 'css/[name]-[contenthash:8].css',
|
73
|
-
chunkFilename: isDevelopment
|
74
|
-
? 'css/[id].css'
|
75
|
-
: 'css/[id]-[contenthash:8].css'
|
69
|
+
filename: `css/[name]${hash}.css`,
|
70
|
+
chunkFilename: `css/[id]${hash}.css`
|
76
71
|
})
|
77
72
|
)
|
78
73
|
}
|
@@ -80,12 +75,17 @@ const getPlugins = () => {
|
|
80
75
|
return plugins
|
81
76
|
}
|
82
77
|
|
78
|
+
// Don't use contentHash except for production for performance
|
79
|
+
// https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
|
80
|
+
const hash = isProduction ? '-[contenthash]' : ''
|
83
81
|
module.exports = {
|
84
82
|
mode: 'production',
|
85
83
|
output: {
|
86
|
-
filename:
|
87
|
-
chunkFilename:
|
88
|
-
|
84
|
+
filename: `js/[name]${hash}.js`,
|
85
|
+
chunkFilename: `js/[name]${hash}.chunk.js`,
|
86
|
+
|
87
|
+
// https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
|
88
|
+
hotUpdateChunkFilename: 'js/[id].[fullhash].hot-update.js',
|
89
89
|
path: config.outputPath,
|
90
90
|
publicPath: config.publicPath
|
91
91
|
},
|
@@ -1,8 +1,8 @@
|
|
1
1
|
const { merge } = require('webpack-merge')
|
2
|
-
const webpack = require('webpack')
|
3
2
|
|
4
3
|
const baseConfig = require('./base')
|
5
4
|
const devServer = require('../dev_server')
|
5
|
+
const { runningWebpackDevServer } = require('../env')
|
6
6
|
|
7
7
|
const { outputPath: contentBase, publicPath } = require('../config')
|
8
8
|
|
@@ -11,44 +11,44 @@ let devConfig = {
|
|
11
11
|
devtool: 'cheap-module-source-map'
|
12
12
|
}
|
13
13
|
|
14
|
-
if (
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
if (runningWebpackDevServer) {
|
15
|
+
const liveReload = devServer.live_reload !== undefined ? devServer.live_reload : !devServer.hmr
|
16
|
+
|
17
|
+
const devServerConfig = {
|
18
|
+
devMiddleware: {
|
19
|
+
publicPath
|
20
|
+
},
|
21
|
+
compress: devServer.compress,
|
22
|
+
allowedHosts: devServer.allowed_hosts,
|
23
|
+
host: devServer.host,
|
24
|
+
port: devServer.port,
|
25
|
+
https: devServer.https,
|
26
|
+
hot: devServer.hmr,
|
27
|
+
liveReload,
|
28
|
+
historyApiFallback: { disableDotRule: true },
|
29
|
+
headers: devServer.headers,
|
30
|
+
static: {
|
31
|
+
publicPath: contentBase
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
if (devServer.static) {
|
36
|
+
devServerConfig.static = { ...devServerConfig.static, ...devServer.static }
|
37
|
+
}
|
38
|
+
|
39
|
+
if (devServer.client) {
|
40
|
+
devServerConfig.client = devServer.client
|
23
41
|
}
|
24
42
|
|
25
43
|
devConfig = merge(devConfig, {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
hot: devServer.hmr,
|
35
|
-
contentBase,
|
36
|
-
inline: devServer.inline,
|
37
|
-
injectClient: devServer.inject_client,
|
38
|
-
useLocalIp: devServer.use_local_ip,
|
39
|
-
public: devServer.public,
|
40
|
-
publicPath,
|
41
|
-
historyApiFallback: { disableDotRule: true },
|
42
|
-
headers: devServer.headers,
|
43
|
-
overlay: devServer.overlay,
|
44
|
-
stats: {
|
45
|
-
entrypoints: false,
|
46
|
-
errorDetails: true,
|
47
|
-
modules: false,
|
48
|
-
moduleTrace: false
|
49
|
-
},
|
50
|
-
watchOptions: devServer.watch_options
|
51
|
-
}
|
44
|
+
stats: {
|
45
|
+
colors: true,
|
46
|
+
entrypoints: false,
|
47
|
+
errorDetails: true,
|
48
|
+
modules: false,
|
49
|
+
moduleTrace: false
|
50
|
+
},
|
51
|
+
devServer: devServerConfig
|
52
52
|
})
|
53
53
|
}
|
54
54
|
|
@@ -37,7 +37,7 @@ const tryCssMinimizer = () => {
|
|
37
37
|
moduleExists('css-minimizer-webpack-plugin')
|
38
38
|
) {
|
39
39
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
|
40
|
-
return new CssMinimizerPlugin(
|
40
|
+
return new CssMinimizerPlugin()
|
41
41
|
}
|
42
42
|
|
43
43
|
return null
|
data/package/index.js
CHANGED
@@ -10,6 +10,7 @@ const config = require('./config')
|
|
10
10
|
const devServer = require('./dev_server')
|
11
11
|
const { nodeEnv } = require('./env')
|
12
12
|
const { moduleExists, canProcess } = require('./utils/helpers')
|
13
|
+
const inliningCss = require('./inliningCss')
|
13
14
|
|
14
15
|
const webpackConfig = () => {
|
15
16
|
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
@@ -25,5 +26,6 @@ module.exports = {
|
|
25
26
|
rules,
|
26
27
|
moduleExists,
|
27
28
|
canProcess,
|
29
|
+
inliningCss,
|
28
30
|
...webpackMerge
|
29
31
|
}
|
data/package/rules/babel.js
CHANGED
@@ -8,7 +8,7 @@ const {
|
|
8
8
|
const { isProduction } = require('../env')
|
9
9
|
|
10
10
|
module.exports = {
|
11
|
-
test: /\.(js|jsx|mjs|ts|tsx)?(\.erb)?$/,
|
11
|
+
test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
|
12
12
|
include: [sourcePath, ...additionalPaths].map((p) => {
|
13
13
|
try {
|
14
14
|
return realpathSync(p)
|
data/package/rules/file.js
CHANGED
data/package/rules/sass.js
CHANGED
data/package/rules/stylus.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
|
-
|
3
2
|
const { canProcess, moduleExists } = require('./helpers')
|
3
|
+
const inliningCss = require('../inliningCss')
|
4
4
|
|
5
5
|
const getStyleRule = (test, preprocessors = []) => {
|
6
6
|
if (moduleExists('css-loader')) {
|
@@ -10,8 +10,10 @@ const getStyleRule = (test, preprocessors = []) => {
|
|
10
10
|
options: { sourceMap: true }
|
11
11
|
}))
|
12
12
|
|
13
|
+
// style-loader is required when using css modules with HMR on the webpack-dev-server
|
14
|
+
|
13
15
|
const use = [
|
14
|
-
|
16
|
+
inliningCss ? 'style-loader' : require('mini-css-extract-plugin').loader,
|
15
17
|
{
|
16
18
|
loader: require.resolve('css-loader'),
|
17
19
|
options: {
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rails/webpacker",
|
3
|
-
"version": "6.0.0-
|
3
|
+
"version": "6.0.0-rc.6",
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
5
|
"main": "package/index.js",
|
6
6
|
"files": [
|
@@ -8,40 +8,36 @@
|
|
8
8
|
"lib/install/config/webpacker.yml"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
|
-
"node": ">=
|
12
|
-
"yarn": ">=1 <
|
11
|
+
"node": ">= 12.13.0 || >=14",
|
12
|
+
"yarn": ">=1 <4"
|
13
13
|
},
|
14
14
|
"dependencies": {
|
15
|
-
"@babel/core": "^7.
|
16
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
17
|
-
"@babel/plugin-transform-runtime": "^7.
|
18
|
-
"@babel/preset-env": "^7.
|
19
|
-
"@babel/runtime": "^7.
|
15
|
+
"@babel/core": "^7.15.5",
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
17
|
+
"@babel/plugin-transform-runtime": "^7.15.0",
|
18
|
+
"@babel/preset-env": "^7.15.6",
|
19
|
+
"@babel/runtime": "^7.15.4",
|
20
20
|
"babel-loader": "^8.2.2",
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"core-js": "^3.8.0",
|
25
|
-
"glob": "^7.1.6",
|
26
|
-
"js-yaml": "^3.14.0",
|
21
|
+
"compression-webpack-plugin": "^9.0.0",
|
22
|
+
"glob": "^7.2.0",
|
23
|
+
"js-yaml": "^4.1.0",
|
27
24
|
"path-complete-extname": "^1.0.0",
|
28
|
-
"pnp-webpack-plugin": "^1.
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"webpack": "^5.
|
32
|
-
"webpack-
|
33
|
-
"webpack-
|
34
|
-
"webpack-
|
35
|
-
"webpack-sources": "^2.2.0"
|
25
|
+
"pnp-webpack-plugin": "^1.7.0",
|
26
|
+
"terser-webpack-plugin": "^5.2.4",
|
27
|
+
"webpack": "^5.53.0",
|
28
|
+
"webpack-assets-manifest": "^5.0.6",
|
29
|
+
"webpack-cli": "^4.8.0",
|
30
|
+
"webpack-merge": "^5.8.0",
|
31
|
+
"webpack-sources": "^3.2.1"
|
36
32
|
},
|
37
33
|
"devDependencies": {
|
38
|
-
"eslint": "^7.
|
39
|
-
"eslint-config-airbnb": "^18.2.
|
40
|
-
"eslint-config-prettier": "^
|
41
|
-
"eslint-plugin-import": "^2.
|
42
|
-
"eslint-plugin-jsx-a11y": "^6.
|
43
|
-
"eslint-plugin-react": "^7.
|
44
|
-
"jest": "^
|
34
|
+
"eslint": "^7.32.0",
|
35
|
+
"eslint-config-airbnb": "^18.2.1",
|
36
|
+
"eslint-config-prettier": "^8.3.0",
|
37
|
+
"eslint-plugin-import": "^2.24.2",
|
38
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
39
|
+
"eslint-plugin-react": "^7.26.0",
|
40
|
+
"jest": "^27.2.1"
|
45
41
|
},
|
46
42
|
"jest": {
|
47
43
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
data/test/command_test.rb
CHANGED
@@ -31,3 +31,79 @@ class CommandTest < Minitest::Test
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
class ClearCommandVersioningTest < Minitest::Test
|
36
|
+
def setup
|
37
|
+
@now = Time.parse("2021-01-01 12:34:56 UTC")
|
38
|
+
# Test assets to be kept and deleted, path and mtime
|
39
|
+
@prev_files = {
|
40
|
+
# recent versions to be kept with Webpacker.commands.clean(count = 2)
|
41
|
+
"js/application-deadbeef.js" => @now - 4000,
|
42
|
+
"js/common-deadbeee.js" => @now - 4002,
|
43
|
+
"css/common-deadbeed.css" => @now - 4004,
|
44
|
+
"media/images/logo-deadbeeb.css" => @now - 4006,
|
45
|
+
"js/application-1eadbeef.js" => @now - 8000,
|
46
|
+
"js/common-1eadbeee.js" => @now - 8002,
|
47
|
+
"css/common-1eadbeed.css" => @now - 8004,
|
48
|
+
"media/images/logo-1eadbeeb.css" => @now - 8006,
|
49
|
+
# new files to be kept with Webpacker.commands.clean(age = 3600)
|
50
|
+
"js/brandnew-0001.js" => @now,
|
51
|
+
"js/brandnew-0002.js" => @now - 10,
|
52
|
+
"js/brandnew-0003.js" => @now - 20,
|
53
|
+
"js/brandnew-0004.js" => @now - 40,
|
54
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
55
|
+
@expired_files = {
|
56
|
+
# old files that are outside count = 2 or age = 3600 and to be deleted
|
57
|
+
"js/application-0eadbeef.js" => @now - 9000,
|
58
|
+
"js/common-0eadbeee.js" => @now - 9002,
|
59
|
+
"css/common-0eadbeed.css" => @now - 9004,
|
60
|
+
"js/brandnew-0005.js" => @now - 3640,
|
61
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
62
|
+
@all_files = @prev_files.merge(@expired_files)
|
63
|
+
@dir_glob_stub = Proc.new { |arg|
|
64
|
+
case arg
|
65
|
+
when "#{Webpacker.config.public_output_path}/**/*"
|
66
|
+
@all_files.keys
|
67
|
+
else
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
}
|
71
|
+
@file_mtime_stub = Proc.new { |longpath|
|
72
|
+
@all_files[longpath]
|
73
|
+
}
|
74
|
+
@file_delete_mock = Minitest::Mock.new
|
75
|
+
@expired_files.keys.each do |longpath|
|
76
|
+
@file_delete_mock.expect(:delete, 1, [longpath])
|
77
|
+
end
|
78
|
+
@file_delete_stub = Proc.new { |longpath|
|
79
|
+
if @prev_files.has_key?(longpath)
|
80
|
+
flunk "#{longpath} should not be deleted"
|
81
|
+
else
|
82
|
+
@file_delete_mock.delete(longpath)
|
83
|
+
end
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def time_and_files_stub(&proc)
|
88
|
+
Time.stub :now, @now do
|
89
|
+
Dir.stub :glob, @dir_glob_stub do
|
90
|
+
File.stub :directory?, false do
|
91
|
+
File.stub :file?, true do
|
92
|
+
File.stub :mtime, @file_mtime_stub do
|
93
|
+
File.stub :delete, @file_delete_stub do
|
94
|
+
yield proc
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
@file_delete_mock.verify
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_clean_command_with_versioned_files
|
105
|
+
time_and_files_stub do
|
106
|
+
assert Webpacker.commands.clean
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/test/configuration_test.rb
CHANGED
@@ -44,7 +44,7 @@ class ConfigurationTest < Webpacker::Test
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_cache_path
|
47
|
-
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/
|
47
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/webpacker").to_s
|
48
48
|
assert_equal @config.cache_path.to_s, cache_path
|
49
49
|
end
|
50
50
|
|
@@ -5,11 +5,13 @@ class DevServerRunnerTest < Webpacker::Test
|
|
5
5
|
def setup
|
6
6
|
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
7
7
|
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
8
|
+
@original_webpacker_config = ENV["WEBPACKER_CONFIG"]
|
8
9
|
end
|
9
10
|
|
10
11
|
def teardown
|
11
12
|
ENV["NODE_ENV"] = @original_node_env
|
12
13
|
ENV["RAILS_ENV"] = @original_rails_env
|
14
|
+
ENV["WEBPACKER_CONFIG"] = @original_webpacker_config
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_run_cmd_via_node_modules
|
@@ -38,6 +40,7 @@ class DevServerRunnerTest < Webpacker::Test
|
|
38
40
|
def dev_server.port; "3035"; end
|
39
41
|
def dev_server.pretty?; false; end
|
40
42
|
def dev_server.https?; true; end
|
43
|
+
def dev_server.hmr?; false; end
|
41
44
|
Webpacker::DevServer.stub(:new, dev_server) do
|
42
45
|
verify_command(cmd, argv: ["--https"])
|
43
46
|
end
|
@@ -46,8 +49,8 @@ class DevServerRunnerTest < Webpacker::Test
|
|
46
49
|
def test_environment_variables
|
47
50
|
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
|
48
51
|
env = Webpacker::Compiler.env.dup
|
49
|
-
env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/
|
50
|
-
env["
|
52
|
+
ENV["WEBPACKER_CONFIG"] = env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
|
53
|
+
env["WEBPACK_SERVE"] = "true"
|
51
54
|
verify_command(cmd, env: env)
|
52
55
|
end
|
53
56
|
|