Skip to content

Commit

Permalink
feat(tool-workspace): make executables hoisting smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
suin committed Jun 25, 2024
1 parent 5651340 commit 5e96117
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"biome": "tools/toolbox/node_modules/@biomejs/biome/bin/biome",
"builder": "tools/toolbox/node_modules/@yarnpkg/builder/lib/cli.js",
"chokidar": "tools/toolbox/node_modules/chokidar-cli/index.js",
"husky": "tools/toolbox/node_modules/husky/bin.mjs",
"tsc": "tools/toolbox/node_modules/typescript/bin/tsc",
"tsserver": "tools/toolbox/node_modules/typescript/bin/tsserver"
}
Expand Down
27 changes: 12 additions & 15 deletions plugins/tool-workspace/bundles/@yarnpkg/plugin-tool-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,14 @@ module.exports = {
`${banner} The package ${dependencies} ${were} installed in the workspace ${pretty(toolWorkspaceIdent)}, instead of the workspace root ${name ? ` ${pretty(name)}` : ""} to keep the workspace root clean.`,
);
}
var updatingTopLevelWorkspaceBins = false;
async function updateTopLevelWorkspaceBins(project, options) {
if (updatingTopLevelWorkspaceBins) {
return;
}
const toolWorkspace = findToolWorkspace(project);
if (!toolWorkspace) {
return;
}
const { topLevelWorkspace } = project;
const oldBin = Object.fromEntries(topLevelWorkspace.manifest.bin.entries());
let reinstall = false;
let linksTools = false;
for (const [name, path] of topLevelWorkspace.manifest.bin) {
const binPath = import_fslib.ppath.join(topLevelWorkspace.cwd, path);
const symlinkPath = import_fslib.npath.toPortablePath(
Expand All @@ -275,7 +271,7 @@ module.exports = {
}
}
if (!import_fslib.xfs.existsSync(symlinkPath)) {
reinstall = true;
linksTools = true;
}
}
const bins = await import_core.scriptUtils.getWorkspaceAccessibleBinaries(toolWorkspace);
Expand All @@ -288,14 +284,14 @@ module.exports = {
}
const newBin = Object.fromEntries(topLevelWorkspace.manifest.bin.entries());
const assert = await import("node:assert/strict");
const banner = import_core.formatUtils.pretty(
project.configuration,
`[${pluginName}]`,
import_core.formatUtils.Type.ID,
);
try {
assert.deepEqual(newBin, oldBin);
} catch (error) {
const banner = import_core.formatUtils.pretty(
project.configuration,
`[${pluginName}]`,
import_core.formatUtils.Type.ID,
);
options.report.reportInfo(
import_core.MessageName.UNNAMED,
`${banner} Updating the top level workspace bins.`,
Expand All @@ -304,13 +300,14 @@ module.exports = {
for (const line of diff) {
options.report.reportInfo(import_core.MessageName.UNNAMED, `${banner} ${line}`);
}
reinstall = true;
linksTools = true;
}
if (!reinstall) {
if (!linksTools) {
return;
}
updatingTopLevelWorkspaceBins = true;
await project.install(options);
options.report.reportInfo(import_core.MessageName.UNNAMED, `${banner} Linking tools.`);
await topLevelWorkspace.persistManifest();
await project.linkEverything(options);
}
return __toCommonJS(sources_exports);
})();
Expand Down
20 changes: 8 additions & 12 deletions plugins/tool-workspace/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,14 @@ function reportMovedDependencies(project: Project, options: InstallOptions): voi
);
}

let updatingTopLevelWorkspaceBins = false;

async function updateTopLevelWorkspaceBins(project: Project, options: InstallOptions): Promise<void> {
if (updatingTopLevelWorkspaceBins) {
return;
}
const toolWorkspace = findToolWorkspace(project);
if (!toolWorkspace) {
return;
}
const { topLevelWorkspace } = project;
const oldBin = Object.fromEntries(topLevelWorkspace.manifest.bin.entries());
let reinstall = false;
let linksTools = false;
for (const [name, path] of topLevelWorkspace.manifest.bin) {
const binPath = ppath.join(topLevelWorkspace.cwd, path);
const symlinkPath = npath.toPortablePath(
Expand All @@ -242,7 +237,7 @@ async function updateTopLevelWorkspaceBins(project: Project, options: InstallOpt
}
}
if (!xfs.existsSync(symlinkPath)) {
reinstall = true;
linksTools = true;
}
}
const bins = await scriptUtils.getWorkspaceAccessibleBinaries(toolWorkspace);
Expand All @@ -252,23 +247,24 @@ async function updateTopLevelWorkspaceBins(project: Project, options: InstallOpt
}
const newBin = Object.fromEntries(topLevelWorkspace.manifest.bin.entries());
const assert = await import("node:assert/strict");
const banner = formatUtils.pretty(project.configuration, `[${pluginName}]`, formatUtils.Type.ID);
try {
// @ts-expect-error
assert.deepEqual(newBin, oldBin);
} catch (error) {
const banner = formatUtils.pretty(project.configuration, `[${pluginName}]`, formatUtils.Type.ID);
options.report.reportInfo(MessageName.UNNAMED, `${banner} Updating the top level workspace bins.`);
const diff = (error as import("node:assert/strict").AssertionError).message.split("\n").slice(3);
for (const line of diff) {
options.report.reportInfo(MessageName.UNNAMED, `${banner} ${line}`);
}
reinstall = true;
linksTools = true;
}
if (!reinstall) {
if (!linksTools) {
return;
}
updatingTopLevelWorkspaceBins = true;
await project.install(options);
options.report.reportInfo(MessageName.UNNAMED, `${banner} Linking tools.`);
await topLevelWorkspace.persistManifest();
await project.linkEverything(options);
}

declare module "@yarnpkg/core" {
Expand Down
1 change: 1 addition & 0 deletions tools/toolbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@biomejs/biome": "^1.8.2",
"@yarnpkg/builder": "^4.1.1",
"chokidar-cli": "^3.0.0",
"husky": "^9.0.11",
"typescript": "^5.5.2"
}
}
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ __metadata:
biome: tools/toolbox/node_modules/@biomejs/biome/bin/biome
builder: tools/toolbox/node_modules/@yarnpkg/builder/lib/cli.js
chokidar: tools/toolbox/node_modules/chokidar-cli/index.js
husky: tools/toolbox/node_modules/husky/bin.mjs
tsc: tools/toolbox/node_modules/typescript/bin/tsc
tsserver: tools/toolbox/node_modules/typescript/bin/tsserver
languageName: unknown
Expand All @@ -175,6 +176,7 @@ __metadata:
"@biomejs/biome": "npm:^1.8.2"
"@yarnpkg/builder": "npm:^4.1.1"
chokidar-cli: "npm:^3.0.0"
husky: "npm:^9.0.11"
typescript: "npm:^5.5.2"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -1912,6 +1914,15 @@ __metadata:
languageName: node
linkType: hard

"husky@npm:^9.0.11":
version: 9.0.11
resolution: "husky@npm:9.0.11"
bin:
husky: bin.mjs
checksum: 10c0/2c787dcf74a837fc9a4fea7da907509d4bd9a289f4ea10ecc9d86279e4d4542b0f5f6443a619bccae19e265f2677172cc2b86aae5c932a35a330cc227d914605
languageName: node
linkType: hard

"iconv-lite@npm:^0.6.2":
version: 0.6.3
resolution: "iconv-lite@npm:0.6.3"
Expand Down

0 comments on commit 5e96117

Please sign in to comment.