shakapacker 7.0.2 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/dummy.yml +4 -2
- data/.github/workflows/generator.yml +4 -2
- data/.github/workflows/jest.yml +5 -3
- data/.github/workflows/js-lint.yml +5 -3
- data/.github/workflows/rubocop.yml +4 -2
- data/.github/workflows/ruby-backward-compatibility.yml +5 -3
- data/.github/workflows/ruby.yml +5 -3
- data/CHANGELOG.md +15 -1
- data/CONTRIBUTING.md +3 -4
- data/README.md +37 -23
- data/docs/deployment.md +1 -1
- data/docs/react.md +4 -4
- data/docs/troubleshooting.md +4 -8
- data/docs/using_esbuild_loader.md +3 -5
- data/docs/v6_upgrade.md +1 -1
- data/docs/v7_upgrade.md +2 -2
- data/lib/install/template.rb +2 -2
- data/lib/shakapacker/compiler.rb +1 -1
- data/lib/shakapacker/deprecation_helper.rb +1 -1
- data/lib/shakapacker/dev_server_runner.rb +2 -1
- data/lib/shakapacker/utils/misc.rb +1 -1
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +35 -2
- data/lib/shakapacker/webpack_runner.rb +4 -3
- data/lib/tasks/shakapacker/binstubs.rake +2 -2
- data/lib/tasks/shakapacker/check_binstubs.rake +7 -2
- data/lib/tasks/shakapacker/install.rake +2 -2
- data/package/__tests__/index.js +24 -0
- data/package/environments/__tests__/base-bc.js +1 -1
- data/package/environments/__tests__/development.js +9 -9
- data/package/environments/__tests__/production.js +12 -12
- data/package/index.d.ts +61 -0
- data/package/index.js +8 -2
- data/package.json +12 -1
- data/rakelib/release.rake +1 -1
- data/spec/backward_compatibility_specs/compiler_spec.rb +2 -2
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +5 -3
- data/spec/backward_compatibility_specs/configuration_spec.rb +16 -8
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +17 -16
- data/spec/backward_compatibility_specs/dev_server_spec.rb +1 -1
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +2 -0
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +2 -1
- data/spec/backward_compatibility_specs/helper_spec.rb +20 -20
- data/spec/backward_compatibility_specs/instance_spec.rb +3 -3
- data/spec/backward_compatibility_specs/manifest_spec.rb +12 -12
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +3 -3
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +9 -5
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +14 -18
- data/spec/dummy/config/webpack/commonWebpackConfig.js +1 -1
- data/spec/fixtures/beta_pnpm-lock.v7.yaml +116 -0
- data/spec/fixtures/beta_pnpm-lock.v8.yaml +2537 -0
- data/spec/fixtures/git_url_pnpm-lock.v7.yaml +126 -0
- data/spec/fixtures/git_url_pnpm-lock.v8.yaml +3728 -0
- data/spec/fixtures/github_url_pnpm-lock.v7.yaml +126 -0
- data/spec/fixtures/github_url_pnpm-lock.v8.yaml +3728 -0
- data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +18 -0
- data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +22 -0
- data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +117 -0
- data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +117 -0
- data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +116 -0
- data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/without_pnpm-lock.v7.yaml +23 -0
- data/spec/fixtures/without_pnpm-lock.v8.yaml +27 -0
- data/spec/generator_specs/generator_spec.rb +11 -7
- data/spec/shakapacker/compiler_spec.rb +2 -2
- data/spec/shakapacker/compiler_strategy_spec.rb +5 -3
- data/spec/shakapacker/configuration_spec.rb +16 -6
- data/spec/shakapacker/dev_server_runner_spec.rb +22 -16
- data/spec/shakapacker/dev_server_spec.rb +1 -1
- data/spec/shakapacker/digest_strategy_spec.rb +2 -0
- data/spec/shakapacker/engine_rake_tasks_spec.rb +2 -1
- data/spec/shakapacker/helper_spec.rb +20 -20
- data/spec/shakapacker/instance_spec.rb +2 -2
- data/spec/shakapacker/manifest_spec.rb +12 -12
- data/spec/shakapacker/mtime_strategy_spec.rb +3 -3
- data/spec/shakapacker/rake_tasks_spec.rb +6 -3
- data/spec/shakapacker/shakapacker_spec.rb +4 -4
- data/spec/shakapacker/version_checker_spec.rb +470 -123
- data/spec/shakapacker/webpack_runner_spec.rb +14 -18
- 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
|
-
|
40
|
+
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
|
40
41
|
end
|
41
42
|
|
42
43
|
if @argv.delete "--trace-deprecation"
|
43
|
-
|
44
|
+
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --trace-deprecation"
|
44
45
|
end
|
45
46
|
|
46
47
|
if @argv.delete "--no-deprecation"
|
47
|
-
|
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
|
-
|
5
|
-
|
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
|
data/package/__tests__/index.js
CHANGED
@@ -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/
|
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
|
19
|
+
const environmentConfig = require('../development')
|
20
20
|
|
21
|
-
expect(
|
22
|
-
expect(
|
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
|
32
|
+
const environmentConfig = require('../development')
|
33
33
|
|
34
|
-
expect(
|
35
|
-
expect(
|
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
|
45
|
+
const environmentConfig = require('../development')
|
46
46
|
|
47
|
-
expect(
|
48
|
-
expect(
|
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
|
19
|
+
const environmentConfig = require('../production')
|
20
20
|
|
21
|
-
expect(
|
22
|
-
expect(
|
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
|
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
|
45
|
+
const environmentConfig = require('../production')
|
46
46
|
|
47
|
-
expect(
|
48
|
-
expect(
|
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
|
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
|
71
|
+
const environmentConfig = require('../production')
|
72
72
|
|
73
|
-
expect(
|
74
|
-
expect(
|
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
|
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/)
|
data/package/index.d.ts
ADDED
@@ -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
|
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
|
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([:
|
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([:
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
233
|
-
|
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 "
|
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 "
|
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 "
|
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 "
|
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
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
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
|
-
|
75
|
+
klass.run(argv)
|
75
76
|
|
76
|
-
|
77
|
-
|
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 "
|
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 "
|
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
|