Skip to content

Commit 38aa2da

Browse files
author
Murat Mehmet
committed
fix: ask if user wants to continue with outdated version
1 parent 2715a97 commit 38aa2da

12 files changed

+32
-28
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
],
1717
rules: {
1818
'no-console': ['error', { allow: ['warn', 'error'] }],
19+
'no-process-exit': 'off',
1920
'prettier/prettier': 'warn',
2021
'node/no-missing-import': 'off',
2122
'node/no-empty-function': 'off',

src/__tests__/mocks/mockAll.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { mockPList } from './mockPList';
1515
import { notificationServiceM as mockNotificationServiceTemplate } from '../../scaffold/notification-service/notificationServiceM';
1616
import { notificationViewControllerM as mockNotificationContentTemplate } from '../../scaffold/notification-content/notificationViewControllerM';
1717

18-
jest.spyOn(process, 'abort').mockImplementation(() => {
19-
throw new Error('program aborted');
18+
jest.spyOn(process, 'exit').mockImplementation(() => {
19+
throw new Error('program exited');
2020
});
2121

2222
function writeMockProject(

src/__tests__/unit/prompter.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('prompter', () => {
173173

174174
await expect(async () => {
175175
await confirm('test');
176-
}).rejects.toThrowError('program aborted');
176+
}).rejects.toThrowError('program exited');
177177

178178
expect(mockPrompter.confirm).toHaveBeenCalled();
179179
});
@@ -186,7 +186,7 @@ describe('prompter', () => {
186186

187187
await expect(async () => {
188188
await text('test');
189-
}).rejects.toThrowError('program aborted');
189+
}).rejects.toThrowError('program exited');
190190

191191
expect(mockPrompter.text).toHaveBeenCalled();
192192
});
@@ -202,7 +202,7 @@ it('should cancel multiselect', async () => {
202202
multiselect('test', {
203203
options: [{ value: 'opt1' }, { value: 'opt2' }],
204204
})
205-
).rejects.toThrowError('program aborted');
205+
).rejects.toThrowError('program exited');
206206

207207
expect(mockPrompter.multiselect).toHaveBeenCalled();
208208
});
@@ -217,7 +217,7 @@ it('should cancel select', async () => {
217217
select('test', {
218218
options: [{ value: 'opt1' }, { value: 'opt2' }],
219219
})
220-
).rejects.toThrowError('program aborted');
220+
).rejects.toThrowError('program exited');
221221

222222
expect(mockPrompter.select).toHaveBeenCalled();
223223
});

src/__tests__/unit/utils/checkForUpdate.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ jest.mock('../../../../package.json', () => ({
99
version: '1.0.0',
1010
name: 'react-native-integrate',
1111
}));
12+
jest.spyOn(process, 'exit').mockImplementation(() => {
13+
throw new Error('program exited');
14+
});
1215

1316
describe('checkForUpdate', () => {
1417
beforeEach(() => {

src/__tests__/unit/utils/getInstalledPackages.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ describe('getInstalledPackages', () => {
2727

2828
expect(() => {
2929
getInstalledPackages();
30-
}).toThrowError('program aborted');
30+
}).toThrowError('program exited');
3131
});
3232
});

src/__tests__/unit/utils/updateIntegrationStatus.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe('updateIntegrationStatus', () => {
133133
},
134134
});
135135
});
136-
it('should abort for unsupported lock file version', () => {
136+
it('should exit for unsupported lock file version', () => {
137137
// @ts-ignore
138138
// eslint-disable-next-line @typescript-eslint/no-empty-function
139139

@@ -152,9 +152,9 @@ describe('updateIntegrationStatus', () => {
152152
},
153153
},
154154
]);
155-
}).toThrowError('program aborted');
155+
}).toThrowError('program exited');
156156
});
157-
it('should abort when has no read permission', () => {
157+
it('should exit when has no read permission', () => {
158158
mockFs.setReadPermission(false);
159159
// @ts-ignore
160160
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -174,9 +174,9 @@ describe('updateIntegrationStatus', () => {
174174
},
175175
},
176176
]);
177-
}).toThrowError('program aborted');
177+
}).toThrowError('program exited');
178178
});
179-
it('should abort when has no write permission', () => {
179+
it('should exit when has no write permission', () => {
180180
mockFs.setWritePermission(false);
181181
// @ts-ignore
182182
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -190,6 +190,6 @@ describe('updateIntegrationStatus', () => {
190190
},
191191
},
192192
]);
193-
}).toThrowError('program aborted');
193+
}).toThrowError('program exited');
194194
});
195195
});

