@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/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [v1.5.1] - 2025-12-04
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Add `Importmap` methods to set local imports using `package.json`
|
|
14
|
+
- Add static `Importmap.importFromFile()` to import from a local JSON file
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- Update package & module `exports`
|
|
18
|
+
|
|
19
|
+
## [v1.5.0] - 2025-12-03
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- Add `Importmap` class with `Map`-like methods and SRI/`<script>` generating methods
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
- Update `@aegisjsproject/idb` and `yaml`
|
|
10
26
|
|
|
11
27
|
## [v1.4.88] - 2025-11-19
|
|
12
28
|
|
package/cli.cjs
CHANGED
|
@@ -4,12 +4,13 @@ var json_js = require('@shgysk8zer0/npm-utils/json.js');
|
|
|
4
4
|
var yaml_js = require('@shgysk8zer0/npm-utils/yaml.js');
|
|
5
5
|
var commander = require('commander');
|
|
6
6
|
var node_path = require('node:path');
|
|
7
|
-
require('node:fs/promises');
|
|
7
|
+
var promises = require('node:fs/promises');
|
|
8
8
|
require('@shgysk8zer0/polyfills');
|
|
9
9
|
require('@shgysk8zer0/npm-utils/path.js');
|
|
10
10
|
|
|
11
11
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
12
|
-
const imports = {
|
|
12
|
+
const imports$1 = {
|
|
13
|
+
"@node/": "/node_modules/",
|
|
13
14
|
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.10/",
|
|
14
15
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
15
16
|
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.5.1/browser.min.js",
|
|
@@ -48,8 +49,8 @@ const imports = {
|
|
|
48
49
|
"@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",
|
|
49
50
|
"@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.mjs",
|
|
50
51
|
"@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",
|
|
51
|
-
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
52
|
-
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
52
|
+
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.5/",
|
|
53
|
+
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.5/idb.min.js",
|
|
53
54
|
"@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.1/",
|
|
54
55
|
"@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.1/otp.min.js",
|
|
55
56
|
"@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",
|
|
@@ -71,7 +72,7 @@ const imports = {
|
|
|
71
72
|
"@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/main.js",
|
|
72
73
|
"@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/",
|
|
73
74
|
"@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/",
|
|
74
|
-
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.
|
|
75
|
+
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
|
|
75
76
|
"@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
|
|
76
77
|
leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
|
|
77
78
|
"leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",
|
|
@@ -80,10 +81,10 @@ const imports = {
|
|
|
80
81
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
81
82
|
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",
|
|
82
83
|
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
83
|
-
marked: "https://unpkg.com/marked@17.0.
|
|
84
|
+
marked: "https://unpkg.com/marked@17.0.1/lib/marked.esm.js",
|
|
84
85
|
"marked-highlight": "https://unpkg.com/marked-highlight@2.2.3/src/index.js",
|
|
85
|
-
yaml: "https://unpkg.com/yaml@2.8.
|
|
86
|
-
"yaml/": "https://unpkg.com/yaml@2.8.
|
|
86
|
+
yaml: "https://unpkg.com/yaml@2.8.2/browser/dist/index.js",
|
|
87
|
+
"yaml/": "https://unpkg.com/yaml@2.8.2/browser/dist/",
|
|
87
88
|
"firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",
|
|
88
89
|
"firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",
|
|
89
90
|
"firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",
|
|
@@ -97,14 +98,145 @@ const imports = {
|
|
|
97
98
|
"firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",
|
|
98
99
|
"firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js"
|
|
99
100
|
};
|
|
100
|
-
const
|
|
101
|
+
const scopes$1 = {
|
|
102
|
+
};
|
|
103
|
+
var json = {
|
|
104
|
+
imports: imports$1,
|
|
105
|
+
scopes: scopes$1
|
|
101
106
|
};
|
|
102
107
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
const SHA256 = 'SHA-256';
|
|
109
|
+
const SHA384 = 'SHA-384';
|
|
110
|
+
const SHA512 = 'SHA-512';
|
|
111
|
+
const DEFAULT_ALGO = SHA384;
|
|
112
|
+
|
|
113
|
+
const BASE64 = 'base64';
|
|
114
|
+
|
|
115
|
+
const { imports, scopes } = json;
|
|
116
|
+
|
|
117
|
+
class Importmap {
|
|
118
|
+
#imports = {};
|
|
119
|
+
#scopes = {};
|
|
120
|
+
|
|
121
|
+
constructor({ imports: i = imports, scopes: s = scopes } = {}) {
|
|
122
|
+
this.#imports = i;
|
|
123
|
+
this.#scopes = s;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get imports() {
|
|
127
|
+
return structuredClone(this.#imports);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get scopes() {
|
|
131
|
+
return structuredClone(this.#scopes);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
delete(key) {
|
|
135
|
+
return Reflect.deleteProperty(this.#imports, key);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get(key) {
|
|
139
|
+
return Reflect.get(this.#imports, key);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
has(key) {
|
|
143
|
+
return Reflect.has(this.#imports, key);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
set(key, newValue) {
|
|
147
|
+
return Reflect.set(this.#imports, key, newValue);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
toJSON() {
|
|
151
|
+
return { imports: this.#imports, scopes: this.#scopes };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
toString() {
|
|
155
|
+
return JSON.stringify(this);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async importLocalPackage(name = 'package.json', { signal } = {}) {
|
|
159
|
+
const path = node_path.join(process.cwd(), name);
|
|
160
|
+
const pkg = await promises.readFile(path, { encoding: 'utf8', signal });
|
|
161
|
+
|
|
162
|
+
return this.setLocalPackage(JSON.parse(pkg));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
setLocalPackage({ name, module, exports = {} }) {
|
|
166
|
+
if (typeof name !== 'string') {
|
|
167
|
+
return false;
|
|
168
|
+
} else if (typeof exports === 'string' ) {
|
|
169
|
+
this.set(name, exports);
|
|
170
|
+
return true;
|
|
171
|
+
} else if (typeof exports === 'object') {
|
|
172
|
+
Object.entries(exports).forEach(([key, value]) => {
|
|
173
|
+
if (key.startsWith('.')) {
|
|
174
|
+
const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
|
|
175
|
+
const resolved = typeof value === 'string' ? value : value.import ?? value.default;
|
|
176
|
+
|
|
177
|
+
if (typeof resolved === 'string' && resolved.startsWith('./')) {
|
|
178
|
+
if (importKey.includes('*') && resolved.includes('*')) {
|
|
179
|
+
const [prefix, suffix] = importKey.split('*');
|
|
180
|
+
|
|
181
|
+
if (resolved.endsWith('*' + suffix)) {
|
|
182
|
+
this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
this.set(importKey, resolved.substring(1));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return true;
|
|
192
|
+
} else if (typeof module === 'string') {
|
|
193
|
+
this.set(name, module);
|
|
194
|
+
return true;
|
|
195
|
+
} else {
|
|
196
|
+
this.set(name, '/');
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
202
|
+
const integrity = await this.getIntegrity({ algo, alphabet, signal });
|
|
203
|
+
|
|
204
|
+
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
208
|
+
if (signal instanceof AbortSignal && signal.aborted) {
|
|
209
|
+
throw signal.reason;
|
|
210
|
+
} else {
|
|
211
|
+
const prefix = algo.toLowerCase().replace('-', '') + '-';
|
|
212
|
+
const encoded = new TextEncoder().encode(this);
|
|
213
|
+
const hash = await crypto.subtle.digest(algo, encoded);
|
|
214
|
+
|
|
215
|
+
return prefix + new Uint8Array(hash).toBase64({ alphabet });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
static get SHA256() {
|
|
220
|
+
return SHA256;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static get SHA384() {
|
|
224
|
+
return SHA384;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static get SHA512() {
|
|
228
|
+
return SHA512;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static async importFromFile(path = 'importmap.json', { signal } = {}) {
|
|
232
|
+
const fullPath = node_path.join(process.cwd(), path);
|
|
233
|
+
const importmap = await promises.readFile(fullPath, { encoding: 'utf8', signal });
|
|
234
|
+
|
|
235
|
+
return new Importmap(JSON.parse(importmap));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const importmap = new Importmap({ imports, scopes });
|
|
108
240
|
|
|
109
241
|
/* eslint-env node */
|
|
110
242
|
|
|
@@ -161,10 +293,10 @@ async function init() {
|
|
|
161
293
|
|
|
162
294
|
init().then(async ({ opts: { input, encoding, format, output }}) => {
|
|
163
295
|
const mod = typeof input === 'string'
|
|
164
|
-
? await parse(input, { encoding }).then(({ imports
|
|
296
|
+
? await parse(input, { encoding }).then(({ imports, scope = {}, ...rest }) => ({
|
|
165
297
|
...rest,
|
|
166
|
-
imports: { ...imports
|
|
167
|
-
scope: { ...scope
|
|
298
|
+
imports: { ...imports, ...importmap.imports },
|
|
299
|
+
scope: { ...scope, ...importmap.scope },
|
|
168
300
|
}))
|
|
169
301
|
: importmap;
|
|
170
302
|
|
package/cli.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { writeJSONFile, readJSONFile } from '@shgysk8zer0/npm-utils/json.js';
|
|
2
2
|
import { writeYAMLFile, readYAMLFile } from '@shgysk8zer0/npm-utils/yaml.js';
|
|
3
3
|
import { program } from 'commander';
|
|
4
|
-
import { extname } from 'node:path';
|
|
5
|
-
import 'node:fs/promises';
|
|
4
|
+
import { join, extname } from 'node:path';
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
6
|
import '@shgysk8zer0/polyfills';
|
|
7
7
|
import '@shgysk8zer0/npm-utils/path.js';
|
|
8
8
|
|
|
9
|
-
const imports = {
|
|
9
|
+
const imports$1 = {
|
|
10
|
+
"@node/": "/node_modules/",
|
|
10
11
|
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.10/",
|
|
11
12
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
12
13
|
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.5.1/browser.min.js",
|
|
@@ -45,8 +46,8 @@ const imports = {
|
|
|
45
46
|
"@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",
|
|
46
47
|
"@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.mjs",
|
|
47
48
|
"@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.
|
|
49
|
+
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.5/",
|
|
50
|
+
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.5/idb.min.js",
|
|
50
51
|
"@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.1/",
|
|
51
52
|
"@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.1/otp.min.js",
|
|
52
53
|
"@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",
|
|
@@ -68,7 +69,7 @@ const imports = {
|
|
|
68
69
|
"@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/main.js",
|
|
69
70
|
"@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/",
|
|
70
71
|
"@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/",
|
|
71
|
-
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.
|
|
72
|
+
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
|
|
72
73
|
"@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
|
|
73
74
|
leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
|
|
74
75
|
"leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",
|
|
@@ -77,10 +78,10 @@ const imports = {
|
|
|
77
78
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
78
79
|
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",
|
|
79
80
|
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
80
|
-
marked: "https://unpkg.com/marked@17.0.
|
|
81
|
+
marked: "https://unpkg.com/marked@17.0.1/lib/marked.esm.js",
|
|
81
82
|
"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.
|
|
83
|
+
yaml: "https://unpkg.com/yaml@2.8.2/browser/dist/index.js",
|
|
84
|
+
"yaml/": "https://unpkg.com/yaml@2.8.2/browser/dist/",
|
|
84
85
|
"firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",
|
|
85
86
|
"firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",
|
|
86
87
|
"firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",
|
|
@@ -94,14 +95,145 @@ const imports = {
|
|
|
94
95
|
"firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",
|
|
95
96
|
"firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js"
|
|
96
97
|
};
|
|
97
|
-
const
|
|
98
|
+
const scopes$1 = {
|
|
99
|
+
};
|
|
100
|
+
var json = {
|
|
101
|
+
imports: imports$1,
|
|
102
|
+
scopes: scopes$1
|
|
98
103
|
};
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
const SHA256 = 'SHA-256';
|
|
106
|
+
const SHA384 = 'SHA-384';
|
|
107
|
+
const SHA512 = 'SHA-512';
|
|
108
|
+
const DEFAULT_ALGO = SHA384;
|
|
109
|
+
|
|
110
|
+
const BASE64 = 'base64';
|
|
111
|
+
|
|
112
|
+
const { imports, scopes } = json;
|
|
113
|
+
|
|
114
|
+
class Importmap {
|
|
115
|
+
#imports = {};
|
|
116
|
+
#scopes = {};
|
|
117
|
+
|
|
118
|
+
constructor({ imports: i = imports, scopes: s = scopes } = {}) {
|
|
119
|
+
this.#imports = i;
|
|
120
|
+
this.#scopes = s;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get imports() {
|
|
124
|
+
return structuredClone(this.#imports);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get scopes() {
|
|
128
|
+
return structuredClone(this.#scopes);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
delete(key) {
|
|
132
|
+
return Reflect.deleteProperty(this.#imports, key);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
get(key) {
|
|
136
|
+
return Reflect.get(this.#imports, key);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
has(key) {
|
|
140
|
+
return Reflect.has(this.#imports, key);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
set(key, newValue) {
|
|
144
|
+
return Reflect.set(this.#imports, key, newValue);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
toJSON() {
|
|
148
|
+
return { imports: this.#imports, scopes: this.#scopes };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
toString() {
|
|
152
|
+
return JSON.stringify(this);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async importLocalPackage(name = 'package.json', { signal } = {}) {
|
|
156
|
+
const path = join(process.cwd(), name);
|
|
157
|
+
const pkg = await readFile(path, { encoding: 'utf8', signal });
|
|
158
|
+
|
|
159
|
+
return this.setLocalPackage(JSON.parse(pkg));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
setLocalPackage({ name, module, exports = {} }) {
|
|
163
|
+
if (typeof name !== 'string') {
|
|
164
|
+
return false;
|
|
165
|
+
} else if (typeof exports === 'string' ) {
|
|
166
|
+
this.set(name, exports);
|
|
167
|
+
return true;
|
|
168
|
+
} else if (typeof exports === 'object') {
|
|
169
|
+
Object.entries(exports).forEach(([key, value]) => {
|
|
170
|
+
if (key.startsWith('.')) {
|
|
171
|
+
const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
|
|
172
|
+
const resolved = typeof value === 'string' ? value : value.import ?? value.default;
|
|
173
|
+
|
|
174
|
+
if (typeof resolved === 'string' && resolved.startsWith('./')) {
|
|
175
|
+
if (importKey.includes('*') && resolved.includes('*')) {
|
|
176
|
+
const [prefix, suffix] = importKey.split('*');
|
|
177
|
+
|
|
178
|
+
if (resolved.endsWith('*' + suffix)) {
|
|
179
|
+
this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
this.set(importKey, resolved.substring(1));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
return true;
|
|
189
|
+
} else if (typeof module === 'string') {
|
|
190
|
+
this.set(name, module);
|
|
191
|
+
return true;
|
|
192
|
+
} else {
|
|
193
|
+
this.set(name, '/');
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
199
|
+
const integrity = await this.getIntegrity({ algo, alphabet, signal });
|
|
200
|
+
|
|
201
|
+
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
205
|
+
if (signal instanceof AbortSignal && signal.aborted) {
|
|
206
|
+
throw signal.reason;
|
|
207
|
+
} else {
|
|
208
|
+
const prefix = algo.toLowerCase().replace('-', '') + '-';
|
|
209
|
+
const encoded = new TextEncoder().encode(this);
|
|
210
|
+
const hash = await crypto.subtle.digest(algo, encoded);
|
|
211
|
+
|
|
212
|
+
return prefix + new Uint8Array(hash).toBase64({ alphabet });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
static get SHA256() {
|
|
217
|
+
return SHA256;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
static get SHA384() {
|
|
221
|
+
return SHA384;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static get SHA512() {
|
|
225
|
+
return SHA512;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
static async importFromFile(path = 'importmap.json', { signal } = {}) {
|
|
229
|
+
const fullPath = join(process.cwd(), path);
|
|
230
|
+
const importmap = await readFile(fullPath, { encoding: 'utf8', signal });
|
|
231
|
+
|
|
232
|
+
return new Importmap(JSON.parse(importmap));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const importmap = new Importmap({ imports, scopes });
|
|
105
237
|
|
|
106
238
|
/* eslint-env node */
|
|
107
239
|
|
|
@@ -158,10 +290,10 @@ async function init() {
|
|
|
158
290
|
|
|
159
291
|
init().then(async ({ opts: { input, encoding, format, output }}) => {
|
|
160
292
|
const mod = typeof input === 'string'
|
|
161
|
-
? await parse(input, { encoding }).then(({ imports
|
|
293
|
+
? await parse(input, { encoding }).then(({ imports, scope = {}, ...rest }) => ({
|
|
162
294
|
...rest,
|
|
163
|
-
imports: { ...imports
|
|
164
|
-
scope: { ...scope
|
|
295
|
+
imports: { ...imports, ...importmap.imports },
|
|
296
|
+
scope: { ...scope, ...importmap.scope },
|
|
165
297
|
}))
|
|
166
298
|
: importmap;
|
|
167
299
|
|
package/importmap.cjs
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var node_path = require('node:path');
|
|
6
|
+
var promises = require('node:fs/promises');
|
|
7
|
+
require('@shgysk8zer0/polyfills');
|
|
8
|
+
|
|
9
|
+
const imports$1 = {
|
|
10
|
+
"@node/": "/node_modules/",
|
|
4
11
|
"@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.10/",
|
|
5
12
|
"@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
|
|
6
13
|
"@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.5.1/browser.min.js",
|
|
@@ -39,8 +46,8 @@ const imports = {
|
|
|
39
46
|
"@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",
|
|
40
47
|
"@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.mjs",
|
|
41
48
|
"@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",
|
|
42
|
-
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
43
|
-
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.
|
|
49
|
+
"@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.5/",
|
|
50
|
+
"@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.5/idb.min.js",
|
|
44
51
|
"@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.1/",
|
|
45
52
|
"@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.1/otp.min.js",
|
|
46
53
|
"@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",
|
|
@@ -62,7 +69,7 @@ const imports = {
|
|
|
62
69
|
"@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/main.js",
|
|
63
70
|
"@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/",
|
|
64
71
|
"@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/",
|
|
65
|
-
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.
|
|
72
|
+
"@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
|
|
66
73
|
"@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
|
|
67
74
|
leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
|
|
68
75
|
"leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",
|
|
@@ -71,10 +78,10 @@ const imports = {
|
|
|
71
78
|
"highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
72
79
|
"@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",
|
|
73
80
|
"@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
|
|
74
|
-
marked: "https://unpkg.com/marked@17.0.
|
|
81
|
+
marked: "https://unpkg.com/marked@17.0.1/lib/marked.esm.js",
|
|
75
82
|
"marked-highlight": "https://unpkg.com/marked-highlight@2.2.3/src/index.js",
|
|
76
|
-
yaml: "https://unpkg.com/yaml@2.8.
|
|
77
|
-
"yaml/": "https://unpkg.com/yaml@2.8.
|
|
83
|
+
yaml: "https://unpkg.com/yaml@2.8.2/browser/dist/index.js",
|
|
84
|
+
"yaml/": "https://unpkg.com/yaml@2.8.2/browser/dist/",
|
|
78
85
|
"firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",
|
|
79
86
|
"firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",
|
|
80
87
|
"firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",
|
|
@@ -88,8 +95,149 @@ const imports = {
|
|
|
88
95
|
"firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",
|
|
89
96
|
"firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js"
|
|
90
97
|
};
|
|
91
|
-
const
|
|
98
|
+
const scopes$1 = {
|
|
92
99
|
};
|
|
100
|
+
var json = {
|
|
101
|
+
imports: imports$1,
|
|
102
|
+
scopes: scopes$1
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const SHA256 = 'SHA-256';
|
|
106
|
+
const SHA384 = 'SHA-384';
|
|
107
|
+
const SHA512 = 'SHA-512';
|
|
108
|
+
const DEFAULT_ALGO = SHA384;
|
|
109
|
+
|
|
110
|
+
const BASE64 = 'base64';
|
|
111
|
+
|
|
112
|
+
const { imports, scopes } = json;
|
|
113
|
+
|
|
114
|
+
class Importmap {
|
|
115
|
+
#imports = {};
|
|
116
|
+
#scopes = {};
|
|
117
|
+
|
|
118
|
+
constructor({ imports: i = imports, scopes: s = scopes } = {}) {
|
|
119
|
+
this.#imports = i;
|
|
120
|
+
this.#scopes = s;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get imports() {
|
|
124
|
+
return structuredClone(this.#imports);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get scopes() {
|
|
128
|
+
return structuredClone(this.#scopes);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
delete(key) {
|
|
132
|
+
return Reflect.deleteProperty(this.#imports, key);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
get(key) {
|
|
136
|
+
return Reflect.get(this.#imports, key);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
has(key) {
|
|
140
|
+
return Reflect.has(this.#imports, key);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
set(key, newValue) {
|
|
144
|
+
return Reflect.set(this.#imports, key, newValue);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
toJSON() {
|
|
148
|
+
return { imports: this.#imports, scopes: this.#scopes };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
toString() {
|
|
152
|
+
return JSON.stringify(this);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async importLocalPackage(name = 'package.json', { signal } = {}) {
|
|
156
|
+
const path = node_path.join(process.cwd(), name);
|
|
157
|
+
const pkg = await promises.readFile(path, { encoding: 'utf8', signal });
|
|
158
|
+
|
|
159
|
+
return this.setLocalPackage(JSON.parse(pkg));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
setLocalPackage({ name, module, exports = {} }) {
|
|
163
|
+
if (typeof name !== 'string') {
|
|
164
|
+
return false;
|
|
165
|
+
} else if (typeof exports === 'string' ) {
|
|
166
|
+
this.set(name, exports);
|
|
167
|
+
return true;
|
|
168
|
+
} else if (typeof exports === 'object') {
|
|
169
|
+
Object.entries(exports).forEach(([key, value]) => {
|
|
170
|
+
if (key.startsWith('.')) {
|
|
171
|
+
const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
|
|
172
|
+
const resolved = typeof value === 'string' ? value : value.import ?? value.default;
|
|
173
|
+
|
|
174
|
+
if (typeof resolved === 'string' && resolved.startsWith('./')) {
|
|
175
|
+
if (importKey.includes('*') && resolved.includes('*')) {
|
|
176
|
+
const [prefix, suffix] = importKey.split('*');
|
|
177
|
+
|
|
178
|
+
if (resolved.endsWith('*' + suffix)) {
|
|
179
|
+
this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
this.set(importKey, resolved.substring(1));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
return true;
|
|
189
|
+
} else if (typeof module === 'string') {
|
|
190
|
+
this.set(name, module);
|
|
191
|
+
return true;
|
|
192
|
+
} else {
|
|
193
|
+
this.set(name, '/');
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
199
|
+
const integrity = await this.getIntegrity({ algo, alphabet, signal });
|
|
200
|
+
|
|
201
|
+
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
205
|
+
if (signal instanceof AbortSignal && signal.aborted) {
|
|
206
|
+
throw signal.reason;
|
|
207
|
+
} else {
|
|
208
|
+
const prefix = algo.toLowerCase().replace('-', '') + '-';
|
|
209
|
+
const encoded = new TextEncoder().encode(this);
|
|
210
|
+
const hash = await crypto.subtle.digest(algo, encoded);
|
|
211
|
+
|
|
212
|
+
return prefix + new Uint8Array(hash).toBase64({ alphabet });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
static get SHA256() {
|
|
217
|
+
return SHA256;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
static get SHA384() {
|
|
221
|
+
return SHA384;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static get SHA512() {
|
|
225
|
+
return SHA512;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
static async importFromFile(path = 'importmap.json', { signal } = {}) {
|
|
229
|
+
const fullPath = node_path.join(process.cwd(), path);
|
|
230
|
+
const importmap = await promises.readFile(fullPath, { encoding: 'utf8', signal });
|
|
231
|
+
|
|
232
|
+
return new Importmap(JSON.parse(importmap));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const importmap = new Importmap({ imports, scopes });
|
|
237
|
+
var importmap$1 = { imports, scopes };
|
|
93
238
|
|
|
239
|
+
exports.Importmap = Importmap;
|
|
240
|
+
exports.default = importmap$1;
|
|
241
|
+
exports.importmap = importmap;
|
|
94
242
|
exports.imports = imports;
|
|
95
|
-
exports.
|
|
243
|
+
exports.scopes = scopes;
|