@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
@@ -1,16 +1,16 @@
|
|
1
|
-
import abslog from
|
2
|
-
import { join, isAbsolute } from
|
3
|
-
import { EikConfig } from
|
4
|
-
import { typeSlug } from
|
5
|
-
import ValidateInput from
|
6
|
-
import CreateTempDirectory from
|
7
|
-
import CreateZipFile from
|
8
|
-
import CheckBundleSizes from
|
9
|
-
import DryRun from
|
10
|
-
import CheckIfAlreadyPublished from
|
11
|
-
import UploadFiles from
|
12
|
-
import SaveMetafile from
|
13
|
-
import Cleanup from
|
1
|
+
import abslog from "abslog";
|
2
|
+
import { join, isAbsolute } from "path";
|
3
|
+
import { EikConfig } from "@eik/common";
|
4
|
+
import { typeSlug } from "../../../utils/index.js";
|
5
|
+
import ValidateInput from "./tasks/validate-input.js";
|
6
|
+
import CreateTempDirectory from "./tasks/create-temp-directory.js";
|
7
|
+
import CreateZipFile from "./tasks/create-zip-file.js";
|
8
|
+
import CheckBundleSizes from "./tasks/check-bundle-sizes.js";
|
9
|
+
import DryRun from "./tasks/dry-run.js";
|
10
|
+
import CheckIfAlreadyPublished from "./tasks/check-if-already-published.js";
|
11
|
+
import UploadFiles from "./tasks/upload-files.js";
|
12
|
+
import SaveMetafile from "./tasks/save-metafile.js";
|
13
|
+
import Cleanup from "./tasks/cleanup.js";
|
14
14
|
|
15
15
|
/**
|
16
16
|
* @typedef {object} PublishOptions
|
@@ -44,128 +44,128 @@ import Cleanup from './tasks/cleanup.js';
|
|
44
44
|
*/
|
45
45
|
|
46
46
|
export default class Publish {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
47
|
+
/**
|
48
|
+
* @param {PublishOptions} options
|
49
|
+
*/
|
50
|
+
constructor({
|
51
|
+
logger,
|
52
|
+
cwd = process.cwd(),
|
53
|
+
token,
|
54
|
+
dryRun = false,
|
55
|
+
server,
|
56
|
+
type = "package",
|
57
|
+
name,
|
58
|
+
version = "1.0.0",
|
59
|
+
map = [],
|
60
|
+
out = "./.eik",
|
61
|
+
files = {},
|
62
|
+
}) {
|
63
|
+
const config = new EikConfig(
|
64
|
+
{
|
65
|
+
server,
|
66
|
+
type,
|
67
|
+
name,
|
68
|
+
version,
|
69
|
+
"import-map": map,
|
70
|
+
out,
|
71
|
+
files,
|
72
|
+
},
|
73
|
+
[[server, token]],
|
74
|
+
cwd,
|
75
|
+
);
|
76
|
+
config.validate();
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
this.log = abslog(logger);
|
79
|
+
this.cwd = cwd;
|
80
|
+
this.dryRun = dryRun;
|
81
|
+
this.config = config;
|
82
|
+
this.path = isAbsolute(config.out) ? config.out : join(cwd, config.out);
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
84
|
+
this.validateInput = new ValidateInput({
|
85
|
+
logger: this.log,
|
86
|
+
path: this.path,
|
87
|
+
config,
|
88
|
+
});
|
89
|
+
this.createTempDirectory = new CreateTempDirectory({
|
90
|
+
path: this.path,
|
91
|
+
logger: this.log,
|
92
|
+
config,
|
93
|
+
});
|
94
|
+
this.createZipFile = new CreateZipFile({
|
95
|
+
logger: this.log,
|
96
|
+
path: this.path,
|
97
|
+
config,
|
98
|
+
});
|
99
|
+
this.checkBundleSizes = new CheckBundleSizes({
|
100
|
+
cwd,
|
101
|
+
logger: this.log,
|
102
|
+
config,
|
103
|
+
});
|
104
|
+
this.runDryRun = new DryRun({ path: this.path, config });
|
105
|
+
this.checkIfAlreadyPublished = new CheckIfAlreadyPublished({
|
106
|
+
logger: this.log,
|
107
|
+
path: this.path,
|
108
|
+
config,
|
109
|
+
});
|
110
|
+
this.uploadFiles = new UploadFiles({ logger: this.log, config });
|
111
|
+
this.saveMetafile = new SaveMetafile({ logger: this.log, cwd, config });
|
112
|
+
this.cleanup = new Cleanup({
|
113
|
+
logger: this.log,
|
114
|
+
path: this.path,
|
115
|
+
config,
|
116
|
+
});
|
117
|
+
}
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
119
|
+
/**
|
120
|
+
* @returns {Promise<PublishResult>}
|
121
|
+
*/
|
122
|
+
async run() {
|
123
|
+
this.log.debug(`Running package command against server`);
|
124
|
+
this.log.debug(` ==> package name: ${this.config.name}`);
|
125
|
+
this.log.debug(` ==> package version: ${this.config.version}`);
|
126
|
+
this.log.debug(` ==> server: ${this.config.server}`);
|
127
|
+
this.log.debug(` ==> type: ${this.config.type}`);
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
await this.validateInput.process();
|
130
|
+
await this.createTempDirectory.process();
|
131
|
+
const zipFile = await this.createZipFile.process();
|
132
|
+
await this.checkBundleSizes.process();
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
134
|
+
if (this.dryRun) {
|
135
|
+
const files = await this.runDryRun.process(zipFile);
|
136
|
+
return {
|
137
|
+
type: typeSlug(this.config.type),
|
138
|
+
server: this.config.server,
|
139
|
+
name: this.config.name,
|
140
|
+
// @ts-expect-error Not sure where this.level originated
|
141
|
+
level: this.level,
|
142
|
+
dryRun: this.dryRun,
|
143
|
+
integrity: "",
|
144
|
+
created: null,
|
145
|
+
author: {},
|
146
|
+
org: "",
|
147
|
+
version: this.config.version,
|
148
|
+
response: {},
|
149
|
+
files,
|
150
|
+
};
|
151
|
+
}
|
152
152
|
|
153
|
-
|
154
|
-
|
155
|
-
|
153
|
+
const response = await this.uploadFiles.process(zipFile);
|
154
|
+
await this.saveMetafile.process(response);
|
155
|
+
await this.cleanup.process();
|
156
156
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
157
|
+
return {
|
158
|
+
type: typeSlug(this.config.type),
|
159
|
+
server: this.config.server,
|
160
|
+
name: this.config.name,
|
161
|
+
// @ts-expect-error Not sure where this.level originated
|
162
|
+
level: this.level,
|
163
|
+
dryRun: this.dryRun,
|
164
|
+
created: null,
|
165
|
+
author: {},
|
166
|
+
org: "",
|
167
|
+
version: this.config.version,
|
168
|
+
...response,
|
169
|
+
};
|
170
|
+
}
|
171
171
|
}
|
@@ -1,24 +1,22 @@
|
|
1
|
-
import bytes from
|
2
|
-
import fs from
|
3
|
-
import { gzipSizeSync } from
|
4
|
-
import Task from
|
1
|
+
import bytes from "bytes";
|
2
|
+
import fs from "fs";
|
3
|
+
import { gzipSizeSync } from "gzip-size";
|
4
|
+
import Task from "./task.js";
|
5
5
|
|
6
6
|
export default class CheckBundleSizes extends Task {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
}
|
7
|
+
async process() {
|
8
|
+
this.log.debug("Checking bundle file sizes");
|
9
|
+
try {
|
10
|
+
for (const mapping of await this.config.mappings()) {
|
11
|
+
const file = mapping.source.absolute;
|
12
|
+
this.log.debug(
|
13
|
+
` ==> entrypoint size (${
|
14
|
+
mapping.source.destination
|
15
|
+
} => ${file}): ${bytes(gzipSizeSync(fs.readFileSync(file, "utf8")))}`,
|
16
|
+
);
|
17
|
+
}
|
18
|
+
} catch (err) {
|
19
|
+
throw new Error(`Failed to check bundle sizes: ${err.message}`);
|
20
|
+
}
|
21
|
+
}
|
24
22
|
}
|
@@ -1,84 +1,79 @@
|
|
1
|
-
import { join } from
|
2
|
-
import { integrity, versions } from
|
3
|
-
import hash from
|
4
|
-
import { typeSlug } from
|
5
|
-
import Task from
|
1
|
+
import { join } from "path";
|
2
|
+
import { integrity, versions } from "../../../../utils/http/index.js";
|
3
|
+
import hash from "../../../../utils/hash/index.js";
|
4
|
+
import { typeSlug } from "../../../../utils/index.js";
|
5
|
+
import Task from "./task.js";
|
6
6
|
|
7
7
|
export default class CheckIfAlreadyPublished extends Task {
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
async process() {
|
9
|
+
const { log, path } = this;
|
10
|
+
const { server, name, version, files, type } = this.config;
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
);
|
15
|
-
log.debug(' ==> Fetching package metadata from server');
|
12
|
+
log.debug(`Checking for existence of package ${name} version ${version}`);
|
13
|
+
log.debug(" ==> Fetching package metadata from server");
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
try {
|
16
|
+
if (await integrity(server, typeSlug(type), name, version)) {
|
17
|
+
throw new Error(
|
18
|
+
`${name} version ${version} already exists on the Eik server. Publishing is not necessary.`,
|
19
|
+
);
|
20
|
+
}
|
21
|
+
log.debug(` ==> Package version ${version} does not yet exist`);
|
22
|
+
} catch (err) {
|
23
|
+
throw new Error(
|
24
|
+
`Unable to fetch package metadata from server: ${err.message}`,
|
25
|
+
);
|
26
|
+
}
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
let pkgVersions;
|
29
|
+
try {
|
30
|
+
pkgVersions = await versions(server, typeSlug(type), name);
|
31
|
+
} catch (err) {
|
32
|
+
throw new Error(
|
33
|
+
`Unable to fetch package metadata from server: ${err.message}`,
|
34
|
+
);
|
35
|
+
}
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
if (!pkgVersions) {
|
38
|
+
log.debug(" ==> Package has never been published");
|
39
|
+
return null;
|
40
|
+
}
|
43
41
|
|
44
|
-
|
45
|
-
|
42
|
+
log.debug(` ==> However, previous versions of package do exist`);
|
43
|
+
log.debug(" ==> Checking if local files have changed");
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
let localHash;
|
46
|
+
try {
|
47
|
+
const localFiles = [join(path, "eik.json")];
|
48
|
+
if (files) {
|
49
|
+
const mappings = await this.config.mappings();
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
`Unable to hash local files for comparison: ${err.message}`,
|
65
|
-
);
|
66
|
-
}
|
51
|
+
for (const mapping of mappings) {
|
52
|
+
const destination = join(path, mapping.destination.filePathname);
|
53
|
+
localFiles.push(destination);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
localHash = await hash.files(localFiles);
|
57
|
+
} catch (err) {
|
58
|
+
throw new Error(
|
59
|
+
`Unable to hash local files for comparison: ${err.message}`,
|
60
|
+
);
|
61
|
+
}
|
67
62
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
63
|
+
// @ts-expect-error
|
64
|
+
const versionMap = new Map(pkgVersions);
|
65
|
+
for (const v of versionMap.values()) {
|
66
|
+
const same = hash.compare(v.integrity, localHash);
|
67
|
+
if (same) {
|
68
|
+
throw new Error(
|
69
|
+
`Version ${v.version} of this package already contains these files, publishing is not necessary.`,
|
70
|
+
);
|
71
|
+
}
|
72
|
+
log.debug(
|
73
|
+
" ==> New files do not match existing files, continue with publishing",
|
74
|
+
);
|
75
|
+
}
|
81
76
|
|
82
|
-
|
83
|
-
|
77
|
+
return localHash;
|
78
|
+
}
|
84
79
|
}
|
@@ -1,21 +1,21 @@
|
|
1
|
-
import { join } from
|
2
|
-
import { existsSync } from
|
3
|
-
import { readdir } from
|
4
|
-
import { rimraf } from
|
5
|
-
import Task from
|
1
|
+
import { join } from "node:path";
|
2
|
+
import { existsSync } from "node:fs";
|
3
|
+
import { readdir } from "node:fs/promises";
|
4
|
+
import { rimraf } from "rimraf";
|
5
|
+
import Task from "./task.js";
|
6
6
|
|
7
7
|
export default class Cleanup extends Task {
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
async process() {
|
9
|
+
const { log, path } = this;
|
10
|
+
log.debug("Cleaning up");
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
if (existsSync(path)) {
|
13
|
+
const dir = await readdir(path);
|
14
|
+
await Promise.all(
|
15
|
+
dir
|
16
|
+
.filter((file) => file !== "integrity.json")
|
17
|
+
.map((file) => rimraf(join(path, file))),
|
18
|
+
);
|
19
|
+
}
|
20
|
+
}
|
21
21
|
}
|
@@ -1,25 +1,25 @@
|
|
1
|
-
import { makeDirectorySync } from
|
2
|
-
import Task from
|
1
|
+
import { makeDirectorySync } from "make-dir";
|
2
|
+
import Task from "./task.js";
|
3
3
|
|
4
4
|
class IOError extends Error {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
constructor(message, err) {
|
6
|
+
super(`${message}: ${err.message}`);
|
7
|
+
this.name = this.constructor.name;
|
8
|
+
Error.captureStackTrace(this, this.constructor);
|
9
|
+
}
|
10
10
|
}
|
11
11
|
|
12
12
|
export default class CreateTempDir extends Task {
|
13
|
-
|
14
|
-
|
13
|
+
async process() {
|
14
|
+
const { log, path } = this;
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
log.debug(`Creating temporary directory`);
|
17
|
+
log.debug(` ==> ${path}`);
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
try {
|
20
|
+
makeDirectorySync(path);
|
21
|
+
} catch (err) {
|
22
|
+
throw new IOError("Unable to create temp dir", err);
|
23
|
+
}
|
24
|
+
}
|
25
25
|
}
|