@iconify/tools 2.0.3 → 2.0.7

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.
@@ -0,0 +1,5 @@
1
+ import type { ExportTargetOptions } from '../../export/helpers/prepare';
2
+ /**
3
+ * Get current branch from cloned git repo
4
+ */
5
+ export declare function getGitRepoBranch(options: ExportTargetOptions, checkout?: string): Promise<string>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGitRepoBranch = void 0;
4
+ const exec_1 = require("../../misc/exec");
5
+ /**
6
+ * Get current branch from cloned git repo
7
+ */
8
+ async function getGitRepoBranch(options, checkout) {
9
+ const result = await (0, exec_1.execAsync)('git branch --show-current', {
10
+ cwd: options.target,
11
+ });
12
+ const branch = result.stdout.trim();
13
+ if (typeof checkout === 'string' && branch !== checkout) {
14
+ // Checkout correct branch
15
+ await (0, exec_1.execAsync)(`git checkout ${checkout}`, {
16
+ cwd: options.target,
17
+ });
18
+ return await getGitRepoBranch(options);
19
+ }
20
+ return branch;
21
+ }
22
+ exports.getGitRepoBranch = getGitRepoBranch;
@@ -0,0 +1,18 @@
1
+ // src/download/git/branch.ts
2
+ import { execAsync } from "../../misc/exec.mjs";
3
+ async function getGitRepoBranch(options, checkout) {
4
+ const result = await execAsync("git branch --show-current", {
5
+ cwd: options.target
6
+ });
7
+ const branch = result.stdout.trim();
8
+ if (typeof checkout === "string" && branch !== checkout) {
9
+ await execAsync(`git checkout ${checkout}`, {
10
+ cwd: options.target
11
+ });
12
+ return await getGitRepoBranch(options);
13
+ }
14
+ return branch;
15
+ }
16
+ export {
17
+ getGitRepoBranch
18
+ };
@@ -1,7 +1,8 @@
1
1
  import { ExportTargetOptions } from '../../export/helpers/prepare';
2
2
  import type { DocumentNotModified } from '../types/modified';
3
+ import type { DownloadSourceMixin } from '../types/sources';
3
4
  interface IfModifiedSinceOption {
4
- ifModifiedSince: string | true;
5
+ ifModifiedSince: string | true | DownloadGitRepoResult;
5
6
  }
6
7
  /**
7
8
  * Options for downloadGitRepo()
@@ -14,8 +15,8 @@ export interface DownloadGitRepoOptions extends ExportTargetOptions, Partial<IfM
14
15
  /**
15
16
  * Result
16
17
  */
