webpacker-jets 3.2.100

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintignore +4 -0
  3. data/.eslintrc.js +14 -0
  4. data/.gitignore +6 -0
  5. data/.rubocop.yml +124 -0
  6. data/.travis.yml +32 -0
  7. data/CHANGELOG.md +523 -0
  8. data/Gemfile +13 -0
  9. data/Gemfile.lock +154 -0
  10. data/MIT-LICENSE +20 -0
  11. data/README.md +445 -0
  12. data/Rakefile +12 -0
  13. data/docs/assets.md +106 -0
  14. data/docs/cloud9.md +310 -0
  15. data/docs/css.md +116 -0
  16. data/docs/deployment.md +74 -0
  17. data/docs/docker.md +49 -0
  18. data/docs/env.md +65 -0
  19. data/docs/es6.md +53 -0
  20. data/docs/folder-structure.md +66 -0
  21. data/docs/misc.md +23 -0
  22. data/docs/props.md +223 -0
  23. data/docs/testing.md +128 -0
  24. data/docs/troubleshooting.md +119 -0
  25. data/docs/typescript.md +116 -0
  26. data/docs/webpack-dev-server.md +92 -0
  27. data/docs/webpack.md +297 -0
  28. data/docs/yarn.md +12 -0
  29. data/exe/webpack +8 -0
  30. data/exe/webpack-dev-server +8 -0
  31. data/gemfiles/Gemfile-rails-edge +13 -0
  32. data/gemfiles/Gemfile-rails.4.2.x +10 -0
  33. data/gemfiles/Gemfile-rails.5.0.x +10 -0
  34. data/gemfiles/Gemfile-rails.5.1.x +10 -0
  35. data/lib/install/angular.rb +27 -0
  36. data/lib/install/coffee.rb +22 -0
  37. data/lib/install/config/.babelrc +18 -0
  38. data/lib/install/config/.postcssrc.yml +3 -0
  39. data/lib/install/config/webpack/development.js +3 -0
  40. data/lib/install/config/webpack/environment.js +3 -0
  41. data/lib/install/config/webpack/production.js +3 -0
  42. data/lib/install/config/webpack/staging.js +3 -0
  43. data/lib/install/config/webpack/test.js +3 -0
  44. data/lib/install/config/webpacker.yml +79 -0
  45. data/lib/install/elm.rb +38 -0
  46. data/lib/install/erb.rb +22 -0
  47. data/lib/install/examples/angular/hello_angular.js +7 -0
  48. data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
  49. data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
  50. data/lib/install/examples/angular/hello_angular/index.ts +8 -0
  51. data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
  52. data/lib/install/examples/angular/tsconfig.json +19 -0
  53. data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
  54. data/lib/install/examples/elm/Main.elm +54 -0
  55. data/lib/install/examples/elm/hello_elm.js +12 -0
  56. data/lib/install/examples/erb/hello_erb.js.erb +6 -0
  57. data/lib/install/examples/react/.babelrc +6 -0
  58. data/lib/install/examples/react/hello_react.jsx +26 -0
  59. data/lib/install/examples/vue/app.vue +22 -0
  60. data/lib/install/examples/vue/hello_vue.js +70 -0
  61. data/lib/install/javascript/packs/application.js +10 -0
  62. data/lib/install/loaders/coffee.js +6 -0
  63. data/lib/install/loaders/elm.js +23 -0
  64. data/lib/install/loaders/erb.js +11 -0
  65. data/lib/install/loaders/typescript.js +6 -0
  66. data/lib/install/loaders/vue.js +13 -0
  67. data/lib/install/react.rb +28 -0
  68. data/lib/install/template.rb +37 -0
  69. data/lib/install/vue.rb +26 -0
  70. data/lib/tasks/installers.rake +24 -0
  71. data/lib/tasks/webpacker.rake +22 -0
  72. data/lib/tasks/webpacker/check_binstubs.rake +12 -0
  73. data/lib/tasks/webpacker/check_node.rake +24 -0
  74. data/lib/tasks/webpacker/check_yarn.rake +24 -0
  75. data/lib/tasks/webpacker/clobber.rake +16 -0
  76. data/lib/tasks/webpacker/compile.rake +41 -0
  77. data/lib/tasks/webpacker/install.rake +13 -0
  78. data/lib/tasks/webpacker/verify_install.rake +16 -0
  79. data/lib/tasks/webpacker/yarn_install.rake +6 -0
  80. data/lib/webpacker.rb +32 -0
  81. data/lib/webpacker/commands.rb +23 -0
  82. data/lib/webpacker/compiler.rb +88 -0
  83. data/lib/webpacker/configuration.rb +87 -0
  84. data/lib/webpacker/dev_server.rb +61 -0
  85. data/lib/webpacker/dev_server_proxy.rb +26 -0
  86. data/lib/webpacker/dev_server_runner.rb +51 -0
  87. data/lib/webpacker/helper.rb +66 -0
  88. data/lib/webpacker/instance.rb +44 -0
  89. data/lib/webpacker/manifest.rb +75 -0
  90. data/lib/webpacker/railtie.rb +82 -0
  91. data/lib/webpacker/rake_tasks.rb +6 -0
  92. data/lib/webpacker/runner.rb +22 -0
  93. data/lib/webpacker/version.rb +9 -0
  94. data/lib/webpacker/webpack_runner.rb +15 -0
  95. data/package.json +67 -0
  96. data/package/__tests__/environment.js +74 -0
  97. data/package/config.js +34 -0
  98. data/package/config_types/__tests__/config_list.js +123 -0
  99. data/package/config_types/__tests__/config_object.js +43 -0
  100. data/package/config_types/config_list.js +85 -0
  101. data/package/config_types/config_object.js +55 -0
  102. data/package/config_types/index.js +7 -0
  103. data/package/environment.js +116 -0
  104. data/package/environments/development.js +46 -0
  105. data/package/environments/production.js +37 -0
  106. data/package/environments/test.js +3 -0
  107. data/package/index.js +20 -0
  108. data/package/rules/babel.js +13 -0
  109. data/package/rules/css.js +39 -0
  110. data/package/rules/file.js +13 -0
  111. data/package/rules/index.js +11 -0
  112. data/package/rules/sass.js +15 -0
  113. data/package/utils/__tests__/deep_assign.js +11 -0
  114. data/package/utils/__tests__/deep_merge.js +10 -0
  115. data/package/utils/__tests__/objectify.js +9 -0
  116. data/package/utils/deep_assign.js +22 -0
  117. data/package/utils/deep_merge.js +23 -0
  118. data/package/utils/helpers.js +32 -0
  119. data/package/utils/objectify.js +4 -0
  120. data/test/command_test.rb +27 -0
  121. data/test/compiler_test.rb +35 -0
  122. data/test/configuration_test.rb +69 -0
  123. data/test/dev_server_test.rb +24 -0
  124. data/test/helper_test.rb +52 -0
  125. data/test/manifest_test.rb +28 -0
  126. data/test/rake_tasks_test.rb +29 -0
  127. data/test/test_app/Rakefile +3 -0
  128. data/test/test_app/app/javascript/packs/application.js +10 -0
  129. data/test/test_app/config/application.rb +11 -0
  130. data/test/test_app/config/environment.rb +4 -0
  131. data/test/test_app/config/webpacker.yml +65 -0
  132. data/test/test_app/public/packs/manifest.json +6 -0
  133. data/test/test_helper.rb +29 -0
  134. data/webpacker-jets.gemspec +29 -0
  135. data/yarn.lock +5768 -0
  136. metadata +250 -0
