mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Switch to pnpm for JS dependencies (#28671)
This will bring significant improvements to install speed & storage requirements. For information on how it may affect you, see https://meta.discourse.org/t/324521 This commit: - removes the `yarn.lock` and replaces with `pnpm-lock.yaml` - updates workspaces to pnpm format - adjusts package dependencies to work with pnpm's stricter resolution strategy - updates Rails app to load modules from more specific node_modules directories - adds a `.pnpmfile` which automatically cleans up old yarn-managed `node_modules` directories - updates various scripts to call `pnpm` instead of `yarn` - updates patches to use pnpm's native patch system instead of patch-package - adds a patch for licensee to support pnpm
This commit is contained in:
@ -12,7 +12,7 @@ task "assets:precompile:build" do
|
||||
|
||||
raise "Unknown ember version '#{ember_version}'" if !%w[5].include?(ember_version)
|
||||
|
||||
compile_command = "CI=1 yarn --cwd app/assets/javascripts/discourse run ember build"
|
||||
compile_command = "CI=1 pnpm --dir=app/assets/javascripts/discourse ember build"
|
||||
|
||||
heap_size_limit = check_node_heap_size_limit
|
||||
|
||||
@ -158,7 +158,7 @@ def compress_node(from, to)
|
||||
base_source_map = assets_path + assets_additional_path
|
||||
|
||||
cmd = <<~SH
|
||||
yarn terser '#{assets_path}/#{from}' -m -c -o '#{to_path}' --source-map "base='#{base_source_map}',root='#{source_map_root}',url='#{source_map_url}',includeSources=true"
|
||||
pnpm terser '#{assets_path}/#{from}' -m -c -o '#{to_path}' --source-map "base='#{base_source_map}',root='#{source_map_root}',url='#{source_map_url}',includeSources=true"
|
||||
SH
|
||||
|
||||
STDERR.puts cmd
|
||||
|
@ -147,7 +147,7 @@ task "docker:test" do
|
||||
def run_or_fail_prettier(*patterns)
|
||||
if patterns.any? { |p| Dir[p].any? }
|
||||
patterns = patterns.map { |p| "'#{p}'" }.join(" ")
|
||||
run_or_fail("yarn pprettier --list-different #{patterns}")
|
||||
run_or_fail("pnpm pprettier --list-different #{patterns}")
|
||||
else
|
||||
puts "Skipping prettier. Pattern not found."
|
||||
true
|
||||
@ -156,12 +156,12 @@ task "docker:test" do
|
||||
|
||||
begin
|
||||
@good = true
|
||||
@good &&= run_or_fail("yarn install")
|
||||
@good &&= run_or_fail("pnpm install")
|
||||
|
||||
unless ENV["SKIP_LINT"]
|
||||
puts "Running linters/prettyfiers"
|
||||
puts "eslint #{`yarn eslint -v`}"
|
||||
puts "prettier #{`yarn prettier -v`}"
|
||||
puts "eslint #{`pnpm eslint -v`}"
|
||||
puts "prettier #{`pnpm prettier -v`}"
|
||||
|
||||
if ENV["SINGLE_PLUGIN"]
|
||||
@good &&= run_or_fail("bundle exec rubocop --parallel plugins/#{ENV["SINGLE_PLUGIN"]}")
|
||||
@ -171,7 +171,7 @@ task "docker:test" do
|
||||
)
|
||||
@good &&=
|
||||
run_or_fail(
|
||||
"yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern plugins/#{ENV["SINGLE_PLUGIN"]}",
|
||||
"pnpm eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern plugins/#{ENV["SINGLE_PLUGIN"]}",
|
||||
)
|
||||
|
||||
puts "Listing prettier offenses in #{ENV["SINGLE_PLUGIN"]}:"
|
||||
@ -183,10 +183,10 @@ task "docker:test" do
|
||||
else
|
||||
@good &&= run_or_fail("bundle exec rake plugin:update_all") unless ENV["SKIP_PLUGINS"]
|
||||
@good &&= run_or_fail("bundle exec rubocop --parallel") unless ENV["SKIP_CORE"]
|
||||
@good &&= run_or_fail("yarn eslint app/assets/javascripts") unless ENV["SKIP_CORE"]
|
||||
@good &&= run_or_fail("pnpm eslint app/assets/javascripts") unless ENV["SKIP_CORE"]
|
||||
@good &&=
|
||||
run_or_fail(
|
||||
"yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern plugins",
|
||||
"pnpm eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern plugins",
|
||||
) unless ENV["SKIP_PLUGINS"]
|
||||
|
||||
@good &&=
|
||||
@ -202,7 +202,7 @@ task "docker:test" do
|
||||
puts "Listing prettier offenses in core:"
|
||||
@good &&=
|
||||
run_or_fail(
|
||||
'yarn pprettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.js"',
|
||||
'pnpm pprettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.js"',
|
||||
)
|
||||
end
|
||||
|
||||
@ -210,7 +210,7 @@ task "docker:test" do
|
||||
puts "Listing prettier offenses in plugins:"
|
||||
@good &&=
|
||||
run_or_fail(
|
||||
'yarn pprettier --list-different "plugins/**/assets/stylesheets/**/*.scss" "plugins/**/assets/javascripts/**/*.{js,es6}"',
|
||||
'pnpm pprettier --list-different "plugins/**/assets/stylesheets/**/*.scss" "plugins/**/assets/javascripts/**/*.{js,es6}"',
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -304,7 +304,7 @@ task "docker:test" do
|
||||
unless ENV["SKIP_CORE"]
|
||||
@good &&=
|
||||
run_or_fail(
|
||||
"cd app/assets/javascripts/discourse && CI=1 yarn ember exam --load-balance --parallel=#{qunit_concurrency} --random",
|
||||
"cd app/assets/javascripts/discourse && CI=1 pnpm ember exam --load-balance --parallel=#{qunit_concurrency} --random",
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -46,7 +46,7 @@ def write_template(path, task_name, template)
|
||||
|
||||
File.write(output_path, "#{header}\n\n#{template}")
|
||||
puts "#{basename} created"
|
||||
system("yarn run prettier --write #{output_path}", exception: true)
|
||||
system("pnpm prettier --write #{output_path}", exception: true)
|
||||
puts "#{basename} prettified"
|
||||
end
|
||||
|
||||
@ -59,7 +59,7 @@ def write_hbs_template(path, task_name, template)
|
||||
basename = File.basename(path)
|
||||
output_path = "#{Rails.root}/app/assets/javascripts/#{path}"
|
||||
File.write(output_path, "#{header}\n#{template}")
|
||||
system("yarn run prettier --write #{output_path}", exception: true)
|
||||
system("pnpm prettier --write #{output_path}", exception: true)
|
||||
puts "#{basename} created"
|
||||
end
|
||||
|
||||
@ -204,7 +204,7 @@ end
|
||||
task "javascript:update" => "clean_up" do
|
||||
require "uglifier"
|
||||
|
||||
system("yarn install", exception: true)
|
||||
system("pnpm install", exception: true)
|
||||
|
||||
versions = {}
|
||||
start = Time.now
|
||||
|
@ -11,13 +11,13 @@ task "qunit:test", %i[timeout qunit_path filter] do |_, args|
|
||||
abort err.message
|
||||
end
|
||||
|
||||
unless system("command -v yarn >/dev/null;")
|
||||
abort "Yarn is not installed. Download from https://yarnpkg.com/lang/en/docs/install/"
|
||||
unless system("command -v pnpm >/dev/null;")
|
||||
abort "pnpm is not installed. See https://pnpm.io/installation"
|
||||
end
|
||||
|
||||
report_requests = ENV["REPORT_REQUESTS"] == "1"
|
||||
|
||||
system("yarn install", exception: true)
|
||||
system("pnpm install", exception: true)
|
||||
|
||||
# ensure we have this port available
|
||||
def port_available?(port)
|
||||
@ -108,7 +108,7 @@ task "qunit:test", %i[timeout qunit_path filter] do |_, args|
|
||||
# Bypass `ember test` - it only works properly for the `/tests` path.
|
||||
# We have to trigger a `build` manually so that JS is available for rails to serve.
|
||||
system(
|
||||
"yarn",
|
||||
"pnpm",
|
||||
"ember",
|
||||
"build",
|
||||
chdir: "#{Rails.root}/app/assets/javascripts/discourse",
|
||||
@ -124,10 +124,10 @@ task "qunit:test", %i[timeout qunit_path filter] do |_, args|
|
||||
"#{qunit_path}?#{query}&testem=1"
|
||||
end
|
||||
|
||||
cmd += %w[yarn testem ci -f testem.js]
|
||||
cmd += %w[pnpm testem ci -f testem.js]
|
||||
cmd += ["--parallel", parallel] if parallel
|
||||
else
|
||||
cmd += ["yarn", "ember", "exam", "--query", query]
|
||||
cmd += ["pnpm", "ember", "exam", "--query", query]
|
||||
cmd += ["--load-balance", "--parallel", parallel] if parallel
|
||||
cmd += ["--filter", filter] if filter
|
||||
cmd << "--write-execution-file" if ENV["QUNIT_WRITE_EXECUTION_FILE"]
|
||||
|
@ -10,7 +10,7 @@ task "smoke:test" do
|
||||
abort err.message
|
||||
end
|
||||
|
||||
system("yarn install", exception: true)
|
||||
system("pnpm install", exception: true)
|
||||
|
||||
url = ENV["URL"]
|
||||
if !url
|
||||
|
@ -9,7 +9,7 @@ def library_src
|
||||
end
|
||||
|
||||
task "svgicons:update" do
|
||||
system("yarn install", exception: true)
|
||||
system("pnpm install", exception: true)
|
||||
|
||||
dependencies = [{ source: "@fortawesome/fontawesome-free/sprites", destination: "fontawesome" }]
|
||||
|
||||
|
Reference in New Issue
Block a user