@shgysk8zer0/importmap 1.3.5 → 1.3.7
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 +16 -0
- package/hash.js +42 -0
- package/importmap.json +9 -5
- package/index.cjs +56 -22
- package/index.mjs +56 -21
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [v1.3.7] - 2024-03-26
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Add `@aegisjsproject/sanitizer`
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Update handling of hashes & SRI
|
|
16
|
+
|
|
17
|
+
## [v1.3.6] - 2024-03-18
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- Add GitHub Action to run `npm run update`
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- More updates, but automated this time
|
|
24
|
+
|
|
9
25
|
## [v1.3.5] - 2024-03-12
|
|
10
26
|
|
|
11
27
|
### Changed
|
package/hash.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const SHA1 = 'SHA-1';
|
|
2
|
+
export const SHA256 = 'SHA-256';
|
|
3
|
+
export const SHA384 = 'SHA-384';
|
|
4
|
+
export const SHA512 = 'SHA-512';
|
|
5
|
+
export const DEFAULT_ALGO = SHA384;
|
|
6
|
+
export const SHA = SHA1;
|
|
7
|
+
|
|
8
|
+
export const BASE64 = 'base64';
|
|
9
|
+
export const SRI = 'sri';
|
|
10
|
+
export const HEX = 'hex';
|
|
11
|
+
export const BUFFER = 'buffer';
|
|
12
|
+
|
|
13
|
+
export async function hash(data, { algo = DEFAULT_ALGO, output = BUFFER } = {}) {
|
|
14
|
+
const buffer = await new TextEncoder().encode(data);
|
|
15
|
+
const hash = await crypto.subtle.digest(algo, buffer);
|
|
16
|
+
|
|
17
|
+
switch (output) {
|
|
18
|
+
case BUFFER:
|
|
19
|
+
return hash;
|
|
20
|
+
|
|
21
|
+
case HEX:
|
|
22
|
+
return Array.from(
|
|
23
|
+
new Uint8Array(hash),
|
|
24
|
+
byte => byte.toString(16).padStart(2, '0')
|
|
25
|
+
).join('');
|
|
26
|
+
|
|
27
|
+
case BASE64:
|
|
28
|
+
return btoa(hash);
|
|
29
|
+
|
|
30
|
+
case SRI: {
|
|
31
|
+
const codeUnits = new Uint16Array(hash);
|
|
32
|
+
const charCodes = new Uint8Array(codeUnits.buffer);
|
|
33
|
+
const result = btoa(String.fromCharCode(...charCodes));
|
|
34
|
+
return `${algo.replace('-', '').toLowerCase()}-${result}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
default:
|
|
38
|
+
throw new TypeError(`Unsupported output type: "${output}".`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const sri = async(data, { algo = SHA384 } = {}) => hash(data, { algo, output: SRI });
|
package/importmap.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"imports": {
|
|
3
|
-
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@0.3.
|
|
3
|
+
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@0.3.4/",
|
|
4
4
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
5
|
-
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.
|
|
6
|
-
"@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.
|
|
5
|
+
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.3/all.min.js",
|
|
6
|
+
"@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.3/",
|
|
7
7
|
"@shgysk8zer0/jswaggersheets": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/swagger.js",
|
|
8
8
|
"@shgysk8zer0/jswaggersheets/": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/",
|
|
9
9
|
"@shgysk8zer0/jss/": "https://unpkg.com/@shgysk8zer0/jss@1.0.1/",
|
|
10
10
|
"@shgysk8zer0/consts/": "https://unpkg.com/@shgysk8zer0/consts@1.0.8/",
|
|
11
11
|
"@shgysk8zer0/http/": "https://unpkg.com/@shgysk8zer0/http@1.0.5/",
|
|
12
12
|
"@shgysk8zer0/http-status": "https://unpkg.com/@shgysk8zer0/http-status@1.1.1/http-status.js",
|
|
13
|
-
"@aegisjsproject/
|
|
14
|
-
"@aegisjsproject/
|
|
13
|
+
"@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.0.2/sanitizer.js",
|
|
14
|
+
"@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.0.2/",
|
|
15
|
+
"@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.0/core.js",
|
|
16
|
+
"@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.0/",
|
|
15
17
|
"@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.1.1/styles.js",
|
|
16
18
|
"@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.1.1/",
|
|
17
19
|
"@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.2/component.js",
|
|
@@ -27,6 +29,8 @@
|
|
|
27
29
|
"urlpattern-polyfill": "https://unpkg.com/urlpattern-polyfill@10.0.0/index.js",
|
|
28
30
|
"highlight.js": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/core.min.js",
|
|
29
31
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/",
|
|
32
|
+
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/core.min.js",
|
|
33
|
+
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/",
|
|
30
34
|
"marked": "https://unpkg.com/marked@12.0.1/lib/marked.esm.js",
|
|
31
35
|
"marked-highlight": "https://unpkg.com/marked-highlight@2.1.1/src/index.js",
|
|
32
36
|
"firebase/": "https://www.gstatic.com/firebasejs/9.23.0/"
|
package/index.cjs
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var promises = require('node:fs/promises');
|
|
4
|
-
var node_crypto = require('node:crypto');
|
|
5
4
|
var yaml_js = require('@shgysk8zer0/npm-utils/yaml.js');
|
|
6
5
|
var json_js = require('@shgysk8zer0/npm-utils/json.js');
|
|
7
6
|
var path_js = require('@shgysk8zer0/npm-utils/path.js');
|
|
8
7
|
|
|
9
8
|
const imports$1 = {
|
|
10
|
-
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@0.3.
|
|
9
|
+
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@0.3.4/",
|
|
11
10
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
12
|
-
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.
|
|
13
|
-
"@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.
|
|
11
|
+
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.3/all.min.js",
|
|
12
|
+
"@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.3/",
|
|
14
13
|
"@shgysk8zer0/jswaggersheets": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/swagger.js",
|
|
15
14
|
"@shgysk8zer0/jswaggersheets/": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/",
|
|
16
15
|
"@shgysk8zer0/jss/": "https://unpkg.com/@shgysk8zer0/jss@1.0.1/",
|
|
17
16
|
"@shgysk8zer0/consts/": "https://unpkg.com/@shgysk8zer0/consts@1.0.8/",
|
|
18
17
|
"@shgysk8zer0/http/": "https://unpkg.com/@shgysk8zer0/http@1.0.5/",
|
|
19
18
|
"@shgysk8zer0/http-status": "https://unpkg.com/@shgysk8zer0/http-status@1.1.1/http-status.js",
|
|
20
|
-
"@aegisjsproject/
|
|
21
|
-
"@aegisjsproject/
|
|
19
|
+
"@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.0.2/sanitizer.js",
|
|
20
|
+
"@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.0.2/",
|
|
21
|
+
"@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.0/core.js",
|
|
22
|
+
"@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.0/",
|
|
22
23
|
"@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.1.1/styles.js",
|
|
23
24
|
"@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.1.1/",
|
|
24
25
|
"@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.2/component.js",
|
|
@@ -34,6 +35,8 @@ const imports$1 = {
|
|
|
34
35
|
"urlpattern-polyfill": "https://unpkg.com/urlpattern-polyfill@10.0.0/index.js",
|
|
35
36
|
"highlight.js": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/core.min.js",
|
|
36
37
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/",
|
|
38
|
+
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/core.min.js",
|
|
39
|
+
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/",
|
|
37
40
|
marked: "https://unpkg.com/marked@12.0.1/lib/marked.esm.js",
|
|
38
41
|
"marked-highlight": "https://unpkg.com/marked-highlight@2.1.1/src/index.js",
|
|
39
42
|
"firebase/": "https://www.gstatic.com/firebasejs/9.23.0/"
|
|
@@ -45,6 +48,45 @@ var importmap = {
|
|
|
45
48
|
scope: scope$1
|
|
46
49
|
};
|
|
47
50
|
|
|
51
|
+
const SHA384 = 'SHA-384';
|
|
52
|
+
const DEFAULT_ALGO = SHA384;
|
|
53
|
+
|
|
54
|
+
const BASE64 = 'base64';
|
|
55
|
+
const SRI = 'sri';
|
|
56
|
+
const HEX = 'hex';
|
|
57
|
+
const BUFFER = 'buffer';
|
|
58
|
+
|
|
59
|
+
async function hash(data, { algo = DEFAULT_ALGO, output = BUFFER } = {}) {
|
|
60
|
+
const buffer = await new TextEncoder().encode(data);
|
|
61
|
+
const hash = await crypto.subtle.digest(algo, buffer);
|
|
62
|
+
|
|
63
|
+
switch (output) {
|
|
64
|
+
case BUFFER:
|
|
65
|
+
return hash;
|
|
66
|
+
|
|
67
|
+
case HEX:
|
|
68
|
+
return Array.from(
|
|
69
|
+
new Uint8Array(hash),
|
|
70
|
+
byte => byte.toString(16).padStart(2, '0')
|
|
71
|
+
).join('');
|
|
72
|
+
|
|
73
|
+
case BASE64:
|
|
74
|
+
return btoa(hash);
|
|
75
|
+
|
|
76
|
+
case SRI: {
|
|
77
|
+
const codeUnits = new Uint16Array(hash);
|
|
78
|
+
const charCodes = new Uint8Array(codeUnits.buffer);
|
|
79
|
+
const result = btoa(String.fromCharCode(...charCodes));
|
|
80
|
+
return `${algo.replace('-', '').toLowerCase()}-${result}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
default:
|
|
84
|
+
throw new TypeError(`Unsupported output type: "${output}".`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const sri = async(data, { algo = SHA384 } = {}) => hash(data, { algo, output: SRI });
|
|
89
|
+
|
|
48
90
|
const UNPKG = 'https://unpkg.com/';
|
|
49
91
|
|
|
50
92
|
const cache = new Map();
|
|
@@ -166,9 +208,7 @@ var unpkg = /*#__PURE__*/Object.freeze({
|
|
|
166
208
|
});
|
|
167
209
|
|
|
168
210
|
const { imports, scope } = importmap;
|
|
169
|
-
|
|
170
211
|
const ENCODING = 'utf8';
|
|
171
|
-
const ALGO = 'sha384';
|
|
172
212
|
|
|
173
213
|
function mergeWithImportmap({ imports = {}, scope = {}}) {
|
|
174
214
|
return {
|
|
@@ -185,31 +225,25 @@ async function createImportmapJSON(path = 'importmap.json', {
|
|
|
185
225
|
await promises.writeFile(path, JSON.stringify(importmap, null, spaces), { encoding: ENCODING, signal });
|
|
186
226
|
}
|
|
187
227
|
|
|
188
|
-
function getImportmapIntegrity({
|
|
228
|
+
async function getImportmapIntegrity({
|
|
189
229
|
importmap = { imports, scope },
|
|
190
|
-
algo =
|
|
191
|
-
encoding = ENCODING,
|
|
192
|
-
spaces = 2,
|
|
230
|
+
algo = DEFAULT_ALGO,
|
|
193
231
|
} = {}) {
|
|
194
|
-
|
|
195
|
-
hash.update(JSON.stringify(importmap, null, spaces), encoding);
|
|
196
|
-
return `${algo}-${hash.digest('base64')}`;
|
|
232
|
+
return await sri(JSON.stringify(importmap), { algo });
|
|
197
233
|
}
|
|
198
234
|
|
|
199
|
-
function
|
|
235
|
+
async function getImportmapScript({
|
|
200
236
|
importmap = { imports, scope },
|
|
201
|
-
algo =
|
|
202
|
-
spaces = 2,
|
|
237
|
+
algo = DEFAULT_ALGO,
|
|
203
238
|
} = {}) {
|
|
204
|
-
const integrity = getImportmapIntegrity({ importmap, algo
|
|
205
|
-
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(importmap
|
|
239
|
+
const integrity = await getImportmapIntegrity({ importmap, algo });
|
|
240
|
+
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(importmap)}</script>`;
|
|
206
241
|
}
|
|
207
242
|
|
|
208
|
-
exports.ALGO = ALGO;
|
|
209
243
|
exports.ENCODING = ENCODING;
|
|
210
244
|
exports.createImportmapJSON = createImportmapJSON;
|
|
211
|
-
exports.getImportMapScript = getImportMapScript;
|
|
212
245
|
exports.getImportmapIntegrity = getImportmapIntegrity;
|
|
246
|
+
exports.getImportmapScript = getImportmapScript;
|
|
213
247
|
exports.importmap = importmap;
|
|
214
248
|
exports.imports = imports;
|
|
215
249
|
exports.mergeWithImportmap = mergeWithImportmap;
|
package/index.mjs
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { writeFile } from 'node:fs/promises';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
2
|
import { readYAMLFile, writeYAMLFile } from '@shgysk8zer0/npm-utils/yaml.js';
|
|
4
3
|
import { readJSONFile, writeJSONFile } from '@shgysk8zer0/npm-utils/json.js';
|
|
5
4
|
import { getFileURL } from '@shgysk8zer0/npm-utils/path.js';
|
|
6
5
|
|
|
7
6
|
const imports$1 = {
|
|
8
|
-
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@0.3.
|
|
7
|
+
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@0.3.4/",
|
|
9
8
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
10
|
-
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.
|
|
11
|
-
"@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.
|
|
9
|
+
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.3/all.min.js",
|
|
10
|
+
"@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.3.3/",
|
|
12
11
|
"@shgysk8zer0/jswaggersheets": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/swagger.js",
|
|
13
12
|
"@shgysk8zer0/jswaggersheets/": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/",
|
|
14
13
|
"@shgysk8zer0/jss/": "https://unpkg.com/@shgysk8zer0/jss@1.0.1/",
|
|
15
14
|
"@shgysk8zer0/consts/": "https://unpkg.com/@shgysk8zer0/consts@1.0.8/",
|
|
16
15
|
"@shgysk8zer0/http/": "https://unpkg.com/@shgysk8zer0/http@1.0.5/",
|
|
17
16
|
"@shgysk8zer0/http-status": "https://unpkg.com/@shgysk8zer0/http-status@1.1.1/http-status.js",
|
|
18
|
-
"@aegisjsproject/
|
|
19
|
-
"@aegisjsproject/
|
|
17
|
+
"@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.0.2/sanitizer.js",
|
|
18
|
+
"@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.0.2/",
|
|
19
|
+
"@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.0/core.js",
|
|
20
|
+
"@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.0/",
|
|
20
21
|
"@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.1.1/styles.js",
|
|
21
22
|
"@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.1.1/",
|
|
22
23
|
"@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.2/component.js",
|
|
@@ -32,6 +33,8 @@ const imports$1 = {
|
|
|
32
33
|
"urlpattern-polyfill": "https://unpkg.com/urlpattern-polyfill@10.0.0/index.js",
|
|
33
34
|
"highlight.js": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/core.min.js",
|
|
34
35
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/",
|
|
36
|
+
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/core.min.js",
|
|
37
|
+
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.9.0/es/",
|
|
35
38
|
marked: "https://unpkg.com/marked@12.0.1/lib/marked.esm.js",
|
|
36
39
|
"marked-highlight": "https://unpkg.com/marked-highlight@2.1.1/src/index.js",
|
|
37
40
|
"firebase/": "https://www.gstatic.com/firebasejs/9.23.0/"
|
|
@@ -43,6 +46,45 @@ var importmap = {
|
|
|
43
46
|
scope: scope$1
|
|
44
47
|
};
|
|
45
48
|
|
|
49
|
+
const SHA384 = 'SHA-384';
|
|
50
|
+
const DEFAULT_ALGO = SHA384;
|
|
51
|
+
|
|
52
|
+
const BASE64 = 'base64';
|
|
53
|
+
const SRI = 'sri';
|
|
54
|
+
const HEX = 'hex';
|
|
55
|
+
const BUFFER = 'buffer';
|
|
56
|
+
|
|
57
|
+
async function hash(data, { algo = DEFAULT_ALGO, output = BUFFER } = {}) {
|
|
58
|
+
const buffer = await new TextEncoder().encode(data);
|
|
59
|
+
const hash = await crypto.subtle.digest(algo, buffer);
|
|
60
|
+
|
|
61
|
+
switch (output) {
|
|
62
|
+
case BUFFER:
|
|
63
|
+
return hash;
|
|
64
|
+
|
|
65
|
+
case HEX:
|
|
66
|
+
return Array.from(
|
|
67
|
+
new Uint8Array(hash),
|
|
68
|
+
byte => byte.toString(16).padStart(2, '0')
|
|
69
|
+
).join('');
|
|
70
|
+
|
|
71
|
+
case BASE64:
|
|
72
|
+
return btoa(hash);
|
|
73
|
+
|
|
74
|
+
case SRI: {
|
|
75
|
+
const codeUnits = new Uint16Array(hash);
|
|
76
|
+
const charCodes = new Uint8Array(codeUnits.buffer);
|
|
77
|
+
const result = btoa(String.fromCharCode(...charCodes));
|
|
78
|
+
return `${algo.replace('-', '').toLowerCase()}-${result}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
default:
|
|
82
|
+
throw new TypeError(`Unsupported output type: "${output}".`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const sri = async(data, { algo = SHA384 } = {}) => hash(data, { algo, output: SRI });
|
|
87
|
+
|
|
46
88
|
const UNPKG = 'https://unpkg.com/';
|
|
47
89
|
|
|
48
90
|
const cache = new Map();
|
|
@@ -164,9 +206,7 @@ var unpkg = /*#__PURE__*/Object.freeze({
|
|
|
164
206
|
});
|
|
165
207
|
|
|
166
208
|
const { imports, scope } = importmap;
|
|
167
|
-
|
|
168
209
|
const ENCODING = 'utf8';
|
|
169
|
-
const ALGO = 'sha384';
|
|
170
210
|
|
|
171
211
|
function mergeWithImportmap({ imports = {}, scope = {}}) {
|
|
172
212
|
return {
|
|
@@ -183,24 +223,19 @@ async function createImportmapJSON(path = 'importmap.json', {
|
|
|
183
223
|
await writeFile(path, JSON.stringify(importmap, null, spaces), { encoding: ENCODING, signal });
|
|
184
224
|
}
|
|
185
225
|
|
|
186
|
-
function getImportmapIntegrity({
|
|
226
|
+
async function getImportmapIntegrity({
|
|
187
227
|
importmap = { imports, scope },
|
|
188
|
-
algo =
|
|
189
|
-
encoding = ENCODING,
|
|
190
|
-
spaces = 2,
|
|
228
|
+
algo = DEFAULT_ALGO,
|
|
191
229
|
} = {}) {
|
|
192
|
-
|
|
193
|
-
hash.update(JSON.stringify(importmap, null, spaces), encoding);
|
|
194
|
-
return `${algo}-${hash.digest('base64')}`;
|
|
230
|
+
return await sri(JSON.stringify(importmap), { algo });
|
|
195
231
|
}
|
|
196
232
|
|
|
197
|
-
function
|
|
233
|
+
async function getImportmapScript({
|
|
198
234
|
importmap = { imports, scope },
|
|
199
|
-
algo =
|
|
200
|
-
spaces = 2,
|
|
235
|
+
algo = DEFAULT_ALGO,
|
|
201
236
|
} = {}) {
|
|
202
|
-
const integrity = getImportmapIntegrity({ importmap, algo
|
|
203
|
-
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(importmap
|
|
237
|
+
const integrity = await getImportmapIntegrity({ importmap, algo });
|
|
238
|
+
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(importmap)}</script>`;
|
|
204
239
|
}
|
|
205
240
|
|
|
206
|
-
export {
|
|
241
|
+
export { ENCODING, createImportmapJSON, getImportmapIntegrity, getImportmapScript, importmap, imports, mergeWithImportmap, scope, unpkg };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shgysk8zer0/importmap",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18.0.0"
|
|
6
6
|
},
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
},
|
|
60
60
|
"homepage": "https://github.com/shgysk8zer0/importmap#readme",
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@babel/eslint-parser": "^7.
|
|
62
|
+
"@babel/eslint-parser": "^7.24.1",
|
|
63
63
|
"@babel/eslint-plugin": "^7.23.5",
|
|
64
|
-
"@babel/plugin-syntax-import-assertions": "^7.
|
|
64
|
+
"@babel/plugin-syntax-import-assertions": "^7.24.1",
|
|
65
65
|
"@rollup/plugin-json": "^6.1.0",
|
|
66
66
|
"@shgysk8zer0/js-utils": "^1.0.1",
|
|
67
67
|
"@shgysk8zer0/rollup-import": "^1.2.2"
|