File: sprockets_patch.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (57 lines) | stat: -rw-r--r-- 1,715 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

# This backports https://github.com/rails/sprockets/pull/759 to Sprockets v3.7.2 to
# fix thread-safety issues with compiling SASS.
#
# This pull request has already been merged in Sprockets v4.2.0, but we
# don't plan on upgrading: https://gitlab.com/gitlab-org/gitlab/-/issues/373997#note_1360248557

require 'sprockets/utils'

unless Gem::Version.new(Sprockets::VERSION) == Gem::Version.new('3.7.2')
  raise 'New version of Sprockets detected. This patch can likely be removed.'
end

# rubocop:disable Style/SoleNestedConditional -- Keep the format consistent with upstream project
module Sprockets
  module Utils
    extend self

    MODULE_INCLUDE_MUTEX = Mutex.new
    private_constant :MODULE_INCLUDE_MUTEX

    # Internal: Inject into target module for the duration of the block.
    #
    # mod - Module
    #
    # Returns result of block.
    def module_include(base, mod)
      MODULE_INCLUDE_MUTEX.synchronize do
        old_methods = {}

        mod.instance_methods.each do |sym|
          old_methods[sym] = base.instance_method(sym) if base.method_defined?(sym)
        end

        unless UNBOUND_METHODS_BIND_TO_ANY_OBJECT
          base.send(:include, mod) unless base < mod
        end

        mod.instance_methods.each do |sym|
          method = mod.instance_method(sym)
          base.send(:define_method, sym, method)
        end

        yield
      ensure
        mod.instance_methods.each do |sym|
          base.send(:undef_method, sym) if base.method_defined?(sym)
        end
        old_methods.each do |sym, method|
          base.send(:define_method, sym, method)
        end
      end
    end
  end
end
# rubocop:enable Style/SoleNestedConditional