Skip to content

Commit

Permalink
Merge pull request #17 from tiktok/chao/add-lockfile-version-check
Browse files Browse the repository at this point in the history
chore: add lockfile version check
  • Loading branch information
g-chao authored Mar 19, 2024
2 parents 89c55ba + d1b0646 commit 1c914d6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/pnpm-sync-lib/etc/pnpm-sync-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface IDependencyMeta {
export interface ILockfile {
// (undocumented)
importers: Record<string, ILockfileImporter>;
// (undocumented)
lockfileVersion: number | string;
}

// @beta (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/pnpm-sync-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pnpm-sync-lib",
"version": "0.1.4",
"version": "0.1.5",
"description": "API library for integrating \"pnpm-sync\" with your toolchain",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/pnpm-sync-lib/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ export interface ILockfileImporter {
* @beta
*/
export interface ILockfile {
lockfileVersion: number | string;
importers: Record<string, ILockfileImporter>;
}
12 changes: 9 additions & 3 deletions packages/pnpm-sync-lib/src/pnpmSyncPrepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,23 @@ export async function pnpmSyncPrepareAsync({
}
});

if (!fs.existsSync(lockfilePath)) {
throw Error('The input pnpm-lock.yaml path is not correct!');
if (!fs.existsSync(lockfilePath) || !fs.existsSync(storePath)) {
throw Error('The input pnpm-lock.yaml path or the input .pnpm folder path is not correct!');
}

const startTime = hrtime.bigint();

// read the pnpm-lock.yaml
const pnpmLockfile = await readPnpmLockfile(lockfilePath, {
const pnpmLockfile: ILockfile | undefined = await readPnpmLockfile(lockfilePath, {
ignoreIncompatible: true
});

// currently, only support lockfileVersion 6.x, which is pnpm v8
const lockfileVersion: string | undefined = pnpmLockfile?.lockfileVersion.toString();
if (!lockfileVersion || !lockfileVersion.startsWith('6.')) {
throw Error(`The pnpm-lock.yaml format is not supported; pnpm-sync requires lockfile version 6`);
}

// find injected dependency and all its available versions
const injectedDependencyToVersion: Map<string, Set<string>> = getInjectedDependencyToVersion(pnpmLockfile);

Expand Down
2 changes: 1 addition & 1 deletion packages/pnpm-sync/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pnpm-sync",
"version": "0.1.4",
"version": "0.1.5",
"description": "Recopy injected dependencies whenever a project is rebuilt in your PNPM workspace",
"keywords": [
"rush",
Expand Down

0 comments on commit 1c914d6

Please sign in to comment.