js-routes 2.2.4 → 2.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.github/workflows/ci.yml +36 -0
  4. data/Appraisals +2 -4
  5. data/CHANGELOG.md +6 -0
  6. data/Readme.md +54 -46
  7. data/gemfiles/rails50_sprockets_3.gemfile +1 -1
  8. data/gemfiles/rails51_sprockets_3.gemfile +1 -1
  9. data/gemfiles/rails52_sprockets_3.gemfile +1 -1
  10. data/gemfiles/rails70_sprockets_4.gemfile +8 -0
  11. data/lib/js_routes/engine.rb +6 -1
  12. data/lib/js_routes/generators/base.rb +16 -0
  13. data/lib/js_routes/generators/middleware.rb +9 -8
  14. data/lib/js_routes/generators/webpacker.rb +3 -1
  15. data/lib/js_routes/instance.rb +1 -1
  16. data/lib/js_routes/version.rb +1 -1
  17. data/lib/routes.d.ts +1 -0
  18. data/lib/routes.js +10 -3
  19. data/lib/routes.ts +22 -15
  20. data/package.json +7 -6
  21. data/spec/js_routes/default_serializer_spec.rb +1 -1
  22. data/spec/js_routes/module_types/amd_spec.rb +2 -2
  23. data/spec/js_routes/module_types/dts/routes.spec.d.ts +1 -0
  24. data/spec/js_routes/module_types/dts_spec.rb +1 -1
  25. data/spec/js_routes/module_types/umd_spec.rb +1 -1
  26. data/spec/js_routes/options_spec.rb +2 -2
  27. data/spec/js_routes/rails_routes_compatibility_spec.rb +4 -2
  28. data/spec/js_routes/route_specification_spec.rb +1 -1
  29. data/spec/js_routes/zzz_last_post_rails_init_spec.rb +8 -2
  30. data/spec/spec_helper.rb +1 -5
  31. data/yarn.lock +760 -448
  32. metadata +6 -10
  33. data/.travis.yml +0 -67
  34. data/gemfiles/rails40_sprockets_2.gemfile +0 -8
  35. data/gemfiles/rails40_sprockets_3.gemfile +0 -8
  36. data/gemfiles/rails41_sprockets_2.gemfile +0 -8
  37. data/gemfiles/rails41_sprockets_3.gemfile +0 -8
  38. data/gemfiles/rails42_sprockets_2.gemfile +0 -8
  39. data/gemfiles/rails42_sprockets_3.gemfile +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66ff94f5c78d966f76e2a9f47d1c838c757c3e243c37f03599b24c286b15b9b7
4
- data.tar.gz: c5803e4a35b99923769970149f07a6893a84c6343f10f76c8a89645974dce959
3
+ metadata.gz: 55d34a6a511e250d1fc59aa2e868a3148734bc6fafc6f156ff86eea1f0d6f81e
4
+ data.tar.gz: 94143965ae4a2a14db535dd484521c3348c18eee2ca6f61ee72186e908cdc786
5
5
  SHA512:
6
- metadata.gz: a34c75f950a02a6634687889e4072f7d88f37520a6dc2ba5bfd2ccbbb71962159a70170bf7ac55b22db45de2727f7c573dfce8c80debc33f34abbd9cb1132c1f
7
- data.tar.gz: 779b340c9dac721c8b427a16011ed961a05dde4d15594838649fb0860bac42e60344a682718a0b94f35f785350126ca59c7f739dac43cb47e0a7b84e45fa468a
6
+ metadata.gz: d727f254cec5e5269e92ef1180309aacb3362fc4aa8065c2fb604237d9096918c1e0ab534b7b443df656fb5218962e949522ce3338b4be9d99e17d0268f6efbb
7
+ data.tar.gz: 9ce12dc8aefab9a646aadc2318e541f6b422fc9340856e69488889374727c7de7f7e70fa8fbe510263b9d7f5edf2097657ae62fac0a90d0206b9b2be5481b48a
data/.eslintrc.js CHANGED
@@ -4,7 +4,7 @@
4
4
  'eslint:recommended',
5
5
  'plugin:@typescript-eslint/eslint-recommended',
6
6
  'plugin:@typescript-eslint/recommended',
7
- 'prettier/@typescript-eslint',
7
+ 'prettier',
8
8
  ],
9
9
  parser: '@typescript-eslint/parser',
