Skip to content

Commit cc2195d

Browse files
committed
Update projects that used the FileSystem API
1 parent 426815d commit cc2195d

8 files changed

Lines changed: 68 additions & 27 deletions

File tree

‎apps/rush-lib/src/cli/actions/PublishAction.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,11 @@ export class PublishAction extends BaseRushAction {
388388
const destFolder: string = this._releaseFolder.value ?
389389
this._releaseFolder.value : path.join(this.rushConfiguration.commonTempFolder, 'artifacts', 'packages');
390390

391-
FileSystem.move(tarballPath, path.join(destFolder, tarballName), { overwrite: true });
391+
FileSystem.move({
392+
sourcePath: tarballPath,
393+
destinationPath: path.join(destFolder, tarballName),
394+
overwrite: true
395+
});
392396
}
393397
}
394398

@@ -417,7 +421,10 @@ export class PublishAction extends BaseRushAction {
417421
const toApiFolderPath: string = path.join(project.projectFolder, toApiFolder);
418422
if (FileSystem.exists(fromApiFolderPath) && FileSystem.exists(toApiFolderPath)) {
419423
FileSystem.readFolder(fromApiFolderPath).forEach(fileName => {
420-
FileSystem.copyFile(path.join(fromApiFolderPath, fileName), path.join(toApiFolderPath, fileName));
424+
FileSystem.copyFile({
425+
sourcePath: path.join(fromApiFolderPath, fileName),
426+
destinationPath: path.join(toApiFolderPath, fileName)
427+
});
421428
console.log(`Copied file ${fileName} from ${fromApiFolderPath} to ${toApiFolderPath}`);
422429
});
423430
}

‎apps/rush-lib/src/logic/InstallManager.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ export class InstallManager {
333333
}
334334
}
335335

336-
FileSystem.createSymbolicLinkJunction(packageManagerToolFolder, localPackageManagerToolFolder);
336+
FileSystem.createSymbolicLinkJunction({
337+
linkPath: localPackageManagerToolFolder,
338+
linkTargetPath: packageManagerToolFolder
339+
});
337340

338341
lock.release();
339342
});
@@ -976,17 +979,17 @@ export class InstallManager {
976979
}
977980

978981
/**
979-
* Copies the file "sourcePath" to "targetPath", overwriting the target file location.
982+
* Copies the file "sourcePath" to "destinationPath", overwriting the target file location.
980983
* If the source file does not exist, then the target file is deleted.
981984
*/
982-
private _syncFile(sourcePath: string, targetPath: string): void {
985+
private _syncFile(sourcePath: string, destinationPath: string): void {
983986
if (FileSystem.exists(sourcePath)) {
984-
console.log('Updating ' + targetPath);
985-
FileSystem.copyFile(sourcePath, targetPath);
987+
console.log('Updating ' + destinationPath);
988+
FileSystem.copyFile({sourcePath, destinationPath});
986989
} else {
987-
if (FileSystem.exists(targetPath)) {
988-
console.log('Deleting ' + targetPath);
989-
FileSystem.deleteFile(targetPath);
990+
if (FileSystem.exists(destinationPath)) {
991+
console.log('Deleting ' + destinationPath);
992+
FileSystem.deleteFile(destinationPath);
990993
}
991994
}
992995
}

‎apps/rush-lib/src/logic/StandardScriptUpdater.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ export class StandardScriptUpdater {
7474
+ ' for this Rush version. Please run "rush update" and commit the changes.');
7575
} else {
7676
console.log(`Script is out of date; updating "${targetFilePath}"`);
77-
FileSystem.copyFile(sourceFilePath, targetFilePath);
77+
FileSystem.copyFile({
78+
sourcePath: sourceFilePath,
79+
destinationPath: targetFilePath
80+
});
7881
}
7982
}
8083

‎apps/rush-lib/src/logic/base/BaseLinkManager.ts‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as fs from 'fs';
66
import * as os from 'os';
77
import * as path from 'path';
88

9-
import { FileSystem } from '@microsoft/node-core-library';
9+
import { FileSystem, IFileSystemCreateLinkOptions } from '@microsoft/node-core-library';
1010

1111
import { RushConfiguration } from '../../api/RushConfiguration';
1212
import { Utilities } from '../../utilities/Utilities';
@@ -18,24 +18,37 @@ export enum SymlinkKind {
1818
Directory
1919
}
2020

