diff --git a/internal/sync-pnpm/index.js b/internal/sync-pnpm/index.js index 1aef13f2..eeb96a63 100755 --- a/internal/sync-pnpm/index.js +++ b/internal/sync-pnpm/index.js @@ -3,11 +3,13 @@ import { createRequire } from 'node:module'; import { getPackages } from '@manypkg/get-packages'; import { findRoot } from '@manypkg/find-root'; -import { readJson, pathExists } from 'fs-extra/esm'; +import { readJson, pathExists, remove } from 'fs-extra/esm'; import { hardLinkDir } from '@pnpm/fs.hard-link-dir'; import resolvePackagePath from 'resolve-package-path'; +import Debug from 'debug'; const require = createRequire(import.meta.url); +const debug = Debug('sync-pnpm'); const syncDir = './dist'; @@ -35,6 +37,12 @@ export default async function syncPnpm(dir = process.cwd()) { const syncTo = join(resolvedPackagePath, syncDir); if (await pathExists(syncFrom)) { + if (await pathExists(syncTo)) { + await remove(syncTo); + debug(`removed ${syncTo} before syncing`); + } + + debug(`syncing from ${syncFrom} to ${syncTo}`); await hardLinkDir(syncFrom, [syncTo]); } } diff --git a/internal/sync-pnpm/package.json b/internal/sync-pnpm/package.json index 3f886c0e..38da6732 100644 --- a/internal/sync-pnpm/package.json +++ b/internal/sync-pnpm/package.json @@ -13,6 +13,7 @@ "@manypkg/find-root": "^2.1.0", "@manypkg/get-packages": "^2.1.0", "@pnpm/fs.hard-link-dir": "^1.0.3", + "debug": "^4.3.4", "fs-extra": "^11.1.0", "resolve-package-path": "^4.0.3" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c90e9fc4..ae737a92 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -223,12 +223,14 @@ importers: '@manypkg/find-root': ^2.1.0 '@manypkg/get-packages': ^2.1.0 '@pnpm/fs.hard-link-dir': ^1.0.3 + debug: ^4.3.4 fs-extra: ^11.1.0 resolve-package-path: ^4.0.3 dependencies: '@manypkg/find-root': 2.1.0 '@manypkg/get-packages': 2.1.0 '@pnpm/fs.hard-link-dir': 1.0.3 + debug: 4.3.4 fs-extra: 11.1.0 resolve-package-path: 4.0.3