@iconify/tools 5.0.0-beta.2 → 5.0.0-beta.4

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.
@@ -2,6 +2,7 @@ import { ExportTargetOptions } from "../../export/helpers/prepare.js";
2
2
  import { DocumentNotModified } from "../types/modified.js";
3
3
  import { DownloadSourceMixin } from "../types/sources.js";
4
4
  import { GitHubAPIOptions } from "./types.js";
5
+ import { UnzipFilterCallback } from "../helpers/unzip.js";
5
6
  interface IfModifiedSinceOption {
6
7
  ifModifiedSince: string | DownloadGitHubRepoResult;
7
8
  }
@@ -12,6 +13,7 @@ interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAPIOption
12
13
  cleanupOldFiles?: boolean;
13
14
  cleanupOldDirectories?: boolean;
14
15
  log?: boolean;
16
+ filter?: UnzipFilterCallback;
15
17
  }
16
18
  /**
17
19
  * Result
@@ -30,7 +30,7 @@ async function downloadGitHubRepo(options) {
30
30
  let exists = false;
31
31
  try {
32
32
  exists = (await promises.stat(archiveTarget)).isFile();
33
- } catch (err) {}
33
+ } catch {}
34
34
  if (!exists) await downloadFile({
35
35
  uri: `https://api.github.com/repos/${options.user}/${options.repo}/zipball/${hash}`,
36
36
  headers: {
@@ -50,9 +50,9 @@ async function downloadGitHubRepo(options) {
50
50
  force: true,
51
51
  recursive: true
52
52
  });
53
- } catch (err) {}
53
+ } catch {}
54
54
  }
55
- await unzip(archiveTarget, rootDir);
55
+ await unzip(archiveTarget, rootDir, options.filter);
56
56
  const matchingDirs = await findMatchingDirs(rootDir, hash);
57
57
  if (matchingDirs.length !== 1) throw new Error(`Error unpacking ${hash}.zip`);
58
58
  return {
@@ -1,6 +1,7 @@
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 { UnzipFilterCallback } from "../helpers/unzip.js";
4
5
  import { GitLabAPIOptions } from "./types.js";
5
6
  interface IfModifiedSinceOption {
6
7
  ifModifiedSince: string | DownloadGitLabRepoResult;
@@ -12,6 +13,7 @@ interface DownloadGitLabRepoOptions extends ExportTargetOptions, GitLabAPIOption
12
13
  cleanupOldFiles?: boolean;
13
14
  cleanupOldDirectories?: boolean;
14
15
  log?: boolean;
16
+ filter?: UnzipFilterCallback;
15
17
  }
16
18
  /**
17
19
  * Result
@@ -31,7 +31,7 @@ async function downloadGitLabRepo(options) {
31
31
  let exists = false;
32
32
  try {
33
33
  exists = (await promises.stat(archiveTarget)).isFile();
34
- } catch (err) {}
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 }
@@ -48,9 +48,9 @@ async function downloadGitLabRepo(options) {
48
48
  force: true,
49
49
  recursive: true
50
50
  });
51
- } catch (err) {}
51
+ } catch {}
52
52
  }
53
- await unzip(archiveTarget, rootDir);
53
+ await unzip(archiveTarget, rootDir, options.filter);
54
54
  const matchingDirs = await findMatchingDirs(rootDir, hash);
55
55
  if (matchingDirs.length !== 1) throw new Error(`Error unpacking ${hash}.zip`);
56
56
  return {
@@ -1,5 +1,6 @@
1
+ type UnzipFilterCallback = (file: string) => boolean;
1
2
  /**
2
3
  * Unzip archive
3
4
  */
4
- declare function unzip(source: string, path: string): Promise<void>;
5
- export { unzip };
5
+ declare function unzip(source: string, path: string, filter?: UnzipFilterCallback): Promise<void>;
6
+ export { UnzipFilterCallback, unzip };
@@ -5,14 +5,15 @@ import { unzip as unzip$1 } from "fflate";
5
5
  /**
6
6
  * Unzip archive
7
7
  */
8
- async function unzip(source, path) {
8
+ async function unzip(source, path, filter) {
9
9
  const dir = normalize(path);
10
10
  const data = await readFile(source);
11
11
  async function writeFiles(data$1) {
12
12
  const createdDirs = /* @__PURE__ */ new Set();
13
13
  for (const name in data$1) {
14
14
  const filePath = normalize(join(dir, name));
15
- if (filePath.startsWith("/") || filePath.includes("..") || filePath.includes(":")) throw new Error("Invalid file path in zip: " + filePath);
15
+ if (filter && !filter(filePath)) continue;
16
+ if (filePath.startsWith("/") || filePath.includes("../") || filePath.includes(":")) throw new Error("Invalid file path in zip: " + filePath);
16
17
  if (filePath.includes("/._")) continue;
17
18
  const isDir = filePath.endsWith("/");
18
19
  const fileDir = isDir ? filePath.slice(0, filePath.length - 1) : dirname(filePath);
package/lib/index.d.ts CHANGED
@@ -14,11 +14,11 @@ import { getGitRepoHash } from "./download/git/hash.js";
14
14
  import { downloadGitRepo } from "./download/git/index.js";
15
15
  import { resetGitRepoContents } from "./download/git/reset.js";
16
16
  import { getGitHubRepoHash } from "./download/github/hash.js";
17
+ import { unzip } from "./download/helpers/unzip.js";
17
18
  import { downloadGitHubRepo } from "./download/github/index.js";
18
19
  import { getGitLabRepoHash } from "./download/gitlab/hash.js";
19
20
  import { downloadGitLabRepo } from "./download/gitlab/index.js";
20
21
  import { untar } from "./download/helpers/untar.js";
21
- import { unzip } from "./download/helpers/unzip.js";
22
22
  import { downloadNPMPackage } from "./download/npm/index.js";
23
23
  import { downloadPackage } from "./download/index.js";
24
24
  import { getNPMVersion, getPackageVersion } from "./download/npm/version.js";
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.0-beta.2",
6
+ "version": "5.0.0-beta.4",
7
7
  "publishConfig": {
8
8
  "tag": "next"
9
9
  },