Skip to content

Commit c2ad988

Browse files
committed
refactor: optimise package size
Signed-off-by: Andres Correa Casablanca <andreu@kindspells.dev>
1 parent 34996d7 commit c2ad988

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+76
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
# testing artifacts
2020
**/tests/playground/*.mjs
21+
**/*-test-artifact.*
2122

2223
# moon
2324
.moon/cache

@kindspells/astro-shield/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
}
2323
},
2424
"imports": {
25-
"#as/*": "./src/*"
25+
"#as/*": {
26+
"types": "./src/*.mts",
27+
"import": "./dist/*.mjs"
28+
}
2629
},
2730
"files": ["dist/*"],
2831
"scripts": {

@kindspells/astro-shield/rollup.config.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ const outputBaseConfig = {
2323

2424
export default defineConfig([
2525
{
26-
input: 'src/main.mts',
27-
output: [{ format: 'esm', file: 'dist/main.mjs', sourcemap: true }],
26+
input: 'src/core.mts',
27+
output: [{ format: 'esm', file: 'dist/core.mjs', sourcemap: true }],
2828
...outputBaseConfig,
2929
},
3030
{
31-
input: 'src/core.mts',
32-
output: [{ format: 'esm', file: 'dist/core.mjs', sourcemap: true }],
31+
input: 'src/main.mts',
32+
output: [{ format: 'esm', file: 'dist/main.mjs', sourcemap: true }],
33+
external: ['#as/core'],
3334
...outputBaseConfig,
3435
},
3536
{
@@ -40,6 +41,7 @@ export default defineConfig([
4041
{
4142
input: 'src/main.mts',
4243
output: [{ format: 'esm', file: 'dist/main.d.mts' }],
44+
external: ['#as/core'],
4345
plugins: [dts()],
4446
},
4547
])

@kindspells/astro-shield/src/core.mts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,15 @@ import type { Plugin } from 'vite'
1515
import { doesFileExist, scanDirectory } from './fs.mts'
1616
import { patchHeaders } from './headers.mts'
1717
import type {
18+
HashesCollection,
19+
Logger,
20+
MiddlewareHashes,
21+
PerPageHashes,
1822
SecurityHeadersOptions,
1923
SRIOptions,
2024
StrictShieldOptions,
2125
} from './types.mts'
2226

23-
export type MiddlewareHashes = {
24-
scripts: Map<string, string>
25-
styles: Map<string, string>
26-
}
27-
28-
export type PerPageHashes = { scripts: Set<string>; styles: Set<string> }
29-
export type PerPageHashesCollection = Map<string, PerPageHashes>
30-
31-
export type HashesCollection = {
32-
inlineScriptHashes: Set<string>
33-
inlineStyleHashes: Set<string>
34-
extScriptHashes: Set<string>
35-
extStyleHashes: Set<string>
36-
perPageSriHashes: PerPageHashesCollection
37-
perResourceSriHashes: MiddlewareHashes
38-
}
39-
40-
export type Logger = {
41-
info(msg: string): void
42-
warn(msg: string): void
43-
error(msg: string): void
44-
}
45-
4627
export type HashesModule = {
4728
[k in keyof HashesCollection]: HashesCollection[k] extends Set<string>
4829
? string[] | undefined

@kindspells/astro-shield/e2e/e2e.test.mts renamed to @kindspells/astro-shield/src/e2e/e2e.test.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import {
2323
it,
2424
} from 'vitest'
2525

26-
import type { HashesModule } from '#as/core.mjs'
27-
import { generateSRIHash } from '#as/core.mjs'
28-
import { doesFileExist } from '#as/fs.mjs'
26+
import type { HashesModule } from '../core.mts'
27+
import { generateSRIHash } from '../core.mts'
28+
import { doesFileExist } from '../fs.mts'
2929

3030
const execFile = promisify(_execFile)
3131

@kindspells/astro-shield/e2e/fixtures/dynamic/astro.config.mjs renamed to @kindspells/astro-shield/src/e2e/fixtures/dynamic/astro.config.mjs

File renamed without changes.

@kindspells/astro-shield/e2e/fixtures/dynamic/package.json renamed to @kindspells/astro-shield/src/e2e/fixtures/dynamic/package.json

File renamed without changes.

@kindspells/astro-shield/e2e/fixtures/dynamic/src/env.d.ts renamed to @kindspells/astro-shield/src/e2e/fixtures/dynamic/src/env.d.ts

File renamed without changes.

@kindspells/astro-shield/e2e/fixtures/dynamic/src/pages/index.astro renamed to @kindspells/astro-shield/src/e2e/fixtures/dynamic/src/pages/index.astro

File renamed without changes.

@kindspells/astro-shield/e2e/fixtures/hybrid/astro.config.mjs renamed to @kindspells/astro-shield/src/e2e/fixtures/hybrid/astro.config.mjs

File renamed without changes.

0 commit comments

Comments
 (0)