Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: patch workspace modules links
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { readdir, symlink, unlink } from "fs/promises"; | ||
import { join } from "path"; | ||
import { safeReadLink, safeStat } from "~/util/fs"; | ||
import { parsePackageFile } from "~/util/package"; | ||
import { getPackageNames, packagesPath } from "~/util/workspace"; | ||
|
||
async function patch(packagePath: string) { | ||
const wsPath = `${packagePath}/node_modules/@suid`; | ||
if (!(await safeStat(wsPath))) return; | ||
const dependencyNames = await readdir(wsPath); | ||
for (const dependencyName of dependencyNames) { | ||
const dependencyPath = join(wsPath, dependencyName); | ||
const link = await safeReadLink(dependencyPath); | ||
if (!link) continue; | ||
const pkg = await parsePackageFile(join(dependencyPath, "package.json")); | ||
if (pkg.publishConfig?.directory) { | ||
await unlink(dependencyPath); | ||
await symlink( | ||
join(link, pkg.publishConfig.directory), | ||
dependencyPath, | ||
"junction" | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @link https://github.com/pnpm/pnpm/issues/3901 | ||
*/ | ||
async function patchWsModulesLinks() { | ||
const { name } = patchWsModulesLinks; | ||
const packageNames = await getPackageNames(); | ||
for (const packageName of packageNames) { | ||
console.log(`[${name}] ${packageName}`); | ||
const packagePath = `${packagesPath}/${packageName}`; | ||
await patch(packagePath); | ||
} | ||
} | ||
|
||
export default patchWsModulesLinks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import patchWsModulesLinks from "~/actions/patchWsModulesLinks"; | ||
|
||
async function postinstall() { | ||
await patchWsModulesLinks(); | ||
} | ||
|
||
export default postinstall; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters