Skip to content

Commit

Permalink
Merge pull request #7 from tiktok/chao/add-eslint
Browse files Browse the repository at this point in the history
feat: add eslint
  • Loading branch information
octogonz authored Feb 9, 2024
2 parents 177dcd7 + 16ad33c commit 9c4dbf5
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 14 deletions.
5 changes: 5 additions & 0 deletions packages/pnpm-sync-lib/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require("@rushstack/eslint-patch/modern-module-resolution");
module.exports = {
extends: ['@rushstack/eslint-config/profile/node'],
parserOptions: { tsconfigRootDir: __dirname }
};
2 changes: 2 additions & 0 deletions packages/pnpm-sync-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"build": "heft build --clean",
"test": "heft test --clean",
"lint": "eslint src/**",
"prepublishOnly": "heft build --clean"
},
"dependencies": {
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/pnpm-sync-lib/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -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<TargetFolder>
targetFolders: Array<ITargetFolder>
}
}

export interface TargetFolder {
export interface ITargetFolder {
folderPath: string
}

13 changes: 6 additions & 7 deletions packages/pnpm-sync-lib/src/pnpmSyncPrepare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PnpmSyncJson } from "./interfaces";
import { IPnpmSyncJson } from "./interfaces";
import {
readWantedLockfile,
type Lockfile,
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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<string, Set<string>> {
const injectedDependencyToVersion: Map<string, Set<string>> = 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) {
Expand All @@ -200,13 +200,12 @@ function getInjectedDependencyToVersion(
injectedDependencyToVersion
);
}

return injectedDependencyToVersion;
}
function processDependencies(
dependencies: Dependencies | undefined,
injectedDependencyToVersion: Map<string, Set<string>>
) {
): void {
if (dependencies) {
for (const dependency in dependencies) {
if (injectedDependencyToVersion.has(dependency)) {
Expand Down
5 changes: 5 additions & 0 deletions packages/pnpm-sync/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require("@rushstack/eslint-patch/modern-module-resolution");
module.exports = {
extends: ['@rushstack/eslint-config/profile/node'],
parserOptions: { tsconfigRootDir: __dirname }
};
2 changes: 2 additions & 0 deletions packages/pnpm-sync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"scripts": {
"build": "heft build --clean",
"test": "heft test --clean",
"lint": "eslint src/**",
"prepublishOnly": "heft build --clean"
},
"bin": {
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/pnpm-sync/src/start.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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 <value>', 'The pnpm-lock.yaml file path')
.requiredOption('-s, --store <value>', '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);
}
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9c4dbf5

Please sign in to comment.