webpacker-jets 3.2.100

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintignore +4 -0
  3. data/.eslintrc.js +14 -0
  4. data/.gitignore +6 -0
  5. data/.rubocop.yml +124 -0
  6. data/.travis.yml +32 -0
  7. data/CHANGELOG.md +523 -0
  8. data/Gemfile +13 -0
  9. data/Gemfile.lock +154 -0
  10. data/MIT-LICENSE +20 -0
  11. data/README.md +445 -0
  12. data/Rakefile +12 -0
  13. data/docs/assets.md +106 -0
  14. data/docs/cloud9.md +310 -0
  15. data/docs/css.md +116 -0
  16. data/docs/deployment.md +74 -0
  17. data/docs/docker.md +49 -0
  18. data/docs/env.md +65 -0
  19. data/docs/es6.md +53 -0
  20. data/docs/folder-structure.md +66 -0
  21. data/docs/misc.md +23 -0
  22. data/docs/props.md +223 -0
  23. data/docs/testing.md +128 -0
  24. data/docs/troubleshooting.md +119 -0
  25. data/docs/typescript.md +116 -0
  26. data/docs/webpack-dev-server.md +92 -0
  27. data/docs/webpack.md +297 -0
  28. data/docs/yarn.md +12 -0
  29. data/exe/webpack +8 -0
  30. data/exe/webpack-dev-server +8 -0
  31. data/gemfiles/Gemfile-rails-edge +13 -0
  32. data/gemfiles/Gemfile-rails.4.2.x +10 -0
  33. data/gemfiles/Gemfile-rails.5.0.x +10 -0
  34. data/gemfiles/Gemfile-rails.5.1.x +10 -0
  35. data/lib/install/angular.rb +27 -0
  36. data/lib/install/coffee.rb +22 -0
  37. data/lib/install/config/.babelrc +18 -0
  38. data/lib/install/config/.postcssrc.yml +3 -0
  39. data/lib/install/config/webpack/development.js +3 -0
  40. data/lib/install/config/webpack/environment.js +3 -0
  41. data/lib/install/config/webpack/production.js +3 -0
  42. data/lib/install/config/webpack/staging.js +3 -0
  43. data/lib/install/config/webpack/test.js +3 -0
  44. data/lib/install/config/webpacker.yml +79 -0
  45. data/lib/install/elm.rb +38 -0
  46. data/lib/install/erb.rb +22 -0
  47. data/lib/install/examples/angular/hello_angular.js +7 -0
  48. data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
  49. data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
  50. data/lib/install/examples/angular/hello_angular/index.ts +8 -0
  51. data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
  52. data/lib/install/examples/angular/tsconfig.json +19 -0
  53. data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
  54. data/lib/install/examples/elm/Main.elm +54 -0
  55. data/lib/install/examples/elm/hello_elm.js +12 -0
  56. data/lib/install/examples/erb/hello_erb.js.erb +6 -0
  57. data/lib/install/examples/react/.babelrc +6 -0
  58. data/lib/install/examples/react/hello_react.jsx +26 -0
  59. data/lib/install/examples/vue/app.vue +22 -0
  60. data/lib/install/examples/vue/hello_vue.js +70 -0
  61. data/lib/install/javascript/packs/application.js +10 -0
  62. data/lib/install/loaders/coffee.js +6 -0
  63. data/lib/install/loaders/elm.js +23 -0
  64. data/lib/install/loaders/erb.js +11 -0
  65. data/lib/install/loaders/typescript.js +6 -0
  66. data/lib/install/loaders/vue.js +13 -0
  67. data/lib/install/react.rb +28 -0
  68. data/lib/install/template.rb +37 -0
  69. data/lib/install/vue.rb +26 -0
  70. data/lib/tasks/installers.rake +24 -0
  71. data/lib/tasks/webpacker.rake +22 -0
  72. data/lib/tasks/webpacker/check_binstubs.rake +12 -0
  73. data/lib/tasks/webpacker/check_node.rake +24 -0
  74. data/lib/tasks/webpacker/check_yarn.rake +24 -0
  75. data/lib/tasks/webpacker/clobber.rake +16 -0
  76. data/lib/tasks/webpacker/compile.rake +41 -0
  77. data/lib/tasks/webpacker/install.rake +13 -0
  78. data/lib/tasks/webpacker/verify_install.rake +16 -0
  79. data/lib/tasks/webpacker/yarn_install.rake +6 -0
  80. data/lib/webpacker.rb +32 -0
  81. data/lib/webpacker/commands.rb +23 -0
  82. data/lib/webpacker/compiler.rb +88 -0
  83. data/lib/webpacker/configuration.rb +87 -0
  84. data/lib/webpacker/dev_server.rb +61 -0
  85. data/lib/webpacker/dev_server_proxy.rb +26 -0
  86. data/lib/webpacker/dev_server_runner.rb +51 -0
  87. data/lib/webpacker/helper.rb +66 -0
  88. data/lib/webpacker/instance.rb +44 -0
  89. data/lib/webpacker/manifest.rb +75 -0
  90. data/lib/webpacker/railtie.rb +82 -0
  91. data/lib/webpacker/rake_tasks.rb +6 -0
  92. data/lib/webpacker/runner.rb +22 -0
  93. data/lib/webpacker/version.rb +9 -0
  94. data/lib/webpacker/webpack_runner.rb +15 -0
  95. data/package.json +67 -0
  96. data/package/__tests__/environment.js +74 -0
  97. data/package/config.js +34 -0
  98. data/package/config_types/__tests__/config_list.js +123 -0
  99. data/package/config_types/__tests__/config_object.js +43 -0
  100. data/package/config_types/config_list.js +85 -0
  101. data/package/config_types/config_object.js +55 -0
  102. data/package/config_types/index.js +7 -0
  103. data/package/environment.js +116 -0
  104. data/package/environments/development.js +46 -0
  105. data/package/environments/production.js +37 -0
  106. data/package/environments/test.js +3 -0
  107. data/package/index.js +20 -0
  108. data/package/rules/babel.js +13 -0
  109. data/package/rules/css.js +39 -0
  110. data/package/rules/file.js +13 -0
  111. data/package/rules/index.js +11 -0
  112. data/package/rules/sass.js +15 -0
  113. data/package/utils/__tests__/deep_assign.js +11 -0
  114. data/package/utils/__tests__/deep_merge.js +10 -0
  115. data/package/utils/__tests__/objectify.js +9 -0
  116. data/package/utils/deep_assign.js +22 -0
  117. data/package/utils/deep_merge.js +23 -0
  118. data/package/utils/helpers.js +32 -0
  119. data/package/utils/objectify.js +4 -0
  120. data/test/command_test.rb +27 -0
  121. data/test/compiler_test.rb +35 -0
  122. data/test/configuration_test.rb +69 -0
  123. data/test/dev_server_test.rb +24 -0
  124. data/test/helper_test.rb +52 -0
  125. data/test/manifest_test.rb +28 -0
  126. data/test/rake_tasks_test.rb +29 -0
  127. data/test/test_app/Rakefile +3 -0
  128. data/test/test_app/app/javascript/packs/application.js +10 -0
  129. data/test/test_app/config/application.rb +11 -0
  130. data/test/test_app/config/environment.rb +4 -0
  131. data/test/test_app/config/webpacker.yml +65 -0
  132. data/test/test_app/public/packs/manifest.json +6 -0
  133. data/test/test_helper.rb +29 -0
  134. data/webpacker-jets.gemspec +29 -0
  135. data/yarn.lock +5768 -0
  136. metadata +250 -0
