@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.
Files changed (78) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/classes/alias.js +108 -118
  3. package/classes/index.js +58 -58
  4. package/classes/integrity.js +89 -97
  5. package/classes/login.js +47 -47
  6. package/classes/meta.js +75 -80
  7. package/classes/ping.js +53 -53
  8. package/classes/publish/map.js +90 -92
  9. package/classes/publish/package/index.js +130 -130
  10. package/classes/publish/package/tasks/check-bundle-sizes.js +19 -21
  11. package/classes/publish/package/tasks/check-if-already-published.js +67 -72
  12. package/classes/publish/package/tasks/cleanup.js +17 -17
  13. package/classes/publish/package/tasks/create-temp-directory.js +17 -17
  14. package/classes/publish/package/tasks/create-zip-file.js +60 -65
  15. package/classes/publish/package/tasks/dry-run.js +15 -15
  16. package/classes/publish/package/tasks/save-metafile.js +17 -17
  17. package/classes/publish/package/tasks/task.js +7 -7
  18. package/classes/publish/package/tasks/upload-files.js +52 -56
  19. package/classes/publish/package/tasks/validate-input.js +24 -24
  20. package/classes/version.js +152 -163
  21. package/commands/alias.js +87 -87
  22. package/commands/index.js +24 -24
  23. package/commands/init.js +98 -105
  24. package/commands/integrity.js +52 -52
  25. package/commands/login.js +96 -98
  26. package/commands/map-alias.js +73 -73
  27. package/commands/map.js +72 -72
  28. package/commands/meta.js +49 -50
  29. package/commands/npm-alias.js +69 -69
  30. package/commands/package-alias.js +79 -80
  31. package/commands/ping.js +25 -25
  32. package/commands/publish.js +120 -124
  33. package/commands/version.js +86 -88
  34. package/formatters/alias.js +60 -63
  35. package/formatters/artifact.js +77 -77
  36. package/formatters/file.js +25 -25
  37. package/formatters/index.js +4 -4
  38. package/formatters/version.js +49 -51
  39. package/index.js +61 -61
  40. package/package.json +3 -2
  41. package/types/classes/alias.d.ts +1 -1
  42. package/types/classes/integrity.d.ts +1 -1
  43. package/types/classes/login.d.ts +1 -1
  44. package/types/classes/meta.d.ts +1 -1
  45. package/types/classes/ping.d.ts +1 -1
  46. package/types/classes/publish/map.d.ts +1 -1
  47. package/types/classes/publish/package/index.d.ts +11 -11
  48. package/types/classes/publish/package/tasks/check-bundle-sizes.d.ts +1 -1
  49. package/types/classes/publish/package/tasks/check-if-already-published.d.ts +1 -1
  50. package/types/classes/publish/package/tasks/cleanup.d.ts +1 -1
  51. package/types/classes/publish/package/tasks/create-temp-directory.d.ts +1 -1
  52. package/types/classes/publish/package/tasks/create-zip-file.d.ts +1 -1
  53. package/types/classes/publish/package/tasks/dry-run.d.ts +1 -1
  54. package/types/classes/publish/package/tasks/save-metafile.d.ts +1 -1
  55. package/types/classes/publish/package/tasks/task.d.ts +1 -1
  56. package/types/classes/publish/package/tasks/upload-files.d.ts +1 -1
  57. package/types/classes/publish/package/tasks/validate-input.d.ts +1 -1
  58. package/types/classes/version.d.ts +3 -3
  59. package/types/utils/hash/index.d.ts +3 -3
  60. package/types/utils/http/index.d.ts +4 -4
  61. package/types/utils/index.d.ts +3 -3
  62. package/types/utils/json/index.d.ts +3 -3
  63. package/utils/hash/file.js +4 -4
  64. package/utils/hash/files.js +9 -9
  65. package/utils/hash/index.js +3 -3
  66. package/utils/http/index.js +4 -4
  67. package/utils/http/integrity.js +18 -18
  68. package/utils/http/latest-version.js +37 -37
  69. package/utils/http/request.js +42 -42
  70. package/utils/http/versions.js +20 -20
  71. package/utils/index.js +3 -3
  72. package/utils/json/index.js +3 -3
  73. package/utils/json/read.js +26 -26
  74. package/utils/json/write-eik.js +17 -17
  75. package/utils/json/write.js +26 -28
  76. package/utils/logger.js +43 -43
  77. package/utils/type-title.js +3 -3
  78. package/utils/url.js +2 -2
