@eik/esbuild-plugin 1.0.4 → 1.1.2
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/package.json +13 -16
- package/src/plugin.js +17 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eik/esbuild-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "ESBuild 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": "./src/plugin.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "tap --no-coverage",
|
|
12
|
-
"test:snapshot": "TAP_SNAPSHOT=1 tap
|
|
12
|
+
"test:snapshot": "TAP_SNAPSHOT=1 tap test/*.js --no-coverage",
|
|
13
13
|
"lint": "eslint . --ext=js",
|
|
14
14
|
"lint:fix": "eslint . --fix --ext=js"
|
|
15
15
|
},
|
|
@@ -35,22 +35,19 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/eik-lib/esbuild-plugin#readme",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@semantic-release/changelog": "
|
|
39
|
-
"@semantic-release/
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"eslint-plugin-import": "2.24.0",
|
|
48
|
-
"fastify": "3.13.0",
|
|
49
|
-
"semantic-release": "17.4.7",
|
|
50
|
-
"tap": "15.0.5"
|
|
38
|
+
"@semantic-release/changelog": "6.0.1",
|
|
39
|
+
"@semantic-release/git": "10.0.1",
|
|
40
|
+
"esbuild": "0.14.13",
|
|
41
|
+
"eslint": "8.7.0",
|
|
42
|
+
"eslint-config-airbnb-base": "15.0.0",
|
|
43
|
+
"eslint-plugin-import": "2.25.4",
|
|
44
|
+
"fastify": "3.27.0",
|
|
45
|
+
"semantic-release": "19.0.2",
|
|
46
|
+
"tap": "15.1.6"
|
|
51
47
|
},
|
|
52
48
|
"dependencies": {
|
|
49
|
+
"@eik/common": "3.0.0",
|
|
53
50
|
"esbuild-plugin-import-map": "2.1.0",
|
|
54
|
-
"
|
|
51
|
+
"undici": "4.12.2"
|
|
55
52
|
}
|
|
56
53
|
}
|
package/src/plugin.js
CHANGED
|
@@ -1,55 +1,45 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-syntax */
|
|
2
2
|
|
|
3
3
|
import * as importMapPlugin from 'esbuild-plugin-import-map';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import fs from 'fs';
|
|
4
|
+
import { helpers } from '@eik/common';
|
|
5
|
+
import { request } from 'undici';
|
|
7
6
|
|
|
8
|
-
async
|
|
7
|
+
const fetchImportMaps = async (urls = []) => {
|
|
9
8
|
try {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
9
|
+
const maps = urls.map(async (map) => {
|
|
10
|
+
const {
|
|
11
|
+
statusCode,
|
|
12
|
+
body,
|
|
13
|
+
} = await request(map, { maxRedirections: 2 });
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const maps = urls.map((map) => fetch(map).then((result) => {
|
|
22
|
-
if (result.status === 404) {
|
|
15
|
+
if (statusCode === 404) {
|
|
23
16
|
throw new Error('Import map could not be found on server');
|
|
24
|
-
} else if (
|
|
17
|
+
} else if (statusCode >= 400 && statusCode < 500) {
|
|
25
18
|
throw new Error('Server rejected client request');
|
|
26
|
-
} else if (
|
|
19
|
+
} else if (statusCode >= 500) {
|
|
27
20
|
throw new Error('Server error');
|
|
28
21
|
}
|
|
29
|
-
return
|
|
30
|
-
})
|
|
22
|
+
return body.json();
|
|
23
|
+
});
|
|
31
24
|
return await Promise.all(maps);
|
|
32
25
|
} catch (err) {
|
|
33
26
|
throw new Error(
|
|
34
27
|
`Unable to load import map file from server: ${err.message}`,
|
|
35
28
|
);
|
|
36
29
|
}
|
|
37
|
-
}
|
|
30
|
+
};
|
|
38
31
|
|
|
39
32
|
export async function load({
|
|
40
|
-
path =
|
|
33
|
+
path = process.cwd(),
|
|
41
34
|
maps = [],
|
|
42
35
|
urls = [],
|
|
43
36
|
} = {}) {
|
|
44
37
|
const pMaps = Array.isArray(maps) ? maps : [maps];
|
|
45
38
|
const pUrls = Array.isArray(urls) ? urls : [urls];
|
|
46
39
|
|
|
47
|
-
const
|
|
48
|
-
for (const map of importMapUrls) {
|
|
49
|
-
pUrls.push(map);
|
|
50
|
-
}
|
|
40
|
+
const config = await helpers.getDefaults(path);
|
|
51
41
|
|
|
52
|
-
const fetched = await fetchImportMaps(pUrls);
|
|
42
|
+
const fetched = await fetchImportMaps([...config.map, ...pUrls]);
|
|
53
43
|
const mappings = pMaps.concat(fetched);
|
|
54
44
|
|
|
55
45
|
await importMapPlugin.load(mappings);
|