@rushstack/node-core-library
Advanced tools
Comparing version 3.38.0 to 3.39.0
@@ -5,2 +5,14 @@ { | ||
{ | ||
"version": "3.39.0", | ||
"tag": "@rushstack/node-core-library_v3.39.0", | ||
"date": "Fri, 04 Jun 2021 19:59:53 GMT", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"comment": "BREAKING CHANGE: Remove FileSystem.copyFileToManyAsync API. It was determined that this API was a likely source of 0-length file copies. Recommended replacement is to call copyFileAsync." | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "3.38.0", | ||
@@ -7,0 +19,0 @@ "tag": "@rushstack/node-core-library_v3.38.0", |
# Change Log - @rushstack/node-core-library | ||
This log was last generated on Wed, 19 May 2021 00:11:39 GMT and should not be manually modified. | ||
This log was last generated on Fri, 04 Jun 2021 19:59:53 GMT and should not be manually modified. | ||
## 3.39.0 | ||
Fri, 04 Jun 2021 19:59:53 GMT | ||
### Minor changes | ||
- BREAKING CHANGE: Remove FileSystem.copyFileToManyAsync API. It was determined that this API was a likely source of 0-length file copies. Recommended replacement is to call copyFileAsync. | ||
## 3.38.0 | ||
@@ -6,0 +13,0 @@ Wed, 19 May 2021 00:11:39 GMT |
@@ -114,13 +114,2 @@ /// <reference types="node" /> | ||
/** | ||
* The options for {@link FileSystem.copyFile} | ||
* @public | ||
*/ | ||
export interface IFileSystemCopyFileToManyOptions extends IFileSystemCopyFileBaseOptions { | ||
/** | ||
* The path that the object will be copied to. | ||
* The path may be absolute or relative. | ||
*/ | ||
destinationPaths: string[]; | ||
} | ||
/** | ||
* Specifies the behavior of {@link FileSystem.copyFiles} in a situation where the target object | ||
@@ -455,13 +444,2 @@ * already exists. | ||
/** | ||
* Copies a single file from one location to one or more other locations. | ||
* By default, the file at the destination is overwritten if it already exists. | ||
* | ||
* @remarks | ||
* The `copyFileToManyAsync()` API cannot be used to copy folders. It copies at most one file. | ||
* | ||
* The implementation is based on `createReadStream()` and `createWriteStream()` from the | ||
* `fs-extra` package. | ||
*/ | ||
static copyFileToManyAsync(options: IFileSystemCopyFileToManyOptions): Promise<void>; | ||
/** | ||
* Copies a file or folder from one location to another, recursively copying any folder contents. | ||
@@ -468,0 +446,0 @@ * By default, destinationPath is overwritten if it already exists. |
@@ -560,82 +560,2 @@ "use strict"; | ||
/** | ||
* Copies a single file from one location to one or more other locations. | ||
* By default, the file at the destination is overwritten if it already exists. | ||
* | ||
* @remarks | ||
* The `copyFileToManyAsync()` API cannot be used to copy folders. It copies at most one file. | ||
* | ||
* The implementation is based on `createReadStream()` and `createWriteStream()` from the | ||
* `fs-extra` package. | ||
*/ | ||
static async copyFileToManyAsync(options) { | ||
options = Object.assign(Object.assign({}, COPY_FILE_DEFAULT_OPTIONS), options); | ||
if (FileSystem.getStatistics(options.sourcePath).isDirectory()) { | ||
throw new Error('The specified path refers to a folder; this operation expects a file path:\n' + options.sourcePath); | ||
} | ||
await FileSystem._wrapExceptionAsync(async () => { | ||
// See flags documentation: https://nodejs.org/api/fs.html#fs_file_system_flags | ||
const writeFlags = []; | ||
switch (options.alreadyExistsBehavior) { | ||
case "error" /* Error */: | ||
case "ignore" /* Ignore */: | ||
writeFlags.push('wx'); | ||
break; | ||
case "overwrite" /* Overwrite */: | ||
default: | ||
writeFlags.push('w'); | ||
} | ||
const flags = writeFlags.join(); | ||
const createPipePromise = (sourceStream, destinationPath) => { | ||
return new Promise((resolve, reject) => { | ||
const destinationStream = fs.createWriteStream(destinationPath); | ||
const streamsToDestroy = [destinationStream]; | ||
sourceStream.on('error', (e) => { | ||
for (const streamToDestroy of streamsToDestroy) { | ||
streamToDestroy.destroy(); | ||
} | ||
reject(e); | ||
}); | ||
sourceStream | ||
.pipe(destinationStream) | ||
.on('close', () => { | ||
resolve(); | ||
}) | ||
.on('error', (e) => { | ||
if (FileSystem.isNotExistError(e)) { | ||
destinationStream.destroy(); | ||
FileSystem.ensureFolder(nodeJsPath.dirname(destinationStream.path)); | ||
const retryDestinationStream = fsx.createWriteStream(destinationPath, { | ||
flags | ||
}); | ||
streamsToDestroy.push(retryDestinationStream); | ||
sourceStream | ||
.pipe(retryDestinationStream) | ||
.on('close', () => { | ||
resolve(); | ||
}) | ||
.on('error', (e2) => { | ||
reject(e2); | ||
}); | ||
} | ||
else if (options.alreadyExistsBehavior === "ignore" /* Ignore */ && | ||
FileSystem.isErrnoException(e) && | ||
e.code === 'EEXIST') { | ||
resolve(); | ||
} | ||
else { | ||
reject(e); | ||
} | ||
}); | ||
}); | ||
}; | ||
const sourceStream = fsx.createReadStream(options.sourcePath); | ||
const uniqueDestinationPaths = new Set(options.destinationPaths); | ||
const pipePromises = []; | ||
for (const destinationPath of uniqueDestinationPaths) { | ||
pipePromises.push(createPipePromise(sourceStream, destinationPath)); | ||
} | ||
await Promise.all(pipePromises); | ||
}); | ||
} | ||
/** | ||
* Copies a file or folder from one location to another, recursively copying any folder contents. | ||
@@ -642,0 +562,0 @@ * By default, destinationPath is overwritten if it already exists. |
@@ -28,3 +28,3 @@ /** | ||
export { Sort } from './Sort'; | ||
export { AlreadyExistsBehavior, FileSystem, FileSystemCopyFilesAsyncFilter, FileSystemCopyFilesFilter, FileSystemStats, IFileSystemCopyFileBaseOptions, IFileSystemCopyFileOptions, IFileSystemCopyFilesAsyncOptions, IFileSystemCopyFilesOptions, IFileSystemCopyFileToManyOptions, IFileSystemCreateLinkOptions, IFileSystemDeleteFileOptions, IFileSystemMoveOptions, IFileSystemReadFileOptions, IFileSystemReadFolderOptions, IFileSystemUpdateTimeParameters, IFileSystemWriteFileOptions } from './FileSystem'; | ||
export { AlreadyExistsBehavior, FileSystem, FileSystemCopyFilesAsyncFilter, FileSystemCopyFilesFilter, FileSystemStats, IFileSystemCopyFileBaseOptions, IFileSystemCopyFileOptions, IFileSystemCopyFilesAsyncOptions, IFileSystemCopyFilesOptions, IFileSystemCreateLinkOptions, IFileSystemDeleteFileOptions, IFileSystemMoveOptions, IFileSystemReadFileOptions, IFileSystemReadFolderOptions, IFileSystemUpdateTimeParameters, IFileSystemWriteFileOptions } from './FileSystem'; | ||
export { FileWriter, IFileWriterFlags } from './FileWriter'; | ||
@@ -31,0 +31,0 @@ export { LegacyAdapters, LegacyCallback } from './LegacyAdapters'; |
{ | ||
"name": "@rushstack/node-core-library", | ||
"version": "3.38.0", | ||
"version": "3.39.0", | ||
"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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
957186
13405