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

faster-webpack-upload-plugin

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faster-webpack-upload-plugin - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

2

package.json
{
"name": "faster-webpack-upload-plugin",
"version": "1.1.1",
"version": "1.2.0",
"author": "WangTieZhu92",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -42,3 +42,3 @@ # faster-webpack-upload-plugin

username|Username for authentication|String|(none)
localPath|Folder path which need upload|String|(none)
~~localPath~~|~~Folder path which need upload~~|~~String~~|Deprecated,don't need it anymore
remotePath|Folder path on server|String|(none)

@@ -51,3 +51,10 @@ log|Show log when is uploading|Boolean \| {info: Boolean, progress: Boolean, warning: Boolean, error: Boolean}|false

## Change Log
### 1.2.0
```
- change: remove the code of scanning local directory, so remove the option "localPath"
- fix: when webpack watching mode add new folder, the plugin can auto retry and make it right
```
## License
This project is licensed under [MIT](http://www.opensource.org/licenses/mit-license.php).

@@ -44,9 +44,8 @@ 'use strict'

async upload(compilation, callback) {
const {localPath, remotePath, log, fileIgnores, clearFolder, ...others} = this.options;
const {remotePath, log, clearFolder, ...others} = this.options;
const folders = [];
const files = [];
const files = []; // Array<{local: string, remote: string, size: string, folder: string[]}>
const uploadedFiles = [];

@@ -58,2 +57,3 @@

if (this.options.firstEmit) {
// first emit will check the remotePath folder exists and clear remote folder and files
try {

@@ -63,3 +63,3 @@ await sftp.exists(remotePath);

log && log.info && console.log(chalk.red('Clearing remote folder...'));
await sftp.rmdir(remotePath, true);
await sftp.rmdir(remotePath, true); //clear
await sftp.mkdir(remotePath, true);

@@ -71,29 +71,21 @@ }

this.getFolderNFiles(folders, files, localPath, remotePath);
this.getFolderNFiles(folders, files, compilation.assets);
this.options.firstEmit = false;
this.options.firstEmit = false;
} else {
const assets = compilation.assets;
for (const file in assets) {
if (assets[file].emitted) {
if (fileIgnores && fileIgnores.some((regexp) => regexp.test(assets[file].existsAt))) {
return;
}
files.push({
local: assets[file].existsAt,
remote: formatRemotePath(remotePath, file),
size: assets[file].size(),
})
}
}
this.getFolderNFiles(null, files, compilation.assets);
}
if (folders.length > 0) {
log && log.info && console.log(chalk.green('Creating remote folders...'));
await Promise.all(folders.map(folder => sftp.mkdir(folder).catch(() => log && log.warning && console.log(chalk.yellow('Folder create failed,it might exists')))));
for (let folder of folders) {
await sftp.mkdir(folder, true).catch(() => log && log.warning && console.log(chalk.yellow(`Folder "${folder}" create failed,it might exists`)))
}
//this way will make many warning
// await Promise.all(folders.map(folder => sftp.mkdir(folder, true).catch(() => log && log.warning && console.log(chalk.yellow(`Folder "${folder}" create failed,it might exists`)))));
}
log && log.info && console.log(chalk.green('Uploading...'));
const pb = log && log.progress && new ProgressBar('', 50);

@@ -104,3 +96,14 @@

sftp.fastPut(file.local, file.remote)
.catch(log && log.error && console.log)
.catch((err) => {
// upload err checker, if err end with "No such file", it will make dir and retry
if (err.toString().includes("No such file")) {
log && log.warning && console.log(chalk.yellow(`File: "${file.remote}"'s folder not exists,make a folder and retrying...`));
return async function retry() {
await sftp.mkdir(file.folder, true).catch(() => null);
return await sftp.fastPut(file.local, file.remote).catch(log && log.error && console);
}();
}
})
.then(result => {

@@ -122,2 +125,3 @@ if (result) {

// webpack finished callback
if (callback) {

@@ -128,40 +132,34 @@ callback();

getFolderNFiles(folders, files, local, remote, file) {
if (file) {
const localPath = path.join(local, file);
const stats = fs.statSync(localPath);
if (stats.isDirectory()) {
const folder = remote + '/' + file;
const list = fs.readdirSync(local + '/' + file);
getFolderNFiles(folders, files, assets){
const folderSet = folders && new Set();
for (const file in assets) {
folders.push(folder);
for (const f of list) {
this.getFolderNFiles(folders, files, localPath, folder, f);
}
} else {
if (this.options.fileIgnores && this.options.fileIgnores.some((regexp) => regexp.test(localPath))) {
return;
}
if (assets[file].emitted && (!this.options.fileIgnores || !this.options.fileIgnores.some((regexp) => regexp.test(assets[file].existsAt)))) {
const remote = formatRemotePath(this.options.remotePath, file);
let folder = remote.substr(0, remote.lastIndexOf("/"));
const split = folder.replace(this.options.remotePath, "").split("/");
folders && folderSet.add(folder);
files.push({
local: localPath,
remote: remote + '/' + file,
size: stats.size,
local: assets[file].existsAt,
remote,
folder,
size: assets[file].size(),
});
}
} else {
const fileList = fs.readdirSync(local);
for (const f of fileList) {
this.getFolderNFiles(folders, files, local, remote, f);
}
}
if (folders) {
const copy = Array.from(folderSet);
folderSet.forEach((f) => !copy.some(s => (s !== f) && s.includes(f)) && folders.push(f));
}
}
}
function formatRemotePath(remotePath, filePath) {
return (remotePath + '/' + filePath).replace(/\\/g, '/');
return (remotePath + '/' + filePath).replace(/\\/g, '/').replace(/\.\//g, "");
}
module.exports = FasterWebpackUploadPlugin;
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