Skip to content

Commit b800049

Browse files
Rich HarrisGrygrFlzr
Rich Harris
andauthored
Emit types (#442)
* build declaration files for app-utils * app-utils tsconfig: only look at source files * make kit types available where they need to be * changeset Co-authored-by: GrygrFlzr <[email protected]>
1 parent 4c6a4e7 commit b800049

File tree

18 files changed

+80
-63
lines changed

18 files changed

+80
-63
lines changed

Diff for: .changeset/modern-moose-greet.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@sveltejs/app-utils': patch
3+
'create-svelte': patch
4+
'@sveltejs/kit': patch
5+
---
6+
7+
Include type declarations

Diff for: packages/app-utils/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"version": "1.0.0-next.1",
44
"scripts": {
55
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
6+
"build": "tsc",
67
"format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore",
78
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
8-
"test": "uvu"
9+
"test": "uvu",
10+
"prepublishOnly": "npm run build"
911
},
1012
"devDependencies": {
1113
"@types/node": "^14.14.22",

Diff for: packages/app-utils/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"emitDeclarationOnly": true,
77
"noImplicitAny": true,
88
"target": "es2020",
9-
"allowSyntheticDefaultImports": true
9+
"allowSyntheticDefaultImports": true,
10+
"moduleResolution": "node"
1011
},
11-
"include": ["./files", "./http"]
12+
"include": ["./files/**.js", "./http/**.js"]
1213
}

Diff for: packages/create-svelte/template/svelte.config.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @type {import('@sveltejs/kit').Config} */
12
module.exports = {
23
kit: {
34
// By default, `npm run build` will create a standard Node app.

Diff for: packages/create-svelte/template/tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"paths": {
5+
"$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"],
6+
"$components/*": ["src/components/*"]
7+
}
8+
},
9+
"include": [
10+
"src/**/*.js",
11+
"src/**/*.ts",
12+
"src/**/*.svelte"
13+
]
14+
}

Diff for: packages/create-svelte/template/vite.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Consult https://vitejs.dev/config/ to learn about these options
22
import { resolve } from 'path';
33

4+
/** @type {import('vite').UserConfig} */
45
export default {
56
resolve: {
67
alias: {

Diff for: packages/kit/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@
6060
"./renderer": {
6161
"import": "./dist/renderer.js"
6262
}
63-
}
63+
},
64+
"types": "types.d.ts"
6465
}

