@rushstack/node-core-library
Advanced tools
+12
-0
@@ -5,2 +5,14 @@ { | ||
| { | ||
| "version": "3.22.1", | ||
| "tag": "@rushstack/node-core-library_v3.22.1", | ||
| "date": "Tue, 26 May 2020 23:00:25 GMT", | ||
| "comments": { | ||
| "patch": [ | ||
| { | ||
| "comment": "Make not-exist error messages more readable." | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "version": "3.22.0", | ||
@@ -7,0 +19,0 @@ "tag": "@rushstack/node-core-library_v3.22.0", |
+8
-1
| # Change Log - @rushstack/node-core-library | ||
| This log was last generated on Fri, 22 May 2020 15:08:42 GMT and should not be manually modified. | ||
| This log was last generated on Tue, 26 May 2020 23:00:25 GMT and should not be manually modified. | ||
| ## 3.22.1 | ||
| Tue, 26 May 2020 23:00:25 GMT | ||
| ### Patches | ||
| - Make not-exist error messages more readable. | ||
| ## 3.22.0 | ||
@@ -6,0 +13,0 @@ Fri, 22 May 2020 15:08:42 GMT |
+17
-3
@@ -407,7 +407,21 @@ /// <reference types="node" /> | ||
| /** | ||
| * Returns true if the error provided indicates the file or folder | ||
| * does not exist. | ||
| * Returns true if the error provided indicates the file or folder does not exist. | ||
| */ | ||
| static isNotExistError(error: NodeJS.ErrnoException): boolean; | ||
| static isNotExistError(error: Error): boolean; | ||
| /** | ||
| * Returns true if the error provided indicates the file does not exist. | ||
| */ | ||
| static isFileDoesNotExistError(error: Error): boolean; | ||
| /** | ||
| * Returns true if the error provided indicates the folder does not exist. | ||
| */ | ||
| static isFolderDoesNotExistError(error: Error): boolean; | ||
| /** | ||
| * Detects if the provided error object is a `NodeJS.ErrnoException` | ||
| */ | ||
| static isErrnoException(error: Error): error is NodeJS.ErrnoException; | ||
| private static _wrapException; | ||
| private static _wrapExceptionAsync; | ||
| private static _updateErrorMessage; | ||
| } | ||
| //# sourceMappingURL=FileSystem.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../src/FileSystem.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K,GAAG,KAAK,IAAI,MAAM,CAAC,cAAc;IAU5E,OAAO,CAAC,MAAM,CAAC,cAAc;mBASR,mBAAmB;IASxC,OAAO,CAAC,MAAM,CAAC,mBAAmB;CASnC"} |
+242
-143
@@ -69,3 +69,5 @@ "use strict"; | ||
| static exists(path) { | ||
| return fsx.existsSync(path); | ||
| return FileSystem._wrapException(() => { | ||
| return fsx.existsSync(path); | ||
| }); | ||
| } | ||
@@ -79,3 +81,5 @@ /** | ||
| static getStatistics(path) { | ||
| return fsx.statSync(path); | ||
| return FileSystem._wrapException(() => { | ||
| return fsx.statSync(path); | ||
| }); | ||
| } | ||
@@ -86,3 +90,5 @@ /** | ||
| static getStatisticsAsync(path) { | ||
| return fsx.stat(path); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.stat(path); | ||
| }); | ||
| } | ||
@@ -97,3 +103,5 @@ /** | ||
| static updateTimes(path, times) { | ||
| fsx.utimesSync(path, times.accessedTime, times.modifiedTime); | ||
| return FileSystem._wrapException(() => { | ||
| fsx.utimesSync(path, times.accessedTime, times.modifiedTime); | ||
| }); | ||
| } | ||
@@ -104,5 +112,7 @@ /** | ||
| static updateTimesAsync(path, times) { | ||
| // This cast is needed because the fs-extra typings require both parameters | ||
| // to have the same type (number or Date), whereas Node.js does not require that. | ||
| return fsx.utimes(path, times.accessedTime, times.modifiedTime); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| // This cast is needed because the fs-extra typings require both parameters | ||
| // to have the same type (number or Date), whereas Node.js does not require that. | ||
| return fsx.utimes(path, times.accessedTime, times.modifiedTime); | ||
| }); | ||
| } | ||
@@ -116,3 +126,5 @@ /** | ||
| static changePosixModeBits(path, mode) { | ||
| fs.chmodSync(path, mode); | ||
| FileSystem._wrapException(() => { | ||
| fs.chmodSync(path, mode); | ||
| }); | ||
| } | ||
@@ -123,3 +135,5 @@ /** | ||
| static changePosixModeBitsAsync(path, mode) { | ||
| return fsx.chmod(path, mode); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.chmod(path, mode); | ||
| }); | ||
| } | ||
@@ -137,3 +151,5 @@ /** | ||
| static getPosixModeBits(path) { | ||
| return FileSystem.getStatistics(path).mode; | ||
| return FileSystem._wrapException(() => { | ||
| return FileSystem.getStatistics(path).mode; | ||
| }); | ||
| } | ||
@@ -144,5 +160,5 @@ /** | ||
| static getPosixModeBitsAsync(path) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return FileSystem._wrapExceptionAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
| return (yield FileSystem.getStatisticsAsync(path)).mode; | ||
| }); | ||
| })); | ||
| } | ||
@@ -174,19 +190,21 @@ /** | ||
| static move(options) { | ||
| options = Object.assign({}, MOVE_DEFAULT_OPTIONS, options); | ||
| try { | ||
| fsx.moveSync(options.sourcePath, options.destinationPath, { overwrite: options.overwrite }); | ||
| } | ||
| catch (error) { | ||
| if (options.ensureFolderExists) { | ||
| if (!FileSystem.isNotExistError(error)) { | ||
| FileSystem._wrapException(() => { | ||
| options = Object.assign({}, MOVE_DEFAULT_OPTIONS, options); | ||
| try { | ||
| fsx.moveSync(options.sourcePath, options.destinationPath, { overwrite: options.overwrite }); | ||
| } | ||
| catch (error) { | ||
| if (options.ensureFolderExists) { | ||
| if (!FileSystem.isNotExistError(error)) { | ||
| throw error; | ||
| } | ||
| const folderPath = nodeJsPath.dirname(options.destinationPath); | ||
| FileSystem.ensureFolder(folderPath); | ||
| fsx.moveSync(options.sourcePath, options.destinationPath, { overwrite: options.overwrite }); | ||
| } | ||
| else { | ||
| throw error; | ||
| } | ||
| const folderPath = nodeJsPath.dirname(options.destinationPath); | ||
| FileSystem.ensureFolder(folderPath); | ||
| fsx.moveSync(options.sourcePath, options.destinationPath, { overwrite: options.overwrite }); | ||
| } | ||
| else { | ||
| throw error; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
@@ -197,3 +215,3 @@ /** | ||
| static moveAsync(options) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return FileSystem._wrapExceptionAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
| options = Object.assign({}, MOVE_DEFAULT_OPTIONS, options); | ||
@@ -216,3 +234,3 @@ try { | ||
| } | ||
| }); | ||
| })); | ||
| } | ||
@@ -230,3 +248,5 @@ // =============== | ||
| static ensureFolder(folderPath) { | ||
| fsx.ensureDirSync(folderPath); | ||
| FileSystem._wrapException(() => { | ||
| fsx.ensureDirSync(folderPath); | ||
| }); | ||
| } | ||
@@ -237,3 +257,5 @@ /** | ||
| static ensureFolderAsync(folderPath) { | ||
| return fsx.ensureDir(folderPath); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.ensureDir(folderPath); | ||
| }); | ||
| } | ||
@@ -247,22 +269,13 @@ /** | ||
| static readFolder(folderPath, options) { | ||
| options = Object.assign({}, READ_FOLDER_DEFAULT_OPTIONS, options); | ||
| let fileNames; | ||
| try { | ||
| return FileSystem._wrapException(() => { | ||
| options = Object.assign({}, READ_FOLDER_DEFAULT_OPTIONS, options); | ||
| // @todo: Update this to use Node 10's `withFileTypes: true` option when we drop support for Node 8 | ||
| fileNames = fsx.readdirSync(folderPath); | ||
| } | ||
| catch (e) { | ||
| if (FileSystem.isNotExistError(e)) { | ||
| throw new Error(`Folder does not exist: "${folderPath}"`); | ||
| const fileNames = fsx.readdirSync(folderPath); | ||
| if (options.absolutePaths) { | ||
| return fileNames.map(fileName => nodeJsPath.resolve(folderPath, fileName)); | ||
| } | ||
| else { | ||
| throw e; | ||
| return fileNames; | ||
| } | ||
| } | ||
| if (options.absolutePaths) { | ||
| return fileNames.map(fileName => nodeJsPath.resolve(folderPath, fileName)); | ||
| } | ||
| else { | ||
| return fileNames; | ||
| } | ||
| }); | ||
| } | ||
@@ -273,17 +286,6 @@ /** | ||
| static readFolderAsync(folderPath, options) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return FileSystem._wrapExceptionAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
| options = Object.assign({}, READ_FOLDER_DEFAULT_OPTIONS, options); | ||
| let fileNames; | ||
| try { | ||
| // @todo: Update this to use Node 10's `withFileTypes: true` option when we drop support for Node 8 | ||
| fileNames = yield fsx.readdir(folderPath); | ||
| } | ||
| catch (e) { | ||
| if (FileSystem.isNotExistError(e)) { | ||
| throw new Error(`Folder does not exist: "${folderPath}"`); | ||
| } | ||
| else { | ||
| throw e; | ||
| } | ||
| } | ||
| // @todo: Update this to use Node 10's `withFileTypes: true` option when we drop support for Node 8 | ||
| const fileNames = yield fsx.readdir(folderPath); | ||
| if (options.absolutePaths) { | ||
@@ -295,3 +297,3 @@ return fileNames.map(fileName => nodeJsPath.resolve(folderPath, fileName)); | ||
| } | ||
| }); | ||
| })); | ||
| } | ||
@@ -306,3 +308,5 @@ /** | ||
| static deleteFolder(folderPath) { | ||
| fsx.removeSync(folderPath); | ||
| FileSystem._wrapException(() => { | ||
| fsx.removeSync(folderPath); | ||
| }); | ||
| } | ||
@@ -313,3 +317,5 @@ /** | ||
| static deleteFolderAsync(folderPath) { | ||
| return fsx.remove(folderPath); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.remove(folderPath); | ||
| }); | ||
| } | ||
@@ -325,3 +331,5 @@ /** | ||
| static ensureEmptyFolder(folderPath) { | ||
| fsx.emptyDirSync(folderPath); | ||
| FileSystem._wrapException(() => { | ||
| fsx.emptyDirSync(folderPath); | ||
| }); | ||
| } | ||
@@ -332,3 +340,5 @@ /** | ||
| static ensureEmptyFolderAsync(folderPath) { | ||
| return fsx.emptyDir(folderPath); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.emptyDir(folderPath); | ||
| }); | ||
| } | ||
@@ -348,22 +358,24 @@ // =============== | ||
| static writeFile(filePath, contents, options) { | ||
| options = Object.assign({}, WRITE_FILE_DEFAULT_OPTIONS, options); | ||
| if (options.convertLineEndings) { | ||
| contents = Text_1.Text.convertTo(contents.toString(), options.convertLineEndings); | ||
| } | ||
| try { | ||
| fsx.writeFileSync(filePath, contents, { encoding: options.encoding }); | ||
| } | ||
| catch (error) { | ||
| if (options.ensureFolderExists) { | ||
| if (!FileSystem.isNotExistError(error)) { | ||
| FileSystem._wrapException(() => { | ||
| options = Object.assign({}, WRITE_FILE_DEFAULT_OPTIONS, options); | ||
| if (options.convertLineEndings) { | ||
| contents = Text_1.Text.convertTo(contents.toString(), options.convertLineEndings); | ||
| } | ||
| try { | ||
| fsx.writeFileSync(filePath, contents, { encoding: options.encoding }); | ||
| } | ||
| catch (error) { | ||
| if (options.ensureFolderExists) { | ||
| if (!FileSystem.isNotExistError(error)) { | ||
| throw error; | ||
| } | ||
| const folderPath = nodeJsPath.dirname(filePath); | ||
| FileSystem.ensureFolder(folderPath); | ||
| fsx.writeFileSync(filePath, contents, { encoding: options.encoding }); | ||
| } | ||
| else { | ||
| throw error; | ||
| } | ||
| const folderPath = nodeJsPath.dirname(filePath); | ||
| FileSystem.ensureFolder(folderPath); | ||
| fsx.writeFileSync(filePath, contents, { encoding: options.encoding }); | ||
| } | ||
| else { | ||
| throw error; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
@@ -374,3 +386,3 @@ /** | ||
| static writeFileAsync(filePath, contents, options) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return FileSystem._wrapExceptionAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
| options = Object.assign({}, WRITE_FILE_DEFAULT_OPTIONS, options); | ||
@@ -396,3 +408,3 @@ if (options.convertLineEndings) { | ||
| } | ||
| }); | ||
| })); | ||
| } | ||
@@ -409,22 +421,24 @@ /** | ||
| static appendToFile(filePath, contents, options) { | ||
| options = Object.assign({}, APPEND_TO_FILE_DEFAULT_OPTIONS, options); | ||
| if (options.convertLineEndings) { | ||
| contents = Text_1.Text.convertTo(contents.toString(), options.convertLineEndings); | ||
| } | ||
| try { | ||
| fsx.appendFileSync(filePath, contents, { encoding: options.encoding }); | ||
| } | ||
| catch (error) { | ||
| if (options.ensureFolderExists) { | ||
| if (!FileSystem.isNotExistError(error)) { | ||
| FileSystem._wrapException(() => { | ||
| options = Object.assign({}, APPEND_TO_FILE_DEFAULT_OPTIONS, options); | ||
| if (options.convertLineEndings) { | ||
| contents = Text_1.Text.convertTo(contents.toString(), options.convertLineEndings); | ||
| } | ||
| try { | ||
| fsx.appendFileSync(filePath, contents, { encoding: options.encoding }); | ||
| } | ||
| catch (error) { | ||
| if (options.ensureFolderExists) { | ||
| if (!FileSystem.isNotExistError(error)) { | ||
| throw error; | ||
| } | ||
| const folderPath = nodeJsPath.dirname(filePath); | ||
| FileSystem.ensureFolder(folderPath); | ||
| fsx.appendFileSync(filePath, contents, { encoding: options.encoding }); | ||
| } | ||
| else { | ||
| throw error; | ||
| } | ||
| const folderPath = nodeJsPath.dirname(filePath); | ||
| FileSystem.ensureFolder(folderPath); | ||
| fsx.appendFileSync(filePath, contents, { encoding: options.encoding }); | ||
| } | ||
| else { | ||
| throw error; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
@@ -435,3 +449,3 @@ /** | ||
| static appendToFileAsync(filePath, contents, options) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return FileSystem._wrapExceptionAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
| options = Object.assign({}, APPEND_TO_FILE_DEFAULT_OPTIONS, options); | ||
@@ -457,3 +471,3 @@ if (options.convertLineEndings) { | ||
| } | ||
| }); | ||
| })); | ||
| } | ||
@@ -467,8 +481,10 @@ /** | ||
| static readFile(filePath, options) { | ||
| options = Object.assign({}, READ_FILE_DEFAULT_OPTIONS, options); | ||
| let contents = FileSystem.readFileToBuffer(filePath).toString(options.encoding); | ||
| if (options.convertLineEndings) { | ||
| contents = Text_1.Text.convertTo(contents, options.convertLineEndings); | ||
| } | ||
| return contents; | ||
| return FileSystem._wrapException(() => { | ||
| options = Object.assign({}, READ_FILE_DEFAULT_OPTIONS, options); | ||
| let contents = FileSystem.readFileToBuffer(filePath).toString(options.encoding); | ||
| if (options.convertLineEndings) { | ||
| contents = Text_1.Text.convertTo(contents, options.convertLineEndings); | ||
| } | ||
| return contents; | ||
| }); | ||
| } | ||
@@ -479,3 +495,3 @@ /** | ||
| static readFileAsync(filePath, options) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return FileSystem._wrapExceptionAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
| options = Object.assign({}, READ_FILE_DEFAULT_OPTIONS, options); | ||
@@ -487,3 +503,3 @@ let contents = (yield FileSystem.readFileToBufferAsync(filePath)).toString(options.encoding); | ||
| return contents; | ||
| }); | ||
| })); | ||
| } | ||
@@ -496,3 +512,5 @@ /** | ||
| static readFileToBuffer(filePath) { | ||
| return fsx.readFileSync(filePath); | ||
| return FileSystem._wrapException(() => { | ||
| return fsx.readFileSync(filePath); | ||
| }); | ||
| } | ||
@@ -503,3 +521,5 @@ /** | ||
| static readFileToBufferAsync(filePath) { | ||
| return fsx.readFile(filePath); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.readFile(filePath); | ||
| }); | ||
| } | ||
@@ -512,3 +532,5 @@ /** | ||
| static copyFile(options) { | ||
| fsx.copySync(options.sourcePath, options.destinationPath); | ||
| FileSystem._wrapException(() => { | ||
| fsx.copySync(options.sourcePath, options.destinationPath); | ||
| }); | ||
| } | ||
@@ -519,4 +541,4 @@ /** | ||
| static copyFileAsync(options) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield fsx.copy(options.sourcePath, options.destinationPath); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.copy(options.sourcePath, options.destinationPath); | ||
| }); | ||
@@ -531,11 +553,13 @@ } | ||
| static deleteFile(filePath, options) { | ||
| options = Object.assign({}, DELETE_FILE_DEFAULT_OPTIONS, options); | ||
| try { | ||
| fsx.unlinkSync(filePath); | ||
| } | ||
| catch (error) { | ||
| if (options.throwIfNotExists || !FileSystem.isNotExistError(error)) { | ||
| throw error; | ||
| FileSystem._wrapException(() => { | ||
| options = Object.assign({}, DELETE_FILE_DEFAULT_OPTIONS, options); | ||
| try { | ||
| fsx.unlinkSync(filePath); | ||
| } | ||
| } | ||
| catch (error) { | ||
| if (options.throwIfNotExists || !FileSystem.isNotExistError(error)) { | ||
| throw error; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
@@ -546,3 +570,3 @@ /** | ||
| static deleteFileAsync(filePath, options) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return FileSystem._wrapExceptionAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
| options = Object.assign({}, DELETE_FILE_DEFAULT_OPTIONS, options); | ||
@@ -557,3 +581,3 @@ try { | ||
| } | ||
| }); | ||
| })); | ||
| } | ||
@@ -569,3 +593,5 @@ // =============== | ||
| static getLinkStatistics(path) { | ||
| return fsx.lstatSync(path); | ||
| return FileSystem._wrapException(() => { | ||
| return fsx.lstatSync(path); | ||
| }); | ||
| } | ||
@@ -576,3 +602,5 @@ /** | ||
| static getLinkStatisticsAsync(path) { | ||
| return fsx.lstat(path); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.lstat(path); | ||
| }); | ||
| } | ||
@@ -584,4 +612,6 @@ /** | ||
| static createSymbolicLinkJunction(options) { | ||
| // For directories, we use a Windows "junction". On POSIX operating systems, this produces a regular symlink. | ||
| fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'junction'); | ||
| FileSystem._wrapException(() => { | ||
| // For directories, we use a Windows "junction". On POSIX operating systems, this produces a regular symlink. | ||
| fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'junction'); | ||
| }); | ||
| } | ||
@@ -592,4 +622,6 @@ /** | ||
| static createSymbolicLinkJunctionAsync(options) { | ||
| // For directories, we use a Windows "junction". On POSIX operating systems, this produces a regular symlink. | ||
| return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'junction'); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| // For directories, we use a Windows "junction". On POSIX operating systems, this produces a regular symlink. | ||
| return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'junction'); | ||
| }); | ||
| } | ||
@@ -601,3 +633,5 @@ /** | ||
| static createSymbolicLinkFile(options) { | ||
| fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'file'); | ||
| FileSystem._wrapException(() => { | ||
| fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'file'); | ||
| }); | ||
| } | ||
@@ -608,3 +642,5 @@ /** | ||
| static createSymbolicLinkFileAsync(options) { | ||
| return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'file'); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'file'); | ||
| }); | ||
| } | ||
@@ -616,3 +652,5 @@ /** | ||
| static createSymbolicLinkFolder(options) { | ||
| fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'dir'); | ||
| FileSystem._wrapException(() => { | ||
| fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'dir'); | ||
| }); | ||
| } | ||
@@ -623,3 +661,5 @@ /** | ||
| static createSymbolicLinkFolderAsync(options) { | ||
| return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'dir'); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'dir'); | ||
| }); | ||
| } | ||
@@ -631,3 +671,5 @@ /** | ||
| static createHardLink(options) { | ||
| fsx.linkSync(options.linkTargetPath, options.newLinkPath); | ||
| FileSystem._wrapException(() => { | ||
| fsx.linkSync(options.linkTargetPath, options.newLinkPath); | ||
| }); | ||
| } | ||
@@ -638,3 +680,5 @@ /** | ||
| static createHardLinkAsync(options) { | ||
| return fsx.link(options.linkTargetPath, options.newLinkPath); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.link(options.linkTargetPath, options.newLinkPath); | ||
| }); | ||
| } | ||
@@ -647,3 +691,5 @@ /** | ||
| static getRealPath(linkPath) { | ||
| return fsx.realpathSync(linkPath); | ||
| return FileSystem._wrapException(() => { | ||
| return fsx.realpathSync(linkPath); | ||
| }); | ||
| } | ||
@@ -654,3 +700,5 @@ /** | ||
| static getRealPathAsync(linkPath) { | ||
| return fsx.realpath(linkPath); | ||
| return FileSystem._wrapExceptionAsync(() => { | ||
| return fsx.realpath(linkPath); | ||
| }); | ||
| } | ||
@@ -661,10 +709,61 @@ // =============== | ||
| /** | ||
| * Returns true if the error provided indicates the file or folder | ||
| * does not exist. | ||
| * Returns true if the error provided indicates the file or folder does not exist. | ||
| */ | ||
| static isNotExistError(error) { | ||
| return error.code === 'ENOENT' || error.code === 'ENOTDIR'; | ||
| return FileSystem.isFileDoesNotExistError(error) || FileSystem.isFolderDoesNotExistError(error); | ||
| } | ||
| /** | ||
| * Returns true if the error provided indicates the file does not exist. | ||
| */ | ||
| static isFileDoesNotExistError(error) { | ||
| return FileSystem.isErrnoException(error) && (error.code === 'ENOENT'); | ||
| } | ||
| /** | ||
| * Returns true if the error provided indicates the folder does not exist. | ||
| */ | ||
| static isFolderDoesNotExistError(error) { | ||
| return FileSystem.isErrnoException(error) && (error.code === 'ENOTDIR'); | ||
| } | ||
| /** | ||
| * Detects if the provided error object is a `NodeJS.ErrnoException` | ||
| */ | ||
| static isErrnoException(error) { | ||
| const typedError = error; | ||
| return (typeof typedError.code === 'string' && | ||
| typeof typedError.errno === 'number' && | ||
| typeof typedError.path === 'string' && | ||
| typeof typedError.syscall === 'string'); | ||
| } | ||
| static _wrapException(fn) { | ||
| try { | ||
| return fn(); | ||
| } | ||
| catch (error) { | ||
| FileSystem._updateErrorMessage(error); | ||
| throw error; | ||
| } | ||
| } | ||
| static _wrapExceptionAsync(fn) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| try { | ||
| return yield fn(); | ||
| } | ||
| catch (error) { | ||
| FileSystem._updateErrorMessage(error); | ||
| throw error; | ||
| } | ||
| }); | ||
| } | ||
| static _updateErrorMessage(error) { | ||
| if (FileSystem.isErrnoException(error)) { | ||
| if (FileSystem.isFileDoesNotExistError(error)) { // eslint-disable-line @typescript-eslint/no-use-before-define | ||
| error.message = `File does not exist: ${error.path}\n${error.message}`; | ||
| } | ||
| else if (FileSystem.isFolderDoesNotExistError(error)) { // eslint-disable-line @typescript-eslint/no-use-before-define | ||
| error.message = `Folder does not exist: ${error.path}\n${error.message}`; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| exports.FileSystem = FileSystem; | ||
| //# sourceMappingURL=FileSystem.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"FileSystem.js","sourceRoot":"","sources":["../src/FileSystem.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;AAE3D,mCAAmC;AACnC,yBAAyB;AACzB,gCAAgC;AAEhC,iCAAqD;AA2JrD,MAAM,oBAAoB,GAAoC;IAC5D,SAAS,EAAE,IAAI;IACf,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AAEF,MAAM,2BAA2B,GAA0C;IACzE,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,MAAM,0BAA0B,GAAyC;IACvE,kBAAkB,EAAE,KAAK;IACzB,kBAAkB,EAAE,SAAS;IAC7B,QAAQ,mBAAe;CACxB,CAAC;AAEF,MAAM,8BAA8B,qBAC/B,0BAA0B,CAC9B,CAAC;AAEF,MAAM,yBAAyB,GAAwC;IACrE,QAAQ,mBAAe;IACvB,kBAAkB,EAAE,SAAS;CAC9B,CAAC;AAEF,MAAM,2BAA2B,GAA0C;IACzE,gBAAgB,EAAE,KAAK;CACxB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAa,UAAU;IAErB,kBAAkB;IAClB,oBAAoB;IACpB,kBAAkB;IAElB;;;;;;;;;;OAUG;IACI,MAAM,CAAC,MAAM,CAAC,IAAY;QAC/B,OAAO,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAAC,IAAY;QACtC,OAAO,GAAG,CAAC,QAAQ,CA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AwB,CAAC,OAAqC;QAC1E,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,6BAA6B,CAAC,OAAqC;QAC/E,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc,CAAC,OAAqC;QAChE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,mBAAmB,CAAC,OAAqC;QACrE,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/D,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,QAAgB;QACxC,OAAO,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,gBAAgB,CAAC,QAAgB;QAC7C,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,kBAAkB;IAClB,oBAAoB;IACpB,kBAAkB;IAElB;;;OAGG;IACI,MAAM,CAAC,eAAe,CAAC,KAA4B;QACxD,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;IAC7D,CAAC;CACF;AAtoBD,gCAsoBC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport * as nodeJsPath from 'path';\r\nimport * as fs from 'fs';\r\nimport * as fsx from 'fs-extra';\r\n\r\nimport { Text, NewlineKind, Encoding } from './Text';\r\nimport { PosixModeBits } from './PosixModeBits';\r\n\r\n// The PosixModeBits are intended to be used with bitwise operations.\r\n/* eslint-disable no-bitwise */\r\n\r\n/**\r\n * The options for FileSystem.readFolder()\r\n * @public\r\n */\r\nexport interface IFileSystemReadFolderOptions {\r\n /**\r\n * If true, returns the absolute paths of the files in the folder.\r\n * @defaultValue false\r\n */\r\n absolutePaths?: boolean;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.writeFile()\r\n * @public\r\n */\r\nexport interface IFileSystemWriteFileOptions {\r\n /**\r\n * If true, will ensure the folder is created before writing the file.\r\n * @defaultValue false\r\n */\r\n ensureFolderExists?: boolean;\r\n\r\n /**\r\n * If specified, will normalize line endings to the specified style of newline.\r\n * @defaultValue `undefined` which means no conversion will be performed\r\n */\r\n convertLineEndings?: NewlineKind;\r\n\r\n /**\r\n * If specified, will change the encoding of the file that will be written.\r\n * @defaultValue \"utf8\"\r\n */\r\n encoding?: Encoding;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.readFile()\r\n * @public\r\n */\r\nexport interface IFileSystemReadFileOptions {\r\n /**\r\n * If specified, will change the encoding of the file that will be written.\r\n * @defaultValue Encoding.Utf8\r\n */\r\n encoding?: Encoding;\r\n\r\n /**\r\n * If specified, will normalize line endings to the specified style of newline.\r\n * @defaultValue `undefined` which means no conversion will be performed\r\n */\r\n convertLineEndings?: NewlineKind;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.move()\r\n * @public\r\n */\r\nexport interface IFileSystemMoveOptions {\r\n /**\r\n * The path of the existing object to be moved.\r\n * The path may be absolute or relative.\r\n */\r\n sourcePath: string;\r\n\r\n /**\r\n * The new path for the object.\r\n * The path may be absolute or relative.\r\n */\r\n destinationPath: string;\r\n\r\n /**\r\n * If true, will overwrite the file if it already exists.\r\n * @defaultValue true\r\n */\r\n overwrite?: boolean;\r\n\r\n /**\r\n * If true, will ensure the folder is created before writing the file.\r\n * @defaultValue false\r\n */\r\n ensureFolderExists?: boolean;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.copyFile()\r\n * @public\r\n */\r\nexport interface IFileSystemCopyFileOptions {\r\n /**\r\n * The path of the existing object to be copied.\r\n * The path may be absolute or relative.\r\n */\r\n sourcePath: string;\r\n\r\n /**\r\n * The path that the object will be copied to.\r\n * The path may be absolute or relative.\r\n */\r\n destinationPath: string;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.deleteFile()\r\n * @public\r\n*/\r\nexport interface IFileSystemDeleteFileOptions {\r\n /**\r\n * If true, will throw an exception if the file did not exist before `deleteFile()` was called.\r\n * @defaultValue false\r\n */\r\n throwIfNotExists?: boolean;\r\n}\r\n\r\n/**\r\n * The parameters for `updateTimes()`.\r\n * Both times must be specified.\r\n * @public\r\n */\r\nexport interface IFileSystemUpdateTimeParameters {\r\n /**\r\n * The POSIX epoch time or Date when this was last accessed.\r\n */\r\n accessedTime: number | Date;\r\n\r\n /**\r\n * The POSIX epoch time or Date when this was last modified\r\n */\r\n modifiedTime: number | Date;\r\n}\r\n\r\n/**\r\n * The options for `FileSystem.createSymbolicLinkJunction()`, `createSymbolicLinkFile()`,\r\n * `createSymbolicLinkFolder()`, and `createHardLink()`.\r\n *\r\n * @public\r\n */\r\nexport interface IFileSystemCreateLinkOptions {\r\n /**\r\n * The existing path that the symbolic link will point to.\r\n */\r\n linkTargetPath: string;\r\n\r\n /**\r\n * The new path for the new symlink link to be created.\r\n */\r\n newLinkPath: string;\r\n}\r\n\r\nconst MOVE_DEFAULT_OPTIONS: Partial<IFileSystemMoveOptions> = {\r\n overwrite: true,\r\n ensureFolderExists: false\r\n};\r\n\r\nconst READ_FOLDER_DEFAULT_OPTIONS: Partial<IFileSystemReadFolderOptions> = {\r\n absolutePaths: false\r\n};\r\n\r\nconst WRITE_FILE_DEFAULT_OPTIONS: Partial<IFileSystemWriteFileOptions> = {\r\n ensureFolderExists: false,\r\n convertLineEndings: undefined,\r\n encoding: Encoding.Utf8\r\n};\r\n\r\nconst APPEND_TO_FILE_DEFAULT_OPTIONS: Partial<IFileSystemWriteFileOptions> = {\r\n ...WRITE_FILE_DEFAULT_OPTIONS\r\n};\r\n\r\nconst READ_FILE_DEFAULT_OPTIONS: Partial<IFileSystemReadFileOptions> = {\r\n encoding: Encoding.Utf8,\r\n convertLineEndings: undefined\r\n};\r\n\r\nconst DELETE_FILE_DEFAULT_OPTIONS: Partial<IFileSystemDeleteFileOptions> = {\r\n throwIfNotExists: false\r\n};\r\n\r\n/**\r\n * The FileSystem API provides a complete set of recommended operations for interacting with the file system.\r\n *\r\n * @remarks\r\n * We recommend to use this instead of the native `fs` API, because `fs` is a minimal set of low-level\r\n * primitives that must be mapped for each supported operating system. The FileSystem API takes a\r\n * philosophical approach of providing \"one obvious way\" to do each operation. We also prefer synchronous\r\n * operations except in cases where there would be a clear performance benefit for using async, since synchronous\r\n * code is much easier to read and debug. Also, indiscriminate parallelism has been seen to actually worsen\r\n * performance, versus improving it.\r\n *\r\n * Note that in the documentation, we refer to \"filesystem objects\", this can be a\r\n * file, folder, symbolic link, hard link, directory junction, etc.\r\n *\r\n * @public\r\n */\r\nexport class FileSystem {\r\n\r\n // ===============\r\n // COMMON OPERATIONS\r\n // ===============\r\n\r\n /**\r\n * Returns true if the path exists on disk.\r\n * Behind the scenes it uses `fs.existsSync()`.\r\n * @remarks\r\n * There is a debate about the fact that after `fs.existsSync()` returns true,\r\n * the file might be deleted before fs.readSync() is called, which would imply that everybody\r\n * should catch a `readSync()` exception, and nobody should ever use `fs.existsSync()`.\r\n * We find this to be unpersuasive, since \"unexceptional exceptions\" really hinder the\r\n * break-on-exception debugging experience. Also, throwing/catching is generally slow.\r\n * @param path - The absolute or relative path to the filesystem object.\r\n */\r\n public static exists(path: string): boolean {\r\n return fsx.existsSync(path);\r\n }\r\n\r\n /**\r\n * Gets the statistics for a particular filesystem object.\r\n * If the path is a link, this function follows the link and returns statistics about the link target.\r\n * Behind the scenes it uses `fs.statSync()`.\r\n * @param path - The absolute or relative path to the filesystem object.\r\n */\r\n public static getStatistics(path: string): fs.Stats {\r\n return fsx.statSync(path);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.getStatistics}.\r\n */\r\n public static getStatisticsAsync(path: string): Promise<fs.Stats> {\r\n return fsx.stat(path);\r\n }\r\n\r\n /**\r\n * Updates the accessed and modified timestamps of the filesystem object referenced by path.\r\n * Behind the scenes it uses `fs.utimesSync()`.\r\n * The caller should specify both times in the `times` parameter.\r\n * @param path - The path of the file that should be modified.\r\n * @param times - The times that the object should be updated to reflect.\r\n */\r\n public static updateTimes(path: string, times: IFileSystemUpdateTimeParameters): void {\r\n fsx.utimesSync(path, times.accessedTime, times.modifiedTime);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.updateTimes}.\r\n */\r\n public static updateTimesAsync(path: string, times: IFileSystemUpdateTimeParameters): Promise<void> {\r\n // This cast is needed because the fs-extra typings require both parameters\r\n // to have the same type (number or Date), whereas Node.js does not require that.\r\n return fsx.utimes(path, times.accessedTime as number, times.modifiedTime as number);\r\n }\r\n\r\n\r\n /**\r\n * Changes the permissions (i.e. file mode bits) for a filesystem object.\r\n * Behind the scenes it uses `fs.chmodSync()`.\r\n * @param path - The absolute or relative path to the object that should be updated.\r\n * @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum\r\n */\r\n public static changePosixModeBits(path: string, mode: PosixModeBits): void {\r\n fs.chmodSync(path, mode);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.changePosixModeBits}.\r\n */\r\n public static changePosixModeBitsAsync(path: string, mode: PosixModeBits): Promise<void> {\r\n return fsx.chmod(path, mode);\r\n }\r\n\r\n /**\r\n * Retrieves the permissions (i.e. file mode bits) for a filesystem object.\r\n * Behind the scenes it uses `fs.chmodSync()`.\r\n * @param path - The absolute or relative path to the object that should be updated.\r\n *\r\n * @remarks\r\n * This calls {@link FileSystem.getStatistics} to get the POSIX mode bits.\r\n * If statistics in addition to the mode bits are needed, it is more efficient\r\n * to call {@link FileSystem.getStatistics} directly instead.\r\n */\r\n public static getPosixModeBits(path: string): PosixModeBits {\r\n return FileSystem.getStatistics(path).mode;\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.getPosixModeBits}.\r\n */\r\n public static async getPosixModeBitsAsync(path: string): Promise<PosixModeBits> {\r\n return (await FileSystem.getStatisticsAsync(path)).mode;\r\n }\r\n\r\n /**\r\n * Returns a 10-character string representation of a PosixModeBits value similar to what\r\n * would be displayed by a command such as \"ls -l\" on a POSIX-like operating system.\r\n * @remarks\r\n * For example, `PosixModeBits.AllRead | PosixModeBits.AllWrite` would be formatted as \"-rw-rw-rw-\".\r\n * @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum\r\n */\r\n public static formatPosixModeBits(modeBits: PosixModeBits): string {\r\n let result: string = '-'; // (later we may add support for additional states such as S_IFDIR or S_ISUID)\r\n\r\n result += (modeBits & PosixModeBits.UserRead) ? 'r' : '-';\r\n result += (modeBits & PosixModeBits.UserWrite) ? 'w' : '-';\r\n result += (modeBits & PosixModeBits.UserExecute) ? 'x' : '-';\r\n\r\n result += (modeBits & PosixModeBits.GroupRead) ? 'r' : '-';\r\n result += (modeBits & PosixModeBits.GroupWrite) ? 'w' : '-';\r\n result += (modeBits & PosixModeBits.GroupExecute) ? 'x' : '-';\r\n\r\n result += (modeBits & PosixModeBits.OthersRead) ? 'r' : '-';\r\n result += (modeBits & PosixModeBits.OthersWrite) ? 'w' : '-';\r\n result += (modeBits & PosixModeBits.OthersExecute) ? 'x' : '-';\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Moves a file. The folder must exist, unless the `ensureFolderExists` option is provided.\r\n * Behind the scenes it uses `fs-extra.moveSync()`\r\n */\r\n public static move(options: IFileSystemMoveOptions): void {\r\n options = {\r\n ...MOVE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n try {\r\n fsx.moveSync(options.sourcePath, options.destinationPath, { overwrite: options.overwrite });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(options.destinationPath);\r\n FileSystem.ensureFolder(folderPath);\r\n fsx.moveSync(options.sourcePath, options.destinationPath, { overwrite: options.overwrite });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.move}.\r\n */\r\n public static async moveAsync(options: IFileSystemMoveOptions): Promise<void> {\r\n options = {\r\n ...MOVE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n try {\r\n await fsx.move(options.sourcePath, options.destinationPath, { overwrite: options.overwrite });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(options.destinationPath);\r\n await FileSystem.ensureFolderAsync(nodeJsPath.dirname(folderPath));\r\n await fsx.move(options.sourcePath, options.destinationPath, { overwrite: options.overwrite });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n // ===============\r\n // FOLDER OPERATIONS\r\n // ===============\r\n\r\n /**\r\n * Recursively creates a folder at a given path.\r\n * Behind the scenes is uses `fs-extra.ensureDirSync()`.\r\n * @remarks\r\n * Throws an exception if anything in the folderPath is not a folder.\r\n * @param folderPath - The absolute or relative path of the folder which should be created.\r\n */\r\n public static ensureFolder(folderPath: string): void {\r\n fsx.ensureDirSync(folderPath);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.ensureFolder}.\r\n */\r\n public static ensureFolderAsync(folderPath: string): Promise<void> {\r\n return fsx.ensureDir(folderPath);\r\n }\r\n\r\n /**\r\n * Reads the contents of the folder, not including \".\" or \"..\".\r\n * Behind the scenes it uses `fs.readdirSync()`.\r\n * @param folderPath - The absolute or relative path to the folder which should be read.\r\n * @param options - Optional settings that can change the behavior. Type: `IReadFolderOptions`\r\n */\r\n public static readFolder(folderPath: string, options?: IFileSystemReadFolderOptions): string[] {\r\n options = {\r\n ...READ_FOLDER_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n let fileNames: string[]\r\n try {\r\n // @todo: Update this to use Node 10's `withFileTypes: true` option when we drop support for Node 8\r\n fileNames = fsx.readdirSync(folderPath);\r\n } catch (e) {\r\n if (FileSystem.isNotExistError(e)) {\r\n throw new Error(`Folder does not exist: \"${folderPath}\"`);\r\n } else {\r\n throw e;\r\n }\r\n }\r\n\r\n if (options.absolutePaths) {\r\n return fileNames.map(fileName => nodeJsPath.resolve(folderPath, fileName));\r\n } else {\r\n return fileNames;\r\n }\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.readFolder}.\r\n */\r\n public static async readFolderAsync(folderPath: string, options?: IFileSystemReadFolderOptions): Promise<string[]> {\r\n options = {\r\n ...READ_FOLDER_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n let fileNames: string[];\r\n try {\r\n // @todo: Update this to use Node 10's `withFileTypes: true` option when we drop support for Node 8\r\n fileNames = await fsx.readdir(folderPath);\r\n } catch (e) {\r\n if (FileSystem.isNotExistError(e)) {\r\n throw new Error(`Folder does not exist: \"${folderPath}\"`);\r\n } else {\r\n throw e;\r\n }\r\n }\r\n\r\n if (options.absolutePaths) {\r\n return fileNames.map(fileName => nodeJsPath.resolve(folderPath, fileName));\r\n } else {\r\n return fileNames;\r\n }\r\n }\r\n\r\n /**\r\n * Deletes a folder, including all of its contents.\r\n * Behind the scenes is uses `fs-extra.removeSync()`.\r\n * @remarks\r\n * Does not throw if the folderPath does not exist.\r\n * @param folderPath - The absolute or relative path to the folder which should be deleted.\r\n */\r\n public static deleteFolder(folderPath: string): void {\r\n fsx.removeSync(folderPath);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.deleteFolder}.\r\n */\r\n public static deleteFolderAsync(folderPath: string): Promise<void> {\r\n return fsx.remove(folderPath);\r\n }\r\n\r\n /**\r\n * Deletes the content of a folder, but not the folder itself. Also ensures the folder exists.\r\n * Behind the scenes it uses `fs-extra.emptyDirSync()`.\r\n * @remarks\r\n * This is a workaround for a common race condition, where the virus scanner holds a lock on the folder\r\n * for a brief period after it was deleted, causing EBUSY errors for any code that tries to recreate the folder.\r\n * @param folderPath - The absolute or relative path to the folder which should have its contents deleted.\r\n */\r\n public static ensureEmptyFolder(folderPath: string): void {\r\n fsx.emptyDirSync(folderPath);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.ensureEmptyFolder}.\r\n */\r\n public static ensureEmptyFolderAsync(folderPath: string): Promise<void> {\r\n return fsx.emptyDir(folderPath);\r\n }\r\n\r\n // ===============\r\n // FILE OPERATIONS\r\n // ===============\r\n\r\n /**\r\n * Writes a text string to a file on disk, overwriting the file if it already exists.\r\n * Behind the scenes it uses `fs.writeFileSync()`.\r\n * @remarks\r\n * Throws an error if the folder doesn't exist, unless ensureFolder=true.\r\n * @param filePath - The absolute or relative path of the file.\r\n * @param contents - The text that should be written to the file.\r\n * @param options - Optional settings that can change the behavior. Type: `IWriteFileOptions`\r\n */\r\n public static writeFile(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): void {\r\n options = {\r\n ...WRITE_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents.toString(), options.convertLineEndings);\r\n }\r\n\r\n try {\r\n fsx.writeFileSync(filePath, contents, { encoding: options.encoding });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(filePath);\r\n FileSystem.ensureFolder(folderPath);\r\n fsx.writeFileSync(filePath, contents, { encoding: options.encoding });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.writeFile}.\r\n */\r\n public static async writeFileAsync(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): Promise<void> {\r\n options = {\r\n ...WRITE_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents.toString(), options.convertLineEndings);\r\n }\r\n\r\n try {\r\n await fsx.writeFile(filePath, contents, { encoding: options.encoding });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(filePath);\r\n await FileSystem.ensureFolderAsync(folderPath);\r\n await fsx.writeFile(filePath, contents, { encoding: options.encoding });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Writes a text string to a file on disk, appending to the file if it already exists.\r\n * Behind the scenes it uses `fs.appendFileSync()`.\r\n * @remarks\r\n * Throws an error if the folder doesn't exist, unless ensureFolder=true.\r\n * @param filePath - The absolute or relative path of the file.\r\n * @param contents - The text that should be written to the file.\r\n * @param options - Optional settings that can change the behavior. Type: `IWriteFileOptions`\r\n */\r\n public static appendToFile(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): void {\r\n options = {\r\n ...APPEND_TO_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents.toString(), options.convertLineEndings);\r\n }\r\n\r\n try {\r\n fsx.appendFileSync(filePath, contents, { encoding: options.encoding });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(filePath);\r\n FileSystem.ensureFolder(folderPath);\r\n fsx.appendFileSync(filePath, contents, { encoding: options.encoding });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.appendToFile}.\r\n */\r\n public static async appendToFileAsync(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): Promise<void> {\r\n options = {\r\n ...APPEND_TO_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents.toString(), options.convertLineEndings);\r\n }\r\n\r\n try {\r\n await fsx.appendFile(filePath, contents, { encoding: options.encoding });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(filePath);\r\n await FileSystem.ensureFolderAsync(folderPath);\r\n await fsx.appendFile(filePath, contents, { encoding: options.encoding });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Reads the contents of a file into a string.\r\n * Behind the scenes it uses `fs.readFileSync()`.\r\n * @param filePath - The relative or absolute path to the file whose contents should be read.\r\n * @param options - Optional settings that can change the behavior. Type: `IReadFileOptions`\r\n */\r\n public static readFile(filePath: string, options?: IFileSystemReadFileOptions): string {\r\n options = {\r\n ...READ_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n let contents: string = FileSystem.readFileToBuffer(filePath).toString(options.encoding);\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents, options.convertLineEndings);\r\n }\r\n\r\n return contents;\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.readFile}.\r\n */\r\n public static async readFileAsync(filePath: string, options?: IFileSystemReadFileOptions): Promise<string> {\r\n options = {\r\n ...READ_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n let contents: string = (await FileSystem.readFileToBufferAsync(filePath)).toString(options.encoding);\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents, options.convertLineEndings);\r\n }\r\n\r\n return contents;\r\n }\r\n\r\n /**\r\n * Reads the contents of a file into a buffer.\r\n * Behind the scenes is uses `fs.readFileSync()`.\r\n * @param filePath - The relative or absolute path to the file whose contents should be read.\r\n */\r\n public static readFileToBuffer(filePath: string): Buffer {\r\n return fsx.readFileSync(filePath);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.readFileToBuffer}.\r\n */\r\n public static readFileToBufferAsync(filePath: string): Promise<Buffer> {\r\n return fsx.readFile(filePath);\r\n }\r\n\r\n /**\r\n * Copies a file from one location to another.\r\n * By default, destinationPath is overwritten if it already exists.\r\n * Behind the scenes it uses `fs.copyFileSync()`.\r\n */\r\n public static copyFile(options: IFileSystemCopyFileOptions): void {\r\n fsx.copySync(options.sourcePath, options.destinationPath);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.copyFile}.\r\n */\r\n public static async copyFileAsync(options: IFileSystemCopyFileOptions): Promise<void> {\r\n await fsx.copy(options.sourcePath, options.destinationPath);\r\n }\r\n\r\n /**\r\n * Deletes a file. Can optionally throw if the file doesn't exist.\r\n * Behind the scenes it uses `fs.unlinkSync()`.\r\n * @param filePath - The absolute or relative path to the file that should be deleted.\r\n * @param options - Optional settings that can change the behavior. Type: `IDeleteFileOptions`\r\n */\r\n public static deleteFile(filePath: string, options?: IFileSystemDeleteFileOptions): void {\r\n options = {\r\n ...DELETE_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n try {\r\n fsx.unlinkSync(filePath);\r\n } catch (error) {\r\n if (options.throwIfNotExists || !FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.deleteFile}.\r\n */\r\n public static async deleteFileAsync(filePath: string, options?: IFileSystemDeleteFileOptions): Promise<void> {\r\n options = {\r\n ...DELETE_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n try {\r\n await fsx.unlink(filePath);\r\n } catch (error) {\r\n if (options.throwIfNotExists || !FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n // ===============\r\n // LINK OPERATIONS\r\n // ===============\r\n\r\n /**\r\n * Gets the statistics of a filesystem object. Does NOT follow the link to its target.\r\n * Behind the scenes it uses `fs.lstatSync()`.\r\n * @param path - The absolute or relative path to the filesystem object.\r\n */\r\n public static getLinkStatistics(path: string): fs.Stats {\r\n return fsx.lstatSync(path);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.getLinkStatistics}.\r\n */\r\n public static getLinkStatisticsAsync(path: string): Promise<fs.Stats> {\r\n return fsx.lstat(path);\r\n }\r\n\r\n /**\r\n * Creates a Windows \"directory junction\". Behaves like `createSymbolicLinkToFile()` on other platforms.\r\n * Behind the scenes it uses `fs.symlinkSync()`.\r\n */\r\n public static createSymbolicLinkJunction(options: IFileSystemCreateLinkOptions): void {\r\n // For directories, we use a Windows \"junction\". On POSIX operating systems, this produces a regular symlink.\r\n fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'junction');\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.createSymbolicLinkJunction}.\r\n */\r\n public static createSymbolicLinkJunctionAsync(options: IFileSystemCreateLinkOptions): Promise<void> {\r\n // For directories, we use a Windows \"junction\". On POSIX operating systems, this produces a regular symlink.\r\n return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'junction');\r\n }\r\n\r\n /**\r\n * Creates a symbolic link to a file (on Windows this requires elevated permissionsBits).\r\n * Behind the scenes it uses `fs.symlinkSync()`.\r\n */\r\n public static createSymbolicLinkFile(options: IFileSystemCreateLinkOptions): void {\r\n fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'file');\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.createSymbolicLinkFile}.\r\n */\r\n public static createSymbolicLinkFileAsync(options: IFileSystemCreateLinkOptions): Promise<void> {\r\n return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'file');\r\n }\r\n\r\n /**\r\n * Creates a symbolic link to a folder (on Windows this requires elevated permissionsBits).\r\n * Behind the scenes it uses `fs.symlinkSync()`.\r\n */\r\n public static createSymbolicLinkFolder(options: IFileSystemCreateLinkOptions): void {\r\n fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'dir');\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.createSymbolicLinkFolder}.\r\n */\r\n public static createSymbolicLinkFolderAsync(options: IFileSystemCreateLinkOptions): Promise<void> {\r\n return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'dir');\r\n }\r\n\r\n /**\r\n * Creates a hard link.\r\n * Behind the scenes it uses `fs.linkSync()`.\r\n */\r\n public static createHardLink(options: IFileSystemCreateLinkOptions): void {\r\n fsx.linkSync(options.linkTargetPath, options.newLinkPath);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.createHardLink}.\r\n */\r\n public static createHardLinkAsync(options: IFileSystemCreateLinkOptions): Promise<void> {\r\n return fsx.link(options.linkTargetPath, options.newLinkPath);\r\n }\r\n\r\n /**\r\n * Follows a link to its destination and returns the absolute path to the final target of the link.\r\n * Behind the scenes it uses `fs.realpathSync()`.\r\n * @param linkPath - The path to the link.\r\n */\r\n public static getRealPath(linkPath: string): string {\r\n return fsx.realpathSync(linkPath);\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.getRealPath}.\r\n */\r\n public static getRealPathAsync(linkPath: string): Promise<string> {\r\n return fsx.realpath(linkPath);\r\n }\r\n\r\n // ===============\r\n // UTILITY FUNCTIONS\r\n // ===============\r\n\r\n /**\r\n * Returns true if the error provided indicates the file or folder\r\n * does not exist.\r\n */\r\n public static isNotExistError(error: NodeJS.ErrnoException): boolean {\r\n return error.code === 'ENOENT' || error.code === 'ENOTDIR';\r\n }\r\n}\r\n"]} | ||
| {"version":3,"file":"FileSystem.js","sourceRoot":"","sources":["../src/FileSystem.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;AAE3D,mCAAmC;AACnC,yBAAyB;AACzB,gCAAgC;AAEhC,iCAAqD;AA2JrD,MAAM,oBAAoB,GAAoC;IAC5D,SAAS,EAAE,IAAI;IACf,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AAEF,MAAM,2BAA2B,GAA0C;IACzE,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,MAAM,0BAA0B,GAAyC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,EAAE,CAAC;SACb;QAAC,OAAO,KAAK,EAAE;YACd,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;YACtC,MAAM,KAAK,CAAC;SACb;IACH,CAAC;IAEO,MAAM,CAAO,mBAAmB,CAAU,EAA0B;;YAC1E,IAAI;gBACF,OAAO,MAAM,EAAE,EAAE,CAAC;aACnB;YAAC,OAAO,KAAK,EAAE;gBACd,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;gBACtC,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;IAEO,MAAM,CAAC,mBAAmB,CAAC,KAAY;QAC7C,IAAI,UAAU,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE;YACtC,IAAI,UAAU,CAAC,uBAAuB,CAAC,KAAK,CAAC,EAAE,EAAE,8DAA8D;gBAC7G,KAAK,CAAC,OAAO,GAAG,wBAAwB,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;aACxE;iBAAM,IAAI,UAAU,CAAC,yBAAyB,CAAC,KAAK,CAAC,EAAE,EAAE,8DAA8D;gBACtH,KAAK,CAAC,OAAO,GAAG,0BAA0B,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;aAC1E;SACF;IACH,CAAC;CACF;AA7vBD,gCA6vBC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport * as nodeJsPath from 'path';\r\nimport * as fs from 'fs';\r\nimport * as fsx from 'fs-extra';\r\n\r\nimport { Text, NewlineKind, Encoding } from './Text';\r\nimport { PosixModeBits } from './PosixModeBits';\r\n\r\n// The PosixModeBits are intended to be used with bitwise operations.\r\n/* eslint-disable no-bitwise */\r\n\r\n/**\r\n * The options for FileSystem.readFolder()\r\n * @public\r\n */\r\nexport interface IFileSystemReadFolderOptions {\r\n /**\r\n * If true, returns the absolute paths of the files in the folder.\r\n * @defaultValue false\r\n */\r\n absolutePaths?: boolean;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.writeFile()\r\n * @public\r\n */\r\nexport interface IFileSystemWriteFileOptions {\r\n /**\r\n * If true, will ensure the folder is created before writing the file.\r\n * @defaultValue false\r\n */\r\n ensureFolderExists?: boolean;\r\n\r\n /**\r\n * If specified, will normalize line endings to the specified style of newline.\r\n * @defaultValue `undefined` which means no conversion will be performed\r\n */\r\n convertLineEndings?: NewlineKind;\r\n\r\n /**\r\n * If specified, will change the encoding of the file that will be written.\r\n * @defaultValue \"utf8\"\r\n */\r\n encoding?: Encoding;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.readFile()\r\n * @public\r\n */\r\nexport interface IFileSystemReadFileOptions {\r\n /**\r\n * If specified, will change the encoding of the file that will be written.\r\n * @defaultValue Encoding.Utf8\r\n */\r\n encoding?: Encoding;\r\n\r\n /**\r\n * If specified, will normalize line endings to the specified style of newline.\r\n * @defaultValue `undefined` which means no conversion will be performed\r\n */\r\n convertLineEndings?: NewlineKind;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.move()\r\n * @public\r\n */\r\nexport interface IFileSystemMoveOptions {\r\n /**\r\n * The path of the existing object to be moved.\r\n * The path may be absolute or relative.\r\n */\r\n sourcePath: string;\r\n\r\n /**\r\n * The new path for the object.\r\n * The path may be absolute or relative.\r\n */\r\n destinationPath: string;\r\n\r\n /**\r\n * If true, will overwrite the file if it already exists.\r\n * @defaultValue true\r\n */\r\n overwrite?: boolean;\r\n\r\n /**\r\n * If true, will ensure the folder is created before writing the file.\r\n * @defaultValue false\r\n */\r\n ensureFolderExists?: boolean;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.copyFile()\r\n * @public\r\n */\r\nexport interface IFileSystemCopyFileOptions {\r\n /**\r\n * The path of the existing object to be copied.\r\n * The path may be absolute or relative.\r\n */\r\n sourcePath: string;\r\n\r\n /**\r\n * The path that the object will be copied to.\r\n * The path may be absolute or relative.\r\n */\r\n destinationPath: string;\r\n}\r\n\r\n/**\r\n * The options for FileSystem.deleteFile()\r\n * @public\r\n*/\r\nexport interface IFileSystemDeleteFileOptions {\r\n /**\r\n * If true, will throw an exception if the file did not exist before `deleteFile()` was called.\r\n * @defaultValue false\r\n */\r\n throwIfNotExists?: boolean;\r\n}\r\n\r\n/**\r\n * The parameters for `updateTimes()`.\r\n * Both times must be specified.\r\n * @public\r\n */\r\nexport interface IFileSystemUpdateTimeParameters {\r\n /**\r\n * The POSIX epoch time or Date when this was last accessed.\r\n */\r\n accessedTime: number | Date;\r\n\r\n /**\r\n * The POSIX epoch time or Date when this was last modified\r\n */\r\n modifiedTime: number | Date;\r\n}\r\n\r\n/**\r\n * The options for `FileSystem.createSymbolicLinkJunction()`, `createSymbolicLinkFile()`,\r\n * `createSymbolicLinkFolder()`, and `createHardLink()`.\r\n *\r\n * @public\r\n */\r\nexport interface IFileSystemCreateLinkOptions {\r\n /**\r\n * The existing path that the symbolic link will point to.\r\n */\r\n linkTargetPath: string;\r\n\r\n /**\r\n * The new path for the new symlink link to be created.\r\n */\r\n newLinkPath: string;\r\n}\r\n\r\nconst MOVE_DEFAULT_OPTIONS: Partial<IFileSystemMoveOptions> = {\r\n overwrite: true,\r\n ensureFolderExists: false\r\n};\r\n\r\nconst READ_FOLDER_DEFAULT_OPTIONS: Partial<IFileSystemReadFolderOptions> = {\r\n absolutePaths: false\r\n};\r\n\r\nconst WRITE_FILE_DEFAULT_OPTIONS: Partial<IFileSystemWriteFileOptions> = {\r\n ensureFolderExists: false,\r\n convertLineEndings: undefined,\r\n encoding: Encoding.Utf8\r\n};\r\n\r\nconst APPEND_TO_FILE_DEFAULT_OPTIONS: Partial<IFileSystemWriteFileOptions> = {\r\n ...WRITE_FILE_DEFAULT_OPTIONS\r\n};\r\n\r\nconst READ_FILE_DEFAULT_OPTIONS: Partial<IFileSystemReadFileOptions> = {\r\n encoding: Encoding.Utf8,\r\n convertLineEndings: undefined\r\n};\r\n\r\nconst DELETE_FILE_DEFAULT_OPTIONS: Partial<IFileSystemDeleteFileOptions> = {\r\n throwIfNotExists: false\r\n};\r\n\r\n/**\r\n * The FileSystem API provides a complete set of recommended operations for interacting with the file system.\r\n *\r\n * @remarks\r\n * We recommend to use this instead of the native `fs` API, because `fs` is a minimal set of low-level\r\n * primitives that must be mapped for each supported operating system. The FileSystem API takes a\r\n * philosophical approach of providing \"one obvious way\" to do each operation. We also prefer synchronous\r\n * operations except in cases where there would be a clear performance benefit for using async, since synchronous\r\n * code is much easier to read and debug. Also, indiscriminate parallelism has been seen to actually worsen\r\n * performance, versus improving it.\r\n *\r\n * Note that in the documentation, we refer to \"filesystem objects\", this can be a\r\n * file, folder, symbolic link, hard link, directory junction, etc.\r\n *\r\n * @public\r\n */\r\nexport class FileSystem {\r\n // ===============\r\n // COMMON OPERATIONS\r\n // ===============\r\n\r\n /**\r\n * Returns true if the path exists on disk.\r\n * Behind the scenes it uses `fs.existsSync()`.\r\n * @remarks\r\n * There is a debate about the fact that after `fs.existsSync()` returns true,\r\n * the file might be deleted before fs.readSync() is called, which would imply that everybody\r\n * should catch a `readSync()` exception, and nobody should ever use `fs.existsSync()`.\r\n * We find this to be unpersuasive, since \"unexceptional exceptions\" really hinder the\r\n * break-on-exception debugging experience. Also, throwing/catching is generally slow.\r\n * @param path - The absolute or relative path to the filesystem object.\r\n */\r\n public static exists(path: string): boolean {\r\n return FileSystem._wrapException(() => {\r\n return fsx.existsSync(path);\r\n });\r\n }\r\n\r\n /**\r\n * Gets the statistics for a particular filesystem object.\r\n * If the path is a link, this function follows the link and returns statistics about the link target.\r\n * Behind the scenes it uses `fs.statSync()`.\r\n * @param path - The absolute or relative path to the filesystem object.\r\n */\r\n public static getStatistics(path: string): fs.Stats {\r\n return FileSystem._wrapException(() => {\r\n return fsx.statSync(path);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.getStatistics}.\r\n */\r\n public static getStatisticsAsync(path: string): Promise<fs.Stats> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.stat(path);\r\n });\r\n }\r\n\r\n /**\r\n * Updates the accessed and modified timestamps of the filesystem object referenced by path.\r\n * Behind the scenes it uses `fs.utimesSync()`.\r\n * The caller should specify both times in the `times` parameter.\r\n * @param path - The path of the file that should be modified.\r\n * @param times - The times that the object should be updated to reflect.\r\n */\r\n public static updateTimes(path: string, times: IFileSystemUpdateTimeParameters): void {\r\n return FileSystem._wrapException(() => {\r\n fsx.utimesSync(path, times.accessedTime, times.modifiedTime);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.updateTimes}.\r\n */\r\n public static updateTimesAsync(path: string, times: IFileSystemUpdateTimeParameters): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n // This cast is needed because the fs-extra typings require both parameters\r\n // to have the same type (number or Date), whereas Node.js does not require that.\r\n return fsx.utimes(path, times.accessedTime as number, times.modifiedTime as number);\r\n });\r\n }\r\n\r\n\r\n /**\r\n * Changes the permissions (i.e. file mode bits) for a filesystem object.\r\n * Behind the scenes it uses `fs.chmodSync()`.\r\n * @param path - The absolute or relative path to the object that should be updated.\r\n * @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum\r\n */\r\n public static changePosixModeBits(path: string, mode: PosixModeBits): void {\r\n FileSystem._wrapException(() => {\r\n fs.chmodSync(path, mode);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.changePosixModeBits}.\r\n */\r\n public static changePosixModeBitsAsync(path: string, mode: PosixModeBits): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.chmod(path, mode);\r\n });\r\n }\r\n\r\n /**\r\n * Retrieves the permissions (i.e. file mode bits) for a filesystem object.\r\n * Behind the scenes it uses `fs.chmodSync()`.\r\n * @param path - The absolute or relative path to the object that should be updated.\r\n *\r\n * @remarks\r\n * This calls {@link FileSystem.getStatistics} to get the POSIX mode bits.\r\n * If statistics in addition to the mode bits are needed, it is more efficient\r\n * to call {@link FileSystem.getStatistics} directly instead.\r\n */\r\n public static getPosixModeBits(path: string): PosixModeBits {\r\n return FileSystem._wrapException(() => {\r\n return FileSystem.getStatistics(path).mode;\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.getPosixModeBits}.\r\n */\r\n public static getPosixModeBitsAsync(path: string): Promise<PosixModeBits> {\r\n return FileSystem._wrapExceptionAsync(async () => {\r\n return (await FileSystem.getStatisticsAsync(path)).mode;\r\n });\r\n }\r\n\r\n /**\r\n * Returns a 10-character string representation of a PosixModeBits value similar to what\r\n * would be displayed by a command such as \"ls -l\" on a POSIX-like operating system.\r\n * @remarks\r\n * For example, `PosixModeBits.AllRead | PosixModeBits.AllWrite` would be formatted as \"-rw-rw-rw-\".\r\n * @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum\r\n */\r\n public static formatPosixModeBits(modeBits: PosixModeBits): string {\r\n let result: string = '-'; // (later we may add support for additional states such as S_IFDIR or S_ISUID)\r\n\r\n result += (modeBits & PosixModeBits.UserRead) ? 'r' : '-';\r\n result += (modeBits & PosixModeBits.UserWrite) ? 'w' : '-';\r\n result += (modeBits & PosixModeBits.UserExecute) ? 'x' : '-';\r\n\r\n result += (modeBits & PosixModeBits.GroupRead) ? 'r' : '-';\r\n result += (modeBits & PosixModeBits.GroupWrite) ? 'w' : '-';\r\n result += (modeBits & PosixModeBits.GroupExecute) ? 'x' : '-';\r\n\r\n result += (modeBits & PosixModeBits.OthersRead) ? 'r' : '-';\r\n result += (modeBits & PosixModeBits.OthersWrite) ? 'w' : '-';\r\n result += (modeBits & PosixModeBits.OthersExecute) ? 'x' : '-';\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Moves a file. The folder must exist, unless the `ensureFolderExists` option is provided.\r\n * Behind the scenes it uses `fs-extra.moveSync()`\r\n */\r\n public static move(options: IFileSystemMoveOptions): void {\r\n FileSystem._wrapException(() => {\r\n options = {\r\n ...MOVE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n try {\r\n fsx.moveSync(options.sourcePath, options.destinationPath, { overwrite: options.overwrite });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(options.destinationPath);\r\n FileSystem.ensureFolder(folderPath);\r\n fsx.moveSync(options.sourcePath, options.destinationPath, { overwrite: options.overwrite });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.move}.\r\n */\r\n public static moveAsync(options: IFileSystemMoveOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(async () => {\r\n options = {\r\n ...MOVE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n try {\r\n await fsx.move(options.sourcePath, options.destinationPath, { overwrite: options.overwrite });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(options.destinationPath);\r\n await FileSystem.ensureFolderAsync(nodeJsPath.dirname(folderPath));\r\n await fsx.move(options.sourcePath, options.destinationPath, { overwrite: options.overwrite });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n });\r\n }\r\n\r\n // ===============\r\n // FOLDER OPERATIONS\r\n // ===============\r\n\r\n /**\r\n * Recursively creates a folder at a given path.\r\n * Behind the scenes is uses `fs-extra.ensureDirSync()`.\r\n * @remarks\r\n * Throws an exception if anything in the folderPath is not a folder.\r\n * @param folderPath - The absolute or relative path of the folder which should be created.\r\n */\r\n public static ensureFolder(folderPath: string): void {\r\n FileSystem._wrapException(() => {\r\n fsx.ensureDirSync(folderPath);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.ensureFolder}.\r\n */\r\n public static ensureFolderAsync(folderPath: string): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.ensureDir(folderPath);\r\n });\r\n }\r\n\r\n /**\r\n * Reads the contents of the folder, not including \".\" or \"..\".\r\n * Behind the scenes it uses `fs.readdirSync()`.\r\n * @param folderPath - The absolute or relative path to the folder which should be read.\r\n * @param options - Optional settings that can change the behavior. Type: `IReadFolderOptions`\r\n */\r\n public static readFolder(folderPath: string, options?: IFileSystemReadFolderOptions): string[] {\r\n return FileSystem._wrapException(() => {\r\n options = {\r\n ...READ_FOLDER_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n // @todo: Update this to use Node 10's `withFileTypes: true` option when we drop support for Node 8\r\n const fileNames: string[] = fsx.readdirSync(folderPath);\r\n if (options.absolutePaths) {\r\n return fileNames.map(fileName => nodeJsPath.resolve(folderPath, fileName));\r\n } else {\r\n return fileNames;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.readFolder}.\r\n */\r\n public static readFolderAsync(folderPath: string, options?: IFileSystemReadFolderOptions): Promise<string[]> {\r\n return FileSystem._wrapExceptionAsync(async () => {\r\n options = {\r\n ...READ_FOLDER_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n // @todo: Update this to use Node 10's `withFileTypes: true` option when we drop support for Node 8\r\n const fileNames: string[] = await fsx.readdir(folderPath);\r\n if (options.absolutePaths) {\r\n return fileNames.map(fileName => nodeJsPath.resolve(folderPath, fileName));\r\n } else {\r\n return fileNames;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Deletes a folder, including all of its contents.\r\n * Behind the scenes is uses `fs-extra.removeSync()`.\r\n * @remarks\r\n * Does not throw if the folderPath does not exist.\r\n * @param folderPath - The absolute or relative path to the folder which should be deleted.\r\n */\r\n public static deleteFolder(folderPath: string): void {\r\n FileSystem._wrapException(() => {\r\n fsx.removeSync(folderPath);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.deleteFolder}.\r\n */\r\n public static deleteFolderAsync(folderPath: string): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.remove(folderPath);\r\n });\r\n }\r\n\r\n /**\r\n * Deletes the content of a folder, but not the folder itself. Also ensures the folder exists.\r\n * Behind the scenes it uses `fs-extra.emptyDirSync()`.\r\n * @remarks\r\n * This is a workaround for a common race condition, where the virus scanner holds a lock on the folder\r\n * for a brief period after it was deleted, causing EBUSY errors for any code that tries to recreate the folder.\r\n * @param folderPath - The absolute or relative path to the folder which should have its contents deleted.\r\n */\r\n public static ensureEmptyFolder(folderPath: string): void {\r\n FileSystem._wrapException(() => {\r\n fsx.emptyDirSync(folderPath);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.ensureEmptyFolder}.\r\n */\r\n public static ensureEmptyFolderAsync(folderPath: string): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.emptyDir(folderPath);\r\n });\r\n }\r\n\r\n // ===============\r\n // FILE OPERATIONS\r\n // ===============\r\n\r\n /**\r\n * Writes a text string to a file on disk, overwriting the file if it already exists.\r\n * Behind the scenes it uses `fs.writeFileSync()`.\r\n * @remarks\r\n * Throws an error if the folder doesn't exist, unless ensureFolder=true.\r\n * @param filePath - The absolute or relative path of the file.\r\n * @param contents - The text that should be written to the file.\r\n * @param options - Optional settings that can change the behavior. Type: `IWriteFileOptions`\r\n */\r\n public static writeFile(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): void {\r\n FileSystem._wrapException(() => {\r\n options = {\r\n ...WRITE_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents.toString(), options.convertLineEndings);\r\n }\r\n\r\n try {\r\n fsx.writeFileSync(filePath, contents, { encoding: options.encoding });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(filePath);\r\n FileSystem.ensureFolder(folderPath);\r\n fsx.writeFileSync(filePath, contents, { encoding: options.encoding });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.writeFile}.\r\n */\r\n public static writeFileAsync(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(async () => {\r\n options = {\r\n ...WRITE_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents.toString(), options.convertLineEndings);\r\n }\r\n\r\n try {\r\n await fsx.writeFile(filePath, contents, { encoding: options.encoding });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(filePath);\r\n await FileSystem.ensureFolderAsync(folderPath);\r\n await fsx.writeFile(filePath, contents, { encoding: options.encoding });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Writes a text string to a file on disk, appending to the file if it already exists.\r\n * Behind the scenes it uses `fs.appendFileSync()`.\r\n * @remarks\r\n * Throws an error if the folder doesn't exist, unless ensureFolder=true.\r\n * @param filePath - The absolute or relative path of the file.\r\n * @param contents - The text that should be written to the file.\r\n * @param options - Optional settings that can change the behavior. Type: `IWriteFileOptions`\r\n */\r\n public static appendToFile(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): void {\r\n FileSystem._wrapException(() => {\r\n options = {\r\n ...APPEND_TO_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents.toString(), options.convertLineEndings);\r\n }\r\n\r\n try {\r\n fsx.appendFileSync(filePath, contents, { encoding: options.encoding });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(filePath);\r\n FileSystem.ensureFolder(folderPath);\r\n fsx.appendFileSync(filePath, contents, { encoding: options.encoding });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.appendToFile}.\r\n */\r\n public static appendToFileAsync(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(async () => {\r\n options = {\r\n ...APPEND_TO_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents.toString(), options.convertLineEndings);\r\n }\r\n\r\n try {\r\n await fsx.appendFile(filePath, contents, { encoding: options.encoding });\r\n } catch (error) {\r\n if (options.ensureFolderExists) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n\r\n const folderPath: string = nodeJsPath.dirname(filePath);\r\n await FileSystem.ensureFolderAsync(folderPath);\r\n await fsx.appendFile(filePath, contents, { encoding: options.encoding });\r\n } else {\r\n throw error;\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Reads the contents of a file into a string.\r\n * Behind the scenes it uses `fs.readFileSync()`.\r\n * @param filePath - The relative or absolute path to the file whose contents should be read.\r\n * @param options - Optional settings that can change the behavior. Type: `IReadFileOptions`\r\n */\r\n public static readFile(filePath: string, options?: IFileSystemReadFileOptions): string {\r\n return FileSystem._wrapException(() => {\r\n options = {\r\n ...READ_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n let contents: string = FileSystem.readFileToBuffer(filePath).toString(options.encoding);\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents, options.convertLineEndings);\r\n }\r\n\r\n return contents;\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.readFile}.\r\n */\r\n public static readFileAsync(filePath: string, options?: IFileSystemReadFileOptions): Promise<string> {\r\n return FileSystem._wrapExceptionAsync(async () => {\r\n options = {\r\n ...READ_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n let contents: string = (await FileSystem.readFileToBufferAsync(filePath)).toString(options.encoding);\r\n if (options.convertLineEndings) {\r\n contents = Text.convertTo(contents, options.convertLineEndings);\r\n }\r\n\r\n return contents;\r\n });\r\n }\r\n\r\n /**\r\n * Reads the contents of a file into a buffer.\r\n * Behind the scenes is uses `fs.readFileSync()`.\r\n * @param filePath - The relative or absolute path to the file whose contents should be read.\r\n */\r\n public static readFileToBuffer(filePath: string): Buffer {\r\n return FileSystem._wrapException(() => {\r\n return fsx.readFileSync(filePath);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.readFileToBuffer}.\r\n */\r\n public static readFileToBufferAsync(filePath: string): Promise<Buffer> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.readFile(filePath);\r\n });\r\n }\r\n\r\n /**\r\n * Copies a file from one location to another.\r\n * By default, destinationPath is overwritten if it already exists.\r\n * Behind the scenes it uses `fs.copyFileSync()`.\r\n */\r\n public static copyFile(options: IFileSystemCopyFileOptions): void {\r\n FileSystem._wrapException(() => {\r\n fsx.copySync(options.sourcePath, options.destinationPath);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.copyFile}.\r\n */\r\n public static copyFileAsync(options: IFileSystemCopyFileOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.copy(options.sourcePath, options.destinationPath);\r\n });\r\n }\r\n\r\n /**\r\n * Deletes a file. Can optionally throw if the file doesn't exist.\r\n * Behind the scenes it uses `fs.unlinkSync()`.\r\n * @param filePath - The absolute or relative path to the file that should be deleted.\r\n * @param options - Optional settings that can change the behavior. Type: `IDeleteFileOptions`\r\n */\r\n public static deleteFile(filePath: string, options?: IFileSystemDeleteFileOptions): void {\r\n FileSystem._wrapException(() => {\r\n options = {\r\n ...DELETE_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n try {\r\n fsx.unlinkSync(filePath);\r\n } catch (error) {\r\n if (options.throwIfNotExists || !FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.deleteFile}.\r\n */\r\n public static deleteFileAsync(filePath: string, options?: IFileSystemDeleteFileOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(async () => {\r\n options = {\r\n ...DELETE_FILE_DEFAULT_OPTIONS,\r\n ...options\r\n };\r\n\r\n try {\r\n await fsx.unlink(filePath);\r\n } catch (error) {\r\n if (options.throwIfNotExists || !FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n }\r\n });\r\n }\r\n\r\n // ===============\r\n // LINK OPERATIONS\r\n // ===============\r\n\r\n /**\r\n * Gets the statistics of a filesystem object. Does NOT follow the link to its target.\r\n * Behind the scenes it uses `fs.lstatSync()`.\r\n * @param path - The absolute or relative path to the filesystem object.\r\n */\r\n public static getLinkStatistics(path: string): fs.Stats {\r\n return FileSystem._wrapException(() => {\r\n return fsx.lstatSync(path);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.getLinkStatistics}.\r\n */\r\n public static getLinkStatisticsAsync(path: string): Promise<fs.Stats> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.lstat(path);\r\n });\r\n }\r\n\r\n /**\r\n * Creates a Windows \"directory junction\". Behaves like `createSymbolicLinkToFile()` on other platforms.\r\n * Behind the scenes it uses `fs.symlinkSync()`.\r\n */\r\n public static createSymbolicLinkJunction(options: IFileSystemCreateLinkOptions): void {\r\n FileSystem._wrapException(() => {\r\n // For directories, we use a Windows \"junction\". On POSIX operating systems, this produces a regular symlink.\r\n fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'junction');\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.createSymbolicLinkJunction}.\r\n */\r\n public static createSymbolicLinkJunctionAsync(options: IFileSystemCreateLinkOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n // For directories, we use a Windows \"junction\". On POSIX operating systems, this produces a regular symlink.\r\n return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'junction');\r\n });\r\n }\r\n\r\n /**\r\n * Creates a symbolic link to a file (on Windows this requires elevated permissionsBits).\r\n * Behind the scenes it uses `fs.symlinkSync()`.\r\n */\r\n public static createSymbolicLinkFile(options: IFileSystemCreateLinkOptions): void {\r\n FileSystem._wrapException(() => {\r\n fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'file');\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.createSymbolicLinkFile}.\r\n */\r\n public static createSymbolicLinkFileAsync(options: IFileSystemCreateLinkOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'file');\r\n });\r\n }\r\n\r\n /**\r\n * Creates a symbolic link to a folder (on Windows this requires elevated permissionsBits).\r\n * Behind the scenes it uses `fs.symlinkSync()`.\r\n */\r\n public static createSymbolicLinkFolder(options: IFileSystemCreateLinkOptions): void {\r\n FileSystem._wrapException(() => {\r\n fsx.symlinkSync(options.linkTargetPath, options.newLinkPath, 'dir');\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.createSymbolicLinkFolder}.\r\n */\r\n public static createSymbolicLinkFolderAsync(options: IFileSystemCreateLinkOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.symlink(options.linkTargetPath, options.newLinkPath, 'dir');\r\n });\r\n }\r\n\r\n /**\r\n * Creates a hard link.\r\n * Behind the scenes it uses `fs.linkSync()`.\r\n */\r\n public static createHardLink(options: IFileSystemCreateLinkOptions): void {\r\n FileSystem._wrapException(() => {\r\n fsx.linkSync(options.linkTargetPath, options.newLinkPath);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.createHardLink}.\r\n */\r\n public static createHardLinkAsync(options: IFileSystemCreateLinkOptions): Promise<void> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.link(options.linkTargetPath, options.newLinkPath);\r\n });\r\n }\r\n\r\n /**\r\n * Follows a link to its destination and returns the absolute path to the final target of the link.\r\n * Behind the scenes it uses `fs.realpathSync()`.\r\n * @param linkPath - The path to the link.\r\n */\r\n public static getRealPath(linkPath: string): string {\r\n return FileSystem._wrapException(() => {\r\n return fsx.realpathSync(linkPath);\r\n });\r\n }\r\n\r\n /**\r\n * An async version of {@link FileSystem.getRealPath}.\r\n */\r\n public static getRealPathAsync(linkPath: string): Promise<string> {\r\n return FileSystem._wrapExceptionAsync(() => {\r\n return fsx.realpath(linkPath);\r\n });\r\n }\r\n\r\n // ===============\r\n // UTILITY FUNCTIONS\r\n // ===============\r\n\r\n /**\r\n * Returns true if the error provided indicates the file or folder does not exist.\r\n */\r\n public static isNotExistError(error: Error): boolean {\r\n return FileSystem.isFileDoesNotExistError(error) || FileSystem.isFolderDoesNotExistError(error);\r\n }\r\n\r\n /**\r\n * Returns true if the error provided indicates the file does not exist.\r\n */\r\n public static isFileDoesNotExistError(error: Error): boolean {\r\n return FileSystem.isErrnoException(error) && (error.code === 'ENOENT');\r\n }\r\n\r\n /**\r\n * Returns true if the error provided indicates the folder does not exist.\r\n */\r\n public static isFolderDoesNotExistError(error: Error): boolean {\r\n return FileSystem.isErrnoException(error) && (error.code === 'ENOTDIR');\r\n }\r\n\r\n /**\r\n * Detects if the provided error object is a `NodeJS.ErrnoException`\r\n */\r\n public static isErrnoException(error: Error): error is NodeJS.ErrnoException {\r\n const typedError: NodeJS.ErrnoException = error;\r\n return (\r\n typeof typedError.code === 'string' &&\r\n typeof typedError.errno === 'number' &&\r\n typeof typedError.path === 'string' &&\r\n typeof typedError.syscall === 'string'\r\n );\r\n }\r\n\r\n private static _wrapException<TResult>(fn: () => TResult): TResult {\r\n try {\r\n return fn();\r\n } catch (error) {\r\n FileSystem._updateErrorMessage(error);\r\n throw error;\r\n }\r\n }\r\n\r\n private static async _wrapExceptionAsync<TResult>(fn: () => Promise<TResult>): Promise<TResult> {\r\n try {\r\n return await fn();\r\n } catch (error) {\r\n FileSystem._updateErrorMessage(error);\r\n throw error;\r\n }\r\n }\r\n\r\n private static _updateErrorMessage(error: Error): void {\r\n if (FileSystem.isErrnoException(error)) {\r\n if (FileSystem.isFileDoesNotExistError(error)) { // eslint-disable-line @typescript-eslint/no-use-before-define\r\n error.message = `File does not exist: ${error.path}\\n${error.message}`;\r\n } else if (FileSystem.isFolderDoesNotExistError(error)) { // eslint-disable-line @typescript-eslint/no-use-before-define\r\n error.message = `Folder does not exist: ${error.path}\\n${error.message}`;\r\n }\r\n }\r\n }\r\n}\r\n"]} |
+2
-2
@@ -33,3 +33,3 @@ "use strict"; | ||
| if (FileSystem_1.FileSystem.isNotExistError(error)) { | ||
| throw new Error(`Input file not found: ${jsonFilename}`); | ||
| throw error; | ||
| } | ||
@@ -52,3 +52,3 @@ else { | ||
| if (FileSystem_1.FileSystem.isNotExistError(error)) { | ||
| throw new Error(`Input file not found: ${jsonFilename}`); | ||
| throw error; | ||
| } | ||
@@ -55,0 +55,0 @@ else { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"JsonFile.js","sourceRoot":"","sources":["../src/JsonFile.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;AAE3D,yBAAyB;AACzB,2BAA2B;AAO3B,iCAGgB;AAChB,6CAA0C;AA2D1C,MAAM,gBAAgB,GAAW,MAAM,CAAC;AAExC;;;GAGG;AACH,MAAa,QAAQ;IACnB;;OAEG;IACI,MAAM,CAAC,IAAI,CAAC,YAAoB;QACrC,IAAI;YACF,MAAM,QAAQ,GAAW,uBAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC3D,OAAO,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC5B;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,uBAAU,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE;gBACrC,MAAM,IAAI,KAAK,CAAC,yBAAyB,YAAY,EAAE,CAAC,CAAC;aAC1D;iBAAM;gB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AC,cAAc,CAAC,OAAiB;QAC7C,IAAI,MAAM,GAAW,EAAE,CAAC;QAExB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;YACzB,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBACxB,sDAAsD;gBACtD,MAAM,IAAI,IAAI,GAAG,GAAG,CAAC;aACtB;iBAAM,IAAI,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBAC1C,sEAAsE;gBACtE,IAAI,MAAM,EAAE;oBACV,MAAM,IAAI,GAAG,CAAC;iBACf;gBACD,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC;aACpB;iBAAM;gBACL,gFAAgF;gBAEhF,sCAAsC;gBACtC,yCAAyC;gBACzC,MAAM,UAAU,GAAW,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,qBAAqB;qBAC1E,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,gBAAgB;gBAC1C,MAAM,IAAI,KAAK,UAAU,IAAI,CAAC;aAC/B;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAjUD,4BAiUC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport * as os from 'os';\r\nimport * as jju from 'jju';\r\n\r\nimport {\r\n JsonSchema,\r\n IJsonSchemaErrorInfo,\r\n IJsonSchemaValidateOptions\r\n} from './JsonSchema';\r\nimport {\r\n Text,\r\n NewlineKind\r\n} from './Text';\r\nimport { FileSystem } from './FileSystem';\r\n\r\n/**\r\n * Represents a JSON-serializable object whose type has not been determined yet.\r\n *\r\n * @remarks\r\n *\r\n * This type is similar to `any`, except that it communicates that the object is serializable JSON.\r\n *\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type JsonObject = any;\r\n\r\n/**\r\n * Options for JsonFile.stringify()\r\n *\r\n * @public\r\n */\r\nexport interface IJsonFileStringifyOptions {\r\n /**\r\n * If provided, the specified newline type will be used instead of the default `\\r\\n`.\r\n */\r\n newlineConversion?: NewlineKind;\r\n\r\n /**\r\n * If true, then the \"jju\" library will be used to improve the text formatting.\r\n * Note that this is slightly slower than the native JSON.stringify() implementation.\r\n */\r\n prettyFormatting?: boolean;\r\n}\r\n\r\n/**\r\n * Options for JsonFile.saveJsonFile()\r\n *\r\n * @public\r\n */\r\nexport interface IJsonFileSaveOptions extends IJsonFileStringifyOptions {\r\n /**\r\n * If there is an existing file, and the contents have not changed, then\r\n * don't write anything; this preserves the old timestamp.\r\n */\r\n onlyIfChanged?: boolean;\r\n\r\n /**\r\n * Creates the folder recursively using FileSystem.ensureFolder()\r\n * Defaults to false.\r\n */\r\n ensureFolderExists?: boolean;\r\n\r\n /**\r\n * If true, use the \"jju\" library to preserve the existing JSON formatting: The file will be loaded\r\n * from the target filename, the new content will be merged in (preserving whitespace and comments),\r\n * and then the file will be overwritten with the merged contents. If the target file does not exist,\r\n * then the file is saved normally.\r\n */\r\n updateExistingFile?: boolean;\r\n}\r\n\r\nconst DEFAULT_ENCODING: string = 'utf8';\r\n\r\n/**\r\n * Utilities for reading/writing JSON files.\r\n * @public\r\n */\r\nexport class JsonFile {\r\n /**\r\n * Loads a JSON file.\r\n */\r\n public static load(jsonFilename: string): JsonObject {\r\n try {\r\n const contents: string = FileSystem.readFile(jsonFilename);\r\n return jju.parse(contents);\r\n } catch (error) {\r\n if (FileSystem.isNotExistError(error)) {\r\n throw new Error(`Input file not found: ${jsonFilename}`);\r\n } else {\r\n throw new Error(`Error reading \"${jsonFilename}\":` + os.EOL + ` ${error.message}`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * An async version of {@link JsonFile.load}.\r\n */\r\n public static async loadAsync(jsonFilename: string): Promise<JsonObject> {\r\n try {\r\n const contents: string = await FileSystem.readFileAsync(jsonFilename);\r\n return jju.parse(contents);\r\n } catch (error) {\r\n if (FileSystem.isNotExistError(error)) {\r\n throw new Error(`Input file not found: ${jsonFilename}`);\r\n } else {\r\n throw new Error(`Error reading \"${jsonFilename}\":` + os.EOL + ` ${error.message}`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Parses a JSON file's contents.\r\n */\r\n public static parseString(jsonContents: string): JsonObject {\r\n return jju.parse(jsonContents);\r\n }\r\n\r\n /**\r\n * Loads a JSON file and validate its schema.\r\n */\r\n public static loadAndValidate(\r\n jsonFilename: string,\r\n jsonSchema: JsonSchema,\r\n options?: IJsonSchemaValidateOptions\r\n ): JsonObject {\r\n const jsonObject: JsonObject = JsonFile.load(jsonFilename);\r\n jsonSchema.validateObject(jsonObject, jsonFilename, options);\r\n\r\n return jsonObject;\r\n }\r\n\r\n /**\r\n * An async version of {@link JsonFile.loadAndValidate}.\r\n */\r\n public static async loadAndValidateAsync(\r\n jsonFilename: string,\r\n jsonSchema: JsonSchema,\r\n options?: IJsonSchemaValidateOptions\r\n ): Promise<JsonObject> {\r\n const jsonObject: JsonObject = await JsonFile.loadAsync(jsonFilename);\r\n jsonSchema.validateObject(jsonObject, jsonFilename, options);\r\n\r\n return jsonObject;\r\n }\r\n\r\n /**\r\n * Loads a JSON file and validate its schema, reporting errors using a callback\r\n * @remarks\r\n * See JsonSchema.validateObjectWithCallback() for more info.\r\n */\r\n public static loadAndValidateWithCallback(\r\n jsonFilename: string,\r\n jsonSchema: JsonSchema,\r\n errorCallback: (errorInfo: IJsonSchemaErrorInfo) => void\r\n ): JsonObject {\r\n const jsonObject: JsonObject = JsonFile.load(jsonFilename);\r\n jsonSchema.validateObjectWithCallback(jsonObject, errorCallback);\r\n\r\n return jsonObject;\r\n }\r\n\r\n /**\r\n * An async version of {@link JsonFile.loadAndValidateWithCallback}.\r\n */\r\n public static async loadAndValidateWithCallbackAsync(\r\n jsonFilename: string,\r\n jsonSchema: JsonSchema,\r\n errorCallback: (errorInfo: IJsonSchemaErrorInfo) => void\r\n ): Promise<JsonObject> {\r\n const jsonObject: JsonObject = await JsonFile.loadAsync(jsonFilename);\r\n jsonSchema.validateObjectWithCallback(jsonObject, errorCallback);\r\n\r\n return jsonObject;\r\n }\r\n\r\n /**\r\n * Serializes the specified JSON object to a string buffer.\r\n * @param jsonObject - the object to be serialized\r\n * @param options - other settings that control serialization\r\n * @returns a JSON string, with newlines, and indented with two spaces\r\n */\r\n public static stringify(jsonObject: JsonObject, options?: IJsonFileStringifyOptions): string {\r\n return JsonFile.updateString('', jsonObject, options);\r\n }\r\n\r\n /**\r\n * Serializes the specified JSON object to a string buffer.\r\n * @param jsonObject - the object to be serialized\r\n * @param options - other settings that control serialization\r\n * @returns a JSON string, with newlines, and indented with two spaces\r\n */\r\n public static updateString(\r\n previousJson: string,\r\n newJsonObject: JsonObject,\r\n options?: IJsonFileStringifyOptions\r\n ): string {\r\n if (!options) {\r\n options = { };\r\n }\r\n\r\n JsonFile.validateNoUndefinedMembers(newJsonObject);\r\n\r\n let stringified: string;\r\n\r\n if (previousJson !== '') {\r\n // NOTE: We don't use mode=json here because comments aren't allowed by strict JSON\r\n stringified = jju.update(previousJson, newJsonObject, {\r\n mode: 'cjson',\r\n indent: 2\r\n });\r\n } else if (options.prettyFormatting) {\r\n stringified = jju.stringify(newJsonObject, {\r\n mode: 'json',\r\n indent: 2\r\n });\r\n } else {\r\n stringified = JSON.stringify(newJsonObject, undefined, 2);\r\n }\r\n\r\n // Add the trailing newline\r\n stringified = Text.ensureTrailingNewline(stringified);\r\n\r\n if (options && options.newlineConversion) {\r\n stringified = Text.convertTo(stringified, options.newlineConversion);\r\n }\r\n\r\n return stringified;\r\n }\r\n\r\n /**\r\n * Saves the file to disk. Returns false if nothing was written due to options.onlyIfChanged.\r\n * @param jsonObject - the object to be saved\r\n * @param jsonFilename - the file path to write\r\n * @param options - other settings that control how the file is saved\r\n * @returns false if ISaveJsonFileOptions.onlyIfChanged didn't save anything; true otherwise\r\n */\r\n public static save(jsonObject: JsonObject, jsonFilename: string, options?: IJsonFileSaveOptions): boolean {\r\n if (!options) {\r\n options = { };\r\n }\r\n\r\n // Do we need to read the previous file contents?\r\n let oldBuffer: Buffer | undefined = undefined;\r\n if (options.updateExistingFile || options.onlyIfChanged) {\r\n try {\r\n oldBuffer = FileSystem.readFileToBuffer(jsonFilename);\r\n } catch (error) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n let jsonToUpdate: string = '';\r\n if (options.updateExistingFile && oldBuffer) {\r\n jsonToUpdate = oldBuffer.toString(DEFAULT_ENCODING);\r\n }\r\n\r\n const newJson: string = JsonFile.updateString(jsonToUpdate, jsonObject, options);\r\n\r\n const newBuffer: Buffer = Buffer.from(newJson, DEFAULT_ENCODING);\r\n\r\n if (options.onlyIfChanged) {\r\n // Has the file changed?\r\n if (oldBuffer && Buffer.compare(newBuffer, oldBuffer) === 0) {\r\n // Nothing has changed, so don't touch the file\r\n return false;\r\n }\r\n }\r\n\r\n FileSystem.writeFile(jsonFilename, newBuffer.toString(DEFAULT_ENCODING), {\r\n ensureFolderExists: options.ensureFolderExists\r\n });\r\n\r\n // TEST CODE: Used to verify that onlyIfChanged isn't broken by a hidden transformation during saving.\r\n /*\r\n const oldBuffer2: Buffer = FileSystem.readFileToBuffer(jsonFilename);\r\n if (Buffer.compare(buffer, oldBuffer2) !== 0) {\r\n console.log('new:' + buffer.toString('hex'));\r\n console.log('old:' + oldBuffer2.toString('hex'));\r\n\r\n throw new Error('onlyIfChanged logic is broken');\r\n }\r\n */\r\n return true;\r\n }\r\n\r\n /**\r\n * An async version of {@link JsonFile.loadAndValidateWithCallback}.\r\n */\r\n public static async saveAsync(jsonObject: JsonObject, jsonFilename: string, options?: IJsonFileSaveOptions): Promise<boolean> {\r\n if (!options) {\r\n options = { };\r\n }\r\n\r\n // Do we need to read the previous file contents?\r\n let oldBuffer: Buffer | undefined = undefined;\r\n if (options.updateExistingFile || options.onlyIfChanged) {\r\n try {\r\n oldBuffer = await FileSystem.readFileToBufferAsync(jsonFilename);\r\n } catch (error) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n let jsonToUpdate: string = '';\r\n if (options.updateExistingFile && oldBuffer) {\r\n jsonToUpdate = oldBuffer.toString(DEFAULT_ENCODING);\r\n }\r\n\r\n const newJson: string = JsonFile.updateString(jsonToUpdate, jsonObject, options);\r\n\r\n const newBuffer: Buffer = Buffer.from(newJson, DEFAULT_ENCODING);\r\n\r\n if (options.onlyIfChanged) {\r\n // Has the file changed?\r\n if (oldBuffer && Buffer.compare(newBuffer, oldBuffer) === 0) {\r\n // Nothing has changed, so don't touch the file\r\n return false;\r\n }\r\n }\r\n\r\n await FileSystem.writeFileAsync(jsonFilename, newBuffer.toString(DEFAULT_ENCODING), {\r\n ensureFolderExists: options.ensureFolderExists\r\n });\r\n\r\n // TEST CODE: Used to verify that onlyIfChanged isn't broken by a hidden transformation during saving.\r\n /*\r\n const oldBuffer2: Buffer = await FileSystem.readFileToBufferAsync(jsonFilename);\r\n if (Buffer.compare(buffer, oldBuffer2) !== 0) {\r\n console.log('new:' + buffer.toString('hex'));\r\n console.log('old:' + oldBuffer2.toString('hex'));\r\n\r\n throw new Error('onlyIfChanged logic is broken');\r\n }\r\n */\r\n return true;\r\n }\r\n\r\n /**\r\n * Used to validate a data structure before writing. Reports an error if there\r\n * are any undefined members.\r\n */\r\n public static validateNoUndefinedMembers(jsonObject: JsonObject): void {\r\n return JsonFile._validateNoUndefinedMembers(jsonObject, []);\r\n }\r\n\r\n // Private implementation of validateNoUndefinedMembers()\r\n private static _validateNoUndefinedMembers(jsonObject: JsonObject, keyPath: string[]): void {\r\n if (!jsonObject) {\r\n return;\r\n }\r\n if (typeof jsonObject === 'object') {\r\n for (const key of Object.keys(jsonObject)) {\r\n keyPath.push(key);\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n const value: any = jsonObject[key];\r\n if (value === undefined) {\r\n const fullPath: string = JsonFile._formatKeyPath(keyPath);\r\n throw new Error(`The value for ${fullPath} is \"undefined\" and cannot be serialized as JSON`);\r\n }\r\n\r\n JsonFile._validateNoUndefinedMembers(value, keyPath);\r\n keyPath.pop();\r\n }\r\n }\r\n }\r\n\r\n // Given this input: ['items', '4', 'syntax', 'parameters', 'string \"with\" symbols\", 'type']\r\n // Return this string: items[4].syntax.parameters[\"string \\\"with\\\" symbols\"].type\r\n private static _formatKeyPath(keyPath: string[]): string {\r\n let result: string = '';\r\n\r\n for (const key of keyPath) {\r\n if (/^[0-9]+$/.test(key)) {\r\n // It's an integer, so display like this: parent[123]\r\n result += `[${key}]`;\r\n } else if (/^[a-z_][a-z_0-9]*$/i.test(key)) {\r\n // It's an alphanumeric identifier, so display like this: parent.name\r\n if (result) {\r\n result += '.';\r\n }\r\n result += `${key}`;\r\n } else {\r\n // It's a freeform string, so display like this: parent[\"A path: \\\"C:\\\\file\\\"\"]\r\n\r\n // Convert this: A path: \"C:\\file\"\r\n // To this: A path: \\\"C:\\\\file\\\"\r\n const escapedKey: string = key.replace(/[\\\\]/g, '\\\\\\\\') // escape backslashes\r\n .replace(/[\"]/g, '\\\\'); // escape quotes\r\n result += `[\"${escapedKey}\"]`;\r\n }\r\n }\r\n return result;\r\n }\r\n}\r\n"]} | ||
| {"version":3,"file":"JsonFile.js","sourceRoot":"","sources":["../src/JsonFile.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;AAE3D,yBAAyB;AACzB,2BAA2B;AAO3B,iCAGgB;AAChB,6CAA0C;AA2D1C,MAAM,gBAAgB,GAAW,MAAM,CAAC;AAExC;;;GAGG;AACH,MAAa,QAAQ;IACnB;;OAEG;IACI,MAAM,CAAC,IAAI,CAAC,YAAoB;QACrC,IAAI;YACF,MAAM,QAAQ,GAAW,uBAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC3D,OAAO,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC5B;QAAC,OAAO,KAAK,EAAE;YAC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CAAC;IAED,+FAA+F;IAC/F,kFAAkF;IAC1E,MAAM,CAAC,cAAc,CAAC,OAAiB;QAC7C,IAAI,MAAM,GAAW,EAAE,CAAC;QAExB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;YACzB,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBACxB,sDAAsD;gBACtD,MAAM,IAAI,IAAI,GAAG,GAAG,CAAC;aACtB;iBAAM,IAAI,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBAC1C,sEAAsE;gBACtE,IAAI,MAAM,EAAE;oBACV,MAAM,IAAI,GAAG,CAAC;iBACf;gBACD,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC;aACpB;iBAAM;gBACL,gFAAgF;gBAEhF,sCAAsC;gBACtC,yCAAyC;gBACzC,MAAM,UAAU,GAAW,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,qBAAqB;qBAC1E,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,gBAAgB;gBAC1C,MAAM,IAAI,KAAK,UAAU,IAAI,CAAC;aAC/B;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAjUD,4BAiUC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport * as os from 'os';\r\nimport * as jju from 'jju';\r\n\r\nimport {\r\n JsonSchema,\r\n IJsonSchemaErrorInfo,\r\n IJsonSchemaValidateOptions\r\n} from './JsonSchema';\r\nimport {\r\n Text,\r\n NewlineKind\r\n} from './Text';\r\nimport { FileSystem } from './FileSystem';\r\n\r\n/**\r\n * Represents a JSON-serializable object whose type has not been determined yet.\r\n *\r\n * @remarks\r\n *\r\n * This type is similar to `any`, except that it communicates that the object is serializable JSON.\r\n *\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type JsonObject = any;\r\n\r\n/**\r\n * Options for JsonFile.stringify()\r\n *\r\n * @public\r\n */\r\nexport interface IJsonFileStringifyOptions {\r\n /**\r\n * If provided, the specified newline type will be used instead of the default `\\r\\n`.\r\n */\r\n newlineConversion?: NewlineKind;\r\n\r\n /**\r\n * If true, then the \"jju\" library will be used to improve the text formatting.\r\n * Note that this is slightly slower than the native JSON.stringify() implementation.\r\n */\r\n prettyFormatting?: boolean;\r\n}\r\n\r\n/**\r\n * Options for JsonFile.saveJsonFile()\r\n *\r\n * @public\r\n */\r\nexport interface IJsonFileSaveOptions extends IJsonFileStringifyOptions {\r\n /**\r\n * If there is an existing file, and the contents have not changed, then\r\n * don't write anything; this preserves the old timestamp.\r\n */\r\n onlyIfChanged?: boolean;\r\n\r\n /**\r\n * Creates the folder recursively using FileSystem.ensureFolder()\r\n * Defaults to false.\r\n */\r\n ensureFolderExists?: boolean;\r\n\r\n /**\r\n * If true, use the \"jju\" library to preserve the existing JSON formatting: The file will be loaded\r\n * from the target filename, the new content will be merged in (preserving whitespace and comments),\r\n * and then the file will be overwritten with the merged contents. If the target file does not exist,\r\n * then the file is saved normally.\r\n */\r\n updateExistingFile?: boolean;\r\n}\r\n\r\nconst DEFAULT_ENCODING: string = 'utf8';\r\n\r\n/**\r\n * Utilities for reading/writing JSON files.\r\n * @public\r\n */\r\nexport class JsonFile {\r\n /**\r\n * Loads a JSON file.\r\n */\r\n public static load(jsonFilename: string): JsonObject {\r\n try {\r\n const contents: string = FileSystem.readFile(jsonFilename);\r\n return jju.parse(contents);\r\n } catch (error) {\r\n if (FileSystem.isNotExistError(error)) {\r\n throw error;\r\n } else {\r\n throw new Error(`Error reading \"${jsonFilename}\":` + os.EOL + ` ${error.message}`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * An async version of {@link JsonFile.load}.\r\n */\r\n public static async loadAsync(jsonFilename: string): Promise<JsonObject> {\r\n try {\r\n const contents: string = await FileSystem.readFileAsync(jsonFilename);\r\n return jju.parse(contents);\r\n } catch (error) {\r\n if (FileSystem.isNotExistError(error)) {\r\n throw error;\r\n } else {\r\n throw new Error(`Error reading \"${jsonFilename}\":` + os.EOL + ` ${error.message}`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Parses a JSON file's contents.\r\n */\r\n public static parseString(jsonContents: string): JsonObject {\r\n return jju.parse(jsonContents);\r\n }\r\n\r\n /**\r\n * Loads a JSON file and validate its schema.\r\n */\r\n public static loadAndValidate(\r\n jsonFilename: string,\r\n jsonSchema: JsonSchema,\r\n options?: IJsonSchemaValidateOptions\r\n ): JsonObject {\r\n const jsonObject: JsonObject = JsonFile.load(jsonFilename);\r\n jsonSchema.validateObject(jsonObject, jsonFilename, options);\r\n\r\n return jsonObject;\r\n }\r\n\r\n /**\r\n * An async version of {@link JsonFile.loadAndValidate}.\r\n */\r\n public static async loadAndValidateAsync(\r\n jsonFilename: string,\r\n jsonSchema: JsonSchema,\r\n options?: IJsonSchemaValidateOptions\r\n ): Promise<JsonObject> {\r\n const jsonObject: JsonObject = await JsonFile.loadAsync(jsonFilename);\r\n jsonSchema.validateObject(jsonObject, jsonFilename, options);\r\n\r\n return jsonObject;\r\n }\r\n\r\n /**\r\n * Loads a JSON file and validate its schema, reporting errors using a callback\r\n * @remarks\r\n * See JsonSchema.validateObjectWithCallback() for more info.\r\n */\r\n public static loadAndValidateWithCallback(\r\n jsonFilename: string,\r\n jsonSchema: JsonSchema,\r\n errorCallback: (errorInfo: IJsonSchemaErrorInfo) => void\r\n ): JsonObject {\r\n const jsonObject: JsonObject = JsonFile.load(jsonFilename);\r\n jsonSchema.validateObjectWithCallback(jsonObject, errorCallback);\r\n\r\n return jsonObject;\r\n }\r\n\r\n /**\r\n * An async version of {@link JsonFile.loadAndValidateWithCallback}.\r\n */\r\n public static async loadAndValidateWithCallbackAsync(\r\n jsonFilename: string,\r\n jsonSchema: JsonSchema,\r\n errorCallback: (errorInfo: IJsonSchemaErrorInfo) => void\r\n ): Promise<JsonObject> {\r\n const jsonObject: JsonObject = await JsonFile.loadAsync(jsonFilename);\r\n jsonSchema.validateObjectWithCallback(jsonObject, errorCallback);\r\n\r\n return jsonObject;\r\n }\r\n\r\n /**\r\n * Serializes the specified JSON object to a string buffer.\r\n * @param jsonObject - the object to be serialized\r\n * @param options - other settings that control serialization\r\n * @returns a JSON string, with newlines, and indented with two spaces\r\n */\r\n public static stringify(jsonObject: JsonObject, options?: IJsonFileStringifyOptions): string {\r\n return JsonFile.updateString('', jsonObject, options);\r\n }\r\n\r\n /**\r\n * Serializes the specified JSON object to a string buffer.\r\n * @param jsonObject - the object to be serialized\r\n * @param options - other settings that control serialization\r\n * @returns a JSON string, with newlines, and indented with two spaces\r\n */\r\n public static updateString(\r\n previousJson: string,\r\n newJsonObject: JsonObject,\r\n options?: IJsonFileStringifyOptions\r\n ): string {\r\n if (!options) {\r\n options = { };\r\n }\r\n\r\n JsonFile.validateNoUndefinedMembers(newJsonObject);\r\n\r\n let stringified: string;\r\n\r\n if (previousJson !== '') {\r\n // NOTE: We don't use mode=json here because comments aren't allowed by strict JSON\r\n stringified = jju.update(previousJson, newJsonObject, {\r\n mode: 'cjson',\r\n indent: 2\r\n });\r\n } else if (options.prettyFormatting) {\r\n stringified = jju.stringify(newJsonObject, {\r\n mode: 'json',\r\n indent: 2\r\n });\r\n } else {\r\n stringified = JSON.stringify(newJsonObject, undefined, 2);\r\n }\r\n\r\n // Add the trailing newline\r\n stringified = Text.ensureTrailingNewline(stringified);\r\n\r\n if (options && options.newlineConversion) {\r\n stringified = Text.convertTo(stringified, options.newlineConversion);\r\n }\r\n\r\n return stringified;\r\n }\r\n\r\n /**\r\n * Saves the file to disk. Returns false if nothing was written due to options.onlyIfChanged.\r\n * @param jsonObject - the object to be saved\r\n * @param jsonFilename - the file path to write\r\n * @param options - other settings that control how the file is saved\r\n * @returns false if ISaveJsonFileOptions.onlyIfChanged didn't save anything; true otherwise\r\n */\r\n public static save(jsonObject: JsonObject, jsonFilename: string, options?: IJsonFileSaveOptions): boolean {\r\n if (!options) {\r\n options = { };\r\n }\r\n\r\n // Do we need to read the previous file contents?\r\n let oldBuffer: Buffer | undefined = undefined;\r\n if (options.updateExistingFile || options.onlyIfChanged) {\r\n try {\r\n oldBuffer = FileSystem.readFileToBuffer(jsonFilename);\r\n } catch (error) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n let jsonToUpdate: string = '';\r\n if (options.updateExistingFile && oldBuffer) {\r\n jsonToUpdate = oldBuffer.toString(DEFAULT_ENCODING);\r\n }\r\n\r\n const newJson: string = JsonFile.updateString(jsonToUpdate, jsonObject, options);\r\n\r\n const newBuffer: Buffer = Buffer.from(newJson, DEFAULT_ENCODING);\r\n\r\n if (options.onlyIfChanged) {\r\n // Has the file changed?\r\n if (oldBuffer && Buffer.compare(newBuffer, oldBuffer) === 0) {\r\n // Nothing has changed, so don't touch the file\r\n return false;\r\n }\r\n }\r\n\r\n FileSystem.writeFile(jsonFilename, newBuffer.toString(DEFAULT_ENCODING), {\r\n ensureFolderExists: options.ensureFolderExists\r\n });\r\n\r\n // TEST CODE: Used to verify that onlyIfChanged isn't broken by a hidden transformation during saving.\r\n /*\r\n const oldBuffer2: Buffer = FileSystem.readFileToBuffer(jsonFilename);\r\n if (Buffer.compare(buffer, oldBuffer2) !== 0) {\r\n console.log('new:' + buffer.toString('hex'));\r\n console.log('old:' + oldBuffer2.toString('hex'));\r\n\r\n throw new Error('onlyIfChanged logic is broken');\r\n }\r\n */\r\n return true;\r\n }\r\n\r\n /**\r\n * An async version of {@link JsonFile.loadAndValidateWithCallback}.\r\n */\r\n public static async saveAsync(jsonObject: JsonObject, jsonFilename: string, options?: IJsonFileSaveOptions): Promise<boolean> {\r\n if (!options) {\r\n options = { };\r\n }\r\n\r\n // Do we need to read the previous file contents?\r\n let oldBuffer: Buffer | undefined = undefined;\r\n if (options.updateExistingFile || options.onlyIfChanged) {\r\n try {\r\n oldBuffer = await FileSystem.readFileToBufferAsync(jsonFilename);\r\n } catch (error) {\r\n if (!FileSystem.isNotExistError(error)) {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n let jsonToUpdate: string = '';\r\n if (options.updateExistingFile && oldBuffer) {\r\n jsonToUpdate = oldBuffer.toString(DEFAULT_ENCODING);\r\n }\r\n\r\n const newJson: string = JsonFile.updateString(jsonToUpdate, jsonObject, options);\r\n\r\n const newBuffer: Buffer = Buffer.from(newJson, DEFAULT_ENCODING);\r\n\r\n if (options.onlyIfChanged) {\r\n // Has the file changed?\r\n if (oldBuffer && Buffer.compare(newBuffer, oldBuffer) === 0) {\r\n // Nothing has changed, so don't touch the file\r\n return false;\r\n }\r\n }\r\n\r\n await FileSystem.writeFileAsync(jsonFilename, newBuffer.toString(DEFAULT_ENCODING), {\r\n ensureFolderExists: options.ensureFolderExists\r\n });\r\n\r\n // TEST CODE: Used to verify that onlyIfChanged isn't broken by a hidden transformation during saving.\r\n /*\r\n const oldBuffer2: Buffer = await FileSystem.readFileToBufferAsync(jsonFilename);\r\n if (Buffer.compare(buffer, oldBuffer2) !== 0) {\r\n console.log('new:' + buffer.toString('hex'));\r\n console.log('old:' + oldBuffer2.toString('hex'));\r\n\r\n throw new Error('onlyIfChanged logic is broken');\r\n }\r\n */\r\n return true;\r\n }\r\n\r\n /**\r\n * Used to validate a data structure before writing. Reports an error if there\r\n * are any undefined members.\r\n */\r\n public static validateNoUndefinedMembers(jsonObject: JsonObject): void {\r\n return JsonFile._validateNoUndefinedMembers(jsonObject, []);\r\n }\r\n\r\n // Private implementation of validateNoUndefinedMembers()\r\n private static _validateNoUndefinedMembers(jsonObject: JsonObject, keyPath: string[]): void {\r\n if (!jsonObject) {\r\n return;\r\n }\r\n if (typeof jsonObject === 'object') {\r\n for (const key of Object.keys(jsonObject)) {\r\n keyPath.push(key);\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n const value: any = jsonObject[key];\r\n if (value === undefined) {\r\n const fullPath: string = JsonFile._formatKeyPath(keyPath);\r\n throw new Error(`The value for ${fullPath} is \"undefined\" and cannot be serialized as JSON`);\r\n }\r\n\r\n JsonFile._validateNoUndefinedMembers(value, keyPath);\r\n keyPath.pop();\r\n }\r\n }\r\n }\r\n\r\n // Given this input: ['items', '4', 'syntax', 'parameters', 'string \"with\" symbols\", 'type']\r\n // Return this string: items[4].syntax.parameters[\"string \\\"with\\\" symbols\"].type\r\n private static _formatKeyPath(keyPath: string[]): string {\r\n let result: string = '';\r\n\r\n for (const key of keyPath) {\r\n if (/^[0-9]+$/.test(key)) {\r\n // It's an integer, so display like this: parent[123]\r\n result += `[${key}]`;\r\n } else if (/^[a-z_][a-z_0-9]*$/i.test(key)) {\r\n // It's an alphanumeric identifier, so display like this: parent.name\r\n if (result) {\r\n result += '.';\r\n }\r\n result += `${key}`;\r\n } else {\r\n // It's a freeform string, so display like this: parent[\"A path: \\\"C:\\\\file\\\"\"]\r\n\r\n // Convert this: A path: \"C:\\file\"\r\n // To this: A path: \\\"C:\\\\file\\\"\r\n const escapedKey: string = key.replace(/[\\\\]/g, '\\\\\\\\') // escape backslashes\r\n .replace(/[\"]/g, '\\\\'); // escape quotes\r\n result += `[\"${escapedKey}\"]`;\r\n }\r\n }\r\n return result;\r\n }\r\n}\r\n"]} |
+1
-1
| { | ||
| "name": "@rushstack/node-core-library", | ||
| "version": "3.22.0", | ||
| "version": "3.22.1", | ||
| "description": "Core libraries that every NodeJS toolchain project should use", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
691446
2.03%9427
1.5%