Socket
Socket
Sign inDemoInstall

@squared-functions/task

Package Overview
Dependencies
11
Maintainers
1
Versions
304
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.4 to 1.2.0

133

gulp/index.js

@@ -1,2 +0,2 @@

/* @squared-functions/task/gulp 1.1.4
/* @squared-functions/task/gulp 1.2.0
https://github.com/anpham6/squared-functions */

@@ -7,16 +7,17 @@

const path = require("path");
const fs = require("fs-extra");
const fs = require("fs");
const child_process = require("child_process");
const which = require("which");
const index_1 = require("../index");
const PATH_GULPBIN = which.sync('gulp', { nothrow: true });
const sanitizePath = (value) => value.replace(/\\/g, '\\\\');
const MODULE_NAME = 'gulp';
const PATH_GULPBIN = which.sync(MODULE_NAME, { nothrow: true });
const normalizePath = (value) => value.replace(/\\/g, '\\\\');
class Gulp extends index_1.default {
constructor() {
super(...arguments);
this.moduleName = 'gulp';
this.moduleName = MODULE_NAME;
}
static async using(instance, assets, beforeStage = false) {
const gulp = instance.module.settings;
if (!gulp) {
const settings = instance.module.settings;
if (!settings) {
return;

@@ -31,27 +32,20 @@ }

for (const { handler, task, preceding } of item.tasks) {
if (instance.moduleName === handler && !!preceding === beforeStage) {
let gulpfile = gulp[task];
if (MODULE_NAME === handler && !!preceding === beforeStage) {
let gulpfile = settings[task];
if (gulpfile) {
if (!scheduled.has(task)) {
try {
if (fs.existsSync(gulpfile = path.resolve(gulpfile))) {
if (!taskMap.has(task)) {
taskMap.set(task, new Map());
}
const dirMap = taskMap.get(task);
if (!dirMap.has(origDir)) {
dirMap.set(origDir, { gulpfile, items: [] });
}
dirMap.get(origDir).items.push(item.localUri);
scheduled.add(task);
delete item.sourceUTF8;
}
if (!scheduled.has(task) && index_1.default.existsSafe(gulpfile = path.resolve(gulpfile))) {
if (!taskMap.has(task)) {
taskMap.set(task, new Map());
}
catch (err) {
instance.writeFail(['Unable to resolve file', gulpfile], err);
const dirMap = taskMap.get(task);
if (!dirMap.has(origDir)) {
dirMap.set(origDir, { gulpfile, items: [] });
}
dirMap.get(origDir).items.push(item.localUri);
scheduled.add(task);
delete item.sourceUTF8;
}
}
else {
instance.writeFail(['Unable to locate task', instance.moduleName + ': ' + task], new Error(task + ' (Unknown)'));
instance.writeFail(['Unable to locate task', MODULE_NAME + ': ' + task], new Error(task + ' (Unknown)'));
}

@@ -131,3 +125,3 @@ }

if (tasks.length) {
await index_1.default.allSettled(tasks, ['Execute tasks', instance.moduleName], this.errors);
await index_1.default.allSettled(tasks, { rejected: ['Execute tasks', MODULE_NAME], errors: this.errors });
}

@@ -137,45 +131,62 @@ }

const { task, origDir, data } = gulp;
const taskName = this.moduleName + ': ' + task;
const tempDir = this.getTempDir(true);
try {
fs.mkdirpSync(tempDir);
const hint = this.moduleName + ': ' + task;
Promise.all(data.items.map(uri => fs.copyFile(uri, path.join(tempDir, path.basename(uri)))))
const time = Date.now();
const writeError = (value, err, hint = taskName) => {
if (err) {
this.writeFail([value, hint], err, this.logType.FILE);
}
this.writeTimeProcess('gulp', task, time, { failed: true });
index_1.default.removeDir(tempDir);
};
this.formatMessage(this.logType.PROCESS, 'gulp', ['Executing task...', task], data.gulpfile);
if (index_1.default.createDir(tempDir)) {
Promise.all(data.items.map(uri => {
return new Promise((resolve, reject) => {
fs.copyFile(uri, path.join(tempDir, path.basename(uri)), err => {
if (!err) {
resolve();
}
else {
reject(err);
}
});
});
}))
.then(() => {
this.formatMessage(this.logType.PROCESS, 'gulp', ['Executing task...', task], data.gulpfile);
const time = Date.now();
const output = PATH_GULPBIN ? child_process.execFile(PATH_GULPBIN, [task, '--gulpfile', `"${sanitizePath(data.gulpfile)}"`, '--cwd', `"${sanitizePath(tempDir)}"`], { cwd: process.cwd(), shell: true }) : child_process.exec(`gulp ${task} --gulpfile "${sanitizePath(data.gulpfile)}" --cwd "${sanitizePath(tempDir)}"`, { cwd: process.cwd() });
output.on('close', code => {
(PATH_GULPBIN ? child_process.execFile(PATH_GULPBIN, [task, '--gulpfile', `"${normalizePath(data.gulpfile)}"`, '--cwd', `"${normalizePath(tempDir)}"`], { cwd: process.cwd(), shell: true }) : child_process.exec(`gulp ${task} --gulpfile "${normalizePath(data.gulpfile)}" --cwd "${normalizePath(tempDir)}"`, { cwd: process.cwd() }))
.on('close', code => {
if (!code) {
index_1.default.allSettled(data.items.map(uri => fs.unlink(uri).then(() => manager.delete(uri))), ['Unable to delete file', hint], this.errors)
.then(() => {
fs.readdir(tempDir)
.then(value => {
Promise.all(value.map(filename => {
data.items.forEach(uri => this.deleteFile(uri));
try {
for (const filename of fs.readdirSync(tempDir)) {
try {
const uri = path.join(origDir, filename);
return fs.move(path.join(tempDir, filename), uri, { overwrite: true }).then(() => manager.add(uri));
}))
.then(() => {
this.writeTimeProcess('gulp', task, time);
callback();
})
.catch(err_1 => {
this.writeFail(['Unable to replace files', hint], err_1, this.logType.FILE);
callback();
});
})
.catch(err_1 => {
this.writeFail(['Unable to read directory', hint], err_1);
callback();
});
});
fs.renameSync(path.join(tempDir, filename), uri);
manager.add(uri);
}
catch (err) {
this.writeFail(["Unable to rename file" /* RENAME_FILE */, taskName], err, this.logType.FILE);
}
}
this.writeTimeProcess('gulp', task, time);
index_1.default.removeDir(tempDir);
callback();
}
catch (err) {
writeError("Unable to read directory" /* READ_DIRECTORY */, err);
callback();
}
}
else {
writeError('');
callback();
}
});
output.on('error', err => this.writeFail(['Unknown', hint], err));
});
})
.on('error', err => writeError("Unknown" /* UNKNOWN */, err));
})
.catch(err => writeError("Unable to copy file" /* COPY_FILE */, err, tempDir));
}
catch (err) {
this.writeFail(['Unable to create directory', tempDir], err, this.logType.FILE);
else {
writeError("Unable to create directory" /* CREATE_DIRECTORY */, null, tempDir);
callback();

@@ -182,0 +193,0 @@ }

@@ -1,2 +0,2 @@

/* @squared-functions/task 1.1.4
/* @squared-functions/task 1.2.0
https://github.com/anpham6/squared-functions */

@@ -3,0 +3,0 @@

{
"name": "@squared-functions/task",
"version": "1.1.4",
"version": "1.2.0",
"description": "Task functions for squared-functions",

@@ -18,7 +18,6 @@ "main": "index.js",

"dependencies": {
"@squared-functions/module": "^1.1.4",
"@squared-functions/types": "^1.1.4",
"fs-extra": "^9.1.0",
"@squared-functions/module": "^1.2.0",
"@squared-functions/types": "^1.2.0",
"which": "^2.0.2"
}
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc