Skip to content

Commit

Permalink
refactor: avoid relative backtrack imports
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Correa Casablanca <[email protected]>
  • Loading branch information
castarco committed Mar 18, 2024
1 parent 062c155 commit 8b4b13e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
6 changes: 3 additions & 3 deletions e2e/e2e.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"default": "./src/state.mjs"
}
},
"imports": {
"#as/*": "./src/*"
},
"files": ["src/*"],
"scripts": {
"format": "biome format --write .",
Expand Down
6 changes: 3 additions & 3 deletions tests/core.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('generateSRIHash', () => {
'sha256-TWupyvVdPa1DyFqLnQMqRpuUWdS3nKPnz70IcS/1o3Q=',
],
['', 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='],
]
] as const

it.each(cases)(
'generates correct hash for utf8 strings',
Expand Down
6 changes: 3 additions & 3 deletions tests/fs.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/main.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/state.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
10 changes: 3 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}

0 comments on commit 8b4b13e

Please sign in to comment.