@e-mc/file-manager 0.9.15 → 0.9.16

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 (3) hide show
  1. package/README.md +10 -10
  2. package/index.js +25 -13
  3. package/package.json +10 -10
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.15/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.16/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, IncrementalMatch, TaskAction } from "./squared";
@@ -286,15 +286,15 @@ NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-
286
286
 
287
287
  ## References
288
288
 
289
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/squared.d.ts
290
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/asset.d.ts
291
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/core.d.ts
292
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/filemanager.d.ts
293
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/logger.d.ts
294
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/module.d.ts
295
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/node.d.ts
296
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/request.d.ts
297
- - https://www.unpkg.com/@e-mc/types@0.9.15/lib/settings.d.ts
289
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/squared.d.ts
290
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/asset.d.ts
291
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/core.d.ts
292
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/filemanager.d.ts
293
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/logger.d.ts
294
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/module.d.ts
295
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/node.d.ts
296
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/request.d.ts
297
+ - https://www.unpkg.com/@e-mc/types@0.9.16/lib/settings.d.ts
298
298
 
299
299
  * https://www.npmjs.com/package/@types/node
300
300
 
package/index.js CHANGED
@@ -7,6 +7,7 @@ const pm = require("picomatch");
7
7
  const chalk = require("chalk");
8
8
  const types_1 = require("@e-mc/types");
9
9
  const core_1 = require("@e-mc/core");
10
+ const module_1 = require("@e-mc/types/lib/module");
10
11
  const util_1 = require("@e-mc/request/util");
11
12
  const asset_1 = require("@e-mc/document/asset");
12
13
  const util_2 = require("@e-mc/document/util");
@@ -112,7 +113,7 @@ function unsetContent(item) {
112
113
  item.buffer = null;
113
114
  }
114
115
  if ('sourceUTF8' in item) {
115
- item.sourceUTF8 = '';
116
+ item.sourceUTF8 = undefined;
116
117
  }
117
118
  }
