-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathclean.cjs
More file actions
50 lines (43 loc) · 1.62 KB
/
Copy pathclean.cjs
File metadata and controls
50 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
/** @type {{ name: string; factory: (require: NodeJS.Require) => unknown; }} */
module.exports = {
name: "plugin-clean",
factory: (require) => {
// @ts-expect-error Yarn internal package
const { BaseCommand } = require("@yarnpkg/cli");
class CleanCommand extends BaseCommand {
static paths = [["clean"]];
async execute() {
// @ts-expect-error Yarn internal package
const { Configuration, Project } = require("@yarnpkg/core");
// @ts-expect-error Yarn internal package
const { npath } = require("@yarnpkg/fslib");
const { spawnSync } = require("node:child_process");
const fs = require("node:fs");
const configuration = await Configuration.find(
this.context.cwd,
this.context.plugins
);
const { project } = await Project.find(configuration, this.context.cwd);
// Remove symlinks first. On Windows, `git clean` resolves/traverses
// symlinks, causing an infinite loop.
for (const ws of project.workspaces) {
const rntaPath = npath.join(
npath.fromPortablePath(ws.cwd),
"node_modules",
"react-native-test-app"
);
const stats = fs.lstatSync(rntaPath, { throwIfNoEntry: false });
if (stats?.isSymbolicLink()) {
fs.rmSync(rntaPath, { force: true, recursive: true });
}
}
spawnSync("git", ["clean", "-dfqx", "--exclude=.yarn/cache"], {
cwd: npath.fromPortablePath(project.cwd),
stdio: "inherit",
});
}
}
return { commands: [CleanCommand] };
},
};