@@ -1,4 +1,4 @@
1
- import { join } from 'path';
1
+ import { join } from "path";
2
2
 
3
3
  /**
4
4
  * Fetches the latest version from an Eik server of a package by name, optionally restricting the lookup to a specified semver major version
@@ -12,44 +12,44 @@ import { join } from 'path';
12
12
  * @throws Error
13
13
  */
14
14
  export default async (server, type, name, major) => {
15
- const url = new URL(`${join(type, name)}?t=${Date.now()}`, server);
16
- const res = await fetch(url);
17
- if (!res.ok) {
18
- if (res.status === 404) {
19
- return null;
20
- }
21
- throw new Error('Server responded with non 200 status code.');
22
- }
15
+ const url = new URL(`${join(type, name)}?t=${Date.now()}`, server);
16
+ const res = await fetch(url);
17
+ if (!res.ok) {
18
+ if (res.status === 404) {
19
+ return null;
20
+ }
21
+ throw new Error("Server responded with non 200 status code.");
22
+ }
23
23
 
24
- let body;
25
- try {
26
- body = await res.json();
27
- } catch (err) {
28
- throw new Error(
29
- 'An error occurred while attempting to parse json response from server.',
30
- );
31
- }
24
+ let body;
25
+ try {
26
+ body = await res.json();
27
+ } catch (err) {
28
+ throw new Error(
29
+ "An error occurred while attempting to parse json response from server.",
30
+ );
31
+ }
32
32
 
33
- let versions;
34
- try {
35
- versions = new Map(body.versions);
36
- } catch (err) {
37
- throw new Error(
38
- 'An error occurred while attempting to create an internal versions map. The JSON returned from the server is most likely invalid.',
39
- );
40
- }
33
+ let versions;
34
+ try {
35
+ versions = new Map(body.versions);
36
+ } catch (err) {
37
+ throw new Error(
38
+ "An error occurred while attempting to create an internal versions map. The JSON returned from the server is most likely invalid.",
39
+ );
40
+ }
41
41
 
42
- const highestMajor = Math.max(...versions.keys());
43
- if (Number.isNaN(highestMajor)) {
44
- throw new Error(
45
- 'An error occurred while attempting to get the highest major version from the internal versions map.',
46
- );
47
- }
42
+ const highestMajor = Math.max(...versions.keys());
43
+ if (Number.isNaN(highestMajor)) {
44
+ throw new Error(
45
+ "An error occurred while attempting to get the highest major version from the internal versions map.",
46
+ );
47
+ }
48
48
 
49
- try {
50
- const entry = versions.get(Number(major || highestMajor));
51
- return entry.version;
52
- } catch (err) {
53
- return null;
54
- }
49
+ try {
50
+ const entry = versions.get(Number(major || highestMajor));
51
+ return entry.version;
52
+ } catch (err) {
53
+ return null;
54
+ }
55
55
  };
@@ -1,4 +1,4 @@
1
- import { readFile } from 'node:fs/promises';
1
+ import { readFile } from "node:fs/promises";
2
2
 
3
3
  /**
4
4
  * @typedef {object} RequestOptions
@@ -21,54 +21,54 @@ import { readFile } from 'node:fs/promises';
21
21
  * @throws Error
22
22
  */
