Skip to content

Commit

Permalink
fix: some paths and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
porkus1990 committed Jul 15, 2022
1 parent fe76f7f commit 589c667
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@porkus1990/mopeds",
"version": "0.2.0",
"version": "0.2.3",
"private": false,
"description": "A tool for updating peerDependencies in monorepos",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist/*.js", "dist/**/*.js"],
"scripts": {
"test": "jest",
"lint": "eslint .",
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ program

const handleContent = program.opts().dryRun ? new Log : new Write;
let changedSomething = false;
while (!changedSomething) {
let hardStop = 0;
while (!changedSomething && hardStop < 20) {
hardStop++;
changedSomething = await strategy.run(handleContent);
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/sync-deps/SyncDepsByPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class SyncDepsByPath extends Base implements IStrategy {
}
});
const fileToWrite = { ...file, dependencies, peerDependencies };
if (Object.keys(fileToWrite.dependencies).length === 0) delete fileToWrite.dependencies;
if (Object.keys(fileToWrite.peerDependencies).length === 0) delete fileToWrite.peerDependencies;

handleContent.handle(file, fileToWrite, this.packagePaths);

Expand Down
4 changes: 2 additions & 2 deletions src/sync-deps/strategies/Lerna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class Lerna implements IStrategy {
constructor(packagePrefix: string = '') {
this.packagePrefix = packagePrefix;
const lernaConfig = JSON.parse(readFileSync(
path.resolve(process.cwd(), './package.json'),
path.resolve(process.cwd(), './lerna.json'),
).toString());

const runFor = lernaConfig.packages ?? [];
const runFor = lernaConfig.packages ?? [path.resolve(process.cwd(), './packages')];
this.runFor = runFor.map(rfor => rfor.replace('/*', ''));
}

Expand Down
4 changes: 3 additions & 1 deletion src/sync-deps/strategies/handle-change/Write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { IHandleContent } from './handle-content.interface';

class Write implements IHandleContent {
public handle(oldFile: IPackageType, newFile: IPackageType, paths: string[]): boolean {
if (oldFile !== newFile) {
const oldFileStringified = JSON.stringify(oldFile, null, 2);
const newFileStringified = JSON.stringify(newFile, null, 2);
if (oldFileStringified !== newFileStringified) {
let prefix = oldFile.name.split('/')[0] ?? '';
if (prefix !== '') {
prefix = `${prefix}/`;
Expand Down

0 comments on commit 589c667

Please sign in to comment.