Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update indirect dependencies in yarn.lock. `ruby rejuvenation.rb & yarn install`
#!/usr/bin/env ruby
# USAGE: `$> ruby rejuvenation.rb`
require 'json'
EXTRACT_DEPENDENCY_NAME = /"?(.+?)@.+?"?(?:,\s+|\Z)/.freeze
EXTRACT_DEPENDENCY_DETAILS = /(^((?!= ).*?):\n.*?(?:\n\n|\Z))/m.freeze
def direct_dependencies_names
package_json = JSON.parse(File.open('package.json').read)
direct_dependencies = package_json.fetch_values('dependencies', 'devDependencies', 'peerDependencies') { }
direct_dependencies.compact.inject([]) { |memo, v| memo.concat(v.keys) }
end
@dependencies = direct_dependencies_names
yarn_lock_content = File.open('yarn.lock').read
File.open('yarn.lock', 'w') do |file|
yarn_lock_content.scan(EXTRACT_DEPENDENCY_DETAILS).map do |dependency_block|
direct_dep = @dependencies.include?(dependency_block[1].match(EXTRACT_DEPENDENCY_NAME).to_a[1])
file.puts dependency_block[0] if direct_dep
end
end
`yarn install`
$> curl "https://gist.githubusercontent.com/pftg/fa8fe4ca2bb4638fbd19324376487f42/raw/f9056244c416d2f56d6d94290e5ecef5960abf66/rejuvenation.rb" | ruby

or

$> ruby rejuvenation.rb
$> yarn install
@pftg

This comment has been minimized.

Copy link
Owner Author

@pftg pftg commented Dec 24, 2019

curl https://gist.githubusercontent.com/pftg/fa8fe4ca2bb4638fbd19324376487f42/raw/88575f171703d14e26f8348954f41bcdc1ad78b3/rejuvenation.rb | ruby > yarn.lock.new

@Ibadichan

This comment has been minimized.

Copy link

@Ibadichan Ibadichan commented Feb 15, 2020

can you rewrite this script in JS, please?

@pftg

This comment has been minimized.

Copy link
Owner Author

@pftg pftg commented Feb 15, 2020

👍

@pftg

This comment has been minimized.

Copy link
Owner Author

@pftg pftg commented May 19, 2020

curl "https://gist.githubusercontent.com/pftg/fa8fe4ca2bb4638fbd19324376487f42/raw/f9056244c416d2f56d6d94290e5ecef5960abf66/rejuvenation.rb" | ruby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment