mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00

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>
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
const crypto = require("crypto");
|
|
const mergeTrees = require("broccoli-merge-trees");
|
|
const funnel = require("broccoli-funnel");
|
|
|
|
// Bump to cache-bust if there are any changes to the workbox compilation logic
|
|
// which are not caused by a simple workbox version bump
|
|
const COMPILER_VERSION = 2;
|
|
|
|
module.exports = function generateWorkboxTree() {
|
|
const workboxDeps = [
|
|
"workbox-sw",
|
|
"workbox-routing",
|
|
"workbox-core",
|
|
"workbox-strategies",
|
|
"workbox-expiration",
|
|
"workbox-cacheable-response",
|
|
];
|
|
|
|
const nodes = workboxDeps.map((name) => {
|
|
return funnel(`../../../../node_modules/${name}/build`);
|
|
});
|
|
|
|
const versions = workboxDeps.map((name) => {
|
|
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
|
|
// workbox is responsible for loading its own files and doesn't support customized names per-file.
|
|
// Sprockets' default behaviour for these files is disabled via freedom_patches/sprockets.rb.
|
|
const versionHash = crypto
|
|
.createHash("md5")
|
|
.update(
|
|
`${versions.join("|")}|${COMPILER_VERSION}|${
|
|
process.env["DISCOURSE_ASSET_URL_SALT"] || ""
|
|
}`
|
|
)
|
|
.digest("hex");
|
|
|
|
return funnel(mergeTrees(nodes), {
|
|
destDir: `assets/workbox-${versionHash}`,
|
|
});
|
|
};
|