23
23
  async function request(options) {
24
- const { method = 'POST', host, pathname, data, file, map, token } = options;
25
- const body = new FormData();
26
- const headers = new Headers();
24
+ const { method = "POST", host, pathname, data, file, map, token } = options;
25
+ const body = new FormData();
26
+ const headers = new Headers();
27
27
 
28
- if (data) {
29
- for (const [key, value] of Object.entries(data)) {
30
- body.set(key, value);
31
- }
32
- }
28
+ if (data) {
29
+ for (const [key, value] of Object.entries(data)) {
30
+ body.set(key, value);
31
+ }
32
+ }
33
33
 
34
- if (file) {
35
- const fileData = await readFile(file);
36
- body.set('package', new Blob([fileData]));
37
- }
34
+ if (file) {
35
+ const fileData = await readFile(file);
36
+ body.set("package", new Blob([fileData]));
37
+ }
38
38
 
39
- if (map) {
40
- const mapData = await readFile(map);
41
- body.set('map', new Blob([mapData]));
42
- }
39
+ if (map) {
40
+ const mapData = await readFile(map);
41
+ body.set("map", new Blob([mapData]));
42
+ }
43
43
 
44
- if (token) {
45
- headers.set('Authorization', `Bearer ${token}`);
46
- }
44
+ if (token) {
45
+ headers.set("Authorization", `Bearer ${token}`);
46
+ }
47
47
 
48
- try {
49
- const url = new URL(pathname, host);
50
- url.search = `?t=${Date.now()}`;
48
+ try {
49
+ const url = new URL(pathname, host);
50
+ url.search = `?t=${Date.now()}`;
51
51
 
52
- const res = await fetch(url, { method, body, headers });
52
+ const res = await fetch(url, { method, body, headers });
53
53
 
54
- if (!res.ok) {
55
- const err = new Error(
56
- `Server responded with a non 200 ok status code. Response: ${res.status}`,
57
- );
58
- // @ts-ignore
59
- err.statusCode = res.status;
60
- throw err;
61
- }
62
- if (res?.headers?.get('content-type')?.includes('application/json')) {
63
- return { message: await res.json(), status: res.status };
64
- }
65
- return { message: await res.text(), status: res.status };
66
- } catch (err) {
67
- if (!err.statusCode) {
68
- err.statusCode = 500;
69
- }
70
- throw err;
71
- }
54
+ if (!res.ok) {
55
+ const err = new Error(
56
+ `Server responded with a non 200 ok status code. Response: ${res.status}`,
57
+ );
58
+ // @ts-ignore
59
+ err.statusCode = res.status;
60
+ throw err;
61
+ }
62
+ if (res?.headers?.get("content-type")?.includes("application/json")) {
63
+ return { message: await res.json(), status: res.status };
64
+ }
65
+ return { message: await res.text(), status: res.status };
66
+ } catch (err) {
67
+ if (!err.statusCode) {
68
+ err.statusCode = 500;
69
+ }
70
+ throw err;
71
+ }
72
72
  }
73
73
 
74
74
  export default request;
@@ -1,4 +1,4 @@
1
- import { join } from 'path';
1
+ import { join } from "path";
2
2
 
3
3
  /**
4
4
  * Fetches package versions by name from a given Eik asset server.
@@ -11,27 +11,27 @@ import { join } from 'path';
11
11
  * @throws Error
12
12
  */
13
13
  export default async (server, type, name) => {
14
- const pkg = join(type, name);
15
- const url = new URL(pkg, server);
16
- url.search = `?t=${Date.now()}`;
14
+ const pkg = join(type, name);
15
+ const url = new URL(pkg, server);
16
+ url.search = `?t=${Date.now()}`;
17
17
 
18
- const res = await fetch(url);
18
+ const res = await fetch(url);
19
19
 
20
- if (!res.ok) {
21
- if (res.status === 404) {
22
- return null;
23
- }
24
- throw new Error('Server responded with non 200 status code.');
25
- }
20
+ if (!res.ok) {
21
+ if (res.status === 404) {
22
+ return null;
23
+ }
24
+ throw new Error("Server responded with non 200 status code.");
25
+ }
26
26
 
27
- let body;
28
- try {
29
- body = await res.json();
30
- } catch (err) {
31
- throw new Error(
32
- 'An error occurred while attempting to parse json response from server.',
33
- );
34
- }
27
+ let body;
28
+ try {
29
+ body = await res.json();
30
+ } catch (err) {
31
+ throw new Error(
32
+ "An error occurred while attempting to parse json response from server.",
33
+ );
34
+ }
35
35
 
36
- return body.versions;
36
+ return body.versions;
37
37
  };
package/utils/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { helpers } from '@eik/common';
2
- import logger from './logger.js';
3
- import typeTitle from './type-title.js';
1
+ import { helpers } from "@eik/common";
2
+ import logger from "./logger.js";
3
+ import typeTitle from "./type-title.js";
4
4
 
5
5
  const { getDefaults, typeSlug } = helpers;
6
6
 
@@ -1,5 +1,5 @@
1
- import read from './read.js';
2
- import write from './write.js';
3
- import writeEik from './write-eik.js';
1
+ import read from "./read.js";
2
+ import write from "./write.js";
3
+ import writeEik from "./write-eik.js";
4
4
 
5
5
  export default { read, write, writeEik };
@@ -1,6 +1,6 @@
1
- import assert from 'assert';
2
- import fs from 'node:fs/promises';
3
- import { join, isAbsolute } from 'path';
1
+ import assert from "assert";
2
+ import fs from "node:fs/promises";
3
+ import { join, isAbsolute } from "path";
4
4
 
