@iconify/tools 5.0.11 → 5.0.12

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.
@@ -1,6 +1,6 @@
1
1
  import { scanDirectory } from "../../misc/scan.js";
2
- import { promises } from "fs";
3
- import { createHash } from "crypto";
2
+ import { promises } from "node:fs";
3
+ import { createHash } from "node:crypto";
4
4
 
5
5
  const cacheVersion = 1;
6
6
  const storedFiles = Object.create(null);
@@ -1,6 +1,6 @@
1
1
  import { axiosConfig, fetchCallbacks } from "./config.js";
2
2
  import { getFetch } from "./fetch.js";
3
- import { writeFile } from "fs/promises";
3
+ import { writeFile } from "node:fs/promises";
4
4
 
5
5
  /**
6
6
  * Download file
@@ -1,5 +1,4 @@
1
1
  import { execAsync } from "../../misc/exec.js";
2
- import "../../index.js";
3
2
 
4
3
  /**
5
4
  * Reset Git repo contents
@@ -2,7 +2,7 @@ import { prepareDirectoryForExport } from "../../export/helpers/prepare.js";
2
2
  import { getGitHubRepoHash } from "./hash.js";
3
3
  import { downloadFile } from "../api/download.js";
4
4
  import { unzip } from "../helpers/unzip.js";
5
- import { promises } from "fs";
5
+ import { promises } from "node:fs";
6
6
 
7
7
  /**
8
8
  * Find matching directories
@@ -3,19 +3,19 @@ import { downloadFile } from "../api/download.js";
3
3
  import { unzip } from "../helpers/unzip.js";
4
4
  import { defaultGitLabBaseURI } from "./types.js";
5
5
  import { getGitLabRepoHash } from "./hash.js";
6
- import { promises } from "fs";
6
+ import fs from "node:fs/promises";
7
7
 
8
8
  /**
9
9
  * Find matching directories
10
10
  */
11
11
  async function findMatchingDirs(rootDir, hash) {
12
12
  const matches = [];
13
- const files = await promises.readdir(rootDir);
13
+ const files = await fs.readdir(rootDir);
14
14
  for (let i = 0; i < files.length; i++) {
15
15
  const file = files[i];
16
16
  const lastChunk = file.split("-").pop();
17
17
  if (lastChunk.length < 4 || lastChunk !== hash.slice(0, lastChunk.length)) continue;
18
- if ((await promises.stat(rootDir + "/" + file)).isDirectory()) matches.push(file);
18
+ if ((await fs.stat(rootDir + "/" + file)).isDirectory()) matches.push(file);
19
19
  }
20
20
  return matches;
21
21
  }
