js-routes 1.2.3 → 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/.eslintrc.js +15 -0
  3. data/.gitignore +5 -0
  4. data/.nvmrc +1 -0
  5. data/.travis.yml +46 -15
  6. data/Appraisals +17 -14
  7. data/CHANGELOG.md +212 -0
  8. data/Rakefile +18 -1
  9. data/Readme.md +344 -92
  10. data/VERSION_2_UPGRADE.md +66 -0
  11. data/app/assets/javascripts/js-routes.js.erb +1 -2
  12. data/gemfiles/{rails32.gemfile → rails40_sprockets_2.gemfile} +2 -2
  13. data/gemfiles/rails40_sprockets_3.gemfile +8 -0
  14. data/gemfiles/rails41_sprockets_2.gemfile +8 -0
  15. data/gemfiles/rails41_sprockets_3.gemfile +8 -0
  16. data/gemfiles/{rails41.gemfile → rails42_sprockets_2.gemfile} +2 -2
  17. data/gemfiles/{rails41_sprockets3.gemfile → rails42_sprockets_3.gemfile} +1 -1
  18. data/gemfiles/{rails42_sprockets3.gemfile → rails50_sprockets_3.gemfile} +1 -1
  19. data/gemfiles/{rails40_sprockets3.gemfile → rails51_sprockets_3.gemfile} +1 -1
  20. data/gemfiles/{rails40.gemfile → rails52_sprockets_3.gemfile} +2 -2
  21. data/js-routes.gemspec +11 -11
  22. data/lib/js_routes/configuration.rb +111 -0
  23. data/lib/js_routes/engine.rb +56 -11
  24. data/lib/js_routes/generators/middleware.rb +58 -0
  25. data/lib/js_routes/generators/webpacker.rb +32 -0
  26. data/lib/js_routes/instance.rb +173 -0
  27. data/lib/js_routes/middleware.rb +40 -0
  28. data/lib/js_routes/route.rb +172 -0
  29. data/lib/js_routes/version.rb +2 -2
  30. data/lib/js_routes.rb +24 -240
  31. data/lib/routes.d.ts +79 -0
  32. data/lib/routes.js +496 -403
  33. data/lib/routes.ts +726 -0
  34. data/lib/tasks/js_routes.rake +8 -2
  35. data/lib/templates/erb.js +11 -0
  36. data/lib/templates/initializer.rb +5 -0
  37. data/lib/templates/routes.js.erb +1 -0
  38. data/package.json +37 -0
  39. data/spec/dummy/app/assets/config/manifest.js +2 -0
  40. data/spec/js_routes/default_serializer_spec.rb +22 -4
  41. data/spec/js_routes/module_types/amd_spec.rb +35 -0
  42. data/spec/js_routes/module_types/cjs_spec.rb +15 -0
  43. data/spec/js_routes/module_types/dts/routes.spec.d.ts +114 -0
  44. data/spec/js_routes/module_types/dts/test.spec.ts +56 -0
  45. data/spec/js_routes/module_types/dts_spec.rb +111 -0
  46. data/spec/js_routes/module_types/esm_spec.rb +45 -0
  47. data/spec/js_routes/module_types/nil_spec.rb +87 -0
  48. data/spec/js_routes/module_types/umd_spec.rb +85 -0
  49. data/spec/js_routes/options_spec.rb +226 -195
  50. data/spec/js_routes/rails_routes_compatibility_spec.rb +259 -108
  51. data/spec/js_routes/route_specification_spec.rb +40 -0
  52. data/spec/js_routes/zzz_last_post_rails_init_spec.rb +19 -8
  53. data/spec/spec_helper.rb +61 -107
  54. data/spec/support/routes.rb +81 -0
  55. data/spec/tsconfig.json +4 -0
  56. data/tsconfig.json +28 -0
  57. data/yarn.lock +2145 -0
  58. metadata +63 -38
  59. data/Guardfile +0 -3
  60. data/gemfiles/rails42.gemfile +0 -8
  61. data/lib/routes.js.coffee +0 -331
  62. data/spec/js_routes/amd_compatibility_spec.rb +0 -42
  63. data/spec/js_routes/generated_javascript_spec.rb +0 -87
  64. data/temp +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 55daff16f999cf2dfd6cfdbbe241e6c2cbbb7fbf
