chrome-webstore-upload 4.0.2 → 4.0.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.
@@ -18,5 +18,11 @@ declare class APIClient {
18
18
  Authorization: string;
19
19
  'x-goog-api-version': string;
20
20
  };
21
+ _uploadHeaders(token: string, fileName: string): {
22
+ Authorization: string;
23
+ 'x-goog-api-version': string;
24
+ 'X-Goog-Upload-Protocol': string;
25
+ 'X-Goog-Upload-File-Name': string;
26
+ };
21
27
  }
22
28
  export default function chromeWebstoreUpload(options: APIClientOptions): APIClient;
@@ -52,13 +52,14 @@ class APIClient {
52
52
  throw new Error('Read stream missing');
53
53
  }
54
54
  // Convert string path (file or directory) to stream
55
+ const fileName = typeof streamOrPath === 'string' && streamOrPath.endsWith('.crx') ? 'extension.crx' : 'extension.zip';
55
56
  const readStream = typeof streamOrPath === 'string'
56
57
  ? await getStreamFromPath(streamOrPath)
57
58
  : streamOrPath;
58
59
  const { extensionId } = this;
59
60
  const request = await fetch(uploadExistingURI(extensionId), {
60
61
  method: 'PUT',
61
- headers: this._headers(await token),
62
+ headers: this._uploadHeaders(await token, fileName),
62
63
  // @ts-expect-error Node extension? 🤷‍♂️ Required https://github.com/nodejs/node/issues/46221
63
64
  duplex: 'half',
64
65
  // Until they figure it out, this seems to work. Alternatively use https://stackoverflow.com/a/76780381/288906
@@ -127,6 +128,13 @@ class APIClient {
127
128
  'x-goog-api-version': '2',
128
129
  };
129
130
  }
131
+ _uploadHeaders(token, fileName) {
132
+ return {
133
+ ...this._headers(token),
134
+ 'X-Goog-Upload-Protocol': 'raw',
135
+ 'X-Goog-Upload-File-Name': fileName,
136
+ };
137
+ }
130
138
  }
131
139
  export default function chromeWebstoreUpload(options) {
132
140
  return new APIClient(options);
@@ -1,10 +1,12 @@
1
1
  import { readdir } from 'node:fs/promises';
2
- import { basename, join } from 'node:path';
2
+ import { join, relative } from 'node:path';
3
3
  import { isNotJunk } from 'junk';
4
4
  import yazl from 'yazl';
5
5
  export default async function zipStreamFromDirectory(directory) {
6
- const allFiles = await readdir(directory, { recursive: true });
7
- const files = allFiles.filter(file => isNotJunk(basename(file)));
6
+ const entries = await readdir(directory, { recursive: true, withFileTypes: true });
7
+ const files = entries
8
+ .filter(entry => entry.isFile() && isNotJunk(entry.name))
9
+ .map(entry => relative(directory, join(entry.parentPath, entry.name)));
8
10
  if (!files.includes('manifest.json')) {
9
11
  throw new Error(`manifest.json was not found in ${directory}`);
10
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-webstore-upload",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Upload Chrome Extensions to the Chrome Web Store",
5
5
  "keywords": [
6
6
  "chrome",
@@ -34,7 +34,7 @@
34
34
  "prepack": "npm run build",
35
35
  "test": "xo && vitest run && tsc",
36
36
  "test:upload": "eval $(cat .env) node test/live-test.js",
37
- "upload": "npm run bundle && npm run test:upload"
37
+ "upload": "npm run build && npm run bundle && npm run test:upload"
38
38
  },
39
39
  "xo": {
40
40
  "rules": {
package/readme.md CHANGED
@@ -33,7 +33,7 @@ const store = chromeWebstoreUpload({
33
33
 
34
34
  ### Upload to existing extension
35
35
 
36
- You can upload a zip file, crx file, or a directory. If you provide a directory, it will be automatically zipped.
36
+ You can upload a zip file, crx file, or a directory. If you provide a directory, it will be automatically zipped. Crx files are only supported as path, not as stream.
37
37
 
38
38
  ```javascript
39
39
  import fs from 'fs';