Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: monorepo + tsc + examples + deps #6

Merged
merged 32 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
762d5c6
chore: lint
maxholman Jun 11, 2024
4ca5e54
chore: remove duplicate base64 methods
maxholman Jun 11, 2024
867f9f4
chore: improve tsc setup
maxholman Jun 11, 2024
06b7458
chore: moved examples
maxholman Jun 11, 2024
87f91b7
chore(deps): update dev deps
maxholman Jun 11, 2024
ef642ea
core: target nodejs 20 + pnpm 9.2
maxholman Jun 11, 2024
189f41d
chore: update actions workflow versions
maxholman Jun 11, 2024
68ca9f5
chore(deps): updated dev deps
maxholman Jun 11, 2024
3343bbe
chore: nodejs 20
maxholman Jun 11, 2024
859d6b5
chore: initial commit
maxholman Jun 11, 2024
39af255
chore: use vitest
maxholman Jun 11, 2024
258ff67
chore: latest block65/custom-error
maxholman Jun 11, 2024
5a0c2f4
chore: update export paths
maxholman Jun 11, 2024
30c894b
chore: lockfile regenerated
maxholman Jun 11, 2024
5da2294
chore: remove redundant invariants
maxholman Jun 11, 2024
24f45d2
chore: lint
maxholman Jun 11, 2024
b16369a
chore: renamed fixtures
maxholman Jun 11, 2024
6db55e6
chore: update tsc
maxholman Jun 11, 2024
915d6a5
chore: improve docs
maxholman Jun 11, 2024
0746ec1
refactor: monorepo + examples + tests + my oh my
maxholman Jun 11, 2024
c1ece32
chore: simplify implementation
maxholman Jun 11, 2024
3d21c2d
chore: run a wrangler deploy dry run (fka build) as a test
maxholman Jun 11, 2024
80ac8d9
Merge branch 'master' into lint-tsc-etal
maxholman Jun 11, 2024
fef3034
chore: only publish the single package
maxholman Jun 11, 2024
39a3bd8
chore: pnpm 9.3
maxholman Jun 11, 2024
9e90cf7
chore: redundant files
maxholman Jun 11, 2024
75bfc93
chore: fix deps for node modules
maxholman Jun 11, 2024
93344f8
chore: ensure node version file is respected
maxholman Jun 11, 2024
38fc0e4
chore: test 3 versions of node, just in case
maxholman Jun 11, 2024
64fc72e
chore: lint
maxholman Jun 11, 2024
77a083b
chore: remove useless type extending any
maxholman Jun 11, 2024
f7e5556
chore: change default goal to build
maxholman Jun 11, 2024
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
43 changes: 41 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
module.exports = {
root: true,
extends: ['@block65/eslint-config'],
extends: [
'@block65/eslint-config',
'@block65/eslint-config/typescript',
'@block65/eslint-config/react',
],
parserOptions: {
project: ['./tsconfig-eslint.json'],
project: [
'./tsconfig.json',

'./examples/browser/tsconfig.json',
'./examples/browser/tsconfig-sw.json',
'./examples/browser/tsconfig.node.json',
'./examples/nodejs/tsconfig.json',
'./examples/cloudflare-workers/tsconfig.json',

'./packages/web-push/tsconfig.json',
'./packages/web-push/test/tsconfig.json',
],
},
rules: {
'no-console': 'off',
},
overrides: [
{
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
rules: {
'no-restricted-syntax': 'off',
'@typescript-eslint/no-import-type-side-effects': 'error',
},
},

{
files: ['**/*.test.ts', '**/*.test.tsx', '**/test/*.ts'],
rules: {
'@typescript-eslint/consistent-type-imports': 'off',
'import/no-extraneous-dependencies': 'off',
},
},

{
files: ['*.config.js', '*.config.ts'],
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
],
};
20 changes: 11 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
node-version-file: '.node-version'

- run: make
- run: pnpm publish --access=public --no-git-checks

- run: pnpm publish -r --filter @block65/webcrypto-web-push --access=public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
20 changes: 13 additions & 7 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ on:

jobs:
test:
strategy:
matrix:
node-version: ['18', '20', '22']

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: 16
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
node-version: ${{ matrix.node-version }}

- run: make test
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
node_modules
dist
coverage

.wrangler

*.tsbuildinfo

sqlite.db
**/migrations/meta/
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
20
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm-lock.yaml
45 changes: 22 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
.DEFAULT_GOAL := build

SRCS = $(wildcard lib/**)
.PHONY: build
build: node_modules
pnpm exec tsc -b

all: dist
.PHONY: dev
dev: node_modules
pnpm exec tsc -b -w

.PHONY: clean
clean:
pnpm tsc -b --clean
clean: node_modules
pnpm exec tsc -b --clean

.PHONY: test
test: node_modules
pnpm exec vitest
$(MAKE) smoketest
.PHONY: distclean
distclean: clean
rm -rf node_modules

.PHONY: lint
lint: node_modules
pnpm exec eslint .
pnpm exec prettier --check .

node_modules: package.json
pnpm install

dist: node_modules tsconfig-lib.json $(SRCS)
pnpm exec tsc -b tsconfig-lib.json

.PHONY: dist-watch
dist-watch:
pnpm exec tsc -w --preserveWatchOutput
.PHONY: test
test: node_modules
pnpm run -r test

.PHONY: pretty
pretty: node_modules
pnpm exec eslint --fix .
pnpm exec eslint --fix . || true
pnpm exec prettier --write .

.PHONY: dev-server
dev-server: node_modules
pnpm exec wrangler dev src/worker.ts

.PHONY: smoketest
smoketest: dist
pnpm exec node -e "import('@block65/webcrypto-web-push').then(() => console.log('smoketest ok')).catch(console.error)"
pnpx sort-package-json package.json packages/*/package.json examples/*/package.json
3 changes: 3 additions & 0 deletions examples/browser/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# WARN: these keys are not secure, generate your own!
VITE_SERVER_VAPID_PUBLIC_KEY=BKKXE3jJV5UJ6c8HVPam6DvMPGZK26r-M7ojsO2T_KdjdeMT2d7oQpaO-VI3o3wn33mQ8JlHta3OSJ5f67Ac5ZY
VITE_SERVER_URL=http://localhost:3000
25 changes: 25 additions & 0 deletions examples/browser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
dev-dist
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
18 changes: 18 additions & 0 deletions examples/browser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="dark" />
</head>

<style>
@import 'the-new-css-reset';
@import '@block65/react-design-system/css';
</style>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "browser-example",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite dev"
},
"dependencies": {
"@block65/react-design-system": "^0.32.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"the-new-css-reset": "^1.11.2",
"vite-plugin-pwa": "^0.20.0",
"workbox-window": "^7.1.0"
},
"devDependencies": {
"@block65/webcrypto-web-push": "workspace:*",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"typescript": "^5.4.5",
"vite": "^5.2.13"
}
}
20 changes: 20 additions & 0 deletions examples/browser/public/push-sw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference lib="webworker" />

declare const selfie: ServiceWorkerGlobalScope;

selfie.addEventListener('push', async (event) => {
// Keep the service worker alive until the notification is shown.
event.waitUntil(
selfie.registration.pushManager.getSubscription().then((subscription) => {
if (!subscription) {
throw new Error('No subscription found.');
}

selfie.registration.showNotification('Web Push', {
// event.data?.json()
body: event.data?.text() || '<empty>',
requireInteraction: false, // can dismiss itself automatically
});
}),
);
});
Loading