Skip to content

Commit

Permalink
Use webpacker dir config variable instead of hardcode. #309
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Aug 6, 2023
1 parent 3b2c235 commit 90db9e5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## master

* Use webpacker config variable instead of hardcode [#309](https://github.com/railsware/js-routes/issues/309)
* Use `File.exist?` to be compatible with all versions of ruby [#310](https://github.com/railsware/js-routes/issues/310)

## v2.2.7

* Fix ESM Tree Shaking [#306](https://github.com/railsware/js-routes/issues/306)
Expand Down
2 changes: 1 addition & 1 deletion lib/js_routes/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def source_file
end

def output_file
webpacker_dir = pathname('app', 'javascript')
webpacker_dir = defined?(Webpacker) ? Webpacker.config.source_path : pathname('app', 'javascript')
sprockets_dir = pathname('app','assets','javascripts')
file_name = file || default_file_name
sprockets_file = sprockets_dir.join(file_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/js_routes/generators/webpacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class JsRoutes::Generators::Webpacker < Rails::Generators::Base
def create_webpack
copy_file "initializer.rb", "config/initializers/js_routes.rb"
copy_file "erb.js", "config/webpack/loaders/erb.js"
copy_file "routes.js.erb", "app/javascript/routes.js.erb"
copy_file "routes.js.erb", "#{Webpacker.config.source_path}/routes.js.erb"
inject_into_file "config/webpack/environment.js", loader_content
if path = application_js_path
inject_into_file path, pack_content
Expand Down
2 changes: 1 addition & 1 deletion lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ RubyVariables.WRAPPER(
let key;
switch (route[0]) {
case NodeTypes.GROUP:
return "(" + this.build_path_spec(route[1]) + ")";
return `(${this.build_path_spec(route[1])})`;
case NodeTypes.CAT:
return (this.build_path_spec(route[1]) + this.build_path_spec(route[2]));
case NodeTypes.STAR:
Expand Down
2 changes: 1 addition & 1 deletion lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ declare const module: { exports: any } | undefined;
RubyVariables.WRAPPER(
// eslint-disable-next-line
(): RouterExposedMethods => {
const hasProp = (value: unknown, key: string) =>
const hasProp = (value: unknown, key: string): boolean =>
Object.prototype.hasOwnProperty.call(value, key);
enum NodeTypes {
GROUP = 1,
Expand Down

0 comments on commit 90db9e5

Please sign in to comment.