@eik/cli 3.1.3 → 3.1.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.
- package/CHANGELOG.md +7 -0
- package/classes/alias.js +108 -118
- package/classes/index.js +58 -58
- package/classes/integrity.js +89 -97
- package/classes/login.js +47 -47
- package/classes/meta.js +75 -80
- package/classes/ping.js +53 -53
- package/classes/publish/map.js +90 -92
- package/classes/publish/package/index.js +130 -130
- package/classes/publish/package/tasks/check-bundle-sizes.js +19 -21
- package/classes/publish/package/tasks/check-if-already-published.js +67 -72
- package/classes/publish/package/tasks/cleanup.js +17 -17
- package/classes/publish/package/tasks/create-temp-directory.js +17 -17
- package/classes/publish/package/tasks/create-zip-file.js +60 -65
- package/classes/publish/package/tasks/dry-run.js +15 -15
- package/classes/publish/package/tasks/save-metafile.js +17 -17
- package/classes/publish/package/tasks/task.js +7 -7
- package/classes/publish/package/tasks/upload-files.js +52 -56
- package/classes/publish/package/tasks/validate-input.js +24 -24
- package/classes/version.js +152 -163
- package/commands/alias.js +87 -87
- package/commands/index.js +24 -24
- package/commands/init.js +98 -105
- package/commands/integrity.js +52 -52
- package/commands/login.js +96 -98
- package/commands/map-alias.js +73 -73
- package/commands/map.js +72 -72
- package/commands/meta.js +49 -50
- package/commands/npm-alias.js +69 -69
- package/commands/package-alias.js +79 -80
- package/commands/ping.js +25 -25
- package/commands/publish.js +120 -124
- package/commands/version.js +86 -88
- package/formatters/alias.js +60 -63
- package/formatters/artifact.js +77 -77
- package/formatters/file.js +25 -25
- package/formatters/index.js +4 -4
- package/formatters/version.js +49 -51
- package/index.js +61 -61
- package/package.json +3 -2
- package/types/classes/alias.d.ts +1 -1
- package/types/classes/integrity.d.ts +1 -1
- package/types/classes/login.d.ts +1 -1
- package/types/classes/meta.d.ts +1 -1
- package/types/classes/ping.d.ts +1 -1
- package/types/classes/publish/map.d.ts +1 -1
- package/types/classes/publish/package/index.d.ts +11 -11
- package/types/classes/publish/package/tasks/check-bundle-sizes.d.ts +1 -1
- package/types/classes/publish/package/tasks/check-if-already-published.d.ts +1 -1
- package/types/classes/publish/package/tasks/cleanup.d.ts +1 -1
- package/types/classes/publish/package/tasks/create-temp-directory.d.ts +1 -1
- package/types/classes/publish/package/tasks/create-zip-file.d.ts +1 -1
- package/types/classes/publish/package/tasks/dry-run.d.ts +1 -1
- package/types/classes/publish/package/tasks/save-metafile.d.ts +1 -1
- package/types/classes/publish/package/tasks/task.d.ts +1 -1
- package/types/classes/publish/package/tasks/upload-files.d.ts +1 -1
- package/types/classes/publish/package/tasks/validate-input.d.ts +1 -1
- package/types/classes/version.d.ts +3 -3
- package/types/utils/hash/index.d.ts +3 -3
- package/types/utils/http/index.d.ts +4 -4
- package/types/utils/index.d.ts +3 -3
- package/types/utils/json/index.d.ts +3 -3
- package/utils/hash/file.js +4 -4
- package/utils/hash/files.js +9 -9
- package/utils/hash/index.js +3 -3
- package/utils/http/index.js +4 -4
- package/utils/http/integrity.js +18 -18
- package/utils/http/latest-version.js +37 -37
- package/utils/http/request.js +42 -42
- package/utils/http/versions.js +20 -20
- package/utils/index.js +3 -3
- package/utils/json/index.js +3 -3
- package/utils/json/read.js +26 -26
- package/utils/json/write-eik.js +17 -17
- package/utils/json/write.js +26 -28
- package/utils/logger.js +43 -43
- package/utils/type-title.js +3 -3
- package/utils/url.js +2 -2
package/classes/login.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import abslog from
|
2
|
-
import eik from
|
3
|
-
import { request } from
|
1
|
+
import abslog from "abslog";
|
2
|
+
import eik from "@eik/common";
|
3
|
+
import { request } from "../utils/http/index.js";
|
4
4
|
|
5
5
|
const { schemas } = eik;
|
6
6
|
|
@@ -12,52 +12,52 @@ const { schemas } = eik;
|
|
12
12
|
*/
|
13
13
|
|
14
14
|
export default class Login {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
/**
|
16
|
+
* @param {LoginOptions} options
|
17
|
+
*/
|
18
|
+
constructor({ logger, server, key }) {
|
19
|
+
this.log = abslog(logger);
|
20
|
+
this.server = server;
|
21
|
+
this.key = key;
|
22
|
+
}
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
/**
|
25
|
+
* @returns {Promise<string | false>} Bearer token, or false if login fails
|
26
|
+
*/
|
27
|
+
async run() {
|
28
|
+
this.log.debug("Validating input");
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
try {
|
31
|
+
schemas.assert.server(this.server);
|
32
|
+
if (!this.key || typeof !this.key === "string") {
|
33
|
+
// @ts-expect-error
|
34
|
+
throw new schemas.ValidationError('"key" must be a string');
|
35
|
+
}
|
36
|
+
} catch (err) {
|
37
|
+
this.log.error(err.message);
|
38
|
+
return false;
|
39
|
+
}
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
this.log.debug("Requesting jwt token from server");
|
42
|
+
try {
|
43
|
+
const { message } = await request({
|
44
|
+
host: this.server,
|
45
|
+
method: "POST",
|
46
|
+
pathname: "/auth/login",
|
47
|
+
data: { key: this.key },
|
48
|
+
});
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
50
|
+
this.log.info(`Login successful`);
|
51
|
+
return message.token;
|
52
|
+
} catch (err) {
|
53
|
+
switch (err.statusCode) {
|
54
|
+
case 401:
|
55
|
+
this.log.info("Login unsuccessful. Invalid credentials.");
|
56
|
+
return false;
|
57
|
+
default:
|
58
|
+
this.log.warn("Login unsuccessful. Unknown login error");
|
59
|
+
return false;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
63
|
}
|
package/classes/meta.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import abslog from
|
2
|
-
import { schemas } from
|
3
|
-
import { joinUrlPathname } from
|
1
|
+
import abslog from "abslog";
|
2
|
+
import { schemas } from "@eik/common";
|
3
|
+
import { joinUrlPathname } from "../utils/url.js";
|
4
4
|
|
5
|
-
const types = [
|
5
|
+
const types = ["pkg", "map", "npm"];
|
6
6
|
|
7
7
|
/**
|
8
8
|
* @typedef {object} MetaOptions
|
@@ -13,92 +13,87 @@ const types = ['pkg', 'map', 'npm'];
|
|
13
13
|
*/
|
14
14
|
|
15
15
|
export default class Meta {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
/**
|
17
|
+
* @param {MetaOptions} options
|
18
|
+
*/
|
19
|
+
constructor({ logger, server, name, version }) {
|
20
|
+
this.log = abslog(logger);
|
21
|
+
this.server = server;
|
22
|
+
this.name = name;
|
23
|
+
this.version = version;
|
24
|
+
}
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
/**
|
27
|
+
* @returns {Promise<unknown | false>}
|
28
|
+
*/
|
29
|
+
async run() {
|
30
|
+
this.log.debug("Validating input");
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
try {
|
33
|
+
schemas.assert.server(this.server);
|
34
|
+
} catch (err) {
|
35
|
+
this.log.error(err.message);
|
36
|
+
return false;
|
37
|
+
}
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
url.search = `?t=${Date.now()}`;
|
48
|
-
typeFetches.push(fetch(url));
|
49
|
-
}
|
39
|
+
this.log.debug("Requesting meta information from asset server");
|
40
|
+
try {
|
41
|
+
const typeFetches = [];
|
42
|
+
for (const type of types) {
|
43
|
+
const url = new URL(joinUrlPathname(type, this.name), this.server);
|
44
|
+
url.search = `?t=${Date.now()}`;
|
45
|
+
typeFetches.push(fetch(url));
|
46
|
+
}
|
50
47
|
|
51
|
-
|
48
|
+
const responses = await Promise.all(typeFetches);
|
52
49
|
|
53
|
-
|
50
|
+
const data = {};
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
52
|
+
for (const res of responses) {
|
53
|
+
if (res.ok) {
|
54
|
+
const { versions, type, name, org } = await res.json();
|
55
|
+
data[type] = {
|
56
|
+
versions: Object.values(versions),
|
57
|
+
type,
|
58
|
+
name,
|
59
|
+
org,
|
60
|
+
};
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
62
|
+
const vers = new Map(versions);
|
63
|
+
data[type].versions = Array.from(vers.values());
|
64
|
+
for (let i = 0; i < data[type].versions.length; i++) {
|
65
|
+
const { version } = data[type].versions[i];
|
66
|
+
const url = new URL(
|
67
|
+
joinUrlPathname(type, name, version),
|
68
|
+
this.server,
|
69
|
+
);
|
73
70
|
|
74
|
-
|
75
|
-
|
71
|
+
const resp = await fetch(url);
|
72
|
+
const meta = await resp.json();
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
74
|
+
data[type].versions[i] = {
|
75
|
+
...data[type].versions[i],
|
76
|
+
...meta,
|
77
|
+
};
|
78
|
+
}
|
79
|
+
}
|
83
80
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
return false;
|
89
|
-
}
|
81
|
+
if (res.status === 400) {
|
82
|
+
this.log.warn("Client attempted to send an invalid URL parameter");
|
83
|
+
return false;
|
84
|
+
}
|
90
85
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
86
|
+
if (res.status === 401) {
|
87
|
+
this.log.warn("Client unauthorized with server");
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
}
|
96
91
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
92
|
+
return data;
|
93
|
+
} catch (err) {
|
94
|
+
this.log.error("Unable to retrieve meta information for package");
|
95
|
+
this.log.warn(err.message);
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
}
|
104
99
|
}
|
package/classes/ping.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import abslog from
|
2
|
-
import { schemas } from
|
1
|
+
import abslog from "abslog";
|
2
|
+
import { schemas } from "@eik/common";
|
3
3
|
|
4
4
|
/**
|
5
5
|
* @typedef {object} PingOptions
|
@@ -8,55 +8,55 @@ import { schemas } from '@eik/common';
|
|
8
8
|
*/
|
9
9
|
|
10
10
|
export default class Ping {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
11
|
+
/**
|
12
|
+
* @param {PingOptions} options
|
13
|
+
*/
|
14
|
+
constructor({ logger, server } = {}) {
|
15
|
+
this.log = abslog(logger);
|
16
|
+
this.server = server;
|
17
|
+
}
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Run the ping command
|
21
|
+
* @returns {Promise<boolean>}
|
22
|
+
*/
|
23
|
+
async run() {
|
24
|
+
this.log.debug("Validating input");
|
25
|
+
|
26
|
+
try {
|
27
|
+
schemas.assert.server(this.server);
|
28
|
+
} catch (err) {
|
29
|
+
this.log.error(err.message);
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
|
33
|
+
this.log.debug("Requesting ping from server");
|
34
|
+
try {
|
35
|
+
const result = await fetch(/** @type {string}*/ (this.server));
|
36
|
+
|
37
|
+
if (!result.ok) {
|
38
|
+
const err = new Error("Ping unsuccessful");
|
39
|
+
// @ts-expect-error
|
40
|
+
err.statusCode = result.status;
|
41
|
+
throw err;
|
42
|
+
}
|
43
|
+
|
44
|
+
this.log.info(`Ping successful`);
|
45
|
+
return true;
|
46
|
+
} catch (err) {
|
47
|
+
if (err.code === "ENOTFOUND") {
|
48
|
+
this.log.info("Ping unsuccessful. Server not found.");
|
49
|
+
return false;
|
50
|
+
}
|
51
|
+
|
52
|
+
switch (err.statusCode) {
|
53
|
+
case 404:
|
54
|
+
this.log.info("Ping unsuccessful. Route not found.");
|
55
|
+
return false;
|
56
|
+
default:
|
57
|
+
this.log.warn("Ping unsuccessful. Unknown server error");
|
58
|
+
return false;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
62
|
}
|
package/classes/publish/map.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import assert from
|
2
|
-
import abslog from
|
3
|
-
import { join, parse, isAbsolute } from
|
4
|
-
import { existsSync } from
|
5
|
-
import { schemas } from
|
6
|
-
import { request } from
|
7
|
-
import { joinUrlPathname } from
|
1
|
+
import assert from "assert";
|
2
|
+
import abslog from "abslog";
|
3
|
+
import { join, parse, isAbsolute } from "path";
|
4
|
+
import { existsSync } from "fs";
|
5
|
+
import { schemas } from "@eik/common";
|
6
|
+
import { request } from "../../utils/http/index.js";
|
7
|
+
import { joinUrlPathname } from "../../utils/url.js";
|
8
8
|
|
9
9
|
/**
|
10
10
|
* @typedef {object} PublishMapOptions
|
@@ -26,95 +26,93 @@ import { joinUrlPathname } from '../../utils/url.js';
|
|
26
26
|
*/
|
27
27
|
|
28
28
|
export default class PublishMap {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
29
|
+
/**
|
30
|
+
* @param {PublishMapOptions} options
|
31
|
+
*/
|
32
|
+
constructor({
|
33
|
+
logger,
|
34
|
+
cwd = process.cwd(),
|
35
|
+
server,
|
36
|
+
token,
|
37
|
+
file,
|
38
|
+
name,
|
39
|
+
version,
|
40
|
+
}) {
|
41
|
+
this.log = abslog(logger);
|
42
|
+
this.cwd = cwd;
|
43
|
+
this.server = server;
|
44
|
+
this.token = token;
|
45
|
+
this.name = name;
|
46
|
+
this.version = version;
|
47
|
+
this.file = file;
|
48
|
+
}
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
/**
|
51
|
+
* @returns {Promise<PublishMapResult>}
|
52
|
+
*/
|
53
|
+
async run() {
|
54
|
+
this.log.debug("Running import map publish command");
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
this.log.debug("Validating input");
|
57
|
+
parse(this.cwd);
|
58
|
+
schemas.assert.server(this.server);
|
59
|
+
assert(
|
60
|
+
this.token && typeof this.token === "string",
|
61
|
+
'Parameter "token" is not valid',
|
62
|
+
);
|
63
|
+
schemas.assert.name(this.name);
|
64
|
+
schemas.assert.version(this.version);
|
65
|
+
parse(this.file);
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
this.absoluteFile = isAbsolute(this.file)
|
68
|
+
? this.file
|
69
|
+
: join(this.cwd, this.file);
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
assert(
|
72
|
+
existsSync(this.absoluteFile),
|
73
|
+
'Parameter "file" is not valid. File does not exist',
|
74
|
+
);
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
76
|
+
this.log.debug(
|
77
|
+
`Uploading import map "${this.name}" version "${this.version}" to asset server`,
|
78
|
+
);
|
79
|
+
try {
|
80
|
+
await request({
|
81
|
+
method: "PUT",
|
82
|
+
host: this.server,
|
83
|
+
pathname: joinUrlPathname("map", this.name, this.version),
|
84
|
+
map: this.absoluteFile,
|
85
|
+
token: this.token,
|
86
|
+
});
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
}
|
119
|
-
}
|
88
|
+
return {
|
89
|
+
server: this.server,
|
90
|
+
name: this.name,
|
91
|
+
version: this.version,
|
92
|
+
type: "map",
|
93
|
+
};
|
94
|
+
} catch (err) {
|
95
|
+
const msg = "Unable to complete upload of import map to server";
|
96
|
+
switch (err.statusCode) {
|
97
|
+
case 400:
|
98
|
+
throw new Error(
|
99
|
+
`${msg}: Client attempted to send an invalid URL parameter`,
|
100
|
+
);
|
101
|
+
case 401:
|
102
|
+
throw new Error(`${msg}: Client unauthorized with server`);
|
103
|
+
case 409:
|
104
|
+
throw new Error(
|
105
|
+
`${msg}: Map with name "${this.name}" and version "${this.version}" already exists on server`,
|
106
|
+
);
|
107
|
+
case 415:
|
108
|
+
throw new Error(
|
109
|
+
`${msg}: Client attempted to send an unsupported file format to server`,
|
110
|
+
);
|
111
|
+
case 502:
|
112
|
+
throw new Error(`${msg}: Server was unable to write file to storage`);
|
113
|
+
default:
|
114
|
+
throw new Error(`${msg}: Server failed`);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
120
118
|
}
|