@@ -0,0 +1,44 @@
1
+ class Webpacker::Instance
2
+ cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
3
+
4
+ attr_reader :root_path, :config_path
5
+
6
+ def initialize(root_path: Jets.root, config_path: Jets.root.join("config/webpacker.yml"))
7
+ @root_path, @config_path = root_path, config_path
8
+ end
9
+
10
+ def env
11
+ (ENV["NODE_ENV"].presence_in(available_environments) ||
12
+ Jets.env.presence_in(available_environments) ||
13
+ "production".freeze).inquiry
14
+ end
15
+
16
+ def config
17
+ @config ||= Webpacker::Configuration.new self
18
+ end
19
+
20
+ def compiler
21
+ @compiler ||= Webpacker::Compiler.new self
22
+ end
23
+
24
+ def dev_server
25
+ @dev_server ||= Webpacker::DevServer.new self
26
+ end
27
+
28
+ def manifest
29
+ @manifest ||= Webpacker::Manifest.new self
30
+ end
31
+
32
+ def commands
33
+ @commands ||= Webpacker::Commands.new self
34
+ end
35
+
36
+ private
37
+ def available_environments
38
+ if config_path.exist?
39
+ YAML.load(config_path.read).keys
40
+ else
41
+ [].freeze
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,75 @@
1
+ # Singleton registry for accessing the packs path using a generated manifest.
2
+ # This allows javascript_pack_tag, stylesheet_pack_tag, asset_pack_path to take a reference to,
3
+ # say, "calendar.js" or "calendar.css" and turn it into "/packs/calendar-1016838bab065ae1e314.js" or
4
+ # "/packs/calendar-1016838bab065ae1e314.css".
5
+ #
6
+ # When the configuration is set to on-demand compilation, with the `compile: true` option in
7
+ # the webpacker.yml file, any lookups will be preceeded by a compilation if one is needed.
8
+ class Webpacker::Manifest
9
+ class MissingEntryError < StandardError; end
10
+
11
+ delegate :config, :compiler, :dev_server, to: :@webpacker
12
+
13
+ def initialize(webpacker)
14
+ @webpacker = webpacker
15
+ end
16
+
17
+ def refresh
18
+ @data = load
19
+ end
20
+
21
+ def lookup(name)
22
+ compile if compiling?
23
+ find name
24
+ end
25
+
26
+ def lookup!(name)
27
+ lookup(name) || handle_missing_entry(name)
28
+ end
29
+
30
+ private
31
+ def compiling?
32
+ config.compile? && !dev_server.running?
33
+ end
34
+
35
+ def compile
36
+ Webpacker.logger.tagged("Webpacker") { compiler.compile }
37
+ end
38
+
39
+ def find(name)
40
+ data[name.to_s].presence
41
+ end
42
+
43
+ def handle_missing_entry(name)
44
+ raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(name)
45
+ end
46
+
47
+ def missing_file_from_manifest_error(bundle_name)
48
+ <<-MSG
49
+ Webpacker can't find #{bundle_name} in #{config.public_manifest_path}. Possible causes:
50
+ 1. You want to set webpacker.yml value of compile to true for your environment
51
+ unless you are using the `webpack -w` or the webpack-dev-server.
52
+ 2. webpack has not yet re-run to reflect updates.
53
+ 3. You have misconfigured Webpacker's config/webpacker.yml file.
54
+ 4. Your webpack configuration is not creating a manifest.
55
+ Your manifest contains:
56
+ #{JSON.pretty_generate(@data)}
57
+ MSG
58
+ end
59
+
60
+ def data
61
+ if config.cache_manifest?
62
+ @data ||= load
63
+ else
64
+ refresh
65
+ end
66
+ end
67
+
68
+ def load
69
+ if config.public_manifest_path.exist?
70
+ JSON.parse config.public_manifest_path.read
71
+ else
72
+ {}
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,82 @@
1
+ require "rails/railtie"
2
+
3
+ require "webpacker/helper"
4
+ require "webpacker/dev_server_proxy"
5
+
6
+ class Webpacker::Engine < ::Rails::Engine
7
+ # Allows Webpacker config values to be set via Rails env config files
8
+ config.webpacker = ActiveSupport::OrderedOptions.new
9
+ config.webpacker.check_yarn_integrity = false
10
+
11
+ # ================================
12
+ # Check Yarn Integrity Initializer
13
+ # ================================
14
+ #
15
+ # development (on by default):
16
+ #
17
+ # to turn off:
18
+ # - edit config/environments/development.rb
19
+ # - add `config.webpacker.check_yarn_integrity = false`
20
+ #
21
+ # production (off by default):
22
+ #
23
+ # to turn on:
24
+ # - edit config/environments/production.rb
25
+ # - add `config.webpacker.check_yarn_integrity = false`
26
+ initializer "webpacker.yarn_check" do |app|
27
+ if File.exist?("yarn.lock") && app.config.webpacker.check_yarn_integrity
28
+ output = `yarn check --integrity 2>&1`
29
+
30
+ unless $?.success?
31
+ warn "\n\n"
32
+ warn "========================================"
33
+ warn " Your Yarn packages are out of date!"
34
+ warn " Please run `yarn install` to update."
35
+ warn "========================================"
36
+ warn "\n\n"
37
+ warn "To disable this check, please add `config.webpacker.check_yarn_integrity = false`"
38
+ warn "to your Rails development config file (config/environments/development.rb)."
39
+ warn "\n\n"
40
+ warn output
41
+ warn "\n\n"
42
+
43
+ exit(1)
44
+ end
45
+ end
46
+ end
47
+
48
+ initializer "webpacker.proxy" do |app|
49
+ if Rails.env.development?
50
+ app.middleware.insert_before 0,
51
+ Rails::VERSION::MAJOR >= 5 ?
52
+ Webpacker::DevServerProxy : "Webpacker::DevServerProxy", ssl_verify_none: true
53
+ end
54
+ end
55
+
56
+ initializer "webpacker.helper" do
57
+ ActiveSupport.on_load :action_controller do
58
+ ActionController::Base.helper Webpacker::Helper
59
+ end
60
+
61
+ ActiveSupport.on_load :action_view do
62
+ include Webpacker::Helper
63
+ end
64
+ end
65
+
66
+ initializer "webpacker.logger" do
67
+ config.after_initialize do
68
+ if ::Rails.logger.respond_to?(:tagged)
69
+ Webpacker.logger = ::Rails.logger
70
+ else
71
+ Webpacker.logger = ActiveSupport::TaggedLogging.new(::Rails.logger)
72
+ end
73
+ end
74
+ end
75
+
76
+ initializer "webpacker.bootstrap" do
77
+ if defined?(Rails::Server) || defined?(Rails::Console)
78
+ Webpacker.bootstrap
79
+ Spring.after_fork { Webpacker.bootstrap } if defined?(Spring)
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,6 @@
1
+ class Webpacker::RakeTasks
2
+ def self.load!
3
+ tasks_path = File.expand_path("../tasks", __dir__)
4
+ Dir.glob("#{tasks_path}/**/*.rake").sort.each { |ext| load ext }
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+ module Webpacker
2
+ class Runner
3
+ def self.run(argv)
4
+ $stdout.sync = true
5
+
6
+ new(argv).run
7
+ end
8
+
9
+ def initialize(argv)
10
+ @argv = argv
11
+
12
+ @app_path = File.expand_path(".", Dir.pwd)
13
+ @node_modules_path = File.join(@app_path, "node_modules")
14
+ @webpack_config = File.join(@app_path, "config/webpack/#{ENV["NODE_ENV"]}.js")
15
+
16
+ unless File.exist?(@webpack_config)
17
+ $stderr.puts "webpack config #{@webpack_config} not found, please run 'jets webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment."
18
+ exit!
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ module Webpacker
2
+ # Change the version in package.json too, please!
3
+ # Since this fork and branch originally started from rails/webpacker
4
+ # The git tags collide. As a hacky workaround adding 100 to the patch version.
5
+ # Example:
6
+ # webpacker-jets 3.2.100 # added 100 to the patch version
7
+ # webpacker 3.2.0 # original
8
+ VERSION = "3.2.100".freeze
9
+ end
@@ -0,0 +1,15 @@
1
+ require "shellwords"
2
+ require "webpacker/runner"
3
+
4
+ module Webpacker
5
+ class WebpackRunner < Webpacker::Runner
6
+ def run
7
+ env = { "NODE_PATH" => @node_modules_path.shellescape }
8
+ cmd = [ "#{@node_modules_path}/.bin/webpack", "--config", @webpack_config ] + @argv
9
+
10
+ Dir.chdir(@app_path) do
11
+ exec env, *cmd
12
+ end
13
+ end
14
+ end
15
+ end
data/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@rails/webpacker",
3
+ "version": "3.2.0",
4
+ "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
+ "main": "package/index.js",
6
+ "files": [
7
+ "package",
8
+ "lib/install/config/webpacker.yml"
9
+ ],
10
+ "engines": {
11
+ "node": ">=6.0.0",
12
+ "yarn": ">=0.25.2"
13
+ },
14
+ "dependencies": {
15
+ "babel-core": "^6.26.0",
16
+ "babel-loader": "^7.1.2",
17
+ "babel-plugin-syntax-dynamic-import": "^6.18.0",
18
+ "babel-plugin-transform-class-properties": "^6.24.1",
19
+ "babel-plugin-transform-object-rest-spread": "^6.26.0",
20
+ "babel-polyfill": "^6.26.0",
21
+ "babel-preset-env": "^1.6.1",
22
+ "case-sensitive-paths-webpack-plugin": "^2.1.1",
23
+ "compression-webpack-plugin": "^1.0.1",
24
+ "css-loader": "^0.28.7",
25
+ "extract-text-webpack-plugin": "^3.0.2",
26
+ "file-loader": "^1.1.5",
27
+ "glob": "^7.1.2",
28
+ "js-yaml": "^3.10.0",
29
+ "node-sass": "^4.7.2",
30
+ "path-complete-extname": "^0.1.0",
31
+ "postcss-cssnext": "^3.0.2",
32
+ "postcss-import": "^11.0.0",
33
+ "postcss-loader": "^2.0.9",
34
+ "sass-loader": "^6.0.6",
35
+ "style-loader": "^0.19.0",
36
+ "webpack": "^3.10.0",
37
+ "webpack-manifest-plugin": "^1.3.2"
38
+ },
39
+ "devDependencies": {
40
+ "eslint": "^4.13.0",
41
+ "eslint-config-airbnb": "^16.1.0",
42
+ "eslint-plugin-import": "^2.8.0",
43
+ "eslint-plugin-jsx-a11y": "^6.0.2",
44
+ "eslint-plugin-react": "^7.5.1",
45
+ "jest": "^21.2.1"
46
+ },
47
+ "jest": {
48
+ "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
49
+ "roots": [
50
+ "<rootDir>/package"
51
+ ]
52
+ },
53
+ "scripts": {
54
+ "test": "jest",
55
+ "lint": "eslint {package,lib}/"
56
+ },
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/rails/webpacker.git"
60
+ },
61
+ "author": "David Heinemeier Hansson <david@basecamp.com>",
62
+ "license": "MIT",
63
+ "bugs": {
64
+ "url": "https://github.com/rails/webpacker/issues"
65
+ },
66
+ "homepage": "https://github.com/rails/webpacker"
67
+ }
@@ -0,0 +1,74 @@
1
+ /* global test expect, describe, afterAll, beforeEach */
2
+
3
+ // environment.js expects to find config/webpacker.yml and resolved modules from
4
+ // the root of a Rails project
5
+
6
+ const chdirApp = () => process.chdir('test/test_app')
7
+ const chdirCwd = () => process.chdir(process.cwd())
8
+ chdirApp()
9
+
10
+ const { resolve } = require('path')
11
+ const rules = require('../rules')
12
+ const { ConfigList } = require('../config_types')
13
+ const Environment = require('../environment')
14
+
15
+ describe('Environment', () => {
16
+ afterAll(chdirCwd)
17
+
18
+ let environment
19
+
20
+ describe('toWebpackConfig', () => {
21
+ beforeEach(() => {
22
+ environment = new Environment()
23
+ })
24
+
25
+ test('should return entry', () => {
26
+ const config = environment.toWebpackConfig()
27
+ expect(config.entry.application).toEqual(resolve('app', 'javascript', 'packs', 'application.js'))
28
+ })
29
+
30
+ test('should return output', () => {
31
+ const config = environment.toWebpackConfig()
32
+ expect(config.output.filename).toEqual('[name]-[chunkhash].js')
33
+ expect(config.output.chunkFilename).toEqual('[name]-[chunkhash].chunk.js')
34
+ expect(config.output.path).toEqual(resolve('public', 'packs-test'))
35
+ expect(config.output.publicPath).toEqual('/packs-test/')
36
+ })
37
+
38
+ test('should return default loader rules for each file in config/loaders', () => {
39
+ const config = environment.toWebpackConfig()
40
+ const defaultRules = Object.keys(rules)
41
+ const configRules = config.module.rules
42
+
43
+ expect(defaultRules.length).toBeGreaterThan(1)
44
+ expect(configRules.length).toEqual(defaultRules.length)
45
+ })
46
+
47
+ test('should return default plugins', () => {
48
+ const config = environment.toWebpackConfig()
49
+ expect(config.plugins.length).toEqual(4)
50
+ })
51
+
52
+ test('should return default resolveLoader', () => {
53
+ const config = environment.toWebpackConfig()
54
+ expect(config.resolveLoader.modules).toEqual(['node_modules'])
55
+ })
56
+
57
+ test('should return default resolve.modules with additions', () => {
58
+ const config = environment.toWebpackConfig()
59
+ expect(config.resolve.modules).toEqual([
60
+ resolve('app', 'javascript'),
61
+ resolve('app/assets'),
62
+ resolve('/etc/yarn'),
63
+ 'node_modules'
64
+ ])
65
+ })
66
+
67
+ test('returns plugins property as Array', () => {
68
+ const config = environment.toWebpackConfig()
69
+
70
+ expect(config.plugins).toBeInstanceOf(Array)
71
+ expect(config.plugins).not.toBeInstanceOf(ConfigList)
72
+ })
73
+ })
74
+ })
data/package/config.js ADDED
@@ -0,0 +1,34 @@
1
+ const { resolve } = require('path')
2
+ const { safeLoad } = require('js-yaml')
3
+ const { readFileSync } = require('fs')
4
+ const deepMerge = require('./utils/deep_merge')
5
+
6
+ const defaultFilePath = require.resolve('../lib/install/config/webpacker.yml')
7
+ const filePath = resolve('config', 'webpacker.yml')
8
+
9
+ const environment = process.env.NODE_ENV || 'development'
10
+ const defaultConfig = safeLoad(readFileSync(defaultFilePath), 'utf8')[environment]
11
+ const appConfig = safeLoad(readFileSync(filePath), 'utf8')[environment]
12
+ const config = deepMerge(defaultConfig, appConfig)
13
+
14
+ const isBoolean = str => /^true/.test(str) || /^false/.test(str)
15
+
16
+ const fetch = key =>
17
+ (isBoolean(process.env[key]) ? JSON.parse(process.env[key]) : process.env[key])
18
+
19
+ const devServer = (key) => {
20
+ const envValue = fetch(`WEBPACKER_DEV_SERVER_${key.toUpperCase().replace(/_/g, '')}`)
21
+ if (typeof envValue === 'undefined' || envValue === null) return config.dev_server[key]
22
+ return envValue
23
+ }
24
+
25
+ if (config.dev_server) {
26
+ Object.keys(config.dev_server).forEach((key) => {
27
+ config.dev_server[key] = devServer(key)
28
+ })
29
+ }
30
+
31
+ config.outputPath = resolve('public', config.public_output_path)
32
+ config.publicPath = `/${config.public_output_path}/`.replace(/([^:]\/)\/+/g, '$1')
33
+
34
+ module.exports = config
@@ -0,0 +1,123 @@
1
+ /* global test expect */
2
+
3
+ const ConfigList = require('../config_list')
4
+
5
+ test('new', () => {
6
+ const list = new ConfigList()
7
+ expect(list).toBeInstanceOf(ConfigList)
8
+ expect(list).toBeInstanceOf(Array)
9
+ })
10
+
11
+ test('set', () => {
12
+ const list = new ConfigList()
13
+ expect(list.set('key', 'value')).toEqual([{ key: 'key', value: 'value' }])
14
+ })
15
+
16
+ test('get', () => {
17
+ const list = new ConfigList()
18
+ list.append('key', 'value')
19
+ expect(list.get('key')).toEqual('value')
20
+ })
21
+
22
+ test('append', () => {
23
+ const list = new ConfigList()
24
+ list.append('key', 'value')
25
+ expect(list.append('key1', 'value1')).toEqual([
26
+ { key: 'key', value: 'value' },
27
+ { key: 'key1', value: 'value1' }
28
+ ])
29
+ })
30
+
31
+ test('prepend', () => {
32
+ const list = new ConfigList()
33
+ list.append('key', 'value')
34
+ expect(list.prepend('key1', 'value1')).toEqual([
35
+ { key: 'key1', value: 'value1' },
36
+ { key: 'key', value: 'value' }
37
+ ])
38
+ })
39
+
40
+ test('insert without position', () => {
41
+ const list = new ConfigList()
42
+ list.append('key', 'value')
43
+
44
+ expect(list.insert('key1', 'value1')).toEqual([
45
+ { key: 'key', value: 'value' },
46
+ { key: 'key1', value: 'value1' }
47
+ ])
48
+
49
+ expect(list.insert('key2', 'value2')).toEqual([
50
+ { key: 'key', value: 'value' },
51
+ { key: 'key1', value: 'value1' },
52
+ { key: 'key2', value: 'value2' }
53
+ ])
54
+ })
55
+
56
+ test('insert before an item', () => {
57
+ const list = new ConfigList()
58
+ list.append('key', 'value')
59
+ list.append('key1', 'value1')
60
+
61
+ expect(list.insert('key2', 'value2', { before: 'key' })).toEqual([
62
+ { key: 'key2', value: 'value2' },
63
+ { key: 'key', value: 'value' },
64
+ { key: 'key1', value: 'value1' }
65
+ ])
66
+
67
+ expect(list.insert('key3', 'value3', { before: 'key2' })).toEqual([
68
+ { key: 'key3', value: 'value3' },
69
+ { key: 'key2', value: 'value2' },
70
+ { key: 'key', value: 'value' },
71
+ { key: 'key1', value: 'value1' }
72
+ ])
73
+ })
74
+
75
+ test('insert after an item', () => {
76
+ const list = new ConfigList()
77
+ list.append('key', 'value')
78
+ list.append('key1', 'value1')
79
+
80
+ expect(list.insert('key2', 'value2', { after: 'key' })).toEqual([
81
+ { key: 'key', value: 'value' },
82
+ { key: 'key2', value: 'value2' },
83
+ { key: 'key1', value: 'value1' }
84
+ ])
85
+
86
+ expect(list.insert('key3', 'value3', { after: 'key2' })).toEqual([
87
+ { key: 'key', value: 'value' },
88
+ { key: 'key2', value: 'value2' },
89
+ { key: 'key3', value: 'value3' },
90
+ { key: 'key1', value: 'value1' }
91
+ ])
92
+ })
93
+
94
+ test('delete', () => {
95
+ const list = new ConfigList()
96
+ list.append('key', 'value')
97
+ list.append('key1', 'value1')
98
+ expect(list.delete('key')).toEqual([{ key: 'key1', value: 'value1' }])
99
+ expect(list.delete('key1')).toEqual([])
100
+ })
101
+
102
+ test('getIndex', () => {
103
+ const list = new ConfigList()
104
+ list.append('key', 'value')
105
+ list.append('key1', 'value1')
106
+ expect(list.getIndex('key')).toEqual(0)
107
+ expect(list.getIndex('key2')).toEqual(-1)
108
+ expect(() => list.getIndex('key2', true)).toThrow('Item key2 not found')
109
+ })
110
+
111
+ test('values', () => {
112
+ const list = new ConfigList()
113
+ list.append('key', 'value')
114
+ list.append('key1', 'value1')
115
+ expect(list.values()).toEqual(['value', 'value1'])
116
+ })
117
+
118
+ test('keys', () => {
119
+ const list = new ConfigList()
120
+ list.append('key', 'value')
121
+ list.append('key1', 'value1')
122
+ expect(list.keys()).toEqual(['key', 'key1'])
123
+ })