5
5
  /**
6
6
  * Reads a file at a given location, assumes the contents to be JSON and then deserializes into a JavaScript object
@@ -17,27 +17,27 @@ import { join, isAbsolute } from 'path';
17
17
  * @example json.read({ filename: './relative/path/to/file.json', cwd: '/path/to/cwd });
18
18
  */
19
19
  export default async (location) => {
20
- if (typeof location !== 'string') {
21
- assert(
22
- location.filename,
23
- 'When "location" is not of type "string" then it must be an "object" with property "filename"',
24
- );
25
- }
26
- let cwd = process.cwd();
27
- let filename = '';
28
- if (typeof location === 'string') {
29
- filename = location;
30
- } else {
31
- filename = location.filename;
32
- if (location.cwd) {
33
- cwd = location.cwd;
34
- }
35
- }
36
- const path = isAbsolute(filename) ? filename : join(cwd, filename);
37
- try {
38
- const meta = await fs.readFile(path, 'utf8');
39
- return JSON.parse(meta);
40
- } catch (err) {
41
- return {};
42
- }
20
+ if (typeof location !== "string") {
21
+ assert(
22
+ location.filename,
23
+ 'When "location" is not of type "string" then it must be an "object" with property "filename"',
24
+ );
25
+ }
26
+ let cwd = process.cwd();
27
+ let filename = "";
28
+ if (typeof location === "string") {
29
+ filename = location;
30
+ } else {
31
+ filename = location.filename;
32
+ if (location.cwd) {
33
+ cwd = location.cwd;
34
+ }
35
+ }
36
+ const path = isAbsolute(filename) ? filename : join(cwd, filename);
37
+ try {
38
+ const meta = await fs.readFile(path, "utf8");
39
+ return JSON.parse(meta);
40
+ } catch (err) {
41
+ return {};
42
+ }
43
43
  };
@@ -1,5 +1,5 @@
1
- import fs from 'node:fs/promises';
2
- import { join } from 'path';
1
+ import fs from "node:fs/promises";
2
+ import { join } from "path";
3
3
 
4
4
  /**
5
5
  * Reads, updates and then writes data to given eik.json file (defaults to file in current directory)
@@ -14,20 +14,20 @@ import { join } from 'path';
14
14
  * @example json.writeEik({ key: 'value' }, { cwd: '/path/to/cwd', filename: 'eik.json' });
15
15
  */
16
16
  export default async (data = {}, options) => {
17
- const { cwd = process.cwd(), filename = 'eik.json' } = options;
18
- const eikpath = join(cwd, filename);
19
- const eik = await fs.readFile(eikpath, 'utf-8');
20
- const eikjson = JSON.parse(eik);
17
+ const { cwd = process.cwd(), filename = "eik.json" } = options;
18
+ const eikpath = join(cwd, filename);
19
+ const eik = await fs.readFile(eikpath, "utf-8");
20
+ const eikjson = JSON.parse(eik);
21
21
 
22
- await fs.writeFile(
23
- eikpath,
24
- JSON.stringify(
25
- {
26
- ...eikjson,
27
- ...data,
28
- },
29
- null,
30
- 2,
31
- ),
32
- );
22
+ await fs.writeFile(
23
+ eikpath,
24
+ JSON.stringify(
25
+ {
26
+ ...eikjson,
27
+ ...data,
28
+ },
29
+ null,
30
+ 2,
31
+ ),
32
+ );
33
33
  };
@@ -1,6 +1,6 @@
1
- import assert from 'assert';
2
- import fs from 'node:fs/promises';
3
- import { join, isAbsolute, dirname } from 'path';
1
+ import assert from "assert";
2
+ import fs from "node:fs/promises";
3
+ import { join, isAbsolute, dirname } from "path";
4
4
 
5
5
  /**
6
6
  * Utility function that can be used to write a JavaScript object to a file at a given location.
@@ -20,29 +20,27 @@ import { join, isAbsolute, dirname } from 'path';
20
20
  * @throws Error
21
21
  */
