shakapacker 7.0.2 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dummy.yml +4 -2
  3. data/.github/workflows/generator.yml +4 -2
  4. data/.github/workflows/jest.yml +5 -3
  5. data/.github/workflows/js-lint.yml +5 -3
  6. data/.github/workflows/rubocop.yml +4 -2
  7. data/.github/workflows/ruby-backward-compatibility.yml +5 -3
  8. data/.github/workflows/ruby.yml +5 -3
  9. data/CHANGELOG.md +15 -1
  10. data/CONTRIBUTING.md +3 -4
  11. data/README.md +37 -23
  12. data/docs/deployment.md +1 -1
  13. data/docs/react.md +4 -4
  14. data/docs/troubleshooting.md +4 -8
  15. data/docs/using_esbuild_loader.md +3 -5
  16. data/docs/v6_upgrade.md +1 -1
  17. data/docs/v7_upgrade.md +2 -2
  18. data/lib/install/template.rb +2 -2
  19. data/lib/shakapacker/compiler.rb +1 -1
  20. data/lib/shakapacker/deprecation_helper.rb +1 -1
  21. data/lib/shakapacker/dev_server_runner.rb +2 -1
  22. data/lib/shakapacker/utils/misc.rb +1 -1
  23. data/lib/shakapacker/version.rb +1 -1
  24. data/lib/shakapacker/version_checker.rb +35 -2
  25. data/lib/shakapacker/webpack_runner.rb +4 -3
  26. data/lib/tasks/shakapacker/binstubs.rake +2 -2
  27. data/lib/tasks/shakapacker/check_binstubs.rake +7 -2
  28. data/lib/tasks/shakapacker/install.rake +2 -2
  29. data/package/__tests__/index.js +24 -0
  30. data/package/environments/__tests__/base-bc.js +1 -1
  31. data/package/environments/__tests__/development.js +9 -9
  32. data/package/environments/__tests__/production.js +12 -12
  33. data/package/index.d.ts +61 -0
  34. data/package/index.js +8 -2
  35. data/package.json +12 -1
  36. data/rakelib/release.rake +1 -1
  37. data/spec/backward_compatibility_specs/compiler_spec.rb +2 -2
  38. data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +5 -3
  39. data/spec/backward_compatibility_specs/configuration_spec.rb +16 -8
  40. data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +17 -16
  41. data/spec/backward_compatibility_specs/dev_server_spec.rb +1 -1
  42. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +2 -0
  43. data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +2 -1
  44. data/spec/backward_compatibility_specs/helper_spec.rb +20 -20
  45. data/spec/backward_compatibility_specs/instance_spec.rb +3 -3
  46. data/spec/backward_compatibility_specs/manifest_spec.rb +12 -12
  47. data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +3 -3
  48. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +9 -5
  49. data/spec/backward_compatibility_specs/webpack_runner_spec.rb +14 -18
  50. data/spec/dummy/config/webpack/commonWebpackConfig.js +1 -1
  51. data/spec/fixtures/beta_pnpm-lock.v7.yaml +116 -0
  52. data/spec/fixtures/beta_pnpm-lock.v8.yaml +2537 -0
  53. data/spec/fixtures/git_url_pnpm-lock.v7.yaml +126 -0
  54. data/spec/fixtures/git_url_pnpm-lock.v8.yaml +3728 -0
  55. data/spec/fixtures/github_url_pnpm-lock.v7.yaml +126 -0
  56. data/spec/fixtures/github_url_pnpm-lock.v8.yaml +3728 -0
  57. data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +18 -0
  58. data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +22 -0
  59. data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +117 -0
  60. data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +2558 -0
  61. data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +117 -0
  62. data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +2558 -0
  63. data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +116 -0
  64. data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +2558 -0
  65. data/spec/fixtures/without_pnpm-lock.v7.yaml +23 -0
  66. data/spec/fixtures/without_pnpm-lock.v8.yaml +27 -0
  67. data/spec/generator_specs/generator_spec.rb +11 -7
  68. data/spec/shakapacker/compiler_spec.rb +2 -2
  69. data/spec/shakapacker/compiler_strategy_spec.rb +5 -3
  70. data/spec/shakapacker/configuration_spec.rb +16 -6
  71. data/spec/shakapacker/dev_server_runner_spec.rb +22 -16
  72. data/spec/shakapacker/dev_server_spec.rb +1 -1
  73. data/spec/shakapacker/digest_strategy_spec.rb +2 -0
  74. data/spec/shakapacker/engine_rake_tasks_spec.rb +2 -1
  75. data/spec/shakapacker/helper_spec.rb +20 -20
  76. data/spec/shakapacker/instance_spec.rb +2 -2
  77. data/spec/shakapacker/manifest_spec.rb +12 -12
  78. data/spec/shakapacker/mtime_strategy_spec.rb +3 -3
  79. data/spec/shakapacker/rake_tasks_spec.rb +6 -3
  80. data/spec/shakapacker/shakapacker_spec.rb +4 -4
  81. data/spec/shakapacker/version_checker_spec.rb +470 -123
  82. data/spec/shakapacker/webpack_runner_spec.rb +14 -18
  83. metadata +20 -3