@@ -30,21 +30,21 @@ async function downloadGitLabRepo(options) {
30
30
  const archiveTarget = rootDir + "/" + hash + ".zip";
31
31
  let exists = false;
32
32
  try {
33
- exists = (await promises.stat(archiveTarget)).isFile();
33
+ exists = (await fs.stat(archiveTarget)).isFile();
34
34
  } catch {}
35
35
  if (!exists) await downloadFile({
36
36
  uri: `${options.uri || defaultGitLabBaseURI}/${options.project}/repository/archive.zip?sha=${hash}`,
37
37
  headers: { Authorization: "token " + options.token }
38
38
  }, archiveTarget);
39
- const files = await promises.readdir(rootDir);
39
+ const files = await fs.readdir(rootDir);
40
40
  const hashSearch = "-" + hash;
41
41
  for (let i = 0; i < files.length; i++) {
42
42
  if (files[i] === hash + ".zip") continue;
43
43
  const filename = rootDir + "/" + files[i];
44
- const stat = await promises.lstat(filename);
44
+ const stat = await fs.lstat(filename);
45
45
  const isDir = stat.isDirectory();
46
46
  if (stat.isSymbolicLink() || isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) try {
47
- await promises.rm(filename, {
47
+ await fs.rm(filename, {
48
48
  force: true,
49
49
  recursive: true
50
50
  });
@@ -1,5 +1,5 @@
1
- import { unpackTar } from "modern-tar/fs";
2
1
  import { createReadStream } from "node:fs";
2
+ import { unpackTar } from "modern-tar/fs";
3
3
  import { createGunzip } from "node:zlib";
4
4
  import { pipeline } from "node:stream/promises";
5
5
 
@@ -1,15 +1,14 @@
1
1
  import { ExportTargetOptions } from "../../export/helpers/prepare.js";
2
2
  import { DocumentNotModified } from "../types/modified.js";
3
3
  import { DownloadSourceMixin } from "../types/sources.js";
4
+ import { NPMPackageOptions } from "./types.js";
4
5
  interface IfModifiedSinceOption {
5
6
  ifModifiedSince: string | true | DownloadNPMPackageResult;
6
7
  }
7
8
  /**
8
9
  * Options for downloadNPMPackage()
9
10
  */
10
- interface DownloadNPMPackageOptions extends ExportTargetOptions, Partial<IfModifiedSinceOption> {
11
- package: string;
12
- tag?: string;
11
+ interface DownloadNPMPackageOptions extends NPMPackageOptions, ExportTargetOptions, Partial<IfModifiedSinceOption> {
13
12
  log?: boolean;
14
13
  }
15
14
  /**
@@ -2,7 +2,7 @@ import { normalizeDir, prepareDirectoryForExport } from "../../export/helpers/pr
2
2
  import { downloadFile } from "../api/download.js";
3
3
  import { untar } from "../helpers/untar.js";
4
4
  import { getNPMVersion, getPackageVersion } from "./version.js";
5
- import { promises } from "fs";
5
+ import fs from "node:fs/promises";
6
6
 
7
7
  async function downloadNPMPackage(options) {
8
8
  const rootDir = options.target = normalizeDir(options.target);
@@ -25,7 +25,7 @@ async function downloadNPMPackage(options) {
25
25
  await prepareDirectoryForExport(options);
26
26
  let archiveExists = false;
27
27
  try {
28
- archiveExists = (await promises.stat(archiveTarget)).isFile();
28
+ archiveExists = (await fs.stat(archiveTarget)).isFile();
29
29
  } catch {}
30
30
  if (!archiveExists) {
31
31
  if (options.log) console.log(`Downloading ${archiveURL}`);
@@ -4,5 +4,6 @@
4
4
  interface NPMPackageOptions {
5
5
  package: string;
6
6
  tag?: string;
7
+ fetch?: boolean;
7
8
  }
8
9
  export { NPMPackageOptions };
@@ -1,23 +1,29 @@
1
+ import { getFetch } from "../api/fetch.js";
1
2
  import { execAsync } from "../../misc/exec.js";
2
- import { promises } from "fs";
3
+ import fs from "node:fs/promises";
3
4
 
4
5
  /**
5
6
  * Get version of package from NPM registry
6
7
  */
7
8
  async function getNPMVersion(options) {
8
9
  const tag = options.tag || "latest";
9
- const result = await execAsync(`npm view ${options.package}@${tag} --json`, { maxBuffer: 1024 * 1024 * 8 });
10
- const data = JSON.parse(result.stdout);
10
+ const packageName = options.package;
11
+ let data;
12
+ if (options.fetch) data = await getFetch()(`https://registry.npmjs.org/${packageName}/${tag}`).then((res) => res.json());
13
+ else {
14
+ const result = await execAsync(`npm view ${packageName}@${tag} --json`, { maxBuffer: 1024 * 1024 * 8 });
15
+ data = JSON.parse(result.stdout);
16
+ }
11
17
  return {
12
18
  version: data.version,
13
- file: data.dist?.tarball
19
+ file: data.dist?.tarball ?? `https://registry.npmjs.org/${packageName}/-/${packageName.split("/").pop()}-${data.version}.tgz`
14
20
  };
15
21
  }
16
22
  /**
17
23
  * Get version of package from filename
18
24
  */
19
25
  async function getPackageVersion(target) {
20
- return JSON.parse(await promises.readFile(target + "/package.json", "utf8")).version;
26
+ return JSON.parse(await fs.readFile(target + "/package.json", "utf8")).version;
21
27
  }
22
28
 
23
29
  export { getNPMVersion, getPackageVersion };
@@ -1,5 +1,5 @@
1
1
  import { prepareDirectoryForExport } from "./helpers/prepare.js";
2
- import { promises } from "fs";
2
+ import fs from "node:fs/promises";
3
3
 
4
4
  /**
5
5
  * Export icon set to directory
@@ -16,7 +16,7 @@ async function exportToDirectory(iconSet, options) {
16
16
  const store = async (name, target) => {
17
17
  const svg = iconSet.toString(name, customisations);
18
18
  if (!svg) return;
19
- await promises.writeFile(target, svg, "utf8");
19
+ await fs.writeFile(target, svg, "utf8");
20
20
  storedFiles.add(target);
21
21
  if (options.log) console.log(`Saved ${target} (${svg.length} bytes)`);
22
22
  };
@@ -1,5 +1,5 @@
1
1
  import { writeJSONFile } from "../../misc/write-json.js";
2
- import { promises } from "fs";
2
+ import fs from "node:fs/promises";
3
3
 
4
4
  /**
5
5
  * Write custom files
@@ -10,11 +10,11 @@ async function exportCustomFiles(dir, options, result) {
10
10
  const content = customFiles[filename];
11
11
  if (content === null) {
12
12
  try {
13
- await promises.unlink(dir + "/" + filename);
13
+ await fs.unlink(dir + "/" + filename);
14
14
  } catch {}
15
15
  continue;
16
16
  }
17
- if (typeof content === "string") await promises.writeFile(dir + "/" + filename, content, "utf8");
17
+ if (typeof content === "string") await fs.writeFile(dir + "/" + filename, content, "utf8");
18
18
  else if (typeof content === "object") await writeJSONFile(dir + "/" + filename, content);
19
19
  result?.add(filename);
20
20
  }
@@ -2,7 +2,7 @@ import { prepareDirectoryForExport } from "./helpers/prepare.js";
2
2
  import { writeJSONFile } from "../misc/write-json.js";
3
3
  import { exportCustomFiles } from "./helpers/custom-files.js";
4
4
  import { getTypesVersion } from "./helpers/types-version.js";
5
- import { promises } from "fs";
5
+ import fs from "node:fs/promises";
6
6
 
7
7
  /**
8
8
  * Content for .d.ts files
@@ -25,13 +25,13 @@ async function exportIconPackage(iconSet, options) {
25
25
  const data = iconSet.resolve(name, false);
26
26
  if (!data) return;
27
27
  const typesFilename = name + ".d.ts";
28
- await promises.writeFile(`${dir}/${typesFilename}`, typesContent, "utf8");
28
+ await fs.writeFile(`${dir}/${typesFilename}`, typesContent, "utf8");
29
29
  files.add(typesFilename);
30
30
  let content = `const data = ` + JSON.stringify(data, null, " ") + ";\n";
31
31
  if (!esm) content += "exports.__esModule = true;\nexports.default = data;\n";
32
32
  else content += "export default data;\n";
33
33
  const contentFilename = name + ".js";
34
- await promises.writeFile(`${dir}/${contentFilename}`, content, "utf8");
34
+ await fs.writeFile(`${dir}/${contentFilename}`, content, "utf8");
35
35
  files.add(contentFilename);
36
36
  });
37
37
  await exportCustomFiles(dir, options, files);
@@ -3,7 +3,7 @@ import { writeJSONFile } from "../misc/write-json.js";
3
3
  import { exportCustomFiles } from "./helpers/custom-files.js";
4
4
  import { getTypesVersion } from "./helpers/types-version.js";
5
5
  import { defaultIconDimensions } from "@iconify/utils/lib/icon/defaults";
6
- import { promises } from "fs";
6
+ import fs from "node:fs/promises";
7
7
 
8
8
  const exportTypes = {
9
9
  icons: "IconifyJSON",
@@ -105,10 +105,10 @@ async function exportJSONPackage(iconSet, options) {
105
105
  files.add(jsonFilename);
106
106
  }
107
107
  const cjsContent = cjsImports.concat([""], cjsExports);
108
- await promises.writeFile(dir + "/index.js", cjsContent.join("\n") + "\n", "utf8");
108
+ await fs.writeFile(dir + "/index.js", cjsContent.join("\n") + "\n", "utf8");
109
109
  files.add("index.js");
110
110
  const mjsContent = mjsImports.concat([""], mjsConsts, [`export { ${mjsExports.join(", ")} };`]);
111
- await promises.writeFile(dir + "/index.mjs", mjsContent.join("\n") + "\n", "utf8");
111
+ await fs.writeFile(dir + "/index.mjs", mjsContent.join("\n") + "\n", "utf8");
112
112
  files.add("index.mjs");
113
113
  const usedTypes = Object.values(exportTypes);
114
114
  const typesData = [
@@ -117,7 +117,7 @@ async function exportJSONPackage(iconSet, options) {
117
117
  `export { ${usedTypes.join(", ")} };`,
118
118
  ""
119
119
  ].concat(dtsContent);
120
- await promises.writeFile(dir + "/index.d.ts", typesData.join("\n") + "\n", "utf8");
120
+ await fs.writeFile(dir + "/index.d.ts", typesData.join("\n") + "\n", "utf8");
121
121
  files.add("index.d.ts");
122
122
  await exportCustomFiles(dir, options, files);
123
123
  options.customisePackage?.(packageJSON);
@@ -3,7 +3,8 @@ import { cleanupSVG } from "../svg/cleanup.js";
3
3
  import { blankIconSet } from "../icon-set/index.js";
4
4
  import { scanDirectory, scanDirectorySync } from "../misc/scan.js";
5
5
  import { cleanupIconKeyword } from "../misc/keyword.js";
6
- import { promises, readFileSync } from "fs";
6
+ import { readFileSync } from "node:fs";
7
+ import { readFile } from "node:fs/promises";
7
8
 
8
9
  function importDir(iconSet, options, getKeyword, files, readFile, done) {
9
10
  let i = 0;
@@ -63,7 +64,7 @@ function importDirectory(path, options = {}) {
63
64
  else done(result);
64
65
  } else done(params[1]);
65
66
  }, files, (filename, done) => {
66
- promises.readFile(filename, "utf8").then(done).catch(reject);
67
+ readFile(filename, "utf8").then(done).catch(reject);
67
68
  }, fulfill);
68
69
  } catch (err) {
69
70
  reject(err);
@@ -1,6 +1,6 @@
1
1
  import { scanDirectory } from "./scan.js";
2
2
  import { normalizeDir } from "../export/helpers/prepare.js";
3
- import { promises } from "fs";
3
+ import { readFile } from "node:fs/promises";
4
4
 
5
5
  /**
6
6
  * Extensions that are treated as text
@@ -37,13 +37,13 @@ async function compareDirectories(dir1, dir2, options) {
37
37
  if (!files2.includes(file)) return false;
38
38
  const ext = file.split(".").pop().toLowerCase();
39
39
  if (!textExtensions.has(ext)) {
40
- const content1 = await promises.readFile(dir1 + "/" + file);
41
- const content2 = await promises.readFile(dir2 + "/" + file);
40
+ const content1 = await readFile(dir1 + "/" + file);
41
+ const content2 = await readFile(dir2 + "/" + file);
42
42
  if (Buffer.compare(content1, content2) !== 0) return false;
43
43
  continue;
44
44
  }
45
- let content1 = await promises.readFile(dir1 + "/" + file, "utf8");
46
- let content2 = await promises.readFile(dir2 + "/" + file, "utf8");
45
+ let content1 = await readFile(dir1 + "/" + file, "utf8");
46
+ let content2 = await readFile(dir2 + "/" + file, "utf8");
47
47
  if (content1 === content2) continue;
48
48
  if (ignoreNewLine) {
49
49
  content1 = content1.replace(/\s+\n/g, "\n").trimEnd();
@@ -1,4 +1,4 @@
1
- import { ExecOptions } from "child_process";
1
+ import { ExecOptions } from "node:child_process";
2
2
  interface ExecResult {
3
3
  stdout: string;
4
4
  stderr: string;
package/lib/misc/exec.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolve } from "pathe";
2
- import { exec } from "child_process";
2
+ import { exec } from "node:child_process";
3
3
 
4
4
  /**
5
5
  * Exec as Promise
@@ -1,4 +1,4 @@
1
- import { Stats } from "fs";
1
+ import { Stats } from "node:fs";
2
2
  /**
3
3
  * Callback
4
4
  *
package/lib/misc/scan.js CHANGED
@@ -1,4 +1,4 @@
1
- import { promises, readdirSync, statSync } from "fs";
1
+ import { promises, readdirSync, statSync } from "node:fs";
2
2
 
3
3
  /**
4
4
  * Reusable functions
@@ -1,10 +1,10 @@
1
- import { promises } from "fs";
1
+ import { writeFile } from "node:fs/promises";
2
2
 
3
3
  /**
4
4
  * Write JSON file
5
5
  */
6
6
  async function writeJSONFile(filename, data) {
7
- return promises.writeFile(filename, JSON.stringify(data, null, " ") + "\n");
7
+ return writeFile(filename, JSON.stringify(data, null, " ") + "\n");
8
8
  }
9
9
 
10
10
  export { writeJSONFile };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
5
5
  "author": "Vjacheslav Trushkin",
6
- "version": "5.0.11",
6
+ "version": "5.0.12",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/iconify/tools/issues",
9
9
  "homepage": "https://github.com/iconify/tools",
@@ -14,10 +14,10 @@
14
14
  "module": "./lib/index.js",
15
15
  "types": "./lib/index.d.ts",
16
16
  "dependencies": {
17
- "@cyberalien/svg-utils": "^1.2.8",
17
+ "@cyberalien/svg-utils": "^1.2.15",
18
18
  "@iconify/types": "^2.0.0",
19
- "@iconify/utils": "^3.1.0",
20
- "fflate": "^0.8.2",
19
+ "@iconify/utils": "^3.1.3",
20
+ "fflate": "^0.8.3",
21
21
  "modern-tar": "^0.7.6",
22
22
  "pathe": "^2.0.3",
23
23
  "svgo": "^4.0.1"
@@ -26,19 +26,19 @@
26
26
  "@eslint/eslintrc": "^3.3.5",
27
27
  "@eslint/js": "^9.39.4",
28
28
  "@types/jest": "^30.0.0",
29
- "@types/node": "^24.12.0",
30
- "@typescript-eslint/eslint-plugin": "^8.57.2",
31
- "@typescript-eslint/parser": "^8.57.2",
29
+ "@types/node": "^24.12.4",
30
+ "@typescript-eslint/eslint-plugin": "^8.59.4",
31
+ "@typescript-eslint/parser": "^8.59.4",
32
32
  "cross-env": "^10.1.0",
33
33
  "eslint": "^9.39.4",
34
34
  "eslint-config-prettier": "^10.1.8",
35
35
  "eslint-plugin-prettier": "^5.5.5",
36
36
  "globals": "^16.5.0",
37
- "prettier": "^3.8.1",
37
+ "prettier": "^3.8.3",
38
38
  "rimraf": "^6.1.3",
39
39
  "tsdown": "^0.20.3",
40
40
  "typescript": "^5.9.3",
41
- "vitest": "^4.1.2"
41
+ "vitest": "^4.1.6"
42
42
  },
43
43
  "exports": {
44
44
  "./*": "./*",