4
- data.tar.gz: c6e9c73edbaf8f95667565114d844b7fc92788c4
2
+ SHA256:
3
+ metadata.gz: 66ff94f5c78d966f76e2a9f47d1c838c757c3e243c37f03599b24c286b15b9b7
4
+ data.tar.gz: c5803e4a35b99923769970149f07a6893a84c6343f10f76c8a89645974dce959
5
5
  SHA512:
6
- metadata.gz: 50876af1368b52bdabdd1cb4b2f6f85a2c1121c98f24aa0d6f415152edeadf127981f804d6cf2d3b72eff7d8f9cbff3056caa6529b5f3dfd435638fc1ac564c1
7
- data.tar.gz: 6dfded8fd06823e2140020c541ce138525bde7c2e7fe6bdfd6b00d2f891069ecc94421fc2a283a8e21cd56e834febbdbb639a7a8afaaebc936274887da39a57c
6
+ metadata.gz: a34c75f950a02a6634687889e4072f7d88f37520a6dc2ba5bfd2ccbbb71962159a70170bf7ac55b22db45de2727f7c573dfce8c80debc33f34abbd9cb1132c1f
7
+ data.tar.gz: 779b340c9dac721c8b427a16011ed961a05dde4d15594838649fb0860bac42e60344a682718a0b94f35f785350126ca59c7f739dac43cb47e0a7b84e45fa468a
data/.eslintrc.js ADDED
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: [
4
+ 'eslint:recommended',
5
+ 'plugin:@typescript-eslint/eslint-recommended',
6
+ 'plugin:@typescript-eslint/recommended',
7
+ 'prettier/@typescript-eslint',
8
+ ],
9
+ parser: '@typescript-eslint/parser',
10
+ plugins: ['@typescript-eslint'],
11
+ rules: {
12
+ '@typescript-eslint/ban-types': 'off',
13
+ '@typescript-eslint/no-explicit-any': 'off'
14
+ },
15
+ };
data/.gitignore CHANGED
@@ -14,6 +14,9 @@ log
14
14
 
15
15
  # jeweler generated
16
16
  pkg
17
+ tmp
18
+
19
+ node_modules
17
20
 
18
21
  # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
22
  #
