@shgysk8zer0/importmap 1.4.88 → 1.5.1
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/cli.cjs +149 -17
- package/cli.js +150 -18
- package/importmap.cjs +157 -9
- package/importmap.js +152 -9
- package/importmap.json +9 -8
- package/index.cjs +149 -21
- package/index.js +149 -22
- package/package.json +5 -2
package/importmap.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import '@shgysk8zer0/polyfills';
|
|
4
|
+
|
|
5
|
+
const imports$1 = {
|
|
6
|
+
"@node/": "/node_modules/",
|
|
2
7
|
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.10/",
|
|
3
8
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
4
9
|
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.5.1/browser.min.js",
|
|
@@ -37,8 +42,8 @@ const imports = {
|
|
|
37
42
|
"@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",
|
|
38
43
|
"@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.mjs",
|
|
39
44
|
"@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",
|
|
40
|
-
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
41
|
-
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
45
|
+
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.5/",
|
|
46
|
+
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.5/idb.min.js",
|
|
42
47
|
"@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.1/",
|
|
43
48
|
"@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.1/otp.min.js",
|
|
44
49
|
"@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",
|
|
@@ -60,7 +65,7 @@ const imports = {
|
|
|
60
65
|
"@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/main.js",
|
|
61
66
|
"@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/",
|
|
62
67
|
"@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/",
|
|
63
|
-
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.
|
|
68
|
+
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
|
|
64
69
|
"@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
|
|
65
70
|
leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
|
|
66
71
|
"leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",
|
|
@@ -69,10 +74,10 @@ const imports = {
|
|
|
69
74
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
70
75
|
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",
|
|
71
76
|
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
72
|
-
marked: "https://unpkg.com/marked@17.0.
|
|
77
|
+
marked: "https://unpkg.com/marked@17.0.1/lib/marked.esm.js",
|
|
73
78
|
"marked-highlight": "https://unpkg.com/marked-highlight@2.2.3/src/index.js",
|
|
74
|
-
yaml: "https://unpkg.com/yaml@2.8.
|
|
75
|
-
"yaml/": "https://unpkg.com/yaml@2.8.
|
|
79
|
+
yaml: "https://unpkg.com/yaml@2.8.2/browser/dist/index.js",
|
|
80
|
+
"yaml/": "https://unpkg.com/yaml@2.8.2/browser/dist/",
|
|
76
81
|
"firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",
|
|
77
82
|
"firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",
|
|
78
83
|
"firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",
|
|
@@ -86,7 +91,145 @@ const imports = {
|
|
|
86
91
|
"firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",
|
|
87
92
|
"firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js"
|
|
88
93
|
};
|
|
89
|
-
const
|
|
94
|
+
const scopes$1 = {
|
|
95
|
+
};
|
|
96
|
+
var json = {
|
|
97
|
+
imports: imports$1,
|
|
98
|
+
scopes: scopes$1
|
|
90
99
|
};
|
|
91
100
|
|
|
92
|
-
|
|
101
|
+
const SHA256 = 'SHA-256';
|
|
102
|
+
const SHA384 = 'SHA-384';
|
|
103
|
+
const SHA512 = 'SHA-512';
|
|
104
|
+
const DEFAULT_ALGO = SHA384;
|
|
105
|
+
|
|
106
|
+
const BASE64 = 'base64';
|
|
107
|
+
|
|
108
|
+
const { imports, scopes } = json;
|
|
109
|
+
|
|
110
|
+
class Importmap {
|
|
111
|
+
#imports = {};
|
|
112
|
+
#scopes = {};
|
|
113
|
+
|
|
114
|
+
constructor({ imports: i = imports, scopes: s = scopes } = {}) {
|
|
115
|
+
this.#imports = i;
|
|
116
|
+
this.#scopes = s;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
get imports() {
|
|
120
|
+
return structuredClone(this.#imports);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get scopes() {
|
|
124
|
+
return structuredClone(this.#scopes);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
delete(key) {
|
|
128
|
+
return Reflect.deleteProperty(this.#imports, key);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get(key) {
|
|
132
|
+
return Reflect.get(this.#imports, key);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
has(key) {
|
|
136
|
+
return Reflect.has(this.#imports, key);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
set(key, newValue) {
|
|
140
|
+
return Reflect.set(this.#imports, key, newValue);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
toJSON() {
|
|
144
|
+
return { imports: this.#imports, scopes: this.#scopes };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
toString() {
|
|
148
|
+
return JSON.stringify(this);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async importLocalPackage(name = 'package.json', { signal } = {}) {
|
|
152
|
+
const path = join(process.cwd(), name);
|
|
153
|
+
const pkg = await readFile(path, { encoding: 'utf8', signal });
|
|
154
|
+
|
|
155
|
+
return this.setLocalPackage(JSON.parse(pkg));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setLocalPackage({ name, module, exports = {} }) {
|
|
159
|
+
if (typeof name !== 'string') {
|
|
160
|
+
return false;
|
|
161
|
+
} else if (typeof exports === 'string' ) {
|
|
162
|
+
this.set(name, exports);
|
|
163
|
+
return true;
|
|
164
|
+
} else if (typeof exports === 'object') {
|
|
165
|
+
Object.entries(exports).forEach(([key, value]) => {
|
|
166
|
+
if (key.startsWith('.')) {
|
|
167
|
+
const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
|
|
168
|
+
const resolved = typeof value === 'string' ? value : value.import ?? value.default;
|
|
169
|
+
|
|
170
|
+
if (typeof resolved === 'string' && resolved.startsWith('./')) {
|
|
171
|
+
if (importKey.includes('*') && resolved.includes('*')) {
|
|
172
|
+
const [prefix, suffix] = importKey.split('*');
|
|
173
|
+
|
|
174
|
+
if (resolved.endsWith('*' + suffix)) {
|
|
175
|
+
this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
this.set(importKey, resolved.substring(1));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return true;
|
|
185
|
+
} else if (typeof module === 'string') {
|
|
186
|
+
this.set(name, module);
|
|
187
|
+
return true;
|
|
188
|
+
} else {
|
|
189
|
+
this.set(name, '/');
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
195
|
+
const integrity = await this.getIntegrity({ algo, alphabet, signal });
|
|
196
|
+
|
|
197
|
+
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
201
|
+
if (signal instanceof AbortSignal && signal.aborted) {
|
|
202
|
+
throw signal.reason;
|
|
203
|
+
} else {
|
|
204
|
+
const prefix = algo.toLowerCase().replace('-', '') + '-';
|
|
205
|
+
const encoded = new TextEncoder().encode(this);
|
|
206
|
+
const hash = await crypto.subtle.digest(algo, encoded);
|
|
207
|
+
|
|
208
|
+
return prefix + new Uint8Array(hash).toBase64({ alphabet });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static get SHA256() {
|
|
213
|
+
return SHA256;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
static get SHA384() {
|
|
217
|
+
return SHA384;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
static get SHA512() {
|
|
221
|
+
return SHA512;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static async importFromFile(path = 'importmap.json', { signal } = {}) {
|
|
225
|
+
const fullPath = join(process.cwd(), path);
|
|
226
|
+
const importmap = await readFile(fullPath, { encoding: 'utf8', signal });
|
|
227
|
+
|
|
228
|
+
return new Importmap(JSON.parse(importmap));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const importmap = new Importmap({ imports, scopes });
|
|
233
|
+
var importmap$1 = { imports, scopes };
|
|
234
|
+
|
|
235
|
+
export { Importmap, importmap$1 as default, importmap, imports, scopes };
|
package/importmap.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"imports": {
|
|
3
|
+
"@node/": "/node_modules/",
|
|
3
4
|
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.10/",
|
|
4
5
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
5
6
|
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.5.1/browser.min.js",
|
|
@@ -38,8 +39,8 @@
|
|
|
38
39
|
"@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",
|
|
39
40
|
"@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.mjs",
|
|
40
41
|
"@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",
|
|
41
|
-
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
42
|
-
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
42
|
+
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.5/",
|
|
43
|
+
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.5/idb.min.js",
|
|
43
44
|
"@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.1/",
|
|
44
45
|
"@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.1/otp.min.js",
|
|
45
46
|
"@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
"@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/main.js",
|
|
62
63
|
"@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/",
|
|
63
64
|
"@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/",
|
|
64
|
-
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.
|
|
65
|
+
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
|
|
65
66
|
"@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
|
|
66
67
|
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
|
|
67
68
|
"leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",
|
|
@@ -70,10 +71,10 @@
|
|
|
70
71
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
71
72
|
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",
|
|
72
73
|
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
73
|
-
"marked": "https://unpkg.com/marked@17.0.
|
|
74
|
+
"marked": "https://unpkg.com/marked@17.0.1/lib/marked.esm.js",
|
|
74
75
|
"marked-highlight": "https://unpkg.com/marked-highlight@2.2.3/src/index.js",
|
|
75
|
-
"yaml": "https://unpkg.com/yaml@2.8.
|
|
76
|
-
"yaml/": "https://unpkg.com/yaml@2.8.
|
|
76
|
+
"yaml": "https://unpkg.com/yaml@2.8.2/browser/dist/index.js",
|
|
77
|
+
"yaml/": "https://unpkg.com/yaml@2.8.2/browser/dist/",
|
|
77
78
|
"firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",
|
|
78
79
|
"firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",
|
|
79
80
|
"firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",
|
|
@@ -87,5 +88,5 @@
|
|
|
87
88
|
"firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",
|
|
88
89
|
"firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js"
|
|
89
90
|
},
|
|
90
|
-
"
|
|
91
|
-
}
|
|
91
|
+
"scopes": {}
|
|
92
|
+
}
|
package/index.cjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var promises = require('node:fs/promises');
|
|
4
|
+
var node_path = require('node:path');
|
|
4
5
|
require('@shgysk8zer0/polyfills');
|
|
5
6
|
var yaml_js = require('@shgysk8zer0/npm-utils/yaml.js');
|
|
6
7
|
var json_js = require('@shgysk8zer0/npm-utils/json.js');
|
|
7
8
|
var path_js = require('@shgysk8zer0/npm-utils/path.js');
|
|
8
9
|
|
|
9
10
|
const imports$1 = {
|
|
11
|
+
"@node/": "/node_modules/",
|
|
10
12
|
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.10/",
|
|
11
13
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
12
14
|
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.5.1/browser.min.js",
|
|
@@ -45,8 +47,8 @@ const imports$1 = {
|
|
|
45
47
|
"@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",
|
|
46
48
|
"@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.mjs",
|
|
47
49
|
"@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",
|
|
48
|
-
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
49
|
-
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
50
|
+
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.5/",
|
|
51
|
+
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.5/idb.min.js",
|
|
50
52
|
"@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.1/",
|
|
51
53
|
"@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.1/otp.min.js",
|
|
52
54
|
"@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",
|
|
@@ -68,7 +70,7 @@ const imports$1 = {
|
|
|
68
70
|
"@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/main.js",
|
|
69
71
|
"@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/",
|
|
70
72
|
"@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/",
|
|
71
|
-
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.
|
|
73
|
+
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
|
|
72
74
|
"@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
|
|
73
75
|
leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
|
|
74
76
|
"leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",
|
|
@@ -77,10 +79,10 @@ const imports$1 = {
|
|
|
77
79
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
78
80
|
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",
|
|
79
81
|
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
80
|
-
marked: "https://unpkg.com/marked@17.0.
|
|
82
|
+
marked: "https://unpkg.com/marked@17.0.1/lib/marked.esm.js",
|
|
81
83
|
"marked-highlight": "https://unpkg.com/marked-highlight@2.2.3/src/index.js",
|
|
82
|
-
yaml: "https://unpkg.com/yaml@2.8.
|
|
83
|
-
"yaml/": "https://unpkg.com/yaml@2.8.
|
|
84
|
+
yaml: "https://unpkg.com/yaml@2.8.2/browser/dist/index.js",
|
|
85
|
+
"yaml/": "https://unpkg.com/yaml@2.8.2/browser/dist/",
|
|
84
86
|
"firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",
|
|
85
87
|
"firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",
|
|
86
88
|
"firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",
|
|
@@ -94,16 +96,16 @@ const imports$1 = {
|
|
|
94
96
|
"firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",
|
|
95
97
|
"firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js"
|
|
96
98
|
};
|
|
97
|
-
const
|
|
99
|
+
const scopes$1 = {
|
|
100
|
+
};
|
|
101
|
+
var json = {
|
|
102
|
+
imports: imports$1,
|
|
103
|
+
scopes: scopes$1
|
|
98
104
|
};
|
|
99
105
|
|
|
100
|
-
|
|
101
|
-
__proto__: null,
|
|
102
|
-
imports: imports$1,
|
|
103
|
-
scope: scope$1
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
+
const SHA256 = 'SHA-256';
|
|
106
107
|
const SHA384 = 'SHA-384';
|
|
108
|
+
const SHA512 = 'SHA-512';
|
|
107
109
|
const DEFAULT_ALGO = SHA384;
|
|
108
110
|
|
|
109
111
|
const BASE64 = 'base64';
|
|
@@ -140,6 +142,132 @@ async function hash(data, { algo = DEFAULT_ALGO, output = BUFFER } = {}) {
|
|
|
140
142
|
|
|
141
143
|
const sri = async(data, { algo = SHA384 } = {}) => hash(data, { algo, output: SRI });
|
|
142
144
|
|
|
145
|
+
const { imports, scopes } = json;
|
|
146
|
+
|
|
147
|
+
class Importmap {
|
|
148
|
+
#imports = {};
|
|
149
|
+
#scopes = {};
|
|
150
|
+
|
|
151
|
+
constructor({ imports: i = imports, scopes: s = scopes } = {}) {
|
|
152
|
+
this.#imports = i;
|
|
153
|
+
this.#scopes = s;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
get imports() {
|
|
157
|
+
return structuredClone(this.#imports);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
get scopes() {
|
|
161
|
+
return structuredClone(this.#scopes);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
delete(key) {
|
|
165
|
+
return Reflect.deleteProperty(this.#imports, key);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
get(key) {
|
|
169
|
+
return Reflect.get(this.#imports, key);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
has(key) {
|
|
173
|
+
return Reflect.has(this.#imports, key);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
set(key, newValue) {
|
|
177
|
+
return Reflect.set(this.#imports, key, newValue);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
toJSON() {
|
|
181
|
+
return { imports: this.#imports, scopes: this.#scopes };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
toString() {
|
|
185
|
+
return JSON.stringify(this);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async importLocalPackage(name = 'package.json', { signal } = {}) {
|
|
189
|
+
const path = node_path.join(process.cwd(), name);
|
|
190
|
+
const pkg = await promises.readFile(path, { encoding: 'utf8', signal });
|
|
191
|
+
|
|
192
|
+
return this.setLocalPackage(JSON.parse(pkg));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
setLocalPackage({ name, module, exports = {} }) {
|
|
196
|
+
if (typeof name !== 'string') {
|
|
197
|
+
return false;
|
|
198
|
+
} else if (typeof exports === 'string' ) {
|
|
199
|
+
this.set(name, exports);
|
|
200
|
+
return true;
|
|
201
|
+
} else if (typeof exports === 'object') {
|
|
202
|
+
Object.entries(exports).forEach(([key, value]) => {
|
|
203
|
+
if (key.startsWith('.')) {
|
|
204
|
+
const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
|
|
205
|
+
const resolved = typeof value === 'string' ? value : value.import ?? value.default;
|
|
206
|
+
|
|
207
|
+
if (typeof resolved === 'string' && resolved.startsWith('./')) {
|
|
208
|
+
if (importKey.includes('*') && resolved.includes('*')) {
|
|
209
|
+
const [prefix, suffix] = importKey.split('*');
|
|
210
|
+
|
|
211
|
+
if (resolved.endsWith('*' + suffix)) {
|
|
212
|
+
this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
this.set(importKey, resolved.substring(1));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
return true;
|
|
222
|
+
} else if (typeof module === 'string') {
|
|
223
|
+
this.set(name, module);
|
|
224
|
+
return true;
|
|
225
|
+
} else {
|
|
226
|
+
this.set(name, '/');
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
232
|
+
const integrity = await this.getIntegrity({ algo, alphabet, signal });
|
|
233
|
+
|
|
234
|
+
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
238
|
+
if (signal instanceof AbortSignal && signal.aborted) {
|
|
239
|
+
throw signal.reason;
|
|
240
|
+
} else {
|
|
241
|
+
const prefix = algo.toLowerCase().replace('-', '') + '-';
|
|
242
|
+
const encoded = new TextEncoder().encode(this);
|
|
243
|
+
const hash = await crypto.subtle.digest(algo, encoded);
|
|
244
|
+
|
|
245
|
+
return prefix + new Uint8Array(hash).toBase64({ alphabet });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
static get SHA256() {
|
|
250
|
+
return SHA256;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
static get SHA384() {
|
|
254
|
+
return SHA384;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
static get SHA512() {
|
|
258
|
+
return SHA512;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
static async importFromFile(path = 'importmap.json', { signal } = {}) {
|
|
262
|
+
const fullPath = node_path.join(process.cwd(), path);
|
|
263
|
+
const importmap = await promises.readFile(fullPath, { encoding: 'utf8', signal });
|
|
264
|
+
|
|
265
|
+
return new Importmap(JSON.parse(importmap));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const importmap = new Importmap({ imports, scopes });
|
|
270
|
+
|
|
143
271
|
const UNPKG = 'https://unpkg.com/';
|
|
144
272
|
|
|
145
273
|
const cache = new Map();
|
|
@@ -265,18 +393,17 @@ var unpkg = /*#__PURE__*/Object.freeze({
|
|
|
265
393
|
updateYAML: updateYAML
|
|
266
394
|
});
|
|
267
395
|
|
|
268
|
-
const { imports, scope } = importmap;
|
|
269
396
|
const ENCODING = 'utf8';
|
|
270
397
|
|
|
271
|
-
function mergeWithImportmap({ imports = {},
|
|
398
|
+
function mergeWithImportmap({ imports = {}, scopes = {}}) {
|
|
272
399
|
return {
|
|
273
|
-
imports: { ...imports
|
|
274
|
-
|
|
400
|
+
imports: { ...importmap.imports, ...imports },
|
|
401
|
+
scopes: { ...importmap.scope, ...scopes },
|
|
275
402
|
};
|
|
276
403
|
}
|
|
277
404
|
|
|
278
405
|
async function createImportmapJSON(path = 'importmap.json', {
|
|
279
|
-
importmap = { imports,
|
|
406
|
+
importmap = { imports, scopes },
|
|
280
407
|
spaces = 2,
|
|
281
408
|
signal,
|
|
282
409
|
} = {}) {
|
|
@@ -284,14 +411,14 @@ async function createImportmapJSON(path = 'importmap.json', {
|
|
|
284
411
|
}
|
|
285
412
|
|
|
286
413
|
async function getImportmapIntegrity({
|
|
287
|
-
importmap = { imports,
|
|
414
|
+
importmap = { imports, scopes },
|
|
288
415
|
algo = DEFAULT_ALGO,
|
|
289
416
|
} = {}) {
|
|
290
417
|
return await sri(JSON.stringify(importmap), { algo });
|
|
291
418
|
}
|
|
292
419
|
|
|
293
420
|
async function getImportmapScript({
|
|
294
|
-
importmap = { imports,
|
|
421
|
+
importmap = { imports, scopes },
|
|
295
422
|
algo = DEFAULT_ALGO,
|
|
296
423
|
} = {}) {
|
|
297
424
|
const integrity = await getImportmapIntegrity({ importmap, algo });
|
|
@@ -299,11 +426,12 @@ async function getImportmapScript({
|
|
|
299
426
|
}
|
|
300
427
|
|
|
301
428
|
exports.ENCODING = ENCODING;
|
|
429
|
+
exports.Importmap = Importmap;
|
|
302
430
|
exports.createImportmapJSON = createImportmapJSON;
|
|
303
431
|
exports.getImportmapIntegrity = getImportmapIntegrity;
|
|
304
432
|
exports.getImportmapScript = getImportmapScript;
|
|
305
433
|
exports.importmap = importmap;
|
|
306
434
|
exports.imports = imports;
|
|
307
435
|
exports.mergeWithImportmap = mergeWithImportmap;
|
|
308
|
-
exports.
|
|
436
|
+
exports.scopes = scopes;
|
|
309
437
|
exports.unpkg = unpkg;
|