2024-09-03 05:51:07 -04:00
|
|
|
const fs = require("fs");
|
2024-09-12 08:45:25 -04:00
|
|
|
const { execSync, execFileSync } = require("child_process");
|
2024-09-03 05:51:07 -04:00
|
|
|
|
2024-09-12 08:45:25 -04:00
|
|
|
const discourseRoot = __dirname;
|
|
|
|
|
|
|
|
if (fs.existsSync(`${discourseRoot}/node_modules/.yarn-integrity`)) {
|
2024-09-03 05:51:07 -04:00
|
|
|
console.log(
|
|
|
|
"Detected yarn-managed node_modules. Performing one-time cleanup..."
|
|
|
|
);
|
|
|
|
|
|
|
|
// Delete entire contents of all node_modules directories
|
|
|
|
// But keep the directories themselves, in case they are volume mounts (e.g. in devcontainer)
|
|
|
|
execSync(
|
2024-09-12 08:45:25 -04:00
|
|
|
`find ${discourseRoot}/node_modules ${discourseRoot}/app/assets/javascripts/*/node_modules -mindepth 1 -maxdepth 1 -exec rm -rf {} +`
|
2024-09-03 05:51:07 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
console.log("cleanup done");
|
|
|
|
}
|
2024-09-12 08:45:25 -04:00
|
|
|
|
|
|
|
const pluginBase = `${discourseRoot}/plugins/`;
|
|
|
|
const cwd = process.cwd();
|
|
|
|
const pluginName =
|
|
|
|
cwd.startsWith(pluginBase) && cwd.replace(pluginBase, "").split("/", 2)[0];
|
|
|
|
|
|
|
|
if (
|
|
|
|
pluginName &&
|
|
|
|
fs.existsSync(`${discourseRoot}/plugins/${pluginName}/package.json`) &&
|
|
|
|
!process.argv.includes("--ignore-workspace")
|
|
|
|
) {
|
|
|
|
console.log(
|
|
|
|
"> pnpm was run inside a plugin directory. Re-executing with --ignore-workspace..."
|
|
|
|
);
|
|
|
|
|
2024-11-08 12:54:22 -05:00
|
|
|
const indexOfPnpm = process.argv.findIndex((a) => a.endsWith("pnpm"));
|
|
|
|
const newArgs = [...process.argv];
|
|
|
|
newArgs.splice(indexOfPnpm + 1, 0, "--ignore-workspace");
|
|
|
|
|
2024-09-12 08:45:25 -04:00
|
|
|
try {
|
2024-11-08 12:54:22 -05:00
|
|
|
execFileSync(newArgs[0], newArgs.slice(1), {
|
|
|
|
stdio: "inherit",
|
|
|
|
});
|
2024-09-12 08:45:25 -04:00
|
|
|
} catch (e) {
|
|
|
|
if (e.status) {
|
|
|
|
process.exit(e.status);
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
process.exit(0);
|
|
|
|
}
|