@eik/rollup-plugin 4.0.67 → 5.0.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 CHANGED
@@ -1,3 +1,23 @@
1
+ # [5.0.0](https://github.com/eik-lib/rollup-plugin/compare/v4.0.68...v5.0.0) (2025-05-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update eik/common to use shared fetchImportMap ([#234](https://github.com/eik-lib/rollup-plugin/issues/234)) ([78d25cd](https://github.com/eik-lib/rollup-plugin/commit/78d25cdb12ca9d16b3001c410fd190611a643ce6))
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * The option maxRedirections was removed.
12
+ Drop support for Node 18.
13
+
14
+ ## [4.0.68](https://github.com/eik-lib/rollup-plugin/compare/v4.0.67...v4.0.68) (2025-05-07)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * fixing redirect issue with node v24 ([#233](https://github.com/eik-lib/rollup-plugin/issues/233)) ([8bc43ca](https://github.com/eik-lib/rollup-plugin/commit/8bc43caa1188d1bc3ec4107776908d9760498c47))
20
+
1
21
  ## [4.0.67](https://github.com/eik-lib/rollup-plugin/compare/v4.0.66...v4.0.67) (2025-05-07)
2
22
 
3
23
 
package/dist/plugin.cjs CHANGED
@@ -2,54 +2,12 @@
2
2
 
3
3
  var rollupPluginImportMap = require('rollup-plugin-import-map');
4
4
  var common = require('@eik/common');
5
- var undici = require('undici');
6
5
 
7
6
  /**
8
7
  * @typedef {object} ImportMap
9
8
  * @property {Record<string, string>} imports
10
9
  */
11
10
 
12
- /**
13
- * @param {string[]} urls
14
- * @returns {Promise<ImportMap[]>}
15
- */
16
- const fetchImportMaps = async (urls = []) => {
17
- try {
18
- const maps = urls.map(async (map) => {
19
- const response = await undici.request(map, {
20
- maxRedirections: 2,
21
- });
22
-
23
- if (response.statusCode === 404) {
24
- throw new Error("Import map could not be found on server");
25
- } else if (response.statusCode >= 400 && response.statusCode < 500) {
26
- throw new Error("Server rejected client request");
27
- } else if (response.statusCode >= 500) {
28
- throw new Error("Server error");
29
- }
30
-
31
- let contentType = response.headers["content-type"];
32
- if (!Array.isArray(contentType)) contentType = [contentType];
33
-
34
- if (!contentType.find((type) => type.startsWith("application/json"))) {
35
- const content = await response.body.text();
36
- if (content.length === 0) {
37
- throw new Error(`${map} did not return JSON, got an empty response`);
38
- }
39
- throw new Error(`${map} did not return JSON, got: ${content}`);
40
- }
41
-
42
- const json = await response.body.json();
43
- return /** @type {ImportMap}*/ (json);
44
- });
45
- return await Promise.all(maps);
46
- } catch (err) {
47
- throw new Error(
48
- `Unable to load import map file from server: ${err.message}`,
49
- );
50
- }
51
- };
52
-
53
11
  /**
54
12
  * @typedef {object} PluginOptions
55
13
  * @property {string} [path=process.cwd()] Path to `eik.json`.
@@ -86,12 +44,15 @@ function esmImportToUrl({
86
44
  */
