diff --git a/e2e/e2e.test.mts b/e2e/e2e.test.mts index bbc504e..a8f4232 100644 --- a/e2e/e2e.test.mts +++ b/e2e/e2e.test.mts @@ -23,8 +23,8 @@ import { it, } from 'vitest' -import { generateSRIHash } from '../src/core.mjs' -import { doesFileExist } from '../src/fs.mjs' +import { generateSRIHash } from '#as/core.mjs' +import { doesFileExist } from '#as/fs.mjs' const execFile = promisify(_execFile) @@ -261,7 +261,7 @@ describe('middleware', () => { afterEach(cleanServer) afterAll(cleanServer) // Just in case - const checkHtmlIsPatched = async path => { + const checkHtmlIsPatched = async (path: string) => { const response = await fetch(urlBase + path) const content = await response.text() return _checkHtmlIsPatched(content) diff --git a/package.json b/package.json index bd07a60..06bad8a 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,9 @@ "default": "./src/state.mjs" } }, + "imports": { + "#as/*": "./src/*" + }, "files": ["src/*"], "scripts": { "format": "biome format --write .", diff --git a/tests/core.test.mts b/tests/core.test.mts index dbc4d73..1280ce9 100644 --- a/tests/core.test.mts +++ b/tests/core.test.mts @@ -17,8 +17,8 @@ import { sriHashesEqual, updateDynamicPageSriHashes, updateStaticPageSriHashes, -} from '../src/core.mjs' -import { doesFileExist } from '../src/fs.mjs' +} from '#as/core.mjs' +import { doesFileExist } from '#as/fs.mjs' type SriHashes = { scripts: Record @@ -198,7 +198,7 @@ describe('generateSRIHash', () => { 'sha256-TWupyvVdPa1DyFqLnQMqRpuUWdS3nKPnz70IcS/1o3Q=', ], ['', 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='], - ] + ] as const it.each(cases)( 'generates correct hash for utf8 strings', diff --git a/tests/fs.test.mts b/tests/fs.test.mts index c3ce5d1..d68c34b 100644 --- a/tests/fs.test.mts +++ b/tests/fs.test.mts @@ -9,9 +9,9 @@ import { relative, resolve } from 'node:path' import { describe, expect, it } from 'vitest' -import type { HashesCollection } from '../src/core.mjs' -import { generateSRIHash } from '../src/core.mjs' -import { doesFileExist, scanDirectory } from '../src/fs.mjs' +import type { HashesCollection } from '#as/core.mjs' +import { generateSRIHash } from '#as/core.mjs' +import { doesFileExist, scanDirectory } from '#as/fs.mjs' const testsDir = new URL('.', import.meta.url).pathname diff --git a/tests/main.test.mts b/tests/main.test.mts index 8188c1b..2395a91 100644 --- a/tests/main.test.mts +++ b/tests/main.test.mts @@ -7,7 +7,7 @@ import type { AstroIntegration } from 'astro' import { describe, expect, it } from 'vitest' -import defaultIntegrationExport, { shield } from '../src/main.mjs' +import defaultIntegrationExport, { shield } from '#as/main.mjs' describe('sriCSP', () => { it('is exported as default', () => { @@ -17,7 +17,7 @@ describe('sriCSP', () => { const checkIntegration = ( integration: AstroIntegration, - keys = ['astro:build:done'], + keys: (keyof AstroIntegration['hooks'])[] = ['astro:build:done' as const], ) => { expect(Object.keys(integration).sort()).toEqual(['hooks', 'name']) expect(integration.name).toBe('@kindspells/astro-shield') diff --git a/tests/state.test.mts b/tests/state.test.mts index 3dca47e..816303f 100644 --- a/tests/state.test.mts +++ b/tests/state.test.mts @@ -6,7 +6,7 @@ import { describe, expect, it } from 'vitest' -import { getGlobalHashes } from '../src/state.mjs' +import { getGlobalHashes } from '#as/state.mjs' describe('getGlobalHashes', () => { it('returns a singleton', () => { diff --git a/tsconfig.json b/tsconfig.json index 7d6cfc0..5fd7cc3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,12 +33,8 @@ "skipLibCheck": true }, "include": [ - "*.mjs", - "*.d.ts", - "*.ts", - "src/core.mjs", - "src/main.mjs", - "src/state.mjs", - "src/main.d.ts" + "src/*", + "tests/**/*.mts", + "e2e/**/*.mts" ] }