tiny-lite-sys 0.0.1
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 +7 -0
- data/tiny-lite-sys.gemspec +11 -0
- data/webpacker-5.4.4/CHANGELOG.md +1074 -0
- data/webpacker-5.4.4/CONTRIBUTING.md +33 -0
- data/webpacker-5.4.4/Gemfile +13 -0
- data/webpacker-5.4.4/Gemfile.lock +183 -0
- data/webpacker-5.4.4/MIT-LICENSE +20 -0
- data/webpacker-5.4.4/README.md +427 -0
- data/webpacker-5.4.4/Rakefile +11 -0
- data/webpacker-5.4.4/docs/assets.md +119 -0
- data/webpacker-5.4.4/docs/cloud9.md +310 -0
- data/webpacker-5.4.4/docs/css.md +308 -0
- data/webpacker-5.4.4/docs/deployment.md +130 -0
- data/webpacker-5.4.4/docs/docker.md +68 -0
- data/webpacker-5.4.4/docs/engines.md +213 -0
- data/webpacker-5.4.4/docs/env.md +63 -0
- data/webpacker-5.4.4/docs/es6.md +72 -0
- data/webpacker-5.4.4/docs/folder-structure.md +66 -0
- data/webpacker-5.4.4/docs/integrations.md +220 -0
- data/webpacker-5.4.4/docs/misc.md +23 -0
- data/webpacker-5.4.4/docs/props.md +223 -0
- data/webpacker-5.4.4/docs/target.md +22 -0
- data/webpacker-5.4.4/docs/testing.md +136 -0
- data/webpacker-5.4.4/docs/troubleshooting.md +158 -0
- data/webpacker-5.4.4/docs/typescript.md +190 -0
- data/webpacker-5.4.4/docs/v4-upgrade.md +142 -0
- data/webpacker-5.4.4/docs/webpack-dev-server.md +92 -0
- data/webpacker-5.4.4/docs/webpack.md +364 -0
- data/webpacker-5.4.4/docs/yarn.md +23 -0
- data/webpacker-5.4.4/gemfiles/Gemfile-rails-edge +12 -0
- data/webpacker-5.4.4/gemfiles/Gemfile-rails.5.2.x +9 -0
- data/webpacker-5.4.4/gemfiles/Gemfile-rails.6.0.x +9 -0
- data/webpacker-5.4.4/lib/install/angular.rb +23 -0
- data/webpacker-5.4.4/lib/install/bin/webpack +18 -0
- data/webpacker-5.4.4/lib/install/bin/webpack-dev-server +18 -0
- data/webpacker-5.4.4/lib/install/binstubs.rb +4 -0
- data/webpacker-5.4.4/lib/install/coffee.rb +25 -0
- data/webpacker-5.4.4/lib/install/config/babel.config.js +82 -0
- data/webpacker-5.4.4/lib/install/config/postcss.config.js +12 -0
- data/webpacker-5.4.4/lib/install/config/webpack/development.js +5 -0
- data/webpacker-5.4.4/lib/install/config/webpack/environment.js +3 -0
- data/webpacker-5.4.4/lib/install/config/webpack/production.js +5 -0
- data/webpacker-5.4.4/lib/install/config/webpack/test.js +5 -0
- data/webpacker-5.4.4/lib/install/config/webpacker.yml +92 -0
- data/webpacker-5.4.4/lib/install/elm.rb +39 -0
- data/webpacker-5.4.4/lib/install/erb.rb +25 -0
- data/webpacker-5.4.4/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/webpacker-5.4.4/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/webpacker-5.4.4/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/webpacker-5.4.4/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/webpacker-5.4.4/lib/install/examples/angular/hello_angular.js +7 -0
- data/webpacker-5.4.4/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/webpacker-5.4.4/lib/install/examples/elm/Main.elm +55 -0
- data/webpacker-5.4.4/lib/install/examples/elm/hello_elm.js +16 -0
- data/webpacker-5.4.4/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/webpacker-5.4.4/lib/install/examples/react/babel.config.js +99 -0
- data/webpacker-5.4.4/lib/install/examples/react/hello_react.jsx +26 -0
- data/webpacker-5.4.4/lib/install/examples/react/tsconfig.json +21 -0
- data/webpacker-5.4.4/lib/install/examples/stimulus/application.js +1 -0
- data/webpacker-5.4.4/lib/install/examples/stimulus/controllers/hello_controller.js +18 -0
- data/webpacker-5.4.4/lib/install/examples/stimulus/controllers/index.js +9 -0
- data/webpacker-5.4.4/lib/install/examples/svelte/app.svelte +11 -0
- data/webpacker-5.4.4/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/webpacker-5.4.4/lib/install/examples/typescript/hello_typescript.ts +4 -0
- data/webpacker-5.4.4/lib/install/examples/typescript/tsconfig.json +24 -0
- data/webpacker-5.4.4/lib/install/examples/vue/app.vue +22 -0
- data/webpacker-5.4.4/lib/install/examples/vue/hello_vue.js +72 -0
- data/webpacker-5.4.4/lib/install/javascript/packs/application.js +18 -0
- data/webpacker-5.4.4/lib/install/loaders/coffee.js +6 -0
- data/webpacker-5.4.4/lib/install/loaders/elm.js +25 -0
- data/webpacker-5.4.4/lib/install/loaders/erb.js +11 -0
- data/webpacker-5.4.4/lib/install/loaders/svelte.js +9 -0
- data/webpacker-5.4.4/lib/install/loaders/vue.js +6 -0
- data/webpacker-5.4.4/lib/install/react.rb +18 -0
- data/webpacker-5.4.4/lib/install/stimulus.rb +12 -0
- data/webpacker-5.4.4/lib/install/svelte.rb +29 -0
- data/webpacker-5.4.4/lib/install/template.rb +63 -0
- data/webpacker-5.4.4/lib/install/typescript.rb +39 -0
- data/webpacker-5.4.4/lib/install/vue.rb +49 -0
- data/webpacker-5.4.4/lib/tasks/installers.rake +42 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/binstubs.rake +13 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/check_node.rake +31 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/check_yarn.rake +30 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/clean.rake +25 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/clobber.rake +20 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/compile.rake +43 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/info.rake +19 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/install.rake +13 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/verify_install.rake +13 -0
- data/webpacker-5.4.4/lib/tasks/webpacker/yarn_install.rake +16 -0
- data/webpacker-5.4.4/lib/tasks/webpacker.rake +28 -0
- data/webpacker-5.4.4/lib/webpacker/commands.rb +74 -0
- data/webpacker-5.4.4/lib/webpacker/compiler.rb +111 -0
- data/webpacker-5.4.4/lib/webpacker/configuration.rb +128 -0
- data/webpacker-5.4.4/lib/webpacker/dev_server.rb +66 -0
- data/webpacker-5.4.4/lib/webpacker/dev_server_proxy.rb +33 -0
- data/webpacker-5.4.4/lib/webpacker/dev_server_runner.rb +72 -0
- data/webpacker-5.4.4/lib/webpacker/env.rb +43 -0
- data/webpacker-5.4.4/lib/webpacker/helper.rb +195 -0
- data/webpacker-5.4.4/lib/webpacker/instance.rb +37 -0
- data/webpacker-5.4.4/lib/webpacker/manifest.rb +118 -0
- data/webpacker-5.4.4/lib/webpacker/railtie.rb +55 -0
- data/webpacker-5.4.4/lib/webpacker/runner.rb +23 -0
- data/webpacker-5.4.4/lib/webpacker/version.rb +4 -0
- data/webpacker-5.4.4/lib/webpacker/webpack_runner.rb +32 -0
- data/webpacker-5.4.4/lib/webpacker.rb +46 -0
- data/webpacker-5.4.4/package/__tests__/config.js +66 -0
- data/webpacker-5.4.4/package/__tests__/dev_server.js +45 -0
- data/webpacker-5.4.4/package/__tests__/development.js +43 -0
- data/webpacker-5.4.4/package/__tests__/env.js +46 -0
- data/webpacker-5.4.4/package/__tests__/production.js +29 -0
- data/webpacker-5.4.4/package/__tests__/staging.js +29 -0
- data/webpacker-5.4.4/package/__tests__/test.js +26 -0
- data/webpacker-5.4.4/package/config.js +40 -0
- data/webpacker-5.4.4/package/configPath.js +3 -0
- data/webpacker-5.4.4/package/config_types/__tests__/config_list.js +118 -0
- data/webpacker-5.4.4/package/config_types/__tests__/config_object.js +43 -0
- data/webpacker-5.4.4/package/config_types/config_list.js +75 -0
- data/webpacker-5.4.4/package/config_types/config_object.js +55 -0
- data/webpacker-5.4.4/package/config_types/index.js +7 -0
- data/webpacker-5.4.4/package/dev_server.js +20 -0
- data/webpacker-5.4.4/package/env.js +18 -0
- data/webpacker-5.4.4/package/environments/__tests__/base.js +101 -0
- data/webpacker-5.4.4/package/environments/base.js +176 -0
- data/webpacker-5.4.4/package/environments/development.js +53 -0
- data/webpacker-5.4.4/package/environments/production.js +77 -0
- data/webpacker-5.4.4/package/environments/test.js +3 -0
- data/webpacker-5.4.4/package/index.js +24 -0
- data/webpacker-5.4.4/package/rules/babel.js +28 -0
- data/webpacker-5.4.4/package/rules/css.js +3 -0
- data/webpacker-5.4.4/package/rules/file.js +21 -0
- data/webpacker-5.4.4/package/rules/index.js +20 -0
- data/webpacker-5.4.4/package/rules/module.css.js +3 -0
- data/webpacker-5.4.4/package/rules/module.sass.js +8 -0
- data/webpacker-5.4.4/package/rules/node_modules.js +22 -0
- data/webpacker-5.4.4/package/rules/sass.js +17 -0
- data/webpacker-5.4.4/package/utils/__tests__/deep_assign.js +32 -0
- data/webpacker-5.4.4/package/utils/__tests__/deep_merge.js +10 -0
- data/webpacker-5.4.4/package/utils/__tests__/get_style_rule.js +65 -0
- data/webpacker-5.4.4/package/utils/__tests__/objectify.js +9 -0
- data/webpacker-5.4.4/package/utils/deep_assign.js +22 -0
- data/webpacker-5.4.4/package/utils/deep_merge.js +22 -0
- data/webpacker-5.4.4/package/utils/get_style_rule.js +45 -0
- data/webpacker-5.4.4/package/utils/helpers.js +58 -0
- data/webpacker-5.4.4/package/utils/objectify.js +3 -0
- data/webpacker-5.4.4/package.json +82 -0
- data/webpacker-5.4.4/test/command_test.rb +33 -0
- data/webpacker-5.4.4/test/compiler_test.rb +80 -0
- data/webpacker-5.4.4/test/configuration_test.rb +109 -0
- data/webpacker-5.4.4/test/dev_server_runner_test.rb +51 -0
- data/webpacker-5.4.4/test/dev_server_test.rb +47 -0
- data/webpacker-5.4.4/test/env_test.rb +23 -0
- data/webpacker-5.4.4/test/helper_test.rb +157 -0
- data/webpacker-5.4.4/test/manifest_test.rb +73 -0
- data/webpacker-5.4.4/test/rake_tasks_test.rb +80 -0
- data/webpacker-5.4.4/test/test_app/Rakefile +3 -0
- data/webpacker-5.4.4/test/test_app/app/javascript/packs/application.js +10 -0
- data/webpacker-5.4.4/test/test_app/app/javascript/packs/multi_entry.css +4 -0
- data/webpacker-5.4.4/test/test_app/app/javascript/packs/multi_entry.js +4 -0
- data/webpacker-5.4.4/test/test_app/bin/webpack +14 -0
- data/webpacker-5.4.4/test/test_app/bin/webpack-dev-server +14 -0
- data/webpacker-5.4.4/test/test_app/config/application.rb +11 -0
- data/webpacker-5.4.4/test/test_app/config/environment.rb +4 -0
- data/webpacker-5.4.4/test/test_app/config/webpack/development.js +0 -0
- data/webpacker-5.4.4/test/test_app/config/webpacker.yml +103 -0
- data/webpacker-5.4.4/test/test_app/config/webpacker_public_root.yml +19 -0
- data/webpacker-5.4.4/test/test_app/config.ru +5 -0
- data/webpacker-5.4.4/test/test_app/package.json +13 -0
- data/webpacker-5.4.4/test/test_app/public/packs/manifest.json +32 -0
- data/webpacker-5.4.4/test/test_app/yarn.lock +11 -0
- data/webpacker-5.4.4/test/test_helper.rb +33 -0
- data/webpacker-5.4.4/test/webpack_runner_test.rb +51 -0
- data/webpacker-5.4.4/test/webpacker_test.rb +13 -0
- data/webpacker-5.4.4/webpacker.gemspec +31 -0
- data/webpacker-5.4.4/yarn.lock +8271 -0
- metadata +215 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
namespace :webpacker do
|
|
2
|
+
desc "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
|
|
3
|
+
task :yarn_install do
|
|
4
|
+
valid_node_envs = %w[test development production]
|
|
5
|
+
node_env = ENV.fetch("NODE_ENV") do
|
|
6
|
+
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
|
|
7
|
+
end
|
|
8
|
+
yarn_flags =
|
|
9
|
+
if `yarn --version`.start_with?("1")
|
|
10
|
+
"--no-progress --frozen-lockfile"
|
|
11
|
+
else
|
|
12
|
+
"--immutable"
|
|
13
|
+
end
|
|
14
|
+
system({ "NODE_ENV" => node_env }, "yarn install #{yarn_flags}")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
tasks = {
|
|
2
|
+
"webpacker:info" => "Provides information on Webpacker's environment",
|
|
3
|
+
"webpacker:install" => "Installs and setup webpack with Yarn",
|
|
4
|
+
"webpacker:compile" => "Compiles webpack bundles based on environment",
|
|
5
|
+
"webpacker:clean" => "Remove old compiled webpacks",
|
|
6
|
+
"webpacker:clobber" => "Removes the webpack compiled output directory",
|
|
7
|
+
"webpacker:check_node" => "Verifies if Node.js is installed",
|
|
8
|
+
"webpacker:check_yarn" => "Verifies if Yarn is installed",
|
|
9
|
+
"webpacker:check_binstubs" => "Verifies that webpack & webpack-dev-server are present",
|
|
10
|
+
"webpacker:binstubs" => "Installs Webpacker binstubs in this application",
|
|
11
|
+
"webpacker:verify_install" => "Verifies if Webpacker is installed",
|
|
12
|
+
"webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn",
|
|
13
|
+
"webpacker:install:react" => "Installs and setup example React component",
|
|
14
|
+
"webpacker:install:vue" => "Installs and setup example Vue component",
|
|
15
|
+
"webpacker:install:angular" => "Installs and setup example Angular component",
|
|
16
|
+
"webpacker:install:elm" => "Installs and setup example Elm component",
|
|
17
|
+
"webpacker:install:svelte" => "Installs and setup example Svelte component",
|
|
18
|
+
"webpacker:install:stimulus" => "Installs and setup example Stimulus component",
|
|
19
|
+
"webpacker:install:erb" => "Installs Erb loader with an example",
|
|
20
|
+
"webpacker:install:coffee" => "Installs CoffeeScript loader with an example",
|
|
21
|
+
"webpacker:install:typescript" => "Installs Typescript loader with an example"
|
|
22
|
+
}.freeze
|
|
23
|
+
|
|
24
|
+
desc "Lists all available tasks in Webpacker"
|
|
25
|
+
task :webpacker do
|
|
26
|
+
puts "Available Webpacker tasks are:"
|
|
27
|
+
tasks.each { |task, message| puts task.ljust(30) + message }
|
|
28
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
class Webpacker::Commands
|
|
2
|
+
delegate :config, :compiler, :manifest, :logger, to: :@webpacker
|
|
3
|
+
|
|
4
|
+
def initialize(webpacker)
|
|
5
|
+
@webpacker = webpacker
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Cleanup old assets in the compile directory. By default it will
|
|
9
|
+
# keep the latest version, 2 backups created within the past hour.
|
|
10
|
+
#
|
|
11
|
+
# Examples
|
|
12
|
+
#
|
|
13
|
+
# To force only 1 backup to be kept, set count=1 and age=0.
|
|
14
|
+
#
|
|
15
|
+
# To only keep files created within the last 10 minutes, set count=0 and
|
|
16
|
+
# age=600.
|
|
17
|
+
#
|
|
18
|
+
def clean(count = 2, age = 3600)
|
|
19
|
+
if config.public_output_path.exist? && config.public_manifest_path.exist?
|
|
20
|
+
versions
|
|
21
|
+
.sort
|
|
22
|
+
.reverse
|
|
23
|
+
.each_with_index
|
|
24
|
+
.drop_while do |(mtime, _), index|
|
|
25
|
+
max_age = [0, Time.now - Time.at(mtime)].max
|
|
26
|
+
max_age < age || index < count
|
|
27
|
+
end
|
|
28
|
+
.each do |(_, files), index|
|
|
29
|
+
files.each do |file|
|
|
30
|
+
if File.file?(file)
|
|
31
|
+
File.delete(file)
|
|
32
|
+
logger.info "Removed #{file}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def clobber
|
|
42
|
+
config.public_output_path.rmtree if config.public_output_path.exist?
|
|
43
|
+
config.cache_path.rmtree if config.cache_path.exist?
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def bootstrap
|
|
47
|
+
manifest.refresh
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def compile
|
|
51
|
+
compiler.compile.tap do |success|
|
|
52
|
+
manifest.refresh if success
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
def versions
|
|
58
|
+
all_files = Dir.glob("#{config.public_output_path}/**/*")
|
|
59
|
+
manifest_config = Dir.glob("#{config.public_manifest_path}*")
|
|
60
|
+
|
|
61
|
+
packs = all_files - manifest_config - current_version
|
|
62
|
+
packs.reject { |file| File.directory?(file) }.group_by { |file| File.mtime(file).utc.to_i }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def current_version
|
|
66
|
+
packs = manifest.refresh.values.map do |value|
|
|
67
|
+
next if value.is_a?(Hash)
|
|
68
|
+
|
|
69
|
+
File.join(config.root_path, "public", "#{value}*")
|
|
70
|
+
end.compact
|
|
71
|
+
|
|
72
|
+
Dir.glob(packs).uniq
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require "open3"
|
|
2
|
+
require "digest/sha1"
|
|
3
|
+
|
|
4
|
+
class Webpacker::Compiler
|
|
5
|
+
# Additional paths that test compiler needs to watch
|
|
6
|
+
# Webpacker::Compiler.watched_paths << 'bower_components'
|
|
7
|
+
#
|
|
8
|
+
# Deprecated. Use additional_paths in the YAML configuration instead.
|
|
9
|
+
cattr_accessor(:watched_paths) { [] }
|
|
10
|
+
|
|
11
|
+
# Additional environment variables that the compiler is being run with
|
|
12
|
+
# Webpacker::Compiler.env['FRONTEND_API_KEY'] = 'your_secret_key'
|
|
13
|
+
cattr_accessor(:env) { {} }
|
|
14
|
+
|
|
15
|
+
delegate :config, :logger, to: :webpacker
|
|
16
|
+
|
|
17
|
+
def initialize(webpacker)
|
|
18
|
+
@webpacker = webpacker
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def compile
|
|
22
|
+
if stale?
|
|
23
|
+
run_webpack.tap do |success|
|
|
24
|
+
# We used to only record the digest on success
|
|
25
|
+
# However, the output file is still written on error, meaning that the digest should still be updated.
|
|
26
|
+
# If it's not, you can end up in a situation where a recompile doesn't take place when it should.
|
|
27
|
+
# See https://github.com/rails/webpacker/issues/2113
|
|
28
|
+
record_compilation_digest
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
logger.info "Everything's up-to-date. Nothing to do"
|
|
32
|
+
true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Returns true if all the compiled packs are up to date with the underlying asset files.
|
|
37
|
+
def fresh?
|
|
38
|
+
watched_files_digest == last_compilation_digest
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns true if the compiled packs are out of date with the underlying asset files.
|
|
42
|
+
def stale?
|
|
43
|
+
!fresh?
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
attr_reader :webpacker
|
|
48
|
+
|
|
49
|
+
def last_compilation_digest
|
|
50
|
+
compilation_digest_path.read if compilation_digest_path.exist? && config.public_manifest_path.exist?
|
|
51
|
+
rescue Errno::ENOENT, Errno::ENOTDIR
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def watched_files_digest
|
|
55
|
+
warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty?
|
|
56
|
+
|
|
57
|
+
files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
|
|
58
|
+
file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
|
|
59
|
+
Digest::SHA1.hexdigest(file_ids.join("/"))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def record_compilation_digest
|
|
63
|
+
config.cache_path.mkpath
|
|
64
|
+
compilation_digest_path.write(watched_files_digest)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def run_webpack
|
|
68
|
+
logger.info "Compiling..."
|
|
69
|
+
|
|
70
|
+
stdout, stderr, status = Open3.capture3(
|
|
71
|
+
webpack_env,
|
|
72
|
+
"#{RbConfig.ruby} ./bin/webpack",
|
|
73
|
+
chdir: File.expand_path(config.root_path)
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if status.success?
|
|
77
|
+
logger.info "Compiled all packs in #{config.public_output_path}"
|
|
78
|
+
logger.error "#{stderr}" unless stderr.empty?
|
|
79
|
+
|
|
80
|
+
if config.webpack_compile_output?
|
|
81
|
+
logger.info stdout
|
|
82
|
+
end
|
|
83
|
+
else
|
|
84
|
+
non_empty_streams = [stdout, stderr].delete_if(&:empty?)
|
|
85
|
+
logger.error "Compilation failed:\n#{non_empty_streams.join("\n\n")}"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
status.success?
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def default_watched_paths
|
|
92
|
+
[
|
|
93
|
+
*config.additional_paths_globbed,
|
|
94
|
+
config.source_path_globbed,
|
|
95
|
+
"yarn.lock", "package.json",
|
|
96
|
+
"config/webpack/**/*"
|
|
97
|
+
].freeze
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def compilation_digest_path
|
|
101
|
+
config.cache_path.join("last-compilation-digest-#{webpacker.env}")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def webpack_env
|
|
105
|
+
return env unless defined?(ActionController::Base)
|
|
106
|
+
|
|
107
|
+
env.merge("WEBPACKER_ASSET_HOST" => ENV.fetch("WEBPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host),
|
|
108
|
+
"WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root),
|
|
109
|
+
"WEBPACKER_CONFIG" => webpacker.config_path.to_s)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
require "active_support/core_ext/hash/keys"
|
|
3
|
+
require "active_support/core_ext/hash/indifferent_access"
|
|
4
|
+
|
|
5
|
+
class Webpacker::Configuration
|
|
6
|
+
attr_reader :root_path, :config_path, :env
|
|
7
|
+
|
|
8
|
+
def initialize(root_path:, config_path:, env:)
|
|
9
|
+
@root_path = root_path
|
|
10
|
+
@config_path = config_path
|
|
11
|
+
@env = env
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def dev_server
|
|
15
|
+
fetch(:dev_server)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def compile?
|
|
19
|
+
fetch(:compile)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def source_path
|
|
23
|
+
root_path.join(fetch(:source_path))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def source_path_globbed
|
|
27
|
+
globbed_path_with_extensions(source_path.relative_path_from(root_path))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def additional_paths
|
|
31
|
+
fetch(:additional_paths) + resolved_paths
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def additional_paths_globbed
|
|
35
|
+
additional_paths.map { |p| globbed_path_with_extensions(p) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def source_entry_path
|
|
39
|
+
source_path.join(fetch(:source_entry_path))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def public_path
|
|
43
|
+
root_path.join(fetch(:public_root_path))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def public_output_path
|
|
47
|
+
public_path.join(fetch(:public_output_path))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def public_manifest_path
|
|
51
|
+
public_output_path.join("manifest.json")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def cache_manifest?
|
|
55
|
+
fetch(:cache_manifest)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def cache_path
|
|
59
|
+
root_path.join(fetch(:cache_path))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def extensions
|
|
63
|
+
fetch(:extensions)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def check_yarn_integrity=(value)
|
|
67
|
+
warn "Webpacker::Configuration#check_yarn_integrity=(value) has been deprecated. The integrity check has been removed from Webpacker so changing this setting will have no effect."
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def webpack_compile_output?
|
|
71
|
+
fetch(:webpack_compile_output)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def extract_css?
|
|
75
|
+
fetch(:extract_css)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
def resolved_paths
|
|
80
|
+
paths = data.fetch(:resolved_paths, [])
|
|
81
|
+
|
|
82
|
+
warn "The resolved_paths option has been deprecated. Use additional_paths instead." unless paths.empty?
|
|
83
|
+
|
|
84
|
+
paths
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def fetch(key)
|
|
88
|
+
data.fetch(key, defaults[key])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def data
|
|
92
|
+
@data ||= load
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def load
|
|
96
|
+
config = begin
|
|
97
|
+
YAML.load_file(config_path.to_s, aliases: true)
|
|
98
|
+
rescue ArgumentError
|
|
99
|
+
YAML.load_file(config_path.to_s)
|
|
100
|
+
end
|
|
101
|
+
config[env].deep_symbolize_keys
|
|
102
|
+
rescue Errno::ENOENT => e
|
|
103
|
+
raise "Webpacker configuration file not found #{config_path}. " \
|
|
104
|
+
"Please run rails webpacker:install " \
|
|
105
|
+
"Error: #{e.message}"
|
|
106
|
+
|
|
107
|
+
rescue Psych::SyntaxError => e
|
|
108
|
+
raise "YAML syntax error occurred while parsing #{config_path}. " \
|
|
109
|
+
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
|
110
|
+
"Error: #{e.message}"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def defaults
|
|
114
|
+
@defaults ||= begin
|
|
115
|
+
path = File.expand_path("../../install/config/webpacker.yml", __FILE__)
|
|
116
|
+
config = begin
|
|
117
|
+
YAML.load_file(path, aliases: true)
|
|
118
|
+
rescue ArgumentError
|
|
119
|
+
YAML.load_file(path)
|
|
120
|
+
end
|
|
121
|
+
HashWithIndifferentAccess.new(config[env])
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def globbed_path_with_extensions(path)
|
|
126
|
+
"#{path}/**/*{#{extensions.join(',')}}"
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
class Webpacker::DevServer
|
|
2
|
+
DEFAULT_ENV_PREFIX = "WEBPACKER_DEV_SERVER".freeze
|
|
3
|
+
|
|
4
|
+
# Configure dev server connection timeout (in seconds), default: 0.01
|
|
5
|
+
# Webpacker.dev_server.connect_timeout = 1
|
|
6
|
+
cattr_accessor(:connect_timeout) { 0.01 }
|
|
7
|
+
|
|
8
|
+
attr_reader :config
|
|
9
|
+
|
|
10
|
+
def initialize(config)
|
|
11
|
+
@config = config
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def running?
|
|
15
|
+
if config.dev_server.present?
|
|
16
|
+
Socket.tcp(host, port, connect_timeout: connect_timeout).close
|
|
17
|
+
true
|
|
18
|
+
else
|
|
19
|
+
false
|
|
20
|
+
end
|
|
21
|
+
rescue
|
|
22
|
+
false
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def host
|
|
26
|
+
fetch(:host)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def port
|
|
30
|
+
fetch(:port)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def https?
|
|
34
|
+
case fetch(:https)
|
|
35
|
+
when true, "true", Hash
|
|
36
|
+
true
|
|
37
|
+
else
|
|
38
|
+
false
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def protocol
|
|
43
|
+
https? ? "https" : "http"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def host_with_port
|
|
47
|
+
"#{host}:#{port}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def pretty?
|
|
51
|
+
fetch(:pretty)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def env_prefix
|
|
55
|
+
config.dev_server.fetch(:env_prefix, DEFAULT_ENV_PREFIX)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
def fetch(key)
|
|
60
|
+
ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def defaults
|
|
64
|
+
config.send(:defaults)[:dev_server] || {}
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "rack/proxy"
|
|
2
|
+
|
|
3
|
+
class Webpacker::DevServerProxy < Rack::Proxy
|
|
4
|
+
delegate :config, :dev_server, to: :@webpacker
|
|
5
|
+
|
|
6
|
+
def initialize(app = nil, opts = {})
|
|
7
|
+
@webpacker = opts.delete(:webpacker) || Webpacker.instance
|
|
8
|
+
opts[:streaming] = false if Rails.env.test? && !opts.key?(:streaming)
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def perform_request(env)
|
|
13
|
+
if env["PATH_INFO"].start_with?("/#{public_output_uri_path}") && dev_server.running?
|
|
14
|
+
env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = dev_server.host
|
|
15
|
+
env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
|
|
16
|
+
env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
|
|
17
|
+
env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
|
|
18
|
+
unless dev_server.https?
|
|
19
|
+
env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
|
|
20
|
+
end
|
|
21
|
+
env["SCRIPT_NAME"] = ""
|
|
22
|
+
|
|
23
|
+
super(env)
|
|
24
|
+
else
|
|
25
|
+
@app.call(env)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
def public_output_uri_path
|
|
31
|
+
config.public_output_path.relative_path_from(config.public_path).to_s + "/"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require "shellwords"
|
|
2
|
+
require "socket"
|
|
3
|
+
require "webpacker/configuration"
|
|
4
|
+
require "webpacker/dev_server"
|
|
5
|
+
require "webpacker/runner"
|
|
6
|
+
|
|
7
|
+
module Webpacker
|
|
8
|
+
class DevServerRunner < Webpacker::Runner
|
|
9
|
+
def run
|
|
10
|
+
load_config
|
|
11
|
+
detect_port!
|
|
12
|
+
execute_cmd
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
def load_config
|
|
17
|
+
app_root = Pathname.new(@app_path)
|
|
18
|
+
|
|
19
|
+
@config = Configuration.new(
|
|
20
|
+
root_path: app_root,
|
|
21
|
+
config_path: app_root.join("config/webpacker.yml"),
|
|
22
|
+
env: ENV["RAILS_ENV"]
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
dev_server = DevServer.new(@config)
|
|
26
|
+
|
|
27
|
+
@hostname = dev_server.host
|
|
28
|
+
@port = dev_server.port
|
|
29
|
+
@pretty = dev_server.pretty?
|
|
30
|
+
|
|
31
|
+
rescue Errno::ENOENT, NoMethodError
|
|
32
|
+
$stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
|
33
|
+
$stdout.puts "Please run bundle exec rails webpacker:install to install Webpacker"
|
|
34
|
+
exit!
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def detect_port!
|
|
38
|
+
server = TCPServer.new(@hostname, @port)
|
|
39
|
+
server.close
|
|
40
|
+
|
|
41
|
+
rescue Errno::EADDRINUSE
|
|
42
|
+
$stdout.puts "Another program is running on port #{@port}. Set a new port in #{@config.config_path} for dev_server"
|
|
43
|
+
exit!
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def execute_cmd
|
|
47
|
+
env = Webpacker::Compiler.env
|
|
48
|
+
env["WEBPACKER_CONFIG"] = @webpacker_config
|
|
49
|
+
|
|
50
|
+
cmd = if node_modules_bin_exist?
|
|
51
|
+
["#{@node_modules_bin_path}/webpack-dev-server"]
|
|
52
|
+
else
|
|
53
|
+
["yarn", "webpack-dev-server"]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
if @argv.include?("--debug-webpacker")
|
|
57
|
+
cmd = [ "node", "--inspect-brk"] + cmd
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
cmd += ["--config", @webpack_config]
|
|
61
|
+
cmd += ["--progress", "--color"] if @pretty
|
|
62
|
+
|
|
63
|
+
Dir.chdir(@app_path) do
|
|
64
|
+
Kernel.exec env, *cmd
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def node_modules_bin_exist?
|
|
69
|
+
File.exist?("#{@node_modules_bin_path}/webpack-dev-server")
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
class Webpacker::Env
|
|
2
|
+
DEFAULT = "production".freeze
|
|
3
|
+
|
|
4
|
+
delegate :config_path, :logger, to: :@webpacker
|
|
5
|
+
|
|
6
|
+
def self.inquire(webpacker)
|
|
7
|
+
new(webpacker).inquire
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def initialize(webpacker)
|
|
11
|
+
@webpacker = webpacker
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def inquire
|
|
15
|
+
fallback_env_warning if config_path.exist? && !current
|
|
16
|
+
current || DEFAULT.inquiry
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
def current
|
|
21
|
+
Rails.env.presence_in(available_environments)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def fallback_env_warning
|
|
25
|
+
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/webpacker.yml, falling back to #{DEFAULT} environment"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def available_environments
|
|
29
|
+
if config_path.exist?
|
|
30
|
+
begin
|
|
31
|
+
YAML.load_file(config_path.to_s, aliases: true)
|
|
32
|
+
rescue ArgumentError
|
|
33
|
+
YAML.load_file(config_path.to_s)
|
|
34
|
+
end
|
|
35
|
+
else
|
|
36
|
+
[].freeze
|
|
37
|
+
end
|
|
38
|
+
rescue Psych::SyntaxError => e
|
|
39
|
+
raise "YAML syntax error occurred while parsing #{config_path}. " \
|
|
40
|
+
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
|
41
|
+
"Error: #{e.message}"
|
|
42
|
+
end
|
|
43
|
+
end
|