@eik/rollup-plugin 4.0.63 → 4.0.65
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 +14 -0
- package/README.md +82 -74
- package/dist/plugin.cjs +86 -55
- package/package.json +28 -21
- package/src/plugin.js +89 -57
- package/types/plugin.d.ts +39 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [4.0.65](https://github.com/eik-lib/rollup-plugin/compare/v4.0.64...v4.0.65) (2025-01-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency undici to v5.28.5 ([#223](https://github.com/eik-lib/rollup-plugin/issues/223)) ([0c5174e](https://github.com/eik-lib/rollup-plugin/commit/0c5174e72e36f2b4ff371c8ebebf890fd0cc2d56))
|
|
7
|
+
|
|
8
|
+
## [4.0.64](https://github.com/eik-lib/rollup-plugin/compare/v4.0.63...v4.0.64) (2024-08-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* include type definitions ([3aa898f](https://github.com/eik-lib/rollup-plugin/commit/3aa898fafeb64bcfc798f2267d2e5c0f2c782b45))
|
|
14
|
+
|
|
1
15
|
## [4.0.63](https://github.com/eik-lib/rollup-plugin/compare/v4.0.62...v4.0.63) (2024-04-04)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Rollup [Eik](https://eik.dev/) plugin to support the use of import maps to map "
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
npm install @eik/rollup-plugin
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
@@ -16,12 +16,12 @@ $ npm install @eik/rollup-plugin
|
|
|
16
16
|
import plugin from "@eik/rollup-plugin";
|
|
17
17
|
|
|
18
18
|
export default {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
input: "source/main.js",
|
|
20
|
+
plugins: [plugin()],
|
|
21
|
+
output: {
|
|
22
|
+
file: "build.js",
|
|
23
|
+
format: "esm",
|
|
24
|
+
},
|
|
25
25
|
};
|
|
26
26
|
```
|
|
27
27
|
|
|
@@ -36,12 +36,12 @@ The plugin will attempt to read import map URLs from `eik.json` if present.
|
|
|
36
36
|
|
|
37
37
|
```js
|
|
38
38
|
export default {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
input: "source/main.js",
|
|
40
|
+
plugins: [plugin()],
|
|
41
|
+
output: {
|
|
42
|
+
file: "build.js",
|
|
43
|
+
format: "esm",
|
|
44
|
+
},
|
|
45
45
|
};
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -49,12 +49,12 @@ The path to the location of an `eik.json` file can be specified with the `path`
|
|
|
49
49
|
|
|
50
50
|
```js
|
|
51
51
|
export default {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
input: "source/main.js",
|
|
53
|
+
plugins: [plugin({ path: "/path/to/eik-json-folder" })],
|
|
54
|
+
output: {
|
|
55
|
+
file: "build.js",
|
|
56
|
+
format: "esm",
|
|
57
|
+
},
|
|
58
58
|
};
|
|
59
59
|
```
|
|
60
60
|
|
|
@@ -62,12 +62,12 @@ The plugin can also be told which URLs to load import maps from directly using t
|
|
|
62
62
|
|
|
63
63
|
```js
|
|
64
64
|
export default {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
input: "source/main.js",
|
|
66
|
+
plugins: [plugin({ urls: `http://myserver/import-map` })],
|
|
67
|
+
output: {
|
|
68
|
+
file: "build.js",
|
|
69
|
+
format: "esm",
|
|
70
|
+
},
|
|
71
71
|
};
|
|
72
72
|
```
|
|
73
73
|
|
|
@@ -75,20 +75,22 @@ Additionally, individual mappings can be specified using the `maps` option.
|
|
|
75
75
|
|
|
76
76
|
```js
|
|
77
77
|
export default {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
input: "source/main.js",
|
|
79
|
+
plugins: [
|
|
80
|
+
plugin({
|
|
81
|
+
maps: [
|
|
82
|
+
{
|
|
83
|
+
imports: {
|
|
84
|
+
"lit-element": "https://cdn.eik.dev/lit-element/v2",
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
}),
|
|
89
|
+
],
|
|
90
|
+
output: {
|
|
91
|
+
file: "build.js",
|
|
92
|
+
format: "esm",
|
|
93
|
+
},
|
|
92
94
|
};
|
|
93
95
|
```
|
|
94
96
|
|
|
@@ -98,20 +100,24 @@ ie. in the following example
|
|
|
98
100
|
|
|
99
101
|
```js
|
|
100
102
|
export default {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
input: "source/main.js",
|
|
104
|
+
plugins: [
|
|
105
|
+
plugin({
|
|
106
|
+
path: "/path/to/eik-json-folder",
|
|
107
|
+
urls: ["http://myserver/import-map"],
|
|
108
|
+
maps: [
|
|
109
|
+
{
|
|
110
|
+
imports: {
|
|
111
|
+
"lit-element": "https://cdn.eik.dev/lit-element/v2",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
}),
|
|
116
|
+
],
|
|
117
|
+
output: {
|
|
118
|
+
file: "build.js",
|
|
119
|
+
format: "esm",
|
|
120
|
+
},
|
|
115
121
|
};
|
|
116
122
|
```
|
|
117
123
|
|
|
@@ -119,7 +125,7 @@ Any import map URLs in `eik.json` will be loaded first, then merged with (and ov
|
|
|
119
125
|
|
|
120
126
|
### Plugin result
|
|
121
127
|
|
|
122
|
-
Bundles will have bare imports mapped to absolute URLs.
|
|
128
|
+
Bundles will have bare imports mapped to absolute URLs.
|
|
123
129
|
|
|
124
130
|
Ie. Something like this...
|
|
125
131
|
|
|
@@ -137,11 +143,11 @@ import { LitElement, html, css } from "https://cdn.eik.dev/lit-element/v2";
|
|
|
137
143
|
|
|
138
144
|
This plugin takes an [import map](https://github.com/WICG/import-maps) as options:
|
|
139
145
|
|
|
140
|
-
| option
|
|
141
|
-
|
|
|
142
|
-
| path
|
|
143
|
-
| urls
|
|
144
|
-
| 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. |
|
|
145
151
|
|
|
146
152
|
## Note on the rollup external option
|
|
147
153
|
|
|
@@ -152,21 +158,23 @@ In other words, this will not work:
|
|
|
152
158
|
|
|
153
159
|
```js
|
|
154
160
|
export default {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
161
|
+
input: "source/main.js",
|
|
162
|
+
external: ["lit-element"],
|
|
163
|
+
plugins: [
|
|
164
|
+
plugin({
|
|
165
|
+
maps: [
|
|
166
|
+
{
|
|
167
|
+
imports: {
|
|
168
|
+
"lit-element": "https://cdn.eik.dev/lit-element/v2",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
}),
|
|
173
|
+
],
|
|
174
|
+
output: {
|
|
175
|
+
file: "build.js",
|
|
176
|
+
format: "esm",
|
|
177
|
+
},
|
|
170
178
|
};
|
|
171
179
|
```
|
|
172
180
|
|
package/dist/plugin.cjs
CHANGED
|
@@ -4,72 +4,103 @@ var rollupPluginImportMap = require('rollup-plugin-import-map');
|
|
|
4
4
|
var common = require('@eik/common');
|
|
5
5
|
var undici = require('undici');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} ImportMap
|
|
9
|
+
* @property {Record<string, string>} imports
|
|
10
|
+
*/
|
|
9
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @param {string[]} urls
|
|
14
|
+
* @returns {Promise<ImportMap[]>}
|
|
15
|
+
*/
|
|
10
16
|
const fetchImportMaps = async (urls = []) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = await undici.request(map, { maxRedirections: 2 });
|
|
17
|
+
try {
|
|
18
|
+
const maps = urls.map(async (map) => {
|
|
19
|
+
const { statusCode, body } = await undici.request(map, {
|
|
20
|
+
maxRedirections: 2,
|
|
21
|
+
});
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
if (statusCode === 404) {
|
|
24
|
+
throw new Error("Import map could not be found on server");
|
|
25
|
+
} else if (statusCode >= 400 && statusCode < 500) {
|
|
26
|
+
throw new Error("Server rejected client request");
|
|
27
|
+
} else if (statusCode >= 500) {
|
|
28
|
+
throw new Error("Server error");
|
|
29
|
+
}
|
|
30
|
+
return /** @type {Promise<ImportMap>} */ (body.json());
|
|
31
|
+
});
|
|
32
|
+
return await Promise.all(maps);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Unable to load import map file from server: ${err.message}`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
33
38
|
};
|
|
34
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {object} PluginOptions
|
|
42
|
+
* @property {string} [path=process.cwd()] Path to `eik.json`.
|
|
43
|
+
* @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
|
|
44
|
+
* @property {ImportMap[]} [maps=[]] Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {object} Plugin
|
|
49
|
+
* @property {string} name
|
|
50
|
+
* @property {(options?: unknown) => Promise<void>} buildStart
|
|
51
|
+
* @property {(importee?: string) => string} resolveId
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {PluginOptions} options
|
|
56
|
+
* @returns {Plugin}
|
|
57
|
+
*/
|
|
35
58
|
function esmImportToUrl({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
path = process.cwd(),
|
|
60
|
+
maps = [],
|
|
61
|
+
urls = [],
|
|
39
62
|
} = {}) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
63
|
+
const pMaps = Array.isArray(maps) ? maps : [maps];
|
|
64
|
+
const pUrls = Array.isArray(urls) ? urls : [urls];
|
|
65
|
+
let plugin;
|
|
43
66
|
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
return {
|
|
68
|
+
name: "eik-rollup-plugin",
|
|
46
69
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
70
|
+
/**
|
|
71
|
+
* @this {import('rollup').PluginContext}
|
|
72
|
+
* @param {unknown} [options]
|
|
73
|
+
*/
|
|
74
|
+
async buildStart(options) {
|
|
75
|
+
// Load eik config from eik.json or package.json
|
|
76
|
+
const config = await common.helpers.getDefaults(path);
|
|
77
|
+
this.debug(`Loaded eik config ${JSON.stringify(config, null, 2)}`);
|
|
51
78
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
// Fetch import maps from the server
|
|
80
|
+
try {
|
|
81
|
+
const fetched = await fetchImportMaps([...config.map, ...pUrls]);
|
|
82
|
+
for (const map of fetched) {
|
|
83
|
+
this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`);
|
|
84
|
+
}
|
|
85
|
+
plugin = rollupPluginImportMap.rollupImportMapPlugin([...fetched, ...pMaps]);
|
|
86
|
+
await plugin.buildStart(options);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
this.error(err.message);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
64
91
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
92
|
+
/**
|
|
93
|
+
* @this {import('rollup').PluginContext}
|
|
94
|
+
* @param {string} [importee]
|
|
95
|
+
*/
|
|
96
|
+
resolveId(importee) {
|
|
97
|
+
const resolved = plugin.resolveId(importee);
|
|
98
|
+
if (resolved) {
|
|
99
|
+
this.debug(`Resolved ${importee} to ${resolved.id}`);
|
|
100
|
+
}
|
|
101
|
+
return resolved;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
73
104
|
}
|
|
74
105
|
|
|
75
106
|
module.exports = esmImportToUrl;
|
package/package.json
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eik/rollup-plugin",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.65",
|
|
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",
|
|
7
|
+
"types": "./types/plugin.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
"import": "./src/plugin.js",
|
|
10
|
+
"types": "./types/plugin.d.ts",
|
|
9
11
|
"require": "./dist/plugin.cjs"
|
|
10
12
|
},
|
|
11
13
|
"files": [
|
|
12
14
|
"CHANGELOG.md",
|
|
13
15
|
"package.json",
|
|
14
16
|
"src",
|
|
15
|
-
"dist"
|
|
17
|
+
"dist",
|
|
18
|
+
"types"
|
|
16
19
|
],
|
|
17
|
-
"directories": {
|
|
18
|
-
"dist": "dist"
|
|
19
|
-
},
|
|
20
20
|
"scripts": {
|
|
21
|
+
"clean": "rimraf .tap dist node_modules types",
|
|
21
22
|
"prepare": "npm run -s build",
|
|
22
|
-
"test": "tap --
|
|
23
|
-
"
|
|
24
|
-
"lint": "
|
|
25
|
-
"lint:fix": "eslint . --fix --ext=js",
|
|
23
|
+
"test": "tap --disable-coverage --allow-empty-coverage",
|
|
24
|
+
"lint": "eslint .",
|
|
25
|
+
"lint:fix": "npm run lint -- --fix",
|
|
26
26
|
"start": "node --experimental-modules ./example/server.mjs",
|
|
27
|
-
"build": "rollup -c"
|
|
27
|
+
"build": "rollup -c",
|
|
28
|
+
"types": "run-s types:module types:test",
|
|
29
|
+
"types:module": "tsc",
|
|
30
|
+
"types:test": "tsc --project tsconfig.test.json"
|
|
28
31
|
},
|
|
29
32
|
"repository": {
|
|
30
33
|
"type": "git",
|
|
@@ -45,19 +48,23 @@
|
|
|
45
48
|
},
|
|
46
49
|
"homepage": "https://github.com/eik-lib/rollup-plugin#readme",
|
|
47
50
|
"devDependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"eslint
|
|
53
|
-
"fastify": "4.
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
51
|
+
"@eik/eslint-config": "1.0.7",
|
|
52
|
+
"@eik/prettier-config": "1.0.1",
|
|
53
|
+
"@eik/semantic-release-config": "1.0.0",
|
|
54
|
+
"@eik/typescript-config": "1.0.0",
|
|
55
|
+
"eslint": "9.16.0",
|
|
56
|
+
"fastify": "4.28.1",
|
|
57
|
+
"npm-run-all2": "5.0.2",
|
|
58
|
+
"prettier": "3.4.2",
|
|
59
|
+
"rimraf": "6.0.1",
|
|
60
|
+
"rollup": "4.28.0",
|
|
61
|
+
"semantic-release": "23.1.1",
|
|
62
|
+
"tap": "20.0.3",
|
|
63
|
+
"typescript": "5.6.3"
|
|
57
64
|
},
|
|
58
65
|
"dependencies": {
|
|
59
66
|
"@eik/common": "3.0.1",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
67
|
+
"rollup-plugin-import-map": "3.0.0",
|
|
68
|
+
"undici": "5.28.5"
|
|
62
69
|
}
|
|
63
70
|
}
|
package/src/plugin.js
CHANGED
|
@@ -1,70 +1,102 @@
|
|
|
1
|
-
|
|
1
|
+
import { rollupImportMapPlugin as importMapPlugin } from "rollup-plugin-import-map";
|
|
2
|
+
import { helpers } from "@eik/common";
|
|
3
|
+
import { request } from "undici";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} ImportMap
|
|
7
|
+
* @property {Record<string, string>} imports
|
|
8
|
+
*/
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @param {string[]} urls
|
|
12
|
+
* @returns {Promise<ImportMap[]>}
|
|
13
|
+
*/
|
|
7
14
|
const fetchImportMaps = async (urls = []) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = await request(map, { maxRedirections: 2 });
|
|
15
|
+
try {
|
|
16
|
+
const maps = urls.map(async (map) => {
|
|
17
|
+
const { statusCode, body } = await request(map, {
|
|
18
|
+
maxRedirections: 2,
|
|
19
|
+
});
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
if (statusCode === 404) {
|
|
22
|
+
throw new Error("Import map could not be found on server");
|
|
23
|
+
} else if (statusCode >= 400 && statusCode < 500) {
|
|
24
|
+
throw new Error("Server rejected client request");
|
|
25
|
+
} else if (statusCode >= 500) {
|
|
26
|
+
throw new Error("Server error");
|
|
27
|
+
}
|
|
28
|
+
return /** @type {Promise<ImportMap>} */ (body.json());
|
|
29
|
+
});
|
|
30
|
+
return await Promise.all(maps);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Unable to load import map file from server: ${err.message}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
30
36
|
};
|
|
31
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {object} PluginOptions
|
|
40
|
+
* @property {string} [path=process.cwd()] Path to `eik.json`.
|
|
41
|
+
* @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
|
|
42
|
+
* @property {ImportMap[]} [maps=[]] Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {object} Plugin
|
|
47
|
+
* @property {string} name
|
|
48
|
+
* @property {(options?: unknown) => Promise<void>} buildStart
|
|
49
|
+
* @property {(importee?: string) => string} resolveId
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {PluginOptions} options
|
|
54
|
+
* @returns {Plugin}
|
|
55
|
+
*/
|
|
32
56
|
export default function esmImportToUrl({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
57
|
+
path = process.cwd(),
|
|
58
|
+
maps = [],
|
|
59
|
+
urls = [],
|
|
36
60
|
} = {}) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
const pMaps = Array.isArray(maps) ? maps : [maps];
|
|
62
|
+
const pUrls = Array.isArray(urls) ? urls : [urls];
|
|
63
|
+
let plugin;
|
|
40
64
|
|
|
41
|
-
|
|
42
|
-
|
|
65
|
+
return {
|
|
66
|
+
name: "eik-rollup-plugin",
|
|
43
67
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @this {import('rollup').PluginContext}
|
|
70
|
+
* @param {unknown} [options]
|
|
71
|
+
*/
|
|
72
|
+
async buildStart(options) {
|
|
73
|
+
// Load eik config from eik.json or package.json
|
|
74
|
+
const config = await helpers.getDefaults(path);
|
|
75
|
+
this.debug(`Loaded eik config ${JSON.stringify(config, null, 2)}`);
|
|
48
76
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
// Fetch import maps from the server
|
|
78
|
+
try {
|
|
79
|
+
const fetched = await fetchImportMaps([...config.map, ...pUrls]);
|
|
80
|
+
for (const map of fetched) {
|
|
81
|
+
this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`);
|
|
82
|
+
}
|
|
83
|
+
plugin = importMapPlugin([...fetched, ...pMaps]);
|
|
84
|
+
await plugin.buildStart(options);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
this.error(err.message);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
61
89
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @this {import('rollup').PluginContext}
|
|
92
|
+
* @param {string} [importee]
|
|
93
|
+
*/
|
|
94
|
+
resolveId(importee) {
|
|
95
|
+
const resolved = plugin.resolveId(importee);
|
|
96
|
+
if (resolved) {
|
|
97
|
+
this.debug(`Resolved ${importee} to ${resolved.id}`);
|
|
98
|
+
}
|
|
99
|
+
return resolved;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
70
102
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PluginOptions
|
|
3
|
+
* @property {string} [path=process.cwd()] Path to `eik.json`.
|
|
4
|
+
* @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
|
|
5
|
+
* @property {ImportMap[]} [maps=[]] Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} Plugin
|
|
9
|
+
* @property {string} name
|
|
10
|
+
* @property {(options?: unknown) => Promise<void>} buildStart
|
|
11
|
+
* @property {(importee?: string) => string} resolveId
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @param {PluginOptions} options
|
|
15
|
+
* @returns {Plugin}
|
|
16
|
+
*/
|
|
17
|
+
export default function esmImportToUrl({ path, maps, urls, }?: PluginOptions): Plugin;
|
|
18
|
+
export type PluginOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Path to `eik.json`.
|
|
21
|
+
*/
|
|
22
|
+
path?: string;
|
|
23
|
+
/**
|
|
24
|
+
* URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
|
|
25
|
+
*/
|
|
26
|
+
urls?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
|
|
29
|
+
*/
|
|
30
|
+
maps?: ImportMap[];
|
|
31
|
+
};
|
|
32
|
+
export type Plugin = {
|
|
33
|
+
name: string;
|
|
34
|
+
buildStart: (options?: unknown) => Promise<void>;
|
|
35
|
+
resolveId: (importee?: string) => string;
|
|
36
|
+
};
|
|
37
|
+
export type ImportMap = {
|
|
38
|
+
imports: Record<string, string>;
|
|
39
|
+
};
|