-
Notifications
You must be signed in to change notification settings - Fork 1
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 #34 from tiktok/chao/add-identifier
feat: add an identifier for pnpmSyncPrepare
- Loading branch information
Showing
8 changed files
with
121 additions
and
13 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
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 |
---|---|---|
|
@@ -17,6 +17,21 @@ describe('pnpm-sync-api copy test', () => { | |
const lockfilePath = '../../pnpm-lock.yaml'; | ||
const dotPnpmFolder = '../../node_modules/.pnpm'; | ||
|
||
const pnpmSyncJsonFolder1 = `../test-fixtures/sample-lib1/node_modules`; | ||
const pnpmSyncJsonFolder2 = `../test-fixtures/sample-lib2/node_modules`; | ||
|
||
const pnpmSyncJsonPath1 = `${pnpmSyncJsonFolder1}/.pnpm-sync.json`; | ||
const pnpmSyncJsonPath2 = `${pnpmSyncJsonFolder2}/.pnpm-sync.json`; | ||
|
||
// if .pnpm-sync.json already exists, delete it first | ||
if (fs.existsSync(pnpmSyncJsonPath1)) { | ||
fs.unlinkSync(pnpmSyncJsonPath1); | ||
} | ||
|
||
if (fs.existsSync(pnpmSyncJsonPath2)) { | ||
fs.unlinkSync(pnpmSyncJsonPath2); | ||
} | ||
|
||
// generate .pnpm-sync.json file first. | ||
await pnpmSyncPrepareAsync({ | ||
lockfilePath: lockfilePath, | ||
|
@@ -26,12 +41,6 @@ describe('pnpm-sync-api copy test', () => { | |
logMessageCallback: (): void => {} | ||
}); | ||
|
||
const pnpmSyncJsonFolder1 = `../test-fixtures/sample-lib1/node_modules`; | ||
const pnpmSyncJsonFolder2 = `../test-fixtures/sample-lib2/node_modules`; | ||
|
||
const pnpmSyncJsonPath1 = `${pnpmSyncJsonFolder1}/.pnpm-sync.json`; | ||
const pnpmSyncJsonPath2 = `${pnpmSyncJsonFolder2}/.pnpm-sync.json`; | ||
|
||
const targetFolderPath1 = | ||
'../../../../node_modules/.pnpm/[email protected]/node_modules/api-demo-sample-lib1'; | ||
const targetFolderPath2 = | ||
|
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 |
---|---|---|
|
@@ -201,4 +201,77 @@ describe('pnpm-sync-api prepare test', () => { | |
} | ||
}); | ||
}); | ||
|
||
it('pnpmSyncPrepareAsync should handle identifier (if provided)', async () => { | ||
const lockfilePath = '../../pnpm-lock.yaml'; | ||
const dotPnpmFolder = '../../node_modules/.pnpm'; | ||
|
||
const pnpmSyncJsonFolder = `../test-fixtures/sample-lib1/node_modules`; | ||
const pnpmSyncJsonPath = `${pnpmSyncJsonFolder}/.pnpm-sync.json`; | ||
|
||
if (!fs.existsSync(pnpmSyncJsonFolder)) { | ||
await FileSystem.ensureFolderAsync(pnpmSyncJsonFolder); | ||
} | ||
|
||
// create an .pnpm-sync.json with some identifiers | ||
const pnpmSyncJsonFile = { | ||
version: pnpmSyncLibVersion, | ||
postbuildInjectedCopy: { | ||
sourceFolder: '..', | ||
targetFolders: [ | ||
{ | ||
folderPath: | ||
'../../../../node_modules/.pnpm/[email protected]/node_modules/api-demo-sample-lib1', | ||
lockfileId: 'identifier1' | ||
}, | ||
{ | ||
folderPath: | ||
'../../../../node_modules/.pnpm/[email protected]/node_modules/api-demo-sample-lib2', | ||
lockfileId: 'identifier1' | ||
}, | ||
{ | ||
folderPath: | ||
'../../../../node_modules/.pnpm/[email protected]/node_modules/api-demo-sample-lib3', | ||
lockfileId: 'identifier2' | ||
} | ||
] | ||
} | ||
}; | ||
|
||
// write .pnpm-sync.json | ||
await fs.promises.writeFile(pnpmSyncJsonPath, JSON.stringify(pnpmSyncJsonFile, null, 2)); | ||
|
||
await pnpmSyncPrepareAsync({ | ||
lockfilePath: lockfilePath, | ||
dotPnpmFolder: dotPnpmFolder, | ||
lockfileId: 'identifier1', | ||
ensureFolderAsync: FileSystem.ensureFolderAsync, | ||
readPnpmLockfile, | ||
logMessageCallback: (): void => {} | ||
}); | ||
|
||
// now, read .pnpm-sync.json and check the fields | ||
expect(fs.existsSync(pnpmSyncJsonPath)).toBe(true); | ||
|
||
// the folderPath with identifier1 should be regenerated | ||
// the folderPath with identifier2 should keep as it is | ||
expect(JSON.parse(fs.readFileSync(pnpmSyncJsonPath).toString())).toEqual({ | ||
version: pnpmSyncLibVersion, | ||
postbuildInjectedCopy: { | ||
sourceFolder: '..', | ||
targetFolders: [ | ||
{ | ||
folderPath: | ||
'../../../../node_modules/.pnpm/[email protected]/node_modules/api-demo-sample-lib3', | ||
lockfileId: 'identifier2' | ||
}, | ||
{ | ||
folderPath: | ||
'../../../../node_modules/.pnpm/[email protected]/node_modules/api-demo-sample-lib1', | ||
lockfileId: 'identifier1' | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
}); |