diff --git a/.changeset/modern-moose-greet.md b/.changeset/modern-moose-greet.md new file mode 100644 index 000000000000..f75cb1f98b5f --- /dev/null +++ b/.changeset/modern-moose-greet.md @@ -0,0 +1,7 @@ +--- +'@sveltejs/app-utils': patch +'create-svelte': patch +'@sveltejs/kit': patch +--- + +Include type declarations diff --git a/packages/app-utils/package.json b/packages/app-utils/package.json index 5a69cc5f2a01..955e38187fab 100644 --- a/packages/app-utils/package.json +++ b/packages/app-utils/package.json @@ -3,9 +3,11 @@ "version": "1.0.0-next.1", "scripts": { "lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format", + "build": "tsc", "format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore", "check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore", - "test": "uvu" + "test": "uvu", + "prepublishOnly": "npm run build" }, "devDependencies": { "@types/node": "^14.14.22", diff --git a/packages/app-utils/tsconfig.json b/packages/app-utils/tsconfig.json index 0c8d436dc286..967e49b831fb 100644 --- a/packages/app-utils/tsconfig.json +++ b/packages/app-utils/tsconfig.json @@ -6,7 +6,8 @@ "emitDeclarationOnly": true, "noImplicitAny": true, "target": "es2020", - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "moduleResolution": "node" }, - "include": ["./files", "./http"] + "include": ["./files/**.js", "./http/**.js"] } diff --git a/packages/create-svelte/template/svelte.config.cjs b/packages/create-svelte/template/svelte.config.cjs index d41b7d971683..ce8d98bcb26c 100644 --- a/packages/create-svelte/template/svelte.config.cjs +++ b/packages/create-svelte/template/svelte.config.cjs @@ -1,3 +1,4 @@ +/** @type {import('@sveltejs/kit').Config} */ module.exports = { kit: { // By default, `npm run build` will create a standard Node app. diff --git a/packages/create-svelte/template/tsconfig.json b/packages/create-svelte/template/tsconfig.json new file mode 100644 index 000000000000..37589f01d9d6 --- /dev/null +++ b/packages/create-svelte/template/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "allowJs": true, + "paths": { + "$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"], + "$components/*": ["src/components/*"] + } + }, + "include": [ + "src/**/*.js", + "src/**/*.ts", + "src/**/*.svelte" + ] +} \ No newline at end of file diff --git a/packages/create-svelte/template/vite.config.js b/packages/create-svelte/template/vite.config.js index ad8f48a6d871..c24a94e3740d 100644 --- a/packages/create-svelte/template/vite.config.js +++ b/packages/create-svelte/template/vite.config.js @@ -1,6 +1,7 @@ // Consult https://vitejs.dev/config/ to learn about these options import { resolve } from 'path'; +/** @type {import('vite').UserConfig} */ export default { resolve: { alias: { diff --git a/packages/kit/package.json b/packages/kit/package.json index d3ed7fcc9354..43bc1555cb67 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -60,5 +60,6 @@ "./renderer": { "import": "./dist/renderer.js" } - } + }, + "types": "types.d.ts" } diff --git a/packages/kit/rollup.config.js b/packages/kit/rollup.config.js index df74eb61bc0b..cebe2eccef8a 100644 --- a/packages/kit/rollup.config.js +++ b/packages/kit/rollup.config.js @@ -16,9 +16,10 @@ export default [ input: { 'internal/start': 'src/runtime/internal/start.js', 'internal/singletons': 'src/runtime/internal/singletons.js', - 'app/navigation': 'src/runtime/app/navigation/index.js', - 'app/stores': 'src/runtime/app/stores/index.js', - 'app/paths': 'src/runtime/app/paths/index.js' + 'app/navigation': 'src/runtime/app/navigation.js', + 'app/stores': 'src/runtime/app/stores.js', + 'app/paths': 'src/runtime/app/paths.js', + 'app/env': 'src/runtime/app/env.js' }, output: { dir: 'assets/runtime', @@ -54,7 +55,10 @@ export default [ }, plugins: [ replace({ - __VERSION__: pkg.version + preventAssignment: true, + values: { + __VERSION__: pkg.version + } }), resolve({ extensions: ['.mjs', '.js', '.ts'] diff --git a/packages/kit/src/api/build/index.js b/packages/kit/src/api/build/index.js index 01ce9aa06dc9..917e7f20ae3d 100644 --- a/packages/kit/src/api/build/index.js +++ b/packages/kit/src/api/build/index.js @@ -31,12 +31,7 @@ export async function build(config, { cwd }) { copy_assets(build_dir); - // prettier-ignore - writeFileSync(`${build_dir}/runtime/app/env.js`, [ - 'export const browser = !import.meta.env.SSR;', - 'export const dev = false;', - `export const amp = ${config.kit.amp};` - ].join('\n')); + process.env.VITE_AMP = config.kit.amp ? 'true' : ''; const client_entry_file = `${build_dir}/runtime/internal/start.js`; const client_out_dir = `${cwd}/client/${config.kit.appDir}`; diff --git a/packages/kit/src/api/dev/index.js b/packages/kit/src/api/dev/index.js index 43c6bec79c13..448a0b8a1091 100644 --- a/packages/kit/src/api/dev/index.js +++ b/packages/kit/src/api/dev/index.js @@ -40,16 +40,8 @@ class Watcher extends EventEmitter { async init() { rimraf(dev_dir); - copy_assets(dev_dir); - - // TODO move this (and copy_assets?) into create_app - // prettier-ignore - writeFileSync(`${dev_dir}/runtime/app/env.js`, [ - 'export const browser = !import.meta.env.SSR;', - 'export const dev = true;', - `export const amp = ${this.config.kit.amp};` - ].join('\n')); + process.env.VITE_AMP = this.config.kit.amp ? 'true' : ''; await this.init_filewatcher(); await this.init_server(); diff --git a/packages/kit/src/runtime/app/env.js b/packages/kit/src/runtime/app/env.js new file mode 100644 index 000000000000..43d4e32d97a2 --- /dev/null +++ b/packages/kit/src/runtime/app/env.js @@ -0,0 +1,3 @@ +export const browser = !import.meta.env.SSR; +export const dev = !!import.meta.env.DEV; +export const amp = !!import.meta.env.VITE_AMP; diff --git a/packages/kit/src/runtime/app/navigation/index.js b/packages/kit/src/runtime/app/navigation.js similarity index 85% rename from packages/kit/src/runtime/app/navigation/index.js rename to packages/kit/src/runtime/app/navigation.js index b3d3aa686083..807c6994fc9c 100644 --- a/packages/kit/src/runtime/app/navigation/index.js +++ b/packages/kit/src/runtime/app/navigation.js @@ -1,5 +1,5 @@ -import { router, renderer } from '../../internal/singletons'; -import { get_base_uri } from '../../internal/utils'; +import { router, renderer } from '../internal/singletons'; +import { get_base_uri } from '../internal/utils'; /** * @param {string} href diff --git a/packages/kit/src/runtime/app/paths.js b/packages/kit/src/runtime/app/paths.js new file mode 100644 index 000000000000..22a1e250e863 --- /dev/null +++ b/packages/kit/src/runtime/app/paths.js @@ -0,0 +1 @@ +export { base, assets } from '../internal/singletons'; diff --git a/packages/kit/src/runtime/app/paths/index.js b/packages/kit/src/runtime/app/paths/index.js deleted file mode 100644 index 29cde4f28c78..000000000000 --- a/packages/kit/src/runtime/app/paths/index.js +++ /dev/null @@ -1 +0,0 @@ -export { base, assets } from '../../internal/singletons'; diff --git a/packages/kit/src/runtime/app/stores/index.js b/packages/kit/src/runtime/app/stores.js similarity index 100% rename from packages/kit/src/runtime/app/stores/index.js rename to packages/kit/src/runtime/app/stores.js diff --git a/packages/kit/src/runtime/internal/singletons.js b/packages/kit/src/runtime/internal/singletons.js index 6e559b828ab1..19986a6c8535 100644 --- a/packages/kit/src/runtime/internal/singletons.js +++ b/packages/kit/src/runtime/internal/singletons.js @@ -1,7 +1,7 @@ -/** @type {import('./router').Router} */ +/** @type {any} */ export let router; -/** @type {import('./renderer').Renderer} */ +/** @type {any} */ export let renderer; /** @type {string} */ @@ -10,10 +10,7 @@ export let base; /** @type {string} */ export let assets; -/** @param {{ - * router: import('./router').Router, - * renderer: import('./renderer').Renderer - * }} opts */ +/** @param {any} opts */ export function init(opts) { ({ router, renderer } = opts); } diff --git a/packages/kit/src/types.d.ts b/packages/kit/src/types.d.ts index 4e2d66fb93db..b4623134d19e 100644 --- a/packages/kit/src/types.d.ts +++ b/packages/kit/src/types.d.ts @@ -7,37 +7,6 @@ export type Logger = { info: (msg: string) => void; }; -export type Config = { - compilerOptions?: any; - extensions?: string[]; - kit?: { - adapter?: string | [string, any]; - amp?: boolean; - appDir?: string; - files?: { - assets?: string; - routes?: string; - setup?: string; - template?: string; - }; - host?: string; - hostHeader?: string; - paths?: { - base?: string; - assets?: string; - }; - prerender?: { - crawl?: boolean; - enabled?: boolean; - force?: boolean; - pages?: string[]; - }; - startGlobal?: string; - target?: string; - }; - preprocess?: any; -}; - export type ValidatedConfig = { compilerOptions: any; extensions: string[]; diff --git a/packages/kit/types.d.ts b/packages/kit/types.d.ts new file mode 100644 index 000000000000..7932cd42d817 --- /dev/null +++ b/packages/kit/types.d.ts @@ -0,0 +1,30 @@ +export type Config = { + compilerOptions?: any; + extensions?: string[]; + kit?: { + adapter?: string | [string, any]; + amp?: boolean; + appDir?: string; + files?: { + assets?: string; + routes?: string; + setup?: string; + template?: string; + }; + host?: string; + hostHeader?: string; + paths?: { + base?: string; + assets?: string; + }; + prerender?: { + crawl?: boolean; + enabled?: boolean; + force?: boolean; + pages?: string[]; + }; + startGlobal?: string; + target?: string; + }; + preprocess?: any; +};