mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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:
@@ -117,8 +117,8 @@ docker run -d \
|
||||
echo "Installing gems..."
|
||||
"${SCRIPTPATH}/bundle" install
|
||||
|
||||
echo "Yarn install..."
|
||||
"${SCRIPTPATH}/exec" yarn install --cwd app/assets/javascripts/discourse
|
||||
echo "pnpm install..."
|
||||
"${SCRIPTPATH}/exec" pnpm install
|
||||
|
||||
if [ "${initialize}" = "initialize" ]; then
|
||||
echo "Migrating database..."
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'pathname'
|
||||
require "pathname"
|
||||
|
||||
RAILS_ROOT = File.expand_path("../../", Pathname.new(__FILE__).realpath)
|
||||
PORT = ENV["UNICORN_PORT"] ||= "3000"
|
||||
HOSTNAME = ENV["DISCOURSE_HOSTNAME"] ||= "127.0.0.1"
|
||||
YARN_DIR = File.join(RAILS_ROOT, "app/assets/javascripts/discourse")
|
||||
CUSTOM_ARGS = ["--try", "--test", "--build", "--unicorn", "-u", "--forward-host"]
|
||||
CUSTOM_ARGS = %w[--try --test --build --unicorn -u --forward-host]
|
||||
PROXY =
|
||||
if ARGV.include?("--try")
|
||||
"https://try.discourse.org"
|
||||
@@ -46,25 +45,25 @@ if ARGV.include?("-h") || ARGV.include?("--help")
|
||||
puts "#{"--test".cyan} To run the test suite"
|
||||
puts "#{"--unicorn, -u".cyan} To run a unicorn server as well"
|
||||
puts "The rest of the arguments are passed to ember server per:", ""
|
||||
exec "yarn -s --cwd #{YARN_DIR} run ember #{command} --help"
|
||||
exec "pnpm ember #{command} --help"
|
||||
end
|
||||
|
||||
args = ["-s", "--cwd", YARN_DIR, "run", "ember", command] + (ARGV - CUSTOM_ARGS)
|
||||
args = ["--dir=app/assets/javascripts/discourse", "ember", command] + (ARGV - CUSTOM_ARGS)
|
||||
|
||||
if !args.include?("test") && !args.include?("build") && !args.include?("--proxy")
|
||||
args << "--proxy"
|
||||
args << PROXY
|
||||
end
|
||||
|
||||
# Running yarn install in the root directory will also run it for YARN_DIR via a post-install hook
|
||||
exit 1 if !system "yarn", "-s", "install", "--cwd", RAILS_ROOT
|
||||
if !system "pnpm", "--dir=#{RAILS_ROOT}", "install"
|
||||
abort "pnpm is not installed. run `npm install -g pnpm`" if !system("command -v pnpm >/dev/null;")
|
||||
exit 1
|
||||
end
|
||||
|
||||
yarn_env = {
|
||||
pnpm_env = {
|
||||
"TERM" => "dumb", # simple output from ember-cli, so we can parse/forward it more easily
|
||||
}
|
||||
if ARGV.include?("--forward-host")
|
||||
yarn_env["FORWARD_HOST"] = "true"
|
||||
end
|
||||
pnpm_env["FORWARD_HOST"] = "true" if ARGV.include?("--forward-host")
|
||||
|
||||
if ARGV.include?("-u") || ARGV.include?("--unicorn")
|
||||
unicorn_env = { "DISCOURSE_PORT" => ENV["DISCOURSE_PORT"] || "4200" }
|
||||
@@ -72,12 +71,13 @@ if ARGV.include?("-u") || ARGV.include?("--unicorn")
|
||||
ember_cli_pid = nil
|
||||
|
||||
Thread.new do
|
||||
require 'open3'
|
||||
Open3.popen2e(yarn_env, "yarn", *args.to_a.flatten) do |i, oe, t|
|
||||
require "open3"
|
||||
Open3.popen2e(pnpm_env, "pnpm", *args.to_a.flatten) do |i, oe, t|
|
||||
ember_cli_pid = t.pid
|
||||
puts "Ember CLI running on PID: #{ember_cli_pid}"
|
||||
oe.each do |line|
|
||||
if line.include?("\e[32m200\e") || line.include?("\e[36m304\e[0m") || line.include?("POST /message-bus")
|
||||
if line.include?("\e[32m200\e") || line.include?("\e[36m304\e[0m") ||
|
||||
line.include?("POST /message-bus")
|
||||
# skip 200s and 304s and message bus
|
||||
else
|
||||
puts "[ember-cli] #{line}"
|
||||
@@ -102,5 +102,5 @@ if ARGV.include?("-u") || ARGV.include?("--unicorn")
|
||||
Process.kill("TERM", ember_cli_pid)
|
||||
end
|
||||
else
|
||||
exec(yarn_env, "yarn", *args.to_a.flatten)
|
||||
exec(pnpm_env, "pnpm", *args.to_a.flatten)
|
||||
end
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
yarn --cwd "`dirname $0`"/../app/assets/javascripts/discourse "$@"
|
||||
Reference in New Issue
Block a user