Skip to content

Commit 54b79ad

Browse files
sacgroverdgp1130
authored andcommitted
fix(@angular-devkit/core): Rename to a non-existing dir
Added unit test and requested changes. Fixes #16484
1 parent 1beb582 commit 54b79ad

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/angular_devkit/core/node/host.ts

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import * as fs from 'fs';
9+
import * as path from 'path';
910
import { Observable, concat, from as observableFrom, of, throwError } from 'rxjs';
1011
import {
1112
concatMap,
@@ -316,6 +317,10 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
316317
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
317318
// fixed.
318319
try {
320+
const toSystemPath = getSystemPath(to);
321+
if (!fs.existsSync(path.dirname(toSystemPath))) {
322+
fs.mkdirSync(path.dirname(toSystemPath), { recursive: true });
323+
}
319324
fs.renameSync(getSystemPath(from), getSystemPath(to));
320325
obs.next();
321326
obs.complete();

packages/angular_devkit/core/node/host_spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,20 @@ describe('NodeJsSyncHost', () => {
108108
.then(done, done.fail);
109109
}, 30000);
110110

111+
linuxOnlyIt('rename to a non-existing dir', done => {
112+
113+
Promise.resolve()
114+
.then(() => fs.mkdirSync(root + '/rename'))
115+
.then(() => fs.writeFileSync(root + '/rename/a.txt', 'hello world'))
116+
.then(() => {
117+
host.rename(normalize('/rename/a.txt'), normalize('/rename/b/c/d/a.txt'));
118+
if (fs.existsSync(root + '/rename/b/c/d/a.txt')) {
119+
const resContent = host.read(normalize('/rename/b/c/d/a.txt'));
120+
const content = virtualFs.fileBufferToString(resContent);
121+
expect(content).toEqual('hello world');
122+
}
123+
})
124+
.then(done, done.fail);
125+
}, 30000);
126+
111127
});

0 commit comments

Comments
 (0)