Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules/
.gitignore
.nvmrc
index.html
index.js
importmap.json
importmap.yaml
*.config.js
Expand Down
89 changes: 1 addition & 88 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,93 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add `@aegisjsproject/dev-server`

### Changed
- Update CSP, template, etc

## [v1.1.3] - 2025-11-21

### Added
- Add `npm start` script

### Changed
- Update npm publishing

## [v1.1.2] - 2025-05-01

### Changed
- Use `eslint` & `rollup` directly instead of by other packages
- Update node version via `.npmrc`
- Update Node CI workflow
- Install & use `@shgysk8zer0/eslint-config`
- Add support for `node --test`, including ignoring tests for publishing
- Update ESLint & super-linter
- Switch to more basic Rollup config
- Update `exports` and `main` accordingly

### Fixed
- Fix missed renaming in README

## Removed
- Remove old ESLint config files

## [v1.1.1] - 2023-09-24

### Added
- Add `unpkg` to `package.json`
- Add badges in README

### Changed
- Update `exports` to `package.json` to handle wider variety

### Fixed
- Fix typo in `fix:js` script

### [v1.1.0] - 2023-07-03

### Changed
- Update to node 20
- Update npm publishing GH Action

## [v1.0.5] - 2023-07-02

### Added
- Add `funding`

### Changed
- Updated GitHub Actions workflows
- Update versioning & lock-file scripts
- Update `.npmignore` & `.gitignore`

## [v1.0.4] - 2023-06-08

### Added
- Install `@shgysk8zer0/npm-utils`
- Add `exports` to package config

### Removed
- Uninstall `rollup`, `eslint`

### Changed
- Use `getConfig()` from `@shgysk8zer0/js-utils/rollup` for rollup config

## [v1.0.3] - 2023-06-01

### Fixed
- Revert to old Release Action, now with permissions & link to changelog

## [v1.0.2] - 2023-06-01

### Fixed
- Fix `changelog-entry` to match `[$version]` instead of `$version`

## [v1.0.1] - 2023-05-31

