Skip to content

Commit 3545f6f

Browse files
author
Nick Pape
committed
Replace all the fs references
1 parent 19ff1ed commit 3545f6f

20 files changed

Lines changed: 87 additions & 92 deletions

File tree

‎apps/api-extractor/src/ExternalApiHelper.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// See LICENSE in the project root for license information.
33

44
import * as path from 'path';
5-
import * as fs from 'fs';
5+
import { FileSystem } from '@microsoft/node-core-library';
6+
67
import { Extractor } from './extractor/Extractor';
78

89
/**
@@ -38,14 +39,10 @@ export class ExternalApiHelper {
3839
};
3940

4041
let outputPath: string = path.resolve(rootDir, libFolder);
41-
if (!fs.existsSync(outputPath)) {
42-
fs.mkdirSync(outputPath);
43-
}
42+
FileSystem.createFolder(outputPath);
4443

4544
outputPath = path.join(outputPath, 'external-api-json');
46-
if (!fs.existsSync(outputPath)) {
47-
fs.mkdirSync(outputPath);
48-
}
45+
FileSystem.createFolder(outputPath);
4946

5047
const extractor: Extractor = new Extractor({
5148
compiler: {

‎apps/api-extractor/src/generators/ApiFileGenerator.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as fs from 'fs';
5-
import { Text } from '@microsoft/node-core-library';
4+
import { Text, FileSystem } from '@microsoft/node-core-library';
65
import { ExtractorContext } from '../ExtractorContext';
76
import { AstStructuredType } from '../ast/AstStructuredType';
87
import { AstEnum } from '../ast/AstEnum';
@@ -60,7 +59,7 @@ export class ApiFileGenerator extends AstItemVisitor {
6059
*/
6160
public writeApiFile(reportFilename: string, context: ExtractorContext): void {
6261
const fileContent: string = this.generateApiFileContent(context);
63-
fs.writeFileSync(reportFilename, fileContent);
62+
FileSystem.writeFile(reportFilename, fileContent);
6463
}
6564

