@eik/rollup-plugin 4.0.66 → 4.0.67

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.67](https://github.com/eik-lib/rollup-plugin/compare/v4.0.66...v4.0.67) (2025-05-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * improve logging for non-JSON responses ([#232](https://github.com/eik-lib/rollup-plugin/issues/232)) ([27004b0](https://github.com/eik-lib/rollup-plugin/commit/27004b0fe9c043a8fbfe441d1426e12425bd0584))
7
+
1
8
  ## [4.0.66](https://github.com/eik-lib/rollup-plugin/compare/v4.0.65...v4.0.66) (2025-03-24)
2
9
 
3
10
 
package/dist/plugin.cjs CHANGED
@@ -16,18 +16,31 @@ var undici = require('undici');
16
16
  const fetchImportMaps = async (urls = []) => {
17
17
  try {
18
18
  const maps = urls.map(async (map) => {
19
- const { statusCode, body } = await undici.request(map, {
19
+ const response = await undici.request(map, {
20
20
  maxRedirections: 2,
21
21
  });
22
22
 
23
- if (statusCode === 404) {
23
+ if (response.statusCode === 404) {
24
24
  throw new Error("Import map could not be found on server");
25
- } else if (statusCode >= 400 && statusCode < 500) {
25
+ } else if (response.statusCode >= 400 && response.statusCode < 500) {
26
26
  throw new Error("Server rejected client request");
27
- } else if (statusCode >= 500) {
27
+ } else if (response.statusCode >= 500) {
28
28
  throw new Error("Server error");
29
29
  }
30
- return /** @type {Promise<ImportMap>} */ (body.json());
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);
31
44
  });
32
45
  return await Promise.all(maps);
33
46
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eik/rollup-plugin",
3
- "version": "4.0.66",
3
+ "version": "4.0.67",
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",
@@ -48,11 +48,11 @@
48
48
  },
49
49
  "homepage": "https://github.com/eik-lib/rollup-plugin#readme",
50
50
  "devDependencies": {
51
- "@eik/eslint-config": "1.0.10",
51
+ "@eik/eslint-config": "1.0.13",
52
52
  "@eik/prettier-config": "1.0.1",
53
- "@eik/semantic-release-config": "1.0.0",
53
+ "@eik/semantic-release-config": "1.0.2",
54
54
  "@eik/typescript-config": "1.0.0",
55
- "eslint": "9.21.0",
55
+ "eslint": "9.25.1",
56
56
  "fastify": "4.28.1",
57
57
  "npm-run-all2": "5.0.2",
58
58
  "prettier": "3.4.2",
package/src/plugin.js CHANGED
@@ -14,18 +14,31 @@ import { request } from "undici";
14
14
  const fetchImportMaps = async (urls = []) => {
15
15
  try {
16
16
  const maps = urls.map(async (map) => {
17
- const { statusCode, body } = await request(map, {
17
+ const response = await request(map, {
18
18
  maxRedirections: 2,
19
19
  });
20
20
 
21
- if (statusCode === 404) {
21
+ if (response.statusCode === 404) {
22
22
  throw new Error("Import map could not be found on server");
23
- } else if (statusCode >= 400 && statusCode < 500) {
23
+ } else if (response.statusCode >= 400 && response.statusCode < 500) {
24
24
  throw new Error("Server rejected client request");
25
- } else if (statusCode >= 500) {
25
+ } else if (response.statusCode >= 500) {
26
26
  throw new Error("Server error");
27
27
  }
28
- return /** @type {Promise<ImportMap>} */ (body.json());
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);
29
42
  });
30
43
  return await Promise.all(maps);
31
44
  } catch (err) {