Skip to content

Commit

Permalink
Prepare for v5.2.0
Browse files Browse the repository at this point in the history
Updater script:

1. Upstream uses relative paths for import. Support that.
2. Upstream no longer inlines any sources in js/dist/.

Integration JS:

1. Popper is now referenced via `globalThis["@popperjs/core"]`
   (previously: `globalThis["Popper"]`).

Dependencies:

1. Minimum Popper version bumped to 2.11.5
  • Loading branch information
glebm committed Jul 20, 2022
1 parent 9892831 commit badd3ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion assets/javascripts/bootstrap-global-this-define.js
@@ -1,6 +1,6 @@
// Set a `globalThis` so that bootstrap components are defined on window.bootstrap instead of window.
window['bootstrap'] = {
Popper: window.Popper,
"@popperjs/core": window.Popper,
_originalGlobalThis: window['globalThis']
};
window['globalThis'] = window['bootstrap'];
2 changes: 1 addition & 1 deletion bootstrap.gemspec
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
# SassC requires Ruby 2.3.3. Also specify here to make it obvious.
s.required_ruby_version = '>= 2.3.3'

s.add_runtime_dependency 'popper_js', '>= 2.9.3', '< 3'
s.add_runtime_dependency 'popper_js', '>= 2.11.5', '< 3'

s.add_runtime_dependency 'sassc-rails', '>= 2.0.0'
s.add_runtime_dependency 'autoprefixer-rails', '>= 9.1.0'
Expand Down
13 changes: 9 additions & 4 deletions tasks/updater/js.rb
@@ -1,8 +1,9 @@
require 'pathname'
require 'tsort'

class Updater
module Js
INLINED_SRCS = %w[util/backdrop.js util/component-functions.js util/focustrap.js util/index.js util/sanitizer.js util/scrollbar.js].freeze
INLINED_SRCS = %w[].freeze

def update_javascript_assets
log_status 'Updating javascripts...'
Expand Down Expand Up @@ -49,7 +50,9 @@ def bootstrap_js_files
imports = Deps.new
# Get the imports from the ES6 files to order requires correctly.
read_files('js/src', src_files).each do |name, content|
file_imports = content.scan(%r{import *(?:[a-zA-Z]*|\{[a-zA-Z ,]*\}) *from '\./([\w/-]+)}).flatten(1).map { |f| "#{f}.js" }.uniq
file_imports = content.scan(%r{import *(?:[a-zA-Z]*|\{[a-zA-Z ,]*\}) *from '([\w/.-]+)}).flatten(1).map do |f|
Pathname.new(name).dirname.join("#{f}.js").cleanpath.to_s
end.uniq
imports.add name, *(file_imports - INLINED_SRCS)
end
imports.tsort
Expand All @@ -68,13 +71,15 @@ def initialize
end

def add(from, *tos)
(@imports[from] ||= []).push(*tos.sort)
imports = (@imports[from] ||= [])
imports.push(*tos)
imports.sort!
end

def tsort_each_child(node, &block)
node_imports = @imports[node]
if node_imports.nil?
raise "No imports found for #{node.inspect}"
raise "No imports found for #{node.inspect}\nImports:\n#{@imports.inspect}"
end
node_imports.each(&block)
end
Expand Down

0 comments on commit badd3ae

Please sign in to comment.