21+
export interface IBaseLinkManagerCreateSymlinkOptions extends IFileSystemCreateLinkOptions {
22+
symlinkKind: SymlinkKind;
23+
}
24+
2125
export abstract class BaseLinkManager {
2226
protected _rushConfiguration: RushConfiguration;
2327

24-
protected static _createSymlink(linkTarget: string, linkSource: string, symlinkKind: SymlinkKind): void {
25-
FileSystem.ensureFolder(path.dirname(linkSource));
28+
protected static _createSymlink(options: IBaseLinkManagerCreateSymlinkOptions): void {
29+
FileSystem.ensureFolder(path.dirname(options.linkPath));
2630

27-
if (symlinkKind === SymlinkKind.Directory) {
31+
if (options.symlinkKind === SymlinkKind.Directory) {
2832
// For directories, we use a Windows "junction". On Unix, this produces a regular symlink.
29-
FileSystem.createSymbolicLinkJunction(linkTarget, linkSource);
33+
FileSystem.createSymbolicLinkJunction({
34+
linkPath: options.linkPath,
35+
linkTargetPath: options.linkTargetPath
36+
});
3037
} else {
3138
if (process.platform === 'win32') {
3239
// For files, we use a Windows "hard link", because creating a symbolic link requires
3340
// administrator permission.
34-
FileSystem.createHardLink(linkTarget, linkSource);
41+
FileSystem.createHardLink({
42+
linkPath: options.linkPath,
43+
linkTargetPath: options.linkTargetPath
44+
});
3545
} else {
3646
// However hard links seem to cause build failures on Mac, so for all other operating systems
3747
// we use symbolic links for this case.
38-
FileSystem.createSymbolicLinkFile(linkTarget, linkSource);
48+
FileSystem.createSymbolicLinkFile({
49+
linkPath: options.linkPath,
50+
linkTargetPath: options.linkTargetPath
51+
});
3952
}
4053
}
4154
}
@@ -91,10 +104,11 @@ export abstract class BaseLinkManager {
91104

92105
if (localPackage.children.length === 0) {
93106
// If there are no children, then we can symlink the entire folder
94-
BaseLinkManager._createSymlink(
95-
localPackage.symlinkTargetFolderPath,
96-
localPackage.folderPath,
97-
SymlinkKind.Directory);
107+
BaseLinkManager._createSymlink({
108+
linkPath: localPackage.symlinkTargetFolderPath,
109+
linkTargetPath: localPackage.folderPath,
110+
symlinkKind: SymlinkKind.Directory
111+
});
98112
} else {
99113
// If there are children, then we need to symlink each item in the folder individually
100114
Utilities.createFolderWithRetry(localPackage.folderPath);
@@ -126,7 +140,11 @@ export abstract class BaseLinkManager {
126140
symlinkKind = SymlinkKind.Directory;
127141
}
128142

129-
BaseLinkManager._createSymlink(linkTarget, linkSource, symlinkKind);
143+
BaseLinkManager._createSymlink({
144+
linkPath: linkSource,
145+
linkTargetPath: linkTarget,
146+
symlinkKind
147+
});
130148
}
131149
}
132150
}

‎apps/rush-lib/src/logic/npm/NpmLinkManager.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ export class NpmLinkManager extends BaseLinkManager {
324324
const projectBinFolder: string = path.join(localProjectPackage.folderPath, 'node_modules', '.bin');
325325

326326
if (FileSystem.exists(commonBinFolder)) {
327-
NpmLinkManager._createSymlink(commonBinFolder, projectBinFolder, SymlinkKind.Directory);
327+
NpmLinkManager._createSymlink({
328+
linkPath: projectBinFolder,
329+
linkTargetPath: commonBinFolder,
330+
symlinkKind: SymlinkKind.Directory
331+
});
328332
}
329333
}
330334
}

‎apps/rush-lib/src/utilities/AsyncRecycler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class AsyncRecycler {
7474
}
7575

7676
Utilities.retryUntilTimeout(
77-
() => FileSystem.move(folderPath, newFolderPath),
77+
() => FileSystem.move({ sourcePath: folderPath, destinationPath: newFolderPath }),
7878
maxWaitTimeMs,
7979
(e) => new Error(`Error: ${e}${os.EOL}Often this is caused by a file lock ` +
8080
'from a process like the virus scanner.'),

‎core-build/gulp-core-build/src/tasks/GulpTask.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ export abstract class GulpTask<TTaskConfig> implements IExecutable {
347347
this.buildConfig.rootPath,
348348
(localDestPath || path.basename(localSourcePath)));
349349

350-
FileSystem.copyFile(fullSourcePath, fullDestPath);
350+
FileSystem.copyFile({
351+
sourcePath: fullSourcePath,
352+
destinationPath: fullDestPath
353+
});
351354
}
352355

353356
/**

‎core-build/gulp-core-build/src/tasks/JestTask.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ export class JestTask extends GulpTask<IJestConfig> {
205205
const testFileName: string = path.basename(snapDestFile, '.snap');
206206
const testFile: string = path.resolve(path.dirname(snapDestFile), '..', testFileName); // Up from `__snapshots__`.
207207
if (FileSystem.exists(testFile)) {
208-
FileSystem.copyFile(snapSourceFile, snapDestFile);
208+
FileSystem.copyFile({
209+
sourcePath: snapSourceFile,
210+
destinationPath: snapDestFile
211+
});
209212
return true;
210213
} else {
211214
return false;

0 commit comments

Comments
 (0)