10
10
  plugins: ['@typescript-eslint'],
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby: ["2.7"]
15
+ gemfile:
16
+ - gemfiles/rails50_sprockets_3.gemfile
17
+ - gemfiles/rails51_sprockets_3.gemfile
18
+ - gemfiles/rails52_sprockets_3.gemfile
19
+ - gemfiles/rails70_sprockets_4.gemfile
20
+
21
+ env:
22
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ - uses: actions/setup-node@v3
29
+ with:
30
+ node-version: "16"
31
+ - name: install dependencies
32
+ run: |
33
+ bundle install --jobs 3 --retry 3
34
+ yarn install
35
+ - name: test
36
+ run: bundle exec rake spec
data/Appraisals CHANGED
@@ -8,12 +8,10 @@ def define_appraisal(rails, version, sprockets)
8
8
  end
9
9
 
10
10
  [
11
- [:rails40, '4.0.13', [2, 3]],
12
- [:rails41, '4.1.16', [2, 3]],
13
- [:rails42, '4.2.9', [2, 3]],
14
11
  [:rails50, '5.0.5', [3]],
15
12
  [:rails51, '5.1.3', [3]],
16
- [:rails52, '5.2.3', [3]]
13
+ [:rails52, '5.2.3', [3]],
14
+ [:rails70, '7.0.3.1', [4]]
17
15
  ].each do |name, version, sprockets|
18
16
  define_appraisal(name, version, sprockets)
19
17
  end
data/CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
1
  ## master
2
2
 
