-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from CrowdStrike/turbo-and-sync-pnpm
Turbo and sync pnpm
- Loading branch information
Showing
14 changed files
with
304 additions
and
30 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
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
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,3 @@ | ||
import syncPnpm from '../index.js'; | ||
|
||
await syncPnpm(); |
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,62 @@ | ||
import { join, dirname } from 'node:path'; | ||
import { createRequire } from 'node:module'; | ||
|
||
import { getPackages } from '@manypkg/get-packages'; | ||
import { findRoot } from '@manypkg/find-root'; | ||
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'; | ||
import lockfile from 'proper-lockfile'; | ||
|
||
const require = createRequire(import.meta.url); | ||
const debug = Debug('sync-pnpm'); | ||
|
||
const syncDir = './dist'; | ||
|
||
export default async function syncPnpm(dir = process.cwd()) { | ||
const root = await findRoot(dir); | ||
const ownPackageJson = await readJson(join(dir, 'package.json')); | ||
const ownDependencies = [ | ||
...Object.keys(ownPackageJson.dependencies ?? {}), | ||
...Object.keys(ownPackageJson.devDependencies ?? {}), | ||
]; | ||
|
||
const localPackages = (await getPackages(root.rootDir)).packages; | ||
|
||
const packagesToSync = localPackages.filter( | ||
(p) => | ||
p.packageJson.name !== 'sync-pnpm' && | ||
ownDependencies.includes(p.packageJson.name) | ||
); | ||
|
||
for (const pkg of packagesToSync) { | ||
const syncFrom = join(pkg.dir, syncDir); | ||
const resolvedPackagePath = dirname( | ||
resolvePackagePath(pkg.packageJson.name, dir) | ||
); | ||
const syncTo = join(resolvedPackagePath, syncDir); | ||
|
||
if (await pathExists(syncFrom)) { | ||
let releaseLock; | ||
try { | ||
releaseLock = await lockfile.lock(syncTo, { realpath: false }); | ||
debug(`lockfile created for syncing to ${syncTo}`); | ||
} catch (e) { | ||
debug( | ||
`lockfile already exists for syncing to ${syncTo}, some other sync process is already handling this directory, so skipping...` | ||
); | ||
continue; | ||
} | ||
|
||
if (await pathExists(syncTo)) { | ||
await remove(syncTo); | ||
debug(`removed ${syncTo} before syncing`); | ||
} | ||
|
||
debug(`syncing from ${syncFrom} to ${syncTo}`); | ||
await hardLinkDir(syncFrom, [syncTo]); | ||
releaseLock(); | ||
} | ||
} | ||
} |
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,21 @@ | ||
{ | ||
"name": "sync-pnpm", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "Sync build artifacts of workspace packages to pnpm injected/hard linked copies", | ||
"repository": "https://github.com/CrowdStrike/ember-headless-table.git", | ||
"license": "MIT", | ||
"author": "CrowdStrike UX Team", | ||
"main": "index.js", | ||
"bin": "bin/sync-pnpm.js", | ||
"type": "module", | ||
"dependencies": { | ||
"@manypkg/find-root": "^2.1.0", | ||
"@manypkg/get-packages": "^2.1.0", | ||
"@pnpm/fs.hard-link-dir": "^2.0.0", | ||
"debug": "^4.3.4", | ||
"fs-extra": "^11.1.0", | ||
"proper-lockfile": "^4.1.2", | ||
"resolve-package-path": "^4.0.3" | ||
} | ||
} |
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
Oops, something went wrong.