@@ -58,3 +61,5 @@ gemfiles/*.lock
58
61
  /spec/dummy/app/assets/javascripts/routes.js
59
62
  /spec/dummy/logs
60
63
  /spec/dummy/tmp
64
+ node_modules
65
+
data/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 14
data/.travis.yml CHANGED
@@ -1,25 +1,31 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
 
4
+ before_install:
5
+ - gem install bundler # need for jruby and ruby-head
6
+
4
7
  rvm:
5
- - 1.9.3
6
- - 2.0
7
- - 2.1
8
- - 2.2
9
- - jruby-19mode
8
+ - 2.4.1
9
+ - 2.5.3
10
+ - 2.6.0
10
11
  - ruby-head
11
- - jruby-head
12
+ - jruby
12
13
 
13
14
  gemfile:
14
- - gemfiles/rails32.gemfile
15
- - gemfiles/rails40.gemfile
16
- - gemfiles/rails40_sprockets3.gemfile
17
- - gemfiles/rails41.gemfile
18
- - gemfiles/rails41_sprockets3.gemfile
19
- - gemfiles/rails42.gemfile
20
- - gemfiles/rails42_sprockets3.gemfile
15
+ - gemfiles/rails40_sprockets_2.gemfile
16
+ - gemfiles/rails40_sprockets_3.gemfile
17
+ - gemfiles/rails41_sprockets_2.gemfile
18
+ - gemfiles/rails41_sprockets_3.gemfile
19
+ - gemfiles/rails42_sprockets_2.gemfile
20
+ - gemfiles/rails42_sprockets_3.gemfile
21
+ - gemfiles/rails50_sprockets_3.gemfile
22
+ - gemfiles/rails51_sprockets_3.gemfile
23
+ - gemfiles/rails52_sprockets_3.gemfile
24
+ env:
25
+ TRAVIS_CI: true
21
26
 
22
27
  sudo: false
28
+ dist: xenial
23
29
 
24
30
  notifications:
25
31
  email:
@@ -30,7 +36,32 @@ branches:
30
36
  - master
31
37
 
32
38
  matrix:
39
+ fast_finish: true
33
40
  allow_failures:
34
- - rvm: jruby-19mode
35
41
  - rvm: ruby-head
36
- - rvm: jruby-head
42
+ - rvm: jruby
43
+ exclude:
44
+ - rvm: 2.6.0
45
+ gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault
46
+ - rvm: 2.6.0
47
+ gemfile: gemfiles/rails40_sprockets_3.gemfile # Segmentation fault
48
+ - rvm: 2.6.0
49
+ gemfile: gemfiles/rails41_sprockets_2.gemfile # Segmentation fault
50
+ - rvm: 2.6.0
51
+ gemfile: gemfiles/rails41_sprockets_3.gemfile # Segmentation fault
52
+ - rvm: 2.5.3
53
+ gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault
54
+ - rvm: 2.5.3
55
+ gemfile: gemfiles/rails40_sprockets_3.gemfile # Segmentation fault
56
+ - rvm: 2.5.3
57
+ gemfile: gemfiles/rails41_sprockets_2.gemfile # Segmentation fault
58
+ - rvm: 2.5.3
59
+ gemfile: gemfiles/rails41_sprockets_3.gemfile # Segmentation fault
60
+ - rvm: 2.4.1
61
+ gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault
62
+ - rvm: 2.4.1
63
+ gemfile: gemfiles/rails40_sprockets_3.gemfile # Segmentation fault
64
+ - rvm: 2.4.1
65
+ gemfile: gemfiles/rails41_sprockets_2.gemfile # Segmentation fault
66
+ - rvm: 2.4.1
67
+ gemfile: gemfiles/rails41_sprockets_3.gemfile # Segmentation fault
data/Appraisals CHANGED
@@ -1,16 +1,19 @@
1
- appraise "rails32" do
2
- gem "railties", "~> 3.2.18"
3
- gem 'tzinfo'
4
- end
5
-
6
- {rails40: '4.0.5', rails41: '4.1.1', rails42: '4.2.1'}.each do |rails, version|
7
- appraise "#{rails}" do
8
- gem "railties", "~> #{version}"
9
- gem "sprockets", "< 3"
1
+ def define_appraisal(rails, version, sprockets)
2
+ sprockets.each do |sprocket|
3
+ appraise "#{rails}-sprockets-#{sprocket}" do
4
+ gem "railties", "~> #{version}"
5
+ gem "sprockets", "~> #{sprocket}.0"
6
+ end
10
7
  end
8
+ end
11
9
 
12
- appraise "#{rails}-sprockets3" do
13
- gem "railties", "~> #{version}"
14
- gem "sprockets", "~> 3.0"
15
- end
16
- end
10
+ [
11
+ [:rails40, '4.0.13', [2, 3]],
12
+ [:rails41, '4.1.16', [2, 3]],
13
+ [:rails42, '4.2.9', [2, 3]],
14
+ [:rails50, '5.0.5', [3]],
15
+ [:rails51, '5.1.3', [3]],
16
+ [:rails52, '5.2.3', [3]]
17
+ ].each do |name, version, sprockets|
18
+ define_appraisal(name, version, sprockets)
19
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,217 @@
1
1
  ## master
2
2
 
3
+ ## v2.2.5
4
+
5
+ * Fix middleware generator [#300](https://github.com/railsware/js-routes/issues/300)
6
+ * Support `params` special parameter
7
+
8
+ ## v2.2.4
9
+
10
+ * Fix rails engine loading if sprockets is not in Gemfile. Fixes [#294](https://github.com/railsware/js-routes/issues/294)
11
+
12
+ ## v2.2.3
13
+
14
+ * Fixed NIL module type namespace defintion [#297](https://github.com/railsware/js-routes/issues/297).
15
+ * The patch may cause a problem with nested `namespace` option
16
+ * Ex. Value like `MyProject.Routes` requires to define `window.MyProject` before importing the routes file
17
+
18
+ ## v2.2.2.
19
+
20
+ * Fix custom file path [#295](https://github.com/railsware/js-routes/issues/295)
21
+
22
+ ## v2.2.1
23
+
24
+ * Improve generator to update route files on `assets:precompile` and add them to `.gitignore by default` [#288](https://github.com/railsware/js-routes/issues/288#issuecomment-1012182815)
25
+
26
+ ## v2.2.0
27
+
28
+ * Use Rack Middleware to automatically update routes file in development [#288](https://github.com/railsware/js-routes/issues/288)
29
+ * This setup is now a default recommended due to lack of any downside comparing to [ERB Loader](./Readme.md#webpacker) and [Manual Setup](./Readme.md#advanced-setup)
30
+
31
+ ## v2.1.3
32
+
33
+ * Fix `default_url_options` bug. [#290](https://github.com/railsware/js-routes/issues/290)
34
+
35
+ ## v2.1.2
36
+
37
+ * Improve browser window object detection. [#287](https://github.com/railsware/js-routes/issues/287)
38
+
39
+ ## v2.1.1
40
+
41
+ * Added webpacker generator `./bin/rails generate js_routes:webpacker`
42
+ * Reorganized Readme to describe different setups with their pros and cons more clearly
43
+
44
+ ## v2.1.0
45
+
46
+ * Support typescript defintions file aka `routes.d.ts`. See [Readme.md](./Readme.md#definitions) for more information.
47
+
48
+ ## v2.0.8
49
+
50
+ * Forbid usage of `namespace` option if `module_type` is not `nil`. [#281](https://github.com/railsware/js-routes/issues/281).
51
+
52
+ ## v2.0.7
53
+
54
+ * Remove source map annotation from JS file. Fixes [#277](https://github.com/railsware/js-routes/issues/277)
55
+ * Generated file is not minified, so it is better to use app side bundler/compressor for source maps
56
+
57
+
58
+ ## v2.0.6
59
+
60
+ * Disable `namespace` option default for all envs [#278](https://github.com/railsware/js-routes/issues/278)
61
+
62
+ ## v2.0.5
63
+
64
+ * Fixed backward compatibility issue [#276](https://github.com/railsware/js-routes/issues/276)
65
+
66
+ ## v2.0.4
67
+
68
+ * Fixed backward compatibility issue [#275](https://github.com/railsware/js-routes/issues/275)
69
+
70
+ ## v2.0.3
71
+
72
+ * Fixed backward compatibility issue [#275](https://github.com/railsware/js-routes/issues/275)
73
+
74
+ ## v2.0.2
75
+
76
+ * Fixed backward compatibility issue [#274](https://github.com/railsware/js-routes/issues/274)
77
+
78
+ ## v2.0.1
79
+
80
+ * Fixed backward compatibility issue [#272](https://github.com/railsware/js-routes/issues/272)
81
+
82
+ ## v2.0.0
83
+
84
+ Version 2.0 has some breaking changes.
85
+ See [UPGRADE TO 2.0](./VERSION_2_UPGRADE.md) for guidance.
86
+
87
+ * `module_type` option support
88
+ * `documentation` option spport
89
+ * Migrated implementation to typescript
90
+ * ESM tree shaking support
91
+ * Support camel case `toParam` version of `to_param` property
92
+
93
+ ## v1.4.14
94
+
95
+ * Fix compatibility with UMD modules #237 [Comment](https://github.com/railsware/js-routes/issues/237#issuecomment-752754679)
96
+
97
+ ## v1.4.13
98
+
99
+ * Improve compatibility with node environment #269.
100
+ * Change default file location configuration to Webpacker if both Webpacker and Sprockets are loaded
101
+
102
+ ## v1.4.11
103
+
104
+ * Use app/javascript/routes.js as a default file location if app/javascript directory exists
105
+ * Add `default` export for better experience when used as es6 module
106
+
107
+ ## v1.4.10
108
+
109
+ * Require engine only when sprockets is loaded #257.
110
+
111
+ ## v1.4.9
112
+
113
+ * Allow to specify null namespace and receive routes as an object without assigning it anywhere #247
114
+
115
+ ## v1.4.7
116
+
117
+ * Fix a LocalJumpError on secondary initialization of the app #248
118
+
119
+ ## v1.4.6
120
+
121
+ * Fix regression of #244 in #243
122
+
123
+ ## v1.4.5
124
+
125
+ * Fix escaping inside route parameters and globbing #244
126
+
127
+ ## v1.4.4
128
+
129
+ * More informative stack trace for ParameterMissing error #235
130
+
131
+ ## v1.4.3
132
+
133
+ * Proper implementation of the :subdomain option in routes generation
134
+
135
+ ## v1.4.2
136
+
137
+ * Added JsRoutes namespace to Engine #230
138
+
139
+ ## v1.4.1
140
+
141
+ * Fixed bug when js-routes is used in envs without window.location #224
142
+
143
+
144
+ ## v1.4.0
145
+
146
+ * __breaking change!__ Implemented Routes.config() and Routes.configure instead of Routes.defaults
147
+
148
+ New methods support 4 options at the moment:
149
+
150
+ ``` js
151
+ Routes.configuration(); // =>
152
+ /*
153
+ {
154
+ prefix: "",
155
+ default_url_options: {},
156
+ special_options_key: '_options',
157
+ serializer: function(...) { ... }
158
+ }
159
+ */
160
+
161
+ Routes.configure({
162
+ prefix: '/app',
163
+ default_url_options: {format: 'json'},
164
+ special_options_key: '_my_options_key',
165
+ serializer: function(...) { ... }
166
+ });
167
+ ```
168
+
169
+ ## v1.3.3
170
+
171
+ * Improved optional parameters support #216
172
+
173
+ ## v1.3.2
174
+
175
+ * Added `application` option #214
176
+
177
+ ## v1.3.1
178
+
179
+ * Raise error object with id null passed as route paramter #209
180
+ * Sprockets bugfixes #212
181
+
182
+ ## v1.3.0
183
+
184
+ * Introduce the special _options key. Fixes #86
185
+
186
+ ## v1.2.9
187
+
188
+ * Fixed deprecation varning on Sprockets 3.7
189
+
190
+ ## v1.2.8
191
+
192
+ * Bugfix warning on Sprockets 4.0 #202
193
+
194
+ ## v1.2.7
195
+
196
+ * Drop support 1.9.3
197
+ * Add helper for indexOf, if no native implementation in JS engine
198
+ * Add sprockets3 compatibility
199
+ * Bugfix domain defaults to path #197
200
+
201
+ ## v1.2.6
202
+
203
+ * Use default prefix from `Rails.application.config.relative_url_root` #186
204
+ * Bugfix route globbing with optional fragments bug #191
205
+
206
+ ## v1.2.5
207
+
208
+ * Bugfix subdomain default parameter in routes #184
209
+ * Bugfix infinite recursion in some specific route sets #183
210
+
211
+ ## v1.2.4
212
+
213
+ * Additional bugfixes to support all versions of Sprockets: 2.x and 3.x
214
+
3
215
  ## v1.2.3
4
216
 
5
217
  * Sprockets ~= 3.0 support
data/Rakefile CHANGED
@@ -12,9 +12,26 @@ require 'bundler/gem_tasks'
12
12
  require 'rspec/core'
13
13
  require 'rspec/core/rake_task'
14
14
  require 'appraisal'
15
+ require 'rails/version'
16
+ if Rails.version < "6.1"
17
+ load "rails/tasks/routes.rake"
18
+ end
15
19
 
16
20
  RSpec::Core::RakeTask.new(:spec)
17
21
 
18
22
  task :test_all => :appraisal # test all rails
19
23
 
20
- task :default => :spec
24
+ task :default => :spec
25
+
26
+
27
+ namespace :spec do
28
+ desc "Print all routes defined in test env"
29
+ task :routes do
30
+ require './spec/spec_helper'
31
+ require 'action_dispatch/routing/inspector'
32
+ draw_routes
33
+ all_routes = Rails.application.routes.routes
34
+ inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
35
+ puts inspector.format(ActionDispatch::Routing::ConsoleFormatter::Sheet.new)
36
+ end
37
+ end