@eik/node-client 2.0.0-next.3 → 2.0.0-next.5
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 +28 -0
- package/README.md +31 -0
- package/package.json +3 -11
- package/src/index.js +21 -10
- package/dist/index.cjs +0 -122
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [2.0.0-next.5](https://github.com/eik-lib/node-client/compare/v2.0.0-next.4...v2.0.0-next.5) (2022-09-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add .mapping(dep) shorthand method to resolve mapped bare imports directly ([a557cfd](https://github.com/eik-lib/node-client/commit/a557cfdc56f4553f721d1a67a7670eafc284b565))
|
|
7
|
+
|
|
8
|
+
# [2.0.0-next.4](https://github.com/eik-lib/node-client/compare/v2.0.0-next.3...v2.0.0-next.4) (2022-08-22)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* Remove support for CJS. ESM only ([#106](https://github.com/eik-lib/node-client/issues/106)) ([d74f8c8](https://github.com/eik-lib/node-client/commit/d74f8c8266b67119d8d110524533a0bd7ce19e7d))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* This PR removes the support for CJS in this module. This module is now ESM only.
|
|
19
|
+
|
|
20
|
+
* feat: Remove CJS support. ESM only.
|
|
21
|
+
* Support for CJS is now removed in this module. It is ESM only.
|
|
22
|
+
|
|
23
|
+
* ci: use 0.0.0.0 instead of localhost
|
|
24
|
+
|
|
25
|
+
* fix: remove console.log() statement
|
|
26
|
+
|
|
27
|
+
Co-authored-by: Trygve Lie <trygve.lie@finn.no>
|
|
28
|
+
|
|
1
29
|
# [2.0.0-next.3](https://github.com/eik-lib/node-client/compare/v2.0.0-next.2...v2.0.0-next.3) (2022-08-18)
|
|
2
30
|
|
|
3
31
|
|
package/README.md
CHANGED
|
@@ -187,6 +187,37 @@ If `integrity` of the file is not available, the value for `integrity` will be `
|
|
|
187
187
|
|
|
188
188
|
Returns the import maps defined in Eik config from the Eik server. For the maps to be returned they need to be loaded from the Eik server. This is done by setting the `loadMaps` option on the constructor to `true`.
|
|
189
189
|
|
|
190
|
+
### .mapping(identifier)
|
|
191
|
+
|
|
192
|
+
Returns the last mapping entry for a given bare import `identifier`.
|
|
193
|
+
`identifier` is a `string` key from an import map and the returned `string` is a the matching value from the same import map entry.
|
|
194
|
+
|
|
195
|
+
#### arguments
|
|
196
|
+
|
|
197
|
+
| option | default | type | required | details |
|
|
198
|
+
| ---------- | ------- | -------- | -------- | ------------------- |
|
|
199
|
+
| identifier | | `string` | `true` | Bare import map key |
|
|
200
|
+
|
|
201
|
+
**Example:**
|
|
202
|
+
|
|
203
|
+
If an import map being used looks like:
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"imports": {
|
|
208
|
+
"react": "https://myserver.com/react/18.0.0/react.min.js"
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
When the mapping method is called:
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
const absoluteURL = client.mapping('react');
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`absoluteURL` will be `https://myserver.com/react/18.0.0/react.min.js`
|
|
220
|
+
|
|
190
221
|
## License
|
|
191
222
|
|
|
192
223
|
Copyright (c) 2021 FINN.no
|
package/package.json
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eik/node-client",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.5",
|
|
4
4
|
"description": "A node.js client for interacting with a Eik server.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./
|
|
7
|
-
"exports": {
|
|
8
|
-
"import": "./src/index.js",
|
|
9
|
-
"require": "./dist/index.cjs"
|
|
10
|
-
},
|
|
6
|
+
"main": "./src/index.js",
|
|
11
7
|
"files": [
|
|
12
8
|
"CHANGELOG.md",
|
|
13
9
|
"package.json",
|
|
14
10
|
"LICENSE",
|
|
15
|
-
"dist",
|
|
16
11
|
"src"
|
|
17
12
|
],
|
|
18
13
|
"scripts": {
|
|
19
14
|
"test": "tap --no-coverage",
|
|
20
15
|
"lint:fix": "eslint --fix .",
|
|
21
|
-
"lint": "eslint ."
|
|
22
|
-
"prepare": "npm run -s build",
|
|
23
|
-
"build": "rollup -c"
|
|
16
|
+
"lint": "eslint ."
|
|
24
17
|
},
|
|
25
18
|
"repository": {
|
|
26
19
|
"type": "git",
|
|
@@ -50,7 +43,6 @@
|
|
|
50
43
|
"eslint-plugin-import": "2.26.0",
|
|
51
44
|
"eslint-plugin-prettier": "4.2.1",
|
|
52
45
|
"prettier": "2.7.1",
|
|
53
|
-
"rollup": "2.77.2",
|
|
54
46
|
"semantic-release": "19.0.3",
|
|
55
47
|
"tap": "16.3.0",
|
|
56
48
|
"@babel/eslint-parser": "7.18.9"
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
1
2
|
import { request } from 'undici';
|
|
2
3
|
import { join } from 'path';
|
|
3
4
|
import loader from '@eik/common-config-loader';
|
|
@@ -6,16 +7,15 @@ import Asset from './asset.js';
|
|
|
6
7
|
const trimSlash = (value = '') => {
|
|
7
8
|
if (value.endsWith('/')) return value.substring(0, value.length - 1);
|
|
8
9
|
return value;
|
|
9
|
-
}
|
|
10
|
+
};
|
|
10
11
|
|
|
11
12
|
const fetchImportMaps = async (urls = []) => {
|
|
12
|
-
try{
|
|
13
|
+
try {
|
|
13
14
|
const maps = urls.map(async (map) => {
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const { statusCode, body } = await request(map, {
|
|
16
|
+
maxRedirections: 2,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
19
|
if (statusCode === 404) {
|
|
20
20
|
throw new Error('Import map could not be found on server');
|
|
21
21
|
} else if (statusCode >= 400 && statusCode < 500) {
|
|
@@ -31,7 +31,7 @@ const fetchImportMaps = async (urls = []) => {
|
|
|
31
31
|
`Unable to load import map file from server: ${err.message}`,
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
|
|
36
36
|
export default class NodeClient {
|
|
37
37
|
#development;
|
|
@@ -83,7 +83,8 @@ export default class NodeClient {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
get pathname() {
|
|
86
|
-
if (this.#config.type && this.#config.name && this.#config.version)
|
|
86
|
+
if (this.#config.type && this.#config.name && this.#config.version)
|
|
87
|
+
return join('/', this.type, this.name, this.version);
|
|
87
88
|
throw new Error('Eik config was not loaded before calling .pathname');
|
|
88
89
|
}
|
|
89
90
|
|
|
@@ -101,6 +102,16 @@ export default class NodeClient {
|
|
|
101
102
|
|
|
102
103
|
maps() {
|
|
103
104
|
if (this.#config.version && this.#loadMaps) return this.#maps;
|
|
104
|
-
throw new Error(
|
|
105
|
+
throw new Error(
|
|
106
|
+
'Eik config was not loaded or "loadMaps" is "false" when calling .maps()',
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
mapping(dependency) {
|
|
111
|
+
let mapping = null;
|
|
112
|
+
for (const map of this.maps()) {
|
|
113
|
+
if (map?.imports[dependency]) mapping = map.imports[dependency];
|
|
114
|
+
}
|
|
115
|
+
return mapping;
|
|
105
116
|
}
|
|
106
117
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var undici = require('undici');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var loader = require('@eik/common-config-loader');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
-
|
|
9
|
-
var loader__default = /*#__PURE__*/_interopDefaultLegacy(loader);
|
|
10
|
-
|
|
11
|
-
class Asset {
|
|
12
|
-
constructor({
|
|
13
|
-
value = '',
|
|
14
|
-
} = {}) {
|
|
15
|
-
this.integrity = undefined;
|
|
16
|
-
this.value = value;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const trimSlash = (value = '') => {
|
|
21
|
-
if (value.endsWith('/')) return value.substring(0, value.length - 1);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const fetchImportMaps = async (urls = []) => {
|
|
26
|
-
try{
|
|
27
|
-
const maps = urls.map(async (map) => {
|
|
28
|
-
const {
|
|
29
|
-
statusCode,
|
|
30
|
-
body
|
|
31
|
-
} = await undici.request(map, { maxRedirections: 2 });
|
|
32
|
-
|
|
33
|
-
if (statusCode === 404) {
|
|
34
|
-
throw new Error('Import map could not be found on server');
|
|
35
|
-
} else if (statusCode >= 400 && statusCode < 500) {
|
|
36
|
-
throw new Error('Server rejected client request');
|
|
37
|
-
} else if (statusCode >= 500) {
|
|
38
|
-
throw new Error('Server error');
|
|
39
|
-
}
|
|
40
|
-
return body.json();
|
|
41
|
-
});
|
|
42
|
-
return await Promise.all(maps);
|
|
43
|
-
} catch (err) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
`Unable to load import map file from server: ${err.message}`,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
class NodeClient {
|
|
51
|
-
#development;
|
|
52
|
-
#loadMaps;
|
|
53
|
-
#config;
|
|
54
|
-
#path;
|
|
55
|
-
#base;
|
|
56
|
-
#maps;
|
|
57
|
-
constructor({
|
|
58
|
-
development = false,
|
|
59
|
-
loadMaps = false,
|
|
60
|
-
base = '',
|
|
61
|
-
path = process.cwd(),
|
|
62
|
-
} = {}) {
|
|
63
|
-
this.#development = development;
|
|
64
|
-
this.#loadMaps = loadMaps;
|
|
65
|
-
this.#config = {};
|
|
66
|
-
this.#path = path;
|
|
67
|
-
this.#base = trimSlash(base);
|
|
68
|
-
this.#maps = [];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async load() {
|
|
72
|
-
this.#config = await loader__default["default"].getDefaults(this.#path);
|
|
73
|
-
if (this.#loadMaps) {
|
|
74
|
-
this.#maps = await fetchImportMaps(this.#config.map);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get name() {
|
|
79
|
-
if (this.#config.name) return this.#config.name;
|
|
80
|
-
throw new Error('Eik config was not loaded before calling .name');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get version() {
|
|
84
|
-
if (this.#config.version) return this.#config.version;
|
|
85
|
-
throw new Error('Eik config was not loaded before calling .version');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
get type() {
|
|
89
|
-
if (this.#config.type && this.#config.type === 'package') return 'pkg';
|
|
90
|
-
if (this.#config.type) return this.#config.type;
|
|
91
|
-
throw new Error('Eik config was not loaded before calling .type');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
get server() {
|
|
95
|
-
if (this.#config.server) return this.#config.server;
|
|
96
|
-
throw new Error('Eik config was not loaded before calling .server');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get pathname() {
|
|
100
|
-
if (this.#config.type && this.#config.name && this.#config.version) return path.join('/', this.type, this.name, this.version);
|
|
101
|
-
throw new Error('Eik config was not loaded before calling .pathname');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
base() {
|
|
105
|
-
if (this.#development) return this.#base;
|
|
106
|
-
return `${this.server}${this.pathname}`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
file(file = '') {
|
|
110
|
-
const base = this.base();
|
|
111
|
-
return new Asset({
|
|
112
|
-
value: `${base}${file}`,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
maps() {
|
|
117
|
-
if (this.#config.version && this.#loadMaps) return this.#maps;
|
|
118
|
-
throw new Error('Eik config was not loaded or "loadMaps" is "false" when calling .maps()');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
module.exports = NodeClient;
|