3
+ ## v2.2.6
4
+
5
+ * Prefer to extend `javascript:build` instead of `assets:precompile`. [#305](https://github.com/railsware/js-routes/issues/305)
6
+ * Add stimulus framework application.js location to generators
7
+
3
8
  ## v2.2.5
4
9
 
10
+ * Upgraded eslint and prettier versions [#304](https://github.com/railsware/js-routes/issues/304)
5
11
  * Fix middleware generator [#300](https://github.com/railsware/js-routes/issues/300)
6
12
  * Support `params` special parameter
7
13
 
data/Readme.md CHANGED
@@ -1,10 +1,8 @@
1
1
  # JsRoutes
2
- [![Build Status](https://travis-ci.org/railsware/js-routes.svg?branch=master)](https://travis-ci.org/railsware/js-routes)
3
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes?ref=badge_shield)
4
2
 
5
- Generates javascript file that defines all Rails named routes as javascript helpers
3
+ [![CI](https://github.com/railsware/js-routes/actions/workflows/ci.yml/badge.svg)](https://github.com/railsware/js-routes/actions/workflows/ci.yml)
6
4
 
7
- [UPGRADE TO 2.0](./VERSION_2_UPGRADE.md)
5
+ Generates javascript file that defines all Rails named routes as javascript helpers
8
6
 
9
7
  ## Intallation
10
8
 
@@ -54,20 +52,21 @@ Add the following to `config/environments/development.rb`:
54
52
  config.middleware.use(JsRoutes::Middleware)
55
53
  ```
56
54
 
57
- Use it in `app/javascript/packs/application.js`:
55
+ Use it in any JS file:
58
56
 
59
57
  ``` javascript
60
- import * as Routes from '../routes';
61
- // window.Routes = Routes;
62
- alert(Routes.post_path(1))
58
+ import {post_path} from '../routes';
59
+
60
+ alert(post_path(1))
63
61
  ```
64
62
 
65
- Upgrade `rake assets:precompile` to update js-routes files in `Rakefile`:
63
+ Upgrade js building process to update js-routes files in `Rakefile`:
66
64
 
67
65
  ``` ruby
68
- namespace :assets do
69
- task :precompile => "js:routes:typescript"
70
- end
66
+ task "javascript:build" => "js:routes:typescript"
67
+ # For setups without jsbundling-rails
68
+ task "assets:precompile" => "js:routes:typescript"
69
+
71
70
  ```
72
71
 
73
72
  Add js-routes files to `.gitignore`:
@@ -133,11 +132,12 @@ Create routes file `app/javascript/routes.js.erb`:
133
132
  <%= JsRoutes.generate() %>
134
133
  ```
135
134
 
136
- Use routes wherever you need them `app/javascript/packs/application.js`:
135
+ Use routes wherever you need them:
137
136
 
138
137
  ``` javascript
139
- import * as Routes from 'routes.js.erb';
140
- window.Routes = Routes;
138
+ import {post_path} from 'routes.js.erb';
139
+
140
+ alert(post_path(2));
141
141
  ```
142
142
 
143
143
  <div id='advanced-setup'></div>
@@ -175,14 +175,20 @@ You can manipulate the generated helper manually by injecting ruby into javascri
175
175
  export const routes = <%= JsRoutes.generate(module_type: nil, namespace: nil) %>
176
176
  ```
177
177
 
178
- If you want to generate the routes files outside of the asset pipeline, you can use `JsRoutes.generate!`:
178
+ If you want to generate the routes files manually with custom options, you can use `JsRoutes.generate!`:
179
179
 
180
180
  ``` ruby
181
181
  path = Rails.root.join("app/javascript")
182
182
 
183
- JsRoutes.generate!("#{path}/app_routes.js", exclude: [/^admin_/, /^api_/])
184
- JsRoutes.generate!("#{path}/adm_routes.js", include: /^admin_/)
185
- JsRoutes.generate!("#{path}/api_routes.js", include: /^api_/, default_url_options: {format: "json"})
183
+ JsRoutes.generate!(
184
+ "#{path}/app_routes.js", exclude: [/^admin_/, /^api_/]
185
+ )
186
+ JsRoutes.generate!(
187
+ "#{path}/adm_routes.js", include: /^admin_/
188
+ )
189
+ JsRoutes.generate!(
190
+ "#{path}/api_routes.js", include: /^api_/, default_url_options: {format: "json"}
191
+ )
186
192
  ```
187
193
 
188
194
  <div id='definitions'></div>
@@ -252,11 +258,12 @@ end
252
258
  Or dynamically in JavaScript, although only [Formatter Options](#formatter-options) are supported:
253
259
 
254
260
  ``` js
255
- import * as Routes from 'routes'
256
- Routes.configure({
261
+ import {configure, config} from 'routes'
262
+
263
+ configure({
257
264
  option: value
258
265
  });
259
- Routes.config(); // current config
266
+ config(); // current config
260
267
  ```
261
268
 
262
269
  ### Available Options
@@ -290,7 +297,7 @@ Options to configure JavaScript file generator. These options are only available
290
297
  * Note: generated URLs will first use the protocol, host, and port options specified in the route definition. Otherwise, the URL will be based on the option specified in the `default_url_options` config. If no default option has been set, then the URL will fallback to the current URL based on `window.location`.
291
298
  * `compact` - Remove `_path` suffix in path routes(`*_url` routes stay untouched if they were enabled)
292
299
  * Default: `false`
293
- * Sample route call when option is set to true: Routes.users() => `/users`
300
+ * Sample route call when option is set to true: `users() // => /users`
294
301
  * `application` - a key to specify which rails engine you want to generate routes too.
295
302
  * This option allows to only generate routes for a specific rails engine, that is mounted into routes instead of all Rails app routes
296
303
  * Default: `Rails.application`
@@ -323,41 +330,44 @@ Options to configure routes formatting. These options are available both in Ruby
323
330
  Configuration above will create a nice javascript file with `Routes` object that has all the rails routes available:
324
331
 
325
332
  ``` js
326
- import * as Routes from 'routes';
333
+ import {
334
+ user_path, user_project_path, company_path
335
+ } as Routes from 'routes';
327
336
 
328
- Routes.users_path()
337
+ users_path()
329
338
  // => "/users"
330
339
 
331
- Routes.user_path(1)
340
+ user_path(1)
332
341
  // => "/users/1"
333
342
 
334
- Routes.user_path(1, {format: 'json'})
343
+ user_path(1, {format: 'json'})
335
344
  // => "/users/1.json"
336
345
 
337
- Routes.user_path(1, {anchor: 'profile'})
346
+ user_path(1, {anchor: 'profile'})
338
347
  // => "/users/1#profile"
339
348
 
340
- Routes.new_user_project_path(1, {format: 'json'})
349
+ new_user_project_path(1, {format: 'json'})
341
350
  // => "/users/1/projects/new.json"
342
351
 
343
- Routes.user_project_path(1,2, {q: 'hello', custom: true})
352
+ user_project_path(1,2, {q: 'hello', custom: true})
344
353
  // => "/users/1/projects/2?q=hello&custom=true"
345
354
 
346
- Routes.user_project_path(1,2, {hello: ['world', 'mars']})
355
+ user_project_path(1,2, {hello: ['world', 'mars']})
347
356
  // => "/users/1/projects/2?hello%5B%5D=world&hello%5B%5D=mars"
348
357
 
349
358
  var google = {id: 1, name: "Google"};
350
- Routes.company_path(google)
359
+ company_path(google)
351
360
  // => "/companies/1"
352
361
 
353
362
  var google = {id: 1, name: "Google", to_param: "google"};
354
- Routes.company_path(google)
363
+ company_path(google)
355
364
  // => "/companies/google"
356
365
  ```
357
366
 
358
367
  In order to make routes helpers available globally:
359
368
 
360
369
  ``` js
370
+ import * as Routes from '../routes';
361
371
  jQuery.extend(window, Routes)
362
372
  ```
363
373
 
@@ -366,22 +376,18 @@ jQuery.extend(window, Routes)
366
376
  Possible to get `spec` of route by function `toString`:
367
377
 
368
378
  ```js
369
- Routes.users_path.toString() // => "/users(.:format)"
370
- Routes.user_path.toString() // => "/users/:id(.:format)"
371
- ```
372
-
373
- This function allow to get the same `spec` for route, if you will get string representation of the route function:
379
+ import {user_path, users_path} from '../routes'
374
380
 
375
- ```js
376
- '' + Routes.users_path // => "/users(.:format)", a string representation of the object
377
- '' + Routes.user_path // => "/users/:id(.:format)"
381
+ users_path.toString() // => "/users(.:format)"
382
+ user_path.toString() // => "/users/:id(.:format)"
378
383
  ```
379
384
 
385
+
380
386
  Route function also contain method `requiredParams` inside which returns required param names array:
381
387
 
382
388
  ```js
383
- Routes.users_path.requiredParams() // => []
384
- Routes.user_path.requiredParams() // => ['id']
389
+ users_path.requiredParams() // => []
390
+ user_path.requiredParams() // => ['id']
385
391
  ```
386
392
 
387
393
 
@@ -395,8 +401,10 @@ Sometimes the destinction between JS Hash and Object can not be found by JsRoute
395
401
  In this case you would need to pass a special key to help:
396
402
 
397
403
  ``` js
398
- Routes.company_project_path({company_id: 1, id: 2}) // => Not enough parameters
399
- Routes.company_project_path({company_id: 1, id: 2, _options: true}) // => "/companies/1/projects/2"
404
+ import {company_project_path} from '../routes'
405
+
406
+ company_project_path({company_id: 1, id: 2}) // => Not enough parameters
407
+ company_project_path({company_id: 1, id: 2, _options: true}) // => "/companies/1/projects/2"
400
408
  ```
401
409
 
402
410
 
@@ -417,7 +425,7 @@ import {
417
425
  inbox_message_path,
418
426
  inbox_attachment_path,
419
427
  user_path,
420
- } from 'routes.js.erb'
428
+ } from '../routes'
421
429
  ```
422
430
 
423
431
  Such import structure allows for moddern JS bundlers like [Webpack](https://webpack.js.org/) to only include explicitly imported routes into JS bundle file.
@@ -5,4 +5,4 @@ source "http://rubygems.org"
5
5
  gem "railties", "~> 5.0.5"
6
6
  gem "sprockets", "~> 3.0"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -5,4 +5,4 @@ source "http://rubygems.org"
5
5
  gem "railties", "~> 5.1.3"
6
6
  gem "sprockets", "~> 3.0"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -5,4 +5,4 @@ source "http://rubygems.org"
5
5
  gem "railties", "~> 5.2.3"
6
6
  gem "sprockets", "~> 3.0"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "railties", "~> 7.0.3.1"
6
+ gem "sprockets", "~> 4.0"
7
+
8
+ gemspec path: "../"
@@ -29,7 +29,8 @@ end
29
29
 
30
30
 
31
31
  class Engine < ::Rails::Engine
32
- if defined?(::Sprockets::Railtie)
32
+ def self.install_sprockets!
33
+ return if defined?(@installed_sprockets)
33
34
  require 'sprockets/version'
34
35
  v2 = Gem::Dependency.new('', ' ~> 2')
35
36
  vgte3 = Gem::Dependency.new('', ' >= 3')
@@ -58,6 +59,10 @@ class Engine < ::Rails::Engine
58
59
  raise StandardError, "Sprockets version #{sprockets_version} is not supported"
59
60
  end
60
61
  end
62
+ @installed_sprockets = true
63
+ end
64
+ if defined?(::Sprockets::Railtie)
65
+ install_sprockets!
61
66
  end
62
67
  end
63
68
  end
@@ -0,0 +1,16 @@
1
+
2
+ require "rails/generators"
3
+
4
+ class JsRoutes::Generators::Base < Rails::Generators::Base
5
+
6
+ protected
7
+
8
+ def application_js_path
9
+ [
10
+ "app/javascript/packs/application.js",
11
+ "app/javascript/controllers/application.js",
12
+ ].find do |path|
13
+ File.exists?(Rails.root.join(path))
14
+ end
15
+ end
16
+ end
@@ -1,15 +1,17 @@
1
- require "rails/generators"
1
+ require "js_routes/generators/base"
2
2
 
3
- class JsRoutes::Generators::Middleware < Rails::Generators::Base
3
+ class JsRoutes::Generators::Middleware < JsRoutes::Generators::Base
4
4
 
5
5
  source_root File.expand_path(__FILE__ + "/../../../templates")
6
6
 
7
7
  def create_middleware
8
8
  copy_file "initializer.rb", "config/initializers/js_routes.rb"
9
- inject_into_file "app/javascript/packs/application.js", pack_content
10
9
  inject_into_file "config/environments/development.rb", middleware_content, before: /^end\n\z/
11
10
  inject_into_file "Rakefile", rakefile_content
12
11
  inject_into_file ".gitignore", gitignore_content
12
+ if path = application_js_path
13
+ inject_into_file path, pack_content
14
+ end
13
15
  JsRoutes.generate!
14
16
  JsRoutes.definitions!
15
17
  end
@@ -33,12 +35,11 @@ window.Routes = Routes;
33
35
  end
34
36
 
35
37
  def rakefile_content
38
+ enhanced_task = Bundler.load.gems.find {|g| g.name = 'jsbundling-rails'} ?
39
+ "javascript:build" : "assets:precompile"
36
40
  <<-RB
37
-
38
- # Update js-routes file before assets precompile
39
- namespace :assets do
40
- task :precompile => "js:routes:typescript"
41
- end
41
+ # Update js-routes file before javascript build
42
+ task "#{enhanced_task}" => "js:routes:typescript"
42
43
  RB
43
44
  end
44
45
 
@@ -9,7 +9,9 @@ class JsRoutes::Generators::Webpacker < Rails::Generators::Base
9
9
  copy_file "erb.js", "config/webpack/loaders/erb.js"
10
10
  copy_file "routes.js.erb", "app/javascript/routes.js.erb"
11
11
  inject_into_file "config/webpack/environment.js", loader_content
12
- inject_into_file "app/javascript/packs/application.js", pack_content
12
+ if path = application_js_path
13
+ inject_into_file path, pack_content
14
+ end
13
15
  command = Rails.root.join("./bin/yarn add rails-erb-loader")
14
16
  run command
15
17
  end
@@ -55,7 +55,7 @@ module JsRoutes
55
55
  'ROUTES_OBJECT' => routes_object,
56
56
  'RAILS_VERSION' => ActionPack.version,
57
57
  'DEPRECATED_GLOBBING_BEHAVIOR' => ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR == 0,
58
-
58
+ 'DEPRECATED_FALSE_PARAMETER_BEHAVIOR' => ActionPack::VERSION::MAJOR < 7,
59
59
  'APP_CLASS' => application.class.to_s,
60
60
  'DEFAULT_URL_OPTIONS' => json(@configuration.default_url_options),
61
61
  'PREFIX' => json(@configuration.prefix),
@@ -1,3 +1,3 @@
1
1
  module JsRoutes
2
- VERSION = "2.2.4"
2
+ VERSION = "2.2.6"
3
3
  end
data/lib/routes.d.ts CHANGED
@@ -64,6 +64,7 @@ declare type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
64
64
  declare const RubyVariables: {
65
65
  PREFIX: string;
66
66
  DEPRECATED_GLOBBING_BEHAVIOR: boolean;
67
+ DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
67
68
  SPECIAL_OPTIONS_KEY: string;
68
69
  DEFAULT_URL_OPTIONS: RouteParameters;
69
70
  SERIALIZER: Serializer;
data/lib/routes.js CHANGED
@@ -2,7 +2,10 @@
2
2
  * File generated by js-routes RubyVariables.GEM_VERSION
3
3
  * Based on Rails RubyVariables.RAILS_VERSION routes of RubyVariables.APP_CLASS
4
4
  */
5
- RubyVariables.WRAPPER(() => {
5
+ // eslint-disable-next-line
6
+ RubyVariables.WRAPPER(
7
+ // eslint-disable-next-line
8
+ () => {
6
9
  const hasProp = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
7
10
  let NodeTypes;
8
11
  (function (NodeTypes) {
@@ -176,7 +179,11 @@ RubyVariables.WRAPPER(() => {
176
179
  }
177
180
  path_identifier(object) {
178
181
  const result = this.unwrap_path_identifier(object);
179
- return this.is_nullable(result) || result === false ? "" : "" + result;
182
+ return this.is_nullable(result) ||
183
+ (RubyVariables.DEPRECATED_FALSE_PARAMETER_BEHAVIOR &&
184
+ result === false)
185
+ ? ""
186
+ : "" + result;
180
187
  }
181
188
  unwrap_path_identifier(object) {
182
189
  let result = object;
@@ -262,7 +269,7 @@ RubyVariables.WRAPPER(() => {
262
269
  return { keyword_parameters, query_parameters };
263
270
  }
264
271
  build_route(parts, required_params, default_options, route, absolute, args) {
265
- const { keyword_parameters, query_parameters, } = this.partition_parameters(parts, required_params, default_options, args);
272
+ const { keyword_parameters, query_parameters } = this.partition_parameters(parts, required_params, default_options, args);
266
273
  const missing_params = required_params.filter((param) => !hasProp(query_parameters, param) ||
267
274
  this.is_nullable(query_parameters[param]));
268
275
  if (missing_params.length) {
data/lib/routes.ts CHANGED
@@ -82,6 +82,7 @@ type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
82
82
  declare const RubyVariables: {
83
83
  PREFIX: string;
84
84
  DEPRECATED_GLOBBING_BEHAVIOR: boolean;
85
+ DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
85
86
  SPECIAL_OPTIONS_KEY: string;
86
87
  DEFAULT_URL_OPTIONS: RouteParameters;
87
88
  SERIALIZER: Serializer;
@@ -96,7 +97,9 @@ declare const define:
96
97
 
97
98
  declare const module: { exports: any } | undefined;
98
99
 
100
+ // eslint-disable-next-line
99
101
  RubyVariables.WRAPPER(
102
+ // eslint-disable-next-line
100
103
  (): RouterExposedMethods => {
101
104
  const hasProp = (value: unknown, key: string) =>
102
105
  Object.prototype.hasOwnProperty.call(value, key);
@@ -223,7 +226,7 @@ RubyVariables.WRAPPER(
223
226
  "port",
224
227
  "protocol",
225
228
  ] as const;
226
- type ReservedOption = typeof ReservedOptions[any];
229
+ type ReservedOption = (typeof ReservedOptions)[any];
227
230
 
228
231
  class UtilsClass {
229
232
  configuration: Configuration = {
@@ -234,7 +237,7 @@ RubyVariables.WRAPPER(
234
237
  RubyVariables.SERIALIZER || this.default_serializer.bind(this),
235
238
  };
236
239
 
237
- default_serializer(value: any, prefix?: string | null): string {
240
+ default_serializer(value: unknown, prefix?: string | null): string {
238
241
  if (this.is_nullable(value)) {
239
242
  return "";
240
243
  }
@@ -293,14 +296,16 @@ RubyVariables.WRAPPER(
293
296
  }
294
297
  return {
295
298
  args: args.slice(0, args.length - 1),
296
- options: (last_el as any) as RouteOptions,
299
+ options: last_el as unknown as RouteOptions,
297
300
  };
298
301
  } else {
299
302
  return { args, options: {} };
300
303
  }
301
304
  }
302
305
 
303
- looks_like_serialized_model(object: any): object is ModelRouteParameter {
306
+ looks_like_serialized_model(
307
+ object: unknown
308
+ ): object is ModelRouteParameter {
304
309
  return (
305
310
  this.is_object(object) &&
306
311
  !(this.configuration.special_options_key in object) &&
@@ -310,11 +315,15 @@ RubyVariables.WRAPPER(
310
315
 
311
316
  path_identifier(object: QueryRouteParameter): string {
312
317
  const result = this.unwrap_path_identifier(object);
313
- return this.is_nullable(result) || result === false ? "" : "" + result;
318
+ return this.is_nullable(result) ||
319
+ (RubyVariables.DEPRECATED_FALSE_PARAMETER_BEHAVIOR &&
320
+ result === false)
321
+ ? ""
322
+ : "" + result;
314
323
  }
315
324
 
316
325
  unwrap_path_identifier(object: QueryRouteParameter): unknown {
317
- let result: any = object;
326
+ let result: unknown = object;
318
327
  if (!this.is_object(object)) {
319
328
  return object;
320
329
  }
@@ -411,15 +420,13 @@ RubyVariables.WRAPPER(
411
420
  absolute: boolean,
412
421
  args: OptionalRouteParameter[]
413
422
  ): string {
414
- const {
415
- keyword_parameters,
416
- query_parameters,
417
- } = this.partition_parameters(
418
- parts,
419
- required_params,
420
- default_options,
421
- args
422
- );
423
+ const { keyword_parameters, query_parameters } =
424
+ this.partition_parameters(
425
+ parts,
426
+ required_params,
427
+ default_options,
428
+ args
429
+ );
423
430
  const missing_params = required_params.filter(
424
431
  (param) =>
425
432
  !hasProp(query_parameters, param) ||
data/package.json CHANGED
@@ -12,13 +12,13 @@
12
12
  "dependencies": {
13
13
  "@typescript-eslint/eslint-plugin": "^4.9.0",
14
14
  "@typescript-eslint/parser": "^4.9.0",
15
- "eslint": "^7.14.0",
16
- "eslint-config-prettier": "^6.15.0",
17
- "eslint-plugin-import": "^2.22.1",
15
+ "eslint": "^8.35.0",
16
+ "eslint-config-prettier": "^8.7.0",
17
+ "eslint-plugin-import": "^2.27.5",
18
18
  "husky": "^4.3.0",
19
19
  "lint-staged": "^10.5.2",
20
20
  "pinst": "^2.1.1",
21
- "prettier": "^2.2.1"
21
+ "prettier": "^2.8.4"
22
22
  },
23
23
  "scripts": {
24
24
  "build": "tsc && yarn lint:fix",
@@ -31,7 +31,8 @@
31
31
  }
32
32
  },
33
33
  "lint-staged": {
34
- "./lib/routes.ts": ["yarn lint:fix" ]
34
+ "./lib/routes.ts": [
35
+ "yarn lint:fix"
36
+ ]
35
37
  }
36
-
37
38
  }
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe JsRoutes, "#serialize" do
4
4
 
5
5
  before(:each) do
6
- evaljs(JsRoutes.generate({module_type: nil, namespace: 'Routes'}))
6
+ evaljs(JsRoutes.generate(module_type: nil, namespace: 'Routes'))
7
7
  end
8
8
 
9
9
  it "should provide this method" do
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe JsRoutes, "compatibility with AMD/require.js" do
4
4
 
5
5
  before(:each) do
6
- evaljs("var global = this;", {force: true})
6
+ evaljs("var global = this;", force: true)
7
7
  evaljs("global.GlobalCheck = {};")
8
8
  evaljs("global.define = function (requirs, callback) { global.GlobalCheck['js-routes'] = callback.call(this); return global.GlobalCheck['js-routes']; };")
9
9
  evaljs("global.define.amd = { jQuery: true };")
@@ -25,7 +25,7 @@ describe JsRoutes, "compatibility with AMD/require.js" do
25
25
  };
26
26
  EOF
27
27
  evaljs(strRequire)
28
- evaljs(JsRoutes.generate({module_type: 'AMD'}))
28
+ evaljs(JsRoutes.generate(module_type: 'AMD'))
29
29
  end
30
30
 
31
31
  it "should working from require" do
@@ -64,6 +64,7 @@ declare type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
64
64
  declare const RubyVariables: {
65
65
  PREFIX: string;
66
66
  DEPRECATED_GLOBBING_BEHAVIOR: boolean;
67
+ DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
67
68
  SPECIAL_OPTIONS_KEY: string;
68
69
  DEFAULT_URL_OPTIONS: RouteParameters;
69
70
  SERIALIZER: Serializer;
@@ -12,7 +12,7 @@ describe JsRoutes, "compatibility with DTS" do
12
12
  end
13
13
 
14
14
  let(:generated_js) do
15
- JsRoutes.generate({**OPTIONS, **extra_options})
15
+ JsRoutes.generate(**OPTIONS, **extra_options)
16
16
  end
17
17
 
18
18
  context "when file is generated" do