118
119
  function bundleTorrent(files, mimeType, encoding) {
@@ -152,7 +153,7 @@ function recurseDir(output, subDirs, options) {
152
153
  for (const item of items) {
153
154
  if (!item.isDirectory()) {
154
155
  const pathname = path.join(baseDir, item.name);
155
- if (!ignore.includes(pathname)) {
156
+ if (!ignore.includes(pathname) && !(item.isSymbolicLink() && core_1.Host.isDir(pathname))) {
156
157
  output.push(pathname);
157
158
  }
158
159
  }
@@ -193,24 +194,33 @@ function checkHash(localUri, output, options, data) {
193
194
  }
194
195
  return true;
195
196
  }
196
- function validatePaths(values, patterns, include, dot) {
197
- const items = patterns.map(value => !value.startsWith('*') && /[\\/]/.test(value) ? [core_1.Permission.toPosix(path.resolve(value)), { nocase: PLATFORM_WIN32, dot }] : [value.replace(/(?:^\\|\\+)/g, '/'), { matchBase: true, nocase: PLATFORM_WIN32, dot }]);
197
+ function validatePaths(rootDir, values, patterns, include, dot) {
198
+ const items = patterns.map(value => {
199
+ let invert = false;
200
+ if (!include && value.startsWith('!')) {
201
+ value = value.substring(1);
202
+ invert = true;
203
+ }
204
+ const matchBase = !isMatchRoot(value = core_1.Permission.toPosix(value));
205
+ return [pm(value, { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32, dot, matchBase }), path.isAbsolute(value), invert];
206
+ });
198
207
  return values.filter(value => {
199
- for (const [pattern, options] of items) {
200
- if (pm.isMatch(core_1.Permission.toPosix(value), pattern, options)) {
201
- return include;
208
+ for (const [pattern, absolute, invert] of items) {
209
+ if (pattern(absolute ? value : value.substring(rootDir.length))) {
210
+ return invert ? !include : include;
202
211
  }
203
212
  }
204
213
  return !include;
205
214
  });
206
215
  }
207
- function filterPaths(values, include, exclude, dot) {
216
+ function filterPaths(rootDir, values, include, exclude, dot) {
217
+ rootDir = core_1.Host.normalizePath(rootDir, module_1.NORMALIZE_FLAGS.ENSURE_DIR);
208
218
  if (include) {
209
219
  if ((0, types_1.isString)(include)) {
210
220
  include = [include];
211
221
  }
212
222
  if ((0, types_1.isArray)(include)) {
213
- return validatePaths(values, include, true, dot);
223
+ values = validatePaths(rootDir, values, include, true, dot);
214
224
  }
215
225
  }
216
226
  if (exclude) {
@@ -218,7 +228,7 @@ function filterPaths(values, include, exclude, dot) {
218
228
  exclude = [exclude];
219
229
  }
220
230
  if ((0, types_1.isArray)(exclude)) {
221
- return validatePaths(values, exclude, false, dot);
231
+ return validatePaths(rootDir, values, exclude, false, dot);
222
232
  }
223
233
  }
224
234
  return values;
@@ -313,6 +323,7 @@ function rejectModule(err, type, hint) {
313
323
  const padStart = (value, char) => value > 9 ? value.toString() : char + value;
314
324
  const checksumFile = (algorithm) => "checksum" + '.' + ((0, types_1.isString)(algorithm) ? algorithm.toLowerCase() : "sha256");
315
325
  const checksumError = (algorithm) => new Error("Invalid parameters" + ` (${algorithm || "sha256"})`);
326
+ const isMatchRoot = (value) => !value.startsWith('*') && value.includes('/');
316
327
  const isFunction = (value) => typeof value === 'function';
317
328
  const ignoreAsset = (item, exists) => item.invalid || (0, types_1.hasBit)(item.flags, 1 | (!exists ? 128 : 0));
318
329
  class Scheduler {
@@ -741,10 +752,11 @@ class FileManager extends core_1.Host {
741
752
  let result = [];
742
753
  try {
743
754
  const filename = path.basename(to);
755
+ const output = [];
744
756
  to = joinRoot ? path.join(root, to) : path.resolve(to);
745
757
  recurseDir(result, [root], { ignore: [...ignore, to], sortBy, recursive });
746
- const output = [];
747
- for (const pathname of result = filterPaths(result, include, exclude, options.dot)) {
758
+ result = filterPaths(root, result, include, exclude, options.dot);
759
+ for (const pathname of result) {
748
760
  if (recursive === 1 && path.basename(pathname) === filename) {
749
761
  continue;
750
762
  }
@@ -812,7 +824,7 @@ class FileManager extends core_1.Host {
812
824
  const index = item.indexOf(' ');
813
825
  return [item.substring(0, index), path.join(root, item.substring(index + 1))];
814
826
  });
815
- const checked = include || exclude ? filterPaths(items.map(item => item[1]), include, exclude, options.dot) : null;
827
+ const checked = include || exclude ? filterPaths(root, items.map(item => item[1]), include, exclude, options.dot) : null;
816
828
  let valid;
817
829
  for (const [previous, pathname] of items) {
818
830
  if (checked !== null && !checked.includes(pathname) || recursive === 1 && path.basename(pathname) === filename) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.9.15",
3
+ "version": "0.9.16",
4
4
  "description": "FileManager constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,15 +20,15 @@
20
20
  "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "0.9.15",
24
- "@e-mc/compress": "0.9.15",
25
- "@e-mc/core": "0.9.15",
26
- "@e-mc/document": "0.9.15",
27
- "@e-mc/image": "0.9.15",
28
- "@e-mc/request": "0.9.15",
29
- "@e-mc/task": "0.9.15",
30
- "@e-mc/types": "0.9.15",
31
- "@e-mc/watch": "0.9.15",
23
+ "@e-mc/cloud": "0.9.16",
24
+ "@e-mc/compress": "0.9.16",
25
+ "@e-mc/core": "0.9.16",
26
+ "@e-mc/document": "0.9.16",
27
+ "@e-mc/image": "0.9.16",
28
+ "@e-mc/request": "0.9.16",
29
+ "@e-mc/task": "0.9.16",
30
+ "@e-mc/types": "0.9.16",
31
+ "@e-mc/watch": "0.9.16",
32
32
  "chalk": "4.1.2",
33
33
  "picomatch": "^4.0.2"
34
34
  }