2026-02-01 08:57:18 +08:00
|
|
|
const fs = require("node:fs");
|
|
|
|
|
const path = require("node:path");
|
|
|
|
|
|
2026-02-05 22:29:59 +08:00
|
|
|
const root = path.join(__dirname, "../../");
|
|
|
|
|
|
2026-02-01 08:57:18 +08:00
|
|
|
function setupVscode() {
|
2026-06-10 23:58:54 +08:00
|
|
|
const vscodeDirectory = path.join(root, ".vscode/");
|
|
|
|
|
const settingsFile = path.join(vscodeDirectory, "settings.json");
|
2026-02-01 08:57:18 +08:00
|
|
|
const settingsExampleFile = path.join(
|
2026-06-10 23:58:54 +08:00
|
|
|
vscodeDirectory,
|
|
|
|
|
"settings.example.json",
|
2026-02-01 08:57:18 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(settingsFile) || !fs.existsSync(settingsExampleFile)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.copyFileSync(settingsExampleFile, settingsFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function buildBabelCodeFrameForTest() {
|
|
|
|
|
const { buildBabelCodeFrameForTest } =
|
|
|
|
|
await import("../../scripts/build-babel-code-frame-for-test.js");
|
|
|
|
|
|
|
|
|
|
await buildBabelCodeFrameForTest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
name: "plugin-prepare",
|
|
|
|
|
factory: () => ({
|
|
|
|
|
hooks: {
|
2026-06-10 23:58:54 +08:00
|
|
|
async afterAllInstalled({ cwd: rawCwd }) {
|
|
|
|
|
console.log(`Yarn plugin "prepare" running in "${rawCwd}".`);
|
|
|
|
|
|
|
|
|
|
let cwd = rawCwd;
|
|
|
|
|
|
|
|
|
|
if (process.platform === "win32" && cwd.startsWith("/")) {
|
|
|
|
|
cwd = cwd.slice(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (path.join(cwd, "./") !== root) {
|
|
|
|
|
console.log(
|
|
|
|
|
`Yarn plugin "prepare" skipped, yarn command not running in "${root}".`,
|
|
|
|
|
);
|
2026-02-05 22:29:59 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 08:57:18 +08:00
|
|
|
setupVscode();
|
2026-02-02 16:04:17 +08:00
|
|
|
try {
|
|
|
|
|
await buildBabelCodeFrameForTest();
|
|
|
|
|
} catch {}
|
2026-02-01 08:57:18 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
};
|