@shgysk8zer0/importmap 1.0.0 → 1.0.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.
Files changed (4) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/index.cjs +35 -12
  3. package/index.js +34 -13
  4. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [v1.0.1] - 2023-06-01
10
+
11
+ ### Added
12
+ - Functions and constants and params to merge importmaps or work with different ones
13
+
14
+ ### Fixed
15
+ - Fix typo with missing `"@"` in some mapped URLs
16
+
17
+ ### Changed
18
+ - Update GitHub Release Action
19
+
9
20
  ## [v1.0.0] - 2023-05-30
10
21
 
11
22
  Initial Release
package/index.cjs CHANGED
@@ -16,16 +16,13 @@ const versions = {
16
16
  'highlight.js': '11.8.0',
17
17
  };
18
18
 
19
- const ENCODING = 'utf8';
20
- const ALGO = 'sha384';
21
-
22
19
  const imports = {
23
20
  '@shgysk8zer0/kazoo/': `https://unpkg.com/@shgysk8zer0/kazoo@${versions['@shgysk8zer0/kazoo']}/`,
24
21
  '@shgysk8zer0/konami': `https://unpkg.com/@shgysk8zer0/konami@${versions['@shgysk8zer0/konami']}/konami.js`,
25
22
  '@shgysk8zer0/polyfills': `https://unpkg.com/@shgysk8zer0/polyfills@${versions['@shgysk8zer0/polyfills']}/all.min.js`,
26
23
  '@shgysk8zer0/polyfills/': `https://unpkg.com/@shgysk8zer0/polyfills@${versions['@shgysk8zer0/polyfills']}/`,
27
- '@shgysk8zer0/components/': `https://unpkg.com/@shgysk8zer0/components${versions['@shgysk8zer0/components']}/`,
28
- '@kernvalley/components/': `https://unpkg.com/@shgysk8zer0/components${versions['@shgysk8zer0/components']}/krv/`,
24
+ '@shgysk8zer0/components/': `https://unpkg.com/@shgysk8zer0/components@${versions['@shgysk8zer0/components']}/`,
25
+ '@kernvalley/components/': `https://unpkg.com/@shgysk8zer0/components@${versions['@shgysk8zer0/components']}/krv/`,
29
26
  '@shgysk8zer0/http-status': `https://unpkg.com/@shgysk8zer0/http-status@${versions['@shgysk8zer0/http-status']}/http-status.js`,
30
27
  'leaflet': `https://unpkg.com/leaflet@[${versions.leaflet}]/dist/leaflet-src.esm.js`,
31
28
  'firebase/': `https://www.gstatic.com/firebasejs${versions.firebase}/`,
@@ -36,20 +33,44 @@ const imports = {
36
33
  };
37
34
 
38
35
  const scope = {};
36
+ const importmap = { imports, scope };
37
+ const ENCODING = 'utf8';
38
+ const ALGO = 'sha384';
39
+
40
+ function mergeWithImportmap({ imports = {}, scope = {}}) {
41
+ return {
42
+ imports: { ...importmap.imports, ...imports },
43
+ scope: { ...importmap.scope, ...scope },
44
+ };
45
+ }
39
46
 
40
- async function createImportmapJSON(path = 'importmap.json', { signal, spaces = 2 } = {}) {
41
- await promises.writeFile(path, JSON.stringify({ imports, scope }, null, spaces), { encoding: ENCODING, signal });
47
+ async function createImportmapJSON(path = 'importmap.json', {
48
+ importmap = { imports, scope },
49
+ spaces = 2,
50
+ signal,
51
+ } = {}) {
52
+ await promises.writeFile(path, JSON.stringify(importmap, null, spaces), { encoding: ENCODING, signal });
42
53
  }
43
54
 
44
- function getImportmapIntegrity({ algo = ALGO, spaces = 0 } = {}) {
55
+ function getImportmapIntegrity({
56
+ importmap = { imports, scope },
57
+ algo = ALGO,
58
+ encoding = ENCODING,
59
+ spaces = 2,
60
+ } = {}) {
45
61
  const hash = node_crypto.createHash(algo);
46
- hash.update(JSON.stringify({ imports, scope }, null, spaces), 'utf8');
62
+ hash.update(JSON.stringify(importmap, null, spaces), encoding);
47
63
  return `${algo}-${hash.digest('base64')}`;
48
64
  }
49
65
 
50
- function getImportMapScript({ algo = ALGO, spaces = 0 } = {}) {
51
- const integrity = getImportmapIntegrity({ algo, spaces });
52
- const json = JSON.stringify({ imports, scope }, null, spaces);
66
+ function getImportMapScript({
67
+ importmap = { imports, scope },
68
+ algo = ALGO,
69
+ encoding = ENCODING,
70
+ spaces = 2,
71
+ } = {}) {
72
+ const integrity = getImportmapIntegrity({ importmap, algo, encoding, spaces });
73
+ const json = JSON.stringify(importmap, null, spaces);
53
74
  return `<script type="importmap" integrity="${integrity}">${json}</script>`;
54
75
  }
55
76
 
@@ -58,5 +79,7 @@ exports.ENCODING = ENCODING;
58
79
  exports.createImportmapJSON = createImportmapJSON;
59
80
  exports.getImportMapScript = getImportMapScript;
60
81
  exports.getImportmapIntegrity = getImportmapIntegrity;
82
+ exports.importmap = importmap;
61
83
  exports.imports = imports;
84
+ exports.mergeWithImportmap = mergeWithImportmap;
62
85
  exports.scope = scope;
package/index.js CHANGED
@@ -1,17 +1,14 @@
1
1
  import { writeFile } from 'node:fs/promises';
2
- import { versions } from './versions.js';
3
2
  import { createHash } from 'node:crypto';
4
-
5
- export const ENCODING = 'utf8';
6
- export const ALGO = 'sha384';
3
+ import { versions } from './versions.js';
7
4
 
8
5
  export const imports = {
9
6
  '@shgysk8zer0/kazoo/': `https://unpkg.com/@shgysk8zer0/kazoo@${versions['@shgysk8zer0/kazoo']}/`,
10
7
  '@shgysk8zer0/konami': `https://unpkg.com/@shgysk8zer0/konami@${versions['@shgysk8zer0/konami']}/konami.js`,
11
8
  '@shgysk8zer0/polyfills': `https://unpkg.com/@shgysk8zer0/polyfills@${versions['@shgysk8zer0/polyfills']}/all.min.js`,
12
9
  '@shgysk8zer0/polyfills/': `https://unpkg.com/@shgysk8zer0/polyfills@${versions['@shgysk8zer0/polyfills']}/`,
13
- '@shgysk8zer0/components/': `https://unpkg.com/@shgysk8zer0/components${versions['@shgysk8zer0/components']}/`,
14
- '@kernvalley/components/': `https://unpkg.com/@shgysk8zer0/components${versions['@shgysk8zer0/components']}/krv/`,
10
+ '@shgysk8zer0/components/': `https://unpkg.com/@shgysk8zer0/components@${versions['@shgysk8zer0/components']}/`,
11
+ '@kernvalley/components/': `https://unpkg.com/@shgysk8zer0/components@${versions['@shgysk8zer0/components']}/krv/`,
15
12
  '@shgysk8zer0/http-status': `https://unpkg.com/@shgysk8zer0/http-status@${versions['@shgysk8zer0/http-status']}/http-status.js`,
16
13
  'leaflet': `https://unpkg.com/leaflet@[${versions.leaflet}]/dist/leaflet-src.esm.js`,
17
14
  'firebase/': `https://www.gstatic.com/firebasejs${versions.firebase}/`,
@@ -22,19 +19,43 @@ export const imports = {
22
19
  };
23
20
 
24
21
  export const scope = {};
22
+ export const importmap = { imports, scope };
23
+ export const ENCODING = 'utf8';
24
+ export const ALGO = 'sha384';
25
+
26
+ export function mergeWithImportmap({ imports = {}, scope = {}}) {
27
+ return {
28
+ imports: { ...importmap.imports, ...imports },
29
+ scope: { ...importmap.scope, ...scope },
30
+ };
31
+ }
25
32
 
26
- export async function createImportmapJSON(path = 'importmap.json', { signal, spaces = 2 } = {}) {
27
- await writeFile(path, JSON.stringify({ imports, scope }, null, spaces), { encoding: ENCODING, signal });
33
+ export async function createImportmapJSON(path = 'importmap.json', {
34
+ importmap = { imports, scope },
35
+ spaces = 2,
36
+ signal,
37
+ } = {}) {
38
+ await writeFile(path, JSON.stringify(importmap, null, spaces), { encoding: ENCODING, signal });
28
39
  }
29
40
 
30
- export function getImportmapIntegrity({ algo = ALGO, spaces = 0 } = {}) {
41
+ export function getImportmapIntegrity({
42
+ importmap = { imports, scope },
43
+ algo = ALGO,
44
+ encoding = ENCODING,
45
+ spaces = 2,
46
+ } = {}) {
31
47
  const hash = createHash(algo);
32
- hash.update(JSON.stringify({ imports, scope }, null, spaces), 'utf8');
48
+ hash.update(JSON.stringify(importmap, null, spaces), encoding);
33
49
  return `${algo}-${hash.digest('base64')}`;
34
50
  }
35
51
 
36
- export function getImportMapScript({ algo = ALGO, spaces = 0 } = {}) {
37
- const integrity = getImportmapIntegrity({ algo, spaces });
38
- const json = JSON.stringify({ imports, scope }, null, spaces);
52
+ export function getImportMapScript({
53
+ importmap = { imports, scope },
54
+ algo = ALGO,
55
+ encoding = ENCODING,
56
+ spaces = 2,
57
+ } = {}) {
58
+ const integrity = getImportmapIntegrity({ importmap, algo, encoding, spaces });
59
+ const json = JSON.stringify(importmap, null, spaces);
39
60
  return `<script type="importmap" integrity="${integrity}">${json}</script>`;
40
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgysk8zer0/importmap",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "engines": {
5
5
  "node": ">=18.0.0"
6
6
  },