@shgysk8zer0/importmap 1.8.0 → 1.8.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/cli.js CHANGED
@@ -1,307 +1,16 @@
1
+ #!/usr/bin/env node
1
2
  import { writeJSONFile, readJSONFile } from '@shgysk8zer0/npm-utils/json.js';
2
3
  import { writeYAMLFile, readYAMLFile } from '@shgysk8zer0/npm-utils/yaml.js';
3
- import { program } from 'commander';
4
- import { join, extname } from 'node:path';
5
4
  import { readFile } from 'node:fs/promises';
6
- import '@shgysk8zer0/polyfills';
7
- import '@shgysk8zer0/npm-utils/path.js';
8
-
9
- const imports$1 = {
10
- "@node/": "/node_modules/",
11
- "@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.11/",
12
- "@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.2/konami.js",
13
- "@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.6.2/browser.min.js",
14
- "@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.6.2/",
15
- "@shgysk8zer0/jwk-utils": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.0.20/jwk-utils.min.js",
16
- "@shgysk8zer0/jwk-utils/": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.0.20/",
17
- "@shgysk8zer0/jswaggersheets": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/swagger.js",
18
- "@shgysk8zer0/jswaggersheets/": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/",
19
- "@shgysk8zer0/jss/": "https://unpkg.com/@shgysk8zer0/jss@1.0.1/",
20
- "@shgysk8zer0/consts/": "https://unpkg.com/@shgysk8zer0/consts@1.0.8/",
21
- "@shgysk8zer0/http/": "https://unpkg.com/@shgysk8zer0/http@1.0.5/",
22
- "@shgysk8zer0/http-status": "https://unpkg.com/@shgysk8zer0/http-status@1.1.4/http-status.js",
23
- "@shgysk8zer0/aes-gcm": "https://unpkg.com/@shgysk8zer0/aes-gcm@1.0.8/aes-gcm.min.js",
24
- "@shgysk8zer0/aes-gcm/": "https://unpkg.com/@shgysk8zer0/aes-gcm@1.0.8/",
25
- "@shgysk8zer0/squish": "https://unpkg.com/@shgysk8zer0/squish@1.0.2/squish.min.js",
26
- "@shgysk8zer0/squish/": "https://unpkg.com/@shgysk8zer0/squish@1.0.2/",
27
- "@shgysk8zer0/suid": "https://unpkg.com/@shgysk8zer0/suid@1.0.0/suid.min.js",
28
- "@shgysk8zer0/suid/": "https://unpkg.com/@shgysk8zer0/suid@1.0.0/",
29
- "@shgysk8zer0/geoutils": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/geoutils.min.js",
30
- "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",
31
- "@shgysk8zer0/core-css/": "https://unpkg.com/@shgysk8zer0/core-css@2.5.4/",
32
- "@shgysk8zer0/signals": "https://unpkg.com/@shgysk8zer0/signals@0.0.3/signals.min.js",
33
- "@shgysk8zer0/signals/": "https://unpkg.com/@shgysk8zer0/signals@0.0.3/",
34
- "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
35
- "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
36
- "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/bundle.min.js",
37
- "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",
38
- "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",
39
- "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",
40
- "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.33/core.js",
41
- "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.33/",
42
- "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",
43
- "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",
44
- "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",
45
- "@aegisjsproject/component/": "https://unpkg.com/@aegisjsproject/component@0.1.7/",
46
- "@aegisjsproject/markdown": "https://unpkg.com/@aegisjsproject/markdown@0.1.6/markdown.min.js",
47
- "@aegisjsproject/markdown/": "https://unpkg.com/@aegisjsproject/markdown@0.1.6/",
48
- "@aegisjsproject/aegis-md": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/aegis-md.js",
49
- "@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",
50
- "@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.min.js",
51
- "@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",
52
- "@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.6/",
53
- "@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.6/idb.min.js",
54
- "@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.1/",
55
- "@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.1/otp.min.js",
56
- "@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",
57
- "@aegisjsproject/md-editor/": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/",
58
- "@aegisjsproject/barcodescanner": "https://unpkg.com/@aegisjsproject/barcodescanner@1.2.3/scanner.min.js",
59
- "@aegisjsproject/barcodescanner/": "https://unpkg.com/@aegisjsproject/barcodescanner@1.2.3/",
60
- "@shgysk8zer0/components/": "https://unpkg.com/@shgysk8zer0/components@0.3.22/",
61
- "@aegisjsproject/state": "https://unpkg.com/@aegisjsproject/state@1.0.7/state.mjs",
62
- "@aegisjsproject/state/": "https://unpkg.com/@aegisjsproject/state@1.0.7/",
63
- "@aegisjsproject/router": "https://unpkg.com/@aegisjsproject/router@1.1.15/router.mjs",
64
- "@aegisjsproject/router/": "https://unpkg.com/@aegisjsproject/router@1.1.15/",
65
- "@aegisjsproject/callback-registry": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.0/callbackRegistry.js",
66
- "@aegisjsproject/callback-registry/": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.0/",
67
- "@aegisjsproject/attempt": "https://unpkg.com/@aegisjsproject/attempt@1.0.7/attempt.js",
68
- "@aegisjsproject/attempt/": "https://unpkg.com/@aegisjsproject/attempt@1.0.7/",
69
- "@aegisjsproject/secret-store": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/commands.min.js",
70
- "@aegisjsproject/commands/": "https://unpkg.com/@aegisjsproject/commands@1.0.1/",
71
- "@aegisjsproject/commands": "https://unpkg.com/@aegisjsproject/commands@1.0.1/commands.min.js",
72
- "@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/main.js",
73
- "@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/",
74
- "@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/",
75
- "@aegisjsproject/qr-encoder": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/index.min.js",
76
- "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",
77
- "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",
78
- "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",
79
- "@aegisjsproject/disposable": "https://unpkg.com/@aegisjsproject/disposable@1.0.3/disposable.min.js",
80
- "@aegisjsproject/disposable/": "https://unpkg.com/@aegisjsproject/disposable@1.0.3/",
81
- "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
82
- "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
83
- leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
84
- "leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",
85
- "urlpattern-polyfill": "https://unpkg.com/urlpattern-polyfill@10.1.0/index.js",
86
- "highlight.js": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",
87
- "highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
88
- "highlight.js/styles/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/",
89
- "@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",
90
- "@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",
91
- "@highlightjs/cdn-assets/styles/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/",
92
- marked: "https://unpkg.com/marked@17.0.3/lib/marked.esm.js",
93
- "marked-highlight": "https://unpkg.com/marked-highlight@2.2.3/src/index.js",
94
- yaml: "https://unpkg.com/yaml@2.8.2/browser/dist/index.js",
95
- "yaml/": "https://unpkg.com/yaml@2.8.2/browser/dist/",
96
- "firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",
97
- "firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",
98
- "firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",
99
- "firebase/auth": "https://www.gstatic.com/firebasejs/10.12.1/firebase-auth.js",
100
- "firebase/database": "https://www.gstatic.com/firebasejs/10.12.1/firebase-database.js",
101
- "firebase/firestore": "https://www.gstatic.com/firebasejs/10.12.1/firebase-firestore.js",
102
- "firebase/functions": "https://www.gstatic.com/firebasejs/10.12.1/firebase-functions.js",
103
- "firebase/messaging": "https://www.gstatic.com/firebasejs/10.12.1/firebase-messaging.js",
104
- "firebase/performance": "https://www.gstatic.com/firebasejs/10.12.1/firebase-performance.js",
105
- "firebase/remote-config": "https://www.gstatic.com/firebasejs/10.12.1/firebase-remote-config.js",
106
- "firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",
107
- "firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js",
108
- qr: "https://unpkg.com/qr@0.5.4/index.js",
109
- "qr/": "https://unpkg.com/qr@0.5.4/",
110
- lit: "https://unpkg.com/lit@3.3.2/index.js",
111
- "lit/": "https://unpkg.com/lit@3.3.2/",
112
- "lit-html": "https://unpkg.com/lit-html@3.3.2/lit-html.js",
113
- "lit-html/": "https://unpkg.com/lit-html@3.3.2/",
114
- "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",
115
- "lit-element/": "https://unpkg.com/lit-element@4.2.2/",
116
- "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",
117
- "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",
118
- "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.2.1/",
119
- "normalize.css": "https://unpkg.com/normalize.css@8.0.1/normalize.css"
120
- };
121
- const scopes$1 = {
122
- };
123
- var json = {
124
- imports: imports$1,
125
- scopes: scopes$1
126
- };
127
-
128
- const SHA256 = 'SHA-256';
129
- const SHA384 = 'SHA-384';
130
- const SHA512 = 'SHA-512';
131
- const DEFAULT_ALGO = SHA384;
132
-
133
- const BASE64 = 'base64';
134
-
135
- const { imports, scopes } = json;
136
-
137
- class Importmap {
138
- #imports = {};
139
- #scopes = {};
140
- #base;
141
-
142
- constructor({ imports: i = imports, scopes: s = scopes } = {}) {
143
- this.#imports = i;
144
- this.#scopes = s;
145
- }
146
-
147
- get imports() {
148
- return structuredClone(this.#imports);
149
- }
150
-
151
- get scopes() {
152
- return structuredClone(this.#scopes);
153
- }
154
-
155
- delete(key) {
156
- return Reflect.deleteProperty(this.#imports, key);
157
- }
158
-
159
- get(key) {
160
- return Reflect.get(this.#imports, key);
161
- }
162
-
163
- has(key) {
164
- return Reflect.has(this.#imports, key);
165
- }
166
-
167
- set(key, newValue) {
168
- return Reflect.set(this.#imports, key, newValue);
169
- }
170
-
171
- toJSON() {
172
- return { imports: this.#imports, scopes: this.#scopes };
173
- }
174
-
175
- toString() {
176
- return JSON.stringify(this);
177
- }
178
-
179
- get baseUrl() {
180
- return this.#base;
181
- }
182
-
183
- set baseUrl(val) {
184
- if (typeof val === 'string' && URL.canParse(val)) {
185
- this.#base = val;
186
- }
187
- }
188
-
189
- resolve(specifier, base = this.baseUrl) {
190
- if (specifier instanceof URL) {
191
- return specifier.href;
192
- } else if (typeof specifier !== 'string') {
193
- return null;
194
- } else if (this.has(specifier)) {
195
- return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
196
- } else if (URL.canParse(specifier)) {
197
- return specifier;
198
- } else if (! specifier.startsWith('.')) {
199
- // Find the longest match
200
- const matches = Object.keys(this.imports)
201
- .filter(key => key.endsWith('/') && specifier.startsWith(key))
202
- .sort((a, b) => b.length - a.length);
203
-
204
- if (matches.length === 0) {
205
- return null;
206
- } else {
207
- const match = matches[0];
208
- const target = imports[match];
209
- const subpath = specifier.slice(match.length);
210
- // Resolve the mapping target against the map's base, then the subpath against that
211
- const resolvedTarget = new URL(target, this.baseUrl);
212
- return new URL(subpath, resolvedTarget).href;
213
- }
214
- } else if (typeof base === 'string') {
215
- return URL.parse(specifier, base)?.href ?? null;
216
- } else {
217
- return null;
218
- }
219
- }
220
-
221
- async importLocalPackage(name = 'package.json', { signal } = {}) {
222
- const path = join(process.cwd(), name);
223
- const pkg = await readFile(path, { encoding: 'utf8', signal });
224
-
225
- return this.setLocalPackage(JSON.parse(pkg));
226
- }
227
-
228
- setLocalPackage({ name, module, exports = {} }) {
229
- if (typeof name !== 'string') {
230
- return false;
231
- } else if (typeof exports === 'string' ) {
232
- this.set(name, exports);
233
- return true;
234
- } else if (typeof exports === 'object') {
235
- Object.entries(exports).forEach(([key, value]) => {
236
- if (key.startsWith('.')) {
237
- const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
238
- const resolved = typeof value === 'string' ? value : value.import ?? value.default;
239
-
240
- if (typeof resolved === 'string' && resolved.startsWith('./')) {
241
- if (importKey.includes('*') && resolved.includes('*')) {
242
- const [prefix, suffix] = importKey.split('*');
243
-
244
- if (resolved.endsWith('*' + suffix)) {
245
- this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
246
- }
247
- } else {
248
- this.set(importKey, resolved.substring(1));
249
- }
250
- }
251
- }
252
- });
253
-
254
- return true;
255
- } else if (typeof module === 'string') {
256
- this.set(name, module);
257
- return true;
258
- } else {
259
- this.set(name, '/');
260
- return true;
261
- }
262
- }
263
-
264
- async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
265
- const integrity = await this.getIntegrity({ algo, alphabet, signal });
266
-
267
- return `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
268
- }
269
-
270
- async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
271
- if (signal instanceof AbortSignal && signal.aborted) {
272
- throw signal.reason;
273
- } else {
274
- const prefix = algo.toLowerCase().replace('-', '') + '-';
275
- const encoded = new TextEncoder().encode(this);
276
- const hash = await crypto.subtle.digest(algo, encoded);
277
-
278
- return prefix + new Uint8Array(hash).toBase64({ alphabet });
279
- }
280
- }
281
-
282
- static get SHA256() {
283
- return SHA256;
284
- }
285
-
286
- static get SHA384() {
287
- return SHA384;
288
- }
289
-
290
- static get SHA512() {
291
- return SHA512;
292
- }
293
-
294
- static async importFromFile(path = 'importmap.json', { signal } = {}) {
295
- const fullPath = join(process.cwd(), path);
296
- const importmap = await readFile(fullPath, { encoding: 'utf8', signal });
5
+ import { program } from 'commander';
6
+ import { extname } from 'node:path';
297
7
 
298
- return new Importmap(JSON.parse(importmap));
299
- }
300
- }
8
+ // export const IMPORTMAP_EXP = /<script\b(?=[^>]*\btype=["']importmap["'])(?:[^>]*?\bnonce=["'](?<nonce>[^"']*)["'])?[^>]*>[\s\S]*?<\/script>/i;
9
+ const IMPORTMAP_EXP = /<script\b(?=[^>]*\btype=["']importmap["'])(?:[^>]*?\bnonce=["'](?<nonce>[^"']*)["'])?[^>]*>(?<content>[\s\S]*?)<\/script>/i;
301
10
 
302
- const importmap = new Importmap({ imports, scopes });
11
+ var pkg = JSON.parse('{\n "name": "@shgysk8zer0/importmap",\n "version": "1.8.2",\n "engines": {\n "node": ">=20.10.0"\n },\n "description": "Front-End dependencies based on `<script type=\\"importmap\\">`",\n "type": "module",\n "module": "./index.js",\n "main": "./index.cjs",\n "unpkg": "./index.js",\n "exports": {\n ".": {\n "import": "./index.js",\n "require": "./index.cjs"\n },\n "./importmap": {\n "import": "./importmap.js"\n },\n "./*.json": {\n "import": "./*.json"\n },\n "./*.js": {\n "import": "./*.js",\n "require": "./*.cjs"\n },\n "./*.mjs": {\n "import": "./*.js"\n },\n "./*.cjs": {\n "require": "./*.cjs"\n },\n "./*": {\n "import": "./*.js",\n "require": "./*.cjs"\n }\n },\n "bin": {\n "importmap-utils": "cli.js",\n "importmap-html": "html.js"\n },\n "scripts": {\n "start": "npx @shgysk8zer0/http-server -c ./http.config.js",\n "test": "npm run lint:js && npm run run:tests && npm run test:imports",\n "preversion": "npm test && npm run build",\n "prepare": "npm test && npm run build",\n "update": "node ./update.js",\n "lint:js": "eslint . --ignore-pattern \'importmap.mjs\'",\n "fix:js": "eslint . --fix",\n "build": "npm run build:js",\n "build:js": "rollup -c",\n "test:imports": "rollup -c rollup.test.config.js",\n "run:tests": "node --test *.test.js",\n "create:lock": "npm i --package-lock-only --ignore-scripts --no-audit --no-fund",\n "version:bump": "npm run version:bump:patch",\n "version:bump:patch": "npm version --no-git-tag-version patch && npm run create:lock",\n "version:bump:minor": "npm version --no-git-tag-version minor && npm run create:lock",\n "version:bump:major": "npm version --no-git-tag-version major && npm run create:lock"\n },\n "repository": {\n "type": "git",\n "url": "git+https://github.com/shgysk8zer0/importmap.git"\n },\n "author": "Chris Zuber <admin@kernvalley.us>",\n "license": "MIT",\n "bugs": {\n "url": "https://github.com/shgysk8zer0/importmap/issues"\n },\n "homepage": "https://github.com/shgysk8zer0/importmap#readme",\n "devDependencies": {\n "@shgysk8zer0/eslint-config": "^1.0.7",\n "@shgysk8zer0/js-utils": "^1.0.5",\n "@shgysk8zer0/rollup-import": "^2.0.3",\n "eslint": "^10.0.3"\n },\n "dependencies": {\n "@shgysk8zer0/npm-utils": "^1.1.4",\n "@shgysk8zer0/polyfills": "^0.6.2",\n "commander": "^14.0.3"\n }\n}\n');
303
12
 
304
- // import { updateImportMap } from './html.js';
13
+ var importmap = JSON.parse('{\n "imports": {\n "@node/": "/node_modules/",\n "@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.11/",\n "@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.2/konami.js",\n "@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.6.2/browser.min.js",\n "@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.6.2/",\n "@shgysk8zer0/jwk-utils": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.0.20/jwk-utils.min.js",\n "@shgysk8zer0/jwk-utils/": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.0.20/",\n "@shgysk8zer0/jswaggersheets": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/swagger.js",\n "@shgysk8zer0/jswaggersheets/": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/",\n "@shgysk8zer0/jss/": "https://unpkg.com/@shgysk8zer0/jss@1.0.1/",\n "@shgysk8zer0/consts/": "https://unpkg.com/@shgysk8zer0/consts@1.0.8/",\n "@shgysk8zer0/http/": "https://unpkg.com/@shgysk8zer0/http@1.0.5/",\n "@shgysk8zer0/http-status": "https://unpkg.com/@shgysk8zer0/http-status@1.1.4/http-status.js",\n "@shgysk8zer0/aes-gcm": "https://unpkg.com/@shgysk8zer0/aes-gcm@1.0.8/aes-gcm.min.js",\n "@shgysk8zer0/aes-gcm/": "https://unpkg.com/@shgysk8zer0/aes-gcm@1.0.8/",\n "@shgysk8zer0/squish": "https://unpkg.com/@shgysk8zer0/squish@1.0.2/squish.min.js",\n "@shgysk8zer0/squish/": "https://unpkg.com/@shgysk8zer0/squish@1.0.2/",\n "@shgysk8zer0/suid": "https://unpkg.com/@shgysk8zer0/suid@1.0.0/suid.min.js",\n "@shgysk8zer0/suid/": "https://unpkg.com/@shgysk8zer0/suid@1.0.0/",\n "@shgysk8zer0/geoutils": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/geoutils.min.js",\n "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",\n "@shgysk8zer0/core-css/": "https://unpkg.com/@shgysk8zer0/core-css@2.5.5/",\n "@shgysk8zer0/signals": "https://unpkg.com/@shgysk8zer0/signals@0.0.3/signals.min.js",\n "@shgysk8zer0/signals/": "https://unpkg.com/@shgysk8zer0/signals@0.0.3/",\n "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",\n "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",\n "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.6/bundle.min.js",\n "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.6/",\n "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",\n "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",\n "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.34/core.js",\n "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.34/",\n "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",\n "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",\n "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",\n "@aegisjsproject/component/": "https://unpkg.com/@aegisjsproject/component@0.1.7/",\n "@aegisjsproject/markdown": "https://unpkg.com/@aegisjsproject/markdown@0.1.6/markdown.min.js",\n "@aegisjsproject/markdown/": "https://unpkg.com/@aegisjsproject/markdown@0.1.6/",\n "@aegisjsproject/aegis-md": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/aegis-md.js",\n "@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",\n "@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.min.js",\n "@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",\n "@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.6/",\n "@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.6/idb.min.js",\n "@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.1/",\n "@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.1/otp.min.js",\n "@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",\n "@aegisjsproject/md-editor/": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/",\n "@aegisjsproject/barcodescanner": "https://unpkg.com/@aegisjsproject/barcodescanner@1.2.3/scanner.min.js",\n "@aegisjsproject/barcodescanner/": "https://unpkg.com/@aegisjsproject/barcodescanner@1.2.3/",\n "@shgysk8zer0/components/": "https://unpkg.com/@shgysk8zer0/components@0.3.22/",\n "@aegisjsproject/state": "https://unpkg.com/@aegisjsproject/state@1.0.7/state.mjs",\n "@aegisjsproject/state/": "https://unpkg.com/@aegisjsproject/state@1.0.7/",\n "@aegisjsproject/router": "https://unpkg.com/@aegisjsproject/router@1.1.15/router.mjs",\n "@aegisjsproject/router/": "https://unpkg.com/@aegisjsproject/router@1.1.15/",\n "@aegisjsproject/callback-registry": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.2/callbackRegistry.js",\n "@aegisjsproject/callback-registry/": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.2/",\n "@aegisjsproject/attempt": "https://unpkg.com/@aegisjsproject/attempt@1.0.7/attempt.js",\n "@aegisjsproject/attempt/": "https://unpkg.com/@aegisjsproject/attempt@1.0.7/",\n "@aegisjsproject/secret-store": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/commands.min.js",\n "@aegisjsproject/commands/": "https://unpkg.com/@aegisjsproject/commands@1.0.2/",\n "@aegisjsproject/commands": "https://unpkg.com/@aegisjsproject/commands@1.0.2/commands.min.js",\n "@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/main.js",\n "@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.5/",\n "@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.0.1/",\n "@aegisjsproject/qr-encoder": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/index.min.js",\n "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",\n "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",\n "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",\n "@aegisjsproject/disposable": "https://unpkg.com/@aegisjsproject/disposable@1.0.3/disposable.min.js",\n "@aegisjsproject/disposable/": "https://unpkg.com/@aegisjsproject/disposable@1.0.3/",\n "@aegisjsproject/iota": "https://unpkg.com/@aegisjsproject/iota@1.0.2/iota.min.js",\n "@aegisjsproject/iota/": "https://unpkg.com/@aegisjsproject/iota@1.0.2/",\n "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",\n "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",\n "leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",\n "leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",\n "urlpattern-polyfill": "https://unpkg.com/urlpattern-polyfill@10.1.0/index.js",\n "highlight.js": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",\n "highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",\n "highlight.js/styles/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/",\n "@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",\n "@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",\n "@highlightjs/cdn-assets/styles/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/",\n "marked": "https://unpkg.com/marked@17.0.4/lib/marked.esm.js",\n "marked-highlight": "https://unpkg.com/marked-highlight@2.2.3/src/index.js",\n "yaml": "https://unpkg.com/yaml@2.8.2/browser/dist/index.js",\n "yaml/": "https://unpkg.com/yaml@2.8.2/browser/dist/",\n "firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",\n "firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",\n "firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",\n "firebase/auth": "https://www.gstatic.com/firebasejs/10.12.1/firebase-auth.js",\n "firebase/database": "https://www.gstatic.com/firebasejs/10.12.1/firebase-database.js",\n "firebase/firestore": "https://www.gstatic.com/firebasejs/10.12.1/firebase-firestore.js",\n "firebase/functions": "https://www.gstatic.com/firebasejs/10.12.1/firebase-functions.js",\n "firebase/messaging": "https://www.gstatic.com/firebasejs/10.12.1/firebase-messaging.js",\n "firebase/performance": "https://www.gstatic.com/firebasejs/10.12.1/firebase-performance.js",\n "firebase/remote-config": "https://www.gstatic.com/firebasejs/10.12.1/firebase-remote-config.js",\n "firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",\n "firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js",\n "qr": "https://unpkg.com/qr@0.5.5/index.js",\n "qr/": "https://unpkg.com/qr@0.5.5/",\n "lit": "https://unpkg.com/lit@3.3.2/index.js",\n "lit/": "https://unpkg.com/lit@3.3.2/",\n "lit-html": "https://unpkg.com/lit-html@3.3.2/lit-html.js",\n "lit-html/": "https://unpkg.com/lit-html@3.3.2/",\n "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",\n "lit-element/": "https://unpkg.com/lit-element@4.2.2/",\n "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",\n "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",\n "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.3.1/",\n "normalize.css": "https://unpkg.com/normalize.css@8.0.1/normalize.css"\n },\n "scopes": {}\n}');
305
14
 
306
15
  function guessFileType(file) {
307
16
  const ext = extname(file).toLowerCase();
@@ -330,15 +39,19 @@ async function parse(file, { encoding, signal } = {}) {
330
39
  case 'json':
331
40
  return readJSONFile(file, { encoding, signal });
332
41
 
42
+ case 'html':
43
+ return readFile(file, { encoding, signal }).then(html => {
44
+ const match = IMPORTMAP_EXP.exec(html);
45
+ return JSON.parse(match?.groups?.content ?? '{}');
46
+ });
47
+
333
48
  }
334
49
  }
335
50
 
336
51
  async function init() {
337
- const { version: VERSION } = await readJSONFile(new URL('./package.json', import.meta.url));
338
-
339
52
  program
340
- .name('importmap-utils')
341
- .version(VERSION)
53
+ .name(Object.keys(pkg.bin)[0])
54
+ .version(pkg.version)
342
55
  .description('CLI utility for updating importmap files')
343
56
  .option('-i, --input [input]', 'local JSON or YAML importmap file')
344
57
  .option('-e, --encoding [encoding]', 'encoding', 'utf8')
@@ -354,10 +67,10 @@ async function init() {
354
67
 
355
68
  init().then(async ({ opts: { input, encoding, format, output }}) => {
356
69
  const mod = typeof input === 'string'
357
- ? await parse(input, { encoding }).then(({ imports, scope = {}, ...rest }) => ({
70
+ ? await parse(input, { encoding }).then(({ imports, scopes = {}, ...rest }) => ({
358
71
  ...rest,
359
72
  imports: { ...imports, ...importmap.imports },
360
- scope: { ...scope, ...importmap.scope },
73
+ scopes: { ...scopes, ...importmap.scopes },
361
74
  }))
362
75
  : importmap;
363
76
 
@@ -369,9 +82,5 @@ init().then(async ({ opts: { input, encoding, format, output }}) => {
369
82
  case 'yaml':
370
83
  await writeYAMLFile(output, mod, { encoding });
371
84
  break;
372
-
373
- // case 'html':
374
- // await updateImportMap(output, { spaces: null });
375
- // break;
376
85
  }
377
86
  });
package/consts.js ADDED
@@ -0,0 +1,2 @@
1
+ // export const IMPORTMAP_EXP = /<script\b(?=[^>]*\btype=["']importmap["'])(?:[^>]*?\bnonce=["'](?<nonce>[^"']*)["'])?[^>]*>[\s\S]*?<\/script>/i;
2
+ export const IMPORTMAP_EXP = /<script\b(?=[^>]*\btype=["']importmap["'])(?:[^>]*?\bnonce=["'](?<nonce>[^"']*)["'])?[^>]*>(?<content>[\s\S]*?)<\/script>/i;
package/html.cjs ADDED
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ var commander = require('commander');
4
+ var importmap = require('@shgysk8zer0/importmap');
5
+ var promises = require('node:fs/promises');
6
+
7
+ var pkg = JSON.parse('{\n "name": "@shgysk8zer0/importmap",\n "version": "1.8.2",\n "engines": {\n "node": ">=20.10.0"\n },\n "description": "Front-End dependencies based on `<script type=\\"importmap\\">`",\n "type": "module",\n "module": "./index.js",\n "main": "./index.cjs",\n "unpkg": "./index.js",\n "exports": {\n ".": {\n "import": "./index.js",\n "require": "./index.cjs"\n },\n "./importmap": {\n "import": "./importmap.js"\n },\n "./*.json": {\n "import": "./*.json"\n },\n "./*.js": {\n "import": "./*.js",\n "require": "./*.cjs"\n },\n "./*.mjs": {\n "import": "./*.js"\n },\n "./*.cjs": {\n "require": "./*.cjs"\n },\n "./*": {\n "import": "./*.js",\n "require": "./*.cjs"\n }\n },\n "bin": {\n "importmap-utils": "cli.js",\n "importmap-html": "html.js"\n },\n "scripts": {\n "start": "npx @shgysk8zer0/http-server -c ./http.config.js",\n "test": "npm run lint:js && npm run run:tests && npm run test:imports",\n "preversion": "npm test && npm run build",\n "prepare": "npm test && npm run build",\n "update": "node ./update.js",\n "lint:js": "eslint . --ignore-pattern \'importmap.mjs\'",\n "fix:js": "eslint . --fix",\n "build": "npm run build:js",\n "build:js": "rollup -c",\n "test:imports": "rollup -c rollup.test.config.js",\n "run:tests": "node --test *.test.js",\n "create:lock": "npm i --package-lock-only --ignore-scripts --no-audit --no-fund",\n "version:bump": "npm run version:bump:patch",\n "version:bump:patch": "npm version --no-git-tag-version patch && npm run create:lock",\n "version:bump:minor": "npm version --no-git-tag-version minor && npm run create:lock",\n "version:bump:major": "npm version --no-git-tag-version major && npm run create:lock"\n },\n "repository": {\n "type": "git",\n "url": "git+https://github.com/shgysk8zer0/importmap.git"\n },\n "author": "Chris Zuber <admin@kernvalley.us>",\n "license": "MIT",\n "bugs": {\n "url": "https://github.com/shgysk8zer0/importmap/issues"\n },\n "homepage": "https://github.com/shgysk8zer0/importmap#readme",\n "devDependencies": {\n "@shgysk8zer0/eslint-config": "^1.0.7",\n "@shgysk8zer0/js-utils": "^1.0.5",\n "@shgysk8zer0/rollup-import": "^2.0.3",\n "eslint": "^10.0.3"\n },\n "dependencies": {\n "@shgysk8zer0/npm-utils": "^1.1.4",\n "@shgysk8zer0/polyfills": "^0.6.2",\n "commander": "^14.0.3"\n }\n}\n');
8
+
9
+ async function init() {
10
+ commander.program
11
+ .name(Object.keys(pkg.bin)[1])
12
+ .version(pkg.version)
13
+ .argument('<html-file>')
14
+ .description('CLI utility for updating `<script type="importmap">` in HTML files')
15
+ .option('-a, --algo [algo]', 'Hashing algorigthm to use for `integrity`', 'SHA-384')
16
+ .option('-s, --spaces [spaces]', 'Spaces to indent with', (spaces) => parseInt(spaces) || 0)
17
+ .option('-i, --importmap [importmap]', 'Source importmap.json file.', file => promises.readFile(file, { encoding: 'utf8' }).then(data => JSON.parse(data)))
18
+ .parse(process.argv);
19
+
20
+ return {
21
+ args: commander.program.args,
22
+ opts: commander.program.opts(),
23
+ };
24
+ }
25
+
26
+ init().then(async ({
27
+ args: [file],
28
+ opts: { algo = 'SHA-384', importmap: importmap$1 = Promise.resolve(), spaces } = {}
29
+ } = {}) => {
30
+ await importmap.updateImportmap(file, { algo, spaces, importmap: await importmap$1 });
31
+ });
package/html.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import { program } from 'commander';
3
+ import { updateImportmap } from '@shgysk8zer0/importmap';
4
+ import { readFile } from 'node:fs/promises';
5
+
6
+ var pkg = JSON.parse('{\n "name": "@shgysk8zer0/importmap",\n "version": "1.8.2",\n "engines": {\n "node": ">=20.10.0"\n },\n "description": "Front-End dependencies based on `<script type=\\"importmap\\">`",\n "type": "module",\n "module": "./index.js",\n "main": "./index.cjs",\n "unpkg": "./index.js",\n "exports": {\n ".": {\n "import": "./index.js",\n "require": "./index.cjs"\n },\n "./importmap": {\n "import": "./importmap.js"\n },\n "./*.json": {\n "import": "./*.json"\n },\n "./*.js": {\n "import": "./*.js",\n "require": "./*.cjs"\n },\n "./*.mjs": {\n "import": "./*.js"\n },\n "./*.cjs": {\n "require": "./*.cjs"\n },\n "./*": {\n "import": "./*.js",\n "require": "./*.cjs"\n }\n },\n "bin": {\n "importmap-utils": "cli.js",\n "importmap-html": "html.js"\n },\n "scripts": {\n "start": "npx @shgysk8zer0/http-server -c ./http.config.js",\n "test": "npm run lint:js && npm run run:tests && npm run test:imports",\n "preversion": "npm test && npm run build",\n "prepare": "npm test && npm run build",\n "update": "node ./update.js",\n "lint:js": "eslint . --ignore-pattern \'importmap.mjs\'",\n "fix:js": "eslint . --fix",\n "build": "npm run build:js",\n "build:js": "rollup -c",\n "test:imports": "rollup -c rollup.test.config.js",\n "run:tests": "node --test *.test.js",\n "create:lock": "npm i --package-lock-only --ignore-scripts --no-audit --no-fund",\n "version:bump": "npm run version:bump:patch",\n "version:bump:patch": "npm version --no-git-tag-version patch && npm run create:lock",\n "version:bump:minor": "npm version --no-git-tag-version minor && npm run create:lock",\n "version:bump:major": "npm version --no-git-tag-version major && npm run create:lock"\n },\n "repository": {\n "type": "git",\n "url": "git+https://github.com/shgysk8zer0/importmap.git"\n },\n "author": "Chris Zuber <admin@kernvalley.us>",\n "license": "MIT",\n "bugs": {\n "url": "https://github.com/shgysk8zer0/importmap/issues"\n },\n "homepage": "https://github.com/shgysk8zer0/importmap#readme",\n "devDependencies": {\n "@shgysk8zer0/eslint-config": "^1.0.7",\n "@shgysk8zer0/js-utils": "^1.0.5",\n "@shgysk8zer0/rollup-import": "^2.0.3",\n "eslint": "^10.0.3"\n },\n "dependencies": {\n "@shgysk8zer0/npm-utils": "^1.1.4",\n "@shgysk8zer0/polyfills": "^0.6.2",\n "commander": "^14.0.3"\n }\n}\n');
7
+
8
+ async function init() {
9
+ program
10
+ .name(Object.keys(pkg.bin)[1])
11
+ .version(pkg.version)
12
+ .argument('<html-file>')
13
+ .description('CLI utility for updating `<script type="importmap">` in HTML files')
14
+ .option('-a, --algo [algo]', 'Hashing algorigthm to use for `integrity`', 'SHA-384')
15
+ .option('-s, --spaces [spaces]', 'Spaces to indent with', (spaces) => parseInt(spaces) || 0)
16
+ .option('-i, --importmap [importmap]', 'Source importmap.json file.', file => readFile(file, { encoding: 'utf8' }).then(data => JSON.parse(data)))
17
+ .parse(process.argv);
18
+
19
+ return {
20
+ args: program.args,
21
+ opts: program.opts(),
22
+ };
23
+ }
24
+
25
+ init().then(async ({
26
+ args: [file],
27
+ opts: { algo = 'SHA-384', importmap = Promise.resolve(), spaces } = {}
28
+ } = {}) => {
29
+ await updateImportmap(file, { algo, spaces, importmap: await importmap });
30
+ });