Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions .yarn/plugins/clean.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// @ts-check
const { spawnSync } = require("node:child_process");
const fs = require("node:fs");
const path = require("node:path");

/** @type {{ name: string; factory: (require: NodeRequire) => unknown; }} */
/** @type {{ name: string; factory: (require: NodeJS.Require) => unknown; }} */
module.exports = {
name: "plugin-clean",
factory: (require) => {
Expand All @@ -14,20 +11,35 @@ module.exports = {
static paths = [["clean"]];

async execute() {
const projectRoot = path.dirname(path.dirname(__dirname));
// @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");

// Remove the symlink first. On Windows, `git clean` resolves/traverses
// the symlink, causing an infinite loop.
const symlink = path.join(
projectRoot,
"example",
"node_modules",
"react-native-test-app"
const configuration = await Configuration.find(
this.context.cwd,
this.context.plugins
);
fs.rmSync(symlink, { force: true, maxRetries: 3, recursive: true });
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);
}
}

spawnSync("git", ["clean", "-dfqx", "--exclude=.yarn/cache"], {
cwd: projectRoot,
cwd: npath.fromPortablePath(project.cwd),
stdio: "inherit",
});
}
Expand Down
19 changes: 14 additions & 5 deletions .yarn/plugins/undo-bin-sorting.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
/**
* @typedef {{ values: Map<string, unknown>; }} Configuration
* @typedef {{ cwd: string; }} Workspace
* @typedef {{ cwd: string; manifest: { name: { scope?: string; name: string; } } }} Workspace
* @typedef {{ configuration: Configuration; cwd: string; workspaces: Workspace[]; }} Project
* @typedef {{ mode?: "skip-build" | "update-lockfile"; }} InstallOptions
*/
Expand All @@ -21,9 +21,9 @@
module.exports = {
name: "plugin-undo-bin-sorting",
factory: (require) => {
// @ts-expect-error Yarn internal package
const { npath } = require("@yarnpkg/fslib");
const fs = require("node:fs");
const path = require("node:path");

const asText = /** @type {const} */ ({ encoding: "utf-8" });

Expand All @@ -33,12 +33,21 @@ module.exports = {
hooks: {
/** @type {(project: Project) => void} */
validateProject(project) {
const projectRoot = npath.fromPortablePath(project.cwd);
manifestPath = path.join(projectRoot, "package.json");
orig_rawManifest = fs.readFileSync(manifestPath, asText);
for (const ws of project.workspaces) {
if (ws.manifest.name.name === "react-native-test-app") {
const packagePath = npath.fromPortablePath(ws.cwd);
manifestPath = npath.join(packagePath, "package.json");
orig_rawManifest = fs.readFileSync(manifestPath, asText);
break;
}
}
},
/** @type {(project: Project, options: InstallOptions) => void} */
afterAllInstalled() {
if (!manifestPath) {
return;
}

const rawManifest = fs.readFileSync(manifestPath, asText);
if (rawManifest === orig_rawManifest) {
return;
Expand Down
Loading