src/prompter.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export async function multiselect(
119119
});
120120
if (isCancel(response)) {
121121
cancel('operation cancelled');
122-
process.abort();
122+
process.exit(0);
123123
}
124124
if (isProgressActive) progress.display();
125125
// @ts-ignore
@@ -144,7 +144,7 @@ export async function select(
144144
});
145145
if (isCancel(response)) {
146146
cancel('operation cancelled');
147-
process.abort();
147+
process.exit(0);
148148
}
149149
if (isProgressActive) progress.display();
150150
// @ts-ignore
@@ -165,7 +165,7 @@ export async function confirm(
165165
});
166166
if (isCancel(response)) {
167167
cancel('operation cancelled');
168-
process.abort();
168+
process.exit(0);
169169
}
170170
if (isProgressActive) progress.display();
171171
return response;
@@ -186,7 +186,7 @@ export async function text(
186186
});
187187
if (isCancel(response)) {
188188
cancel('operation cancelled');
189-
process.abort();
189+
process.exit(0);
190190
}
191191
if (isProgressActive) progress.display();
192192
return response;

src/upgrade.ts

-5
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,6 @@ export async function upgrade(): Promise<void> {
546546

547547
if (!options.get().verbose) {
548548
progress.hide();
549-
if (!didPushFail) {
550-
logSuccess(
551-
color.green(`changes committed to ${color.bold(branchName)}`)
552-
);
553-
}
554549
}
555550
}
556551
}

src/utils/checkForUpdate.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import color from 'picocolors';
22
import semver from 'semver/preload';
3-
import { logWarning } from '../prompter';
3+
import { confirm, logWarning } from '../prompter';
44
import { PackageJsonType } from '../types/mod.types';
55
import { runCommand } from './runCommand';
66

@@ -26,6 +26,11 @@ export async function checkForUpdate(): Promise<void> {
2626
`Current: ${color.gray(currentVersion)} | Latest: ${color.green(latestVersion)}\n` +
2727
`${color.yellow('Run')} ${color.blue(`npm install -g ${name}@latest`)} to update.`
2828
);
29+
if (
30+
!(await confirm('would you like to continue with outdated version?'))
31+
) {
32+
process.exit(0);
33+
}
2934
}
3035
} catch (_error) {
3136
/* empty */

src/utils/getInstalledPackages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function getInstalledPackages(): PackageTuples {
1414
} as Record<string, any>) as PackageTuples;
1515
} catch (error) {
1616
console.error('Error fetching installed packages:', error);
17-
process.abort();
17+
process.exit(0);
1818
}
1919
}
2020

src/utils/getIntegrateConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function getIntegrateConfig(projectPath?: string) {
1818
return 'default' in config ? config.default : config;
1919
} catch (error) {
2020
console.error('Error reading integrate.config.js:', error);
21-
process.abort();
21+
process.exit(0);
2222
}
2323
}
2424

src/utils/updateIntegrationStatus.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ export function readLockFile(): LockDataWithMeta {
3535
console.error(
3636
`Error reading integrate-lock.json: lockfileVersion is not equal to ${Constants.CURRENT_LOCK_VERSION}`
3737
);
38-
process.abort();
38+
process.exit(0);
3939
}
4040
return {
4141
lockData,
4242
justCreated: false,
4343
};
4444
} catch (error) {
4545
console.error('Error reading integrate-lock.json:', error);
46-
process.abort();
46+
process.exit(0);
4747
}
4848
}
4949

@@ -54,7 +54,7 @@ function writeLockFile(data: LockData): void {
5454
fs.writeFileSync(lockFilePath, JSON.stringify(data, null, 2));
5555
} catch (error) {
5656
console.error('Error writing integrate-lock.json:', error);
57-
process.abort();
57+
process.exit(0);
5858
}
5959
}
6060

0 commit comments

Comments
 (0)