@@ -0,0 +1,13 @@
1
+ const { join } = require('path')
2
+ const { source_path } = require('../config')
3
+
4
+ module.exports = {
5
+ exclude: /\.(js|jsx|coffee|ts|tsx|vue|elm|scss|sass|css|html|json)?(\.erb)?$/,
6
+ use: [{
7
+ loader: 'file-loader',
8
+ options: {
9
+ name: '[path][name]-[hash].[ext]',
10
+ context: join(source_path)
11
+ }
12
+ }]
13
+ }
@@ -0,0 +1,11 @@
1
+ const babel = require('./babel')
2
+ const file = require('./file')
3
+ const css = require('./css')
4
+ const sass = require('./sass')
5
+
6
+ module.exports = {
7
+ babel,
8
+ css,
9
+ sass,
10
+ file
11
+ }
@@ -0,0 +1,15 @@
1
+ const cssLoader = require('./css')
2
+ const deepMerge = require('../utils/deep_merge')
3
+
4
+ // Duplicate and remove css loader object reference
5
+ let sassLoader = JSON.parse(JSON.stringify(cssLoader))
6
+
7
+ sassLoader = deepMerge(sassLoader, {
8
+ test: /\.(scss|sass)$/i,
9
+ use: [{
10
+ loader: 'sass-loader',
11
+ options: { sourceMap: true }
12
+ }]
13
+ })
14
+
15
+ module.exports = sassLoader
@@ -0,0 +1,11 @@
1
+ /* global test expect */
2
+
3
+ const deepAssign = require('../deep_assign')
4
+
5
+ test('deep assign property', () => {
6
+ const object = { foo: { bar: { } } }
7
+ const path = 'foo.bar'
8
+ const value = { x: 1, y: 2 }
9
+ const expectation = { foo: { bar: { x: 1, y: 2 } } }
10
+ expect(deepAssign(object, path, value)).toEqual(expectation)
11
+ })
@@ -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,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) 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,23 @@
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
+ (Object.assign(
15
+ {},
16
+ result,
17
+ { [key]: deepMerge(target[key], source[key]) }
18
+ )),
19
+ {}
20
+ )
21
+ }
22
+
23
+ module.exports = deepMerge
@@ -0,0 +1,32 @@
1
+ const isObject = value => (
2
+ typeof value === 'object' &&
3
+ value !== null &&
4
+ (value.length === undefined || value.length === null)
5
+ )
6
+
7
+ const isEmpty = value => (value === null || value === undefined)
8
+
9
+ const isString = key => key && typeof key === 'string'
10
+
11
+ const isStrPath = (key) => {
12
+ if (!isString(key)) throw new Error(`Key ${key} should be string`)
13
+ return isString(key) && key.includes('.')
14
+ }
15
+
16
+ const isArray = value => Array.isArray(value)
17
+
18
+ const isEqual = (target, source) => JSON.stringify(target) === JSON.stringify(source)
19
+
20
+ const canMerge = value => isObject(value) || isArray(value)
21
+
22
+ const prettyPrint = obj => JSON.stringify(obj, null, 2)
23
+
24
+ module.exports = {
25
+ isObject,
26
+ isArray,
27
+ isEqual,
28
+ isEmpty,
29
+ isStrPath,
30
+ canMerge,
31
+ prettyPrint
32
+ }
@@ -0,0 +1,4 @@
1
+ const objectify = (path, obj) =>
2
+ path.split('.').reduce((prev, curr) => (prev ? prev[curr] : undefined), obj)
3
+
4
+ module.exports = objectify
@@ -0,0 +1,27 @@
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
+ end
@@ -0,0 +1,35 @@
1
+ require "test_helper"
2
+
3
+ class CompilerTest < Minitest::Test
4
+ def setup
5
+ Webpacker.compiler.send(:compilation_digest_path).tap do |path|
6
+ path.delete if path.exist?
7
+ end
8
+ end
9
+
10
+ def test_custom_environment_variables
11
+ assert Webpacker.compiler.send(:webpack_env)["FOO"] == nil
12
+ Webpacker.compiler.env["FOO"] = "BAR"
13
+ assert Webpacker.compiler.send(:webpack_env)["FOO"] == "BAR"
14
+ end
15
+
16
+ def test_default_watched_paths
17
+ assert_equal Webpacker.compiler.send(:default_watched_paths), [
18
+ "app/assets/**/*",
19
+ "/etc/yarn/**/*",
20
+ "test/test_app/app/javascript/**/*",
21
+ "yarn.lock",
22
+ "package.json",
23
+ "config/webpack/**/*"
24
+ ]
25
+ end
26
+
27
+ def test_freshness
28
+ assert Webpacker.compiler.stale?
29
+ assert !Webpacker.compiler.fresh?
30
+ end
31
+
32
+ def test_compilation_digest_path
33
+ assert Webpacker.compiler.send(:compilation_digest_path).to_s.ends_with?(Webpacker.env)
34
+ end
35
+ end
@@ -0,0 +1,69 @@
1
+ require "test_helper"
2
+
3
+ class ConfigurationTest < Webpacker::Test
4
+ def test_source_path
5
+ source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
6
+ assert_equal source_path, Webpacker.config.source_path.to_s
7
+ end
8
+
9
+ def test_source_entry_path
10
+ source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "packs").to_s
11
+ assert_equal Webpacker.config.source_entry_path.to_s, source_entry_path
12
+ end
13
+
14
+ def test_public_output_path
15
+ public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
16
+ assert_equal Webpacker.config.public_output_path.to_s, public_output_path
17
+ end
18
+
19
+ def test_public_manifest_path
20
+ public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
21
+ assert_equal Webpacker.config.public_manifest_path.to_s, public_manifest_path
22
+ end
23
+
24
+ def test_cache_path
25
+ cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/cache/webpacker").to_s
26
+ assert_equal Webpacker.config.cache_path.to_s, cache_path
27
+ end
28
+
29
+ def test_resolved_paths
30
+ assert_equal Webpacker.config.resolved_paths, ["app/assets", "/etc/yarn"]
31
+ end
32
+
33
+ def test_resolved_paths_globbed
34
+ assert_equal Webpacker.config.resolved_paths_globbed, ["app/assets/**/*", "/etc/yarn/**/*"]
35
+ end
36
+
37
+ def test_extensions
38
+ webpacker_yml = YAML.load_file("lib/install/config/webpacker.yml")
39
+ assert_equal Webpacker.config.extensions, webpacker_yml["default"]["extensions"]
40
+ end
41
+
42
+ def test_cache_manifest?
43
+ with_node_env("development") do
44
+ refute reloaded_config.cache_manifest?
45
+ end
46
+
47
+ with_node_env("test") do
48
+ refute reloaded_config.cache_manifest?
49
+ end
50
+
51
+ with_node_env("production") do
52
+ assert reloaded_config.cache_manifest?
53
+ end
54
+ end
55
+
56
+ def test_compile?
57
+ with_node_env("development") do
58
+ assert reloaded_config.compile?
59
+ end
60
+
61
+ with_node_env("test") do
62
+ assert reloaded_config.compile?
63
+ end
64
+
65
+ with_node_env("production") do
66
+ refute reloaded_config.compile?
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ class DevServerTest < Webpacker::Test
4
+ def test_host
5
+ with_node_env("development") do
6
+ reloaded_config
7
+ assert_equal Webpacker.dev_server.host, "localhost"
8
+ end
9
+ end
10
+
11
+ def test_port
12
+ with_node_env("development") do
13
+ reloaded_config
14
+ assert_equal Webpacker.dev_server.port, 3035
15
+ end
16
+ end
17
+
18
+ def test_https?
19
+ with_node_env("development") do
20
+ reloaded_config
21
+ assert_equal Webpacker.dev_server.https?, false
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,52 @@
1
+ require "test_helper"
2
+
3
+ class HelperTest < ActionView::TestCase
4
+ tests Webpacker::Helper
5
+
6
+ attr_reader :request
7
+
8
+ def setup
9
+ @request = Class.new do
10
+ def send_early_hints(links) end
11
+ def base_url
12
+ "https://example.com"
13
+ end
14
+ end.new
15
+ end
16
+
17
+ def test_asset_pack_path
18
+ assert_equal "/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_path("bootstrap.js")
19
+ assert_equal "/packs/bootstrap-c38deda30895059837cf.css", asset_pack_path("bootstrap.css")
20
+ end
21
+
22
+ def test_asset_pack_url
23
+ assert_equal "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_url("bootstrap.js")
24
+ assert_equal "https://example.com/packs/bootstrap-c38deda30895059837cf.css", asset_pack_url("bootstrap.css")
25
+ end
26
+
27
+ def test_javascript_pack_tag
28
+ assert_equal \
29
+ %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
30
+ javascript_pack_tag("bootstrap.js")
31
+ end
32
+
33
+ def test_javascript_pack_tag_splat
34
+ assert_equal \
35
+ %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
36
+ %(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
37
+ javascript_pack_tag("bootstrap.js", "application.js", defer: true)
38
+ end
39
+
40
+ def test_stylesheet_pack_tag
41
+ assert_equal \
42
+ %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
43
+ stylesheet_pack_tag("bootstrap.css")
44
+ end
45
+
46
+ def test_stylesheet_pack_tag_splat
47
+ assert_equal \
48
+ %(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
49
+ %(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
50
+ stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ require "test_helper"
2
+
3
+ class ManifestTest < Minitest::Test
4
+ def test_lookup_exception!
5
+ manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
6
+ asset_file = "calendar.js"
7
+
8
+ Webpacker.config.stub :compile?, false do
9
+ error = assert_raises Webpacker::Manifest::MissingEntryError do
10
+ Webpacker.manifest.lookup!(asset_file)
11
+ end
12
+
13
+ assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message
14
+ end
15
+ end
16
+
17
+ def test_lookup_success!
18
+ assert_equal Webpacker.manifest.lookup!("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
19
+ end
20
+
21
+ def test_lookup_nil
22
+ assert_nil Webpacker.manifest.lookup("foo.js")
23
+ end
24
+
25
+ def test_lookup_success
26
+ assert_equal Webpacker.manifest.lookup("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class RakeTasksTest < Minitest::Test
4
+ def test_rake_tasks
5
+ output = Dir.chdir(test_app_path) { `rake -T` }
6
+ assert_includes output, "webpacker"
7
+ assert_includes output, "webpacker:check_binstubs"
8
+ assert_includes output, "webpacker:check_node"
9
+ assert_includes output, "webpacker:check_yarn"
10
+ assert_includes output, "webpacker:clobber"
11
+ assert_includes output, "webpacker:compile"
12
+ assert_includes output, "webpacker:install"
13
+ assert_includes output, "webpacker:install:angular"
14
+ assert_includes output, "webpacker:install:elm"
15
+ assert_includes output, "webpacker:install:react"
16
+ assert_includes output, "webpacker:install:vue"
17
+ assert_includes output, "webpacker:verify_install"
18
+ end
19
+
20
+ def test_rake_task_webpacker_check_binstubs
21
+ output = Dir.chdir(test_app_path) { `rake webpacker:check_binstubs 2>&1` }
22
+ refute_includes output, "webpack binstubs not found."
23
+ end
24
+
25
+ private
26
+ def test_app_path
27
+ File.expand_path("test_app", __dir__)
28
+ end
29
+ end