22
22
  export default async (meta = {}, location) => {
23
- if (typeof location !== 'string') {
24
- assert(
25
- location.filename,
26
- 'When "location" is not of type "string" then it must be an "object" with property "filename"',
27
- );
28
- }
29
- let cwd = process.cwd();
30
- let filename = '';
31
- if (typeof location === 'string') {
32
- filename = location;
33
- } else {
34
- filename = location.filename;
35
- if (location.cwd) {
36
- cwd = location.cwd;
37
- }
38
- }
39
- const path = isAbsolute(filename) ? filename : join(cwd, filename);
40
- try {
41
- await fs.mkdir(dirname(path), { recursive: true });
42
- await fs.writeFile(path, JSON.stringify(meta, null, 2));
43
- } catch (err) {
44
- throw new Error(
45
- `Error writing to JSON file ["${path}"]: ${err.message}`,
46
- );
47
- }
23
+ if (typeof location !== "string") {
24
+ assert(
25
+ location.filename,
26
+ 'When "location" is not of type "string" then it must be an "object" with property "filename"',
27
+ );
28
+ }
29
+ let cwd = process.cwd();
30
+ let filename = "";
31
+ if (typeof location === "string") {
32
+ filename = location;
33
+ } else {
34
+ filename = location.filename;
35
+ if (location.cwd) {
36
+ cwd = location.cwd;
37
+ }
38
+ }
39
+ const path = isAbsolute(filename) ? filename : join(cwd, filename);
40
+ try {
41
+ await fs.mkdir(dirname(path), { recursive: true });
42
+ await fs.writeFile(path, JSON.stringify(meta, null, 2));
43
+ } catch (err) {
44
+ throw new Error(`Error writing to JSON file ["${path}"]: ${err.message}`);
45
+ }
48
46
  };
package/utils/logger.js CHANGED
@@ -5,50 +5,50 @@
5
5
  * @param {boolean} debug
6
6
  */
7
7
  const logger = (spinner, debug = false) => ({
8
- /**
9
- * @param {string} message
10
- */
11
- fatal(message) {
12
- spinner.fail(message).start();
13
- },
14
- /**
15
- * @param {string} message
16
- */
17
- error(message) {
18
- spinner.fail(message).start();
19
- },
20
- /**
21
- * @param {string} message
22
- */
23
- warn(message) {
24
- spinner.warn(message).start();
25
- },
26
- /**
27
- * @param {string} message
28
- */
29
- info(message) {
30
- if (typeof message !== 'string') {
31
- spinner.text = '';
32
- spinner.stopAndPersist();
8
+ /**
9
+ * @param {string} message
10
+ */
11
+ fatal(message) {
12
+ spinner.fail(message).start();
13
+ },
14
+ /**
15
+ * @param {string} message
16
+ */
17
+ error(message) {
18
+ spinner.fail(message).start();
19
+ },
20
+ /**
21
+ * @param {string} message
22
+ */
23
+ warn(message) {
24
+ spinner.warn(message).start();
25
+ },
26
+ /**
27
+ * @param {string} message
28
+ */
29
+ info(message) {
30
+ if (typeof message !== "string") {
31
+ spinner.text = "";
32
+ spinner.stopAndPersist();
33
33
 
34
- console.log(message);
35
- spinner.start();
36
- } else {
37
- spinner.succeed(message).start();
38
- }
39
- },
40
- /**
41
- * @param {string} message
42
- */
43
- debug(message) {
44
- if (debug) spinner.info(message).start();
45
- },
46
- /**
47
- * @param {string} message
48
- */
49
- trace(message) {
50
- if (debug) spinner.info(message).start();
51
- },
34
+ console.log(message);
35
+ spinner.start();
36
+ } else {
37
+ spinner.succeed(message).start();
38
+ }
39
+ },
40
+ /**
41
+ * @param {string} message
42
+ */
43
+ debug(message) {
44
+ if (debug) spinner.info(message).start();
45
+ },
46
+ /**
47
+ * @param {string} message
48
+ */
49
+ trace(message) {
50
+ if (debug) spinner.info(message).start();
51
+ },
52
52
  });
53
53
 
54
54
  export default logger;
@@ -1,5 +1,5 @@
1
1
  export default (type) => {
2
- if (type === 'package') return 'PACKAGE';
3
- if (type === 'npm') return 'NPM';
4
- return 'MAP';
2
+ if (type === "package") return "PACKAGE";
3
+ if (type === "npm") return "NPM";
4
+ return "MAP";
5
5
  };
package/utils/url.js CHANGED
@@ -1,4 +1,4 @@
1
- import { join } from 'node:path';
1
+ import { join } from "node:path";
2
2
 
3
3
  /**
4
4
  * A version of path.join that replaces \ (win32) with /
@@ -6,5 +6,5 @@ import { join } from 'node:path';
6
6
  * @returns {string}
7
7
  */
8
8
  export function joinUrlPathname(...parts) {
9
- return join(...parts).replace(/\\/g, '/');
9
+ return join(...parts).replace(/\\/g, "/");
10
10
  }