Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package rubygem-js-routes for openSUSE:Factory checked in at 2022-02-24 18:20:17 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-js-routes (Old) and /work/SRC/openSUSE:Factory/.rubygem-js-routes.new.1958 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-js-routes" Thu Feb 24 18:20:17 2022 rev:25 rq:956118 version:2.2.2 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-js-routes/rubygem-js-routes.changes 2022-02-07 23:38:44.922174185 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-js-routes.new.1958/rubygem-js-routes.changes 2022-02-24 18:23:33.310656841 +0100 @@ -1,0 +2,11 @@ +Tue Feb 15 07:31:20 UTC 2022 - Stephan Kulow <co...@suse.com> + +updated to version 2.2.2 + see installed CHANGELOG.md + + ## v2.2.2. + + * Fix custom file path [#295](https://github.com/railsware/js-routes/issues/295) + + +------------------------------------------------------------------- Old: ---- js-routes-2.2.1.gem New: ---- js-routes-2.2.2.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-js-routes.spec ++++++ --- /var/tmp/diff_new_pack.V35y8r/_old 2022-02-24 18:23:33.738656759 +0100 +++ /var/tmp/diff_new_pack.V35y8r/_new 2022-02-24 18:23:33.742656759 +0100 @@ -24,7 +24,7 @@ # Name: rubygem-js-routes -Version: 2.2.1 +Version: 2.2.2 Release: 0 %define mod_name js-routes %define mod_full_name %{mod_name}-%{version} ++++++ js-routes-2.2.1.gem -> js-routes-2.2.2.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md --- old/CHANGELOG.md 2022-01-20 15:57:52.000000000 +0100 +++ new/CHANGELOG.md 2022-02-01 15:34:29.000000000 +0100 @@ -1,5 +1,9 @@ ## master +## v2.2.2. + +* Fix custom file path [#295](https://github.com/railsware/js-routes/issues/295) + ## v2.2.1 * 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) Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/js_routes/configuration.rb new/lib/js_routes/configuration.rb --- old/lib/js_routes/configuration.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/js_routes/configuration.rb 2022-02-01 15:34:29.000000000 +0100 @@ -0,0 +1,111 @@ +require "pathname" + +module JsRoutes + class Configuration + DEFAULTS = { + namespace: nil, + exclude: [], + include: //, + file: nil, + prefix: -> { Rails.application.config.relative_url_root || "" }, + url_links: false, + camel_case: false, + default_url_options: {}, + compact: false, + serializer: nil, + special_options_key: "_options", + application: -> { Rails.application }, + module_type: 'ESM', + documentation: true, + } #:nodoc: + + attr_accessor(*DEFAULTS.keys) + + def initialize(attributes = nil) + assign(DEFAULTS) + return unless attributes + assign(attributes) + end + + def assign(attributes = nil, &block) + if !attributes && !block + raise "Provide attributes or block" + end + tap(&block) if block + if attributes + attributes.each do |attribute, value| + value = value.call if value.is_a?(Proc) + send(:"#{attribute}=", value) + end + end + normalize_and_verify + self + end + + def [](attribute) + send(attribute) + end + + def merge(attributes) + clone.assign(attributes) + end + + def to_hash + Hash[*members.zip(values).flatten(1)].symbolize_keys + end + + def esm? + module_type === 'ESM' + end + + def dts? + self.module_type === 'DTS' + end + + def modern? + esm? || dts? + end + + def require_esm + raise "ESM module type is required" unless modern? + end + + def source_file + File.dirname(__FILE__) + "/../" + default_file_name + end + + def output_file + webpacker_dir = pathname('app', 'javascript') + sprockets_dir = pathname('app','assets','javascripts') + file_name = file || default_file_name + sprockets_file = sprockets_dir.join(file_name) + webpacker_file = webpacker_dir.join(file_name) + !Dir.exist?(webpacker_dir) && defined?(::Sprockets) ? sprockets_file : webpacker_file + end + + protected + + def normalize_and_verify + normalize + verify + end + + def pathname(*parts) + Pathname.new(File.join(*parts)) + end + + def default_file_name + dts? ? "routes.d.ts" : "routes.js" + end + + def normalize + self.module_type = module_type&.upcase || 'NIL' + end + + def verify + if module_type != 'NIL' && namespace + raise "JsRoutes namespace option can only be used if module_type is nil" + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/js_routes/engine.rb new/lib/js_routes/engine.rb --- old/lib/js_routes/engine.rb 2022-01-20 15:57:52.000000000 +0100 +++ new/lib/js_routes/engine.rb 2022-02-01 15:34:29.000000000 +0100 @@ -1,4 +1,4 @@ -class JsRoutes +module JsRoutes class SprocketsExtension def initialize(filename, &block) @filename = filename diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/js_routes/instance.rb new/lib/js_routes/instance.rb --- old/lib/js_routes/instance.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/js_routes/instance.rb 2022-02-01 15:34:29.000000000 +0100 @@ -0,0 +1,154 @@ +require "js_routes/configuration" +require "js_routes/route" + +module JsRoutes + class Instance + + attr_reader :configuration + # + # Implementation + # + + def initialize(options = {}) + @configuration = JsRoutes.configuration.merge(options) + end + + def generate + # Ensure routes are loaded. If they're not, load them. + if named_routes.empty? && application.respond_to?(:reload_routes!) + application.reload_routes! + end + content = File.read(@configuration.source_file) + + if !@configuration.dts? + content = js_variables.inject(content) do |js, (key, value)| + js.gsub!("RubyVariables.#{key}", value.to_s) || + raise("Missing key #{key} in JS template") + end + end + content + routes_export + prevent_types_export + end + + def generate! + # Some libraries like Devise did not load their routes yet + # so we will wait until initialization process finishes + # https://github.com/railsware/js-routes/issues/7 + Rails.configuration.after_initialize do + file_path = Rails.root.join(@configuration.output_file) + source_code = generate + + # We don't need to rewrite file if it already exist and have same content. + # It helps asset pipeline or webpack understand that file wasn't changed. + next if File.exist?(file_path) && File.read(file_path) == source_code + + File.open(file_path, 'w') do |f| + f.write source_code + end + end + end + + protected + + def js_variables + { + 'GEM_VERSION' => JsRoutes::VERSION, + 'ROUTES_OBJECT' => routes_object, + 'RAILS_VERSION' => ActionPack.version, + 'DEPRECATED_GLOBBING_BEHAVIOR' => ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR == 0, + + 'APP_CLASS' => application.class.to_s, + 'NAMESPACE' => json(@configuration.namespace), + 'DEFAULT_URL_OPTIONS' => json(@configuration.default_url_options), + 'PREFIX' => json(@configuration.prefix), + 'SPECIAL_OPTIONS_KEY' => json(@configuration.special_options_key), + 'SERIALIZER' => @configuration.serializer || json(nil), + 'MODULE_TYPE' => json(@configuration.module_type), + 'WRAPPER' => @configuration.esm? ? 'const __jsr = ' : '', + } + end + + def application + @configuration.application + end + + def json(string) + JsRoutes.json(string) + end + + def named_routes + application.routes.named_routes.to_a + end + + def routes_object + return json({}) if @configuration.modern? + properties = routes_list.map do |comment, name, body| + "#{comment}#{name}: #{body}".indent(2) + end + "{\n" + properties.join(",\n\n") + "}\n" + end + + def static_exports + [:configure, :config, :serialize].map do |name| + [ + "", name, + @configuration.dts? ? + "RouterExposedMethods['#{name}']" : + "__jsr.#{name}" + ] + end + end + + def routes_export + return "" unless @configuration.modern? + [*static_exports, *routes_list].map do |comment, name, body| + "#{comment}export const #{name}#{export_separator}#{body};\n\n" + end.join + end + + def prevent_types_export + return "" unless @configuration.dts? + <<-JS +// By some reason this line prevents all types in a file +// from being automatically exported +export {}; + JS + end + + def export_separator + @configuration.dts? ? ': ' : ' = ' + end + + def routes_list + named_routes.sort_by(&:first).flat_map do |_, route| + route_helpers_if_match(route) + mounted_app_routes(route) + end + end + + def mounted_app_routes(route) + rails_engine_app = app_from_route(route) + if rails_engine_app.respond_to?(:superclass) && + rails_engine_app.superclass == Rails::Engine && !route.path.anchored + rails_engine_app.routes.named_routes.flat_map do |_, engine_route| + route_helpers_if_match(engine_route, route) + end + else + [] + end + end + + def app_from_route(route) + app = route.app + # rails engine in Rails 4.2 use additional + # ActionDispatch::Routing::Mapper::Constraints, which contain app + if app.respond_to?(:app) && app.respond_to?(:constraints) + app.app + else + app + end + end + + def route_helpers_if_match(route, parent_route = nil) + Route.new(@configuration, route, parent_route).helpers + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/js_routes/middleware.rb new/lib/js_routes/middleware.rb --- old/lib/js_routes/middleware.rb 2022-01-20 15:57:52.000000000 +0100 +++ new/lib/js_routes/middleware.rb 2022-02-01 15:34:29.000000000 +0100 @@ -1,4 +1,4 @@ -class JsRoutes +module JsRoutes # A Rack middleware that automatically updates routes file # whenever routes.rb is modified # diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/js_routes/route.rb new/lib/js_routes/route.rb --- old/lib/js_routes/route.rb 2022-01-20 15:57:52.000000000 +0100 +++ new/lib/js_routes/route.rb 2022-02-01 15:34:29.000000000 +0100 @@ -1,4 +1,4 @@ -class JsRoutes +module JsRoutes class Route #:nodoc: FILTERED_DEFAULT_PARTS = [:controller, :action] URL_OPTIONS = [:protocol, :domain, :host, :port, :subdomain] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/js_routes/version.rb new/lib/js_routes/version.rb --- old/lib/js_routes/version.rb 2022-01-20 15:57:52.000000000 +0100 +++ new/lib/js_routes/version.rb 2022-02-01 15:34:29.000000000 +0100 @@ -1,3 +1,3 @@ -class JsRoutes - VERSION = "2.2.1" +module JsRoutes + VERSION = "2.2.2" end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/js_routes.rb new/lib/js_routes.rb --- old/lib/js_routes.rb 2022-01-20 15:57:52.000000000 +0100 +++ new/lib/js_routes.rb 2022-02-01 15:34:29.000000000 +0100 @@ -1,116 +1,12 @@ -require 'uri' -require "pathname" - if defined?(::Rails) && defined?(::Sprockets::Railtie) require 'js_routes/engine' end require 'js_routes/version' -require "js_routes/route" +require "js_routes/configuration" +require "js_routes/instance" require 'active_support/core_ext/string/indent' -class JsRoutes - - class Configuration - DEFAULTS = { - namespace: nil, - exclude: [], - include: //, - file: nil, - prefix: -> { Rails.application.config.relative_url_root || "" }, - url_links: false, - camel_case: false, - default_url_options: {}, - compact: false, - serializer: nil, - special_options_key: "_options", - application: -> { Rails.application }, - module_type: 'ESM', - documentation: true, - } #:nodoc: - - attr_accessor(*DEFAULTS.keys) - - def initialize(attributes = nil) - assign(DEFAULTS) - return unless attributes - assign(attributes) - end - - def assign(attributes) - attributes.each do |attribute, value| - value = value.call if value.is_a?(Proc) - send(:"#{attribute}=", value) - end - normalize_and_verify - self - end - - def [](attribute) - send(attribute) - end - - def merge(attributes) - clone.assign(attributes) - end - - def to_hash - Hash[*members.zip(values).flatten(1)].symbolize_keys - end - - def esm? - module_type === 'ESM' - end - - def dts? - self.module_type === 'DTS' - end - - def modern? - esm? || dts? - end - - def require_esm - raise "ESM module type is required" unless modern? - end - - def source_file - File.dirname(__FILE__) + "/" + default_file_name - end - - def output_file - webpacker_dir = pathname('app', 'javascript') - sprockets_dir = pathname('app','assets','javascripts') - file_name = file || default_file_name - sprockets_file = sprockets_dir.join(file_name) - webpacker_file = webpacker_dir.join(file_name) - !Dir.exist?(webpacker_dir) && defined?(::Sprockets) ? sprockets_file : webpacker_file - end - - def normalize_and_verify - normalize - verify - end - - protected - - def pathname(*parts) - Pathname.new(File.join(*parts)) - end - - def default_file_name - dts? ? "routes.d.ts" : "routes.js" - end - - def normalize - self.module_type = module_type&.upcase || 'NIL' - end - - def verify - if module_type != 'NIL' && namespace - raise "JsRoutes namespace option can only be used if module_type is nil" - end - end - end +module JsRoutes # # API @@ -118,8 +14,7 @@ class << self def setup(&block) - configuration.tap(&block) if block - configuration.normalize_and_verify + configuration.assign(&block) end def configuration @@ -127,11 +22,11 @@ end def generate(**opts) - new(opts).generate + Instance.new(opts).generate end - def generate!(file_name=nil, **opts) - new(file: file_name, **opts).generate! + def generate!(file_name = configuration.file, **opts) + Instance.new(file: file_name, **opts).generate! end def definitions(**opts) @@ -147,154 +42,6 @@ ActiveSupport::JSON.encode(string) end end - - attr_reader :configuration - # - # Implementation - # - - def initialize(options = {}) - @configuration = self.class.configuration.merge(options) - end - - def generate - # Ensure routes are loaded. If they're not, load them. - if named_routes.empty? && application.respond_to?(:reload_routes!) - application.reload_routes! - end - content = File.read(@configuration.source_file) - - if !@configuration.dts? - content = js_variables.inject(content) do |js, (key, value)| - js.gsub!("RubyVariables.#{key}", value.to_s) || - raise("Missing key #{key} in JS template") - end - end - content + routes_export + prevent_types_export - end - - def generate! - # Some libraries like Devise did not load their routes yet - # so we will wait until initialization process finishes - # https://github.com/railsware/js-routes/issues/7 - Rails.configuration.after_initialize do - file_path = Rails.root.join(@configuration.output_file) - source_code = generate - - # We don't need to rewrite file if it already exist and have same content. - # It helps asset pipeline or webpack understand that file wasn't changed. - next if File.exist?(file_path) && File.read(file_path) == source_code - - File.open(file_path, 'w') do |f| - f.write source_code - end - end - end - - protected - - def js_variables - { - 'GEM_VERSION' => JsRoutes::VERSION, - 'ROUTES_OBJECT' => routes_object, - 'RAILS_VERSION' => ActionPack.version, - 'DEPRECATED_GLOBBING_BEHAVIOR' => ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR == 0, - - 'APP_CLASS' => application.class.to_s, - 'NAMESPACE' => json(@configuration.namespace), - 'DEFAULT_URL_OPTIONS' => json(@configuration.default_url_options), - 'PREFIX' => json(@configuration.prefix), - 'SPECIAL_OPTIONS_KEY' => json(@configuration.special_options_key), - 'SERIALIZER' => @configuration.serializer || json(nil), - 'MODULE_TYPE' => json(@configuration.module_type), - 'WRAPPER' => @configuration.esm? ? 'const __jsr = ' : '', - } - end - - def application - @configuration.application - end - - def json(string) - self.class.json(string) - end - - def named_routes - application.routes.named_routes.to_a - end - - def routes_object - return json({}) if @configuration.modern? - properties = routes_list.map do |comment, name, body| - "#{comment}#{name}: #{body}".indent(2) - end - "{\n" + properties.join(",\n\n") + "}\n" - end - - def static_exports - [:configure, :config, :serialize].map do |name| - [ - "", name, - @configuration.dts? ? - "RouterExposedMethods['#{name}']" : - "__jsr.#{name}" - ] - end - end - - def routes_export - return "" unless @configuration.modern? - [*static_exports, *routes_list].map do |comment, name, body| - "#{comment}export const #{name}#{export_separator}#{body};\n\n" - end.join - end - - def prevent_types_export - return "" unless @configuration.dts? - <<-JS -// By some reason this line prevents all types in a file -// from being automatically exported -export {}; - JS - end - - def export_separator - @configuration.dts? ? ': ' : ' = ' - end - - def routes_list - named_routes.sort_by(&:first).flat_map do |_, route| - route_helpers_if_match(route) + mounted_app_routes(route) - end - end - - def mounted_app_routes(route) - rails_engine_app = app_from_route(route) - if rails_engine_app.respond_to?(:superclass) && - rails_engine_app.superclass == Rails::Engine && !route.path.anchored - rails_engine_app.routes.named_routes.flat_map do |_, engine_route| - route_helpers_if_match(engine_route, route) - end - else - [] - end - end - - def app_from_route(route) - app = route.app - # rails engine in Rails 4.2 use additional - # ActionDispatch::Routing::Mapper::Constraints, which contain app - if app.respond_to?(:app) && app.respond_to?(:constraints) - app.app - else - app - end - end - - def route_helpers_if_match(route, parent_route = nil) - Route.new(@configuration, route, parent_route).helpers - end - module Generators end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2022-01-20 15:57:52.000000000 +0100 +++ new/metadata 2022-02-01 15:34:29.000000000 +0100 @@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: js-routes version: !ruby/object:Gem::Version - version: 2.2.1 + version: 2.2.2 platform: ruby authors: - Bogdan Gusiev autorequire: bindir: bin cert_chain: [] -date: 2022-01-20 00:00:00.000000000 Z +date: 2022-02-01 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: railties @@ -170,9 +170,11 @@ - js-routes.gemspec - lib/js-routes.rb - lib/js_routes.rb +- lib/js_routes/configuration.rb - lib/js_routes/engine.rb - lib/js_routes/generators/middleware.rb - lib/js_routes/generators/webpacker.rb +- lib/js_routes/instance.rb - lib/js_routes/middleware.rb - lib/js_routes/route.rb - lib/js_routes/version.rb