Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rushstack/node-core-library

Package Overview
Dependencies
Maintainers
3
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rushstack/node-core-library - npm Package Compare versions

Comparing version 3.22.0 to 3.22.1

12

CHANGELOG.json

@@ -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",

9

CHANGELOG.md
# 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

@@ -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

385

lib/FileSystem.js

@@ -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

@@ -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 {

{
"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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc