@e-mc/file-manager 0.14.1 → 0.14.3

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 +11 -10
  2. package/index.js +31 -18
  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.14.1/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.14.3/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { ChecksumValue, DataSource, IncrementalMatch, TaskAction } from "./squared";
@@ -51,6 +51,7 @@ interface IFileManager extends IHost, Set<string> {
51
51
  readonly emptyDir: Set<string>;
52
52
  readonly cacheToDisk: IHttpDiskCache<ExternalAsset>;
53
53
  readonly cacheToMemory: IHttpMemoryCache<ExternalAsset>;
54
+ [Symbol.asyncIterator](): IteratorObject<[string, Buffer, BufferEncoding?], BuiltinIteratorReturn>;
54
55
  install(name: "document", handler: string, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
55
56
  install(name: "document", target: DocumentConstructor, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
56
57
  install(name: "task", handler: string, module?: TaskModule, ...args: unknown[]): ITask | undefined;
@@ -297,15 +298,15 @@ NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-
297
298
 
298
299
  ## References
299
300
 
300
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/squared.d.ts
301
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/asset.d.ts
302
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/core.d.ts
303
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/filemanager.d.ts
304
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/logger.d.ts
305
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/module.d.ts
306
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/node.d.ts
307
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/request.d.ts
308
- - https://www.unpkg.com/@e-mc/types@0.14.1/lib/settings.d.ts
301
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/squared.d.ts
302
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/asset.d.ts
303
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/core.d.ts
304
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/filemanager.d.ts
305
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/logger.d.ts
306
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/module.d.ts
307
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/node.d.ts
308
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/request.d.ts
309
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/settings.d.ts
309
310
 
310
311
  * https://www.npmjs.com/package/@types/node
311
312
 
package/index.js CHANGED
@@ -153,12 +153,12 @@ function recurseDir(output, subDirs, options) {
153
153
  for (const item of items) {
154
154
  if (!item.isDirectory()) {
155
155
  const pathname = path.join(baseDir, item.name);
156
- if (item.isSymbolicLink() && Host.isDir(pathname) || ignore.length > 0 && !hasPath(ignore, pathname)) {
156
+ if (item.isSymbolicLink() && Host.isDir(pathname) || ignore.length > 0 && (Host.PLATFORM_WIN32 ? ignore.includes(pathname.toLowerCase()) : ignore.includes(pathname))) {
157
157
  continue;
158
158
  }
159
159
  output.push(pathname);
160
160
  }
161
- else if (recursive && (subDirs.length > 1 || !hasPath(ignoreRoot, item.name))) {
161
+ else if (recursive && (subDirs.length > 1 || (Host.PLATFORM_WIN32 ? !ignoreRoot.includes(item.name.toLowerCase()) : !ignoreRoot.includes(item.name)))) {
162
162
  recurseDir(output, subDirs.concat(item.name), options);
163
163
  }
164
164
  }
@@ -294,7 +294,7 @@ function processCacheHeaders(headers, noCache, noStore) {
294
294
  const maxAge = cacheControl.find(value => value.startsWith('max-age='));
295
295
  if (maxAge && (!noCache || cacheControl.includes('public') || cacheControl.includes('must-revalidate'))) {
296
296
  const age = parseHeader(headers, 'age');
297
- let result = parseInt(maxAge.split('=').pop()) * 1000;
297
+ let result = parseInt(maxAge.split('=').at(-1)) * 1000;
298
298
  if (age) {
299
299
  result -= age;
300
300
  if (result < 0 && noCache) {
@@ -498,10 +498,10 @@ const downloadStats = () => [[0, 0], [0, 0], [0, 0]];
498
498
  const isCacheable = (item) => item.initialValue?.cacheable !== false;
499
499
  const getPmOptions = (value, { matchBase = value.startsWith('*') && !value.includes('/'), dot = false } = {}) => ({ nocase: Host.PLATFORM_WIN32, matchBase, dot });
500
500
  const isDownloadAll = (type) => type === 4 || type === 0;
501
+ const isNoContent = (statusCode) => statusCode === 204 || statusCode === 304;
501
502
  const isStored = (noCache, maxAge) => !noCache || typeof maxAge === 'number';
502
503
  const hasFiles = (type, uri) => type === 3 || type === 4 || type === 0 && Request.isRclone(uri);
503
504
  const hasIncremental = (value) => value === "etag" || value === "exists";
504
- const hasPath = (values, name) => Host.PLATFORM_WIN32 ? !values.includes(name.toLowerCase()) : !values.includes(name);
505
505
  const toPathCase = (value) => Host.PLATFORM_WIN32 ? value.toLowerCase() : value;
506
506
  const toPosix = (values) => Host.PLATFORM_WIN32 ? values.map(value => Permission.toPosix(value).toLowerCase()) : values;
507
507
  const formatPercent = (value) => Math.round(value).toString().padStart(3) + '%';
@@ -912,7 +912,7 @@ class ProcessFile {
912
912
  host.Request.open(url, { method: 'HEAD', httpVersion: 1, headers: file.headers })
913
913
  .on('response', res => {
914
914
  const statusCode = res.statusCode;
915
- if (statusCode === 204 || statusCode === 304) {
915
+ if (isNoContent(statusCode)) {
916
916
  file.contentLength = 0;
917
917
  }
918
918
  else if (statusCode < 300) {
@@ -1148,12 +1148,7 @@ class ProcessFile {
1148
1148
  const downloaded = groupData.bundling[uri];
1149
1149
  if (isArray(downloaded)) {
1150
1150
  if (data && !queue.invalid) {
1151
- if (typeof data === 'string') {
1152
- queue.sourceUTF8 = data;
1153
- }
1154
- else {
1155
- queue.buffer = data;
1156
- }
1151
+ setContent(queue, data);
1157
1152
  this.copyDownload(queue, downloaded);
1158
1153
  }
1159
1154
  else {
@@ -1736,6 +1731,20 @@ class FileManager extends Host {
1736
1731
  yield file;
1737
1732
  }
1738
1733
  }
1734
+ *[Symbol.asyncIterator]() {
1735
+ for (const file of this.files) {
1736
+ const asset = this._assets.find(item => item.localUri === file);
1737
+ try {
1738
+ const buffer = asset && this.getBuffer(asset) || fs.readFileSync(file);
1739
+ if (buffer) {
1740
+ yield [file, buffer, asset?.encoding];
1741
+ }
1742
+ }
1743
+ catch (err) {
1744
+ this.addLog(3, err, { source: file });
1745
+ }
1746
+ }
1747
+ }
1739
1748
  add(value, parent, type = FILE_TYPE.TRANSFORM) {
1740
1749
  const file = this.removeCwd(value);
1741
1750
  if (file) {
@@ -2476,7 +2485,7 @@ class FileManager extends Host {
2476
2485
  }
2477
2486
  let filename = file.filename;
2478
2487
  if (!filename && !file.document && !isDownloadAll(type)) {
2479
- filename = url.pathname.split('/').pop();
2488
+ filename = url.pathname.split('/').at(-1);
2480
2489
  if (filename.includes('.')) {
2481
2490
  const mimeType = file.mimeType || Host.lookupMime(filename);
2482
2491
  if (mimeType) {
@@ -2557,7 +2566,7 @@ class FileManager extends Host {
2557
2566
  if (file.buffer) {
2558
2567
  return (typeof minStreamSize === 'number' ? Promise.resolve(file.buffer) : file.buffer);
2559
2568
  }
2560
- let { base64, localUri } = file;
2569
+ let { base64, sourceUTF8, localUri } = file;
2561
2570
  if (localUri) {
2562
2571
  if (typeof minStreamSize === 'number') {
2563
2572
  return Host.streamFile(localUri, { minStreamSize, cache: false, signal: this.signal });
@@ -2566,13 +2575,14 @@ class FileManager extends Host {
2566
2575
  return fs.readFileSync(localUri);
2567
2576
  }
2568
2577
  catch (err) {
2569
- if (!(base64 && isErrorCode(err, 'ENOENT', 'EACCES'))) {
2578
+ if (!(isErrorCode(err, 'ENOENT', 'EACCES') && (sourceUTF8 || base64))) {
2570
2579
  this.writeFail(["Unable to read file", path.basename(localUri)], err, 32);
2580
+ sourceUTF8 = undefined;
2571
2581
  base64 = undefined;
2572
2582
  }
2573
2583
  }
2574
2584
  }
2575
- const result = base64 ? Buffer.from(base64, 'base64') : null;
2585
+ const result = sourceUTF8 ? Buffer.from(sourceUTF8, file.encoding) : base64 ? Buffer.from(base64, 'base64') : null;
2576
2586
  return (typeof minStreamSize === 'number' ? Promise.resolve(result) : result);
2577
2587
  }
2578
2588
  getCacheDir(url, createDir = true) {
@@ -3572,10 +3582,13 @@ class FileManager extends Host {
3572
3582
  .on('response', res => {
3573
3583
  --processTask.pending;
3574
3584
  const statusCode = res.statusCode;
3575
- if (statusCode < 300) {
3576
- const etag = processHeaders(res.headers, item, false, mainEtag);
3585
+ if (isNoContent(statusCode)) {
3586
+ downloadUri(opts, null);
3587
+ }
3588
+ else if (statusCode < 300) {
3589
+ const etag = processHeaders(res.headers, item, false, mainEtag && !opts.noStore);
3577
3590
  let etagDir = null, tempDir;
3578
- if (etag && !opts.noCache) {
3591
+ if (etag && !opts.noCache && !opts.noStore) {
3579
3592
  if (cacheDir || mainEtag) {
3580
3593
  tempDir = this.getCacheDir(href);
3581
3594
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.14.1",
3
+ "version": "0.14.3",
4
4
  "description": "FileManager constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -16,15 +16,15 @@
16
16
  "license": "BSD-3-Clause",
17
17
  "homepage": "https://github.com/anpham6/e-mc#readme",
18
18
  "dependencies": {
19
- "@e-mc/cloud": "0.14.1",
20
- "@e-mc/compress": "0.14.1",
21
- "@e-mc/core": "0.14.1",
22
- "@e-mc/document": "0.14.1",
23
- "@e-mc/image": "0.14.1",
24
- "@e-mc/request": "0.14.1",
25
- "@e-mc/task": "0.14.1",
26
- "@e-mc/types": "0.14.1",
27
- "@e-mc/watch": "0.14.1",
19
+ "@e-mc/cloud": "0.14.3",
20
+ "@e-mc/compress": "0.14.3",
21
+ "@e-mc/core": "0.14.3",
22
+ "@e-mc/document": "0.14.3",
23
+ "@e-mc/image": "0.14.3",
24
+ "@e-mc/request": "0.14.3",
25
+ "@e-mc/task": "0.14.3",
26
+ "@e-mc/types": "0.14.3",
27
+ "@e-mc/watch": "0.14.3",
28
28
  "chalk": "4.1.2",
29
29
  "diff": "^9.0.0",
30
30
  "picomatch": "^4.0.4"