@eik/rollup-plugin 4.0.67 → 4.0.68

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,10 @@
1
+ ## [4.0.68](https://github.com/eik-lib/rollup-plugin/compare/v4.0.67...v4.0.68) (2025-05-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 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))
7
+
1
8
  ## [4.0.67](https://github.com/eik-lib/rollup-plugin/compare/v4.0.66...v4.0.67) (2025-05-07)
2
9
 
3
10
 
package/README.md CHANGED
@@ -143,11 +143,12 @@ import { LitElement, html, css } from "https://cdn.eik.dev/lit-element/v2";
143
143
 
144
144
  This plugin takes an [import map](https://github.com/WICG/import-maps) as options:
145
145
 
146
- | option | default | type | required | details |
147
- | ------ | -------------- | -------- | -------- | --------------------------------------- |
148
- | path | `cwd/eik.json` | `string` | `false` | Path to eik.json file. |
149
- | urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. |
150
- | maps | `[]` | `array` | `false` | Array of import map as objects. |
146
+ | option | default | type | required | details |
147
+ |-------------------|----------------|------------|------------|----------------------------------------------------------|
148
+ | path | `cwd/eik.json` | `string` | `false` | Path to eik.json file. |
149
+ | urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. |
150
+ | maps | `[]` | `array` | `false` | Array of import map as objects. |
151
+ | maxRedirections | `2` | `number` | `false` | Maximum number of redirects when retrieving import maps. |
151
152
 
152
153
  ## Note on the rollup external option
153
154
 
package/dist/plugin.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var rollupPluginImportMap = require('rollup-plugin-import-map');
4
- var common = require('@eik/common');
5
4
  var undici = require('undici');
5
+ var common = require('@eik/common');
6
6
 
7
7
  /**
8
8
  * @typedef {object} ImportMap
@@ -11,13 +11,19 @@ var undici = require('undici');
11
11
 
12
12
  /**
13
13
  * @param {string[]} urls
14
+ * @param {object} options
15
+ * @param {number} options.maxRedirections - undici option for limiting redirects
14
16
  * @returns {Promise<ImportMap[]>}
15
17
  */
16
- const fetchImportMaps = async (urls = []) => {
18
+ const fetchImportMaps = async (urls = [], options) => {
17
19
  try {
18
20
  const maps = urls.map(async (map) => {
19
21
  const response = await undici.request(map, {
20
- maxRedirections: 2,
22
+ dispatcher: new undici.Agent().compose(
23
+ undici.interceptors.redirect({
24
+ maxRedirections: options.maxRedirections,
25
+ }),
26
+ ),
21
27
  });
22
28
 
23
29
  if (response.statusCode === 404) {
@@ -34,9 +40,13 @@ const fetchImportMaps = async (urls = []) => {
34
40
  if (!contentType.find((type) => type.startsWith("application/json"))) {
35
41
  const content = await response.body.text();
36
42
  if (content.length === 0) {
37
- throw new Error(`${map} did not return JSON, got an empty response`);
43
+ throw new Error(
44
+ `${map} did not return JSON, got an empty response. HTTP status: ${response.statusCode}`,
45
+ );
38
46
  }
39
- throw new Error(`${map} did not return JSON, got: ${content}`);
47
+ throw new Error(
48
+ `${map} did not return JSON, got: ${content}. HTTP status: ${response.statusCode}`,
49
+ );
40
50
  }
41
51
 
42
52
  const json = await response.body.json();
@@ -55,6 +65,7 @@ const fetchImportMaps = async (urls = []) => {
55
65
  * @property {string} [path=process.cwd()] Path to `eik.json`.
56
66
  * @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
57
67
  * @property {ImportMap[]} [maps=[]] Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
68
+ * @property {number} [maxRedirections=2] Maximum number of redirects when looking up URLs.
58
69
  */
59
70
 
60
71
  /**
@@ -72,6 +83,7 @@ function esmImportToUrl({
72
83
  path = process.cwd(),
73
84
  maps = [],
74
85
  urls = [],
86
+ maxRedirections = 2,
75
87
  } = {}) {
76
88
  const pMaps = Array.isArray(maps) ? maps : [maps];
77
89
  const pUrls = Array.isArray(urls) ? urls : [urls];
@@ -91,7 +103,9 @@ function esmImportToUrl({
91
103
 
92
104
  // Fetch import maps from the server
93
105
  try {
94
- const fetched = await fetchImportMaps([...config.map, ...pUrls]);
106
+ const fetched = await fetchImportMaps([...config.map, ...pUrls], {
107
+ maxRedirections,
108
+ });
95
109
  for (const map of fetched) {
96
110
  this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`);
97
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eik/rollup-plugin",
3
- "version": "4.0.67",
3
+ "version": "4.0.68",
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",
@@ -65,6 +65,6 @@
65
65
  "dependencies": {
66
66
  "@eik/common": "3.0.1",
67
67
  "rollup-plugin-import-map": "3.0.0",
68
- "undici": "5.29.0"
68
+ "undici": "7.8.0"
69
69
  }
70
70
  }
package/src/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { rollupImportMapPlugin as importMapPlugin } from "rollup-plugin-import-map";
2
+ import { request, Agent, interceptors } from "undici";
2
3
  import { helpers } from "@eik/common";
3
- import { request } from "undici";
4
4
 
5
5
  /**
6
6
  * @typedef {object} ImportMap
@@ -9,13 +9,19 @@ import { request } from "undici";
9
9
 
10
10
  /**
11
11
  * @param {string[]} urls
12
+ * @param {object} options
13
+ * @param {number} options.maxRedirections - undici option for limiting redirects
12
14
  * @returns {Promise<ImportMap[]>}
13
15
  */
14
- const fetchImportMaps = async (urls = []) => {
16
+ const fetchImportMaps = async (urls = [], options) => {
15
17
  try {
16
18
  const maps = urls.map(async (map) => {
17
19
  const response = await request(map, {
18
- maxRedirections: 2,
20
+ dispatcher: new Agent().compose(
21
+ interceptors.redirect({
22
+ maxRedirections: options.maxRedirections,
23
+ }),
24
+ ),
19
25
  });
20
26
 
21
27
  if (response.statusCode === 404) {
@@ -32,9 +38,13 @@ const fetchImportMaps = async (urls = []) => {
32
38
  if (!contentType.find((type) => type.startsWith("application/json"))) {
33
39
  const content = await response.body.text();
34
40
  if (content.length === 0) {
35
- throw new Error(`${map} did not return JSON, got an empty response`);
41
+ throw new Error(
42
+ `${map} did not return JSON, got an empty response. HTTP status: ${response.statusCode}`,
43
+ );
36
44
  }
37
- throw new Error(`${map} did not return JSON, got: ${content}`);
45
+ throw new Error(
46
+ `${map} did not return JSON, got: ${content}. HTTP status: ${response.statusCode}`,
47
+ );
38
48
  }
39
49
 
40
50
  const json = await response.body.json();
@@ -53,6 +63,7 @@ const fetchImportMaps = async (urls = []) => {
53
63
  * @property {string} [path=process.cwd()] Path to `eik.json`.
54
64
  * @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
55
65
  * @property {ImportMap[]} [maps=[]] Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
66
+ * @property {number} [maxRedirections=2] Maximum number of redirects when looking up URLs.
56
67
  */
57
68
 
58
69
  /**
@@ -70,6 +81,7 @@ export default function esmImportToUrl({
70
81
  path = process.cwd(),
71
82
  maps = [],
72
83
  urls = [],
84
+ maxRedirections = 2,
73
85
  } = {}) {
74
86
  const pMaps = Array.isArray(maps) ? maps : [maps];
75
87
  const pUrls = Array.isArray(urls) ? urls : [urls];
@@ -89,7 +101,9 @@ export default function esmImportToUrl({
89
101
 
90
102
  // Fetch import maps from the server
91
103
  try {
92
- const fetched = await fetchImportMaps([...config.map, ...pUrls]);
104
+ const fetched = await fetchImportMaps([...config.map, ...pUrls], {
105
+ maxRedirections,
106
+ });
93
107
  for (const map of fetched) {
94
108
  this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`);
95
109
  }
package/types/plugin.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * @property {string} [path=process.cwd()] Path to `eik.json`.
4
4
  * @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
5
5
  * @property {ImportMap[]} [maps=[]] Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
6
+ * @property {number} [maxRedirections=2] Maximum number of redirects when looking up URLs.
6
7
  */
7
8
  /**
8
9
  * @typedef {object} Plugin
@@ -14,7 +15,7 @@
14
15
  * @param {PluginOptions} options
15
16
  * @returns {Plugin}
16
17
  */
17
- export default function esmImportToUrl({ path, maps, urls, }?: PluginOptions): Plugin;
18
+ export default function esmImportToUrl({ path, maps, urls, maxRedirections, }?: PluginOptions): Plugin;
18
19
  export type PluginOptions = {
19
20
  /**
20
21
  * Path to `eik.json`.
@@ -28,6 +29,10 @@ export type PluginOptions = {
28
29
  * Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
29
30
  */
30
31
  maps?: ImportMap[];
32
+ /**
33
+ * Maximum number of redirects when looking up URLs.
34
+ */
35
+ maxRedirections?: number;
31
36
  };
32
37
  export type Plugin = {
33
38
  name: string;