87
45
  async buildStart(options) {
88
46
  // Load eik config from eik.json or package.json
89
- const config = await common.helpers.getDefaults(path);
47
+ const config = common.helpers.getDefaults(path);
90
48
  this.debug(`Loaded eik config ${JSON.stringify(config, null, 2)}`);
91
49
 
92
50
  // Fetch import maps from the server
93
51
  try {
94
- const fetched = await fetchImportMaps([...config.map, ...pUrls]);
52
+ const fetched = await common.helpers.fetchImportMaps([
53
+ ...config.map,
54
+ ...pUrls,
55
+ ]);
95
56
  for (const map of fetched) {
96
57
  this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`);
97
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eik/rollup-plugin",
3
- "version": "4.0.67",
3
+ "version": "5.0.0",
4
4
  "description": "Rollup plugin for loading import maps from a Eik server and applying the mapping to ECMAScript modules in preparation for upload to the same server.",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.cjs",
@@ -63,8 +63,11 @@
63
63
  "typescript": "5.6.3"
64
64
  },
65
65
  "dependencies": {
66
- "@eik/common": "3.0.1",
66
+ "@eik/common": "5.1.0",
67
67
  "rollup-plugin-import-map": "3.0.0",
68
- "undici": "5.29.0"
68
+ "undici": "7.8.0"
69
+ },
70
+ "engines": {
71
+ "node": ">=20"
69
72
  }
70
73
  }
package/src/plugin.js CHANGED
@@ -1,53 +1,11 @@
1
1
  import { rollupImportMapPlugin as importMapPlugin } from "rollup-plugin-import-map";
2
2
  import { helpers } from "@eik/common";
3
- import { request } from "undici";
4
3
 
5
4
  /**
6
5
  * @typedef {object} ImportMap
7
6
  * @property {Record<string, string>} imports
8
7
  */
9
8
 
10
- /**
11
- * @param {string[]} urls
12
- * @returns {Promise<ImportMap[]>}
13
- */
14
- const fetchImportMaps = async (urls = []) => {
15
- try {
16
- const maps = urls.map(async (map) => {
17
- const response = await request(map, {
18
- maxRedirections: 2,
19
- });
20
-
21
- if (response.statusCode === 404) {
22
- throw new Error("Import map could not be found on server");
23
- } else if (response.statusCode >= 400 && response.statusCode < 500) {
24
- throw new Error("Server rejected client request");
25
- } else if (response.statusCode >= 500) {
26
- throw new Error("Server error");
27
- }
28
-
29
- let contentType = response.headers["content-type"];
30
- if (!Array.isArray(contentType)) contentType = [contentType];
31
-
32
- if (!contentType.find((type) => type.startsWith("application/json"))) {
33
- const content = await response.body.text();
34
- if (content.length === 0) {
35
- throw new Error(`${map} did not return JSON, got an empty response`);
36
- }
37
- throw new Error(`${map} did not return JSON, got: ${content}`);
38
- }
39
-
40
- const json = await response.body.json();
41
- return /** @type {ImportMap}*/ (json);
42
- });
43
- return await Promise.all(maps);
44
- } catch (err) {
45
- throw new Error(
46
- `Unable to load import map file from server: ${err.message}`,
47
- );
48
- }
49
- };
50
-
51
9
  /**
52
10
  * @typedef {object} PluginOptions
53
11
  * @property {string} [path=process.cwd()] Path to `eik.json`.
@@ -84,12 +42,15 @@ export default function esmImportToUrl({
84
42
  */
85
43
  async buildStart(options) {
86
44
  // Load eik config from eik.json or package.json
87
- const config = await helpers.getDefaults(path);
45
+ const config = helpers.getDefaults(path);
88
46
  this.debug(`Loaded eik config ${JSON.stringify(config, null, 2)}`);
89
47
 
90
48
  // Fetch import maps from the server
91
49
  try {
92
- const fetched = await fetchImportMaps([...config.map, ...pUrls]);
50
+ const fetched = await helpers.fetchImportMaps([
51
+ ...config.map,
52
+ ...pUrls,
53
+ ]);
93
54
  for (const map of fetched) {
94
55
  this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`);
95
56
  }
package/types/plugin.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @typedef {object} ImportMap
3
+ * @property {Record<string, string>} imports
4
+ */
1
5
  /**
2
6
  * @typedef {object} PluginOptions
3
7
  * @property {string} [path=process.cwd()] Path to `eik.json`.
@@ -15,6 +19,9 @@
15
19
  * @returns {Plugin}
16
20
  */
17
21
  export default function esmImportToUrl({ path, maps, urls, }?: PluginOptions): Plugin;
22
+ export type ImportMap = {
23
+ imports: Record<string, string>;
24
+ };
18
25
  export type PluginOptions = {
19
26
  /**
20
27
  * Path to `eik.json`.
@@ -34,6 +41,3 @@ export type Plugin = {
34
41
  buildStart: (options?: unknown) => Promise<void>;
35
42
  resolveId: (importee?: string) => string;
36
43
  };
37
- export type ImportMap = {
38
- imports: Record<string, string>;
39
- };