js-routes 2.2.6 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Readme.md +17 -5
- data/lib/js_routes/route.rb +9 -2
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.d.ts +2 -2
- data/lib/routes.ts +4 -5
- data/spec/js_routes/module_types/dts/routes.spec.d.ts +2 -2
- data/spec/js_routes/module_types/dts_spec.rb +1 -1
- data/spec/js_routes/module_types/esm_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc558c858345b705d2ca048eaab529acf4d4ffe20299e152f1c23fcbeb31388e
|
4
|
+
data.tar.gz: 70dc5ab9c6f629d3236d45a5cf202c6bb8f00893041857f137b9569a3467d48c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0536cff5b25734ae0c0399cba8d65fb48503e7038c6e5f7396acb69497505ab8849b109e3348bc2c7a010b073cb3cd4aebed1798c538e8bd0e0270f8949dd53c
|
7
|
+
data.tar.gz: 99e9d0487c9062cf3789a8018beba7bcc0b9f985251921cb6f042c20c571d74fab8a4c79f82ad0a6530dde42ee8a678fb5dbfae184dd64e8756ef47d06805b0b
|
data/CHANGELOG.md
CHANGED
data/Readme.md
CHANGED
@@ -18,7 +18,7 @@ There are several possible ways to setup JsRoutes:
|
|
18
18
|
|
19
19
|
* [Quick and easy](#quick-start)
|
20
20
|
* Uses Rack Middleware to automatically update routes locally
|
21
|
-
* Automatically generates routes files on
|
21
|
+
* Automatically generates routes files on javascript build
|
22
22
|
* Works great for a simple Rails application
|
23
23
|
* [Webpacker ERB Loader](#webpacker)
|
24
24
|
* Requires ESM module system (the default)
|
@@ -414,9 +414,14 @@ JsRoutes itself does not have security holes.
|
|
414
414
|
It makes URLs without access protection more reachable by potential attacker.
|
415
415
|
If that is an issue for you, you may use one of the following solutions:
|
416
416
|
|
417
|
-
###
|
417
|
+
### ESM Tree shaking
|
418
418
|
|
419
|
-
Make sure `module_type` is set to `ESM` (the default)
|
419
|
+
Make sure `module_type` is set to `ESM` (the default). Modern JS bundlers like
|
420
|
+
[Webpack](https://webpack.js.org) can statically determine which ESM exports are used, and remove
|
421
|
+
the unused exports to reduce bundle size. This is known as [Tree
|
422
|
+
Shaking](https://webpack.js.org/guides/tree-shaking/).
|
423
|
+
|
424
|
+
JS files can use named imports to import only required routes into the file, like:
|
420
425
|
|
421
426
|
``` javascript
|
422
427
|
import {
|
@@ -428,8 +433,15 @@ import {
|
|
428
433
|
} from '../routes'
|
429
434
|
```
|
430
435
|
|
431
|
-
|
432
|
-
|
436
|
+
JS files can also use star imports (`import * as`) for tree shaking, as long as only explicit property accesses are used.
|
437
|
+
|
438
|
+
``` javascript
|
439
|
+
import * as routes from '../routes';
|
440
|
+
|
441
|
+
console.log(routes.inbox_path); // OK, only `inbox_path` is included in the bundle
|
442
|
+
|
443
|
+
console.log(Object.keys(routes)); // forces bundler to include all exports, breaking tree shaking
|
444
|
+
```
|
433
445
|
|
434
446
|
### Exclude option
|
435
447
|
|
data/lib/js_routes/route.rb
CHANGED
@@ -33,8 +33,15 @@ module JsRoutes
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def body(absolute)
|
36
|
-
@configuration.dts?
|
37
|
-
definition_body
|
36
|
+
if @configuration.dts?
|
37
|
+
definition_body
|
38
|
+
else
|
39
|
+
# For tree-shaking ESM, add a #__PURE__ comment informing Webpack/minifiers that the call to `__jsr.r`
|
40
|
+
# has no side-effects (e.g. modifying global variables) and is safe to remove when unused.
|
41
|
+
# https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects
|
42
|
+
pure_comment = @configuration.esm? ? '/*#__PURE__*/ ' : ''
|
43
|
+
"#{pure_comment}__jsr.r(#{arguments(absolute).map{|a| json(a)}.join(', ')})"
|
44
|
+
end
|
38
45
|
end
|
39
46
|
|
40
47
|
def definition_body
|
data/lib/js_routes/version.rb
CHANGED
data/lib/routes.d.ts
CHANGED
@@ -32,8 +32,8 @@ declare type RequiredParameters<T extends number> = T extends 1 ? [RequiredRoute
|
|
32
32
|
RequiredRouteParameter,
|
33
33
|
RequiredRouteParameter
|
34
34
|
] : RequiredRouteParameter[];
|
35
|
-
declare type RouteHelperOptions
|
36
|
-
declare type RouteHelper<T extends number = number
|
35
|
+
declare type RouteHelperOptions = RouteOptions & Record<string, OptionalRouteParameter>;
|
36
|
+
declare type RouteHelper<T extends number = number> = ((...args: [...RequiredParameters<T>, RouteHelperOptions]) => string) & RouteHelperExtras;
|
37
37
|
declare type RouteHelpers = Record<string, RouteHelper>;
|
38
38
|
declare type Configuration = {
|
39
39
|
prefix: string;
|
data/lib/routes.ts
CHANGED
@@ -40,11 +40,10 @@ type RequiredParameters<T extends number> = T extends 1
|
|
40
40
|
]
|
41
41
|
: RequiredRouteParameter[];
|
42
42
|
|
43
|
-
type RouteHelperOptions
|
44
|
-
Optional<Record<T, OptionalRouteParameter>>;
|
43
|
+
type RouteHelperOptions = RouteOptions & Record<string, OptionalRouteParameter>;
|
45
44
|
|
46
|
-
type RouteHelper<T extends number = number
|
47
|
-
...args: [...RequiredParameters<T>, RouteHelperOptions
|
45
|
+
type RouteHelper<T extends number = number> = ((
|
46
|
+
...args: [...RequiredParameters<T>, RouteHelperOptions]
|
48
47
|
) => string) &
|
49
48
|
RouteHelperExtras;
|
50
49
|
|
@@ -539,7 +538,7 @@ RubyVariables.WRAPPER(
|
|
539
538
|
let key: string;
|
540
539
|
switch (route[0]) {
|
541
540
|
case NodeTypes.GROUP:
|
542
|
-
return
|
541
|
+
return `(${this.build_path_spec(route[1])})`;
|
543
542
|
case NodeTypes.CAT:
|
544
543
|
return (
|
545
544
|
this.build_path_spec(route[1]) + this.build_path_spec(route[2])
|
@@ -32,8 +32,8 @@ declare type RequiredParameters<T extends number> = T extends 1 ? [RequiredRoute
|
|
32
32
|
RequiredRouteParameter,
|
33
33
|
RequiredRouteParameter
|
34
34
|
] : RequiredRouteParameter[];
|
35
|
-
declare type RouteHelperOptions
|
36
|
-
declare type RouteHelper<T extends number = number
|
35
|
+
declare type RouteHelperOptions = RouteOptions & Record<string, OptionalRouteParameter>;
|
36
|
+
declare type RouteHelper<T extends number = number> = ((...args: [...RequiredParameters<T>, RouteHelperOptions]) => string) & RouteHelperExtras;
|
37
37
|
declare type RouteHelpers = Record<string, RouteHelper>;
|
38
38
|
declare type Configuration = {
|
39
39
|
prefix: string;
|
@@ -105,7 +105,7 @@ DOC
|
|
105
105
|
describe "compiled javascript asset" do
|
106
106
|
subject { ERB.new(File.read("app/assets/javascripts/js-routes.js.erb")).result(binding) }
|
107
107
|
it "should have js routes code" do
|
108
|
-
is_expected.to include("export const inbox_message_path = __jsr.r(")
|
108
|
+
is_expected.to include("export const inbox_message_path = /*#__PURE__*/ __jsr.r(")
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
@@ -24,7 +24,7 @@ describe JsRoutes, "compatibility with ESM" do
|
|
24
24
|
* @param {object | undefined} options
|
25
25
|
* @returns {string} route path
|
26
26
|
*/
|
27
|
-
export const inboxes_path = __jsr.r
|
27
|
+
export const inboxes_path = /*#__PURE__*/ __jsr.r(
|
28
28
|
DOC
|
29
29
|
end
|
30
30
|
|
@@ -39,7 +39,7 @@ DOC
|
|
39
39
|
describe "compiled javascript asset" do
|
40
40
|
subject { ERB.new(File.read("app/assets/javascripts/js-routes.js.erb")).result(binding) }
|
41
41
|
it "should have js routes code" do
|
42
|
-
is_expected.to include("export const inbox_message_path = __jsr.r(")
|
42
|
+
is_expected.to include("export const inbox_message_path = /*#__PURE__*/ __jsr.r(")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
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.
|
4
|
+
version: 2.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
225
|
+
rubygems_version: 3.4.15
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: Brings Rails named routes to javascript
|