DEV: Merge root JS packages (#25857)

Before this commit, we had a yarn package set up in the root directory and also in `app/assets/javascripts`. That meant two `yarn install` calls and two `node_modules` directories. This commit merges them both into the root location, and updates references to node_modules.

A previous attempt can be found at https://github.com/discourse/discourse/pull/21172. This commit re-uses that script to merge the `yarn.lock` files.

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
David Taylor 2024-02-26 13:45:58 +00:00 committed by GitHub
parent b3a1199493
commit 588a79c80c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 8863 additions and 11882 deletions

View File

@ -52,13 +52,25 @@ updates:
- "railties"
- "sprockets-rails"
- package-ecosystem: "npm"
directory: "/app/assets/javascripts/"
directory: "/"
schedule:
interval: daily
time: "08:00"
timezone: Australia/Sydney
open-pull-requests-limit: 20
versioning-strategy: increase
ignore: # These are all vendored so need to be updated manually. See lib/tasks/javascript.rake
- dependency-name: "ace-builds"
- dependency-name: "@json-editor/json-editor"
- dependency-name: "chart.js"
- dependency-name: "chartjs-plugin-datalabels"
- dependency-name: "diffhtml"
- dependency-name: "magnific-popup"
- dependency-name: "pikaday"
- dependency-name: "moment"
- dependency-name: "moment-timezone"
- dependency-name: "@discourse/moment-timezon-names-translations"
- dependency-name: "squoosh"
groups:
babel:
patterns:

View File

@ -77,9 +77,3 @@ jobs:
yarn global add licensee
yarn global upgrade licensee
licensee --errors-only
- name: Check Ember CLI Workspace Licenses
if: ${{ !cancelled() }}
working-directory: ./app/assets/javascripts
run: |
licensee --errors-only

View File

@ -5,17 +5,38 @@
"CC0-1.0",
"CC-BY-3.0",
"CC-BY-4.0",
"Apache-2.0 WITH LLVM-exception"
"Apache-2.0 WITH LLVM-exception",
"ISC"
]
},
"packages": {
"@fortawesome/fontawesome-free": "*",
"@glimmer/interfaces": "*",
"@glimmer/syntax": "*",
"@jspreadsheet/formula": "2.0.2",
"cli-table": "0.3.11",
"component-bind": "1.0.0",
"component-inherit": "0.0.3",
"duplex": "1.0.0",
"ember-template-lint-plugin-discourse": "*",
"glob": "3.1.21",
"indexof": "0.0.1",
"inherits": "1.0.2",
"jsonify": "0.0.1",
"jspreadsheet-ce": "4.13.4",
"line-stream": "0.0.0",
"messageformat": "0.1.5",
"regenerator-transform": "0.10.1",
"source-map": "0.1.43",
"sourcemap-validator": "1.1.1",
"spawn-command": "0.0.2",
"squoosh": "2.0.0",
"taffydb": "2.6.2"
},
"corrections": true
"corrections": true,
"ignore": [
{
"author": "Discourse"
}
]
}

View File

@ -1,35 +0,0 @@
{
"licenses": {
"blueOak": "bronze",
"spdx": [
"CC0-1.0",
"CC-BY-3.0",
"CC-BY-4.0",
"Apache-2.0 WITH LLVM-exception",
"ISC"
]
},
"packages": {
"cli-table": "0.3.11",
"component-bind": "1.0.0",
"component-inherit": "0.0.3",
"duplex": "1.0.0",
"glob": "3.1.21",
"indexof": "0.0.1",
"inherits": "1.0.2",
"jsonify": "0.0.1",
"line-stream": "0.0.0",
"messageformat": "0.1.5",
"regenerator-transform": "0.10.1",
"source-map": "0.1.43",
"sourcemap-validator": "1.1.1",
"jspreadsheet-ce": "4.13.4",
"@jspreadsheet/formula": "2.0.2"
},
"corrections": true,
"ignore": [
{
"author": "Discourse"
}
]
}

