js-routes 2.2.10 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f69479723e452f1b4ed09bf940b3150ad45430b5c601f966f05a082bce0a9494
4
- data.tar.gz: bd47ceb7b1cba241262b8308e913f7d87aef6304d93d9185026e70dd4980487f
3
+ metadata.gz: 8030ebf1b79303bfad35b2003ced97e6ec398b8bab459bf0f867006c9bc5d763
4
+ data.tar.gz: 4d84acaa15dacc791f26e059cb620d5c08d90891103fa5d73750d4bae3973e8b
5
5
  SHA512:
6
- metadata.gz: 4f67b2ccc88195647ea7c694f935848aad52ddd9e46ac1a766df0c29b7e123a147169deb5b8207c8d3a598fcf0c0ba01f98b0d24ee30b326737200f02f2f8235
7
- data.tar.gz: 9aad6d181099b3fdd7ada0facf1269e08669cd1181f94d3039f0e13f8bf2bc5a44172e13843fec5a8317b4c99e1eee6a2de2343e34fe6c3cddebb7a63f9608fb
6
+ metadata.gz: 24e4500fcf1f799633343366f84d619060cd57979edc25a9f83ec17baf6a505e3fbbd838f66b6ec70618bf7d991a0f0614a3c6ad02ce85a90931e4a047f168a6
7
+ data.tar.gz: 7cab5ccd03712368ea32d43604381b32491ada2a933bf656b6efa0002132e638653f250e5a5037487e36c6ecfed01454d6df359e2e308b5fc7cd237c7af2fca2
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
 
