@shgysk8zer0/importmap 1.4.9 → 1.4.10

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 CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [v1.4.10] - 20204-09-20
11
+
12
+ ### Fixed
13
+ - Export the correct files
14
+
10
15
  ## [v1.4.9] - 2024-09-20
11
16
 
12
17
  ### Changed
package/index.js ADDED
@@ -0,0 +1,267 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ import { readYAMLFile, writeYAMLFile } from '@shgysk8zer0/npm-utils/yaml.js';
3
+ import { readJSONFile, writeJSONFile } from '@shgysk8zer0/npm-utils/json.js';
4
+ import { getFileURL } from '@shgysk8zer0/npm-utils/path.js';
5
+
6
+ const imports$1 = {
7
+ "@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.9/",
8
+ "@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.1/konami.js",
9
+ "@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.4.3/all.min.js",
10
+ "@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.4.3/",
11
+ "@shgysk8zer0/jwk-utils": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.0.15/jwk-utils.min.js",
12
+ "@shgysk8zer0/jwk-utils/": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.0.15/",
13
+ "@shgysk8zer0/jswaggersheets": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/swagger.js",
14
+ "@shgysk8zer0/jswaggersheets/": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/",
15
+ "@shgysk8zer0/jss/": "https://unpkg.com/@shgysk8zer0/jss@1.0.1/",
16
+ "@shgysk8zer0/consts/": "https://unpkg.com/@shgysk8zer0/consts@1.0.8/",
17
+ "@shgysk8zer0/http/": "https://unpkg.com/@shgysk8zer0/http@1.0.5/",
18
+ "@shgysk8zer0/http-status": "https://unpkg.com/@shgysk8zer0/http-status@1.1.1/http-status.js",
19
+ "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
20
+ "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
21
+ "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.0.9/bundle.min.js",
22
+ "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.0.9/",
23
+ "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.1.1/sanitizer.js",
24
+ "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.1.1/",
25
+ "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.14/core.js",
26
+ "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.14/",
27
+ "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.1.2/styles.js",
28
+ "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.1.2/",
29
+ "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.3/component.js",
30
+ "@aegisjsproject/component/": "https://unpkg.com/@aegisjsproject/component@0.1.3/",
31
+ "@aegisjsproject/markdown": "https://unpkg.com/@aegisjsproject/markdown@0.1.3/markdown.js",
32
+ "@aegisjsproject/markdown/": "https://unpkg.com/@aegisjsproject/markdown@0.1.3/",
33
+ "@aegisjsproject/aegis-md": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/aegis-md.js",
34
+ "@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",
35
+ "@shgysk8zer0/components/": "https://unpkg.com/@shgysk8zer0/components@0.3.13/",
36
+ "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.5/",
37
+ "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
38
+ leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
39
+ "urlpattern-polyfill": "https://unpkg.com/urlpattern-polyfill@10.0.0/index.js",
40
+ "highlight.js": "https://unpkg.com/@highlightjs/cdn-assets@11.10.0/es/core.min.js",
41
+ "highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.10.0/es/",
42
+ "@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.10.0/es/core.min.js",
43
+ "@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.10.0/es/",
44
+ marked: "https://unpkg.com/marked@14.1.2/lib/marked.esm.js",
45
+ "marked-highlight": "https://unpkg.com/marked-highlight@2.1.4/src/index.js",
46
+ yaml: "https://unpkg.com/yaml@2.5.1/browser/dist/index.js",
47
+ "yaml/": "https://unpkg.com/yaml@2.5.1/browser/dist/",
48
+ "firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",
49
+ "firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",
50
+ "firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",
51
+ "firebase/auth": "https://www.gstatic.com/firebasejs/10.12.1/firebase-auth.js",
52
+ "firebase/database": "https://www.gstatic.com/firebasejs/10.12.1/firebase-database.js",
53
+ "firebase/firestore": "https://www.gstatic.com/firebasejs/10.12.1/firebase-firestore.js",
54
+ "firebase/functions": "https://www.gstatic.com/firebasejs/10.12.1/firebase-functions.js",
55
+ "firebase/messaging": "https://www.gstatic.com/firebasejs/10.12.1/firebase-messaging.js",
56
+ "firebase/performance": "https://www.gstatic.com/firebasejs/10.12.1/firebase-performance.js",
57
+ "firebase/remote-config": "https://www.gstatic.com/firebasejs/10.12.1/firebase-remote-config.js",
58
+ "firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",
59
+ "firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js"
60
+ };
61
+ const scope$1 = {
62
+ };
63
+
64
+ var importmap = /*#__PURE__*/Object.freeze({
65
+ __proto__: null,
66
+ imports: imports$1,
67
+ scope: scope$1
68
+ });
69
+
70
+ const SHA384 = 'SHA-384';
71
+ const DEFAULT_ALGO = SHA384;
72
+
73
+ const BASE64 = 'base64';
74
+ const SRI = 'sri';
75
+ const HEX = 'hex';
76
+ const BUFFER = 'buffer';
77
+
78
+ async function hash(data, { algo = DEFAULT_ALGO, output = BUFFER } = {}) {
79
+ const buffer = await new TextEncoder().encode(data);
80
+ const hash = await crypto.subtle.digest(algo, buffer);
81
+
82
+ switch (output) {
83
+ case BUFFER:
84
+ return hash;
85
+
86
+ case HEX:
87
+ return Array.from(
88
+ new Uint8Array(hash),
89
+ byte => byte.toString(16).padStart(2, '0')
90
+ ).join('');
91
+
92
+ case BASE64:
93
+ return btoa(hash);
94
+
95
+ case SRI: {
96
+ const codeUnits = new Uint16Array(hash);
97
+ const charCodes = new Uint8Array(codeUnits.buffer);
98
+ const result = btoa(String.fromCharCode(...charCodes));
99
+ return `${algo.replace('-', '').toLowerCase()}-${result}`;
100
+ }
101
+
102
+ default:
103
+ throw new TypeError(`Unsupported output type: "${output}".`);
104
+ }
105
+ }
106
+
107
+ const sri = async(data, { algo = SHA384 } = {}) => hash(data, { algo, output: SRI });
108
+
109
+ const UNPKG = 'https://unpkg.com/';
110
+
111
+ const cache = new Map();
112
+
113
+ function parseUnpkgURL(src) {
114
+ const url = new URL(src, UNPKG);
115
+
116
+ if (! url.hostname === UNPKG || url.pathname.length === 1 || url.pathname === '/[object%20Object]') {
117
+ throw new Error(`${src} is not an unpkg URL.`);
118
+ } else {
119
+ const path = url.pathname.substr(1).split('/');
120
+
121
+ if (path.length === 0) {
122
+ throw new Error(`Invalid unpkg URL: ${src}`);
123
+ } else if (path.length !== 1 && path[0].startsWith('@')) {
124
+ const [pkg, version = null] = path[1].split('@');
125
+ return { scope: path[0], pkg, version, module: path.splice(2).join('/') };
126
+ } else {
127
+ const [pkg, version = null] = path[0].split('@');
128
+ return { scope: null, pkg, version, module: path.splice(1).join('/') };
129
+ }
130
+ }
131
+ }
132
+
133
+ function getUnpkgURL({ scope, pkg, version, module = '' }) {
134
+ // console.log({ scope, pkg, version });
135
+ if (typeof pkg !== 'string' || pkg.length === 0) {
136
+ throw new TypeError('Package name must be a non-empty string.');
137
+ } else if (typeof version !== 'string' || version.length === 0) {
138
+ throw new TypeError('Version must be a non-empty string.');
139
+ } else if (typeof scope === 'string' && scope.length !== 0) {
140
+ return new URL(`/${scope}/${pkg}@${version}/${module}`, UNPKG).href;
141
+ } else {
142
+ return new URL(`/${pkg}@${version}/${module}`, UNPKG).href;
143
+ }
144
+ }
145
+
146
+ async function getLatestVersion({ scope, pkg, signal } = {}) {
147
+ const path = typeof scope === 'string' ? `/${scope}/${pkg}/` : `/${pkg}/`;
148
+
149
+ if (cache.has(path)) {
150
+ return await cache.get(path);
151
+ } else {
152
+ const url = new URL(path, 'https://unpkg.com/');
153
+ url.searchParams.set('meta', '');
154
+
155
+ const promise = fetch(url, { method: 'HEAD', signal }).then(resp => {
156
+ const { version } = parseUnpkgURL(resp.url);
157
+ return version;
158
+ });
159
+
160
+ cache.set(path, promise);
161
+ return promise;
162
+ }
163
+ }
164
+
165
+ async function update(imports) {
166
+ let updated = false;
167
+
168
+ const entries = await Promise.all(Object.entries(imports)
169
+ .filter(([,val]) => val.startsWith(UNPKG))
170
+ .map(async ([key, val]) => {
171
+ const { scope, pkg, version: oldVersion, module } = parseUnpkgURL(val);
172
+ const version = await getLatestVersion({ scope, pkg });
173
+
174
+ if (! updated && version > oldVersion) {
175
+ updated = true;
176
+ }
177
+
178
+ return [key, getUnpkgURL({ scope, pkg, version, module })];
179
+ })
180
+ );
181
+
182
+ return { imports: Object.fromEntries(entries), updated };
183
+ }
184
+
185
+ async function updateUnpkg(imports) {
186
+ return update(imports);
187
+ }
188
+
189
+ async function updateYAML(file) {
190
+ if (typeof file === 'string') {
191
+ return await updateJSON(getFileURL(file));
192
+ } else if (file instanceof URL && file.protocol === 'file:') {
193
+ const importmap = await readYAMLFile(file);
194
+ const { updated, imports } = await update(importmap.imports);
195
+
196
+ if (updated) {
197
+ await writeYAMLFile(file, { ...importmap, imports: { ...importmap.imports, ...imports }});
198
+ return true;
199
+ } else {
200
+ return false;
201
+ }
202
+ } else {
203
+ throw new TypeError('File must be a path or file: URL.');
204
+ }
205
+
206
+ }
207
+
208
+ async function updateJSON(file) {
209
+ if (typeof file === 'string') {
210
+ return await updateJSON(getFileURL(file));
211
+ } else if (file instanceof URL && file.protocol === 'file:') {
212
+ const importmap = await readJSONFile(file);
213
+ const { updated, imports } = await update(importmap.imports);
214
+
215
+ if (updated) {
216
+ await writeJSONFile(file, { ...importmap, imports: { ...importmap.imports, ...imports }});
217
+ return true;
218
+ } else {
219
+ return false;
220
+ }
221
+ } else {
222
+ throw new TypeError('File must be a path or file: URL.');
223
+ }
224
+ }
225
+
226
+ var unpkg = /*#__PURE__*/Object.freeze({
227
+ __proto__: null,
228
+ update: update,
229
+ updateJSON: updateJSON,
230
+ updateUnpkg: updateUnpkg,
231
+ updateYAML: updateYAML
232
+ });
233
+
234
+ const { imports, scope } = importmap;
235
+ const ENCODING = 'utf8';
236
+
237
+ function mergeWithImportmap({ imports = {}, scope = {}}) {
238
+ return {
239
+ imports: { ...imports$1, ...imports },
240
+ scope: { ...scope$1, ...scope },
241
+ };
242
+ }
243
+
244
+ async function createImportmapJSON(path = 'importmap.json', {
245
+ importmap = { imports, scope },
246
+ spaces = 2,
247
+ signal,
248
+ } = {}) {
249
+ await writeFile(path, JSON.stringify(importmap, null, spaces), { encoding: ENCODING, signal });
250
+ }
251
+
252
+ async function getImportmapIntegrity({
253
+ importmap = { imports, scope },
254
+ algo = DEFAULT_ALGO,
255
+ } = {}) {
256
+ return await sri(JSON.stringify(importmap), { algo });
257
+ }
258
+
259
+ async function getImportmapScript({
260
+ importmap = { imports, scope },
261
+ algo = DEFAULT_ALGO,
262
+ } = {}) {
263
+ const integrity = await getImportmapIntegrity({ importmap, algo });
264
+ return `<script type="importmap" integrity="${integrity}">${JSON.stringify(importmap)}</script>`;
265
+ }
266
+
267
+ export { ENCODING, createImportmapJSON, getImportmapIntegrity, getImportmapScript, importmap, imports, mergeWithImportmap, scope, unpkg };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgysk8zer0/importmap",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "engines": {
5
5
  "node": ">=18.0.0"
