From b7c294342a495e00e0cdf99e5634db988a7134ab Mon Sep 17 00:00:00 2001 From: Pascal Perrenoud Date: Thu, 22 Jan 2026 10:30:12 +0100 Subject: [PATCH] Use new template --- .gitignore | 6 +++--- .npmignore | 7 +++++++ .prettierignore | 3 +++ .prettierrc | 5 ++++- .woodpecker/test.yml | 43 +++++++++++++++++++++++++++++++++++------- bunfig.toml | 2 -- eslint.config.ts | 15 +++++++++++++++ index.ts | 28 --------------------------- package.json | 36 ++++++++++++++++++++--------------- src/index.ts | 28 +++++++++++++++++++++++++++ test/signature.test.ts | 2 +- tsconfig.json | 35 ++++++++-------------------------- 12 files changed, 126 insertions(+), 84 deletions(-) create mode 100644 .npmignore create mode 100644 .prettierignore delete mode 100644 bunfig.toml create mode 100644 eslint.config.ts delete mode 100644 index.ts create mode 100644 src/index.ts diff --git a/.gitignore b/.gitignore index 0ede773..7f82a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -.idea/ -bun.lockb package-lock.json -node_modules/ ._* +.idea/ .DS_Store +node_modules/ +dist/ diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..aa0e10b --- /dev/null +++ b/.npmignore @@ -0,0 +1,7 @@ +.woodpecker/ +test/ +.gitignore +README.md +.prettierignore +.prettierrc +eslint.config.ts diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..84af45f --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +.woodpecker +node_modules +dist diff --git a/.prettierrc b/.prettierrc index e077495..9e19544 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,8 +1,11 @@ { "arrowParens": "avoid", + "tabWidth": 2, + "useTabs": false, "bracketSpacing": false, "printWidth": 120, "semi": false, "singleQuote": true, + "jsxSingleQuote": true, "trailingComma": "none" -} \ No newline at end of file +} diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 8eb12b4..3288aaa 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -1,9 +1,6 @@ when: - path: - include: [ - 'src/**/*.ts', - 'index.ts' - ] + include: ['**/*.{js,jsx,ts,tsx}'] steps: install: @@ -13,10 +10,42 @@ steps: commands: - npm install - test: - image: oven/bun:alpine + typecheck: + image: node when: - event: [pull_request, push, manual] depends_on: install commands: - - bun test + - npm run typecheck + + lint: + image: node + when: + - event: [pull_request, push, manual] + depends_on: install + commands: + - npm run lint + + fmt: + image: node + when: + - event: [pull_request, push, manual] + depends_on: install + commands: + - npm run check:fmt + + test: + image: node + when: + - event: [pull_request, push, manual] + depends_on: install + commands: + - npm run test + + check: + image: node + when: + - event: [pull_request, push, manual] + depends_on: install + commands: + - npm run check diff --git a/bunfig.toml b/bunfig.toml deleted file mode 100644 index 0f705fb..0000000 --- a/bunfig.toml +++ /dev/null @@ -1,2 +0,0 @@ -[test] -preload = "./test/init.ts" diff --git a/eslint.config.ts b/eslint.config.ts new file mode 100644 index 0000000..754d790 --- /dev/null +++ b/eslint.config.ts @@ -0,0 +1,15 @@ +import js from '@eslint/js' +import globals from 'globals' +import tseslint from 'typescript-eslint' +import {defineConfig, globalIgnores} from 'eslint/config' + +export default defineConfig([ + tseslint.configs.recommended, + { + files: ['**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + plugins: {js}, + extends: ['js/recommended'], + languageOptions: {globals: {...globals.browser, ...globals.node}} + }, + globalIgnores(['dist']) +]) diff --git a/index.ts b/index.ts deleted file mode 100644 index 7f00980..0000000 --- a/index.ts +++ /dev/null @@ -1,28 +0,0 @@ -import SecretBox from './src/secret-box' -import SecretWrap from './src/secret-wrap' -import PrivateBox from './src/private-box' -import PrivateWrap from './src/private-wrap' -import PwdBox from './src/pwd-box' -import PwdWrap from './src/pwd-wrap' -import {hash, verify} from './src/pwd' - -export enum Strength { - weak, - moderate, - strong -} - -export const set_strength = (new_strength: Strength) => { - if (!(new_strength in Strength)) throw 'Invalid strength !' - strength = new_strength -} -let strength = Strength.moderate -export let STRENGTH: () => Strength = () => strength - -export * as kdf from './src/kdf' -export * as misc from './src/misc' -export * as signature from './src/signature' -export * as JWT from './src/jwt' -export const pwd = {hash, verify} - -export {SecretBox, SecretWrap, PrivateBox, PrivateWrap, PwdBox, PwdWrap} diff --git a/package.json b/package.json index c4d688f..7237dad 100644 --- a/package.json +++ b/package.json @@ -3,28 +3,34 @@ "description": "Various crypto utils for encryption, signature, ...", "version": "1.0.0", "author": "Pascal Perrenoud ", - "scripts": { + "check": "clear && npm run typecheck && npm run lint && npm run check:fmt && npm run test && clear && echo 'OK'", + "check:fmt": "npx prettier -c src/*.ts", + "fmt": "prettier --write src/*.ts", + "lint": "eslint src/*.ts", "test": "bun test", - "fmt": "prettier --config .prettierrc '**/*.ts' --write" + "typecheck": "tsc --noEmit" }, - "dependencies": { "jose": "^5.3.0", - "log": "git+https://git.pband.ch/typescript/log.git", - "misc": "git+https://git.pband.ch/typescript/misc.git" + "misc": "git+ssh://git@git.pband.ch:typescript/misc.git#main", + "log": "git+ssh://git@git.pband.ch:typescript/log.git#main" }, "devDependencies": { - "@types/bun": "^1.1.2", - "bun": "^1.1.27", - "logger-console": "git+https://git.pband.ch/typescript/logger-console.git", - "prettier": "^3.3.3" + "@eslint/js": "^9.35.0", + "@types/bun": "^1.2.21", + "bun": "^1.2.21", + "eslint": "^9.35.0", + "globals": "^16.4.0", + "jiti": "^2.5.1", + "logger-console": "git+ssh://git@git.pband.ch:typescript/logger-console.git#main", + "prettier": "^3.6.2", + "typescript": "^5.9.2", + "typescript-eslint": "^8.43.0" }, - - "module": "index.ts", "type": "module", - "files": [ - "index.ts", - "src" - ] + "main": "./src/index.ts", + "exports": { + ".": "./src/index.ts" + } } diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..da1fa3f --- /dev/null +++ b/src/index.ts @@ -0,0 +1,28 @@ +import SecretBox from './secret-box' +import SecretWrap from './secret-wrap' +import PrivateBox from './private-box' +import PrivateWrap from './private-wrap' +import PwdBox from './pwd-box' +import PwdWrap from './pwd-wrap' +import {hash, verify} from './pwd' + +export enum Strength { + weak, + moderate, + strong +} + +export const set_strength = (new_strength: Strength) => { + if (!(new_strength in Strength)) throw 'Invalid strength !' + strength = new_strength +} +let strength = Strength.moderate +export const STRENGTH: () => Strength = () => strength + +export * as kdf from './kdf' +export * as misc from './misc' +export * as signature from './signature' +export * as JWT from './jwt' +export const pwd = {hash, verify} + +export {SecretBox, SecretWrap, PrivateBox, PrivateWrap, PwdBox, PwdWrap} diff --git a/test/signature.test.ts b/test/signature.test.ts index 7bb480e..912fb03 100644 --- a/test/signature.test.ts +++ b/test/signature.test.ts @@ -1,6 +1,6 @@ import {test, expect} from 'bun:test' -import {signature} from '../index' +import {signature} from '..' import {gen, sign, verify} from '../src/signature' test('base case', async () => { diff --git a/tsconfig.json b/tsconfig.json index dd41062..5dc8e0f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,33 +1,14 @@ { "compilerOptions": { - // Enable latest features - "lib": ["ESNext","dom"], - "target": "ESNext", + "target": "ES2020", "module": "ESNext", - "moduleDetection": "force", - "allowJs": true, - "checkJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices + "moduleResolution": "node", + "declaration": true, + "outDir": "dist", + "rootDir": "./src", "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "forceConsistentCasingInFileNames": true, - "noPropertyAccessFromIndexSignature": false + "esModuleInterop": true, + "skipLibCheck": true }, - - "include": [ - "index.ts", - "src/**/*.ts" - ] + "include": ["src"] }