@shgysk8zer0/importmap 1.7.13 → 1.8.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/cli.js CHANGED
@@ -1,306 +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.5/attempt.js",
68
- "@aegisjsproject/attempt/": "https://unpkg.com/@aegisjsproject/attempt@1.0.5/",
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
- };
120
- const scopes$1 = {
121
- };
122
- var json = {
123
- imports: imports$1,
124
- scopes: scopes$1
125
- };
126
-
127
- const SHA256 = 'SHA-256';
128
- const SHA384 = 'SHA-384';
129
- const SHA512 = 'SHA-512';
130
- const DEFAULT_ALGO = SHA384;
131
-
132
- const BASE64 = 'base64';
133
-
134
- const { imports, scopes } = json;
135
-
136
- class Importmap {
137
- #imports = {};
138
- #scopes = {};
139
- #base;
140
-
141
- constructor({ imports: i = imports, scopes: s = scopes } = {}) {
142
- this.#imports = i;
143
- this.#scopes = s;
144
- }
145
-
146
- get imports() {
147
- return structuredClone(this.#imports);
148
- }
149
-
150
- get scopes() {
151
- return structuredClone(this.#scopes);
152
- }
153
-
154
- delete(key) {
155
- return Reflect.deleteProperty(this.#imports, key);
156
- }
157
-
158
- get(key) {
159
- return Reflect.get(this.#imports, key);
160
- }
161
-
162
- has(key) {
163
- return Reflect.has(this.#imports, key);
164
- }
165
-
166
- set(key, newValue) {
167
- return Reflect.set(this.#imports, key, newValue);
168
- }
169
-
170
- toJSON() {
171
- return { imports: this.#imports, scopes: this.#scopes };
172
- }
173
-
174
- toString() {
175
- return JSON.stringify(this);
176
- }
177
-
178
- get baseUrl() {
179
- return this.#base;
180
- }
181
-
182
- set baseUrl(val) {
183
- if (typeof val === 'string' && URL.canParse(val)) {
184
- this.#base = val;
185
- }
186
- }
187
-
188
- resolve(specifier, base = this.baseUrl) {
189
- if (specifier instanceof URL) {
190
- return specifier.href;
191
- } else if (typeof specifier !== 'string') {
192
- return null;
193
- } else if (this.has(specifier)) {
194
- return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
195
- } else if (URL.canParse(specifier)) {
196
- return specifier;
197
- } else if (! specifier.startsWith('.')) {
198
- // Find the longest match
199
- const matches = Object.keys(this.imports)
200
- .filter(key => key.endsWith('/') && specifier.startsWith(key))
201
- .sort((a, b) => b.length - a.length);
202
-
203
- if (matches.length === 0) {
204
- return null;
205
- } else {
206
- const match = matches[0];
207
- const target = imports[match];
208
- const subpath = specifier.slice(match.length);
209
- // Resolve the mapping target against the map's base, then the subpath against that
210
- const resolvedTarget = new URL(target, this.baseUrl);
211
- return new URL(subpath, resolvedTarget).href;
212
- }
213
- } else if (typeof base === 'string') {
214
- return URL.parse(specifier, base)?.href ?? null;
215
- } else {
216
- return null;
217
- }
218
- }
219
-
220
- async importLocalPackage(name = 'package.json', { signal } = {}) {
221
- const path = join(process.cwd(), name);
222
- const pkg = await readFile(path, { encoding: 'utf8', signal });
223
-
224
- return this.setLocalPackage(JSON.parse(pkg));
225
- }
226
-
227
- setLocalPackage({ name, module, exports = {} }) {
228
- if (typeof name !== 'string') {
229
- return false;
230
- } else if (typeof exports === 'string' ) {
231
- this.set(name, exports);
232
- return true;
233
- } else if (typeof exports === 'object') {
234
- Object.entries(exports).forEach(([key, value]) => {
235
- if (key.startsWith('.')) {
236
- const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
237
- const resolved = typeof value === 'string' ? value : value.import ?? value.default;
238
-
239
- if (typeof resolved === 'string' && resolved.startsWith('./')) {
240
- if (importKey.includes('*') && resolved.includes('*')) {
241
- const [prefix, suffix] = importKey.split('*');
242
-
243
- if (resolved.endsWith('*' + suffix)) {
244
- this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
245
- }
246
- } else {
247
- this.set(importKey, resolved.substring(1));
248
- }
249
- }
250
- }
251
- });
252
-
253
- return true;
254
- } else if (typeof module === 'string') {
255
- this.set(name, module);
256
- return true;
257
- } else {
258
- this.set(name, '/');
259
- return true;
260
- }
261
- }
262
-
263
- async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
264
- const integrity = await this.getIntegrity({ algo, alphabet, signal });
265
-
266
- return `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
267
- }
268
-
269
- async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
270
- if (signal instanceof AbortSignal && signal.aborted) {
271
- throw signal.reason;
272
- } else {
273
- const prefix = algo.toLowerCase().replace('-', '') + '-';
274
- const encoded = new TextEncoder().encode(this);
275
- const hash = await crypto.subtle.digest(algo, encoded);
276
-
277
- return prefix + new Uint8Array(hash).toBase64({ alphabet });
278
- }
279
- }
280
-
281
- static get SHA256() {
282
- return SHA256;
283
- }
284
-
285
- static get SHA384() {
286
- return SHA384;
287
- }
288
-
289
- static get SHA512() {
290
- return SHA512;
291
- }
292
-
293
- static async importFromFile(path = 'importmap.json', { signal } = {}) {
294
- const fullPath = join(process.cwd(), path);
295
- const importmap = await readFile(fullPath, { encoding: 'utf8', signal });
5
+ import { program } from 'commander';
6
+ import { extname } from 'node:path';
296
7
 
297
- return new Importmap(JSON.parse(importmap));
298
- }
299
- }
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;
300
10
 
301
- const importmap = new Importmap({ imports, scopes });
11
+ var pkg = JSON.parse('{\n "name": "@shgysk8zer0/importmap",\n "version": "1.8.1",\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.3",\n "@shgysk8zer0/rollup-import": "^2.0.2",\n "eslint": "^10.0.2"\n },\n "dependencies": {\n "@shgysk8zer0/npm-utils": "^1.1.4",\n "@shgysk8zer0/polyfills": "^0.6.2",\n "commander": "^14.0.3"\n }\n}\n');
302
12
 
303
- // 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.4/",\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.5/bundle.min.js",\n "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",\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.33/core.js",\n "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.33/",\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.0/callbackRegistry.js",\n "@aegisjsproject/callback-registry/": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.0/",\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.1/",\n "@aegisjsproject/commands": "https://unpkg.com/@aegisjsproject/commands@1.0.1/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 "@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.3/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.4/index.js",\n "qr/": "https://unpkg.com/qr@0.5.4/",\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.2.1/",\n "normalize.css": "https://unpkg.com/normalize.css@8.0.1/normalize.css"\n },\n "scopes": {}\n}');
304
14
 
305
15
  function guessFileType(file) {
306
16
  const ext = extname(file).toLowerCase();
@@ -329,15 +39,19 @@ async function parse(file, { encoding, signal } = {}) {
329
39
  case 'json':
330
40
  return readJSONFile(file, { encoding, signal });
331
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
+
332
48
  }
333
49
  }
334
50
 
335
51
  async function init() {
336
- const { version: VERSION } = await readJSONFile(new URL('./package.json', import.meta.url));
337
-
338
52
  program
339
- .name('importmap-utils')
340
- .version(VERSION)
53
+ .name(Object.keys(pkg.bin)[0])
54
+ .version(pkg.version)
341
55
  .description('CLI utility for updating importmap files')
342
56
  .option('-i, --input [input]', 'local JSON or YAML importmap file')
343
57
  .option('-e, --encoding [encoding]', 'encoding', 'utf8')
@@ -353,10 +67,10 @@ async function init() {
353
67
 
354
68
  init().then(async ({ opts: { input, encoding, format, output }}) => {
355
69
  const mod = typeof input === 'string'
356
- ? await parse(input, { encoding }).then(({ imports, scope = {}, ...rest }) => ({
70
+ ? await parse(input, { encoding }).then(({ imports, scopes = {}, ...rest }) => ({
357
71
  ...rest,
358
72
  imports: { ...imports, ...importmap.imports },
359
- scope: { ...scope, ...importmap.scope },
73
+ scopes: { ...scopes, ...importmap.scopes },
360
74
  }))
361
75
  : importmap;
362
76
 
@@ -368,9 +82,5 @@ init().then(async ({ opts: { input, encoding, format, output }}) => {
368
82
  case 'yaml':
369
83
  await writeYAMLFile(output, mod, { encoding });
370
84
  break;
371
-
372
- // case 'html':
373
- // await updateImportMap(output, { spaces: null });
374
- // break;
375
85
  }
376
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.1",\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.3",\n "@shgysk8zer0/rollup-import": "^2.0.2",\n "eslint": "^10.0.2"\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.1",\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.3",\n "@shgysk8zer0/rollup-import": "^2.0.2",\n "eslint": "^10.0.2"\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
+ });