@eik/cli 3.0.0-next.2 → 3.1.0
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/CHANGELOG.md +152 -9
- package/classes/alias.js +49 -22
- package/classes/index.js +47 -23
- package/classes/integrity.js +27 -16
- package/classes/login.js +21 -7
- package/classes/meta.js +20 -12
- package/classes/ping.js +20 -9
- package/classes/publish/map.js +33 -10
- package/classes/publish/package/index.js +54 -17
- package/classes/publish/package/tasks/check-bundle-sizes.js +7 -11
- package/classes/publish/package/tasks/check-if-already-published.js +8 -11
- package/classes/publish/package/tasks/cleanup.js +7 -9
- package/classes/publish/package/tasks/create-temp-directory.js +5 -9
- package/classes/publish/package/tasks/create-zip-file.js +6 -11
- package/classes/publish/package/tasks/dry-run.js +4 -8
- package/classes/publish/package/tasks/save-metafile.js +5 -7
- package/classes/publish/package/tasks/task.js +3 -5
- package/classes/publish/package/tasks/upload-files.js +16 -17
- package/classes/publish/package/tasks/validate-input.js +4 -8
- package/classes/version.js +38 -21
- package/commands/alias.js +51 -71
- package/commands/index.js +27 -0
- package/commands/init.js +69 -52
- package/commands/integrity.js +15 -32
- package/commands/login.js +23 -35
- package/commands/map-alias.js +95 -0
- package/commands/map.js +90 -0
- package/commands/meta.js +12 -29
- package/commands/npm-alias.js +90 -0
- package/commands/package-alias.js +102 -0
- package/commands/ping.js +11 -21
- package/commands/publish.js +82 -138
- package/commands/version.js +16 -33
- package/formatters/alias.js +8 -14
- package/formatters/artifact.js +8 -8
- package/formatters/file.js +3 -10
- package/formatters/index.js +5 -5
- package/formatters/version.js +5 -12
- package/index.js +53 -12
- package/package.json +49 -52
- package/readme.md +16 -4
- package/types/classes/alias.d.ts +60 -0
- package/types/classes/index.d.ts +37 -0
- package/types/classes/integrity.d.ts +35 -0
- package/types/classes/login.d.ts +25 -0
- package/types/classes/meta.d.ts +28 -0
- package/types/classes/ping.d.ts +23 -0
- package/types/classes/publish/map.d.ts +51 -0
- package/types/classes/publish/package/index.d.ts +94 -0
- package/types/classes/publish/package/tasks/check-bundle-sizes.d.ts +4 -0
- package/types/classes/publish/package/tasks/check-if-already-published.d.ts +4 -0
- package/types/classes/publish/package/tasks/cleanup.d.ts +4 -0
- package/types/classes/publish/package/tasks/create-temp-directory.d.ts +4 -0
- package/types/classes/publish/package/tasks/create-zip-file.d.ts +4 -0
- package/types/classes/publish/package/tasks/dry-run.d.ts +7 -0
- package/types/classes/publish/package/tasks/save-metafile.d.ts +4 -0
- package/types/classes/publish/package/tasks/task.d.ts +8 -0
- package/types/classes/publish/package/tasks/upload-files.d.ts +4 -0
- package/types/classes/publish/package/tasks/validate-input.d.ts +4 -0
- package/types/classes/version.d.ts +43 -0
- package/types/utils/hash/compare.d.ts +2 -0
- package/types/utils/hash/file.d.ts +2 -0
- package/types/utils/hash/files.d.ts +2 -0
- package/types/utils/hash/index.d.ts +9 -0
- package/types/utils/http/index.d.ts +12 -0
- package/types/utils/http/integrity.d.ts +2 -0
- package/types/utils/http/latest-version.d.ts +2 -0
- package/types/utils/http/request.d.ts +33 -0
- package/types/utils/http/versions.d.ts +5 -0
- package/types/utils/index.d.ts +6 -0
- package/types/utils/json/index.d.ts +9 -0
- package/types/utils/json/read.d.ts +5 -0
- package/types/utils/json/write-eik.d.ts +5 -0
- package/types/utils/json/write.d.ts +5 -0
- package/types/utils/logger.d.ts +33 -0
- package/types/utils/type-title.d.ts +2 -0
- package/utils/hash/compare.js +1 -3
- package/utils/hash/file.js +3 -5
- package/utils/hash/files.js +4 -6
- package/utils/hash/index.js +4 -4
- package/utils/http/index.js +6 -5
- package/utils/http/integrity.js +2 -5
- package/utils/http/latest-version.js +2 -5
- package/utils/http/request.js +25 -19
- package/utils/http/versions.js +2 -5
- package/utils/index.js +5 -4
- package/utils/json/index.js +4 -4
- package/utils/json/read.js +5 -7
- package/utils/json/write-eik.js +4 -6
- package/utils/json/write.js +4 -6
- package/utils/logger.js +2 -5
- package/utils/type-title.js +1 -1
- package/utils/get-cwd.js +0 -14
- package/utils/type-slug.js +0 -4
@@ -0,0 +1,23 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {object} PingOptions
|
3
|
+
* @property {string} [server]
|
4
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
5
|
+
*/
|
6
|
+
export default class Ping {
|
7
|
+
/**
|
8
|
+
* @param {PingOptions} options
|
9
|
+
*/
|
10
|
+
constructor({ logger, server }?: PingOptions);
|
11
|
+
log: abslog.ValidLogger;
|
12
|
+
server: string;
|
13
|
+
/**
|
14
|
+
* Run the ping command
|
15
|
+
* @returns {Promise<boolean>}
|
16
|
+
*/
|
17
|
+
run(): Promise<boolean>;
|
18
|
+
}
|
19
|
+
export type PingOptions = {
|
20
|
+
server?: string;
|
21
|
+
logger?: import("abslog").AbstractLoggerOptions;
|
22
|
+
};
|
23
|
+
import abslog from 'abslog';
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {object} PublishMapOptions
|
3
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
4
|
+
* @property {string} server
|
5
|
+
* @property {string} [cwd]
|
6
|
+
* @property {string} token
|
7
|
+
* @property {string} file
|
8
|
+
* @property {string} name
|
9
|
+
* @property {string} version
|
10
|
+
*/
|
11
|
+
/**
|
12
|
+
* @typedef {object} PublishMapResult
|
13
|
+
* @property {string} server
|
14
|
+
* @property {string} name
|
15
|
+
* @property {string} version
|
16
|
+
* @property {string} type
|
17
|
+
*/
|
18
|
+
export default class PublishMap {
|
19
|
+
/**
|
20
|
+
* @param {PublishMapOptions} options
|
21
|
+
*/
|
22
|
+
constructor({ logger, cwd, server, token, file, name, version, }: PublishMapOptions);
|
23
|
+
log: abslog.ValidLogger;
|
24
|
+
cwd: string;
|
25
|
+
server: string;
|
26
|
+
token: string;
|
27
|
+
name: string;
|
28
|
+
version: string;
|
29
|
+
file: string;
|
30
|
+
/**
|
31
|
+
* @returns {Promise<PublishMapResult>}
|
32
|
+
*/
|
33
|
+
run(): Promise<PublishMapResult>;
|
34
|
+
absoluteFile: string;
|
35
|
+
}
|
36
|
+
export type PublishMapOptions = {
|
37
|
+
logger?: import("abslog").AbstractLoggerOptions;
|
38
|
+
server: string;
|
39
|
+
cwd?: string;
|
40
|
+
token: string;
|
41
|
+
file: string;
|
42
|
+
name: string;
|
43
|
+
version: string;
|
44
|
+
};
|
45
|
+
export type PublishMapResult = {
|
46
|
+
server: string;
|
47
|
+
name: string;
|
48
|
+
version: string;
|
49
|
+
type: string;
|
50
|
+
};
|
51
|
+
import abslog from 'abslog';
|
@@ -0,0 +1,94 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {object} PublishOptions
|
3
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
4
|
+
* @property {string} [cwd]
|
5
|
+
* @property {string} token
|
6
|
+
* @property {boolean} [dryRun=false]
|
7
|
+
* @property {string} server
|
8
|
+
* @property {"package" | "map" | "npm" | "image"} [type="package"]
|
9
|
+
* @property {string} name
|
10
|
+
* @property {string} [version="1.0.0"]
|
11
|
+
* @property {string[]} [map]
|
12
|
+
* @property {string} [out="./.eik"]
|
13
|
+
* @property {Record<string, string>} files
|
14
|
+
*/
|
15
|
+
/**
|
16
|
+
* @typedef {object} PublishResult
|
17
|
+
* @property {string} type
|
18
|
+
* @property {string} server
|
19
|
+
* @property {string} name
|
20
|
+
* @property {unknown} level
|
21
|
+
* @property {boolean} dryRun
|
22
|
+
* @property {string} integrity
|
23
|
+
* @property {unknown} created
|
24
|
+
* @property {unknown} author
|
25
|
+
* @property {string} org
|
26
|
+
* @property {string} version
|
27
|
+
* @property {unknown} response
|
28
|
+
* @property {Array<{ pathname: string; type: string; }>} files
|
29
|
+
*/
|
30
|
+
export default class Publish {
|
31
|
+
/**
|
32
|
+
* @param {PublishOptions} options
|
33
|
+
*/
|
34
|
+
constructor({ logger, cwd, token, dryRun, server, type, name, version, map, out, files, }: PublishOptions);
|
35
|
+
log: abslog.ValidLogger;
|
36
|
+
cwd: string;
|
37
|
+
dryRun: boolean;
|
38
|
+
config: EikConfig;
|
39
|
+
path: string;
|
40
|
+
validateInput: ValidateInput;
|
41
|
+
createTempDirectory: CreateTempDirectory;
|
42
|
+
createZipFile: CreateZipFile;
|
43
|
+
checkBundleSizes: CheckBundleSizes;
|
44
|
+
runDryRun: DryRun;
|
45
|
+
checkIfAlreadyPublished: CheckIfAlreadyPublished;
|
46
|
+
uploadFiles: UploadFiles;
|
47
|
+
saveMetafile: SaveMetafile;
|
48
|
+
cleanup: Cleanup;
|
49
|
+
/**
|
50
|
+
* @returns {Promise<PublishResult>}
|
51
|
+
*/
|
52
|
+
run(): Promise<PublishResult>;
|
53
|
+
}
|
54
|
+
export type PublishOptions = {
|
55
|
+
logger?: import("abslog").AbstractLoggerOptions;
|
56
|
+
cwd?: string;
|
57
|
+
token: string;
|
58
|
+
dryRun?: boolean;
|
59
|
+
server: string;
|
60
|
+
type?: "package" | "map" | "npm" | "image";
|
61
|
+
name: string;
|
62
|
+
version?: string;
|
63
|
+
map?: string[];
|
64
|
+
out?: string;
|
65
|
+
files: Record<string, string>;
|
66
|
+
};
|
67
|
+
export type PublishResult = {
|
68
|
+
type: string;
|
69
|
+
server: string;
|
70
|
+
name: string;
|
71
|
+
level: unknown;
|
72
|
+
dryRun: boolean;
|
73
|
+
integrity: string;
|
74
|
+
created: unknown;
|
75
|
+
author: unknown;
|
76
|
+
org: string;
|
77
|
+
version: string;
|
78
|
+
response: unknown;
|
79
|
+
files: Array<{
|
80
|
+
pathname: string;
|
81
|
+
type: string;
|
82
|
+
}>;
|
83
|
+
};
|
84
|
+
import abslog from 'abslog';
|
85
|
+
import { EikConfig } from '@eik/common';
|
86
|
+
import ValidateInput from './tasks/validate-input.js';
|
87
|
+
import CreateTempDirectory from './tasks/create-temp-directory.js';
|
88
|
+
import CreateZipFile from './tasks/create-zip-file.js';
|
89
|
+
import CheckBundleSizes from './tasks/check-bundle-sizes.js';
|
90
|
+
import DryRun from './tasks/dry-run.js';
|
91
|
+
import CheckIfAlreadyPublished from './tasks/check-if-already-published.js';
|
92
|
+
import UploadFiles from './tasks/upload-files.js';
|
93
|
+
import SaveMetafile from './tasks/save-metafile.js';
|
94
|
+
import Cleanup from './tasks/cleanup.js';
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {object} VersionOptions
|
3
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
4
|
+
* @property {string} server
|
5
|
+
* @property {"package" | "npm" | "map"} [type="package"]
|
6
|
+
* @property {string} name
|
7
|
+
* @property {string} version
|
8
|
+
* @property {import("semver").ReleaseType} [level="patch"]
|
9
|
+
* @property {string} cwd
|
10
|
+
* @property {string[]} [map]
|
11
|
+
* @property {string} [out="./.eik"]
|
12
|
+
* @property {string | Record<string, string>} files
|
13
|
+
*/
|
14
|
+
export default class Version {
|
15
|
+
/**
|
16
|
+
* @param {VersionOptions} options
|
17
|
+
*/
|
18
|
+
constructor({ logger, server, type, name, version, level, cwd, map, out, files, }: VersionOptions);
|
19
|
+
log: abslog.ValidLogger;
|
20
|
+
config: EikConfig;
|
21
|
+
path: string;
|
22
|
+
level: semver.ReleaseType;
|
23
|
+
/**
|
24
|
+
* Similar to `npm version`, but updates `eik.json`
|
25
|
+
* @returns {Promise<string | null>} The new version number, or null if the versioning failed
|
26
|
+
*/
|
27
|
+
run(): Promise<string | null>;
|
28
|
+
}
|
29
|
+
export type VersionOptions = {
|
30
|
+
logger?: import("abslog").AbstractLoggerOptions;
|
31
|
+
server: string;
|
32
|
+
type?: "package" | "npm" | "map";
|
33
|
+
name: string;
|
34
|
+
version: string;
|
35
|
+
level?: import("semver").ReleaseType;
|
36
|
+
cwd: string;
|
37
|
+
map?: string[];
|
38
|
+
out?: string;
|
39
|
+
files: string | Record<string, string>;
|
40
|
+
};
|
41
|
+
import abslog from 'abslog';
|
42
|
+
import { EikConfig } from '@eik/common';
|
43
|
+
import semver from 'semver';
|
@@ -0,0 +1,12 @@
|
|
1
|
+
declare namespace _default {
|
2
|
+
export { latestVersion };
|
3
|
+
export { versions };
|
4
|
+
export { integrity };
|
5
|
+
export { request };
|
6
|
+
}
|
7
|
+
export default _default;
|
8
|
+
import latestVersion from './latest-version.js';
|
9
|
+
import versions from './versions.js';
|
10
|
+
import integrity from './integrity.js';
|
11
|
+
import request from './request.js';
|
12
|
+
export { latestVersion, versions, integrity, request };
|
@@ -0,0 +1,33 @@
|
|
1
|
+
export default request;
|
2
|
+
export type RequestOptions = {
|
3
|
+
method?: string;
|
4
|
+
host: string;
|
5
|
+
pathname: string;
|
6
|
+
data?: unknown;
|
7
|
+
file?: string;
|
8
|
+
map?: string;
|
9
|
+
token?: string;
|
10
|
+
};
|
11
|
+
/**
|
12
|
+
* @typedef {object} RequestOptions
|
13
|
+
* @property {string} [method="POST"]
|
14
|
+
* @property {string} host
|
15
|
+
* @property {string} pathname
|
16
|
+
* @property {unknown} [data]
|
17
|
+
* @property {string} [file]
|
18
|
+
* @property {string} [map]
|
19
|
+
* @property {string} [token]
|
20
|
+
*/
|
21
|
+
/**
|
22
|
+
* HTTP Utility for making requests against an Eik server
|
23
|
+
*
|
24
|
+
* @param {RequestOptions} options
|
25
|
+
*
|
26
|
+
* @returns {Promise<{ status:number; message: object | string }>} - Promise that resolves to an object with properties status and message
|
27
|
+
*
|
28
|
+
* @throws Error
|
29
|
+
*/
|
30
|
+
declare function request(options: RequestOptions): Promise<{
|
31
|
+
status: number;
|
32
|
+
message: object | string;
|
33
|
+
}>;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
export default logger;
|
2
|
+
/**
|
3
|
+
* Creates a logger object that wraps an instance of the "ora" module in order to provide consistent command line logging that includes a spinner
|
4
|
+
*
|
5
|
+
* @param {object} spinner
|
6
|
+
* @param {boolean} debug
|
7
|
+
*/
|
8
|
+
declare function logger(spinner: object, debug?: boolean): {
|
9
|
+
/**
|
10
|
+
* @param {string} message
|
11
|
+
*/
|
12
|
+
fatal(message: string): void;
|
13
|
+
/**
|
14
|
+
* @param {string} message
|
15
|
+
*/
|
16
|
+
error(message: string): void;
|
17
|
+
/**
|
18
|
+
* @param {string} message
|
19
|
+
*/
|
20
|
+
warn(message: string): void;
|
21
|
+
/**
|
22
|
+
* @param {string} message
|
23
|
+
*/
|
24
|
+
info(message: string): void;
|
25
|
+
/**
|
26
|
+
* @param {string} message
|
27
|
+
*/
|
28
|
+
debug(message: string): void;
|
29
|
+
/**
|
30
|
+
* @param {string} message
|
31
|
+
*/
|
32
|
+
trace(message: string): void;
|
33
|
+
};
|
package/utils/hash/compare.js
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
1
|
/**
|
4
2
|
* Compares 2 hash strings for comparison. Returns `true` if hashes are identical, false otherwise.
|
5
3
|
*
|
@@ -10,4 +8,4 @@
|
|
10
8
|
*
|
11
9
|
* @example hash.compare('a1b22c23d24e25f4g33a123b23c34', 'a1b22c23d24e25f4g33a123b23c34');
|
12
10
|
*/
|
13
|
-
|
11
|
+
export default (hash1, hash2) => hash1 === hash2;
|
package/utils/hash/file.js
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const ssri = require('ssri');
|
4
|
-
const fs = require('fs');
|
1
|
+
import ssri from 'ssri';
|
2
|
+
import fs from 'fs';
|
5
3
|
|
6
4
|
/**
|
7
5
|
* Reads a file from a given path and produces and returns an integrity hash from its contents
|
@@ -12,7 +10,7 @@ const fs = require('fs');
|
|
12
10
|
*
|
13
11
|
* @example hash.file('/path/to/file.js');
|
14
12
|
*/
|
15
|
-
|
13
|
+
export default async (path) => {
|
16
14
|
const integrity = await ssri.fromStream(fs.createReadStream(path));
|
17
15
|
return integrity.toString();
|
18
16
|
};
|
package/utils/hash/files.js
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const ssri = require('ssri');
|
4
|
-
const fileHash = require('./file');
|
1
|
+
import ssri from 'ssri';
|
2
|
+
import fileHash from './file.js';
|
5
3
|
|
6
4
|
/**
|
7
5
|
* Reads files from given paths and produces and returns an integrity hash from all files contents
|
8
6
|
*
|
9
|
-
* @param {[
|
7
|
+
* @param {string[]} files - an array of file paths
|
10
8
|
*
|
11
9
|
* @returns {Promise<string>} - integrity string
|
12
10
|
*
|
13
11
|
* @example hash.files(['/path/to/file1.js', '/path/to/file2.js']);
|
14
12
|
*/
|
15
|
-
|
13
|
+
export default async (files) => {
|
16
14
|
const hashes = await Promise.all(files.map(fileHash));
|
17
15
|
const hasher = ssri.create();
|
18
16
|
for (const hash of hashes.sort()) {
|
package/utils/hash/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import file from './file.js';
|
2
|
+
import files from './files.js';
|
3
|
+
import compare from './compare.js';
|
4
4
|
|
5
|
-
|
5
|
+
export default { file, files, compare };
|
package/utils/http/index.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
import latestVersion from './latest-version.js';
|
2
|
+
import versions from './versions.js';
|
3
|
+
import integrity from './integrity.js';
|
4
|
+
import request from './request.js';
|
5
5
|
|
6
|
-
|
6
|
+
export default { latestVersion, versions, integrity, request };
|
7
|
+
export { latestVersion, versions, integrity, request };
|
package/utils/http/integrity.js
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const { join } = require('path');
|
4
|
-
const fetch = require('node-fetch');
|
1
|
+
import { join } from 'path';
|
5
2
|
|
6
3
|
/**
|
7
4
|
* Fetches package integrity string by name and version from a given Eik asset server.
|
@@ -14,7 +11,7 @@ const fetch = require('node-fetch');
|
|
14
11
|
*
|
15
12
|
* @throws Error
|
16
13
|
*/
|
17
|
-
|
14
|
+
export default async (server, type, name, version) => {
|
18
15
|
const url = new URL(join(type, name, version), server);
|
19
16
|
url.search = `?t=${Date.now()}`;
|
20
17
|
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const { join } = require('path');
|
4
|
-
const fetch = require('node-fetch');
|
1
|
+
import { join } from 'path';
|
5
2
|
|
6
3
|
/**
|
7
4
|
* Fetches the latest version from an Eik server of a package by name, optionally restricting the lookup to a specified semver major version
|
@@ -14,7 +11,7 @@ const fetch = require('node-fetch');
|
|
14
11
|
*
|
15
12
|
* @throws Error
|
16
13
|
*/
|
17
|
-
|
14
|
+
export default async (server, type, name, major) => {
|
18
15
|
const url = new URL(`${join(type, name)}?t=${Date.now()}`, server);
|
19
16
|
const res = await fetch(url);
|
20
17
|
if (!res.ok) {
|
package/utils/http/request.js
CHANGED
@@ -1,59 +1,65 @@
|
|
1
|
-
|
1
|
+
import { readFile } from 'node:fs/promises';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
/**
|
4
|
+
* @typedef {object} RequestOptions
|
5
|
+
* @property {string} [method="POST"]
|
6
|
+
* @property {string} host
|
7
|
+
* @property {string} pathname
|
8
|
+
* @property {unknown} [data]
|
9
|
+
* @property {string} [file]
|
10
|
+
* @property {string} [map]
|
11
|
+
* @property {string} [token]
|
12
|
+
*/
|
6
13
|
|
7
14
|
/**
|
8
15
|
* HTTP Utility for making requests against an Eik server
|
9
16
|
*
|
10
|
-
* @param {
|
17
|
+
* @param {RequestOptions} options
|
11
18
|
*
|
12
|
-
* @returns {Promise<{status:number
|
19
|
+
* @returns {Promise<{ status:number; message: object | string }>} - Promise that resolves to an object with properties status and message
|
13
20
|
*
|
14
21
|
* @throws Error
|
15
22
|
*/
|
16
23
|
async function request(options) {
|
17
24
|
const { method = 'POST', host, pathname, data, file, map, token } = options;
|
18
|
-
const
|
19
|
-
const headers =
|
25
|
+
const body = new FormData();
|
26
|
+
const headers = new Headers();
|
20
27
|
|
21
28
|
if (data) {
|
22
29
|
for (const [key, value] of Object.entries(data)) {
|
23
|
-
|
30
|
+
body.set(key, value);
|
24
31
|
}
|
25
32
|
}
|
26
33
|
|
27
34
|
if (file) {
|
28
|
-
|
35
|
+
const fileData = await readFile(file);
|
36
|
+
body.set('package', new Blob([fileData]));
|
29
37
|
}
|
30
38
|
|
31
39
|
if (map) {
|
32
|
-
|
40
|
+
const mapData = await readFile(map);
|
41
|
+
body.set('map', new Blob([mapData]));
|
33
42
|
}
|
34
43
|
|
35
44
|
if (token) {
|
36
|
-
headers.Authorization
|
45
|
+
headers.set('Authorization', `Bearer ${token}`);
|
37
46
|
}
|
38
47
|
|
39
48
|
try {
|
40
49
|
const url = new URL(pathname, host);
|
41
50
|
url.search = `?t=${Date.now()}`;
|
42
51
|
|
43
|
-
const res = await fetch(url, {
|
44
|
-
method,
|
45
|
-
body: form,
|
46
|
-
headers: { ...headers, ...form.getHeaders() },
|
47
|
-
});
|
52
|
+
const res = await fetch(url, { method, body, headers });
|
48
53
|
|
49
54
|
if (!res.ok) {
|
50
55
|
const err = new Error(
|
51
56
|
`Server responded with a non 200 ok status code. Response: ${res.status}`,
|
52
57
|
);
|
58
|
+
// @ts-ignore
|
53
59
|
err.statusCode = res.status;
|
54
60
|
throw err;
|
55
61
|
}
|
56
|
-
if (res
|
62
|
+
if (res?.headers?.get('content-type')?.includes('application/json')) {
|
57
63
|
return { message: await res.json(), status: res.status };
|
58
64
|
}
|
59
65
|
return { message: await res.text(), status: res.status };
|
@@ -65,4 +71,4 @@ async function request(options) {
|
|
65
71
|
}
|
66
72
|
}
|
67
73
|
|
68
|
-
|
74
|
+
export default request;
|