6665
public generateApiFileContent(context: ExtractorContext): string {

‎apps/rush-lib/src/api/CommandLineConfiguration.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as fs from 'fs';
54
import * as path from 'path';
65

76
import {
87
JsonFile,
9-
JsonSchema
8+
JsonSchema,
9+
FileSystem
1010
} from '@microsoft/node-core-library';
1111

1212
import { RushConstants } from '../logic/RushConstants';
@@ -35,7 +35,7 @@ export class CommandLineConfiguration {
3535
*/
3636
public static loadFromFileOrDefault(jsonFilename: string): CommandLineConfiguration {
3737
let commandLineJson: ICommandLineJson | undefined = undefined;
38-
if (fs.existsSync(jsonFilename)) {
38+
if (FileSystem.exists(jsonFilename)) {
3939
commandLineJson = JsonFile.loadAndValidate(jsonFilename, CommandLineConfiguration._jsonSchema);
4040
}
4141

‎apps/rush-lib/src/api/CommonVersionsConfiguration.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as fs from 'fs';
54
import * as path from 'path';
65
import {
76
JsonFile,
87
JsonSchema,
98
MapExtensions,
109
PackageName,
11-
ProtectableMap
10+
ProtectableMap,
11+
FileSystem
1212
} from '@microsoft/node-core-library';
1313

1414
/**
@@ -65,7 +65,7 @@ export class CommonVersionsConfiguration {
6565
public static loadFromFile(jsonFilename: string): CommonVersionsConfiguration {
6666
let commonVersionsJson: ICommonVersionsJson | undefined = undefined;
6767

68-
if (fs.existsSync(jsonFilename)) {
68+
if (FileSystem.exists(jsonFilename)) {
6969
commonVersionsJson = JsonFile.loadAndValidate(jsonFilename, CommonVersionsConfiguration._jsonSchema);
7070
}
7171

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as fs from 'fs';
54
import * as path from 'path';
65
import * as semver from 'semver';
76

7+
import {
8+
FileSystem,
9+
JsonFile
10+
} from '@microsoft/node-core-library';
11+
812
import {
913
PublishUtilities,
1014
IChangeInfoHash
@@ -71,19 +75,18 @@ export class ChangelogGenerator {
7175
const markdownPath: string = path.resolve(project.projectFolder, CHANGELOG_MD);
7276
const markdownJSONPath: string = path.resolve(project.projectFolder, CHANGELOG_JSON);
7377

74-
if (fs.existsSync(markdownPath)) {
78+
if (FileSystem.exists(markdownPath)) {
7579
console.log('Found: ' + markdownPath);
76-
if (!fs.existsSync(markdownJSONPath)) {
80+
if (!FileSystem.exists(markdownJSONPath)) {
7781
throw new Error('A CHANGELOG.md without json: ' + markdownPath);
7882
}
7983

8084
const changelog: IChangelog = ChangelogGenerator._getChangelog(project.packageName, project.projectFolder);
8185
const isLockstepped: boolean = !!project.versionPolicy && project.versionPolicy.isLockstepped;
8286

83-
fs.writeFileSync(
87+
FileSystem.writeFile(
8488
path.join(project.projectFolder, CHANGELOG_MD),
85-
ChangelogGenerator._translateToMarkdown(changelog, rushConfiguration, isLockstepped),
86-
{ encoding: 'utf8' }
89+
ChangelogGenerator._translateToMarkdown(changelog, rushConfiguration, isLockstepped)
8790
);
8891
}
8992

@@ -146,12 +149,11 @@ export class ChangelogGenerator {
146149

147150
if (shouldCommit) {
148151
// Write markdown transform.
149-
fs.writeFileSync(changelogFilename, JSON.stringify(changelog, undefined, 2), { encoding: 'utf8' });
152+
JsonFile.save(changelog, changelogFilename);
150153

151-
fs.writeFileSync(
154+
FileSystem.writeFile(
152155
path.join(projectFolder, CHANGELOG_MD),
153-
ChangelogGenerator._translateToMarkdown(changelog, rushConfiguration, isLockstepped),
154-
{ encoding: 'utf8' }
156+
ChangelogGenerator._translateToMarkdown(changelog, rushConfiguration, isLockstepped)
155157
);
156158
}
157159
return changelog;
@@ -168,8 +170,8 @@ export class ChangelogGenerator {
168170
let changelog: IChangelog | undefined = undefined;
169171

170172
// Try to read the existing changelog.
171-
if (fs.existsSync(changelogFilename)) {
172-
changelog = JSON.parse(fs.readFileSync(changelogFilename, 'utf8')) as IChangelog;
173+
if (FileSystem.exists(changelogFilename)) {
174+
changelog = JsonFile.load(changelogFilename);
173175
}
174176

175177
if (!changelog) {

‎apps/rush-lib/src/scripts/install-run-rush.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getRushVersion(): string {
2626
const rushJsonFolder: string = findRushJsonFolder();
2727
const rushJsonPath: string = path.join(rushJsonFolder, RUSH_JSON_FILENAME);
2828
try {
29-
const rushJsonContents: string = fs.readFileSync(rushJsonPath, 'UTF-8');
29+
const rushJsonContents: string = fs.readFileSync(rushJsonPath, 'utf-8');
3030
// Use a regular expression to parse out the rushVersion value because rush.json supports comments,
3131
// but JSON.parse does not and we don't want to pull in more dependencies than we need to in this script.
3232
const rushJsonMatches: string[] = rushJsonContents.match(/\"rushVersion\"\s*\:\s*\"([0-9a-zA-Z.+\-]+)\"/)!;

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

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

9-
import { Text, Path, FileSystem } from '@microsoft/node-core-library';
9+
import {
10+
Text,
11+
Path,
12+
FileSystem
13+
} from '@microsoft/node-core-library';
1014

1115
import { Utilities } from './Utilities';
1216

@@ -55,7 +59,7 @@ export class AsyncRecycler {
5559

5660
++this._movedFolderCount;
5761

58-
// We need to do a simple "fs.renameSync" here, however if the folder we're trying to rename
62+
// We need to do a simple "FileSystem.move" here, however if the folder we're trying to rename
5963
// has a lock, or if its destination container doesn't exist yet,
6064
// then there seems to be some OS process (virus scanner?) that holds
6165
// a lock on the folder for a split second, which causes renameSync to

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class Utilities {
123123
return;
124124
}
125125

126-
// We need to do a simple "fs.mkdirSync(localModulesFolder)" here,
126+
// We need to do a simple "FileSystem.createFolder(localModulesFolder)" here,
127127
// however if the folder we deleted above happened to contain any files,
128128
// then there seems to be some OS process (virus scanner?) that holds
129129
// a lock on the folder for a split second, which causes mkdirSync to

‎common/reviews/api/node-core-library.api.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class FileSystem {
4141
// (undocumented)
4242
static emptyFolder(folderPath: string): void;
4343
// (undocumented)
44-
static exists(path: string): Boolean;
44+
static exists(path: string): boolean;
4545
// (undocumented)
4646
static followLink(linkPath: string): string;
4747
// (undocumented)

‎core-build/gulp-core-build-karma/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@microsoft/gulp-core-build": "3.8.4",
17+
"@microsoft/node-core-library": "1.4.1",
1718
"chai": "~3.5.0",
1819
"gulp": "~3.9.1",
1920
"gulp-karma": "~0.0.5",

0 commit comments

Comments
 (0)