bundler-as_of 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1bfce3407202aaf89329a360e43325983dfc934b0513dab48db6e192198c40a6
4
+ data.tar.gz: 6c792de9b55a63ec0b7fdb4ad025e46e77c8336fc0e1e938924c9f0a8ef87a49
5
+ SHA512:
6
+ metadata.gz: 2f54bd7c187a5837a4b39e8bd21b6cfff7c4128c86d6552f275f867ebac3b7c2e2c2674e8ed800d24c5ab0d112d751c5b5ae48855b10602e5c4d766333996457
7
+ data.tar.gz: fab4d6ed5775fa363dca6b0f2afdb9fcd81df06df323f42f6771e93f36f7f081dab5495a289bbc9a02415f1fd1f8f410d84f0c9ff06aa303da8a3a3f1193a565
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+ inherit_gem:
5
+ rubocop-shopify: rubocop.yml
6
+
7
+ AllCops:
8
+ NewCops: enable
9
+ TargetRubyVersion: 2.6
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mike.dalessio@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in bundler-as_of.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Mike Dalessio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # Bundler::AsOf
2
+
3
+ Bundler::AsOf allows you to `bundle install` dependencies as of a certain date in the past.
4
+
5
+ This is intended for use with old projects that have not been well-maintained and that won't bundle or won't run today using recent releases (but were able to be bundled on some date in the past).
6
+
7
+
8
+ ## Inspiration
9
+
10
+ Inspiration for this came from [@Schwad](https://github.com/Schwad) and his [`portal_gun`](https://github.com/Schwad/portal_gun) project. Also a bunch of old mdpress presentations that I have sitting around in Dropbox were motivating.
11
+
12
+
13
+ ## How Does It Work?
14
+
15
+ `bundler-as_of` is a [Bundler plugin](https://bundler.io/bundle_plugin.html) that uses a `before-install-all` hook to modify the dependencies that Bundler installs and writes to the lockfile.
16
+
17
+ It traverses the full dependency graph (including transitive dependencies) and whenever possible, resolves the version to the latest release that both:
18
+
19
+ 1. satisfies the version requirements specified (if any)
20
+ 2. existed as-of the date specified
21
+
22
+ So, more specifically, `bundler-as_of` will try to avoid any releases that were made _after_ the specified date.
23
+
24
+ Occasionally, `bundler-as_of` may not be able to find a dependency that meets both of these criteria, and in that case will print a warning and will not modify the dependency.
25
+
26
+
27
+ ## Usage
28
+
29
+ First, install this gem as a bundler plugin. I haven't packaged a gem yet, so the best thing to do right now is bundle from git:
30
+
31
+ ``` sh
32
+ bundle plugin install --git=https://github.com/flavorjones/bundler-as_of --branch=main bundler-as_of
33
+ ```
34
+
35
+ (Note that bundler plugins are project-specific and are installed into the `.bundler` subdirectory.)
36
+
37
+ Second, pick a date and run `bundle install`:
38
+
39
+ ``` ruby
40
+ BUNDLE_AS_OF=2013-11-11 bundle install
41
+ ```
42
+
43
+ You should see something like this as the output:
44
+
45
+ ``` text
46
+ $ BUNDLE_AS_OF=2013-09-22 bundle install
47
+ NOTE: bundler-as_of: bundling dependencies as of 2013-09-22 ...
48
+ NOTE: bundler-as_of: resolving xml-focus [">= 0"] to 0.0.1 released on 2013-08-07
49
+ NOTE: bundler-as_of: resolving rake [">= 0"] to 10.1.0 released on 2013-06-20
50
+ NOTE: bundler-as_of: resolving rspec [">= 0"] to 2.14.1 released on 2013-07-11
51
+ NOTE: bundler-as_of: resolving nokogiri [">= 0"] to 1.6.0 released on 2013-06-10
52
+ NOTE: bundler-as_of: resolving rspec-core ["~> 2.14.0"] to 2.14.5 released on 2013-08-14
53
+ NOTE: bundler-as_of: resolving rspec-expectations ["~> 2.14.0"] to 2.14.2 released on 2013-08-15
54
+ NOTE: bundler-as_of: resolving rspec-mocks ["~> 2.14.0"] to 2.14.3 released on 2013-08-09
55
+ NOTE: bundler-as_of: resolving mini_portile ["~> 0.5.0"] to 0.5.1 released on 2013-07-07
56
+ NOTE: bundler-as_of: resolving diff-lcs ["< 2.0", ">= 1.1.3"] to 1.2.4 released on 2013-04-21
57
+ Fetching gem metadata from https://rubygems.org/.......
58
+ Resolving dependencies...
59
+ Using rake 10.1.0
60
+ Using bundler 2.2.30
61
+ Using diff-lcs 1.2.4
62
+ Using mini_portile 0.5.1
63
+ Using rspec-mocks 2.14.3
64
+ Using rspec-core 2.14.5
65
+ Using rspec-expectations 2.14.2
66
+ Using nokogiri 1.6.0
67
+ Using rspec 2.14.1
68
+ Using xml-focus 0.0.1
69
+ Bundle complete! 9 Gemfile dependencies, 10 gems now installed.
70
+ Use `bundle info [gemname]` to see where a bundled gem is installed.
71
+ ```
72
+
73
+ ## Tips
74
+
75
+ Once you find a date that works, you may want to use something like [`direnv`](https://direnv.net/) to "remember" the date by automatically loading that environment variable when you `cd` into the project directory.
76
+
77
+
78
+ ## This Gem Won't Help You With ...
79
+
80
+ ### ... finding and using the right Ruby version
81
+
82
+ `bundler-as_of` only resolves gem dependencies as of the given date, and doesn't do anything (yet?) to make sure you're using a version of Ruby that existed on that date.
83
+
84
+ A manual alternative is to use a table of [Ruby version release dates](https://www.ruby-lang.org/en/downloads/releases/) and then run everything in the [Ruby dockerhub OCI images](https://hub.docker.com/_/ruby) for the particular version you want to use.
85
+
86
+
87
+ ## Contributing
88
+
89
+ Bug reports and pull requests are welcome on GitHub at https://github.com/flavorjones/bundler-as_of. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/flavorjones/bundler-as_of/blob/main/CODE_OF_CONDUCT.md).
90
+
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
95
+
96
+
97
+ ## Code of Conduct
98
+
99
+ Everyone interacting in the Bundler::AsOf project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/flavorjones/bundler-as_of/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: [:test, :rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "bundler/as_of"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bundler
4
+ module AsOf
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "open-uri"
5
+ require "json"
6
+ require "set"
7
+
8
+ module Bundler
9
+ module AsOf
10
+ BUNDLE_AS_OF = "BUNDLE_AS_OF"
11
+
12
+ class InstallModifier
13
+ def initialize
14
+ @modified_dependencies = {} # name => modified Bundler::Dependency
15
+ end
16
+
17
+ def modify_dependencies(dependencies)
18
+ if as_of_date.nil?
19
+ warn("NOTE: bundler-as_of is installed but #{BUNDLE_AS_OF} is not set")
20
+ return
21
+ end
22
+ warn("NOTE: bundler-as_of: bundling dependencies as of #{as_of_date} ...")
23
+
24
+ resolve_transitive_dependencies(dependencies)
25
+
26
+ dependencies.clear
27
+ @modified_dependencies.each do |name, dep|
28
+ dependencies << dep
29
+ end
30
+ end
31
+
32
+ def resolve_transitive_dependencies(dependencies)
33
+ queued = dependencies.dup
34
+
35
+ while !queued.empty?
36
+ resolving = queued
37
+ queued = []
38
+
39
+ resolving.each do |dependency|
40
+ if dependency.name == "bundler"
41
+ raise(BundlerError, "ERROR: please remove bundler from the Gemfile or gemspec")
42
+ end
43
+
44
+ next if @modified_dependencies.key?(dependency.name)
45
+
46
+ orig_req = dependency.requirements_list
47
+ release = VersionFinder.new(dependency, as_of_date).resolve
48
+ if release
49
+ warn("NOTE: bundler-as_of: resolving #{dependency.name} #{orig_req} to #{release.version} released on #{release.date}")
50
+ @modified_dependencies[release.name] = Bundler::Dependency.new(release.name, release.version)
51
+
52
+ release.dependencies.each do |transitive_name, transitive_req|
53
+ transitive_dep = Gem::Dependency.new(transitive_name, transitive_req.split(","))
54
+ queued << transitive_dep
55
+ end
56
+ else
57
+ warn("NOTE: bundler-as_of: WARNING: could not resolve #{dependency.name} to a version matching #{dependency.requirements_list} from #{as_of_date}")
58
+ @modified_dependencies[dependency.name] = dependency
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def as_of_date
65
+ return nil if as_of_env.nil?
66
+
67
+ @as_of_date ||= begin
68
+ Date.parse(as_of_env)
69
+ rescue Date::Error
70
+ raise(BundlerError, "ERROR: bundler-as_of could not parse #{BUNDLE_AS_OF}=#{as_of_env.inspect}")
71
+ end
72
+ end
73
+
74
+ def as_of_env
75
+ ENV[BUNDLE_AS_OF]
76
+ end
77
+ end
78
+
79
+ class VersionFinder
80
+ def initialize(dependency, as_of_date)
81
+ @dependency = dependency
82
+ @as_of_date = as_of_date
83
+ end
84
+
85
+ def resolve
86
+ releases.each do |release|
87
+ next if release.prerelease
88
+ return release if @dependency.requirement.satisfied_by?(release.version)
89
+ end
90
+ nil
91
+ end
92
+
93
+ def releases
94
+ gem_releases
95
+ .select { |r| r.date <= @as_of_date }
96
+ .sort_by { |r| [r.date, r.version] }
97
+ .reverse
98
+ end
99
+
100
+ def gem_releases
101
+ @gem_releases ||=
102
+ JSON.parse(::URI.parse(gem_url).open.read)
103
+ .map { |r| ReleaseWrapper.new(@dependency.name, r) }
104
+ end
105
+
106
+ def gem_url
107
+ @gem_url ||= "https://rubygems.org/api/v1/versions/#{@dependency.name}.json"
108
+ end
109
+ end
110
+
111
+ class ReleaseWrapper
112
+ attr_reader :name, :version, :date, :prerelease
113
+ def initialize(name, release_json)
114
+ @name = name
115
+ @version = Gem::Version.new(release_json["number"])
116
+ @date = Date.parse(release_json["created_at"])
117
+ @prerelease = release_json["prerelease"]
118
+ end
119
+
120
+ def to_s
121
+ [name, version.to_s, date.to_s, prerelease, dependencies.to_s].to_s
122
+ end
123
+
124
+ def dependencies
125
+ gem_info.find { |info| info[:number] == version.to_s }[:dependencies] || []
126
+ end
127
+
128
+ def gem_info
129
+ @gem_info ||= Marshal.load(::URI.parse(gem_url).open.read)
130
+ end
131
+
132
+ def gem_url
133
+ @gem_url ||= "https://rubygems.org/api/v1/dependencies?gems=#{name}"
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ Bundler::Plugin.add_hook("before-install-all") do |dependencies|
140
+ Bundler::AsOf::InstallModifier.new.modify_dependencies(dependencies)
141
+ end
142
+
143
+ require_relative "as_of/version"
data/plugins.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/as_of"
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundler-as_of
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Dalessio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop-minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-shopify
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ description: |2
56
+ Resolve gem dependencies as-of a date in the past. Intended to resurrect older projects with
57
+ out-of-date dependencies.
58
+ email:
59
+ - mike.dalessio@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".rubocop.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/bundler/as_of.rb
73
+ - lib/bundler/as_of/version.rb
74
+ - plugins.rb
75
+ homepage: https://github.com/flavorjones/bundler-as_of
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ homepage_uri: https://github.com/flavorjones/bundler-as_of
80
+ rubygems_mfa_required: 'true'
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.6.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.2.32
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Resolve gem dependencies as-of a date in the past.
100
+ test_files: []