@@ -19,6 +19,7 @@ module Shakapacker
19
19
  def run
20
20
  env = Shakapacker::Compiler.env
21
21
  env["SHAKAPACKER_CONFIG"] = @shakapacker_config
22
+ env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
22
23
 
23
24
  cmd = if node_modules_bin_exist?
24
25
  ["#{@node_modules_bin_path}/webpack"]
@@ -36,15 +37,15 @@ module Shakapacker
36
37
  end
37
38
 
38
39
  if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
39
- cmd = ["node", "--inspect-brk"] + cmd
40
+ env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
40
41
  end
41
42
 
42
43
  if @argv.delete "--trace-deprecation"
43
- cmd = ["node", "--trace-deprecation"] + cmd
44
+ env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --trace-deprecation"
44
45
  end
45
46
 
46
47
  if @argv.delete "--no-deprecation"
47
- cmd = ["node", "--no-deprecation"] + cmd
48
+ env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --no-deprecation"
48
49
  end
49
50
 
50
51
  # Webpack commands are not compatible with --config option.
@@ -7,9 +7,9 @@ namespace :shakapacker do
7
7
  prefix = task.name.split(/#|shakapacker:binstubs/).first
8
8
 
9
9
  if Rails::VERSION::MAJOR >= 5
10
- exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION='#{binstubs_template_path}'"
10
+ exec "#{RbConfig.ruby} '#{bin_path}/rails' #{prefix}app:template LOCATION='#{binstubs_template_path}'"
11
11
  else
12
- exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION='#{binstubs_template_path}'"
12
+ exec "#{RbConfig.ruby} '#{bin_path}/rake' #{prefix}rails:template LOCATION='#{binstubs_template_path}'"
13
13
  end
14
14
  end
15
15
  end
@@ -1,12 +1,17 @@
1
1
  namespace :shakapacker do
2
2
  desc "Verifies that bin/shakapacker is present"
3
3
  task :check_binstubs do
4
- verify_file_existance("bin/shakapacker", "bin/webpacker")
5
- verify_file_existance("bin/shakapacker-dev-server", "bin/webpacker-dev-server")
4
+ verify_file_existence("bin/shakapacker", "bin/webpacker")
5
+ verify_file_existence("bin/shakapacker-dev-server", "bin/webpacker-dev-server")
6
6
  end
7
7
  end
8
8
 
9
9
  def verify_file_existance(main_file, alternative_file)
10
+ puts "verify_file_existance is deprecated - use verify_file_existence instead"
11
+ verify_file_existence(main_file, alternative_file)
12
+ end
13
+
14
+ def verify_file_existence(main_file, alternative_file)
10
15
  unless File.exist?(Rails.root.join(main_file))
11
16
  if File.exist?(Rails.root.join(alternative_file))
12
17
  Shakapacker.puts_deprecation_message(
@@ -9,9 +9,9 @@ namespace :shakapacker do
9
9
  prefix = task.name.split(/#|shakapacker:install/).first
10
10
 
11
11
  if Rails::VERSION::MAJOR >= 5
12
- exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION='#{install_template_path}'"
12
+ exec "#{RbConfig.ruby} '#{bin_path}/rails' #{prefix}app:template LOCATION='#{install_template_path}'"
13
13
  else
14
- exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION='#{install_template_path}'"
14
+ exec "#{RbConfig.ruby} '#{bin_path}/rake' #{prefix}rails:template LOCATION='#{install_template_path}'"
15
15
  end
16
16
  end
17
17
  end
@@ -1,4 +1,5 @@
1
1
  const index = require('../index')
2
+ const { generateWebpackConfig } = require("../index");
2
3
 
3
4
  describe('index', () => {
4
5
  test('exports webpack-merge v5 functions', () => {
@@ -19,4 +20,27 @@ describe('index', () => {
19
20
  expect(webpackConfig2).not.toHaveProperty('newKey')
20
21
  expect(webpackConfig2.output.path).not.toEqual('new value')
21
22
  })
23
+
24
+ test('webpackConfig merges extra config', () => {
25
+ const { generateWebpackConfig } = require('../index')
26
+
27
+ const webpackConfig = generateWebpackConfig({
28
+ newKey: 'new value',
29
+ output: {
30
+ path: 'new path'
31
+ }
32
+ })
33
+
34
+ expect(webpackConfig).toHaveProperty('newKey', 'new value')
35
+ expect(webpackConfig).toHaveProperty('output.path', 'new path')
36
+ expect(webpackConfig).toHaveProperty('output.publicPath', '/packs/')
37
+ })
38
+
39
+ test('webpackConfig errors if multiple configs are provided', () => {
40
+ const { generateWebpackConfig } = require('../index')
41
+
42
+ expect(() => generateWebpackConfig({}, {})).toThrow(
43
+ 'use webpack-merge to merge configs before passing them to Shakapacker'
44
+ )
45
+ })
22
46
  })
@@ -1,6 +1,6 @@
1
1
  /* global test expect, describe, afterAll, beforeEach */
2
2
 
3
- // environment.js expects to find config/webapacker.yml and resolved modules from
3
+ // environment.js expects to find config/webpacker.yml and resolved modules from
4
4
  // the root of a Rails project
5
5
 
6
6
  const { resetEnv, chdirWebpackerTestApp } = require('../../utils/helpers')
@@ -16,10 +16,10 @@ describe('Development specific config', () => {
16
16
  test('sets filename to use contentHash', () => {
17
17
  const config = require("../../config");
18
18
  config.useContentHash = true
19
- const environmnetConfig = require('../development')
19
+ const environmentConfig = require('../development')
20
20
 
21
- expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
- expect(environmnetConfig.output.chunkFilename).toEqual(
21
+ expect(environmentConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
+ expect(environmentConfig.output.chunkFilename).toEqual(
23
23
  'js/[name]-[contenthash].chunk.js'
24
24
  )
25
25
  })
@@ -29,10 +29,10 @@ describe('Development specific config', () => {
29
29
  test('sets filename without using contentHash', () => {
30
30
  const config = require("../../config");
31
31
  config.useContentHash = false
32
- const environmnetConfig = require('../development')
32
+ const environmentConfig = require('../development')
33
33
 
34
- expect(environmnetConfig.output.filename).toEqual('js/[name].js')
35
- expect(environmnetConfig.output.chunkFilename).toEqual(
34
+ expect(environmentConfig.output.filename).toEqual('js/[name].js')
35
+ expect(environmentConfig.output.chunkFilename).toEqual(
36
36
  'js/[name].chunk.js'
37
37
  )
38
38
  })
@@ -42,10 +42,10 @@ describe('Development specific config', () => {
42
42
  test('sets filename without using contentHash', () => {
43
43
  const config = require("../../config");
44
44
  delete config.useContentHash
45
- const environmnetConfig = require('../development')
45
+ const environmentConfig = require('../development')
46
46
 
47
- expect(environmnetConfig.output.filename).toEqual('js/[name].js')
48
- expect(environmnetConfig.output.chunkFilename).toEqual(
47
+ expect(environmentConfig.output.filename).toEqual('js/[name].js')
48
+ expect(environmentConfig.output.chunkFilename).toEqual(
49
49
  'js/[name].chunk.js'
50
50
  )
51
51
  })
@@ -16,10 +16,10 @@ describe('Production specific config', () => {
16
16
  test('sets filename to use contentHash', () => {
17
17
  const config = require("../../config");
18
18
  config.useContentHash = true
19
- const environmnetConfig = require('../production')
19
+ const environmentConfig = require('../production')
20
20
 
21
- expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
- expect(environmnetConfig.output.chunkFilename).toEqual(
21
+ expect(environmentConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
+ expect(environmentConfig.output.chunkFilename).toEqual(
23
23
  'js/[name]-[contenthash].chunk.js'
24
24
  )
25
25
  })
@@ -28,7 +28,7 @@ describe('Production specific config', () => {
28
28
  const consoleWarnSpy = jest.spyOn(console, 'warn');
29
29
  const config = require("../../config");
30
30
  config.useContentHash = true
31
- const environmnetConfig = require('../production')
31
+ const environmentConfig = require('../production')
32
32
 
33
33
  expect(consoleWarnSpy).not.toHaveBeenCalledWith(
34
34
  expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
@@ -42,10 +42,10 @@ describe('Production specific config', () => {
42
42
  test('sets filename to use contentHash', () => {
43
43
  const config = require("../../config");
44
44
  config.useContentHash = false
45
- const environmnetConfig = require('../production')
45
+ const environmentConfig = require('../production')
46
46
 
47
- expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
48
- expect(environmnetConfig.output.chunkFilename).toEqual(
47
+ expect(environmentConfig.output.filename).toEqual('js/[name]-[contenthash].js')
48
+ expect(environmentConfig.output.chunkFilename).toEqual(
49
49
  'js/[name]-[contenthash].chunk.js'
50
50
  )
51
51
  })
@@ -54,7 +54,7 @@ describe('Production specific config', () => {
54
54
  const consoleWarnSpy = jest.spyOn(console, 'warn');
55
55
  const config = require("../../config");
56
56
  config.useContentHash = false
57
- const environmnetConfig = require('../production')
57
+ const environmentConfig = require('../production')
58
58
 
59
59
  expect(consoleWarnSpy).toHaveBeenCalledWith(
60
60
  expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
@@ -68,10 +68,10 @@ describe('Production specific config', () => {
68
68
  test('sets filename to use contentHash', () => {
69
69
  const config = require("../../config");
70
70
  delete config.useContentHash
71
- const environmnetConfig = require('../production')
71
+ const environmentConfig = require('../production')
72
72
 
73
- expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
74
- expect(environmnetConfig.output.chunkFilename).toEqual(
73
+ expect(environmentConfig.output.filename).toEqual('js/[name]-[contenthash].js')
74
+ expect(environmentConfig.output.chunkFilename).toEqual(
75
75
  'js/[name]-[contenthash].chunk.js'
76
76
  )
77
77
  })
@@ -80,7 +80,7 @@ describe('Production specific config', () => {
80
80
  const consoleWarnSpy = jest.spyOn(console, 'warn');
81
81
  const config = require("../../config");
82
82
  delete config.useContentHash
83
- const environmnetConfig = require('../production')
83
+ const environmentConfig = require('../production')
84
84
 
85
85
  expect(consoleWarnSpy).not.toHaveBeenCalledWith(
86
86
  expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
@@ -0,0 +1,61 @@
1
+ declare module 'shakapacker' {
2
+ import { Configuration } from 'webpack'
3
+
4
+ export interface Config {
5
+ source_path: string
6
+ source_entry_path: string
7
+ nested_entries: boolean
8
+ css_extract_ignore_order_warnings: boolean
9
+ public_root_path: string
10
+ public_output_path: string
11
+ cache_path: string
12
+ webpack_compile_output: boolean
13
+ shakapacker_precompile: boolean
14
+ additional_paths: string[]
15
+ cache_manifest: boolean
16
+ webpack_loader: string
17
+ ensure_consistent_versioning: boolean
18
+ compiler_strategy: string
19
+ useContentHash: boolean
20
+ compile: boolean,
21
+ outputPath: string
22
+ publicPath: string
23
+ publicPathWithoutCDN: string
24
+ manifestPath: string
25
+ }
26
+
27
+ export interface Env {
28
+ railsEnv: string
29
+ nodeEnv: string
30
+ isProduction: boolean
31
+ isDevelopment: boolean
32
+ runningWebpackDevServer: boolean
33
+ }
34
+
35
+ export const config: Config
36
+ export const devServer: Record<string, unknown>
37
+ export function generateWebpackConfig(extraConfig?: Configuration): Configuration
38
+ export const globalMutableWebpackConfig: Configuration
39
+ export const baseConfig: Configuration
40
+ export const env: Env
41
+ export const rules: Record<string, unknown>
42
+ export function moduleExists(packageName: string): boolean
43
+ export function canProcess<T = unknown>(rule: string, fn: (modulePath: string) => T): T | null
44
+ export const inliningCss: boolean
45
+ export * from 'webpack-merge'
46
+ }
47
+
48
+ declare module 'shakapacker/package/babel/preset.js' {
49
+ import { ConfigAPI, PluginItem, TransformOptions } from '@babel/core'
50
+
51
+ interface RequiredTransformOptions {
52
+ plugins: PluginItem[]
53
+ presets: PluginItem[]
54
+ }
55
+
56
+ const defaultConfigFunc: (
57
+ api: ConfigAPI
58
+ ) => TransformOptions & RequiredTransformOptions
59
+
60
+ export = defaultConfigFunc
61
+ }
data/package/index.js CHANGED
@@ -19,9 +19,15 @@ const globalMutableWebpackConfig = () => {
19
19
  return environmentConfig
20
20
  }
21
21
 
22
- const generateWebpackConfig = () => {
22
+ const generateWebpackConfig = (extraConfig = {}, ...extraArgs) => {
23
+ if (extraArgs.length > 0) {
24
+ throw new Error(
25
+ 'Only one extra config may be passed here - use webpack-merge to merge configs before passing them to Shakapacker'
26
+ )
27
+ }
28
+
23
29
  const environmentConfig = globalMutableWebpackConfig()
24
- const immutable = webpackMerge.merge({}, environmentConfig)
30
+ const immutable = webpackMerge.merge({}, environmentConfig, extraConfig)
25
31
  return immutable
26
32
  }
27
33
 
data/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "shakapacker",
3
- "version": "7.0.2",
3
+ "version": "7.1.0",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
+ "types": "package/index.d.ts",
6
7
  "files": [
7
8
  "package",
8
9
  "lib/install/config/shakapacker.yml"
@@ -12,6 +13,8 @@
12
13
  "yarn": ">=1 <4"
13
14
  },
14
15
  "peerDependencies": {
16
+ "@types/babel__core": "^7.0.0",
17
+ "@types/webpack": "^5.0.0",
15
18
  "@babel/core": "^7.17.9",
16
19
  "@babel/plugin-transform-runtime": "^7.17.0",
17
20
  "@babel/preset-env": "^7.16.11",
@@ -25,6 +28,14 @@
25
28
  "webpack-dev-server": "^4.9.0",
26
29
  "webpack-merge": "^5.8.0"
27
30
  },
31
+ "peerDependenciesMeta": {
32
+ "@types/babel__core": {
33
+ "optional": true
34
+ },
35
+ "@types/webpack": {
36
+ "optional": true
37
+ }
38
+ },
28
39
  "dependencies": {
29
40
  "glob": "^7.2.0",
30
41
  "js-yaml": "^4.1.0",
data/rakelib/release.rake CHANGED
@@ -25,7 +25,7 @@ Note, accept defaults for npmjs options. Script will pause to get 2FA tokens.
25
25
 
26
26
  Example: `rake release[2.1.0,false]`")
27
27
  task :create_release, %i[gem_version dry_run] do |_t, args|
28
- # Check if there are uncommited changes
28
+ # Check if there are uncommitted changes
29
29
  Shakapacker::Utils::Misc.uncommitted_changes?(RaisingMessageHandler.new)
30
30
  args_hash = args.to_hash
31
31
 
@@ -26,7 +26,7 @@ describe "Webpacker::Compiler" do
26
26
  allow(Webpacker.compiler).to receive(:strategy).and_return(mocked_strategy)
27
27
 
28
28
  status = OpenStruct.new(success?: true)
29
- allow(Open3).to receive(:capture3).and_return([:sterr, :stdout, status])
29
+ allow(Open3).to receive(:capture3).and_return([:stderr, :stdout, status])
30
30
 
31
31
  expect(Webpacker.compiler.compile).to be true
32
32
  expect(mocked_strategy).to have_received(:after_compile_hook)
@@ -40,7 +40,7 @@ describe "Webpacker::Compiler" do
40
40
  allow(Webpacker.compiler).to receive(:strategy).and_return(mocked_strategy)
41
41
 
42
42
  status = OpenStruct.new(success?: false)
43
- allow(Open3).to receive(:capture3).and_return([:sterr, :stdout, status])
43
+ allow(Open3).to receive(:capture3).and_return([:stderr, :stdout, status])
44
44
 
45
45
  expect(Webpacker.compiler.compile).to be false
46
46
  expect(mocked_strategy).to have_received(:after_compile_hook)
@@ -2,17 +2,19 @@ require_relative "spec_helper_initializer"
2
2
 
3
3
  describe "Webpacker::CompilerStrategy" do
4
4
  describe "#from_config" do
5
- it "returns and instance of MtimeStrategy when compiler_strategy is set to mtime" do
5
+ it "returns an instance of MtimeStrategy when compiler_strategy is set to mtime" do
6
6
  allow(Webpacker.config).to receive(:compiler_strategy).and_return("mtime")
7
+
7
8
  expect(Webpacker::CompilerStrategy.from_config).to be_an_instance_of(Webpacker::MtimeStrategy)
8
9
  end
9
10
 
10
- it "returns and instance of DigestStrategy when compiler_strategy is set to digest" do
11
+ it "returns an instance of DigestStrategy when compiler_strategy is set to digest" do
11
12
  allow(Webpacker.config).to receive(:compiler_strategy).and_return("digest")
13
+
12
14
  expect(Webpacker::CompilerStrategy.from_config).to be_an_instance_of(Webpacker::DigestStrategy)
13
15
  end
14
16
 
15
- it "raise exception for unknown compiler_strategy in the config file" do
17
+ it "raise an exception for unknown compiler_strategy in the config file" do
16
18
  expected_error_message = "Unknown strategy 'other'. Available options are 'mtime' and 'digest'."
17
19
  allow(Webpacker.config).to receive(:compiler_strategy).and_return("other")
18
20
 
@@ -14,36 +14,43 @@ describe "Webpacker::Configuration" do
14
14
 
15
15
  it "#source_path returns correct path" do
16
16
  source_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs").to_s
17
+
17
18
  expect(config.source_path.to_s).to eq source_path
18
19
  end
19
20
 
20
21
  it "#source_entry_path returns correct path" do
21
22
  source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs", "entrypoints").to_s
23
+
22
24
  expect(config.source_entry_path.to_s).to eq source_entry_path
23
25
  end
24
26
 
25
27
  it "#public_root_path returns correct path" do
26
28
  public_root_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public").to_s
29
+
27
30
  expect(config.public_path.to_s).to eq public_root_path
28
31
  end
29
32
 
30
33
  it "#public_output_path returns correct path" do
31
34
  public_output_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs").to_s
35
+
32
36
  expect(config.public_output_path.to_s).to eq public_output_path
33
37
  end
34
38
 
35
39
  it "#public_manifest_path returns correct path" do
36
40
  public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s
41
+
37
42
  expect(config.public_manifest_path.to_s).to eq public_manifest_path
38
43
  end
39
44
 
40
45
  it "#manifest_path returns correct path" do
41
46
  manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s
47
+
42
48
  expect(config.manifest_path.to_s).to eq manifest_path
43
49
  end
44
50
 
45
51
  it "#cache_path returns correct path" do
46
52
  cache_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/tmp/webpacker").to_s
53
+
47
54
  expect(config.cache_path.to_s).to eq cache_path
48
55
  end
49
56
 
@@ -56,7 +63,7 @@ describe "Webpacker::Configuration" do
56
63
  expect(config.cache_manifest?).to be true
57
64
  end
58
65
 
59
- it "returns false in developemnt environemnt" do
66
+ it "returns false in development environment" do
60
67
  with_rails_env("development") do
61
68
  expect(Webpacker.config.cache_manifest?).to be false
62
69
  end
@@ -74,13 +81,13 @@ describe "Webpacker::Configuration" do
74
81
  expect(config.compile?).to be false
75
82
  end
76
83
 
77
- it "returns true in developemnt environemnt" do
84
+ it "returns true in development environment" do
78
85
  with_rails_env("development") do
79
86
  expect(Webpacker.config.compile?).to be true
80
87
  end
81
88
  end
82
89
 
83
- it "returns true in test environemnt" do
90
+ it "returns true in test environment" do
84
91
  with_rails_env("test") do
85
92
  expect(Webpacker.config.compile?).to be true
86
93
  end
@@ -186,11 +193,12 @@ describe "Webpacker::Configuration" do
186
193
 
187
194
  it "#public_output_path returns correct path" do
188
195
  expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
196
+
189
197
  expect(config.public_output_path.to_s).to eq expected_public_output_path
190
198
  end
191
199
  end
192
200
 
193
- context "with webpacker config file containing manifext_path entry" do
201
+ context "with webpacker config file containing manifest_path entry" do
194
202
  config = Webpacker::Configuration.new(
195
203
  root_path: ROOT_PATH,
196
204
  config_path: Pathname.new(File.expand_path("./webpacker_test_app/config/webpacker_manifest_path.yml", __dir__)),
@@ -199,6 +207,7 @@ describe "Webpacker::Configuration" do
199
207
 
200
208
  it "#manifest_path returns correct expected value" do
201
209
  expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs", "manifest.json").to_s
210
+
202
211
  expect(config.manifest_path.to_s).to eq expected_manifest_path
203
212
  end
204
213
  end
@@ -206,8 +215,8 @@ describe "Webpacker::Configuration" do
206
215
  context "with webpacker_precompile entry set to false" do
207
216
  describe "#webpacker_precompile?" do
208
217
  before :each do
209
- ENV.delete("WEBPACKER_PRECOMPILE")
210
218
  ENV.delete("SHAKAPACKER_PRECOMPILE")
219
+ ENV.delete("WEBPACKER_PRECOMPILE")
211
220
  end
212
221
 
213
222
  let(:config) {
@@ -229,9 +238,8 @@ describe "Webpacker::Configuration" do
229
238
  expect(subject).to be true
230
239
  end
231
240
 
232
- it "returns false with WEBPACKER_PRECOMPILE set to falsy value" do
233
- # ENV["WEBPACKER_PRECOMPILE"] = "no"
234
- ENV.delete("WEBPACKER_PRECOMPILE")
241
+ it "returns false with WEBPACKER_PRECOMPILE set to nil" do
242
+ ENV["SHAKAPACKER_PRECOMPILE"] = nil
235
243
  expect(subject).to be false
236
244
  end
237
245
  end
@@ -17,22 +17,25 @@ describe "DevServerRunner" do
17
17
 
18
18
  let(:test_app_path) { File.expand_path("webpacker_test_app", __dir__) }
19
19
 
20
- it "run cmd via node modules" do
20
+ it "supports running via node modules" do
21
21
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
22
+
22
23
  verify_command(cmd, use_node_modules: true)
23
24
  end
24
25
 
25
- it "run cmd via yarn" do
26
+ it "supports running via yarn" do
26
27
  cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
28
+
27
29
  verify_command(cmd, use_node_modules: false)
28
30
  end
29
31
 
30
- it "run cmd argv" do
32
+ it "passes on arguments" do
31
33
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
34
+
32
35
  verify_command(cmd, argv: (["--quiet"]))
33
36
  end
34
37
 
35
- it "run cmd argv with https" do
38
+ it "supports the https flag" do
36
39
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
37
40
 
38
41
  dev_server = double()
@@ -54,26 +57,24 @@ describe "DevServerRunner" do
54
57
  # ENV["WEBPACKER_CONFIG"] is the interface and env["SHAKAPACKER_CONFIG"] is internal
55
58
  ENV["WEBPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
56
59
  env["WEBPACK_SERVE"] = "true"
60
+
57
61
  verify_command(cmd, env: env)
58
62
  end
59
63
 
60
64
  private
61
65
 
62
66
  def verify_command(cmd, use_node_modules: true, argv: [], env: Webpacker::Compiler.env)
63
- cwd = Dir.pwd
64
- Dir.chdir(test_app_path)
65
- klass = Webpacker::DevServerRunner
66
- instance = klass.new(argv)
67
-
68
- allow(klass).to receive(:new).and_return(instance)
69
- allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
70
- allow(Kernel).to receive(:exec).with(env, *cmd)
67
+ Dir.chdir(test_app_path) do
68
+ klass = Webpacker::DevServerRunner
69
+ instance = klass.new(argv)
71
70
 
72
- klass.run(argv)
71
+ allow(klass).to receive(:new).and_return(instance)
72
+ allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
73
+ allow(Kernel).to receive(:exec).with(env, *cmd)
73
74
 
74
- expect(Kernel).to have_received(:exec).with(env, *cmd)
75
+ klass.run(argv)
75
76
 
76
- ensure
77
- Dir.chdir(cwd)
77
+ expect(Kernel).to have_received(:exec).with(env, *cmd)
78
+ end
78
79
  end
79
80
  end
@@ -41,7 +41,7 @@ describe "DevServer" do
41
41
  end
42
42
  end
43
43
 
44
- it "users SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
44
+ it "uses SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
45
45
  expect(Webpacker::DevServer::DEFAULT_ENV_PREFIX).to eq "SHAKAPACKER_DEV_SERVER"
46
46
  end
47
47
  end
@@ -23,6 +23,7 @@ describe "DigestStrategy" do
23
23
 
24
24
  it "is fresh after compilation" do
25
25
  @digest_strategy.after_compile_hook
26
+
26
27
  expect(@digest_strategy.stale?).to be false
27
28
  expect(@digest_strategy.fresh?).to be true
28
29
  end
@@ -30,6 +31,7 @@ describe "DigestStrategy" do
30
31
  it "generates correct compilation_digest_path" do
31
32
  actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
32
33
  expected_path = "last-compilation-digest-#{Webpacker.env}"
34
+
33
35
  expect(actual_path).to eq expected_path
34
36
  end
35
37
  end
@@ -11,11 +11,12 @@ describe "EngineRakeTasks" do
11
11
 
12
12
  it "mounts app:webpacker task successfully" do
13
13
  output = Dir.chdir(mounted_app_path) { `rake -T` }
14
+
14
15
  expect(output).to match /app:webpacker.+DEPRECATED/
15
16
  expect(output).to match /app:webpacker:binstubs.+DEPRECATED/
16
17
  end
17
18
 
18
- it "binstubs adds only expected files to bin directory" do
19
+ it "only adds expected files to bin directory when binstubs is run" do
19
20
  Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
20
21
  expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
21
22
  end