@iconify/tools 2.0.2 → 2.0.6

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
  }
@@ -8,7 +8,7 @@ const minify_1 = require("@iconify/utils/lib/icon-set/minify");
8
8
  const convert_info_1 = require("@iconify/utils/lib/icon-set/convert-info");
9
9
  const props_1 = require("./props");
10
10
  const svg_1 = require("../svg");
11
- // eslint-disable-next-line @typescript-eslint/no-unused-vars-experimental, @typescript-eslint/no-unused-vars
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
12
  function assertNever(v) {
13
13
  //
14
14
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeIconSets = void 0;
4
4
  const _1 = require(".");
5
5
  const match_1 = require("./match");
6
- // eslint-disable-next-line @typescript-eslint/no-unused-vars-experimental, @typescript-eslint/no-unused-vars
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
7
  function assertNever(v) {
8
8
  //
9
9
  }
@@ -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
  }
@@ -52,6 +52,8 @@ exports.shapeModifiyingSVGOPlugins = [
52
52
  * Run SVGO on icon
53
53
  */
54
54
  async function runSVGO(svg, options = {}) {
55
+ // Code
56
+ const code = svg.toString();
55
57
  // Options
56
58
  const multipass = options.multipass !== false;
57
59
  // Plugins list
@@ -60,14 +62,21 @@ async function runSVGO(svg, options = {}) {
60
62
  plugins = options.plugins;
61
63
  }
62
64
  else {
63
- plugins = exports.defaultSVGOPlugins.concat(options.keepShapes ? [] : exports.shapeModifiyingSVGOPlugins, options.cleanupIDs !== false
65
+ // Check for animations: convertShapeToPath and removeHiddenElems plugins currently might ruin animations
66
+ let keepShapes = options.keepShapes;
67
+ if (keepShapes === void 0 &&
68
+ (code.indexOf('<animate') !== -1 || code.indexOf('<set') !== -1)) {
69
+ // Do not check animations: just assume they might break
70
+ keepShapes = true;
71
+ }
72
+ plugins = exports.defaultSVGOPlugins.concat(keepShapes ? [] : exports.shapeModifiyingSVGOPlugins, options.cleanupIDs !== false
64
73
  ? [
65
74
  {
66
75
  name: 'cleanupIDs',
67
76
  params: {
68
77
  prefix: typeof options.cleanupIDs === 'string'
69
78
  ? options.cleanupIDs
70
- : 'svg-',
79
+ : 'svgID',
71
80
  },
72
81
  },
73
82
  ]
@@ -79,7 +88,7 @@ async function runSVGO(svg, options = {}) {
79
88
  multipass,
80
89
  };
81
90
  // Load data (changing type because SVGO types do not include error ?????)
82
- const result = (0, svgo_1.optimize)(svg.toString(), pluginOptions);
91
+ const result = (0, svgo_1.optimize)(code, pluginOptions);
83
92
  if (typeof result.error === 'string') {
84
93
  throw new Error(result.error);
85
94
  }
@@ -44,16 +44,21 @@ var shapeModifiyingSVGOPlugins = [
44
44
  "reusePaths"
45
45
  ];
46
46
  async function runSVGO(svg, options = {}) {
47
+ const code = svg.toString();
47
48
  const multipass = options.multipass !== false;
48
49
  let plugins;
49
50
  if (options.plugins) {
50
51
  plugins = options.plugins;
51
52
  } else {
52
- plugins = defaultSVGOPlugins.concat(options.keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
53
+ let keepShapes = options.keepShapes;
54
+ if (keepShapes === void 0 && (code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1)) {
55
+ keepShapes = true;
56
+ }
57
+ plugins = defaultSVGOPlugins.concat(keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
53
58
  {
54
59
  name: "cleanupIDs",
55
60
  params: {
56
- prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svg-"
61
+ prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
57
62
  }
58
63
  }
59
64
  ] : []);
@@ -62,7 +67,7 @@ async function runSVGO(svg, options = {}) {
62
67
  plugins,
63
68
  multipass
64
69
  };
65
- const result = optimize(svg.toString(), pluginOptions);
70
+ const result = optimize(code, pluginOptions);
66
71
  if (typeof result.error === "string") {
67
72
  throw new Error(result.error);
68
73
  }
@@ -17,8 +17,6 @@ requiredParentTags.set(tags_1.filterTag, tags_1.filterChildTags);
17
17
  requiredParentTags.set(tags_1.defsTag, tags_1.tagsInsideDefs);
18
18
  // <stop> must be inside gradient
19
19
  requiredParentTags.set(tags_1.gradientTags, tags_1.gradientChildTags);
20
- // Animations must be inside shapes or filters
21
- requiredParentTags.set(tags_1.tagsBeforeAnimation, tags_1.animateTags);
22
20
  // <mpath> must be inside <animateMotion>
23
21
  requiredParentTags.set(new Set(['animateMotion']), tags_1.animateMotionChildTags);
24
22
  /**
@@ -3,7 +3,6 @@ import { parseSVG } from "../parse.mjs";
3
3
  import {
4
4
  allValidTags,
5
5
  animateMotionChildTags,
6
- animateTags,
7
6
  badTags,
8
7
  defsTag,
9
8
  feComponentTransferChildTag,
@@ -14,7 +13,6 @@ import {
14
13
  filterTag,
15
14
  gradientChildTags,
16
15
  gradientTags,
17
- tagsBeforeAnimation,
18
16
  tagsInsideDefs,
19
17
  unsupportedTags
20
18
  } from "../data/tags.mjs";
@@ -25,7 +23,6 @@ requiredParentTags.set(feLightningTags, feLightningChildTags);
25
23
  requiredParentTags.set(filterTag, filterChildTags);
26
24
  requiredParentTags.set(defsTag, tagsInsideDefs);
27
25
  requiredParentTags.set(gradientTags, gradientChildTags);
28
- requiredParentTags.set(tagsBeforeAnimation, animateTags);
29
26
  requiredParentTags.set(new Set(["animateMotion"]), animateMotionChildTags);
30
27
  async function checkBadTags(svg) {
31
28
  await parseSVG(svg, (item) => {
@@ -79,10 +79,6 @@ export declare const feMergeChildTags: Set<string>;
79
79
  * Tags that can be used only inside <defs>
80
80
  */
81
81
  export declare const tagsInsideDefs: Set<string>;
82
- /**
83
- * Parent tags for animations
84
- */
85
- export declare const tagsBeforeAnimation: Set<string>;
86
82
  /**
87
83
  * All supported tags
88
84
  */
@@ -4,7 +4,7 @@
4
4
  * Icons cannot have anything that requires external resources, anything that renders inconsistently.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.allValidTags = exports.tagsBeforeAnimation = exports.tagsInsideDefs = exports.feMergeChildTags = exports.feLightningChildTags = exports.feComponentTransferChildTag = exports.filterChildTags = exports.feLightningTags = exports.filterTag = exports.patternTag = exports.gradientChildTags = exports.gradientTags = exports.animateMotionChildTags = exports.animateTags = exports.markerTag = exports.groupTag = exports.useTag = exports.shapeTags = exports.maskAndSymbolTags = exports.defsTag = exports.styleTag = exports.unsupportedTags = exports.badTags = void 0;
7
+ exports.allValidTags = exports.tagsInsideDefs = exports.feMergeChildTags = exports.feLightningChildTags = exports.feComponentTransferChildTag = exports.filterChildTags = exports.feLightningTags = exports.filterTag = exports.patternTag = exports.gradientChildTags = exports.gradientTags = exports.animateMotionChildTags = exports.animateTags = exports.markerTag = exports.groupTag = exports.useTag = exports.shapeTags = exports.maskAndSymbolTags = exports.defsTag = exports.styleTag = exports.unsupportedTags = exports.badTags = void 0;
8
8
  /**
9
9
  * Bad tags
10
10
  *
@@ -153,14 +153,6 @@ exports.tagsInsideDefs = new Set([
153
153
  ...exports.patternTag,
154
154
  ...exports.markerTag,
155
155
  ]);
156
- /**
157
- * Parent tags for animations
158
- */
159
- exports.tagsBeforeAnimation = new Set([
160
- ...exports.shapeTags,
161
- ...exports.filterChildTags,
162
- ...exports.feComponentTransferChildTag,
163
- ]);
164
156
  /**
165
157
  * All supported tags
166
158
  */
@@ -85,11 +85,6 @@ var tagsInsideDefs = new Set([
85
85
  ...patternTag,
86
86
  ...markerTag
87
87
  ]);
88
- var tagsBeforeAnimation = new Set([
89
- ...shapeTags,
90
- ...filterChildTags,
91
- ...feComponentTransferChildTag
92
- ]);
93
88
  var allValidTags = new Set([
94
89
  ...styleTag,
95
90
  ...defsTag,
@@ -129,7 +124,6 @@ export {
129
124
  patternTag,
130
125
  shapeTags,
131
126
  styleTag,
132
- tagsBeforeAnimation,
133
127
  tagsInsideDefs,
134
128
  unsupportedTags,
135
129
  useTag
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.2",
5
+ "version": "2.0.6",
6
6
  "license": "MIT",
7
7
  "bugs": "https://github.com/iconify/tools/issues",
8
8
  "homepage": "https://github.com/iconify/tools",
@@ -22,16 +22,16 @@
22
22
  "test": "npm run test:jest && npm run test:jasmine"
23
23
  },
24
24
  "dependencies": {
25
- "@iconify/utils": "^1.0.20",
25
+ "@iconify/utils": "^1.0.21",
26
26
  "@types/cheerio": "^0.22.30",
27
27
  "@types/node-fetch": "^2.5.12",
28
28
  "@types/svgo": "^2.6.0",
29
29
  "@types/tar": "^6.1.0",
30
30
  "cheerio": "^1.0.0-rc.10",
31
31
  "extract-zip": "^2.0.1",
32
- "node-fetch": "^2.6.6",
32
+ "node-fetch": "^2.6.7",
33
33
  "pathe": "^0.2.0",
34
- "svgo": "^2.7.0",
34
+ "svgo": "^2.8.0",
35
35
  "tar": "^6.1.11"
36
36
  },
37
37
  "exports": {