pnpm-sync-dependencies-meta-injected
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "pnpm-sync-dependencies-meta-injected", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -9,3 +9,3 @@ import { findRoot } from '@manypkg/find-root'; | ||
import lockfile from 'proper-lockfile'; | ||
import resolvePackagePath from 'resolve-package-path'; | ||
import resolvePackageManifestPath from 'resolve-package-path'; | ||
@@ -18,4 +18,2 @@ const require = createRequire(import.meta.url); | ||
export default async function syncPnpm(dir = process.cwd()) { | ||
console.log(dir); | ||
const root = await findRoot(dir); | ||
@@ -37,31 +35,66 @@ const ownPackageJson = await readJson(join(dir, 'package.json')); | ||
for (const pkg of packagesToSync) { | ||
let name = pkg.packageJson.name; | ||
/** | ||
* This likely won't happen, but we can't have declared | ||
* a dependency on a package without a name. | ||
*/ | ||
if (!name) continue; | ||
const syncFrom = join(pkg.dir, syncDir); | ||
const resolvedPackagePath = dirname( | ||
resolvePackagePath(pkg.packageJson.name, dir) | ||
); | ||
const resolvedPackagePath = resolvePackagePath(name, dir); | ||
const syncTo = join(resolvedPackagePath, syncDir); | ||
if (await pathExists(syncFrom)) { | ||
let releaseLock; | ||
await syncPkg(syncFrom, syncTo); | ||
} | ||
} | ||
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; | ||
} | ||
/** | ||
* @param {string} name | ||
* @param {string} startingDirectory resolve from here | ||
*/ | ||
function resolvePackagePath(name, startingDirectory) { | ||
const resolvedManifestPath = resolvePackageManifestPath( | ||
name, | ||
startingDirectory | ||
); | ||
if (await pathExists(syncTo)) { | ||
await remove(syncTo); | ||
debug(`removed ${syncTo} before syncing`); | ||
} | ||
if (!resolvedManifestPath) { | ||
throw new Error(`Could not find package, ${name}`); | ||
} | ||
debug(`syncing from ${syncFrom} to ${syncTo}`); | ||
await hardLinkDir(syncFrom, [syncTo]); | ||
releaseLock(); | ||
const resolvedPackagePath = dirname(resolvedManifestPath); | ||
return resolvedPackagePath; | ||
} | ||
/** | ||
* @param {string} syncFrom | ||
* @param {string} syncTo | ||
*/ | ||
async function syncPkg(syncFrom, syncTo) { | ||
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...` | ||
); | ||
return; | ||
} | ||
if (await pathExists(syncTo)) { | ||
await remove(syncTo); | ||
debug(`removed ${syncTo} before syncing`); | ||
} | ||
debug(`syncing from ${syncFrom} to ${syncTo}`); | ||
await hardLinkDir(syncFrom, [syncTo]); | ||
releaseLock(); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4640
94