3
- ## master
3
+ ## v2.3.0
4
+
5
+ * Drop support of Rails 4.x
6
+ * Fix support of shakapacker [#321](https://github.com/railsware/js-routes/issue/321).
7
+ * Fix support for Rails 8 [#319](https://github.com/railsware/js-routes/issue/319)
8
+ * Deprecated `rake js:routes:typescript`.
9
+ `rake js:routes` now automatically detects if types support can be used on not.
4
10
 
5
11
  ## v2.2.10
6
12
 
@@ -14,7 +20,8 @@
14
20
 
15
21
  * Fix middleware error for non-modern setup.
16
22
  * Added [Sorbet](https://sorbet.org/) method signatures.
17
- * Always use DTS module type when calling JsRoutes.definitions or .definitions!. [#313](https://github.com/railsware/js-routes/issues/313)
23
+ * Always use DTS module type when calling JsRoutes.definitions or .definitions!.
24
+ [#313](https://github.com/railsware/js-routes/issues/313)
18
25
 
19
26
  ## v2.2.8
20
27
 
data/Readme.md CHANGED
@@ -2,7 +2,16 @@
2
2
 
3
3
  [![CI](https://github.com/railsware/js-routes/actions/workflows/ci.yml/badge.svg)](https://github.com/railsware/js-routes/actions/workflows/ci.yml)
4
4
 
5
- Generates javascript file that defines all Rails named routes as javascript helpers
5
+ Generates javascript file that defines all Rails named routes as javascript helpers:
6
+
7
+ ``` js
8
+ import { root_path, api_user_path } from './routes';
9
+
10
+ root_path() # => /
11
+ api_user_path(25, include_profile: true, format: 'json') // => /api/users/25.json?include_profile=true
12
+ ```
13
+
14
+ [More Examples](#usage)
6
15
 
7
16
  ## Intallation
8
17
 
@@ -348,7 +357,7 @@ Configuration above will create a nice javascript file with `Routes` object that
348
357
  ``` js
349
358
  import {
350
359
  user_path, user_project_path, company_path
351
- } as Routes from 'routes';
360
+ } from 'routes';
352
361
 
353
362
  users_path()
354
363
  // => "/users"
@@ -459,15 +468,13 @@ console.log(routes.inbox_path); // OK, only `inbox_path` is included in the bund
459
468
  console.log(Object.keys(routes)); // forces bundler to include all exports, breaking tree shaking
460
469
  ```
461
470
 
462
- ### Exclude option
471
+ ### Exclude/Include options
463
472
 
464
473
  Split your routes into multiple files related to each section of your website like:
465
474
 
466
- ``` javascript
467
- // admin-routes.js.erb
468
- <%= JsRoutes.generate(include: /^admin_/) %>
469
- // app-routes.js.erb
470
- <%= JsRoutes.generate(exclude: /^admin_/) %>
475
+ ``` ruby
476
+ JsRoutes.generate!('app/javascript/admin-routes.js', include: /^admin_/) %>
477
+ JsRoutes.generate!('app/javascript/app-routes.js', exclude: /^admin_/) %>
471
478
  ```
472
479
 
473
480
  ## Advantages over alternatives
@@ -475,17 +482,11 @@ Split your routes into multiple files related to each section of your website li
475
482
  There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
476
483
  Advantages of this one are:
477
484
 
478
- * Rails 4,5,6 support
485
+ * Actively maintained
479
486
  * [ESM Tree shaking](https://webpack.js.org/guides/tree-shaking/) support
480
487
  * Rich options set
481
488
  * Full rails compatibility
482
489
  * Support Rails `#to_param` convention for seo optimized paths
483
490
  * Well tested
484
491
 
485
- #### Thanks to [contributors](https://github.com/railsware/js-routes/contributors)
486
-
487
- #### Have fun
488
-
489
492
 
490
- ## License
491
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes?ref=badge_large)
@@ -1,6 +1,8 @@
1
1
  # typed: strict
2
+
2
3
  require "pathname"
3
4
  require "js_routes/types"
5
+ require 'js_routes/utils'
4
6
 
5
7
  module JsRoutes
6
8
  class Configuration
@@ -114,14 +116,14 @@ module JsRoutes
114
116
 
115
117
  sig { returns(Pathname) }
116
118
  def output_file
117
- webpacker_dir = defined?(::Webpacker) ?
118
- T.unsafe(::Webpacker).config.source_path :
119
- pathname('app', 'javascript')
119
+ shakapacker = JsRoutes::Utils.shakapacker
120
+ shakapacker_dir = shakapacker ?
121
+ shakapacker.config.source_path : pathname('app', 'javascript')
120
122
  sprockets_dir = pathname('app','assets','javascripts')
121
123
  file_name = file || default_file_name
122
124
  sprockets_file = sprockets_dir.join(file_name)
123
- webpacker_file = webpacker_dir.join(file_name)
124
- !Dir.exist?(webpacker_dir) && defined?(::Sprockets) ? sprockets_file : webpacker_file
125
+ webpacker_file = shakapacker_dir.join(file_name)
126
+ !Dir.exist?(shakapacker_dir) && defined?(::Sprockets) ? sprockets_file : webpacker_file
125
127
  end
126
128
 
127
129
  protected
@@ -10,8 +10,7 @@ class JsRoutes::Generators::Middleware < JsRoutes::Generators::Base
10
10
  if path = application_js_path
11
11
  inject_into_file path, pack_content
12
12
  end
13
- JsRoutes.generate!
14
- JsRoutes.definitions! if JsRoutes.configuration.modern?
13
+ JsRoutes.generate!(typed: true)
15
14
  end
16
15
 
17
16
  protected
@@ -34,10 +33,9 @@ alert(`JsRoutes installed.\\nYour root path is ${root_path()}`)
34
33
 
35
34
  def rakefile_content
36
35
  enhanced_task = depends_on_js_bundling? ? "javascript:build" : "assets:precompile"
37
- dependency_task = JsRoutes.configuration.modern? ? "js:routes:typescript" : 'js:routes'
38
36
  <<-RB
39
37
  # Update js-routes file before javascript build
40
- task "#{enhanced_task}" => "#{dependency_task}"
38
+ task "#{enhanced_task}" => "js:routes"
41
39
  RB
42
40
  end
43
41
 
@@ -1,11 +1,12 @@
1
1
  require "rails/generators"
2
+ require 'js_routes/utils'
2
3
 
3
4
  class JsRoutes::Generators::Webpacker < Rails::Generators::Base
4
5
 
5
6
  def create_webpack
6
7
  copy_file "initializer.rb", "config/initializers/js_routes.rb"
7
8
  copy_file "erb.js", "config/webpack/loaders/erb.js"
8
- copy_file "routes.js.erb", "#{Webpacker.config.source_path}/routes.js.erb"
9
+ copy_file "routes.js.erb", "#{JsRoutes::Utils.shakapacker.config.source_path}/routes.js.erb"
9
10
  inject_into_file "config/webpack/environment.js", loader_content
10
11
  if path = application_js_path
11
12
  inject_into_file path, pack_content
@@ -24,9 +24,16 @@ module JsRoutes
24
24
  sig {returns(String)}
25
25
  def generate
26
26
  # Ensure routes are loaded. If they're not, load them.
27
+
27
28
  application = T.unsafe(self.application)
28
- if named_routes.empty? && application.respond_to?(:reload_routes!, true)
29
- application.reload_routes!
29
+ if named_routes.empty?
30
+ if application.is_a?(Rails::Application)
31
+ if Rails.version >= "8.0.0"
32
+ application.reload_routes_unless_loaded
33
+ else
34
+ application.reload_routes!
35
+ end
36
+ end
30
37
  end
31
38
  content = File.read(@configuration.source_file)
32
39
 
@@ -178,8 +185,8 @@ export {};
178
185
  sig { params(route: JourneyRoute).returns(T::Array[StringArray]) }
179
186
  def mounted_app_routes(route)
180
187
  rails_engine_app = T.unsafe(app_from_route(route))
181
- if rails_engine_app.respond_to?(:superclass) &&
182
- rails_engine_app.superclass == Rails::Engine && !route.path.anchored
188
+ if rails_engine_app.is_a?(Class) &&
189
+ rails_engine_app < Rails::Engine && !route.path.anchored
183
190
  rails_engine_app.routes.named_routes.flat_map do |_, engine_route|
184
191
  route_helpers_if_match(engine_route, route)
185
192
  end
@@ -191,9 +198,9 @@ export {};
191
198
  sig { params(route: JourneyRoute).returns(T.untyped) }
192
199
  def app_from_route(route)
193
200
  app = route.app
194
- # rails engine in Rails 4.2 use additional
201
+ # Rails Engine can use additional
195
202
  # ActionDispatch::Routing::Mapper::Constraints, which contain app
196
- if app.respond_to?(:app) && app.respond_to?(:constraints)
203
+ if app.is_a?(ActionDispatch::Routing::Mapper::Constraints)
197
204
  app.app
198
205
  else
199
206
  app
@@ -39,8 +39,7 @@ module JsRoutes
39
39
 
40
40
  sig { void }
41
41
  def regenerate
42
- JsRoutes.generate!
43
- JsRoutes.definitions! if JsRoutes.configuration.modern?
42
+ JsRoutes.generate!(typed: true)
44
43
  end
45
44
 
46
45
  sig { returns(T.nilable(Time)) }
@@ -194,7 +194,9 @@ JS
194
194
  sig { params(spec: SpecNode, parent_spec: T.nilable(RouteSpec)).returns(T.nilable(T.any(UntypedArray, String))) }
195
195
  def serialize(spec, parent_spec=nil)
196
196
  return nil unless spec
197
- # Rails 4 globbing requires * removal
197
+ # Removing special character prefix from route variable name
198
+ # * for globbing
199
+ # : for common parameter
198
200
  return spec.tr(':*', '') if spec.is_a?(String)
199
201
 
200
202
  result = serialize_spec(spec, parent_spec)
@@ -0,0 +1,18 @@
1
+ # typed: strict
2
+
3
+ module JsRoutes
4
+ module Utils
5
+ extend T::Sig
6
+ sig {returns(T.untyped)}
7
+ def self.shakapacker
8
+ if defined?(::Shakapacker)
9
+ ::Shakapacker
10
+ elsif defined?(::Webpacker)
11
+ ::Webpacker
12
+ else
13
+ nil
14
+ end
15
+ end
16
+ end
17
+
18
+ end
@@ -1,4 +1,4 @@
1
1
  # typed: strict
2
2
  module JsRoutes
3
- VERSION = "2.2.10"
3
+ VERSION = "2.3.0"
4
4
  end
data/lib/js_routes.rb CHANGED
@@ -34,9 +34,10 @@ module JsRoutes
34
34
  Instance.new(**opts).generate
35
35
  end
36
36
 
37
- sig { params(file_name: FileName, opts: T.untyped).void }
38
- def generate!(file_name = configuration.file, **opts)
37
+ sig { params(file_name: FileName, typed: T::Boolean, opts: T.untyped).void }
38
+ def generate!(file_name = configuration.file, typed: false, **opts)
39
39
  Instance.new(file: file_name, **opts).generate!
40
+ definitions!(file_name, **opts) if typed
40
41
  end
41
42
 
42
43
  sig { params(file_name: FileName, opts: T.untyped).void }
@@ -46,12 +47,14 @@ module JsRoutes
46
47
 
47
48
  sig { params(opts: T.untyped).returns(String) }
48
49
  def definitions(**opts)
49
- generate(**opts, module_type: 'DTS',)
50
+ generate(**opts, module_type: 'DTS')
50
51
  end
51
52
 
52
53
  sig { params(file_name: FileName, opts: T.untyped).void }
53
54
  def definitions!(file_name = nil, **opts)
54
- file_name ||= configuration.file&.sub(%r{(\.d)?\.(j|t)s\Z}, ".d.ts")
55
+ file_name ||= configuration.file
56
+
57
+ file_name = file_name&.sub(%r{(\.d)?\.(j|t)s\Z}, ".d.ts")
55
58
  generate!(file_name, **opts, module_type: 'DTS')
56
59
  end
57
60
 
data/lib/routes.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  declare type Optional<T> = {
6
6
  [P in keyof T]?: T[P] | null;
7
7
  };
8
+ declare type Collection<T> = Record<string, T>;
8
9
  declare type BaseRouteParameter = string | boolean | Date | number;
9
10
  declare type MethodRouteParameter = BaseRouteParameter | (() => BaseRouteParameter);
10
11
  declare type ModelRouteParameter = {
@@ -19,8 +20,8 @@ declare type OptionalRouteParameter = undefined | null | RequiredRouteParameter;
19
20
  declare type QueryRouteParameter = OptionalRouteParameter | QueryRouteParameter[] | {
20
21
  [k: string]: QueryRouteParameter;
21
22
  };
22
- declare type RouteParameters = Record<string, QueryRouteParameter>;
23
- declare type Serializable = Record<string, unknown>;
23
+ declare type RouteParameters = Collection<QueryRouteParameter>;
24
+ declare type Serializable = Collection<unknown>;
24
25
  declare type Serializer = (value: Serializable) => string;
25
26
  declare type RouteHelperExtras = {
26
27
  requiredParams(): string[];
@@ -32,9 +33,9 @@ declare type RequiredParameters<T extends number> = T extends 1 ? [RequiredRoute
32
33
  RequiredRouteParameter,
33
34
  RequiredRouteParameter
34
35
  ] : RequiredRouteParameter[];
35
- declare type RouteHelperOptions = RouteOptions & Record<string, OptionalRouteParameter>;
36
+ declare type RouteHelperOptions = RouteOptions & Collection<OptionalRouteParameter>;
36
37
  declare type RouteHelper<T extends number = number> = ((...args: [...RequiredParameters<T>, RouteHelperOptions]) => string) & RouteHelperExtras;
37
- declare type RouteHelpers = Record<string, RouteHelper>;
38
+ declare type RouteHelpers = Collection<RouteHelper>;
38
39
  declare type Configuration = {
39
40
  prefix: string;
40
41
  default_url_options: RouteParameters;
@@ -56,7 +57,7 @@ declare type KeywordUrlOptions = Optional<{
56
57
  params: RouteParameters;
57
58
  }>;
58
59
  declare type RouteOptions = KeywordUrlOptions & RouteParameters;
59
- declare type PartsTable = Record<string, {
60
+ declare type PartsTable = Collection<{
60
61
  r?: boolean;
61
62
  d?: OptionalRouteParameter;
62
63
  }>;
@@ -76,5 +77,5 @@ declare const define: undefined | (((arg: unknown[], callback: () => unknown) =>
76
77
  amd?: unknown;
77
78
  });
78
79
  declare const module: {
79
- exports: any;
80
+ exports: unknown;
80
81
  } | undefined;
data/lib/routes.js CHANGED
@@ -30,8 +30,9 @@ RubyVariables.WRAPPER(
30
30
  const ModuleReferences = {
31
31
  CJS: {
32
32
  define(routes) {
33
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
34
- module.exports = routes;
33
+ if (module) {
34
+ module.exports = routes;
35
+ }
35
36
  },
36
37
  isSupported() {
37
38
  return typeof module === "object";
@@ -39,10 +40,11 @@ RubyVariables.WRAPPER(
39
40
  },
40
41
  AMD: {
41
42
  define(routes) {
42
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
43
- define([], function () {
44
- return routes;
45
- });
43
+ if (define) {
44
+ define([], function () {
45
+ return routes;
46
+ });
47
+ }
46
48
  },
47
49
  isSupported() {
48
50
  return typeof define === "function" && !!define.amd;
@@ -290,9 +292,9 @@ RubyVariables.WRAPPER(
290
292
  if (url_params.length) {
291
293
  result += "?" + url_params;
292
294
  }
293
- result += keyword_parameters.anchor
294
- ? "#" + keyword_parameters.anchor
295
- : "";
295
+ if (keyword_parameters.anchor) {
296
+ result += "#" + keyword_parameters.anchor;
297
+ }
296
298
  if (absolute) {
297
299
  result = this.route_url(keyword_parameters) + result;
298
300
  }
@@ -502,28 +504,27 @@ RubyVariables.WRAPPER(
502
504
  define_module(name, module) {
503
505
  this.ensure_module_supported(name);
504
506
  ModuleReferences[name].define(module);
507
+ return module;
505
508
  }
506
509
  }
507
- const Utils = new UtilsClass();
510
+ const utils = new UtilsClass();
508
511
  // We want this helper name to be short
509
512
  const __jsr = {
510
513
  r(parts_table, route_spec, absolute) {
511
- return Utils.route(parts_table, route_spec, absolute);
514
+ return utils.route(parts_table, route_spec, absolute);
512
515
  },
513
516
  };
514
- const result = {
517
+ return utils.define_module(RubyVariables.MODULE_TYPE, {
515
518
  ...__jsr,
516
519
  configure: (config) => {
517
- return Utils.configure(config);
520
+ return utils.configure(config);
518
521
  },
519
522
  config: () => {
520
- return Utils.config();
523
+ return utils.config();
521
524
  },
522
525
  serialize: (object) => {
523
- return Utils.serialize(object);
526
+ return utils.serialize(object);
524
527
  },
525
528
  ...RubyVariables.ROUTES_OBJECT,
526
- };
527
- Utils.define_module(RubyVariables.MODULE_TYPE, result);
528
- return result;
529
+ });
529
530
  })();
data/lib/routes.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  */
5
5
 
6
6
  type Optional<T> = { [P in keyof T]?: T[P] | null };
7
+ type Collection<T> = Record<string, T>;
8
+
7
9
  type BaseRouteParameter = string | boolean | Date | number;
8
10
  type MethodRouteParameter = BaseRouteParameter | (() => BaseRouteParameter);
9
11
  type ModelRouteParameter =
@@ -16,9 +18,9 @@ type QueryRouteParameter =
16
18
  | OptionalRouteParameter
17
19
  | QueryRouteParameter[]
18
20
  | { [k: string]: QueryRouteParameter };
19
- type RouteParameters = Record<string, QueryRouteParameter>;
21
+ type RouteParameters = Collection<QueryRouteParameter>;
20
22
 
21
- type Serializable = Record<string, unknown>;
23
+ type Serializable = Collection<unknown>;
22
24
  type Serializer = (value: Serializable) => string;
23
25
  type RouteHelperExtras = {
24
26
  requiredParams(): string[];
@@ -40,14 +42,14 @@ type RequiredParameters<T extends number> = T extends 1
40
42
  ]
41
43
  : RequiredRouteParameter[];
42
44
 
43
- type RouteHelperOptions = RouteOptions & Record<string, OptionalRouteParameter>;
45
+ type RouteHelperOptions = RouteOptions & Collection<OptionalRouteParameter>;
44
46
 
45
47
  type RouteHelper<T extends number = number> = ((
46
48
  ...args: [...RequiredParameters<T>, RouteHelperOptions]
47
49
  ) => string) &
48
50
  RouteHelperExtras;
49
51
 
50
- type RouteHelpers = Record<string, RouteHelper>;
52
+ type RouteHelpers = Collection<RouteHelper>;
51
53
 
52
54
  type Configuration = {
53
55
  prefix: string;
@@ -74,7 +76,7 @@ type KeywordUrlOptions = Optional<{
74
76
 
75
77
  type RouteOptions = KeywordUrlOptions & RouteParameters;
76
78
 
77
- type PartsTable = Record<string, { r?: boolean; d?: OptionalRouteParameter }>;
79
+ type PartsTable = Collection<{ r?: boolean; d?: OptionalRouteParameter }>;
78
80
 
79
81
  type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
80
82
 
@@ -94,7 +96,7 @@ declare const define:
94
96
  | undefined
95
97
  | (((arg: unknown[], callback: () => unknown) => void) & { amd?: unknown });
96
98
 
97
- declare const module: { exports: any } | undefined;
99
+ declare const module: { exports: unknown } | undefined;
98
100
 
99
101
  // eslint-disable-next-line
100
102
  RubyVariables.WRAPPER(
@@ -148,8 +150,9 @@ RubyVariables.WRAPPER(
148
150
  const ModuleReferences: Record<ModuleType, ModuleDefinition> = {
149
151
  CJS: {
150
152
  define(routes) {
151
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
152
- module!.exports = routes;
153
+ if (module) {
154
+ module.exports = routes;
155
+ }
153
156
  },
154
157
  isSupported() {
155
158
  return typeof module === "object";
@@ -157,10 +160,11 @@ RubyVariables.WRAPPER(
157
160
  },
158
161
  AMD: {
159
162
  define(routes) {
160
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
161
- define!([], function () {
162
- return routes;
163
- });
163
+ if (define) {
164
+ define([], function () {
165
+ return routes;
166
+ });
167
+ }
164
168
  },
165
169
  isSupported() {
166
170
  return typeof define === "function" && !!define.amd;
@@ -419,6 +423,7 @@ RubyVariables.WRAPPER(
419
423
  }
420
424
  return { keyword_parameters, query_parameters };
421
425
  }
426
+
422
427
  build_route(
423
428
  parts: string[],
424
429
  required_params: string[],
@@ -450,9 +455,9 @@ RubyVariables.WRAPPER(
450
455
  if (url_params.length) {
451
456
  result += "?" + url_params;
452
457
  }
453
- result += keyword_parameters.anchor
454
- ? "#" + keyword_parameters.anchor
455
- : "";
458
+ if (keyword_parameters.anchor) {
459
+ result += "#" + keyword_parameters.anchor;
460
+ }
456
461
  if (absolute) {
457
462
  result = this.route_url(keyword_parameters) + result;
458
463
  }
@@ -679,7 +684,7 @@ RubyVariables.WRAPPER(
679
684
  return (isBrowser && window?.location?.port) || "";
680
685
  }
681
686
 
682
- is_object(value: unknown): value is Record<string, unknown> {
687
+ is_object(value: unknown): value is Collection<unknown> {
683
688
  return (
684
689
  typeof value === "object" &&
685
690
  Object.prototype.toString.call(value) === "[object Object]"
@@ -717,13 +722,17 @@ RubyVariables.WRAPPER(
717
722
  }
718
723
  }
719
724
 
720
- define_module(name: ModuleType, module: RouterExposedMethods): void {
725
+ define_module(
726
+ name: ModuleType,
727
+ module: RouterExposedMethods
728
+ ): RouterExposedMethods {
721
729
  this.ensure_module_supported(name);
722
730
  ModuleReferences[name].define(module);
731
+ return module;
723
732
  }
724
733
  }
725
734
 
726
- const Utils = new UtilsClass();
735
+ const utils = new UtilsClass();
727
736
 
728
737
  // We want this helper name to be short
729
738
  const __jsr = {
@@ -732,25 +741,22 @@ RubyVariables.WRAPPER(
732
741
  route_spec: RouteTree,
733
742
  absolute?: boolean
734
743
  ): RouteHelper {
735
- return Utils.route(parts_table, route_spec, absolute);
744
+ return utils.route(parts_table, route_spec, absolute);
736
745
  },
737
746
  };
738
747
 
739
- const result = {
748
+ return utils.define_module(RubyVariables.MODULE_TYPE, {
740
749
  ...__jsr,
741
750
  configure: (config: Partial<Configuration>) => {
742
- return Utils.configure(config);
751
+ return utils.configure(config);
743
752
  },
744
753
  config: (): Configuration => {
745
- return Utils.config();
754
+ return utils.config();
746
755
  },
747
756
  serialize: (object: Serializable): string => {
748
- return Utils.serialize(object);
757
+ return utils.serialize(object);
749
758
  },
750
759
  ...RubyVariables.ROUTES_OBJECT,
751
- };
752
-
753
- Utils.define_module(RubyVariables.MODULE_TYPE, result);
754
- return result;
760
+ });
755
761
  }
756
762
  )();
@@ -2,13 +2,15 @@ namespace :js do
2
2
  desc "Make a js file with all rails route URL helpers"
3
3
  task routes: :environment do
4
4
  require "js-routes"
5
- JsRoutes.generate!
5
+ JsRoutes.generate!(typed: true)
6
6
  end
7
7
 
8
8
  namespace :routes do
9
9
  desc "Make a js file with all rails route URL helpers and typescript definitions for them"
10
10
  task typescript: "js:routes" do
11
- JsRoutes.definitions!
11
+ ActiveSupport::Deprecation.warn(
12
+ "`js:routes:typescript` task is deprecated. Please use `js:routes` instead."
13
+ )
12
14
  end
13
15
  end
14
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.10
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-03 00:00:00.000000000 Z
11
+ date: 2024-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sorbet-runtime
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,48 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.5.2
97
- - !ruby/object:Gem::Dependency
98
- name: bump
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 0.10.0
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: 0.10.0
111
- - !ruby/object:Gem::Dependency
112
- name: byebug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: pry-byebug
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
97
  - !ruby/object:Gem::Dependency
140
98
  name: mini_racer
141
99
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +130,7 @@ files:
172
130
  - lib/js_routes/middleware.rb
173
131
  - lib/js_routes/route.rb
174
132
  - lib/js_routes/types.rb
133
+ - lib/js_routes/utils.rb
175
134
  - lib/js_routes/version.rb
176
135
  - lib/routes.d.ts
177
136
  - lib/routes.js
@@ -185,9 +144,9 @@ licenses:
185
144
  - MIT
186
145
  metadata:
187
146
  bug_tracker_uri: https://github.com/railsware/js-routes/issues
188
- changelog_uri: https://github.com/railsware/js-routes/blob/v2.2.10/CHANGELOG.md
147
+ changelog_uri: https://github.com/railsware/js-routes/blob/v2.3.0/CHANGELOG.md
189
148
  documentation_uri: https://github.com/railsware/js-routes
190
- source_code_uri: https://github.com/railsware/js-routes/tree/v2.2.10/activerecord
149
+ source_code_uri: https://github.com/railsware/js-routes/tree/v2.3.0/activerecord
191
150
  rubygems_mfa_required: 'true'
192
151
  github_repo: ssh://github.com/railsware/js-routes
193
152
  post_install_message:
@@ -205,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
164
  - !ruby/object:Gem::Version
206
165
  version: '0'
207
166
  requirements: []
208
- rubygems_version: 3.2.22
167
+ rubygems_version: 3.5.11
209
168
  signing_key:
210
169
  specification_version: 4
211
170
  summary: Brings Rails named routes to javascript