### Fixed
- Update GitHub Release workflow to use [Auto Release](https://github.com/marketplace/actions/auto-release)

## [v1.0.0] - 2023-05-31
## [v1.0.0] - 2026-04-14

Initial Release
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# npm-template
# `@aegisjsproject/hermes`

A template repo for npm packages
Simple and configurable service worker library

[![CodeQL](https://github.com/shgysk8zer0/npm-template/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/shgysk8zer0/npm-template/actions/workflows/codeql-analysis.yml)
![Node CI](https://github.com/shgysk8zer0/npm-template/workflows/Node%20CI/badge.svg)
![Lint Code Base](https://github.com/shgysk8zer0/npm-template/workflows/Lint%20Code%20Base/badge.svg)
[![CodeQL](https://github.com/AegisJSProject/hermes/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/AegisJSProject/hermes/actions/workflows/codeql-analysis.yml)
![Node CI](https://github.com/AegisJSProject/hermes/workflows/Node%20CI/badge.svg)
![Lint Code Base](https://github.com/AegisJSProject/hermes/workflows/Lint%20Code%20Base/badge.svg)

[![GitHub license](https://img.shields.io/github/license/shgysk8zer0/npm-template.svg)](https://github.com/shgysk8zer0/npm-template/blob/master/LICENSE)
[![GitHub last commit](https://img.shields.io/github/last-commit/shgysk8zer0/npm-template.svg)](https://github.com/shgysk8zer0/npm-template/commits/master)
[![GitHub release](https://img.shields.io/github/release/shgysk8zer0/npm-template?logo=github)](https://github.com/shgysk8zer0/npm-template/releases)
[![GitHub license](https://img.shields.io/github/license/AegisJSProject/hermes.svg)](https://github.com/AegisJSProject/hermes/blob/master/LICENSE)
[![GitHub last commit](https://img.shields.io/github/last-commit/AegisJSProject/hermes.svg)](https://github.com/AegisJSProject/hermes/commits/master)
[![GitHub release](https://img.shields.io/github/release/AegisJSProject/hermes?logo=github)](https://github.com/AegisJSProject/hermes/releases)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/shgysk8zer0?logo=github)](https://github.com/sponsors/shgysk8zer0)

[![npm](https://img.shields.io/npm/v/@shgysk8zer0/npm-template)](https://www.npmjs.com/package/@shgysk8zer0/npm-template)
![node-current](https://img.shields.io/node/v/@shgysk8zer0/npm-template)
![npm bundle size gzipped](https://img.shields.io/bundlephobia/minzip/@shgysk8zer0/npm-template)
[![npm](https://img.shields.io/npm/dw/@shgysk8zer0/npm-template?logo=npm)](https://www.npmjs.com/package/@shgysk8zer0/npm-template)
[![npm](https://img.shields.io/npm/v/@aegisjsproject/hermes)](https://www.npmjs.com/package/@aegisjsproject/hermes)
![node-current](https://img.shields.io/node/v/@aegisjsproject/hermes)
![npm bundle size gzipped](https://img.shields.io/bundlephobia/minzip/@aegisjsproject/hermes)
[![npm](https://img.shields.io/npm/dw/@aegisjsproject/hermes?logo=npm)](https://www.npmjs.com/package/@aegisjsproject/hermes)

[![GitHub followers](https://img.shields.io/github/followers/shgysk8zer0.svg?style=social)](https://github.com/shgysk8zer0)
![GitHub forks](https://img.shields.io/github/forks/shgysk8zer0/npm-template.svg?style=social)
![GitHub stars](https://img.shields.io/github/stars/shgysk8zer0/npm-template.svg?style=social)
[![GitHub followers](https://img.shields.io/github/followers/AegisJSProject.svg?style=social)](https://github.com/AegisJSProject)
![GitHub forks](https://img.shields.io/github/forks/AegisJSProject/hermes.svg?style=social)
![GitHub stars](https://img.shields.io/github/stars/AegisJSProject/hermes.svg?style=social)
[![Twitter Follow](https://img.shields.io/twitter/follow/shgysk8zer0.svg?style=social)](https://twitter.com/shgysk8zer0)

[![Donate using Liberapay](https://img.shields.io/liberapay/receives/shgysk8zer0.svg?logo=liberapay)](https://liberapay.com/shgysk8zer0/donate "Donate using Liberapay")
Expand Down
1 change: 0 additions & 1 deletion consts.js

This file was deleted.

4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { node } from '@shgysk8zer0/eslint-config';
import { browser } from '@shgysk8zer0/eslint-config';

export default node({ files: ['**/*.js'], ignores: ['**/*.min.js', '**/*.cjs', '**/*.mjs'] });
export default browser({ files: ['**/*.js'], ignores: ['**/*.min.js', '**/*.cjs', '**/*.mjs'] });
2 changes: 2 additions & 0 deletions hermes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { HermesWorker } from './worker.js';
export { registerServiceWorker } from './registry.js';
9 changes: 4 additions & 5 deletions http.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { imports } from '@shgysk8zer0/importmap';
import { checkCacheItem, setCacheItem } from '@aegisjsproject/http-utils/cache.js';
import { addTrustedTypePolicy, addScriptSrc, useDefaultCSP } from '@aegisjsproject/http-utils/csp.js';
import { addTrustedTypePolicy, addScriptSrc, useDefaultCSP, addWorkerSrc } from '@aegisjsproject/http-utils/csp.js';

addScriptSrc(
'https://unpkg.com/@aegisjsproject/',
'https://unpkg.com/@shgysk8zer0/',
);

addTrustedTypePolicy('aegis-sanitizer#html');
addWorkerSrc('\'self\'');

addTrustedTypePolicy('aegis-sanitizer#html', 'local#script-url');

export default {
routes: {
Expand All @@ -17,7 +18,6 @@ export default {
open: true,
requestPreprocessors: [
'@aegisjsproject/http-utils/request-id.js',
checkCacheItem,
],
responsePostprocessors: [
'@aegisjsproject/http-utils/compression.js',
Expand All @@ -28,6 +28,5 @@ export default {
response.headers.append('Link', `<${imports['@shgysk8zer0/polyfills']}>; rel="preload"; as="script"; fetchpriority="high"; crossorigin="anonymous"; referrerpolicy="no-referrer"`);
}
},
setCacheItem,
],
};
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link rel="icon" href="/favicon.svg" type="image/svg+xml" sizes="any" />
<script type="importmap" integrity="{{ INTEGRITY }}">{{ IMPORTMAP }}</script>
<script src="{{ POLYFILLS }}" referrerpolicy="no-referrer" crossorigin="anonymous" defer=""></script>
<script type="module" src="/index.js" referrerpolicy="no-referrer"></script>
</head>
<body>
<header id="header">
Expand Down
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { MESSAGE } from 'npm-template/consts.js';
console.log(import.meta);
console.info(MESSAGE);
import { registerServiceWorker } from './registry.js';

const policy = trustedTypes.createPolicy('local#script-url', {
createScriptURL(input) {
if (input.startsWith(location.origin)) {
return input;
}
}
});

registerServiceWorker(policy.createScriptURL(new URL('/sw.config.js', document.baseURI)), { type: 'module', policy });
8 changes: 0 additions & 8 deletions index.test.js

This file was deleted.

8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "npm-template",
"version": "1.1.3",
"name": "@aegisjsproject/hermes",
"version": "1.0.0",
"description": "A template repo for npm packages",
"keywords": [],
"type": "module",
"main": "./index.cjs",
"module": "./index.js",
"unpkg": "./index.min.js",
"main": "./hermes.cjs",
"module": "./hermes.js",
"unpkg": "./hermes.js",
"exports": {
".": {
"import": "./index.js",
Expand Down Expand Up @@ -52,7 +52,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/shgysk8zer0/npm-template.git"
"url": "git+https://github.com/AegisJSProject/hermes.git"
},
"author": "Chris Zuber <admin@kernvalley.us>",
"license": "MIT",
Expand All @@ -67,9 +67,9 @@
}
],
"bugs": {
"url": "https://github.com/shgysk8zer0/npm-template/issues"
"url": "https://github.com/AegisJSProject/hermes/issues"
},
"homepage": "https://github.com/shgysk8zer0/npm-template#readme",
"homepage": "https://github.com/AegisJSProject/hermes#readme",
"devDependencies": {
"@aegisjsproject/dev-server": "^1.0.6",
"@aegisjsproject/http-utils": "^1.0.4",
Expand Down
24 changes: 24 additions & 0 deletions registry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
*
* @param {string|url|TrustedScriptURL} scriptURL
* @param {object} config
* @param {string} [config.scope="/"]
* @param {"classic"|"module"} [config.type="module"]
* @param {"all"|"imports"|"none"} [config.updateViaCache]
* @param {TrustedTypePolicy} [config.policy]
* @returns {Promise<ServiceWorkerRegistration|null}
*/
export async function registerServiceWorker(scriptURL, {
scope = document.documentElement.dataset.serviceWorkerScope ?? '/',
type = 'module', // Default is module since this is an ESM library
updateViaCache = document.documentElement.dataset.serviceWorkerUpdateViaCache,
policy,
} = {}) {
if (! ('serviceWorker' in (globalThis?.navigator ?? {}))) {
return null;
} else if ('trustedTypes' in globalThis && policy instanceof globalThis.TrustedTypePolicy && ! globalThis.trustedTypes.isScriptURL(scriptURL)) {
return await navigator.serviceWorker.register(policy.createScriptURL(scriptURL), { scope, type, updateViaCache });
} else {
return await navigator.serviceWorker.register(scriptURL, { scope, type, updateViaCache });
}
}
29 changes: 13 additions & 16 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import terser from '@rollup/plugin-terser';

export default [{
input: 'index.js',
input: 'hermes.js',
external: () => true,
output: [{
file: 'index.cjs',
file: 'hermes.cjs',
format: 'cjs',
}, {
file: 'index.min.js',
format: 'iife',
plugins: [terser()],
sourcemap: true,
}, {
file: 'index.mjs',
format: 'module',
}],
}, {
input: 'consts.js',
output: {
file: 'consts.cjs',
input: 'registry.js',
output: [{
file: 'registry.cjs',
format: 'cjs',
}],
}, {
input: 'worker.js',
output: [{
file: 'worker.cjs',
format: 'cjs',
}
}],
}];
20 changes: 20 additions & 0 deletions sw.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { HermesWorker } from './worker.js';
import pkg from './package.json' with { type: 'json' };
import importmap from './node_modules/@shgysk8zer0/importmap/importmap.json' with { type: 'json' };

new HermesWorker([
{
name: pkg.name,
version: pkg.version,
strategy: 'network-first',
pattern: new URLPattern({ baseURL: location.origin, pathname: '/*' }),
prefetch: ['/', '/index.js', '/registry.js', '/favicon.svg'],
},
{
name: 'unpkg',
version: '1.0.0',
strategy: 'cache-first',
pattern: new URLPattern({ baseURL: 'http://unpkg.com', pathname: '/*' }),
prefetch: [importmap.imports['@shgysk8zer0/polyfills']],
}
]);
Loading
Loading