@iconify/tools 2.0.4 → 2.0.5

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.
@@ -19,7 +19,7 @@ async function findMatchingDirs(rootDir, hash) {
19
19
  lastChunk !== hash.slice(0, lastChunk.length)) {
20
20
  continue;
21
21
  }
22
- const stat = await fs_1.promises.lstat(rootDir + '/' + file);
22
+ const stat = await fs_1.promises.stat(rootDir + '/' + file);
23
23
  if (stat.isDirectory()) {
24
24
  matches.push(file);
25
25
  }
@@ -41,7 +41,7 @@ async function downloadGitHubRepo(options) {
41
41
  // Check if archive exists
42
42
  let exists = false;
43
43
  try {
44
- const stat = await fs_1.promises.lstat(archiveTarget);
44
+ const stat = await fs_1.promises.stat(archiveTarget);
45
45
  exists = stat.isFile();
46
46
  }
47
47
  catch (err) {
@@ -71,8 +71,10 @@ async function downloadGitHubRepo(options) {
71
71
  const stat = await fs_1.promises.lstat(filename);
72
72
  const isDir = stat.isDirectory();
73
73
  if (
74
- // Remove if directory matches hash to avoid errors extracting zip
75
- (isDir && filename.slice(0 - hashSearch.length) === hashSearch) ||
74
+ // Remove symbolic links
75
+ stat.isSymbolicLink() ||
76
+ // Remove if directory matches hash to avoid errors extracting zip
77
+ (isDir && filename.slice(0 - hashSearch.length) === hashSearch) ||
76
78
  // Remove if directory and cleanupOldDirectories is not disabled
77
79
  (isDir && options.cleanupOldDirectories !== false) ||
78
80
  // Remove if file and cleanupOldFiles is enabled
@@ -15,7 +15,7 @@ async function findMatchingDirs(rootDir, hash) {
15
15
  if (lastChunk.length < 4 || lastChunk !== hash.slice(0, lastChunk.length)) {
16
16
  continue;
17
17
  }
18
- const stat = await fs.lstat(rootDir + "/" + file);
18
+ const stat = await fs.stat(rootDir + "/" + file);
19
19
  if (stat.isDirectory()) {
20
20
  matches.push(file);
21
21
  }
@@ -32,7 +32,7 @@ async function downloadGitHubRepo(options) {
32
32
  const archiveTarget = rootDir + "/" + hash + ".zip";
33
33
  let exists = false;
34
34
  try {
35
- const stat = await fs.lstat(archiveTarget);
35
+ const stat = await fs.stat(archiveTarget);
36
36
  exists = stat.isFile();
37
37
  } catch (err) {
38
38
  }
@@ -56,7 +56,7 @@ async function downloadGitHubRepo(options) {
56
56
  const filename = rootDir + "/" + files[i];
57
57
  const stat = await fs.lstat(filename);
58
58
  const isDir = stat.isDirectory();
59
- if (isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
59
+ if (stat.isSymbolicLink() || isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
60
60
  try {
61
61
  await fs.rm(filename, {
62
62
  force: true,
@@ -36,7 +36,7 @@ async function downloadNPMPackage(options) {
36
36
  // Check if archive exists
37
37
  let archiveExists = false;
38
38
  try {
39
- const stat = await fs_1.promises.lstat(archiveTarget);
39
+ const stat = await fs_1.promises.stat(archiveTarget);
40
40
  archiveExists = stat.isFile();
41
41
  }
42
42
  catch (err) {
@@ -29,7 +29,7 @@ async function downloadNPMPackage(options) {
29
29
  await prepareDirectoryForExport(options);
30
30
  let archiveExists = false;
31
31
  try {
32
- const stat = await fs.lstat(archiveTarget);
32
+ const stat = await fs.stat(archiveTarget);
33
33
  archiveExists = stat.isFile();
34
34
  } catch (err) {
35
35
  }
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ import type { Stats } from 'fs';
1
3
  /**
2
4
  * Callback
3
5
  *
@@ -13,8 +15,8 @@
13
15
  */
14
16
  declare type ScanDirectoryCallbackFalseResult = boolean | null | undefined;
15
17
  declare type ScanDirectoryCallbackStringResult = ScanDirectoryCallbackFalseResult | string;
16
- declare type ScanDirectoryCallbackAsString = (ext: string, file: string, subdir: string, path: string) => ScanDirectoryCallbackStringResult | Promise<ScanDirectoryCallbackStringResult>;
17
- declare type ScanDirectoryCallbackAsCustom<T> = (ext: string, file: string, subdir: string, path: string) => T | ScanDirectoryCallbackFalseResult | Promise<T | ScanDirectoryCallbackFalseResult>;
18
+ declare type ScanDirectoryCallbackAsString = (ext: string, file: string, subdir: string, path: string, stat: Stats) => ScanDirectoryCallbackStringResult | Promise<ScanDirectoryCallbackStringResult>;
19
+ declare type ScanDirectoryCallbackAsCustom<T> = (ext: string, file: string, subdir: string, path: string, stat: Stats) => T | ScanDirectoryCallbackFalseResult | Promise<T | ScanDirectoryCallbackFalseResult>;
18
20
  export declare type ScanDirectoryCallback = ScanDirectoryCallbackAsCustom<unknown> | ScanDirectoryCallbackAsString;
19
21
  /**
20
22
  * Find all files in directory
package/lib/misc/scan.js CHANGED
@@ -15,7 +15,7 @@ async function scanDirectory(path, callback, subdirs = true) {
15
15
  // Exclude hidden items
16
16
  continue;
17
17
  }
18
- const stat = await fs_1.promises.lstat(path + subdir + filename);
18
+ const stat = await fs_1.promises.stat(path + subdir + filename);
19
19
  if (stat.isDirectory()) {
20
20
  if (subdirs) {
21
21
  await scan(subdir + filename + '/');
@@ -31,7 +31,7 @@ async function scanDirectory(path, callback, subdirs = true) {
31
31
  // Callback
32
32
  let callbackResult;
33
33
  if (callback) {
34
- callbackResult = callback(ext, file, subdir, path);
34
+ callbackResult = callback(ext, file, subdir, path, stat);
35
35
  if (callbackResult instanceof Promise) {
36
36
  callbackResult = await callbackResult;
37
37
  }
package/lib/misc/scan.mjs CHANGED
@@ -12,7 +12,7 @@ async function scanDirectory(path, callback, subdirs = true) {
12
12
  if (filename.slice(0, 1) === ".") {
13
13
  continue;
14
14
  }
15
- const stat = await fs.lstat(path + subdir + filename);
15
+ const stat = await fs.stat(path + subdir + filename);
16
16
  if (stat.isDirectory()) {
17
17
  if (subdirs) {
18
18
  await scan(subdir + filename + "/");
@@ -27,7 +27,7 @@ async function scanDirectory(path, callback, subdirs = true) {
27
27
  const file = parts.join(".");
28
28
  let callbackResult;
29
29
  if (callback) {
30
- callbackResult = callback(ext, file, subdir, path);
30
+ callbackResult = callback(ext, file, subdir, path, stat);
31
31
  if (callbackResult instanceof Promise) {
32
32
  callbackResult = await callbackResult;
33
33
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@iconify/tools",
3
3
  "description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
4
4
  "author": "Vjacheslav Trushkin",
5
- "version": "2.0.4",
5
+ "version": "2.0.5",
6
6
  "license": "MIT",
7
7
  "bugs": "https://github.com/iconify/tools/issues",
8
8
  "homepage": "https://github.com/iconify/tools",