@pi-r/gulp 0.11.3 → 0.12.1

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 +36 -30
  2. package/package.json +3 -6
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,22 @@ 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 (gulpfile && Task.isPath(gulpfile = path.resolve(gulpfile), true) && (isString(task) || this.canRead(gulpfile, { ownPermissionOnly: true }))) {
63
+ if (!isString(task)) {
64
+ task = JSON.stringify(task);
65
+ }
66
+ if (!scheduled.has(task)) {
63
67
  try {
64
68
  const buffer = item.sourceUTF8 || item.buffer;
65
69
  if (buffer) {
@@ -85,10 +89,10 @@ class Gulp extends Task {
85
89
  }
86
90
  }
87
91
  else {
88
- if (!(0, types_1.isString)(task)) {
92
+ if (!isString(task)) {
89
93
  task = gulpfile && path.basename(gulpfile);
90
94
  }
91
- this.writeFail(["Unable to perform task", task ? "gulp" + ': ' + task : ''], (0, types_1.errorMessage)(task || "gulp", "Unknown", username), 4);
95
+ this.writeFail(["Unable to perform task", task ? "gulp" + ': ' + task : ''], errorMessage(task || "gulp", "Unknown", username), 4);
92
96
  }
93
97
  }
94
98
  }
@@ -175,24 +179,25 @@ class Gulp extends Task {
175
179
  return { added, deleted };
176
180
  }
177
181
  async parallel(tasks) {
178
- return Promise.allSettled(this.queue(tasks)).then(result => {
179
- let added, deleted, value;
180
- for (const item of result) {
182
+ return Promise.allSettled(this.queue(tasks)).then(items => {
183
+ const result = {};
184
+ let value;
185
+ for (const item of items) {
181
186
  if (item.status === 'fulfilled' && (value = item.value)) {
182
187
  if (value.added) {
183
- (added ||= []).push(...value.added);
188
+ (result.added ||= []).push(...value.added);
184
189
  }
185
190
  if (value.deleted) {
186
- (deleted ||= []).push(...value.deleted);
191
+ (result.deleted ||= []).push(...value.deleted);
187
192
  }
188
193
  }
189
194
  }
190
- return { added, deleted };
195
+ return result;
191
196
  });
192
197
  }
193
198
  spawn(gulp, callback) {
194
199
  const { task, origDir, data } = gulp;
195
- const tempDir = (0, types_1.getTempDir)(true, "gulp");
200
+ const tempDir = getTempDir(true, "gulp");
196
201
  const writeError = (value, err, hint, type = 32) => {
197
202
  if (err) {
198
203
  this.writeFail([value, hint || (this.moduleName + ': ' + task)], err, { type, startTime });
@@ -201,13 +206,14 @@ class Gulp extends Task {
201
206
  callback();
202
207
  }
203
208
  };
209
+ const broadcastId = this.broadcastId;
204
210
  const exec = this.settings.exec;
205
211
  let { path: gulpfile, tasks, opts, items } = data, uid, gid;
206
212
  if (!Array.isArray(tasks)) {
207
- tasks = (0, types_1.isString)(tasks) ? [tasks] : [task];
213
+ tasks = isString(tasks) ? [tasks] : [task];
208
214
  }
209
215
  if (!Array.isArray(opts)) {
210
- opts = (0, types_1.isString)(opts) ? [opts] : [];
216
+ opts = isString(opts) ? [opts] : [];
211
217
  }
212
218
  for (let i = 0; i < opts.length; ++i) {
213
219
  switch (opts[i]) {
@@ -235,7 +241,7 @@ class Gulp extends Task {
235
241
  }
236
242
  opts.splice(i--, 1);
237
243
  }
238
- if ((0, types_1.isPlainObject)(exec)) {
244
+ if (isPlainObject(exec)) {
239
245
  let { uid: u, gid: g } = exec;
240
246
  if ((u = parseInt(u)) >= 0) {
241
247
  uid = u;
@@ -245,18 +251,17 @@ class Gulp extends Task {
245
251
  }
246
252
  }
247
253
  const startTime = process.hrtime();
248
- const broadcastId = this.broadcastId;
249
254
  this.formatMessage(4, "gulp", ['Executing task...', task], gulpfile);
250
255
  Promise.all(items.map(async (src) => fs.promises.copyFile(src, path.join(tempDir, path.basename(src)))))
251
256
  .then(() => {
252
257
  try {
253
- const args = (0, types_1.sanitizeArgs)(tasks).concat(opts, ['--gulpfile', normalizePath(gulpfile), '--cwd', normalizePath(tempDir)]);
258
+ const args = sanitizeArgs(tasks).concat(opts, ['--gulpfile', normalizePath(gulpfile), '--cwd', normalizePath(tempDir)]);
254
259
  if (!BIN_GULP) {
255
260
  args.unshift('gulp');
256
261
  }
257
262
  let out = '', timeStamp = '', message = '';
258
263
  const setMessage = (type, value) => {
259
- if (REGEXP_TIMESTAMP.test((0, node_util_1.stripVTControlCharacters)(value = value.trim()))) {
264
+ if (REGEXP_TIMESTAMP.test(stripVTControlCharacters(value = value.trim()))) {
260
265
  timeStamp = value + ' ';
261
266
  }
262
267
  else {
@@ -264,7 +269,7 @@ class Gulp extends Task {
264
269
  timeStamp = '';
265
270
  }
266
271
  };
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 })
272
+ 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
273
  .on('exit', code => {
269
274
  if (!code) {
270
275
  this.addLog(4, out);
@@ -288,7 +293,7 @@ class Gulp extends Task {
288
293
  }
289
294
  }
290
295
  catch (err) {
291
- if (!copy && (0, types_1.isErrorCode)(err, 'EXDEV')) {
296
+ if (!copy && isErrorCode(err, 'EXDEV')) {
292
297
  copy = true;
293
298
  --i;
294
299
  }
@@ -347,4 +352,5 @@ class Gulp extends Task {
347
352
  });
348
353
  }
349
354
  }
355
+
350
356
  module.exports = Gulp;
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@pi-r/gulp",
3
- "version": "0.11.3",
3
+ "version": "0.12.1",
4
4
  "description": "Gulp task constructor for E-mc.",
5
5
  "main": "index.js",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
6
  "repository": {
10
7
  "type": "git",
11
8
  "url": "git+https://github.com/anpham6/pi-r.git",
@@ -19,8 +16,8 @@
19
16
  "license": "MIT",
20
17
  "homepage": "https://github.com/anpham6/pi-r#readme",
21
18
  "dependencies": {
22
- "@e-mc/task": "^0.13.10",
23
- "@e-mc/types": "^0.13.10",
19
+ "@e-mc/task": "^0.14.1",
20
+ "@e-mc/types": "^0.14.1",
24
21
  "gulp": "^5.0.1",
25
22
  "gulp-cli": "^3.1.0",
26
23
  "which": "^4.0.0"