shakapacker 6.5.4 → 7.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +11 -7
- data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
- data/.github/workflows/dummy.yml +21 -0
- data/.github/workflows/generator.yml +37 -0
- data/.github/workflows/jest.yml +2 -2
- data/.github/workflows/js-lint.yml +2 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby-backward-compatibility.yml +39 -0
- data/.github/workflows/ruby.yml +5 -7
- data/.gitignore +6 -3
- data/.rspec +1 -0
- data/CHANGELOG.md +83 -2
- data/CONTRIBUTING.md +84 -18
- data/Gemfile.development_dependencies +3 -1
- data/README.md +159 -97
- data/Rakefile +46 -6
- data/config/shakapacker.yml +1 -0
- data/docs/deployment.md +11 -10
- data/docs/{developing_webpacker.md → developing_shakapacker.md} +5 -5
- data/docs/react.md +10 -6
- data/docs/style_loader_vs_mini_css.md +3 -3
- data/docs/troubleshooting.md +22 -18
- data/docs/using_esbuild_loader.md +5 -3
- data/docs/using_swc_loader.md +2 -2
- data/docs/v6_upgrade.md +9 -13
- data/docs/v7_upgrade.md +59 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.0.x +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +1 -1
- data/gemfiles/Gemfile-rails.7.0.x +1 -1
- data/lib/install/bin/shakapacker +13 -0
- data/lib/install/bin/shakapacker-dev-server +13 -0
- data/lib/install/binstubs.rb +3 -1
- data/lib/install/config/{webpacker.yml → shakapacker.yml} +28 -11
- data/lib/install/config/webpack/webpack.config.js +3 -2
- data/lib/install/template.rb +51 -34
- data/lib/{webpacker → shakapacker}/base_strategy.rb +2 -2
- data/lib/{webpacker → shakapacker}/commands.rb +4 -4
- data/lib/{webpacker → shakapacker}/compiler.rb +43 -15
- data/lib/{webpacker → shakapacker}/compiler_strategy.rb +6 -6
- data/lib/{webpacker → shakapacker}/configuration.rb +52 -21
- data/lib/shakapacker/deprecation_helper.rb +87 -0
- data/lib/{webpacker → shakapacker}/dev_server.rb +27 -4
- data/lib/{webpacker → shakapacker}/dev_server_proxy.rb +4 -4
- data/lib/shakapacker/dev_server_runner.rb +104 -0
- data/lib/{webpacker → shakapacker}/digest_strategy.rb +6 -6
- data/lib/{webpacker → shakapacker}/env.rb +8 -8
- data/lib/{webpacker → shakapacker}/helper.rb +40 -29
- data/lib/shakapacker/instance.rb +50 -0
- data/lib/{webpacker → shakapacker}/manifest.rb +14 -14
- data/lib/{webpacker → shakapacker}/mtime_strategy.rb +5 -5
- data/lib/shakapacker/railtie.rb +70 -0
- data/lib/shakapacker/runner.rb +28 -0
- data/lib/shakapacker/utils/version_syntax_converter.rb +2 -2
- data/lib/{webpacker → shakapacker}/version.rb +2 -2
- data/lib/{webpacker → shakapacker}/version_checker.rb +8 -8
- data/lib/shakapacker/webpack_runner.rb +67 -0
- data/lib/shakapacker.rb +51 -1
- data/lib/tasks/shakapacker/binstubs.rake +15 -0
- data/lib/tasks/shakapacker/check_binstubs.rake +29 -0
- data/lib/tasks/shakapacker/check_node.rake +31 -0
- data/lib/tasks/shakapacker/check_yarn.rake +33 -0
- data/lib/tasks/shakapacker/clean.rake +23 -0
- data/lib/tasks/shakapacker/clobber.rake +18 -0
- data/lib/tasks/shakapacker/compile.rake +28 -0
- data/lib/tasks/shakapacker/info.rake +21 -0
- data/lib/tasks/shakapacker/install.rake +17 -0
- data/lib/tasks/shakapacker/verify_config.rake +12 -0
- data/lib/tasks/shakapacker/verify_install.rake +4 -0
- data/lib/tasks/shakapacker/yarn_install.rake +24 -0
- data/lib/tasks/shakapacker.rake +18 -0
- data/lib/tasks/webpacker/binstubs.rake +5 -11
- data/lib/tasks/webpacker/check_binstubs.rake +6 -9
- data/lib/tasks/webpacker/check_node.rake +5 -27
- data/lib/tasks/webpacker/check_yarn.rake +5 -29
- data/lib/tasks/webpacker/clean.rake +5 -19
- data/lib/tasks/webpacker/clobber.rake +6 -13
- data/lib/tasks/webpacker/compile.rake +5 -38
- data/lib/tasks/webpacker/info.rake +5 -17
- data/lib/tasks/webpacker/install.rake +5 -13
- data/lib/tasks/webpacker/verify_config.rake +6 -11
- data/lib/tasks/webpacker/verify_install.rake +7 -2
- data/lib/tasks/webpacker/yarn_install.rake +5 -20
- data/lib/tasks/webpacker.rake +15 -13
- data/lib/webpacker/dev_server_runner.rb +9 -96
- data/lib/webpacker/webpack_runner.rb +9 -58
- data/lib/webpacker.rb +3 -47
- data/package/__tests__/config-bc.js +27 -0
- data/package/__tests__/config.js +6 -5
- data/package/__tests__/dev_server-bc.js +46 -0
- data/package/__tests__/dev_server.js +9 -8
- data/package/__tests__/development-bc.js +66 -0
- data/package/__tests__/development.js +36 -5
- data/package/__tests__/env-bc.js +59 -0
- data/package/__tests__/env.js +3 -2
- data/package/__tests__/index-bc.js +22 -0
- data/package/__tests__/index.js +13 -0
- data/package/__tests__/production-bc.js +51 -0
- data/package/__tests__/production.js +25 -3
- data/package/__tests__/staging-bc.js +53 -0
- data/package/__tests__/staging.js +27 -4
- data/package/__tests__/test-bc.js +43 -0
- data/package/__tests__/test.js +22 -4
- data/package/babel/preset.js +1 -4
- data/package/config.js +25 -7
- data/package/dev_server.js +7 -4
- data/package/env.js +22 -3
- data/package/environments/__tests__/base-bc.js +107 -0
- data/package/environments/__tests__/base.js +15 -15
- data/package/environments/__tests__/development.js +53 -0
- data/package/environments/__tests__/production.js +92 -0
- data/package/environments/base.js +5 -4
- data/package/environments/development.js +4 -46
- data/package/environments/production.js +10 -1
- data/package/index.js +35 -5
- data/package/rules/__tests__/__utils__/webpack.js +50 -0
- data/package/rules/__tests__/babel.js +63 -0
- data/package/rules/__tests__/esbuild.js +64 -0
- data/package/rules/__tests__/file.js +27 -0
- data/package/rules/__tests__/index.js +0 -4
- data/package/rules/__tests__/swc.js +63 -0
- data/package/rules/babel.js +13 -24
- data/package/rules/esbuild.js +2 -13
- data/package/rules/file.js +2 -2
- data/package/rules/jscommon.js +26 -0
- data/package/rules/swc.js +2 -13
- data/package/utils/configPath.js +19 -0
- data/package/utils/defaultConfigPath.js +2 -0
- data/package/utils/get_style_rule.js +5 -2
- data/package/utils/helpers.js +25 -2
- data/package/utils/inliningCss.js +7 -0
- data/package/utils/snakeToCamelCase +7 -0
- data/package/webpackDevServerConfig.js +68 -0
- data/package.json +11 -5
- data/{webpacker.gemspec → shakapacker.gemspec} +3 -3
- data/spec/backward_compatibility_specs/command_spec.rb +116 -0
- data/spec/backward_compatibility_specs/compiler_spec.rb +59 -0
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +22 -0
- data/spec/backward_compatibility_specs/configuration_spec.rb +286 -0
- data/{test/dev_server_runner_test.rb → spec/backward_compatibility_specs/dev_server_runner_spec.rb} +37 -39
- data/spec/backward_compatibility_specs/dev_server_spec.rb +47 -0
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +35 -0
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +44 -0
- data/spec/backward_compatibility_specs/env_spec.rb +23 -0
- data/spec/backward_compatibility_specs/helper_spec.rb +243 -0
- data/spec/backward_compatibility_specs/instance_spec.rb +31 -0
- data/spec/backward_compatibility_specs/manifest_spec.rb +100 -0
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +55 -0
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +37 -0
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +24 -0
- data/{test/webpack_runner_test.rb → spec/backward_compatibility_specs/webpack_runner_spec.rb} +15 -16
- data/spec/backward_compatibility_specs/webpacker_spec.rb +41 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +2 -0
- data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/application.js +1 -1
- data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +11 -0
- data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker.yml +1 -1
- data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_css_extract_ignore_order_warnings.yml +1 -1
- data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_defaults_fallback.yml +1 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +7 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +85 -0
- data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_public_root.yml +1 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +13 -0
- data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/public/packs/manifest.json +8 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +1 -0
- data/spec/dummy/.browserslistrc +1 -0
- data/spec/dummy/.gitignore +20 -0
- data/spec/dummy/.prettierrc.yaml +4 -0
- data/spec/dummy/Gemfile +63 -0
- data/spec/dummy/Procfile.dev +5 -0
- data/spec/dummy/Procfile.dev-static +9 -0
- data/spec/dummy/README.md +1 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/hello_world_controller.rb +9 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/javascript/Globals.d.ts +3 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +25 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +47 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +5 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +7 -0
- data/spec/dummy/app/javascript/packs/application.js +17 -0
- data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +8 -0
- data/spec/dummy/app/javascript/packs/server-bundle.ts +8 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/hello_world/index.html.erb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/hello_world.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/babel.config.js +30 -0
- data/spec/dummy/bin/bundle +114 -0
- data/spec/dummy/bin/dev +30 -0
- data/spec/dummy/bin/dev-static +30 -0
- data/spec/dummy/bin/rails +9 -0
- data/spec/dummy/bin/rake +9 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/bin/shakapacker +13 -0
- data/spec/dummy/bin/shakapacker-dev-server +13 -0
- data/spec/dummy/bin/spring +17 -0
- data/spec/dummy/bin/yarn +18 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/credentials.yml.enc +1 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +106 -0
- data/spec/dummy/config/environments/test.rb +49 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +58 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +38 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config/shakapacker.yml +62 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config/webpack/ServerClientOrBoth.js +34 -0
- data/spec/dummy/config/webpack/clientWebpackConfig.js +15 -0
- data/spec/dummy/config/webpack/commonWebpackConfig.js +18 -0
- data/spec/dummy/config/webpack/development.js +32 -0
- data/spec/dummy/config/webpack/production.js +9 -0
- data/spec/dummy/config/webpack/serverWebpackConfig.js +116 -0
- data/spec/dummy/config/webpack/test.js +7 -0
- data/spec/dummy/config/webpack/webpack.config.js +24 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/package.json +44 -0
- data/spec/dummy/postcss.config.js +12 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +1 -0
- data/spec/dummy/spec/rails_helper.rb +118 -0
- data/spec/dummy/spec/spec_helper.rb +96 -0
- data/spec/dummy/spec/system/hello_world_spec.rb +19 -0
- data/spec/dummy/tsconfig.json +21 -0
- data/spec/dummy/vendor/.keep +0 -0
- data/spec/dummy/yarn.lock +4697 -0
- data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +4 -0
- data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +12 -0
- data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +10 -0
- data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +2 -0
- data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +17 -0
- data/spec/generator_specs/e2e_template/files/config/routes.rb +3 -0
- data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +13 -0
- data/spec/generator_specs/e2e_template/template.rb +21 -0
- data/spec/generator_specs/generator_spec.rb +169 -0
- data/{test → spec}/mounted_app/test/dummy/config/application.rb +1 -1
- data/{test → spec}/mounted_app/test/dummy/config/webpacker.yml +11 -5
- data/spec/shakapacker/command_spec.rb +116 -0
- data/spec/shakapacker/compiler_spec.rb +59 -0
- data/spec/shakapacker/compiler_strategy_spec.rb +22 -0
- data/spec/shakapacker/configuration_spec.rb +323 -0
- data/spec/shakapacker/dev_server_runner_spec.rb +72 -0
- data/spec/shakapacker/dev_server_spec.rb +133 -0
- data/spec/shakapacker/digest_strategy_spec.rb +35 -0
- data/spec/shakapacker/engine_rake_tasks_spec.rb +43 -0
- data/spec/shakapacker/env_spec.rb +23 -0
- data/spec/shakapacker/helper_spec.rb +243 -0
- data/spec/shakapacker/instance_spec.rb +31 -0
- data/spec/shakapacker/manifest_spec.rb +100 -0
- data/spec/shakapacker/mtime_strategy_spec.rb +55 -0
- data/spec/shakapacker/rake_tasks_spec.rb +93 -0
- data/spec/shakapacker/shakapacker_spec.rb +41 -0
- data/spec/shakapacker/spec_helper_initializer.rb +24 -0
- data/spec/shakapacker/test_app/.gitignore +2 -0
- data/spec/shakapacker/test_app/Rakefile +3 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/application.js +10 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/generated/something.js +2 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
- data/{test/test_app/bin/webpacker-dev-server → spec/shakapacker/test_app/bin/shakapacker} +3 -3
- data/{test/test_app/bin/webpacker → spec/shakapacker/test_app/bin/shakapacker-dev-server} +3 -3
- data/{test → spec/shakapacker}/test_app/config/application.rb +1 -1
- data/spec/shakapacker/test_app/config/environment.rb +4 -0
- data/spec/shakapacker/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/spec/shakapacker/test_app/config/shakapacker.yml +82 -0
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +84 -0
- data/spec/shakapacker/test_app/config/shakapacker_defaults_fallback.yml +11 -0
- data/{test/test_app/config/webpacker_other_location.yml → spec/shakapacker/test_app/config/shakapacker_manifest_path.yml} +6 -5
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +83 -0
- data/spec/shakapacker/test_app/config/shakapacker_no_precompile.yml +7 -0
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +85 -0
- data/spec/shakapacker/test_app/config/shakapacker_public_root.yml +18 -0
- data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
- data/spec/shakapacker/test_app/config.ru +5 -0
- data/spec/shakapacker/test_app/public/packs/manifest.json +58 -0
- data/spec/shakapacker/test_app/some.config.js +0 -0
- data/spec/shakapacker/test_app/yarn.lock +11 -0
- data/spec/shakapacker/version_checker_spec.rb +951 -0
- data/spec/shakapacker/webpack_runner_spec.rb +55 -0
- data/spec/spec_helper.rb +98 -0
- data/yarn.lock +846 -844
- metadata +314 -213
- data/.github/ISSUE_TEMPLATE/feature-request.md +0 -18
- data/config/webpacker.yml +0 -1
- data/gemfiles/Gemfile-rails.5.2.x +0 -9
- data/lib/tasks/yarn.rake +0 -44
- data/lib/webpacker/instance.rb +0 -45
- data/lib/webpacker/railtie.rb +0 -70
- data/lib/webpacker/runner.rb +0 -23
- data/package/configPath.js +0 -3
- data/package/inliningCss.js +0 -7
- data/test/command_test.rb +0 -109
- data/test/compiler_strategy_test.rb +0 -27
- data/test/compiler_test.rb +0 -60
- data/test/configuration_test.rb +0 -186
- data/test/dev_server_test.rb +0 -47
- data/test/digest_strategy_test.rb +0 -33
- data/test/engine_rake_tasks_test.rb +0 -39
- data/test/env_test.rb +0 -23
- data/test/helper_test.rb +0 -248
- data/test/manifest_test.rb +0 -89
- data/test/mtime_strategy_test.rb +0 -42
- data/test/rake_tasks_test.rb +0 -37
- data/test/test_app/config/webpacker_no_precompile.yml +0 -7
- data/test/test_helper.rb +0 -33
- data/test/version_checker_test.rb +0 -826
- data/test/webpacker_test.rb +0 -49
- /data/{test/mounted_app/test/dummy → spec/backward_compatibility_specs/webpacker_test_app}/Rakefile +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/generated/something.js +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.css +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.js +0 -0
- /data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker-dev-server +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/environment.rb +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpack/webpack.config.js +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_manifest_path.yml +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_nested_entries.yml +0 -0
- /data/{test/mounted_app/test/dummy → spec/backward_compatibility_specs/webpacker_test_app}/config.ru +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/some.config.js +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/yarn.lock +0 -0
- /data/{test → spec}/fixtures/beta_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/beta_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/beta_package.json +0 -0
- /data/{test → spec}/fixtures/beta_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/beta_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/git_url_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/git_url_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/git_url_package.json +0 -0
- /data/{test → spec}/fixtures/git_url_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/git_url_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/github_url_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/github_url_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/github_url_package.json +0 -0
- /data/{test → spec}/fixtures/github_url_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/github_url_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/relative_path_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/relative_path_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/relative_path_package.json +0 -0
- /data/{test → spec}/fixtures/relative_path_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/relative_path_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/semver_caret_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/semver_caret_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/semver_caret_package.json +0 -0
- /data/{test → spec}/fixtures/semver_caret_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/semver_caret_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/semver_exact_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/semver_exact_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/semver_exact_package.json +0 -0
- /data/{test → spec}/fixtures/semver_exact_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/semver_exact_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/semver_tilde_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/semver_tilde_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/semver_tilde_package.json +0 -0
- /data/{test → spec}/fixtures/semver_tilde_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/semver_tilde_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/without_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/without_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/without_package.json +0 -0
- /data/{test → spec}/fixtures/without_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/without_yarn.v2.lock +0 -0
- /data/{test → spec}/mounted_app/Rakefile +0 -0
- /data/{test/test_app → spec/mounted_app/test/dummy}/Rakefile +0 -0
- /data/{test → spec}/mounted_app/test/dummy/bin/rails +0 -0
- /data/{test → spec}/mounted_app/test/dummy/bin/rake +0 -0
- /data/{test → spec}/mounted_app/test/dummy/config/environment.rb +0 -0
- /data/{test/test_app → spec/mounted_app/test/dummy}/config.ru +0 -0
- /data/{test → spec}/mounted_app/test/dummy/package.json +0 -0
- /data/{test → spec/shakapacker}/test_app/package.json +0 -0
@@ -1,10 +1,10 @@
|
|
1
1
|
require "rack/proxy"
|
2
2
|
|
3
|
-
class
|
4
|
-
delegate :config, :dev_server, to: :@
|
3
|
+
class Shakapacker::DevServerProxy < Rack::Proxy
|
4
|
+
delegate :config, :dev_server, to: :@instance
|
5
5
|
|
6
6
|
def initialize(app = nil, opts = {})
|
7
|
-
@
|
7
|
+
@instance = opts.delete(:shakapacker) || Shakapacker.instance
|
8
8
|
opts[:streaming] = false if Rails.env.test? && !opts.key?(:streaming)
|
9
9
|
super
|
10
10
|
end
|
@@ -15,7 +15,7 @@ class Webpacker::DevServerProxy < Rack::Proxy
|
|
15
15
|
env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
|
16
16
|
env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
|
17
17
|
env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
|
18
|
-
unless dev_server.https
|
18
|
+
unless dev_server.protocol == "https"
|
19
19
|
env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
|
20
20
|
end
|
21
21
|
env["SCRIPT_NAME"] = ""
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "shellwords"
|
2
|
+
require "socket"
|
3
|
+
require "shakapacker/configuration"
|
4
|
+
require "shakapacker/dev_server"
|
5
|
+
require "shakapacker/runner"
|
6
|
+
|
7
|
+
module Shakapacker
|
8
|
+
class DevServerRunner < Shakapacker::Runner
|
9
|
+
def run
|
10
|
+
load_config
|
11
|
+
detect_unsupported_switches!
|
12
|
+
detect_port!
|
13
|
+
execute_cmd
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def load_config
|
19
|
+
app_root = Pathname.new(@app_path)
|
20
|
+
|
21
|
+
@config = Configuration.new(
|
22
|
+
root_path: app_root,
|
23
|
+
config_path: Pathname.new(@shakapacker_config),
|
24
|
+
env: ENV["RAILS_ENV"]
|
25
|
+
)
|
26
|
+
|
27
|
+
dev_server = DevServer.new(@config)
|
28
|
+
|
29
|
+
@hostname = dev_server.host
|
30
|
+
@port = dev_server.port
|
31
|
+
@pretty = dev_server.pretty?
|
32
|
+
@https = dev_server.protocol == "https"
|
33
|
+
@hot = dev_server.hmr?
|
34
|
+
|
35
|
+
rescue Errno::ENOENT, NoMethodError
|
36
|
+
$stdout.puts "webpack 'dev_server' configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
37
|
+
$stdout.puts "Please run bundle exec rails shakapacker:install to install Shakapacker"
|
38
|
+
exit!
|
39
|
+
end
|
40
|
+
|
41
|
+
UNSUPPORTED_SWITCHES = %w[--host --port]
|
42
|
+
private_constant :UNSUPPORTED_SWITCHES
|
43
|
+
def detect_unsupported_switches!
|
44
|
+
unsupported_switches = UNSUPPORTED_SWITCHES & @argv
|
45
|
+
if unsupported_switches.any?
|
46
|
+
$stdout.puts "The following CLI switches are not supported by Shakapacker: #{unsupported_switches.join(' ')}. Please edit your command and try again."
|
47
|
+
exit!
|
48
|
+
end
|
49
|
+
|
50
|
+
if @argv.include?("--https") && !@https
|
51
|
+
$stdout.puts "Please set https: true in shakapacker.yml to use the --https command line flag."
|
52
|
+
exit!
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def detect_port!
|
57
|
+
server = TCPServer.new(@hostname, @port)
|
58
|
+
server.close
|
59
|
+
|
60
|
+
rescue Errno::EADDRINUSE
|
61
|
+
$stdout.puts "Another program is running on port #{@port}. Set a new port in #{@config.config_path} for dev_server"
|
62
|
+
exit!
|
63
|
+
end
|
64
|
+
|
65
|
+
def execute_cmd
|
66
|
+
env = Shakapacker::Compiler.env
|
67
|
+
env["SHAKAPACKER_CONFIG"] = @shakapacker_config
|
68
|
+
env["WEBPACK_SERVE"] = "true"
|
69
|
+
|
70
|
+
cmd = if node_modules_bin_exist?
|
71
|
+
["#{@node_modules_bin_path}/webpack", "serve"]
|
72
|
+
else
|
73
|
+
["yarn", "webpack", "serve"]
|
74
|
+
end
|
75
|
+
|
76
|
+
if @argv.include?("--debug-webpacker")
|
77
|
+
Shakapacker.puts_deprecation_message(
|
78
|
+
Shakapacker.short_deprecation_message(
|
79
|
+
"--debug-webpacker",
|
80
|
+
"--debug-shakapacker"
|
81
|
+
)
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
|
86
|
+
cmd = [ "node", "--inspect-brk", "--trace-warnings" ] + cmd
|
87
|
+
end
|
88
|
+
|
89
|
+
cmd += ["--config", @webpack_config]
|
90
|
+
cmd += ["--progress", "--color"] if @pretty
|
91
|
+
|
92
|
+
cmd += ["--hot"] if @hot
|
93
|
+
cmd += @argv
|
94
|
+
|
95
|
+
Dir.chdir(@app_path) do
|
96
|
+
Kernel.exec env, *cmd
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def node_modules_bin_exist?
|
101
|
+
File.exist?("#{@node_modules_bin_path}/webpack-dev-server")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "digest/sha1"
|
2
|
-
require "
|
2
|
+
require "shakapacker/base_strategy"
|
3
3
|
|
4
|
-
module
|
4
|
+
module Shakapacker
|
5
5
|
class DigestStrategy < BaseStrategy
|
6
6
|
# Returns true if all the compiled packs are up to date with the underlying asset files.
|
7
7
|
def fresh?
|
@@ -31,10 +31,10 @@ module Webpacker
|
|
31
31
|
def watched_files_digest
|
32
32
|
if Rails.env.development?
|
33
33
|
warn <<~MSG.strip
|
34
|
-
|
34
|
+
Shakapacker::Compiler - Slow setup for development
|
35
35
|
Prepare JS assets with either:
|
36
|
-
1. Running `bin/
|
37
|
-
2. Set `compile` to false in
|
36
|
+
1. Running `bin/shakapacker-dev-server`
|
37
|
+
2. Set `compile` to false in shakapacker.yml and run `bin/shakapacker -w`
|
38
38
|
MSG
|
39
39
|
end
|
40
40
|
|
@@ -53,7 +53,7 @@ module Webpacker
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def compilation_digest_path
|
56
|
-
config.cache_path.join("last-compilation-digest-#{
|
56
|
+
config.cache_path.join("last-compilation-digest-#{Shakapacker.env}")
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
class
|
2
|
-
delegate :config_path, :logger, to: :@
|
1
|
+
class Shakapacker::Env
|
2
|
+
delegate :config_path, :logger, to: :@instance
|
3
3
|
|
4
|
-
def self.inquire(
|
5
|
-
new(
|
4
|
+
def self.inquire(instance)
|
5
|
+
new(instance).inquire
|
6
6
|
end
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(instance)
|
9
|
+
@instance = instance
|
10
10
|
end
|
11
11
|
|
12
12
|
def inquire
|
13
13
|
fallback_env_warning if config_path.exist? && !current
|
14
|
-
current ||
|
14
|
+
current || Shakapacker::DEFAULT_ENV.inquiry
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
@@ -20,7 +20,7 @@ class Webpacker::Env
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def fallback_env_warning
|
23
|
-
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/
|
23
|
+
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/shakapacker.yml, falling back to #{Shakapacker::DEFAULT_ENV} environment"
|
24
24
|
end
|
25
25
|
|
26
26
|
def available_environments
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module
|
2
|
-
# Returns the current
|
3
|
-
# Could be overridden to use multiple
|
1
|
+
module Shakapacker::Helper
|
2
|
+
# Returns the current Shakapacker instance.
|
3
|
+
# Could be overridden to use multiple Shakapacker
|
4
4
|
# configurations within the same app (e.g. with engines).
|
5
|
-
def
|
6
|
-
|
5
|
+
def current_shakapacker_instance
|
6
|
+
Shakapacker.instance
|
7
7
|
end
|
8
8
|
|
9
|
-
# Computes the relative path for a given
|
9
|
+
# Computes the relative path for a given Shakapacker asset.
|
10
10
|
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
|
11
11
|
# This will use path_to_asset internally, so most of their behaviors will be the same.
|
12
12
|
#
|
@@ -14,10 +14,10 @@ module Webpacker::Helper
|
|
14
14
|
#
|
15
15
|
# <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
|
16
16
|
def asset_pack_path(name, **options)
|
17
|
-
path_to_asset(
|
17
|
+
path_to_asset(current_shakapacker_instance.manifest.lookup!(name), options)
|
18
18
|
end
|
19
19
|
|
20
|
-
# Computes the absolute path for a given
|
20
|
+
# Computes the absolute path for a given Shakapacker asset.
|
21
21
|
# Returns the absolute path using manifest.json and passes it to url_to_asset helper.
|
22
22
|
# This will use url_to_asset internally, so most of their behaviors will be the same.
|
23
23
|
#
|
@@ -25,17 +25,17 @@ module Webpacker::Helper
|
|
25
25
|
#
|
26
26
|
# <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
|
27
27
|
def asset_pack_url(name, **options)
|
28
|
-
url_to_asset(
|
28
|
+
url_to_asset(current_shakapacker_instance.manifest.lookup!(name), options)
|
29
29
|
end
|
30
30
|
|
31
|
-
# Computes the relative path for a given
|
31
|
+
# Computes the relative path for a given Shakapacker image with the same automated processing as image_pack_tag.
|
32
32
|
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
|
33
33
|
# This will use path_to_asset internally, so most of their behaviors will be the same.
|
34
34
|
def image_pack_path(name, **options)
|
35
35
|
resolve_path_to_image(name, **options)
|
36
36
|
end
|
37
37
|
|
38
|
-
# Computes the absolute path for a given
|
38
|
+
# Computes the absolute path for a given Shakapacker image with the same automated
|
39
39
|
# processing as image_pack_tag. Returns the relative path using manifest.json
|
40
40
|
# and passes it to path_to_asset helper. This will use path_to_asset internally,
|
41
41
|
# so most of their behaviors will be the same.
|
@@ -75,7 +75,7 @@ module Webpacker::Helper
|
|
75
75
|
# Creates script tags that reference the js chunks from entrypoints when using split chunks API,
|
76
76
|
# as compiled by webpack per the entries list in package/environments/base.js.
|
77
77
|
# By default, this list is auto-generated to match everything in
|
78
|
-
# app/
|
78
|
+
# app/javascript/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
79
79
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
80
80
|
#
|
81
81
|
# Example:
|
@@ -114,7 +114,7 @@ module Webpacker::Helper
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
# Creates a link tag, for preloading, that references a given
|
117
|
+
# Creates a link tag, for preloading, that references a given Shakapacker asset.
|
118
118
|
# In production mode, the digested reference is automatically looked up.
|
119
119
|
# See: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
|
120
120
|
#
|
@@ -124,7 +124,7 @@ module Webpacker::Helper
|
|
124
124
|
# <link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
125
125
|
def preload_pack_asset(name, **options)
|
126
126
|
if self.class.method_defined?(:preload_link_tag)
|
127
|
-
preload_link_tag(
|
127
|
+
preload_link_tag(current_shakapacker_instance.manifest.lookup!(name), options)
|
128
128
|
else
|
129
129
|
raise "You need Rails >= 5.2 to use this tag."
|
130
130
|
end
|
@@ -133,7 +133,7 @@ module Webpacker::Helper
|
|
133
133
|
# Creates link tags that reference the css chunks from entrypoints when using split chunks API,
|
134
134
|
# as compiled by webpack per the entries list in package/environments/base.js.
|
135
135
|
# By default, this list is auto-generated to match everything in
|
136
|
-
# app/
|
136
|
+
# app/javascript/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
137
137
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
138
138
|
#
|
139
139
|
# Examples:
|
@@ -156,7 +156,7 @@ module Webpacker::Helper
|
|
156
156
|
# <%= stylesheet_pack_tag 'calendar' %>
|
157
157
|
# <%= stylesheet_pack_tag 'map' %>
|
158
158
|
def stylesheet_pack_tag(*names, **options)
|
159
|
-
return "" if
|
159
|
+
return "" if Shakapacker.inlining_css?
|
160
160
|
|
161
161
|
requested_packs = sources_from_manifest_entrypoints(names, type: :stylesheet)
|
162
162
|
appended_packs = available_sources_from_manifest_entrypoints(@stylesheet_pack_tag_queue || [], type: :stylesheet)
|
@@ -169,7 +169,7 @@ module Webpacker::Helper
|
|
169
169
|
def append_stylesheet_pack_tag(*names)
|
170
170
|
if @stylesheet_pack_tag_loaded
|
171
171
|
raise "You can only call append_stylesheet_pack_tag before stylesheet_pack_tag helper. " \
|
172
|
-
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
|
172
|
+
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
|
173
173
|
end
|
174
174
|
|
175
175
|
@stylesheet_pack_tag_queue ||= []
|
@@ -180,20 +180,31 @@ module Webpacker::Helper
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def append_javascript_pack_tag(*names, defer: true)
|
183
|
-
|
184
|
-
|
185
|
-
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
|
183
|
+
update_javascript_pack_tag_queue(defer: defer) do |hash_key|
|
184
|
+
javascript_pack_tag_queue[hash_key] |= names
|
186
185
|
end
|
186
|
+
end
|
187
187
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
nil
|
188
|
+
def prepend_javascript_pack_tag(*names, defer: true)
|
189
|
+
update_javascript_pack_tag_queue(defer: defer) do |hash_key|
|
190
|
+
javascript_pack_tag_queue[hash_key].unshift(*names)
|
191
|
+
end
|
193
192
|
end
|
194
193
|
|
195
194
|
private
|
196
195
|
|
196
|
+
def update_javascript_pack_tag_queue(defer:)
|
197
|
+
if @javascript_pack_tag_loaded
|
198
|
+
raise "You can only call #{caller_locations(1..1).first.label} before javascript_pack_tag helper. " \
|
199
|
+
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
|
200
|
+
end
|
201
|
+
|
202
|
+
yield(defer ? :deferred : :non_deferred)
|
203
|
+
|
204
|
+
# prevent rendering Array#to_s representation when used with <%= … %> syntax
|
205
|
+
nil
|
206
|
+
end
|
207
|
+
|
197
208
|
def javascript_pack_tag_queue
|
198
209
|
@javascript_pack_tag_queue ||= {
|
199
210
|
deferred: [],
|
@@ -202,17 +213,17 @@ module Webpacker::Helper
|
|
202
213
|
end
|
203
214
|
|
204
215
|
def sources_from_manifest_entrypoints(names, type:)
|
205
|
-
names.map { |name|
|
216
|
+
names.map { |name| current_shakapacker_instance.manifest.lookup_pack_with_chunks!(name.to_s, type: type) }.flatten.uniq
|
206
217
|
end
|
207
218
|
|
208
219
|
def available_sources_from_manifest_entrypoints(names, type:)
|
209
|
-
names.map { |name|
|
220
|
+
names.map { |name| current_shakapacker_instance.manifest.lookup_pack_with_chunks(name.to_s, type: type) }.flatten.compact.uniq
|
210
221
|
end
|
211
222
|
|
212
223
|
def resolve_path_to_image(name, **options)
|
213
224
|
path = name.starts_with?("static/") ? name : "static/#{name}"
|
214
|
-
path_to_asset(
|
225
|
+
path_to_asset(current_shakapacker_instance.manifest.lookup!(path), options)
|
215
226
|
rescue
|
216
|
-
path_to_asset(
|
227
|
+
path_to_asset(current_shakapacker_instance.manifest.lookup!(name), options)
|
217
228
|
end
|
218
229
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
class Shakapacker::Instance
|
4
|
+
cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
5
|
+
|
6
|
+
attr_reader :root_path, :config_path
|
7
|
+
|
8
|
+
def initialize(root_path: Rails.root, config_path: Rails.root.join("config/shakapacker.yml"))
|
9
|
+
@root_path = root_path
|
10
|
+
|
11
|
+
# For backward compatibility
|
12
|
+
@config_path = Shakapacker.get_config_file_path_with_backward_compatibility(config_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def env
|
16
|
+
@env ||= Shakapacker::Env.inquire self
|
17
|
+
end
|
18
|
+
|
19
|
+
def config
|
20
|
+
@config ||= Shakapacker::Configuration.new(
|
21
|
+
root_path: root_path,
|
22
|
+
config_path: config_path,
|
23
|
+
env: env
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def strategy
|
28
|
+
@strategy ||= Shakapacker::CompilerStrategy.from_config
|
29
|
+
end
|
30
|
+
|
31
|
+
def compiler
|
32
|
+
@compiler ||= Shakapacker::Compiler.new self
|
33
|
+
end
|
34
|
+
|
35
|
+
def dev_server
|
36
|
+
@dev_server ||= Shakapacker::DevServer.new config
|
37
|
+
end
|
38
|
+
|
39
|
+
def manifest
|
40
|
+
@manifest ||= Shakapacker::Manifest.new self
|
41
|
+
end
|
42
|
+
|
43
|
+
def commands
|
44
|
+
@commands ||= Shakapacker::Commands.new self
|
45
|
+
end
|
46
|
+
|
47
|
+
def inlining_css?
|
48
|
+
dev_server.inline_css? && dev_server.hmr? && dev_server.running?
|
49
|
+
end
|
50
|
+
end
|
@@ -4,14 +4,14 @@
|
|
4
4
|
# "/packs/calendar-1016838bab065ae1e314.css".
|
5
5
|
#
|
6
6
|
# When the configuration is set to on-demand compilation, with the `compile: true` option in
|
7
|
-
# the
|
8
|
-
class
|
7
|
+
# the shakapacker.yml file, any lookups will be preceded by a compilation if one is needed.
|
8
|
+
class Shakapacker::Manifest
|
9
9
|
class MissingEntryError < StandardError; end
|
10
10
|
|
11
|
-
delegate :config, :compiler, :dev_server, to: :@
|
11
|
+
delegate :config, :compiler, :dev_server, to: :@instance
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(instance)
|
14
|
+
@instance = instance
|
15
15
|
end
|
16
16
|
|
17
17
|
def refresh
|
@@ -32,19 +32,19 @@ class Webpacker::Manifest
|
|
32
32
|
lookup_pack_with_chunks(name, pack_type) || handle_missing_entry(name, pack_type)
|
33
33
|
end
|
34
34
|
|
35
|
-
# Computes the relative path for a given
|
35
|
+
# Computes the relative path for a given Shakapacker asset using manifest.json.
|
36
36
|
# If no asset is found, returns nil.
|
37
37
|
#
|
38
38
|
# Example:
|
39
39
|
#
|
40
|
-
#
|
40
|
+
# Shakapacker.manifest.lookup('calendar.js') # => "/packs/calendar-1016838bab065ae1e122.js"
|
41
41
|
def lookup(name, pack_type = {})
|
42
42
|
compile if compiling?
|
43
43
|
|
44
44
|
find(full_pack_name(name, pack_type[:type]))
|
45
45
|
end
|
46
46
|
|
47
|
-
# Like lookup, except that if no asset is found, raises a
|
47
|
+
# Like lookup, except that if no asset is found, raises a Shakapacker::Manifest::MissingEntryError.
|
48
48
|
def lookup!(name, pack_type = {})
|
49
49
|
lookup(name, pack_type) || handle_missing_entry(name, pack_type)
|
50
50
|
end
|
@@ -55,7 +55,7 @@ class Webpacker::Manifest
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def compile
|
58
|
-
|
58
|
+
Shakapacker.logger.tagged("Shakapacker") { compiler.compile }
|
59
59
|
end
|
60
60
|
|
61
61
|
def data
|
@@ -76,7 +76,7 @@ class Webpacker::Manifest
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def handle_missing_entry(name, pack_type)
|
79
|
-
raise
|
79
|
+
raise Shakapacker::Manifest::MissingEntryError, missing_file_from_manifest_error(full_pack_name(name, pack_type[:type]))
|
80
80
|
end
|
81
81
|
|
82
82
|
def load
|
@@ -106,11 +106,11 @@ class Webpacker::Manifest
|
|
106
106
|
<<-MSG
|
107
107
|
Shakapacker can't find #{bundle_name} in #{config.manifest_path}. Possible causes:
|
108
108
|
1. You forgot to install node packages (try `yarn install`) or are running an incompatible version of Node
|
109
|
-
2. Your app has code with a non-standard extension (like a `.jsx` file) but the extension is not in the `extensions` config in `config/
|
110
|
-
3. You have set compile: false (see `config/
|
111
|
-
(unless you are using the `bin/
|
109
|
+
2. Your app has code with a non-standard extension (like a `.jsx` file) but the extension is not in the `extensions` config in `config/shakapacker.yml`
|
110
|
+
3. You have set compile: false (see `config/shakapacker.yml`) for this environment
|
111
|
+
(unless you are using the `bin/shakapacker -w` or the `bin/shakapacker-dev-server`, in which case maybe you aren't running the dev server in the background?)
|
112
112
|
4. webpack has not yet FINISHED running to reflect updates.
|
113
|
-
5. You have misconfigured
|
113
|
+
5. You have misconfigured Shakapacker's `config/shakapacker.yml` file.
|
114
114
|
6. Your webpack configuration is not creating a manifest.
|
115
115
|
|
116
116
|
Your manifest contains:
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require "
|
1
|
+
require "shakapacker/base_strategy"
|
2
2
|
|
3
|
-
module
|
3
|
+
module Shakapacker
|
4
4
|
class MtimeStrategy < BaseStrategy
|
5
5
|
# Returns true if manifest file mtime is newer than the timestamp of the last modified watched file
|
6
6
|
def fresh?
|
@@ -21,11 +21,11 @@ module Webpacker
|
|
21
21
|
def latest_modified_timestamp
|
22
22
|
if Rails.env.development?
|
23
23
|
warn <<~MSG.strip
|
24
|
-
|
24
|
+
Shakapacker::Compiler - Slow setup for development
|
25
25
|
|
26
26
|
Prepare JS assets with either:
|
27
|
-
1. Running `bin/
|
28
|
-
2. Set `compile` to false in
|
27
|
+
1. Running `bin/shakapacker-dev-server`
|
28
|
+
2. Set `compile` to false in shakapacker.yml and run `bin/shakapacker -w`
|
29
29
|
MSG
|
30
30
|
end
|
31
31
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "rails/railtie"
|
2
|
+
|
3
|
+
require "shakapacker/helper"
|
4
|
+
require "shakapacker/dev_server_proxy"
|
5
|
+
require "shakapacker/version_checker"
|
6
|
+
|
7
|
+
class Shakapacker::Engine < ::Rails::Engine
|
8
|
+
# Allows Shakapacker config values to be set via Rails env config files
|
9
|
+
config.shakapacker = ActiveSupport::OrderedOptions.new
|
10
|
+
|
11
|
+
initializer "shakapacker.version_checker" do
|
12
|
+
if File.exist?(Shakapacker::VersionChecker::NodePackageVersion.package_json_path)
|
13
|
+
Shakapacker::VersionChecker.build.raise_if_gem_and_node_package_versions_differ
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
initializer "shakapacker.proxy" do |app|
|
18
|
+
if (Shakapacker.config.dev_server.present? rescue nil)
|
19
|
+
app.middleware.insert_before 0,
|
20
|
+
Rails::VERSION::MAJOR >= 5 ?
|
21
|
+
Shakapacker::DevServerProxy : "Shakapacker::DevServerProxy", ssl_verify_none: true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
initializer "shakapacker.helper" do
|
26
|
+
ActiveSupport.on_load :action_controller do
|
27
|
+
ActionController::Base.helper Shakapacker::Helper
|
28
|
+
end
|
29
|
+
|
30
|
+
ActiveSupport.on_load :action_view do
|
31
|
+
include Shakapacker::Helper
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
initializer "shakapacker.logger" do
|
36
|
+
config.after_initialize do
|
37
|
+
if ::Rails.logger.respond_to?(:tagged)
|
38
|
+
Shakapacker.logger = ::Rails.logger
|
39
|
+
else
|
40
|
+
Shakapacker.logger = ActiveSupport::TaggedLogging.new(::Rails.logger)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
initializer "shakapacker.bootstrap" do
|
46
|
+
if defined?(Rails::Server) || defined?(Rails::Console)
|
47
|
+
Shakapacker.bootstrap
|
48
|
+
if defined?(Spring)
|
49
|
+
require "spring/watcher"
|
50
|
+
Spring.after_fork { Shakapacker.bootstrap }
|
51
|
+
Spring.watch(Shakapacker.config.config_path)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
initializer "shakapacker.set_source" do |app|
|
57
|
+
if Shakapacker.config.config_path.exist?
|
58
|
+
app.config.javascript_path = Shakapacker.config.source_path.relative_path_from(Rails.root.join("app")).to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
initializer "shakapacker.remove_app_packs_from_the_autoload_paths" do
|
63
|
+
Rails.application.config.before_initialize do
|
64
|
+
if Shakapacker.config.config_path.exist?
|
65
|
+
source_path = Shakapacker.config.source_path.to_s
|
66
|
+
ActiveSupport::Dependencies.autoload_paths.delete(source_path)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Shakapacker
|
2
|
+
class Runner
|
3
|
+
def self.run(argv)
|
4
|
+
$stdout.sync = true
|
5
|
+
ENV["NODE_ENV"] ||= (ENV["RAILS_ENV"] == "production") ? "production" : "development"
|
6
|
+
new(argv).run
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(argv)
|
10
|
+
@argv = argv
|
11
|
+
|
12
|
+
@app_path = File.expand_path(".", Dir.pwd)
|
13
|
+
@webpack_config = File.join(@app_path, "config/webpack/webpack.config.js")
|
14
|
+
|
15
|
+
Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
|
16
|
+
|
17
|
+
@node_modules_bin_path = ENV["SHAKAPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
|
18
|
+
@shakapacker_config = ENV["SHAKAPACKER_CONFIG"] || File.join(@app_path, "config/shakapacker.yml")
|
19
|
+
|
20
|
+
@shakapacker_config = Shakapacker.get_config_file_path_with_backward_compatibility(@shakapacker_config)
|
21
|
+
|
22
|
+
unless File.exist?(@webpack_config)
|
23
|
+
$stderr.puts "webpack config #{@webpack_config} not found, please run 'bundle exec rails shakapacker:install' to install Shakapacker with default configs or add the missing config file for your custom environment."
|
24
|
+
exit!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../shakapacker/version"
|
4
4
|
|
5
5
|
module Shakapacker
|
6
6
|
module Utils
|
7
7
|
class VersionSyntaxConverter
|
8
|
-
def rubygem_to_npm(rubygem_version =
|
8
|
+
def rubygem_to_npm(rubygem_version = Shakapacker::VERSION)
|
9
9
|
regex_match = rubygem_version.match(/(\d+\.\d+\.\d+)[.\-]?(.+)?/)
|
10
10
|
return "#{regex_match[1]}-#{regex_match[2]}" if regex_match[2]
|
11
11
|
|