@pi-r/gulp 0.11.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +32 -29
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
- const path = require("node:path");
3
- const fs = require("node:fs");
4
- const child_process = require("node:child_process");
5
- const which = require("which");
6
- const node_util_1 = require("node:util");
7
- const types_1 = require("@e-mc/types");
2
+
3
+ const path = require('node:path');
4
+ const fs = require('node:fs');
5
+ const child_process = require('node:child_process');
6
+ const which = require('which');
7
+ const { stripVTControlCharacters } = require('node:util');
8
+ const { createAbortError, errorMessage, getTempDir, ignoreFlag, isErrorCode, isObject, isPlainObject, isString, sanitizeArgs, sanitizeCmd } = require('@e-mc/types');
8
9
  const Task = require('@e-mc/task');
9
10
  const kGulp = Symbol.for('gulp:constructor');
10
11
  const BIN_NPX = which.sync('npx', { nothrow: true }) || 'npx';
@@ -12,7 +13,7 @@ const BIN_GULP = which.sync("gulp", { nothrow: true }) || '';
12
13
  const REGEXP_TIMESTAMP = /^\[\d+:\d+:\d+\]$/;
13
14
  async function executeTasks(instance, assets, preceding, host) {
14
15
  if (instance.aborted) {
15
- return (0, types_1.createAbortError)(true);
16
+ return createAbortError(true);
16
17
  }
17
18
  return instance.allSettled(instance.collate(assets, preceding), ['Execute tasks', "gulp"]).then(result => {
18
19
  if (host) {
@@ -30,7 +31,7 @@ async function executeTasks(instance, assets, preceding, host) {
30
31
  }
31
32
  });
32
33
  }
33
- const normalizePath = (value) => Task.PLATFORM_WIN32 ? '"' + value.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"' : (0, types_1.sanitizeArgs)(value);
34
+ const normalizePath = (value) => Task.PLATFORM_WIN32 ? '"' + value.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"' : sanitizeArgs(value);
34
35
  class Gulp extends Task {
35
36
  static [kGulp] = true;
36
37
  static async finalize(instance, assets) {
@@ -47,19 +48,19 @@ class Gulp extends Task {
47
48
  const username = this.host?.username || '';
48
49
  for (const item of assets) {
49
50
  const localUri = item.localUri;
50
- if (!localUri || !item.tasks || (0, types_1.ignoreFlag)(item.flags) || !this.canWrite(localUri, { ownPermissionOnly: true })) {
51
+ if (!localUri || !item.tasks || ignoreFlag(item.flags) || !this.canWrite(localUri, { ownPermissionOnly: true })) {
51
52
  continue;
52
53
  }
53
54
  const origDir = path.dirname(localUri);
54
55
  const scheduled = new Set();
55
56
  for (let { task, handler, preceding } of item.tasks) {
56
57
  if (task && handler === "gulp" && !!preceding === isPreceding) {
57
- let gulpfile = (0, types_1.isString)(task) ? username && (0, types_1.isObject)(settings.users) && settings.users[username]?.[task] || settings[task] : task, tasks, opts;
58
- if ((0, types_1.isObject)(gulpfile)) {
58
+ let gulpfile = isString(task) ? username && isObject(settings.users) && settings.users[username]?.[task] || settings[task] : task, tasks, opts;
59
+ if (isObject(gulpfile)) {
59
60
  ({ path: gulpfile, tasks, opts } = gulpfile);
60
61
  }
61
- if ((0, types_1.isString)(gulpfile) && Task.isPath(gulpfile = path.resolve(gulpfile), true) && ((0, types_1.isString)(task) || this.canRead(gulpfile, { ownPermissionOnly: true }))) {
62
- if (!scheduled.has((0, types_1.isString)(task) ? task : task = JSON.stringify(task))) {
62
+ if (isString(gulpfile) && Task.isPath(gulpfile = path.resolve(gulpfile), true) && (isString(task) || this.canRead(gulpfile, { ownPermissionOnly: true }))) {
63
+ if (!scheduled.has(isString(task) ? task : task = JSON.stringify(task))) {
63
64
  try {
64
65
  const buffer = item.sourceUTF8 || item.buffer;
65
66
  if (buffer) {
@@ -85,10 +86,10 @@ class Gulp extends Task {
85
86
  }
86
87
  }
87
88
  else {
88
- if (!(0, types_1.isString)(task)) {
89
+ if (!isString(task)) {
89
90
  task = gulpfile && path.basename(gulpfile);
90
91
  }
91
- this.writeFail(["Unable to perform task", task ? "gulp" + ': ' + task : ''], (0, types_1.errorMessage)(task || "gulp", "Unknown", username), 4);
92
+ this.writeFail(["Unable to perform task", task ? "gulp" + ': ' + task : ''], errorMessage(task || "gulp", "Unknown", username), 4);
92
93
  }
93
94
  }
94
95
  }
@@ -175,24 +176,25 @@ class Gulp extends Task {
175
176
  return { added, deleted };
176
177
  }
177
178
  async parallel(tasks) {
178
- return Promise.allSettled(this.queue(tasks)).then(result => {
179
- let added, deleted, value;
180
- for (const item of result) {
179
+ return Promise.allSettled(this.queue(tasks)).then(items => {
180
+ const result = {};
181
+ let value;
182
+ for (const item of items) {
181
183
  if (item.status === 'fulfilled' && (value = item.value)) {
182
184
  if (value.added) {
183
- (added ||= []).push(...value.added);
185
+ (result.added ||= []).push(...value.added);
184
186
  }
185
187
  if (value.deleted) {
186
- (deleted ||= []).push(...value.deleted);
188
+ (result.deleted ||= []).push(...value.deleted);
187
189
  }
188
190
  }
189
191
  }
190
- return { added, deleted };
192
+ return result;
191
193
  });
192
194
  }
193
195
  spawn(gulp, callback) {
194
196
  const { task, origDir, data } = gulp;
195
- const tempDir = (0, types_1.getTempDir)(true, "gulp");
197
+ const tempDir = getTempDir(true, "gulp");
196
198
  const writeError = (value, err, hint, type = 32) => {
197
199
  if (err) {
198
200
  this.writeFail([value, hint || (this.moduleName + ': ' + task)], err, { type, startTime });
@@ -204,10 +206,10 @@ class Gulp extends Task {
204
206
  const exec = this.settings.exec;
205
207
  let { path: gulpfile, tasks, opts, items } = data, uid, gid;
206
208
  if (!Array.isArray(tasks)) {
207
- tasks = (0, types_1.isString)(tasks) ? [tasks] : [task];
209
+ tasks = isString(tasks) ? [tasks] : [task];
208
210
  }
209
211
  if (!Array.isArray(opts)) {
210
- opts = (0, types_1.isString)(opts) ? [opts] : [];
212
+ opts = isString(opts) ? [opts] : [];
211
213
  }
212
214
  for (let i = 0; i < opts.length; ++i) {
213
215
  switch (opts[i]) {
@@ -235,7 +237,7 @@ class Gulp extends Task {
235
237
  }
236
238
  opts.splice(i--, 1);
237
239
  }
238
- if ((0, types_1.isPlainObject)(exec)) {
240
+ if (isPlainObject(exec)) {
239
241
  let { uid: u, gid: g } = exec;
240
242
  if ((u = parseInt(u)) >= 0) {
241
243
  uid = u;
@@ -250,13 +252,13 @@ class Gulp extends Task {
250
252
  Promise.all(items.map(async (src) => fs.promises.copyFile(src, path.join(tempDir, path.basename(src)))))
251
253
  .then(() => {
252
254
  try {
253
- const args = (0, types_1.sanitizeArgs)(tasks).concat(opts, ['--gulpfile', normalizePath(gulpfile), '--cwd', normalizePath(tempDir)]);
255
+ const args = sanitizeArgs(tasks).concat(opts, ['--gulpfile', normalizePath(gulpfile), '--cwd', normalizePath(tempDir)]);
254
256
  if (!BIN_GULP) {
255
257
  args.unshift('gulp');
256
258
  }
257
259
  let out = '', timeStamp = '', message = '';
258
260
  const setMessage = (type, value) => {
259
- if (REGEXP_TIMESTAMP.test((0, node_util_1.stripVTControlCharacters)(value = value.trim()))) {
261
+ if (REGEXP_TIMESTAMP.test(stripVTControlCharacters(value = value.trim()))) {
260
262
  timeStamp = value + ' ';
261
263
  }
262
264
  else {
@@ -264,7 +266,7 @@ class Gulp extends Task {
264
266
  timeStamp = '';
265
267
  }
266
268
  };
267
- const { stdout, stderr } = child_process.spawn((0, types_1.sanitizeCmd)(BIN_GULP || BIN_NPX, args), { cwd: process.cwd(), shell: true, stdio: Task.hasLogType(32768) && !broadcastId ? 'inherit' : undefined, signal: this.signal, uid, gid })
269
+ const { stdout, stderr } = child_process.spawn(sanitizeCmd(BIN_GULP || BIN_NPX, args), { cwd: process.cwd(), shell: true, stdio: Task.hasLogType(32768) && !broadcastId ? 'inherit' : undefined, signal: this.signal, uid, gid })
268
270
  .on('exit', code => {
269
271
  if (!code) {
270
272
  this.addLog(4, out);
@@ -288,7 +290,7 @@ class Gulp extends Task {
288
290
  }
289
291
  }
290
292
  catch (err) {
291
- if (!copy && (0, types_1.isErrorCode)(err, 'EXDEV')) {
293
+ if (!copy && isErrorCode(err, 'EXDEV')) {
292
294
  copy = true;
293
295
  --i;
294
296
  }
@@ -347,4 +349,5 @@ class Gulp extends Task {
347
349
  });
348
350
  }
349
351
  }
352
+
350
353
  module.exports = Gulp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gulp",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "description": "Gulp task constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -19,8 +19,8 @@
19
19
  "license": "MIT",
20
20
  "homepage": "https://github.com/anpham6/pi-r#readme",
21
21
  "dependencies": {
22
- "@e-mc/task": "^0.13.9",
23
- "@e-mc/types": "^0.13.9",
22
+ "@e-mc/task": "^0.14.0",
23
+ "@e-mc/types": "^0.14.0",
24
24
  "gulp": "^5.0.1",
25
25
  "gulp-cli": "^3.1.0",
26
26
  "which": "^4.0.0"