View File

@ -17,11 +17,11 @@ module.exports = function generateWorkboxTree() {
];
const nodes = workboxDeps.map((name) => {
return funnel(`../node_modules/${name}/build`);
return funnel(`../../../../node_modules/${name}/build`);
});
const versions = workboxDeps.map((name) => {
return require(`../../node_modules/${name}/package.json`).version;
return require(`../../../../../node_modules/${name}/package.json`).version;
});
// Normally Sprockets will create a cachebuster per-file. In this case we need it at the directory level since

View File

@ -1,33 +0,0 @@
{
"private": true,
"scripts": {
"postinstall": "./run-patch-package"
},
"workspaces": [
"admin",
"bootstrap-json",
"deprecation-silencer",
"dialog-holder",
"discourse",
"discourse-common",
"discourse-hbr",
"discourse-i18n",
"discourse-markdown-it",
"discourse-plugins",
"discourse-widget-hbs",
"ember-cli-progress-ci",
"ember-production-deprecations",
"float-kit",
"pretty-text",
"select-kit",
"theme-transpiler",
"truth-helpers"
],
"resolutions": {
"**/unset-value": "2.0.1"
},
"devDependencies": {
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0"
}
}

View File

@ -50,7 +50,7 @@ esbuild
bundle: true,
minify: true,
alias: {
util: "./app/assets/javascripts/node_modules/@zxing/text-encoding",
util: "./node_modules/@zxing/text-encoding",
},
define: {
process: `{ "env": {} }`,

File diff suppressed because it is too large Load Diff

View File

@ -28,12 +28,7 @@ class ThemeSettingsMigrationsRunner
def self.loader_js_lib_content
@loader_js_lib_content ||=
File.read(
File.join(
Rails.root,
"app/assets/javascripts/node_modules/loader.js/dist/loader/loader.js",
),
)
File.read(File.join(Rails.root, "node_modules/loader.js/dist/loader/loader.js"))
end
def initialize(theme, limit: 100, timeout: 100, memory: 2.megabytes)

View File

@ -27,7 +27,7 @@
<meta name="discourse/config/environment" content="<%=u discourse_config_environment(testing: true) %>" />
<style>
<%= File.read("#{Rails.root}/app/assets/javascripts/node_modules/qunit/qunit/qunit.css").html_safe %>
<%= File.read("#{Rails.root}/node_modules/qunit/qunit/qunit.css").html_safe %>
</style>
<%= discourse_stylesheet_link_tag(:desktop, theme_id: nil) %>

View File

@ -41,8 +41,7 @@ class EmberCli < ActiveSupport::CurrentAttributes
def self.ember_version
@version ||=
begin
ember_source_package_raw =
File.read("#{Rails.root}/app/assets/javascripts/node_modules/ember-source/package.json")
ember_source_package_raw = File.read("#{Rails.root}/node_modules/ember-source/package.json")
JSON.parse(ember_source_package_raw)["version"]
end
end

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
module HighlightJs
HIGHLIGHTJS_DIR ||= "#{Rails.root}/app/assets/javascripts/node_modules/@highlightjs/cdn-assets/"
HIGHLIGHTJS_DIR ||= "#{Rails.root}/node_modules/@highlightjs/cdn-assets/"
VERSION ||= 1 # bump to invalidate caches following core changes
def self.languages

View File

@ -332,9 +332,7 @@ module JsLocaleHelper
@ctx ||=
begin
ctx = MiniRacer::Context.new(timeout: 15_000, ensure_gc_after_idle: 2000)
ctx.load(
"#{Rails.root}/app/assets/javascripts/node_modules/messageformat/messageformat.js",
)
ctx.load("#{Rails.root}/node_modules/messageformat/messageformat.js")
ctx
end
)

View File

