jetpacker 0.1.0 → 0.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.
- checksums.yaml +4 -4
- data/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +11 -11
- data/.node-version +1 -0
- data/.rubocop.yml +125 -0
- data/.travis.yml +54 -5
- data/CHANGELOG.jetpacker.md +7 -0
- data/CHANGELOG.md +1000 -0
- data/CONTRIBUTING.md +33 -0
- data/Gemfile +9 -3
- data/Gemfile.lock +157 -21
- data/MIT-LICENSE +20 -0
- data/README.md +671 -16
- data/Rakefile +8 -3
- data/docs/assets.md +119 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +253 -0
- data/docs/deployment.md +130 -0
- data/docs/docker.md +68 -0
- data/docs/engines.md +200 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +72 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +137 -0
- data/docs/troubleshooting.md +156 -0
- data/docs/typescript.md +126 -0
- data/docs/v4-upgrade.md +142 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +364 -0
- data/docs/yarn.md +23 -0
- data/gemfiles/Gemfile-rails-edge +12 -0
- data/gemfiles/Gemfile-rails.4.2.x +9 -0
- data/gemfiles/Gemfile-rails.5.0.x +9 -0
- data/gemfiles/Gemfile-rails.5.1.x +9 -0
- data/gemfiles/Gemfile-rails.5.2.x +9 -0
- data/gemfiles/Gemfile-rails.6.0.x +9 -0
- data/jetpacker.gemspec +28 -22
- data/lib/install/angular.rb +23 -0
- data/lib/install/bin/webpack +18 -0
- data/lib/install/bin/webpack-dev-server +18 -0
- data/lib/install/binstubs.rb +4 -0
- data/lib/install/coffee.rb +25 -0
- data/lib/install/config/.browserslistrc +1 -0
- data/lib/install/config/babel.config.js +72 -0
- data/lib/install/config/postcss.config.js +12 -0
- data/lib/install/config/webpack/development.js +5 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +5 -0
- data/lib/install/config/webpack/test.js +5 -0
- data/lib/install/config/webpacker.yml +96 -0
- data/lib/install/elm.rb +39 -0
- data/lib/install/erb.rb +25 -0
- data/lib/install/examples/angular/hello_angular.js +7 -0
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +55 -0
- data/lib/install/examples/elm/hello_elm.js +16 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/babel.config.js +87 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/react/tsconfig.json +20 -0
- data/lib/install/examples/stimulus/application.js +1 -0
- data/lib/install/examples/stimulus/controllers/hello_controller.js +18 -0
- data/lib/install/examples/stimulus/controllers/index.js +9 -0
- data/lib/install/examples/svelte/app.svelte +11 -0
- data/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/lib/install/examples/typescript/hello_typescript.ts +4 -0
- data/lib/install/examples/typescript/tsconfig.json +23 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +72 -0
- data/lib/install/javascript/packs/application.js +18 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +25 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/svelte.js +9 -0
- data/lib/install/loaders/typescript.js +11 -0
- data/lib/install/loaders/vue.js +6 -0
- data/lib/install/react.rb +18 -0
- data/lib/install/stimulus.rb +12 -0
- data/lib/install/svelte.rb +29 -0
- data/lib/install/template.rb +55 -0
- data/lib/install/typescript.rb +46 -0
- data/lib/install/vue.rb +49 -0
- data/lib/jetpacker/version.rb +2 -1
- data/lib/tasks/installers.rake +37 -0
- data/lib/tasks/webpacker.rake +28 -0
- data/lib/tasks/webpacker/binstubs.rake +11 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +24 -0
- data/lib/tasks/webpacker/check_yarn.rake +24 -0
- data/lib/tasks/webpacker/clean.rake +21 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +43 -0
- data/lib/tasks/webpacker/info.rake +20 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +13 -0
- data/lib/tasks/webpacker/yarn_install.rake +21 -0
- data/lib/webpacker.rb +46 -0
- data/lib/webpacker/commands.rb +50 -0
- data/lib/webpacker/compiler.rb +107 -0
- data/lib/webpacker/configuration.rb +113 -0
- data/lib/webpacker/dev_server.rb +66 -0
- data/lib/webpacker/dev_server_proxy.rb +31 -0
- data/lib/webpacker/dev_server_runner.rb +72 -0
- data/lib/webpacker/env.rb +39 -0
- data/lib/webpacker/helper.rb +176 -0
- data/lib/webpacker/instance.rb +37 -0
- data/lib/webpacker/manifest.rb +118 -0
- data/lib/webpacker/railtie.rb +98 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +4 -0
- data/lib/webpacker/webpack_runner.rb +32 -0
- data/package.json +82 -0
- data/package/__tests__/config.js +55 -0
- data/package/__tests__/dev_server.js +43 -0
- data/package/__tests__/development.js +30 -0
- data/package/__tests__/env.js +46 -0
- data/package/__tests__/production.js +29 -0
- data/package/__tests__/staging.js +29 -0
- data/package/__tests__/test.js +26 -0
- data/package/config.js +37 -0
- data/package/config_types/__tests__/config_list.js +118 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +75 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/dev_server.js +20 -0
- data/package/env.js +19 -0
- data/package/environments/__tests__/base.js +74 -0
- data/package/environments/base.js +166 -0
- data/package/environments/development.js +51 -0
- data/package/environments/production.js +79 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +24 -0
- data/package/rules/babel.js +21 -0
- data/package/rules/css.js +3 -0
- data/package/rules/file.js +20 -0
- data/package/rules/index.js +20 -0
- data/package/rules/module.css.js +3 -0
- data/package/rules/module.sass.js +8 -0
- data/package/rules/node_modules.js +24 -0
- data/package/rules/sass.js +8 -0
- data/package/utils/__tests__/deep_assign.js +32 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/get_style_rule.js +65 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +22 -0
- data/package/utils/get_style_rule.js +45 -0
- data/package/utils/helpers.js +58 -0
- data/package/utils/objectify.js +3 -0
- data/test/command_test.rb +33 -0
- data/test/compiler_test.rb +75 -0
- data/test/configuration_test.rb +108 -0
- data/test/dev_server_runner_test.rb +51 -0
- data/test/dev_server_test.rb +47 -0
- data/test/env_test.rb +23 -0
- data/test/helper_test.rb +142 -0
- data/test/manifest_test.rb +42 -0
- data/test/rake_tasks_test.rb +69 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/bin/webpack +14 -0
- data/test/test_app/bin/webpack-dev-server +14 -0
- data/test/test_app/config.ru +5 -0
- data/test/test_app/config/application.rb +12 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpack/development.js +0 -0
- data/test/test_app/config/webpacker.yml +97 -0
- data/test/test_app/config/webpacker_public_root.yml +19 -0
- data/test/test_app/package.json +13 -0
- data/test/test_app/public/packs/manifest.json +31 -0
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +33 -0
- data/test/webpack_runner_test.rb +51 -0
- data/test/webpacker_test.rb +13 -0
- data/yarn.lock +8321 -0
- metadata +267 -29
- data/.rspec +0 -3
- data/LICENSE.txt +0 -21
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/jetpacker.rb +0 -6
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* global test expect */
|
|
2
|
+
|
|
3
|
+
const deepAssign = require('../deep_assign')
|
|
4
|
+
|
|
5
|
+
describe('deepAssign()', () => {
|
|
6
|
+
test('deeply assigns nested properties', () => {
|
|
7
|
+
const object = { foo: { bar: { } } }
|
|
8
|
+
const path = 'foo.bar'
|
|
9
|
+
const value = { x: 1, y: 2 }
|
|
10
|
+
const expectation = { foo: { bar: { x: 1, y: 2 } } }
|
|
11
|
+
expect(deepAssign(object, path, value)).toEqual(expectation)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('allows assignment of a literal false', () => {
|
|
15
|
+
const object = { foo: { bar: { } } }
|
|
16
|
+
const path = 'foo.bar'
|
|
17
|
+
const value = false
|
|
18
|
+
const expectation = { foo: { bar: false } }
|
|
19
|
+
expect(deepAssign(object, path, value)).toEqual(expectation)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('does not allow assignment of other falsy values', () => {
|
|
23
|
+
const object = { foo: { bar: { } } }
|
|
24
|
+
const path = 'foo.bar'
|
|
25
|
+
const values = [undefined, null, 0, '']
|
|
26
|
+
|
|
27
|
+
values.forEach(value => {
|
|
28
|
+
const expectation = new Error(`Value can't be ${value}`)
|
|
29
|
+
expect(() => deepAssign(object, path, value)).toThrow(expectation)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* global test expect */
|
|
2
|
+
|
|
3
|
+
const deepMerge = require('../deep_merge')
|
|
4
|
+
|
|
5
|
+
test('deep merge objects together', () => {
|
|
6
|
+
const object1 = { foo: { bar: [1, 2, 3], z: 1 }, x: 0 }
|
|
7
|
+
const object2 = { foo: { bar: ['x', 'y'] }, x: 1, y: 2 }
|
|
8
|
+
const expectation = { foo: { bar: [1, 2, 3, 'x', 'y'], z: 1 }, x: 1, y: 2 }
|
|
9
|
+
expect(deepMerge(object1, object2)).toEqual(expectation)
|
|
10
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const { chdirTestApp, chdirCwd } = require('../helpers')
|
|
2
|
+
|
|
3
|
+
chdirTestApp()
|
|
4
|
+
|
|
5
|
+
const getStyleRule = require('../get_style_rule')
|
|
6
|
+
|
|
7
|
+
describe('getStyleRule', () => {
|
|
8
|
+
afterAll(chdirCwd)
|
|
9
|
+
|
|
10
|
+
test('excludes modules by default', () => {
|
|
11
|
+
const cssRule = getStyleRule(/\.(css)$/i)
|
|
12
|
+
const expectation = {
|
|
13
|
+
test: /\.(css)$/i,
|
|
14
|
+
exclude: /\.module\.[a-z]+$/
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
expect(cssRule).toMatchObject(expectation)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('includes modules if set to true', () => {
|
|
21
|
+
const cssRule = getStyleRule(/\.(scss)$/i, true)
|
|
22
|
+
const expectation = {
|
|
23
|
+
test: /\.(scss)$/i,
|
|
24
|
+
include: /\.module\.[a-z]+$/
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
expect(cssRule).toMatchObject(expectation)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('adds extra preprocessors if supplied', () => {
|
|
31
|
+
const expectation = [{ foo: 'bar' }]
|
|
32
|
+
const cssRule = getStyleRule(/\.(css)$/i, true, expectation)
|
|
33
|
+
|
|
34
|
+
expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('adds mini-css-extract-plugin when extract_css is true', () => {
|
|
38
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
39
|
+
const expectation = [MiniCssExtractPlugin.loader]
|
|
40
|
+
|
|
41
|
+
require('../../config').extract_css = true
|
|
42
|
+
const cssRule = getStyleRule(/\.(css)$/i)
|
|
43
|
+
|
|
44
|
+
expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('adds style-loader when extract_css is true', () => {
|
|
48
|
+
const expectation = [{loader: 'style-loader'}]
|
|
49
|
+
|
|
50
|
+
require('../../config').extract_css = false
|
|
51
|
+
const cssRule = getStyleRule(/\.(css)$/i)
|
|
52
|
+
|
|
53
|
+
expect(cssRule.use).toMatchObject(expect.objectContaining(expectation))
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test(`doesn't add mini-css-extract-plugin when extract_css is false`, () => {
|
|
57
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
58
|
+
const expectation = [MiniCssExtractPlugin.loader]
|
|
59
|
+
|
|
60
|
+
require('../../config').extract_css = false
|
|
61
|
+
const cssRule = getStyleRule(/\.(css)$/i)
|
|
62
|
+
|
|
63
|
+
expect(cssRule.use).toMatchObject(expect.not.arrayContaining(expectation))
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* global test expect */
|
|
2
|
+
|
|
3
|
+
const objectify = require('../objectify')
|
|
4
|
+
|
|
5
|
+
test('Get object from a string path', () => {
|
|
6
|
+
const object = { foo: { bar: { x: 1 } } }
|
|
7
|
+
expect(objectify('foo.bar', object)).toEqual({ x: 1 })
|
|
8
|
+
expect(objectify('some.bar', object)).toEqual(undefined)
|
|
9
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { canMerge, prettyPrint } = require('./helpers')
|
|
2
|
+
const deepMerge = require('./deep_merge')
|
|
3
|
+
|
|
4
|
+
const deepAssign = (obj, path, value) => {
|
|
5
|
+
if (!value && value !== false) throw new Error(`Value can't be ${value}`)
|
|
6
|
+
|
|
7
|
+
const keys = path.split('.')
|
|
8
|
+
const key = keys.pop()
|
|
9
|
+
|
|
10
|
+
const objRef = keys.reduce((acc, currentValue) => {
|
|
11
|
+
/* eslint no-param-reassign: 0 */
|
|
12
|
+
if (!acc[currentValue]) acc[currentValue] = {}
|
|
13
|
+
return acc[currentValue]
|
|
14
|
+
}, obj)
|
|
15
|
+
|
|
16
|
+
if (!objRef) throw new Error(`Prop not found: ${path} in ${prettyPrint(obj)}`)
|
|
17
|
+
|
|
18
|
+
objRef[key] = canMerge(value) ? deepMerge(objRef[key], value) : value
|
|
19
|
+
return obj
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = deepAssign
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const {
|
|
2
|
+
isObject, isArray, isEqual, isEmpty
|
|
3
|
+
} = require('./helpers')
|
|
4
|
+
|
|
5
|
+
const deepMerge = (target, source) => {
|
|
6
|
+
if (isEmpty(target)) return source
|
|
7
|
+
if (isEmpty(source)) return target
|
|
8
|
+
if (isEqual(target, source)) return source
|
|
9
|
+
if (isArray(target) && isArray(source)) return [...new Set([...target, ...source])]
|
|
10
|
+
if (!(isObject(target) && isObject(source))) return source
|
|
11
|
+
|
|
12
|
+
return [...Object.keys(target), ...Object.keys(source)].reduce(
|
|
13
|
+
(result, key) => ({
|
|
14
|
+
|
|
15
|
+
...result,
|
|
16
|
+
[key]: deepMerge(target[key], source[key])
|
|
17
|
+
}),
|
|
18
|
+
{}
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = deepMerge
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
2
|
+
const { resolve } = require('path')
|
|
3
|
+
const config = require('../config')
|
|
4
|
+
|
|
5
|
+
const styleLoader = {
|
|
6
|
+
loader: 'style-loader'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const getStyleRule = (test, modules = false, preprocessors = []) => {
|
|
10
|
+
const use = [
|
|
11
|
+
{
|
|
12
|
+
loader: 'css-loader',
|
|
13
|
+
options: {
|
|
14
|
+
sourceMap: true,
|
|
15
|
+
importLoaders: 2,
|
|
16
|
+
modules: modules ? {
|
|
17
|
+
localIdentName: '[name]__[local]___[hash:base64:5]'
|
|
18
|
+
} : false
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
loader: 'postcss-loader',
|
|
23
|
+
options: {
|
|
24
|
+
config: { path: resolve() },
|
|
25
|
+
sourceMap: true
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
...preprocessors
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const options = modules ? { include: /\.module\.[a-z]+$/ } : { exclude: /\.module\.[a-z]+$/ }
|
|
32
|
+
|
|
33
|
+
if (config.extract_css) {
|
|
34
|
+
use.unshift(MiniCssExtractPlugin.loader)
|
|
35
|
+
} else {
|
|
36
|
+
use.unshift(styleLoader)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// sideEffects - See https://github.com/webpack/webpack/issues/6571
|
|
40
|
+
return {
|
|
41
|
+
test, use, sideEffects: !modules, ...options
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = getStyleRule
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const { stringify } = require('flatted/cjs')
|
|
2
|
+
|
|
3
|
+
const isObject = (value) => typeof value === 'object'
|
|
4
|
+
&& value !== null
|
|
5
|
+
&& (value.length === undefined || value.length === null)
|
|
6
|
+
|
|
7
|
+
const isNotObject = (value) => !isObject(value)
|
|
8
|
+
|
|
9
|
+
const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
|
|
10
|
+
|
|
11
|
+
const isEmpty = (value) => value === null || value === undefined
|
|
12
|
+
|
|
13
|
+
const isString = (key) => key && typeof key === 'string'
|
|
14
|
+
|
|
15
|
+
const isStrPath = (key) => {
|
|
16
|
+
if (!isString(key)) throw new Error(`Key ${key} should be string`)
|
|
17
|
+
return isString(key) && key.includes('.')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const isArray = (value) => Array.isArray(value)
|
|
21
|
+
|
|
22
|
+
const isEqual = (target, source) => stringify(target) === stringify(source)
|
|
23
|
+
|
|
24
|
+
const canMerge = (value) => isObject(value) || isArray(value)
|
|
25
|
+
|
|
26
|
+
const prettyPrint = (obj) => JSON.stringify(obj, null, 2)
|
|
27
|
+
|
|
28
|
+
const chdirTestApp = () => {
|
|
29
|
+
try {
|
|
30
|
+
return process.chdir('test/test_app')
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const chdirCwd = () => process.chdir(process.cwd())
|
|
37
|
+
|
|
38
|
+
const resetEnv = () => {
|
|
39
|
+
process.env = {}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
chdirTestApp,
|
|
46
|
+
chdirCwd,
|
|
47
|
+
ensureTrailingSlash,
|
|
48
|
+
isObject,
|
|
49
|
+
isNotObject,
|
|
50
|
+
isBoolean,
|
|
51
|
+
isArray,
|
|
52
|
+
isEqual,
|
|
53
|
+
isEmpty,
|
|
54
|
+
isStrPath,
|
|
55
|
+
canMerge,
|
|
56
|
+
prettyPrint,
|
|
57
|
+
resetEnv
|
|
58
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandTest < Minitest::Test
|
|
4
|
+
def test_compile_command_returns_success_status_when_stale
|
|
5
|
+
Webpacker.compiler.stub :stale?, true do
|
|
6
|
+
Webpacker.compiler.stub :run_webpack, true do
|
|
7
|
+
assert_equal true, Webpacker.commands.compile
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_compile_command_returns_success_status_when_fresh
|
|
13
|
+
Webpacker.compiler.stub :stale?, false do
|
|
14
|
+
Webpacker.compiler.stub :run_webpack, true do
|
|
15
|
+
assert_equal true, Webpacker.commands.compile
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_compile_command_returns_failure_status_when_stale
|
|
21
|
+
Webpacker.compiler.stub :stale?, true do
|
|
22
|
+
Webpacker.compiler.stub :run_webpack, false do
|
|
23
|
+
assert_equal false, Webpacker.commands.compile
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_clean_command_works_with_nested_hashes_and_without_any_compiled_files
|
|
29
|
+
File.stub :delete, true do
|
|
30
|
+
assert Webpacker.commands.clean
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CompilerTest < Minitest::Test
|
|
4
|
+
def remove_compilation_digest_path
|
|
5
|
+
Webpacker.compiler.send(:compilation_digest_path).tap do |path|
|
|
6
|
+
path.delete if path.exist?
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
remove_compilation_digest_path
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def teardown
|
|
15
|
+
remove_compilation_digest_path
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_custom_environment_variables
|
|
19
|
+
assert_nil Webpacker.compiler.send(:webpack_env)["FOO"]
|
|
20
|
+
Webpacker.compiler.env["FOO"] = "BAR"
|
|
21
|
+
assert Webpacker.compiler.send(:webpack_env)["FOO"] == "BAR"
|
|
22
|
+
ensure
|
|
23
|
+
Webpacker.compiler.env = {}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_default_watched_paths
|
|
27
|
+
assert_equal Webpacker.compiler.send(:default_watched_paths), [
|
|
28
|
+
"app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}",
|
|
29
|
+
"/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}",
|
|
30
|
+
"app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}",
|
|
31
|
+
"yarn.lock",
|
|
32
|
+
"package.json",
|
|
33
|
+
"config/webpack/**/*"
|
|
34
|
+
]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_freshness
|
|
38
|
+
assert Webpacker.compiler.stale?
|
|
39
|
+
assert !Webpacker.compiler.fresh?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_freshness_on_compile_success
|
|
43
|
+
status = OpenStruct.new(success?: true)
|
|
44
|
+
|
|
45
|
+
assert Webpacker.compiler.stale?
|
|
46
|
+
Open3.stub :capture3, [:sterr, :stdout, status] do
|
|
47
|
+
Webpacker.compiler.compile
|
|
48
|
+
assert Webpacker.compiler.fresh?
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_freshness_on_compile_fail
|
|
53
|
+
status = OpenStruct.new(success?: false)
|
|
54
|
+
|
|
55
|
+
assert Webpacker.compiler.stale?
|
|
56
|
+
Open3.stub :capture3, [:sterr, :stdout, status] do
|
|
57
|
+
Webpacker.compiler.compile
|
|
58
|
+
assert Webpacker.compiler.fresh?
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_compilation_digest_path
|
|
63
|
+
assert_equal Webpacker.compiler.send(:compilation_digest_path).basename.to_s, "last-compilation-digest-#{Webpacker.env}"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_external_env_variables
|
|
67
|
+
assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"]
|
|
68
|
+
assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"]
|
|
69
|
+
|
|
70
|
+
ENV["WEBPACKER_ASSET_HOST"] = "foo.bar"
|
|
71
|
+
ENV["WEBPACKER_RELATIVE_URL_ROOT"] = "/baz"
|
|
72
|
+
assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"], "foo.bar"
|
|
73
|
+
assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"], "/baz"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ConfigurationTest < Webpacker::Test
|
|
4
|
+
def setup
|
|
5
|
+
@config = Webpacker::Configuration.new(
|
|
6
|
+
root_path: Pathname.new(File.expand_path("test_app", __dir__)),
|
|
7
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker.yml", __dir__)),
|
|
8
|
+
env: "production"
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_source_path
|
|
13
|
+
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
|
|
14
|
+
assert_equal source_path, @config.source_path.to_s
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_source_path_globbed
|
|
18
|
+
assert_equal @config.source_path_globbed,
|
|
19
|
+
"app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_source_entry_path
|
|
23
|
+
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "packs").to_s
|
|
24
|
+
assert_equal @config.source_entry_path.to_s, source_entry_path
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_public_root_path
|
|
28
|
+
public_root_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public").to_s
|
|
29
|
+
assert_equal @config.public_path.to_s, public_root_path
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_public_output_path
|
|
33
|
+
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
|
|
34
|
+
assert_equal @config.public_output_path.to_s, public_output_path
|
|
35
|
+
|
|
36
|
+
@config = Webpacker::Configuration.new(
|
|
37
|
+
root_path: @config.root_path,
|
|
38
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_public_root.yml", __dir__)),
|
|
39
|
+
env: "production"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
|
|
43
|
+
assert_equal @config.public_output_path.to_s, public_output_path
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_public_manifest_path
|
|
47
|
+
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
|
|
48
|
+
assert_equal @config.public_manifest_path.to_s, public_manifest_path
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_cache_path
|
|
52
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/cache/webpacker").to_s
|
|
53
|
+
assert_equal @config.cache_path.to_s, cache_path
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_resolved_paths
|
|
57
|
+
assert_equal @config.resolved_paths, ["app/assets", "/etc/yarn"]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_resolved_paths_globbed
|
|
61
|
+
assert_equal @config.resolved_paths_globbed, [
|
|
62
|
+
"app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}",
|
|
63
|
+
"/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}"
|
|
64
|
+
]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_extensions
|
|
68
|
+
config_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/config/webpacker.yml").to_s
|
|
69
|
+
webpacker_yml = YAML.load_file(config_path)
|
|
70
|
+
assert_equal @config.extensions, webpacker_yml["default"]["extensions"]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_cache_manifest?
|
|
74
|
+
assert @config.cache_manifest?
|
|
75
|
+
|
|
76
|
+
with_rails_env("development") do
|
|
77
|
+
refute Webpacker.config.cache_manifest?
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
with_rails_env("test") do
|
|
81
|
+
refute Webpacker.config.cache_manifest?
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_compile?
|
|
86
|
+
refute @config.compile?
|
|
87
|
+
|
|
88
|
+
with_rails_env("development") do
|
|
89
|
+
assert Webpacker.config.compile?
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
with_rails_env("test") do
|
|
93
|
+
assert Webpacker.config.compile?
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_extract_css?
|
|
98
|
+
assert @config.extract_css?
|
|
99
|
+
|
|
100
|
+
with_rails_env("development") do
|
|
101
|
+
refute Webpacker.config.extract_css?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
with_rails_env("test") do
|
|
105
|
+
refute Webpacker.config.extract_css?
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|