Skip to content

Commit dc3f2a5

Browse files
committed
fix(config): write json file with ending newline
1 parent 27f5122 commit dc3f2a5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/@ionic/cli-framework/src/lib/__tests__/config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('@ionic/cli-framework', () => {
4343
const config = new Config('/path/to/file');
4444
config.c = {};
4545
expect(mockWriteFileAtomicSync).toHaveBeenCalledTimes(1);
46-
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{}');
46+
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{}\n');
4747
});
4848

4949
it('should call readFileSync upon getting c', () => {
@@ -144,7 +144,7 @@ describe('@ionic/cli-framework', () => {
144144
jest.spyOn(config, 'provideDefaults').mockImplementation(() => ({}));
145145
config.set('foo', 5);
146146
expect(mockWriteFileAtomicSync).toHaveBeenCalledTimes(1);
147-
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{\n "foo": 5\n}');
147+
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{\n "foo": 5\n}\n');
148148
});
149149

150150
it('should unset value in file', () => {
@@ -153,7 +153,7 @@ describe('@ionic/cli-framework', () => {
153153
jest.spyOn(config, 'provideDefaults').mockImplementation(() => ({}));
154154
config.unset('foo');
155155
expect(mockWriteFileAtomicSync).toHaveBeenCalledTimes(1);
156-
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{}');
156+
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{}\n');
157157
});
158158

159159
});
@@ -289,7 +289,7 @@ describe('@ionic/cli-framework', () => {
289289
jest.spyOn(config, 'provideDefaults').mockImplementation(() => ({}));
290290
config.set('foo', 5);
291291
expect(mockWriteFileAtomicSync).toHaveBeenCalledTimes(1);
292-
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{\n "sub": {\n "foo": 5\n }\n}');
292+
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{\n "sub": {\n "foo": 5\n }\n}\n');
293293
});
294294

295295
it('should unset value in file', () => {
@@ -298,7 +298,7 @@ describe('@ionic/cli-framework', () => {
298298
jest.spyOn(config, 'provideDefaults').mockImplementation(() => ({}));
299299
config.unset('foo');
300300
expect(mockWriteFileAtomicSync).toHaveBeenCalledTimes(1);
301-
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{\n "sub": {}\n}');
301+
expect(mockWriteFileAtomicSync).toHaveBeenCalledWith('/path/to/file', '{\n "sub": {}\n}\n');
302302
});
303303

304304
});

packages/@ionic/cli-framework/src/lib/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export abstract class BaseConfig<T extends object> {
5252
const v = this.pathPrefix.length === 0 ? value : lodash.set(this.file, [...this.pathPrefix], value);
5353

5454
mkdirpSync(path.dirname(this.p));
55-
writeFileAtomic.sync(this.p, JSON.stringify(v, undefined, 2));
55+
writeFileAtomic.sync(this.p, JSON.stringify(v, undefined, 2) + '\n');
5656
}
5757

5858
get<P extends keyof T>(property: P): T[P];

0 commit comments

Comments
 (0)