Skip to content

Commit

Permalink
refactor: switch to typescript
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Correa Casablanca <[email protected]>
  • Loading branch information
castarco committed Sep 11, 2024
1 parent 2885e51 commit 3204c8c
Show file tree
Hide file tree
Showing 20 changed files with 657 additions and 716 deletions.
17 changes: 17 additions & 0 deletions @kindspells/astro-shield/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ type: 'library'
platform: 'node'

tasks:
build:
platform: 'system'
script: 'rm -rf ./dist && pnpm rollup --config ./rollup.config.mjs'
inputs:
- 'rollup.config.mjs'
- 'package.json'
- 'src/**/*'
outputs:
- 'dist/**/*'
lint:
deps:
- '~:lint.biome'
Expand All @@ -24,6 +33,8 @@ tasks:
inputs:
- 'package.json'
- 'src/**/*'
deps:
- '~:build'
lint.tsc:
command: 'tsc -p . --noEmit'
inputs:
Expand All @@ -40,6 +51,8 @@ tasks:
- 'e2e/**/*'
options:
runInCI: false
deps:
- '~:build'
test.unit:
command: 'vitest -c vitest.config.unit.mts run'
inputs:
Expand All @@ -48,6 +61,8 @@ tasks:
- 'tests/**/*'
options:
runInCI: false
deps:
- '~:build'
test.unit.cov:
command: 'vitest -c vitest.config.unit.mts run --coverage'
inputs:
Expand All @@ -56,3 +71,5 @@ tasks:
- 'tests/**/*'
outputs:
- 'coverage-unit/**/*'
deps:
- '~:build'
32 changes: 19 additions & 13 deletions @kindspells/astro-shield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@
"description": "Astro integration to enhance your website's security with SubResource Integrity hashes, Content-Security-Policy headers, and other techniques.",
"private": false,
"type": "module",
"main": "src/main.mjs",
"types": "src/main.d.ts",
"main": "dist/main.mjs",
"types": "dist/main.d.mts",
"exports": {
".": {
"types": "./src/main.d.ts",
"import": "./src/main.mjs",
"default": "./src/main.mjs"
"types": "./dist/main.d.mts",
"import": "./dist/main.mjs",
"default": "./dist/main.mjs"
},
"./core": {
"import": "./src/core.mjs",
"default": "./src/core.mjs"
"import": "./dist/core.mjs",
"default": "./dist/core.mjs"
},
"./state": {
"import": "./src/state.mjs",
"default": "./src/state.mjs"
"import": "./dist/state.mjs",
"default": "./dist/state.mjs"
}
},
"imports": {
"#as/*": "./src/*"
},
"files": ["src/*"],
"files": ["dist/*"],
"scripts": {
"build": "moon run build",
"format": "biome format --write .",
"lint": "moon run lint",
"lint:biome": "moon run lint.biome",
Expand Down Expand Up @@ -59,10 +60,15 @@
"astro": "^4.0.0"
},
"devDependencies": {
"@types/node": "^20.16.5",
"@types/node": "^22.5.4",
"astro": "^4.15.4",
"get-tsconfig": "^4.8.0",
"rollup": "^4.21.2",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-esbuild": "^6.1.1",
"typescript": "^5.6.2",
"vite": "^5.4.4"
"vite": "^5.4.4",
"vitest": "^2.0.5"
},
"repository": {
"type": "git",
Expand All @@ -80,7 +86,7 @@
"url": "https://ko-fi.com/coderspirit"
}
],
"packageManager": "pnpm@9.0.6",
"packageManager": "pnpm@9.10.0",
"engines": {
"node": ">= 18.0.0"
},
Expand Down
45 changes: 45 additions & 0 deletions @kindspells/astro-shield/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

import { getTsconfig } from 'get-tsconfig'
import { defineConfig } from 'rollup'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'

const projectDir = dirname(fileURLToPath(import.meta.url))
const tsconfig = getTsconfig(projectDir)
const target = tsconfig?.config.compilerOptions?.target ?? 'es2020'

const outputBaseConfig = {
plugins: [
esbuild({
target: ['node18', 'node20', 'node22', target],
loaders: { '.mts': 'ts' },
minify: true,
}),
],
external: ['node:crypto', 'node:fs/promises', 'node:path', 'node:url'],
}

export default defineConfig([
{
input: 'src/main.mts',
output: [{ format: 'esm', file: 'dist/main.mjs', sourcemap: true }],
...outputBaseConfig,
},
{
input: 'src/core.mts',
output: [{ format: 'esm', file: 'dist/core.mjs', sourcemap: true }],
...outputBaseConfig,
},
{
input: 'src/state.mts',
output: [{ format: 'esm', file: 'dist/state.mjs', sourcemap: true }],
...outputBaseConfig,
},
{
input: 'src/main.mts',
output: [{ format: 'esm', file: 'dist/main.d.mts' }],
plugins: [dts()],
},
])
28 changes: 0 additions & 28 deletions @kindspells/astro-shield/src/core.d.ts

This file was deleted.

Loading

0 comments on commit 3204c8c

Please sign in to comment.