@eik/node-client 2.0.27 → 2.1.1

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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [2.1.1](https://github.com/eik-lib/node-client/compare/v2.1.0...v2.1.1) (2026-06-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency @eik/common to v5.1.31 ([#280](https://github.com/eik-lib/node-client/issues/280)) ([5a58f9e](https://github.com/eik-lib/node-client/commit/5a58f9e88bc8d37c8951f617269ad040b3dd6ffa))
7
+
8
+ # [2.1.0](https://github.com/eik-lib/node-client/compare/v2.0.27...v2.1.0) (2026-06-03)
9
+
10
+
11
+ ### Features
12
+
13
+ * Remove CommonJS build ([#279](https://github.com/eik-lib/node-client/issues/279)) ([8d0d75b](https://github.com/eik-lib/node-client/commit/8d0d75b5fd5bd9f9aa49769582f56acbe5d890b6))
14
+
1
15
  ## [2.0.27](https://github.com/eik-lib/node-client/compare/v2.0.26...v2.0.27) (2026-05-29)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,33 +1,28 @@
1
1
  {
2
2
  "name": "@eik/node-client",
3
- "version": "2.0.27",
3
+ "version": "2.1.1",
4
4
  "description": "Utilities for working with assets and import maps on an Eik server",
5
5
  "type": "module",
6
- "main": "./dist/index.cjs",
7
6
  "types": "./types/index.d.ts",
8
7
  "exports": {
9
8
  "types": "./types/index.d.ts",
10
- "import": "./src/index.js",
11
- "require": "./dist/index.cjs"
9
+ "import": "./src/index.js"
12
10
  },
13
11
  "files": [
14
12
  "CHANGELOG.md",
15
13
  "package.json",
16
14
  "LICENSE",
17
- "dist",
18
15
  "src",
19
16
  "types"
20
17
  ],
21
18
  "scripts": {
22
- "build": "rollup -c",
23
- "clean": "node --input-type=module --eval \"import{rmSync}from'node:fs';['.tap','dist','node_modules','types'].forEach(p=>rmSync(p,{recursive:true,force:true}))\"",
19
+ "clean": "node --input-type=module --eval \"import{rmSync}from'node:fs';['.tap','node_modules','types'].forEach(p=>rmSync(p,{recursive:true,force:true}))\"",
24
20
  "lint": "eslint .",
25
21
  "lint:fix": "eslint --fix .",
26
22
  "test": "node --test 'test/*.test.js'",
27
23
  "types": "run-s types:module types:test",
28
24
  "types:module": "tsc",
29
- "types:test": "tsc --project tsconfig.test.json",
30
- "prepare": "npm run -s build"
25
+ "types:test": "tsc --project tsconfig.test.json"
31
26
  },
32
27
  "repository": {
33
28
  "type": "git",
@@ -43,7 +38,7 @@
43
38
  },
44
39
  "homepage": "https://github.com/eik-lib/node-client#readme",
45
40
  "dependencies": {
46
- "@eik/common": "5.1.29",
41
+ "@eik/common": "5.1.31",
47
42
  "abslog": "2.4.4"
48
43
  },
49
44
  "devDependencies": {
@@ -52,10 +47,9 @@
52
47
  "@eik/semantic-release-config": "1.0.17",
53
48
  "@eik/typescript-config": "1.0.2",
54
49
  "@types/node": "25.9.1",
55
- "eslint": "10.4.0",
50
+ "eslint": "10.4.1",
56
51
  "npm-run-all2": "9.0.1",
57
52
  "prettier": "3.8.3",
58
- "rollup": "4.60.4",
59
53
  "semantic-release": "25.0.3",
60
54
  "typescript": "6.0.3"
61
55
  }
package/dist/index.cjs DELETED
@@ -1,359 +0,0 @@
1
- 'use strict';
2
-
3
- var common = require('@eik/common');
4
- var node_path = require('node:path');
5
-
6
- /**
7
- * @typedef {object} AssetOptions
8
- * @property {string} [value=""]
9
- */
10
-
11
- /**
12
- * Holds attributes for use when linking to assets hosted on Eik.
13
- *
14
- * @example
15
- * ```
16
- * // JS and <script>
17
- * const script = eik.file("/app.js");
18
- * const html = `<script
19
- * src="${script.value}"
20
- * ${script.integrity ? `integrity="${script.integrity}"` : ""}
21
- * type="module"></script>`;
22
- * ```
23
- * @example
24
- * ```
25
- * // CSS and <link>
26
- * const styles = eik.file("/styles.css");
27
- * const html = `<link
28
- * href="${styles.value}"
29
- * ${styles.integrity ? `integrity="${styles.integrity}"` : ""}
30
- * rel="stylesheet" />`;
31
- * ```
32
- */
33
- class Asset {
34
- /**
35
- * Value for use in [subresource integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity#examples).
36
- * Not calculated if `development` is `true`.
37
- *
38
- * @type {string | undefined}
39
- */
40
- integrity = undefined;
41
-
42
- /**
43
- * URL to the file for use in `<script>` or `<link>`.
44
- * @type {string}
45
- */
46
- value;
47
-
48
- /**
49
- * @param {AssetOptions} options
50
- */
51
- constructor({ value = "" } = {}) {
52
- this.integrity = undefined;
53
- this.value = value;
54
- }
55
- }
56
-
57
- const trimSlash = (value = "") => {
58
- if (value.endsWith("/")) return value.substring(0, value.length - 1);
59
- return value;
60
- };
61
-
62
- /**
63
- * @typedef {object} Options
64
- * @property {string} [base=null]
65
- * @property {boolean} [development=false]
66
- * @property {boolean} [loadMaps=false]
67
- * @property {string} [path=process.cwd()]
68
- */
69
-
70
- /**
71
- * @typedef {object} ImportMap
72
- * @property {Record<string, string>} imports
73
- */
74
-
75
- /**
76
- * An Eik utility for servers running on Node. With it you can:
77
- * - generate different URLs to assets on an Eik server depending on environment (development vs production).
78
- * - get the import maps you have configured in `eik.json` from the Eik server, should you want to use them in the HTML response.
79
- *
80
- * @example
81
- * ```js
82
- * // Create an instance, then load information from `eik.json` and the Eik server
83
- * import Eik from "@eik/node-client";
84
- *
85
- * const eik = new Eik();
86
- * await eik.load();
87
- * ```
88
- * @example
89
- * ```js
90
- * // Serve a local version of a file from `./public`
91
- * // in development and from Eik in production
92
- * import path from "node:path";
93
- * import Eik from "@eik/node-client";
94
- * import fastifyStatic from "@fastify/static";
95
- * import fastify from "fastify";
96
- *
97
- * const app = fastify();
98
- * app.register(fastifyStatic, {
99
- * root: path.join(process.cwd(), "public"),
100
- * prefix: "/public/",
101
- * });
102
- *
103
- * const eik = new Eik({
104
- * development: process.env.NODE_ENV === "development",
105
- * base: "/public",
106
- * });
107
- *
108
- * // load information from `eik.json` and the Eik server
109
- * await eik.load();
110
- *
111
- * // when development is true script.value will be /public/script.js.
112
- * // when development is false script.value will be
113
- * // https://{server}/pkg/{name}/{version}/script.js
114
- * // where {server}, {name} and {version} are read from eik.json
115
- * const script = eik.file("/script.js");
116
- *
117
- * app.get("/", (req, reply) => {
118
- * reply.type("text/html; charset=utf-8");
119
- * reply.send(`<html><body>
120
- * <script
121
- * src="${script.value}"
122
- * ${script.integrity ? `integrity="${script.integrity}"` : ""}
123
- * type="module"></script>
124
- * </body></html>`);
125
- * });
126
- *
127
- * app.listen({
128
- * port: 3000,
129
- * });
130
- *
131
- * console.log("Listening on http://localhost:3000");
132
- * ```
133
- */
134
- class Eik {
135
- #development;
136
- #loadMaps;
137
- /** @type {import('@eik/common').EikConfig | null} */
138
- #config = null;
139
- #path;
140
- #base;
141
- /** @type {ImportMap[]} */
142
- #maps = [];
143
-
144
- /**
145
- * @param {Options} options
146
- */
147
- constructor({
148
- development = false,
149
- loadMaps = false,
150
- base = "",
151
- path = process.cwd(),
152
- } = {}) {
153
- this.#development = development;
154
- this.#loadMaps = loadMaps;
155
- this.#path = path;
156
- this.#base = trimSlash(base);
157
- }
158
-
159
- /**
160
- * Reads the Eik config from disk into the object instance, used for building {@link file} links in production.
161
- *
162
- * If {@link Options.loadMaps} is `true` the import maps
163
- * defined in the Eik config will be fetched from the Eik server for
164
- * use in {@link maps}.
165
- */
166
- async load() {
167
- this.#config = common.helpers.getDefaults(this.#path);
168
- if (this.#loadMaps && this.#config) {
169
- this.#maps = await common.helpers.fetchImportMaps(this.#config.map);
170
- }
171
- }
172
-
173
- /**
174
- * The `"name"` field from the Eik config
175
- * @throws if read before calling {@link load}
176
- */
177
- get name() {
178
- if (this.#config && this.#config.name) return this.#config.name;
179
- throw new Error("Eik config was not loaded before calling .name");
180
- }
181
-
182
- /**
183
- * The `"version"` field from the Eik config
184
- * @throws if read before calling {@link load}
185
- */
186
- get version() {
187
- if (this.#config && this.#config.version) return this.#config.version;
188
- throw new Error("Eik config was not loaded before calling .version");
189
- }
190
-
191
- /**
192
- * The `"type"` field from the Eik config mapped to its URL equivalent (eg. "package" is "pkg").
193
- * @throws if read before calling {@link load}
194
- */
195
- get type() {
196
- if (this.#config && this.#config.type && this.#config.type === "package")
197
- return "pkg";
198
- if (this.#config && this.#config.type) return this.#config.type;
199
- throw new Error("Eik config was not loaded before calling .type");
200
- }
201
-
202
- /**
203
- * The `"server"` field from the Eik config
204
- * @throws if read before calling {@link load}
205
- */
206
- get server() {
207
- if (this.#config && this.#config.server) return this.#config.server;
208
- throw new Error("Eik config was not loaded before calling .server");
209
- }
210
-
211
- /**
212
- * The pathname to the base on Eik (ex. /pkg/my-app/1.0.0/)
213
- * @throws if read before calling {@link load}
214
- */
215
- get pathname() {
216
- if (
217
- this.#config &&
218
- this.#config.type &&
219
- this.#config.name &&
220
- this.#config.version
221
- )
222
- return node_path.join(
223
- "/",
224
- common.helpers.typeSlug(this.type),
225
- this.name,
226
- this.version,
227
- ).replace(/\\/g, "/");
228
- throw new Error("Eik config was not loaded before calling .pathname");
229
- }
230
-
231
- /**
232
- * Similar to {@link file}, this method returns a path to the base on Eik
233
- * (ex. https://eik.store.com/pkg/my-app/1.0.0), or {@link Options.base}
234
- * if {@link Options.development} is true.
235
- *
236
- * You can use this instead of `file` if you have a directory full of files
237
- * and you don't need {@link Asset.integrity}.
238
- *
239
- * @returns {string} The base path for assets published on Eik
240
- * @throws when {@link Options.development} is false if called before calling {@link load}
241
- */
242
- base() {
243
- if (this.#development) return this.#base;
244
- return `${this.server}${this.pathname}`;
245
- }
246
-
247
- /**
248
- * Get a link to a file that is published on Eik when running in production.
249
- * When {@link Options.development} is `true` the pathname is prefixed
250
- * with the {@link Options.base} option instead of pointing to Eik.
251
- *
252
- * @param {string} pathname pathname to the file relative to the base on Eik (ex: /path/to/script.js for a prod URL https://eik.store.com/pkg/my-app/1.0.0/path/to/script.js)
253
- * @returns {import('./asset.js').Asset}
254
- * @throws when {@link Options.development} is false if called before calling {@link load}
255
- *
256
- * @example
257
- * ```js
258
- * // in production
259
- * const eik = new Eik({
260
- * development: false,
261
- * });
262
- * await eik.load();
263
- *
264
- * const file = eik.file("/path/to/script.js");
265
- * // {
266
- * // value: https://eik.store.com/pkg/my-app/1.0.0/path/to/script.js
267
- * // integrity: sha512-zHQjnD-etc.
268
- * // }
269
- * // where the server URL, app name and version are read from eik.json
270
- * // {
271
- * // "name": "my-app",
272
- * // "version": "1.0.0",
273
- * // "server": "https://eik.store.com",
274
- * // }
275
- * ```
276
- * @example
277
- * ```js
278
- * // in development
279
- * const eik = new Eik({
280
- * development: true,
281
- * base: "/public",
282
- * });
283
- * await eik.load();
284
- *
285
- * const file = eik.file("/path/to/script.js");
286
- * // {
287
- * // value: /public/path/to/script.js
288
- * // integrity: undefined
289
- * // }
290
- * ```
291
- */
292
- file(pathname = "") {
293
- const base = this.base();
294
- return new Asset({
295
- value: `${base}${pathname}`,
296
- });
297
- }
298
-
299
- /**
300
- * When {@link Options.loadMaps} is `true` and you call {@link load}, the client
301
- * fetches the configured import maps from the Eik server.
302
- *
303
- * This method returns the import maps that were fetched during `load`.
304
- *
305
- * @returns {ImportMap[]}
306
- * @throws if {@link Options.loadMaps} is not `true` or called before calling {@link load}
307
- *
308
- * @example
309
- * ```js
310
- * const client = new Eik({
311
- * loadMaps: true,
312
- * });
313
- * await client.load();
314
- *
315
- * const maps = client.maps();
316
- * ```
317
- */
318
- maps() {
319
- if (this.#config && this.#config.version && this.#loadMaps)
320
- return this.#maps;
321
- throw new Error(
322
- 'Eik config was not loaded or "loadMaps" is "false" when calling .maps()',
323
- );
324
- }
325
-
326
- /**
327
- * Function that generates and returns an import map script tag for use in an document head.
328
- *
329
- * Only a single import map is allowed per HTML document.
330
- * A key (ex. `react`) can only be defined once.
331
- * If multiple import maps defined in `eik.json` use the same key, the last key wins.
332
- *
333
- * @example
334
- * ```
335
- * const importMap = eik.toHTML();
336
- *
337
- * <head>
338
- * ...
339
- * ${importMap}
340
- * ...
341
- * </head>
342
- * ```
343
- *
344
- * @returns {string}
345
- */
346
- toHTML() {
347
- const allImportMapKeyValuePairs = this.maps().flatMap((map) =>
348
- Object.entries(map.imports),
349
- );
350
- const mergedAndDedupedImportMapObject = Object.fromEntries(
351
- new Map(allImportMapKeyValuePairs).entries(),
352
- );
353
- return `<script type="importmap">${JSON.stringify({
354
- imports: mergedAndDedupedImportMapObject,
355
- })}</script>`;
356
- }
357
- }
358
-
359
- module.exports = Eik;