17
- export interface DownloadGitRepoResult {
18
- target: string;
18
+ export interface DownloadGitRepoResult extends DownloadSourceMixin<'git'> {
19
+ contentsDir: string;
19
20
  hash: string;
20
21
  }
21
22
  /**
@@ -4,12 +4,14 @@ exports.downloadGitRepo = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const prepare_1 = require("../../export/helpers/prepare");
6
6
  const exec_1 = require("../../misc/exec");
7
+ const branch_1 = require("./branch");
7
8
  const hash_1 = require("./hash");
8
9
  async function downloadGitRepo(options) {
9
10
  const { remote, branch } = options;
10
11
  // Check for last commit
11
12
  const hasHashInTarget = options.target.indexOf('{hash}') !== -1;
12
- if (options.ifModifiedSince || hasHashInTarget) {
13
+ const ifModifiedSince = options.ifModifiedSince;
14
+ if (ifModifiedSince || hasHashInTarget) {
13
15
  // Get actual hash
14
16
  const result = await (0, exec_1.execAsync)(`git ls-remote ${remote} --branch ${branch}`);
15
17
  const parts = result.stdout.split(/\s/);
@@ -17,19 +19,26 @@ async function downloadGitRepo(options) {
17
19
  if (hasHashInTarget) {
18
20
  options.target = options.target.replace('{hash}', latestHash);
19
21
  }
20
- if (options.ifModifiedSince) {
21
- try {
22
+ try {
23
+ // Make sure correct branch is checked out. This will throw error if branch is not available
24
+ await (0, branch_1.getGitRepoBranch)(options, branch);
25
+ if (ifModifiedSince) {
22
26
  // Get expected hash
23
- const expectedHash = options.ifModifiedSince === true
27
+ const expectedHash = ifModifiedSince === true
24
28
  ? await (0, hash_1.getGitRepoHash)(options)
25
- : options.ifModifiedSince;
29
+ : typeof ifModifiedSince === 'string'
30
+ ? ifModifiedSince
31
+ : ifModifiedSince.downloadType === 'git'
32
+ ? ifModifiedSince.hash
33
+ : null;
26
34
  if (latestHash === expectedHash) {
27
35
  return 'not_modified';
28
36
  }
29
37
  }
30
- catch (err) {
31
- //
32
- }
38
+ }
39
+ catch (err) {
40
+ // Cleanup on error
41
+ options.cleanup = true;
33
42
  }
34
43
  }
35
44
  // Prepare target directory
@@ -42,10 +51,12 @@ async function downloadGitRepo(options) {
42
51
  }
43
52
  await (0, exec_1.execAsync)(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
44
53
  }
45
- // Get latest hash
54
+ // Get latest hash and make sure correct branch is available
46
55
  const hash = await (0, hash_1.getGitRepoHash)(options);
56
+ await (0, branch_1.getGitRepoBranch)(options, branch);
47
57
  return {
48
- target,
58
+ downloadType: 'git',
59
+ contentsDir: target,
49
60
  hash,
50
61
  };
51
62
  }
@@ -4,25 +4,29 @@ import {
4
4
  prepareDirectoryForExport
5
5
  } from "../../export/helpers/prepare.mjs";
6
6
  import { execAsync } from "../../misc/exec.mjs";
7
+ import { getGitRepoBranch } from "./branch.mjs";
7
8
  import { getGitRepoHash } from "./hash.mjs";
8
9
  async function downloadGitRepo(options) {
9
10
  const { remote, branch } = options;
10
11
  const hasHashInTarget = options.target.indexOf("{hash}") !== -1;
11
- if (options.ifModifiedSince || hasHashInTarget) {
12
+ const ifModifiedSince = options.ifModifiedSince;
13
+ if (ifModifiedSince || hasHashInTarget) {
12
14
  const result = await execAsync(`git ls-remote ${remote} --branch ${branch}`);
13
15
  const parts = result.stdout.split(/\s/);
14
16
  const latestHash = parts.shift();
15
17
  if (hasHashInTarget) {
16
18
  options.target = options.target.replace("{hash}", latestHash);
17
19
  }
18
- if (options.ifModifiedSince) {
19
- try {
20
- const expectedHash = options.ifModifiedSince === true ? await getGitRepoHash(options) : options.ifModifiedSince;
20
+ try {
21
+ await getGitRepoBranch(options, branch);
22
+ if (ifModifiedSince) {
23
+ const expectedHash = ifModifiedSince === true ? await getGitRepoHash(options) : typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "git" ? ifModifiedSince.hash : null;
21
24
  if (latestHash === expectedHash) {
22
25
  return "not_modified";
23
26
  }
24
- } catch (err) {
25
27
  }
28
+ } catch (err) {
29
+ options.cleanup = true;
26
30
  }
27
31
  }
28
32
  const target = options.target = await prepareDirectoryForExport(options);
@@ -34,8 +38,10 @@ async function downloadGitRepo(options) {
34
38
  await execAsync(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
35
39
  }
36
40
  const hash = await getGitRepoHash(options);
41
+ await getGitRepoBranch(options, branch);
37
42
  return {
38
- target,
43
+ downloadType: "git",
44
+ contentsDir: target,
39
45
  hash
40
46
  };
41
47
  }
@@ -1,8 +1,9 @@
1
1
  import { ExportTargetOptions } from '../../export/helpers/prepare';
2
2
  import type { DocumentNotModified } from '../types/modified';
3
3
  import type { GitHubAPIOptions } from './types';
4
+ import type { DownloadSourceMixin } from '../types/sources';
4
5
  interface IfModifiedSinceOption {
5
- ifModifiedSince: string;
6
+ ifModifiedSince: string | DownloadGitHubRepoResult;
6
7
  }
7
8
  /**
8
9
  * Options for downloadGitRepo()
@@ -15,9 +16,9 @@ export interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAP
15
16
  /**
16
17
  * Result
17
18
  */
18
- export interface DownloadGitHubRepoResult {
19
+ export interface DownloadGitHubRepoResult extends DownloadSourceMixin<'github'> {
19
20
  rootDir: string;
20
- actualDir: string;
21
+ contentsDir: string;
21
22
  hash: string;
22
23
  }
23
24
  /**
@@ -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
  }
@@ -29,8 +29,16 @@ async function findMatchingDirs(rootDir, hash) {
29
29
  async function downloadGitHubRepo(options) {
30
30
  // Check for last commit
31
31
  const hash = await (0, hash_1.getGitHubRepoHash)(options);
32
- if (options.ifModifiedSince && hash === options.ifModifiedSince) {
33
- return 'not_modified';
32
+ const ifModifiedSince = options.ifModifiedSince;
33
+ if (ifModifiedSince) {
34
+ const expectedHash = typeof ifModifiedSince === 'string'
35
+ ? ifModifiedSince
36
+ : ifModifiedSince.downloadType === 'github'
37
+ ? ifModifiedSince.hash
38
+ : null;
39
+ if (hash === expectedHash) {
40
+ return 'not_modified';
41
+ }
34
42
  }
35
43
  // Replace hash in target
36
44
  options.target = options.target.replace('{hash}', hash);
@@ -41,7 +49,7 @@ async function downloadGitHubRepo(options) {
41
49
  // Check if archive exists
42
50
  let exists = false;
43
51
  try {
44
- const stat = await fs_1.promises.lstat(archiveTarget);
52
+ const stat = await fs_1.promises.stat(archiveTarget);
45
53
  exists = stat.isFile();
46
54
  }
47
55
  catch (err) {
@@ -71,8 +79,10 @@ async function downloadGitHubRepo(options) {
71
79
  const stat = await fs_1.promises.lstat(filename);
72
80
  const isDir = stat.isDirectory();
73
81
  if (
74
- // Remove if directory matches hash to avoid errors extracting zip
75
- (isDir && filename.slice(0 - hashSearch.length) === hashSearch) ||
82
+ // Remove symbolic links
83
+ stat.isSymbolicLink() ||
84
+ // Remove if directory matches hash to avoid errors extracting zip
85
+ (isDir && filename.slice(0 - hashSearch.length) === hashSearch) ||
76
86
  // Remove if directory and cleanupOldDirectories is not disabled
77
87
  (isDir && options.cleanupOldDirectories !== false) ||
78
88
  // Remove if file and cleanupOldFiles is enabled
@@ -95,10 +105,11 @@ async function downloadGitHubRepo(options) {
95
105
  if (matchingDirs.length !== 1) {
96
106
  throw new Error(`Error unpacking ${hash}.zip`);
97
107
  }
98
- const actualDir = rootDir + '/' + matchingDirs[0];
108
+ const contentsDir = rootDir + '/' + matchingDirs[0];
99
109
  return {
110
+ downloadType: 'github',
100
111
  rootDir,
101
- actualDir,
112
+ contentsDir,
102
113
  hash,
103
114
  };
104
115
  }
@@ -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
  }
@@ -24,15 +24,19 @@ async function findMatchingDirs(rootDir, hash) {
24
24
  }
25
25
  async function downloadGitHubRepo(options) {
26
26
  const hash = await getGitHubRepoHash(options);
27
- if (options.ifModifiedSince && hash === options.ifModifiedSince) {
28
- return "not_modified";
27
+ const ifModifiedSince = options.ifModifiedSince;
28
+ if (ifModifiedSince) {
29
+ const expectedHash = typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "github" ? ifModifiedSince.hash : null;
30
+ if (hash === expectedHash) {
31
+ return "not_modified";
32
+ }
29
33
  }
30
34
  options.target = options.target.replace("{hash}", hash);
31
35
  const rootDir = options.target = await prepareDirectoryForExport(options);
32
36
  const archiveTarget = rootDir + "/" + hash + ".zip";
33
37
  let exists = false;
34
38
  try {
35
- const stat = await fs.lstat(archiveTarget);
39
+ const stat = await fs.stat(archiveTarget);
36
40
  exists = stat.isFile();
37
41
  } catch (err) {
38
42
  }
@@ -56,7 +60,7 @@ async function downloadGitHubRepo(options) {
56
60
  const filename = rootDir + "/" + files[i];
57
61
  const stat = await fs.lstat(filename);
58
62
  const isDir = stat.isDirectory();
59
- if (isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
63
+ if (stat.isSymbolicLink() || isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
60
64
  try {
61
65
  await fs.rm(filename, {
62
66
  force: true,
@@ -71,10 +75,11 @@ async function downloadGitHubRepo(options) {
71
75
  if (matchingDirs.length !== 1) {
72
76
  throw new Error(`Error unpacking ${hash}.zip`);
73
77
  }
74
- const actualDir = rootDir + "/" + matchingDirs[0];
78
+ const contentsDir = rootDir + "/" + matchingDirs[0];
75
79
  return {
80
+ downloadType: "github",
76
81
  rootDir,
77
- actualDir,
82
+ contentsDir,
78
83
  hash
79
84
  };
80
85
  }
@@ -0,0 +1,20 @@
1
+ import { DownloadGitHubRepoOptions, DownloadGitHubRepoResult } from './github';
2
+ import { DownloadGitRepoOptions, DownloadGitRepoResult } from './git';
3
+ import { DownloadNPMPackageOptions, DownloadNPMPackageResult } from './npm';
4
+ import type { DocumentNotModified } from './types/modified';
5
+ import type { DownloadSourceMixin, DownloadSourceType } from './types/sources';
6
+ /**
7
+ * Add downloadType to options
8
+ */
9
+ declare type ExtendedDownloadGitRepoOptions = DownloadGitRepoOptions & DownloadSourceMixin<'git'>;
10
+ declare type ExtendedDownloadGitHubRepoOptions = DownloadGitHubRepoOptions & DownloadSourceMixin<'github'>;
11
+ declare type ExtendedDownloadNPMPackageOptions = DownloadNPMPackageOptions & DownloadSourceMixin<'npm'>;
12
+ export declare type DownloadOptions<T extends DownloadSourceType> = T extends 'git' ? ExtendedDownloadGitRepoOptions : T extends 'github' ? ExtendedDownloadGitHubRepoOptions : T extends 'npm' ? ExtendedDownloadNPMPackageOptions : never;
13
+ /**
14
+ * Result type from downloadType
15
+ */
16
+ export declare type DownloadResult<T extends DownloadSourceType> = T extends 'git' ? DownloadGitRepoResult : T extends 'github' ? DownloadGitHubRepoResult : T extends 'npm' ? DownloadNPMPackageResult : never;
17
+ export declare function downloadPackage<T extends 'git'>(options: DownloadOptions<T>): Promise<DocumentNotModified | DownloadResult<T>>;
18
+ export declare function downloadPackage<T extends 'github'>(options: DownloadOptions<T>): Promise<DocumentNotModified | DownloadResult<T>>;
19
+ export declare function downloadPackage<T extends 'npm'>(options: DownloadOptions<T>): Promise<DocumentNotModified | DownloadResult<T>>;
20
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadPackage = void 0;
4
+ const github_1 = require("./github");
5
+ const git_1 = require("./git");
6
+ const npm_1 = require("./npm");
7
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
+ function assertNever(v) {
9
+ //
10
+ }
11
+ function downloadPackage(options) {
12
+ const type = options.downloadType;
13
+ switch (type) {
14
+ case 'git': {
15
+ return (0, git_1.downloadGitRepo)(options);
16
+ }
17
+ case 'github':
18
+ return (0, github_1.downloadGitHubRepo)(options);
19
+ case 'npm':
20
+ return (0, npm_1.downloadNPMPackage)(options);
21
+ default:
22
+ assertNever(type);
23
+ throw new Error(`Invalid download type: ${type}`);
24
+ }
25
+ }
26
+ exports.downloadPackage = downloadPackage;
@@ -0,0 +1,30 @@
1
+ // src/download/index.ts
2
+ import {
3
+ downloadGitHubRepo
4
+ } from "./github/index.mjs";
5
+ import {
6
+ downloadGitRepo
7
+ } from "./git/index.mjs";
8
+ import {
9
+ downloadNPMPackage
10
+ } from "./npm/index.mjs";
11
+ function assertNever(v) {
12
+ }
13
+ function downloadPackage(options) {
14
+ const type = options.downloadType;
15
+ switch (type) {
16
+ case "git": {
17
+ return downloadGitRepo(options);
18
+ }
19
+ case "github":
20
+ return downloadGitHubRepo(options);
21
+ case "npm":
22
+ return downloadNPMPackage(options);
23
+ default:
24
+ assertNever(type);
25
+ throw new Error(`Invalid download type: ${type}`);
26
+ }
27
+ }
28
+ export {
29
+ downloadPackage
30
+ };
@@ -1,7 +1,8 @@
1
1
  import { ExportTargetOptions } from '../../export/helpers/prepare';
2
2
  import type { DocumentNotModified } from '../types/modified';
3
+ import type { DownloadSourceMixin } from '../types/sources';
3
4
  interface IfModifiedSinceOption {
4
- ifModifiedSince: string | true;
5
+ ifModifiedSince: string | true | DownloadNPMPackageResult;
5
6
  }
6
7
  /**
7
8
  * Options for downloadNPMPackage()
@@ -14,9 +15,9 @@ export interface DownloadNPMPackageOptions extends ExportTargetOptions, Partial<
14
15
  /**
15
16
  * Result
16
17
  */
17
- export interface DownloadNPMPackageResult {
18
+ export interface DownloadNPMPackageResult extends DownloadSourceMixin<'npm'> {
18
19
  rootDir: string;
19
- actualDir: string;
20
+ contentsDir: string;
20
21
  version: string;
21
22
  }
22
23
  /**
@@ -8,22 +8,39 @@ const untar_1 = require("../helpers/untar");
8
8
  const version_1 = require("./version");
9
9
  async function downloadNPMPackage(options) {
10
10
  const rootDir = (options.target = (0, prepare_1.normalizeDir)(options.target));
11
- const actualDir = rootDir + '/package';
11
+ const contentsDir = rootDir + '/package';
12
12
  // Get latest location
13
13
  const versionInfo = await (0, version_1.getNPMVersion)(options);
14
14
  const version = versionInfo.version;
15
15
  // Check downloaded copy
16
- if (options.ifModifiedSince) {
16
+ const ifModifiedSince = options.ifModifiedSince;
17
+ if (ifModifiedSince) {
17
18
  try {
18
- const expectedVersion = options.ifModifiedSince === true
19
- ? await (0, version_1.getPackageVersion)(actualDir)
20
- : options.ifModifiedSince;
19
+ let expectedVersion;
20
+ if (typeof ifModifiedSince === 'object') {
21
+ // Make sure result object matches
22
+ if (ifModifiedSince.downloadType === 'npm' &&
23
+ ifModifiedSince.rootDir === rootDir &&
24
+ ifModifiedSince.contentsDir === contentsDir) {
25
+ expectedVersion = ifModifiedSince.version;
26
+ }
27
+ else {
28
+ expectedVersion = null;
29
+ }
30
+ }
31
+ else {
32
+ expectedVersion =
33
+ ifModifiedSince === true
34
+ ? await (0, version_1.getPackageVersion)(contentsDir)
35
+ : ifModifiedSince;
36
+ }
21
37
  if (version === expectedVersion) {
22
38
  return 'not_modified';
23
39
  }
24
40
  }
25
41
  catch (err) {
26
- //
42
+ // Clean up on error
43
+ options.cleanup = true;
27
44
  }
28
45
  }
29
46
  const archiveURL = versionInfo.file;
@@ -36,7 +53,7 @@ async function downloadNPMPackage(options) {
36
53
  // Check if archive exists
37
54
  let archiveExists = false;
38
55
  try {
39
- const stat = await fs_1.promises.lstat(archiveTarget);
56
+ const stat = await fs_1.promises.stat(archiveTarget);
40
57
  archiveExists = stat.isFile();
41
58
  }
42
59
  catch (err) {
@@ -56,7 +73,7 @@ async function downloadNPMPackage(options) {
56
73
  }
57
74
  // Remove old unpacked file
58
75
  await (0, prepare_1.prepareDirectoryForExport)({
59
- target: actualDir,
76
+ target: contentsDir,
60
77
  cleanup: true,
61
78
  });
62
79
  // Unpack file
@@ -65,8 +82,9 @@ async function downloadNPMPackage(options) {
65
82
  }
66
83
  await (0, untar_1.untar)(archiveTarget, rootDir);
67
84
  return {
85
+ downloadType: 'npm',
68
86
  rootDir,
69
- actualDir,
87
+ contentsDir,
70
88
  version,
71
89
  };
72
90
  }
@@ -9,16 +9,27 @@ import { untar } from "../helpers/untar.mjs";
9
9
  import { getNPMVersion, getPackageVersion } from "./version.mjs";
10
10
  async function downloadNPMPackage(options) {
11
11
  const rootDir = options.target = normalizeDir(options.target);
12
- const actualDir = rootDir + "/package";
12
+ const contentsDir = rootDir + "/package";
13
13
  const versionInfo = await getNPMVersion(options);
14
14
  const version = versionInfo.version;
15
- if (options.ifModifiedSince) {
15
+ const ifModifiedSince = options.ifModifiedSince;
16
+ if (ifModifiedSince) {
16
17
  try {
17
- const expectedVersion = options.ifModifiedSince === true ? await getPackageVersion(actualDir) : options.ifModifiedSince;
18
+ let expectedVersion;
19
+ if (typeof ifModifiedSince === "object") {
20
+ if (ifModifiedSince.downloadType === "npm" && ifModifiedSince.rootDir === rootDir && ifModifiedSince.contentsDir === contentsDir) {
21
+ expectedVersion = ifModifiedSince.version;
22
+ } else {
23
+ expectedVersion = null;
24
+ }
25
+ } else {
26
+ expectedVersion = ifModifiedSince === true ? await getPackageVersion(contentsDir) : ifModifiedSince;
27
+ }
18
28
  if (version === expectedVersion) {
19
29
  return "not_modified";
20
30
  }
21
31
  } catch (err) {
32
+ options.cleanup = true;
22
33
  }
23
34
  }
24
35
  const archiveURL = versionInfo.file;
@@ -29,7 +40,7 @@ async function downloadNPMPackage(options) {
29
40
  await prepareDirectoryForExport(options);
30
41
  let archiveExists = false;
31
42
  try {
32
- const stat = await fs.lstat(archiveTarget);
43
+ const stat = await fs.stat(archiveTarget);
33
44
  archiveExists = stat.isFile();
34
45
  } catch (err) {
35
46
  }
@@ -45,7 +56,7 @@ async function downloadNPMPackage(options) {
45
56
  }, archiveTarget);
46
57
  }
47
58
  await prepareDirectoryForExport({
48
- target: actualDir,
59
+ target: contentsDir,
49
60
  cleanup: true
50
61
  });
51
62
  if (options.log) {
@@ -53,8 +64,9 @@ async function downloadNPMPackage(options) {
53
64
  }
54
65
  await untar(archiveTarget, rootDir);
55
66
  return {
67
+ downloadType: "npm",
56
68
  rootDir,
57
- actualDir,
69
+ contentsDir,
58
70
  version
59
71
  };
60
72
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Download types
3
+ */
4
+ export declare type DownloadSourceType = 'git' | 'github' | 'npm';
5
+ /**
6
+ * Type in other objects
7
+ */
8
+ export interface DownloadSourceMixin<T extends DownloadSourceType> {
9
+ downloadType: T;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -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
  }
package/lib/index.d.ts CHANGED
@@ -13,10 +13,12 @@ export { importFromFigma } from './import/figma/index';
13
13
  export { importDirectory } from './import/directory';
14
14
  export { downloadGitRepo } from './download/git/index';
15
15
  export { getGitRepoHash } from './download/git/hash';
16
+ export { getGitRepoBranch } from './download/git/branch';
16
17
  export { downloadGitHubRepo } from './download/github/index';
17
18
  export { getGitHubRepoHash } from './download/github/hash';
18
19
  export { downloadNPMPackage } from './download/npm/index';
19
20
  export { getNPMVersion, getPackageVersion } from './download/npm/version';
21
+ export { downloadPackage } from './download/index';
20
22
  export { parseColors, isEmptyColor } from './colors/parse';
21
23
  export { validateColors } from './colors/validate';
22
24
  export { runSVGO } from './optimise/svgo';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendAPIQuery = exports.bumpVersion = exports.cleanupIconKeyword = exports.execAsync = exports.untar = exports.unzip = exports.compareDirectories = exports.scanDirectory = exports.prepareDirectoryForExport = exports.writeJSONFile = exports.exportJSONPackage = exports.exportIconPackage = exports.exportToDirectory = exports.scaleSVG = exports.deOptimisePaths = exports.runSVGO = exports.validateColors = exports.isEmptyColor = exports.parseColors = exports.getPackageVersion = exports.getNPMVersion = exports.downloadNPMPackage = exports.getGitHubRepoHash = exports.downloadGitHubRepo = exports.getGitRepoHash = exports.downloadGitRepo = exports.importDirectory = exports.importFromFigma = exports.mergeIconSets = exports.blankIconSet = exports.IconSet = exports.convertStyleToAttrs = exports.cleanupSVGRoot = exports.cleanupInlineStyle = exports.checkBadTags = exports.removeBadAttributes = exports.cleanupSVG = exports.parseSVGStyle = exports.parseSVG = exports.SVG = void 0;
3
+ exports.sendAPIQuery = exports.bumpVersion = exports.cleanupIconKeyword = exports.execAsync = exports.untar = exports.unzip = exports.compareDirectories = exports.scanDirectory = exports.prepareDirectoryForExport = exports.writeJSONFile = exports.exportJSONPackage = exports.exportIconPackage = exports.exportToDirectory = exports.scaleSVG = exports.deOptimisePaths = exports.runSVGO = exports.validateColors = exports.isEmptyColor = exports.parseColors = exports.downloadPackage = exports.getPackageVersion = exports.getNPMVersion = exports.downloadNPMPackage = exports.getGitHubRepoHash = exports.downloadGitHubRepo = exports.getGitRepoBranch = exports.getGitRepoHash = exports.downloadGitRepo = exports.importDirectory = exports.importFromFigma = exports.mergeIconSets = exports.blankIconSet = exports.IconSet = exports.convertStyleToAttrs = exports.cleanupSVGRoot = exports.cleanupInlineStyle = exports.checkBadTags = exports.removeBadAttributes = exports.cleanupSVG = exports.parseSVGStyle = exports.parseSVG = exports.SVG = void 0;
4
4
  // SVG class and functions
5
5
  var index_1 = require("./svg/index");
6
6
  Object.defineProperty(exports, "SVG", { enumerable: true, get: function () { return index_1.SVG; } });
@@ -37,6 +37,8 @@ var index_4 = require("./download/git/index");
37
37
  Object.defineProperty(exports, "downloadGitRepo", { enumerable: true, get: function () { return index_4.downloadGitRepo; } });
38
38
  var hash_1 = require("./download/git/hash");
39
39
  Object.defineProperty(exports, "getGitRepoHash", { enumerable: true, get: function () { return hash_1.getGitRepoHash; } });
40
+ var branch_1 = require("./download/git/branch");
41
+ Object.defineProperty(exports, "getGitRepoBranch", { enumerable: true, get: function () { return branch_1.getGitRepoBranch; } });
40
42
  var index_5 = require("./download/github/index");
41
43
  Object.defineProperty(exports, "downloadGitHubRepo", { enumerable: true, get: function () { return index_5.downloadGitHubRepo; } });
42
44
  var hash_2 = require("./download/github/hash");
@@ -46,6 +48,8 @@ Object.defineProperty(exports, "downloadNPMPackage", { enumerable: true, get: fu
46
48
  var version_1 = require("./download/npm/version");
47
49
  Object.defineProperty(exports, "getNPMVersion", { enumerable: true, get: function () { return version_1.getNPMVersion; } });
48
50
  Object.defineProperty(exports, "getPackageVersion", { enumerable: true, get: function () { return version_1.getPackageVersion; } });
51
+ var index_7 = require("./download/index");
52
+ Object.defineProperty(exports, "downloadPackage", { enumerable: true, get: function () { return index_7.downloadPackage; } });
49
53
  // Manipulation
50
54
  var parse_2 = require("./colors/parse");
51
55
  Object.defineProperty(exports, "parseColors", { enumerable: true, get: function () { return parse_2.parseColors; } });
@@ -85,5 +89,5 @@ var keyword_1 = require("./misc/keyword");
85
89
  Object.defineProperty(exports, "cleanupIconKeyword", { enumerable: true, get: function () { return keyword_1.cleanupIconKeyword; } });
86
90
  var bump_version_1 = require("./misc/bump-version");
87
91
  Object.defineProperty(exports, "bumpVersion", { enumerable: true, get: function () { return bump_version_1.bumpVersion; } });
88
- var index_7 = require("./download/api/index");
89
- Object.defineProperty(exports, "sendAPIQuery", { enumerable: true, get: function () { return index_7.sendAPIQuery; } });
92
+ var index_8 = require("./download/api/index");
93
+ Object.defineProperty(exports, "sendAPIQuery", { enumerable: true, get: function () { return index_8.sendAPIQuery; } });
package/lib/index.mjs CHANGED
@@ -14,10 +14,12 @@ import { importFromFigma } from "./import/figma/index.mjs";
14
14
  import { importDirectory } from "./import/directory.mjs";
15
15
  import { downloadGitRepo } from "./download/git/index.mjs";
16
16
  import { getGitRepoHash } from "./download/git/hash.mjs";
17
+ import { getGitRepoBranch } from "./download/git/branch.mjs";
17
18
  import { downloadGitHubRepo } from "./download/github/index.mjs";
18
19
  import { getGitHubRepoHash } from "./download/github/hash.mjs";
19
20
  import { downloadNPMPackage } from "./download/npm/index.mjs";
20
21
  import { getNPMVersion, getPackageVersion } from "./download/npm/version.mjs";
22
+ import { downloadPackage } from "./download/index.mjs";
21
23
  import { parseColors, isEmptyColor } from "./colors/parse.mjs";
22
24
  import { validateColors } from "./colors/validate.mjs";
23
25
  import { runSVGO } from "./optimise/svgo.mjs";
@@ -52,11 +54,13 @@ export {
52
54
  downloadGitHubRepo,
53
55
  downloadGitRepo,
54
56
  downloadNPMPackage,
57
+ downloadPackage,
55
58
  execAsync,
56
59
  exportIconPackage,
57
60
  exportJSONPackage,
58
61
  exportToDirectory,
59
62
  getGitHubRepoHash,
63
+ getGitRepoBranch,
60
64
  getGitRepoHash,
61
65
  getNPMVersion,
62
66
  getPackageVersion,
@@ -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
  }
@@ -76,7 +76,7 @@ async function runSVGO(svg, options = {}) {
76
76
  params: {
77
77
  prefix: typeof options.cleanupIDs === 'string'
78
78
  ? options.cleanupIDs
79
- : 'svg-',
79
+ : 'svgID',
80
80
  },
81
81
  },
82
82
  ]
@@ -58,7 +58,7 @@ async function runSVGO(svg, options = {}) {
58
58
  {
59
59
  name: "cleanupIDs",
60
60
  params: {
61
- prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svg-"
61
+ prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
62
62
  }
63
63
  }
64
64
  ] : []);
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.3",
5
+ "version": "2.0.7",
6
6
  "license": "MIT",
7
7
  "bugs": "https://github.com/iconify/tools/issues",
8
8
  "homepage": "https://github.com/iconify/tools",
@@ -22,14 +22,14 @@
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
34
  "svgo": "^2.8.0",
35
35
  "tar": "^6.1.11"
@@ -104,6 +104,10 @@
104
104
  "require": "./lib/download/api/types.js",
105
105
  "import": "./lib/download/api/types.mjs"
106
106
  },
107
+ "./lib/download/git/branch": {
108
+ "require": "./lib/download/git/branch.js",
109
+ "import": "./lib/download/git/branch.mjs"
110
+ },
107
111
  "./lib/download/git/hash": {
108
112
  "require": "./lib/download/git/hash.js",
109
113
  "import": "./lib/download/git/hash.mjs"
@@ -140,6 +144,14 @@
140
144
  "require": "./lib/download/helpers/unzip.js",
141
145
  "import": "./lib/download/helpers/unzip.mjs"
142
146
  },
147
+ "./lib/download": {
148
+ "require": "./lib/download/index.js",
149
+ "import": "./lib/download/index.mjs"
150
+ },
151
+ "./lib/download/index": {
152
+ "require": "./lib/download/index.js",
153
+ "import": "./lib/download/index.mjs"
154
+ },
143
155
  "./lib/download/npm": {
144
156
  "require": "./lib/download/npm/index.js",
145
157
  "import": "./lib/download/npm/index.mjs"
@@ -160,6 +172,10 @@
160
172
  "require": "./lib/download/types/modified.js",
161
173
  "import": "./lib/download/types/modified.mjs"
162
174
  },
175
+ "./lib/download/types/sources": {
176
+ "require": "./lib/download/types/sources.js",
177
+ "import": "./lib/download/types/sources.mjs"
178
+ },
163
179
  "./lib/export/directory": {
164
180
  "require": "./lib/export/directory.js",
165
181
  "import": "./lib/export/directory.mjs"