@ -66,10 +66,12 @@ module PrettyText
end
root_path = "#{Rails.root}/app/assets/javascripts"
ctx.load("#{root_path}/node_modules/loader.js/dist/loader/loader.js")
ctx.load("#{root_path}/node_modules/markdown-it/dist/markdown-it.js")
node_modules = "#{Rails.root}/node_modules"
md_node_modules = "#{Rails.root}/app/assets/javascripts/discourse-markdown-it/node_modules"
ctx.load("#{node_modules}/loader.js/dist/loader/loader.js")
ctx.load("#{md_node_modules}/markdown-it/dist/markdown-it.js")
ctx.load("#{root_path}/handlebars-shim.js")
ctx.load("#{root_path}/node_modules/xss/dist/xss.js")
ctx.load("#{node_modules}/xss/dist/xss.js")
ctx.load("#{Rails.root}/lib/pretty_text/vendor-shims.js")
ctx_load_directory(

View File

@ -1,6 +1,6 @@
{
"name": "discourse",
"version": "1.0.0",
"private": true,
"repository": "https://github.com/discourse/discourse",
"author": "Discourse",
"license": "GPL-2.0-only",
@ -32,7 +32,9 @@
"magnific-popup": "1.1.0",
"moment": "2.29.4",
"moment-timezone": "0.5.43",
"patch-package": "^8.0.0",
"pikaday": "1.8.2",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.8.8",
"puppeteer-core": "^21.0.3",
"squoosh": "discourse/squoosh#dc9649d",
@ -52,7 +54,30 @@
"lttf:ignore": "lint-to-the-future ignore",
"lttf:output": "lint-to-the-future output -o ./lint-progress/",
"lint-progress": "yarn lttf:output && npx html-pages ./lint-progress --no-cache",
"postinstall": "yarn --cwd app/assets/javascripts $(node -e 'const argv = JSON.parse(process.env.npm_config_argv).original; const passthrough = [`--frozen-lockfile`, `-s`].filter(arg => argv.includes(arg)); console.log(passthrough.join(` `));')"
"postinstall": "./app/assets/javascripts/run-patch-package && rm -rf app/assets/javascripts/node_modules"
},
"workspaces": [
"app/assets/javascripts/admin",
"app/assets/javascripts/bootstrap-json",
"app/assets/javascripts/deprecation-silencer",
"app/assets/javascripts/dialog-holder",
"app/assets/javascripts/discourse",
"app/assets/javascripts/discourse-common",
"app/assets/javascripts/discourse-hbr",
"app/assets/javascripts/discourse-i18n",
"app/assets/javascripts/discourse-markdown-it",
"app/assets/javascripts/discourse-plugins",
"app/assets/javascripts/discourse-widget-hbs",
"app/assets/javascripts/ember-cli-progress-ci",
"app/assets/javascripts/ember-production-deprecations",
"app/assets/javascripts/float-kit",
"app/assets/javascripts/pretty-text",
"app/assets/javascripts/select-kit",
"app/assets/javascripts/theme-transpiler",
"app/assets/javascripts/truth-helpers"
],
"resolutions": {
"**/unset-value": "2.0.1"
},
"engines": {
"node": "16.* || >= 18",

View File

@ -159,11 +159,7 @@ RSpec.describe DiscourseJsProcessor do
let(:mini_racer) do
ctx = MiniRacer::Context.new
ctx.eval(
File.open(
"#{Rails.root}/app/assets/javascripts/node_modules/handlebars/dist/handlebars.js",
).read,
)
ctx.eval(File.open("#{Rails.root}/node_modules/handlebars/dist/handlebars.js").read)
ctx.eval(helpers)
ctx
end

View File

@ -4,7 +4,7 @@ require "mini_racer"
RSpec.describe JsLocaleHelper do
let(:v8_ctx) do
node_modules = "#{Rails.root}/app/assets/javascripts/node_modules/"
node_modules = "#{Rails.root}/node_modules/"
transpiler = DiscourseJsProcessor::Transpiler.new
discourse_i18n =

9181
yarn.lock

File diff suppressed because it is too large Load Diff