@shgysk8zer0/importmap 1.0.0
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 +11 -0
- package/LICENSE +21 -0
- package/README.md +72 -0
- package/index.cjs +62 -0
- package/index.js +40 -0
- package/package.json +39 -0
- package/versions.js +12 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [v1.0.0] - 2023-05-30
|
|
10
|
+
|
|
11
|
+
Initial Release
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Chris Zuber
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @shgysk8zer0/importmap
|
|
2
|
+
Front-End dependencies based on [`<script type="importmap">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap)
|
|
3
|
+
|
|
4
|
+
Intended for use with [`rollup`](https://rollupjs.org/) and [`@shgysk8zer0/rollup-import`](https://www.npmjs.com/package/@shgysk8zer0/rollup-import).
|
|
5
|
+
|
|
6
|
+
- - -
|
|
7
|
+
[](https://github.com/shgysk8zer0/importmap/actions/workflows/codeql-analysis.yml)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
[](https://github.com/shgysk8zer0/importmap/blob/master/LICENSE)
|
|
12
|
+
[](https://github.com/shgysk8zer0/importmap/commits/master)
|
|
13
|
+
[](https://github.com/shgysk8zer0/importmap/releases)
|
|
14
|
+
[](https://github.com/sponsors/shgysk8zer0)
|
|
15
|
+
|
|
16
|
+
[](https://www.npmjs.com/package/@shgysk8zer0/importmap)
|
|
17
|
+

|
|
18
|
+

|
|
19
|
+
[](https://www.npmjs.com/package/@shgysk8zer0/importmap)
|
|
20
|
+
|
|
21
|
+
[](https://github.com/shgysk8zer0)
|
|
22
|
+

|
|
23
|
+

|
|
24
|
+
[](https://twitter.com/shgysk8zer0)
|
|
25
|
+
|
|
26
|
+
[](https://liberapay.com/shgysk8zer0/donate "Donate using Liberapay")
|
|
27
|
+
- - -
|
|
28
|
+
|
|
29
|
+
- [Code of Conduct](./.github/CODE_OF_CONDUCT.md)
|
|
30
|
+
- [Contributing](./.github/CONTRIBUTING.md)
|
|
31
|
+
<!-- - [Security Policy](./.github/SECURITY.md) -->
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm i @shgysk8zer0/importmap
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
// rollup.config.js
|
|
43
|
+
import { rollupImport } from '@shgysk8zer0/rollup-import';
|
|
44
|
+
import { imports } from '@shgysk8zer0/importmap';
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
input: 'index.js',
|
|
48
|
+
output: {
|
|
49
|
+
file: 'index.min.js',
|
|
50
|
+
format: 'iife',
|
|
51
|
+
sourcemap: true,
|
|
52
|
+
},
|
|
53
|
+
plugins: [rollupImport({ imports })],
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## For `<script type="importmap">`
|
|
58
|
+
|
|
59
|
+
The module exports `getImportMapScript()`, which can be used to generate the
|
|
60
|
+
required importmap `<script>`:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { getImportMapScript } from '@shgysk8zer0/importmap';
|
|
64
|
+
|
|
65
|
+
getImportMapScript();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Which results in:
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<script type="importmap" integrity="sha384-...">{"imports": {}, "scope": {}}</script>
|
|
72
|
+
```
|
package/index.cjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('node:fs/promises');
|
|
4
|
+
var node_crypto = require('node:crypto');
|
|
5
|
+
|
|
6
|
+
const versions = {
|
|
7
|
+
'@shgysk8zer0/kazoo': '0.0.16',
|
|
8
|
+
'@shgysk8zer0/konami': '1.0.9',
|
|
9
|
+
'@shgysk8zer0/polyfills': '0.0.7',
|
|
10
|
+
'@shgysk8zer0/components': '0.0.9',
|
|
11
|
+
'@shgysk8zer0/http-status': '1.0.1',
|
|
12
|
+
'leaflet': '1.9.3',
|
|
13
|
+
'firebase': '9.16.0',
|
|
14
|
+
'url-pattern': '8.0.2',
|
|
15
|
+
'@webcomponents/custom-elements': '1.6.0',
|
|
16
|
+
'highlight.js': '11.8.0',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ENCODING = 'utf8';
|
|
20
|
+
const ALGO = 'sha384';
|
|
21
|
+
|
|
22
|
+
const imports = {
|
|
23
|
+
'@shgysk8zer0/kazoo/': `https://unpkg.com/@shgysk8zer0/kazoo@${versions['@shgysk8zer0/kazoo']}/`,
|
|
24
|
+
'@shgysk8zer0/konami': `https://unpkg.com/@shgysk8zer0/konami@${versions['@shgysk8zer0/konami']}/konami.js`,
|
|
25
|
+
'@shgysk8zer0/polyfills': `https://unpkg.com/@shgysk8zer0/polyfills@${versions['@shgysk8zer0/polyfills']}/all.min.js`,
|
|
26
|
+
'@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/`,
|
|
29
|
+
'@shgysk8zer0/http-status': `https://unpkg.com/@shgysk8zer0/http-status@${versions['@shgysk8zer0/http-status']}/http-status.js`,
|
|
30
|
+
'leaflet': `https://unpkg.com/leaflet@[${versions.leaflet}]/dist/leaflet-src.esm.js`,
|
|
31
|
+
'firebase/': `https://www.gstatic.com/firebasejs${versions.firebase}/`,
|
|
32
|
+
'url-pattern': `https://unpkg.com/urlpattern-polyfill@${versions['url-pattern']}/index.js`,
|
|
33
|
+
'custom-elements': `https://unpkg.com/@webcomponents/custom-elements@${versions['@webcomponents/custom-elements']}/custom-elements.min.js`,
|
|
34
|
+
'highlight.js': `https://unpkg.com/@highlightjs/cdn-assets@${versions['highlight.js']}/es/highlight.min.js`,
|
|
35
|
+
'highlight.js/': `https://unpkg.com/@highlightjs/cdn-assets@${versions['lighlight.js']}/`,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const scope = {};
|
|
39
|
+
|
|
40
|
+
async function createImportmapJSON(path = 'importmap.json', { signal, spaces = 2 } = {}) {
|
|
41
|
+
await promises.writeFile(path, JSON.stringify({ imports, scope }, null, spaces), { encoding: ENCODING, signal });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getImportmapIntegrity({ algo = ALGO, spaces = 0 } = {}) {
|
|
45
|
+
const hash = node_crypto.createHash(algo);
|
|
46
|
+
hash.update(JSON.stringify({ imports, scope }, null, spaces), 'utf8');
|
|
47
|
+
return `${algo}-${hash.digest('base64')}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getImportMapScript({ algo = ALGO, spaces = 0 } = {}) {
|
|
51
|
+
const integrity = getImportmapIntegrity({ algo, spaces });
|
|
52
|
+
const json = JSON.stringify({ imports, scope }, null, spaces);
|
|
53
|
+
return `<script type="importmap" integrity="${integrity}">${json}</script>`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.ALGO = ALGO;
|
|
57
|
+
exports.ENCODING = ENCODING;
|
|
58
|
+
exports.createImportmapJSON = createImportmapJSON;
|
|
59
|
+
exports.getImportMapScript = getImportMapScript;
|
|
60
|
+
exports.getImportmapIntegrity = getImportmapIntegrity;
|
|
61
|
+
exports.imports = imports;
|
|
62
|
+
exports.scope = scope;
|
package/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { versions } from './versions.js';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
export const ENCODING = 'utf8';
|
|
6
|
+
export const ALGO = 'sha384';
|
|
7
|
+
|
|
8
|
+
export const imports = {
|
|
9
|
+
'@shgysk8zer0/kazoo/': `https://unpkg.com/@shgysk8zer0/kazoo@${versions['@shgysk8zer0/kazoo']}/`,
|
|
10
|
+
'@shgysk8zer0/konami': `https://unpkg.com/@shgysk8zer0/konami@${versions['@shgysk8zer0/konami']}/konami.js`,
|
|
11
|
+
'@shgysk8zer0/polyfills': `https://unpkg.com/@shgysk8zer0/polyfills@${versions['@shgysk8zer0/polyfills']}/all.min.js`,
|
|
12
|
+
'@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/`,
|
|
15
|
+
'@shgysk8zer0/http-status': `https://unpkg.com/@shgysk8zer0/http-status@${versions['@shgysk8zer0/http-status']}/http-status.js`,
|
|
16
|
+
'leaflet': `https://unpkg.com/leaflet@[${versions.leaflet}]/dist/leaflet-src.esm.js`,
|
|
17
|
+
'firebase/': `https://www.gstatic.com/firebasejs${versions.firebase}/`,
|
|
18
|
+
'url-pattern': `https://unpkg.com/urlpattern-polyfill@${versions['url-pattern']}/index.js`,
|
|
19
|
+
'custom-elements': `https://unpkg.com/@webcomponents/custom-elements@${versions['@webcomponents/custom-elements']}/custom-elements.min.js`,
|
|
20
|
+
'highlight.js': `https://unpkg.com/@highlightjs/cdn-assets@${versions['highlight.js']}/es/highlight.min.js`,
|
|
21
|
+
'highlight.js/': `https://unpkg.com/@highlightjs/cdn-assets@${versions['lighlight.js']}/`,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const scope = {};
|
|
25
|
+
|
|
26
|
+
export async function createImportmapJSON(path = 'importmap.json', { signal, spaces = 2 } = {}) {
|
|
27
|
+
await writeFile(path, JSON.stringify({ imports, scope }, null, spaces), { encoding: ENCODING, signal });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getImportmapIntegrity({ algo = ALGO, spaces = 0 } = {}) {
|
|
31
|
+
const hash = createHash(algo);
|
|
32
|
+
hash.update(JSON.stringify({ imports, scope }, null, spaces), 'utf8');
|
|
33
|
+
return `${algo}-${hash.digest('base64')}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getImportMapScript({ algo = ALGO, spaces = 0 } = {}) {
|
|
37
|
+
const integrity = getImportmapIntegrity({ algo, spaces });
|
|
38
|
+
const json = JSON.stringify({ imports, scope }, null, spaces);
|
|
39
|
+
return `<script type="importmap" integrity="${integrity}">${json}</script>`;
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shgysk8zer0/importmap",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=18.0.0"
|
|
6
|
+
},
|
|
7
|
+
"description": "Front-End dependencies based on `<script type=\"importmap\">`",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"module": "index.js",
|
|
10
|
+
"main": "index.cjs",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "npm run lint:js && npm run build",
|
|
13
|
+
"preversion": "npm test",
|
|
14
|
+
"prepare": "npm run build",
|
|
15
|
+
"lint:js": "eslint .",
|
|
16
|
+
"fix:js": "eslint. --fix",
|
|
17
|
+
"build": "npm run build:js",
|
|
18
|
+
"build:js": "rollup -c",
|
|
19
|
+
"create:lock": "npm i --package-lock-only",
|
|
20
|
+
"version:bump": "npm run version:bump:patch",
|
|
21
|
+
"version:bump:patch": "npm version --no-git-tag-version patch",
|
|
22
|
+
"version:bump:minor": "npm version --no-git-tag-version minor",
|
|
23
|
+
"version:bump:major": "npm version --no-git-tag-version major"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/shgysk8zer0/importmap.git"
|
|
28
|
+
},
|
|
29
|
+
"author": "Chris Zuber <admin@kernvalley.us>",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/shgysk8zer0/importmap/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/shgysk8zer0/importmap#readme",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"eslint": "^8.41.0",
|
|
37
|
+
"rollup": "^3.23.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/versions.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const versions = {
|
|
2
|
+
'@shgysk8zer0/kazoo': '0.0.16',
|
|
3
|
+
'@shgysk8zer0/konami': '1.0.9',
|
|
4
|
+
'@shgysk8zer0/polyfills': '0.0.7',
|
|
5
|
+
'@shgysk8zer0/components': '0.0.9',
|
|
6
|
+
'@shgysk8zer0/http-status': '1.0.1',
|
|
7
|
+
'leaflet': '1.9.3',
|
|
8
|
+
'firebase': '9.16.0',
|
|
9
|
+
'url-pattern': '8.0.2',
|
|
10
|
+
'@webcomponents/custom-elements': '1.6.0',
|
|
11
|
+
'highlight.js': '11.8.0',
|
|
12
|
+
};
|