6
6
  },
package/importmap.mjs DELETED
@@ -1 +0,0 @@
1
- export * from './importmap.json' with { type: 'json' };
package/index.mjs DELETED
@@ -1,38 +0,0 @@
1
- import { writeFile } from 'node:fs/promises';
2
- import * as importmap from './importmap.mjs';
3
- import { sri, DEFAULT_ALGO } from './hash.js';
4
-
5
- export const { imports, scope } = importmap;
6
- export const ENCODING = 'utf8';
7
- export { importmap };
8
- export * as unpkg from './unpkg.js';
9
-
10
- export function mergeWithImportmap({ imports = {}, scope = {}}) {
11
- return {
12
- imports: { ...importmap.imports, ...imports },
13
- scope: { ...importmap.scope, ...scope },
14
- };
15
- }
16
-
17
- export async function createImportmapJSON(path = 'importmap.json', {
18
- importmap = { imports, scope },
19
- spaces = 2,
20
- signal,
21
- } = {}) {
22
- await writeFile(path, JSON.stringify(importmap, null, spaces), { encoding: ENCODING, signal });
23
- }
24
-
25
- export async function getImportmapIntegrity({
26
- importmap = { imports, scope },
27
- algo = DEFAULT_ALGO,
28
- } = {}) {
29
- return await sri(JSON.stringify(importmap), { algo });
30
- }
31
-
32
- export async function getImportmapScript({
33
- importmap = { imports, scope },
34
- algo = DEFAULT_ALGO,
35
- } = {}) {
36
- const integrity = await getImportmapIntegrity({ importmap, algo });
37
- return `<script type="importmap" integrity="${integrity}">${JSON.stringify(importmap)}</script>`;
38
- }