Diff for: packages/kit/rollup.config.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export default [
1616
input: {
1717
'internal/start': 'src/runtime/internal/start.js',
1818
'internal/singletons': 'src/runtime/internal/singletons.js',
19-
'app/navigation': 'src/runtime/app/navigation/index.js',
20-
'app/stores': 'src/runtime/app/stores/index.js',
21-
'app/paths': 'src/runtime/app/paths/index.js'
19+
'app/navigation': 'src/runtime/app/navigation.js',
20+
'app/stores': 'src/runtime/app/stores.js',
21+
'app/paths': 'src/runtime/app/paths.js',
22+
'app/env': 'src/runtime/app/env.js'
2223
},
2324
output: {
2425
dir: 'assets/runtime',
@@ -54,7 +55,10 @@ export default [
5455
},
5556
plugins: [
5657
replace({
57-
__VERSION__: pkg.version
58+
preventAssignment: true,
59+
values: {
60+
__VERSION__: pkg.version
61+
}
5862
}),
5963
resolve({
6064
extensions: ['.mjs', '.js', '.ts']

Diff for: packages/kit/src/api/build/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ export async function build(config, { cwd }) {
3131

3232
copy_assets(build_dir);
3333

34-
// prettier-ignore
35-
writeFileSync(`${build_dir}/runtime/app/env.js`, [
36-
'export const browser = !import.meta.env.SSR;',
37-
'export const dev = false;',
38-
`export const amp = ${config.kit.amp};`
39-
].join('\n'));
34+
process.env.VITE_AMP = config.kit.amp ? 'true' : '';
4035

4136
const client_entry_file = `${build_dir}/runtime/internal/start.js`;
4237
const client_out_dir = `${cwd}/client/${config.kit.appDir}`;

Diff for: packages/kit/src/api/dev/index.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,8 @@ class Watcher extends EventEmitter {
4040

4141
async init() {
4242
rimraf(dev_dir);
43-
4443
copy_assets(dev_dir);
45-
46-
// TODO move this (and copy_assets?) into create_app
47-
// prettier-ignore
48-
writeFileSync(`${dev_dir}/runtime/app/env.js`, [
49-
'export const browser = !import.meta.env.SSR;',
50-
'export const dev = true;',
51-
`export const amp = ${this.config.kit.amp};`
52-
].join('\n'));
44+
process.env.VITE_AMP = this.config.kit.amp ? 'true' : '';
5345

5446
await this.init_filewatcher();
5547
await this.init_server();

Diff for: packages/kit/src/runtime/app/env.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const browser = !import.meta.env.SSR;
2+
export const dev = !!import.meta.env.DEV;
3+
export const amp = !!import.meta.env.VITE_AMP;

Diff for: packages/kit/src/runtime/app/navigation/index.js renamed to packages/kit/src/runtime/app/navigation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { router, renderer } from '../../internal/singletons';
2-
import { get_base_uri } from '../../internal/utils';
1+
import { router, renderer } from '../internal/singletons';
2+
import { get_base_uri } from '../internal/utils';
33

44
/**
55
* @param {string} href

Diff for: packages/kit/src/runtime/app/paths.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { base, assets } from '../internal/singletons';

Diff for: packages/kit/src/runtime/app/paths/index.js

-1
This file was deleted.

Diff for: packages/kit/src/runtime/internal/singletons.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/** @type {import('./router').Router} */
1+
/** @type {any} */
22
export let router;
33

4-
/** @type {import('./renderer').Renderer} */
4+
/** @type {any} */
55
export let renderer;
66

77
/** @type {string} */
@@ -10,10 +10,7 @@ export let base;
1010
/** @type {string} */
1111
export let assets;
1212

13-
/** @param {{
14-
* router: import('./router').Router,
15-
* renderer: import('./renderer').Renderer
16-
* }} opts */
13+
/** @param {any} opts */
1714
export function init(opts) {
1815
({ router, renderer } = opts);
1916
}

Diff for: packages/kit/src/types.d.ts

-31
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,6 @@ export type Logger = {
77
info: (msg: string) => void;
88
};
99

10-
export type Config = {
11-
compilerOptions?: any;
12-
extensions?: string[];
13-
kit?: {
14-
adapter?: string | [string, any];
15-
amp?: boolean;
16-
appDir?: string;
17-
files?: {
18-
assets?: string;
19-
routes?: string;
20-
setup?: string;
21-
template?: string;
22-
};
23-
host?: string;
24-
hostHeader?: string;
25-
paths?: {
26-
base?: string;
27-
assets?: string;
28-
};
29-
prerender?: {
30-
crawl?: boolean;
31-
enabled?: boolean;
32-
force?: boolean;
33-
pages?: string[];
34-
};
35-
startGlobal?: string;
36-
target?: string;
37-
};
38-
preprocess?: any;
39-
};
40-
4110
export type ValidatedConfig = {
4211
compilerOptions: any;
4312
extensions: string[];

Diff for: packages/kit/types.d.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export type Config = {
2+
compilerOptions?: any;
3+
extensions?: string[];
4+
kit?: {
5+
adapter?: string | [string, any];
6+
amp?: boolean;
7+
appDir?: string;
8+
files?: {
9+
assets?: string;
10+
routes?: string;
11+
setup?: string;
12+
template?: string;
13+
};
14+
host?: string;
15+
hostHeader?: string;
16+
paths?: {
17+
base?: string;
18+
assets?: string;
19+
};
20+
prerender?: {
21+
crawl?: boolean;
22+
enabled?: boolean;
23+
force?: boolean;
24+
pages?: string[];
25+
};
26+
startGlobal?: string;
27+
target?: string;
28+
};
29+
preprocess?: any;
30+
};

0 commit comments

Comments
 (0)