diff --git a/packages/pnpm-sync-lib/.eslintrc.js b/packages/pnpm-sync-lib/.eslintrc.js new file mode 100644 index 0000000..246aa14 --- /dev/null +++ b/packages/pnpm-sync-lib/.eslintrc.js @@ -0,0 +1,5 @@ +require("@rushstack/eslint-patch/modern-module-resolution"); +module.exports = { + extends: ['@rushstack/eslint-config/profile/node'], + parserOptions: { tsconfigRootDir: __dirname } +}; \ No newline at end of file diff --git a/packages/pnpm-sync-lib/package.json b/packages/pnpm-sync-lib/package.json index ffeed60..6127f97 100644 --- a/packages/pnpm-sync-lib/package.json +++ b/packages/pnpm-sync-lib/package.json @@ -13,6 +13,7 @@ "scripts": { "build": "heft build --clean", "test": "heft test --clean", + "lint": "eslint src/**", "prepublishOnly": "heft build --clean" }, "dependencies": { @@ -23,6 +24,7 @@ }, "devDependencies": { "@rushstack/eslint-config": "^3.6.2", + "@rushstack/eslint-patch": "^1.7.2", "@rushstack/heft": "^0.64.3", "@rushstack/heft-node-rig": "^2.4.5", "@types/heft-jest": "1.0.6", diff --git a/packages/pnpm-sync-lib/src/interfaces.ts b/packages/pnpm-sync-lib/src/interfaces.ts index 5a94a82..160fd5f 100644 --- a/packages/pnpm-sync-lib/src/interfaces.ts +++ b/packages/pnpm-sync-lib/src/interfaces.ts @@ -1,17 +1,17 @@ -export interface PnpmSyncCliArgs { +export interface IPnpmSyncCliArgs { prepare: boolean, lockfile: string, store: string } -export interface PnpmSyncJson { +export interface IPnpmSyncJson { postbuildInjectedCopy: { sourceFolder: string, - targetFolders: Array + targetFolders: Array } } -export interface TargetFolder { +export interface ITargetFolder { folderPath: string } diff --git a/packages/pnpm-sync-lib/src/pnpmSyncPrepare.ts b/packages/pnpm-sync-lib/src/pnpmSyncPrepare.ts index 993b53f..b29778b 100644 --- a/packages/pnpm-sync-lib/src/pnpmSyncPrepare.ts +++ b/packages/pnpm-sync-lib/src/pnpmSyncPrepare.ts @@ -1,4 +1,4 @@ -import { PnpmSyncJson } from "./interfaces"; +import { IPnpmSyncJson } from "./interfaces"; import { readWantedLockfile, type Lockfile, @@ -98,7 +98,7 @@ export async function pnpmSyncPrepare( const pnpmSyncJsonPath = `${projectFolder}/node_modules/.pnpm-sync.json`; - let pnpmSyncJsonFile: PnpmSyncJson = { + let pnpmSyncJsonFile: IPnpmSyncJson = { postbuildInjectedCopy: { sourceFolder: "../..", targetFolders: [], @@ -167,15 +167,15 @@ function transferFilePathToPnpmStorePath( // process dependencies and devDependencies to generate injectedDependencyToFilePath function getInjectedDependencyToVersion( + // eslint-disable-next-line @rushstack/no-new-null pnpmLockfile: Lockfile | null ): Map> { const injectedDependencyToVersion: Map> = new Map(); for (const importerKey in pnpmLockfile?.importers) { - const dependenciesMeta = - pnpmLockfile?.importers[importerKey]?.dependenciesMeta; - if (!dependenciesMeta) { + if (!pnpmLockfile?.importers[importerKey]?.dependenciesMeta){ continue; } + const dependenciesMeta = pnpmLockfile?.importers[importerKey]?.dependenciesMeta; for (const dependency in dependenciesMeta) { if (dependenciesMeta[dependency]?.injected) { @@ -200,13 +200,12 @@ function getInjectedDependencyToVersion( injectedDependencyToVersion ); } - return injectedDependencyToVersion; } function processDependencies( dependencies: Dependencies | undefined, injectedDependencyToVersion: Map> -) { +): void { if (dependencies) { for (const dependency in dependencies) { if (injectedDependencyToVersion.has(dependency)) { diff --git a/packages/pnpm-sync/.eslintrc.js b/packages/pnpm-sync/.eslintrc.js new file mode 100644 index 0000000..246aa14 --- /dev/null +++ b/packages/pnpm-sync/.eslintrc.js @@ -0,0 +1,5 @@ +require("@rushstack/eslint-patch/modern-module-resolution"); +module.exports = { + extends: ['@rushstack/eslint-config/profile/node'], + parserOptions: { tsconfigRootDir: __dirname } +}; \ No newline at end of file diff --git a/packages/pnpm-sync/package.json b/packages/pnpm-sync/package.json index 6be7e1c..791eabb 100644 --- a/packages/pnpm-sync/package.json +++ b/packages/pnpm-sync/package.json @@ -30,6 +30,7 @@ "scripts": { "build": "heft build --clean", "test": "heft test --clean", + "lint": "eslint src/**", "prepublishOnly": "heft build --clean" }, "bin": { @@ -42,6 +43,7 @@ "devDependencies": { "@rushstack/eslint-config": "^3.6.2", "@rushstack/heft": "^0.64.3", + "@rushstack/eslint-patch": "^1.7.2", "@rushstack/heft-node-rig": "^2.4.5", "@types/heft-jest": "1.0.6", "@types/node": "18.17.15", diff --git a/packages/pnpm-sync/src/start.ts b/packages/pnpm-sync/src/start.ts index fcfb5bc..ed3c0e9 100644 --- a/packages/pnpm-sync/src/start.ts +++ b/packages/pnpm-sync/src/start.ts @@ -1,7 +1,7 @@ import { Command } from 'commander'; import { pnpmSyncCopy, pnpmSyncPrepare } from 'pnpm-sync-lib'; -const program = new Command(); +const program:Command = new Command(); program.version(require('../package.json').version); @@ -13,10 +13,10 @@ program.command('prepare') .description('Generate the pnpm-sync.json based on pnpm-lock.yaml file path and .pnpm folder path') .requiredOption('-l, --lockfile ', 'The pnpm-lock.yaml file path') .requiredOption('-s, --store ', 'The .pnpm folder path') - .action(options => { + .action(async options => { const { lockfile, store } = options; try { - pnpmSyncPrepare(lockfile, store); + await pnpmSyncPrepare(lockfile, store); } catch (error) { console.log(error); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb6c141..f6a1c65 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,6 +18,9 @@ importers: '@rushstack/eslint-config': specifier: ^3.6.2 version: 3.6.2(eslint@8.7.0)(typescript@5.3.3) + '@rushstack/eslint-patch': + specifier: ^1.7.2 + version: 1.7.2 '@rushstack/heft': specifier: ^0.64.3 version: 0.64.3(@types/node@18.17.15) @@ -55,6 +58,9 @@ importers: '@rushstack/eslint-config': specifier: ^3.6.2 version: 3.6.2(eslint@8.7.0)(typescript@5.3.3) + '@rushstack/eslint-patch': + specifier: ^1.7.2 + version: 1.7.2 '@rushstack/heft': specifier: ^0.64.3 version: 0.64.3(@types/node@18.17.15)