extension-from-store 0.2.4 → 0.2.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.
package/dist/extract.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { stripCrxHeader } from './crx';
2
- export declare function extractCrx(crxPath: string, extractDir: string, workDir: string): Promise<void>;
2
+ export declare function extractCrx(crxPath: string, extractDir: string, _workDir?: string): Promise<void>;
3
3
  export declare function extractZipArchive(zipPath: string, extractDir: string): Promise<void>;
package/dist/index.cjs CHANGED
@@ -63,8 +63,7 @@ class errors_extensionFromStoreError extends Error {
63
63
  this.cause = cause;
64
64
  }
65
65
  }
66
- const external_extract_zip_namespaceObject = require("extract-zip");
67
- var external_extract_zip_default = /*#__PURE__*/ __webpack_require__.n(external_extract_zip_namespaceObject);
66
+ const external_fflate_namespaceObject = require("fflate");
68
67
  function readUInt32LE(bytes, offset) {
69
68
  const view = new DataView(bytes.buffer, bytes.byteOffset + offset, Uint32Array.BYTES_PER_ELEMENT);
70
69
  return view.getUint32(0, true);
@@ -106,21 +105,38 @@ async function normalizeExtractedModes(dir) {
106
105
  }
107
106
  }
108
107
  }
109
- async function extractCrx(crxPath, extractDir, workDir) {
108
+ async function writeZipEntries(zipData, extractDir) {
109
+ const root = external_node_path_default().resolve(extractDir);
110
+ const entries = (0, external_fflate_namespaceObject.unzipSync)(zipData);
111
+ await promises_default().mkdir(root, {
112
+ recursive: true
113
+ });
114
+ for (const [name, data] of Object.entries(entries)){
115
+ const normalized = name.replace(/\\/g, '/');
116
+ const target = external_node_path_default().resolve(root, normalized);
117
+ const relative = external_node_path_default().relative(root, target);
118
+ if (!relative || relative.startsWith('..') || external_node_path_default().isAbsolute(relative)) throw new Error(`Refusing to extract zip entry outside the extraction dir: ${name}`);
119
+ if (normalized.endsWith('/')) {
120
+ await promises_default().mkdir(target, {
121
+ recursive: true
122
+ });
123
+ continue;
124
+ }
125
+ await promises_default().mkdir(external_node_path_default().dirname(target), {
126
+ recursive: true
127
+ });
128
+ await promises_default().writeFile(target, data);
129
+ }
130
+ }
131
+ async function extractCrx(crxPath, extractDir, _workDir) {
110
132
  const crxBuffer = await promises_default().readFile(crxPath);
111
133
  const zipBuffer = Buffer.from(stripCrxHeader(crxBuffer));
112
- const zipPath = external_node_path_default().join(workDir, 'payload.zip');
113
- await promises_default().writeFile(zipPath, zipBuffer);
114
- await external_extract_zip_default()(zipPath, {
115
- dir: extractDir
116
- });
134
+ await writeZipEntries(new Uint8Array(zipBuffer), extractDir);
117
135
  await normalizeExtractedModes(extractDir);
118
- await promises_default().unlink(zipPath).catch(()=>void 0);
119
136
  }
120
137
  async function extractZipArchive(zipPath, extractDir) {
121
- await external_extract_zip_default()(zipPath, {
122
- dir: extractDir
123
- });
138
+ const zipBuffer = await promises_default().readFile(zipPath);
139
+ await writeZipEntries(new Uint8Array(zipBuffer), extractDir);
124
140
  await normalizeExtractedModes(extractDir);
125
141
  }
126
142
  const external_node_fs_namespaceObject = require("node:fs");
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import promises from "node:fs/promises";
2
2
  import node_os from "node:os";
3
3
  import node_path from "node:path";
4
- import extract_zip from "extract-zip";
4
+ import { unzipSync } from "fflate";
5
5
  import node_fs from "node:fs";
6
6
  import node_http from "node:http";
7
7
  import node_https from "node:https";
@@ -22,21 +22,38 @@ async function normalizeExtractedModes(dir) {
22
22
  }
23
23
  }
24
24
  }
25
- async function extractCrx(crxPath, extractDir, workDir) {
25
+ async function writeZipEntries(zipData, extractDir) {
26
+ const root = node_path.resolve(extractDir);
27
+ const entries = unzipSync(zipData);
28
+ await promises.mkdir(root, {
29
+ recursive: true
30
+ });
31
+ for (const [name, data] of Object.entries(entries)){
32
+ const normalized = name.replace(/\\/g, '/');
33
+ const target = node_path.resolve(root, normalized);
34
+ const relative = node_path.relative(root, target);
35
+ if (!relative || relative.startsWith('..') || node_path.isAbsolute(relative)) throw new Error(`Refusing to extract zip entry outside the extraction dir: ${name}`);
36
+ if (normalized.endsWith('/')) {
37
+ await promises.mkdir(target, {
38
+ recursive: true
39
+ });
40
+ continue;
41
+ }
42
+ await promises.mkdir(node_path.dirname(target), {
43
+ recursive: true
44
+ });
45
+ await promises.writeFile(target, data);
46
+ }
47
+ }
48
+ async function extractCrx(crxPath, extractDir, _workDir) {
26
49
  const crxBuffer = await promises.readFile(crxPath);
27
50
  const zipBuffer = Buffer.from(stripCrxHeader(crxBuffer));
28
- const zipPath = node_path.join(workDir, 'payload.zip');
29
- await promises.writeFile(zipPath, zipBuffer);
30
- await extract_zip(zipPath, {
31
- dir: extractDir
32
- });
51
+ await writeZipEntries(new Uint8Array(zipBuffer), extractDir);
33
52
  await normalizeExtractedModes(extractDir);
34
- await promises.unlink(zipPath).catch(()=>void 0);
35
53
  }
36
54
  async function extractZipArchive(zipPath, extractDir) {
37
- await extract_zip(zipPath, {
38
- dir: extractDir
39
- });
55
+ const zipBuffer = await promises.readFile(zipPath);
56
+ await writeZipEntries(new Uint8Array(zipBuffer), extractDir);
40
57
  await normalizeExtractedModes(extractDir);
41
58
  }
42
59
  const DEFAULT_USER_AGENT = 'extension-from-store';
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "engineStrict": false,
11
11
  "name": "extension-from-store",
12
- "version": "0.2.4",
12
+ "version": "0.2.5",
13
13
  "description": "Download public browser extensions from official stores",
14
14
  "homepage": "https://www.npmjs.com/package/extension-from-store",
15
15
  "type": "module",
@@ -79,7 +79,6 @@
79
79
  "extension-download"
80
80
  ],
81
81
  "dependencies": {
82
- "extract-zip": "^2.0.1",
83
82
  "fflate": "^0.8.3"
84
83
  },
85
84
  "pnpm": {