@eik/rollup-plugin 4.0.68 → 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 +13 -0
- package/README.md +5 -6
- package/dist/plugin.cjs +5 -58
- package/package.json +5 -2
- package/src/plugin.js +5 -58
- package/types/plugin.d.ts +8 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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
|
+
|
|
1
14
|
## [4.0.68](https://github.com/eik-lib/rollup-plugin/compare/v4.0.67...v4.0.68) (2025-05-07)
|
|
2
15
|
|
|
3
16
|
|
package/README.md
CHANGED
|
@@ -143,12 +143,11 @@ 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
|
|
147
|
-
|
|
148
|
-
| path
|
|
149
|
-
| urls
|
|
150
|
-
| maps
|
|
151
|
-
| maxRedirections | `2` | `number` | `false` | Maximum number of redirects when retrieving import maps. |
|
|
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. |
|
|
152
151
|
|
|
153
152
|
## Note on the rollup external option
|
|
154
153
|
|
package/dist/plugin.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var rollupPluginImportMap = require('rollup-plugin-import-map');
|
|
4
|
-
var undici = require('undici');
|
|
5
4
|
var common = require('@eik/common');
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -9,63 +8,11 @@ var common = require('@eik/common');
|
|
|
9
8
|
* @property {Record<string, string>} imports
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
* @param {string[]} urls
|
|
14
|
-
* @param {object} options
|
|
15
|
-
* @param {number} options.maxRedirections - undici option for limiting redirects
|
|
16
|
-
* @returns {Promise<ImportMap[]>}
|
|
17
|
-
*/
|
|
18
|
-
const fetchImportMaps = async (urls = [], options) => {
|
|
19
|
-
try {
|
|
20
|
-
const maps = urls.map(async (map) => {
|
|
21
|
-
const response = await undici.request(map, {
|
|
22
|
-
dispatcher: new undici.Agent().compose(
|
|
23
|
-
undici.interceptors.redirect({
|
|
24
|
-
maxRedirections: options.maxRedirections,
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
if (response.statusCode === 404) {
|
|
30
|
-
throw new Error("Import map could not be found on server");
|
|
31
|
-
} else if (response.statusCode >= 400 && response.statusCode < 500) {
|
|
32
|
-
throw new Error("Server rejected client request");
|
|
33
|
-
} else if (response.statusCode >= 500) {
|
|
34
|
-
throw new Error("Server error");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let contentType = response.headers["content-type"];
|
|
38
|
-
if (!Array.isArray(contentType)) contentType = [contentType];
|
|
39
|
-
|
|
40
|
-
if (!contentType.find((type) => type.startsWith("application/json"))) {
|
|
41
|
-
const content = await response.body.text();
|
|
42
|
-
if (content.length === 0) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`${map} did not return JSON, got an empty response. HTTP status: ${response.statusCode}`,
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
throw new Error(
|
|
48
|
-
`${map} did not return JSON, got: ${content}. HTTP status: ${response.statusCode}`,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const json = await response.body.json();
|
|
53
|
-
return /** @type {ImportMap}*/ (json);
|
|
54
|
-
});
|
|
55
|
-
return await Promise.all(maps);
|
|
56
|
-
} catch (err) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
`Unable to load import map file from server: ${err.message}`,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
11
|
/**
|
|
64
12
|
* @typedef {object} PluginOptions
|
|
65
13
|
* @property {string} [path=process.cwd()] Path to `eik.json`.
|
|
66
14
|
* @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
|
|
67
15
|
* @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.
|
|
69
16
|
*/
|
|
70
17
|
|
|
71
18
|
/**
|
|
@@ -83,7 +30,6 @@ function esmImportToUrl({
|
|
|
83
30
|
path = process.cwd(),
|
|
84
31
|
maps = [],
|
|
85
32
|
urls = [],
|
|
86
|
-
maxRedirections = 2,
|
|
87
33
|
} = {}) {
|
|
88
34
|
const pMaps = Array.isArray(maps) ? maps : [maps];
|
|
89
35
|
const pUrls = Array.isArray(urls) ? urls : [urls];
|
|
@@ -98,14 +44,15 @@ function esmImportToUrl({
|
|
|
98
44
|
*/
|
|
99
45
|
async buildStart(options) {
|
|
100
46
|
// Load eik config from eik.json or package.json
|
|
101
|
-
const config =
|
|
47
|
+
const config = common.helpers.getDefaults(path);
|
|
102
48
|
this.debug(`Loaded eik config ${JSON.stringify(config, null, 2)}`);
|
|
103
49
|
|
|
104
50
|
// Fetch import maps from the server
|
|
105
51
|
try {
|
|
106
|
-
const fetched = await fetchImportMaps([
|
|
107
|
-
|
|
108
|
-
|
|
52
|
+
const fetched = await common.helpers.fetchImportMaps([
|
|
53
|
+
...config.map,
|
|
54
|
+
...pUrls,
|
|
55
|
+
]);
|
|
109
56
|
for (const map of fetched) {
|
|
110
57
|
this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`);
|
|
111
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eik/rollup-plugin",
|
|
3
|
-
"version": "
|
|
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": "
|
|
66
|
+
"@eik/common": "5.1.0",
|
|
67
67
|
"rollup-plugin-import-map": "3.0.0",
|
|
68
68
|
"undici": "7.8.0"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=20"
|
|
69
72
|
}
|
|
70
73
|
}
|
package/src/plugin.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { rollupImportMapPlugin as importMapPlugin } from "rollup-plugin-import-map";
|
|
2
|
-
import { request, Agent, interceptors } from "undici";
|
|
3
2
|
import { helpers } from "@eik/common";
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -7,63 +6,11 @@ import { helpers } from "@eik/common";
|
|
|
7
6
|
* @property {Record<string, string>} imports
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* @param {string[]} urls
|
|
12
|
-
* @param {object} options
|
|
13
|
-
* @param {number} options.maxRedirections - undici option for limiting redirects
|
|
14
|
-
* @returns {Promise<ImportMap[]>}
|
|
15
|
-
*/
|
|
16
|
-
const fetchImportMaps = async (urls = [], options) => {
|
|
17
|
-
try {
|
|
18
|
-
const maps = urls.map(async (map) => {
|
|
19
|
-
const response = await request(map, {
|
|
20
|
-
dispatcher: new Agent().compose(
|
|
21
|
-
interceptors.redirect({
|
|
22
|
-
maxRedirections: options.maxRedirections,
|
|
23
|
-
}),
|
|
24
|
-
),
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
if (response.statusCode === 404) {
|
|
28
|
-
throw new Error("Import map could not be found on server");
|
|
29
|
-
} else if (response.statusCode >= 400 && response.statusCode < 500) {
|
|
30
|
-
throw new Error("Server rejected client request");
|
|
31
|
-
} else if (response.statusCode >= 500) {
|
|
32
|
-
throw new Error("Server error");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let contentType = response.headers["content-type"];
|
|
36
|
-
if (!Array.isArray(contentType)) contentType = [contentType];
|
|
37
|
-
|
|
38
|
-
if (!contentType.find((type) => type.startsWith("application/json"))) {
|
|
39
|
-
const content = await response.body.text();
|
|
40
|
-
if (content.length === 0) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`${map} did not return JSON, got an empty response. HTTP status: ${response.statusCode}`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
throw new Error(
|
|
46
|
-
`${map} did not return JSON, got: ${content}. HTTP status: ${response.statusCode}`,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const json = await response.body.json();
|
|
51
|
-
return /** @type {ImportMap}*/ (json);
|
|
52
|
-
});
|
|
53
|
-
return await Promise.all(maps);
|
|
54
|
-
} catch (err) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
`Unable to load import map file from server: ${err.message}`,
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
9
|
/**
|
|
62
10
|
* @typedef {object} PluginOptions
|
|
63
11
|
* @property {string} [path=process.cwd()] Path to `eik.json`.
|
|
64
12
|
* @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
|
|
65
13
|
* @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.
|
|
67
14
|
*/
|
|
68
15
|
|
|
69
16
|
/**
|
|
@@ -81,7 +28,6 @@ export default function esmImportToUrl({
|
|
|
81
28
|
path = process.cwd(),
|
|
82
29
|
maps = [],
|
|
83
30
|
urls = [],
|
|
84
|
-
maxRedirections = 2,
|
|
85
31
|
} = {}) {
|
|
86
32
|
const pMaps = Array.isArray(maps) ? maps : [maps];
|
|
87
33
|
const pUrls = Array.isArray(urls) ? urls : [urls];
|
|
@@ -96,14 +42,15 @@ export default function esmImportToUrl({
|
|
|
96
42
|
*/
|
|
97
43
|
async buildStart(options) {
|
|
98
44
|
// Load eik config from eik.json or package.json
|
|
99
|
-
const config =
|
|
45
|
+
const config = helpers.getDefaults(path);
|
|
100
46
|
this.debug(`Loaded eik config ${JSON.stringify(config, null, 2)}`);
|
|
101
47
|
|
|
102
48
|
// Fetch import maps from the server
|
|
103
49
|
try {
|
|
104
|
-
const fetched = await fetchImportMaps([
|
|
105
|
-
|
|
106
|
-
|
|
50
|
+
const fetched = await helpers.fetchImportMaps([
|
|
51
|
+
...config.map,
|
|
52
|
+
...pUrls,
|
|
53
|
+
]);
|
|
107
54
|
for (const map of fetched) {
|
|
108
55
|
this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`);
|
|
109
56
|
}
|
package/types/plugin.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
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`.
|
|
4
8
|
* @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
|
|
5
9
|
* @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.
|
|
7
10
|
*/
|
|
8
11
|
/**
|
|
9
12
|
* @typedef {object} Plugin
|
|
@@ -15,7 +18,10 @@
|
|
|
15
18
|
* @param {PluginOptions} options
|
|
16
19
|
* @returns {Plugin}
|
|
17
20
|
*/
|
|
18
|
-
export default function esmImportToUrl({ path, maps, urls,
|
|
21
|
+
export default function esmImportToUrl({ path, maps, urls, }?: PluginOptions): Plugin;
|
|
22
|
+
export type ImportMap = {
|
|
23
|
+
imports: Record<string, string>;
|
|
24
|
+
};
|
|
19
25
|
export type PluginOptions = {
|
|
20
26
|
/**
|
|
21
27
|
* Path to `eik.json`.
|
|
@@ -29,16 +35,9 @@ export type PluginOptions = {
|
|
|
29
35
|
* Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
|
|
30
36
|
*/
|
|
31
37
|
maps?: ImportMap[];
|
|
32
|
-
/**
|
|
33
|
-
* Maximum number of redirects when looking up URLs.
|
|
34
|
-
*/
|
|
35
|
-
maxRedirections?: number;
|
|
36
38
|
};
|
|
37
39
|
export type Plugin = {
|
|
38
40
|
name: string;
|
|
39
41
|
buildStart: (options?: unknown) => Promise<void>;
|
|
40
42
|
resolveId: (importee?: string) => string;
|
|
41
43
|
};
|
|
42
|
-
export type ImportMap = {
|
|
43
|
-
imports: Record<string, string>;
|
|
44
|
-
};
|