Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit types #442

Merged
merged 5 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/app-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions packages/app-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"emitDeclarationOnly": true,
"noImplicitAny": true,
"target": "es2020",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"moduleResolution": "node"
},
"include": ["./files", "./http"]
"include": ["./files/**.js", "./http/**.js"]
}
1 change: 1 addition & 0 deletions packages/create-svelte/template/svelte.config.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@sveltejs/kit').Config} */
module.exports = {
kit: {
// By default, `npm run build` will create a standard Node app.
Expand Down
14 changes: 14 additions & 0 deletions packages/create-svelte/template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions packages/create-svelte/template/vite.config.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"./renderer": {
"import": "./dist/renderer.js"
}
}
},
"types": "types.d.ts"
}
12 changes: 8 additions & 4 deletions packages/kit/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -54,7 +55,10 @@ export default [
},
plugins: [
replace({
__VERSION__: pkg.version
preventAssignment: true,
values: {
__VERSION__: pkg.version
}
}),
resolve({
extensions: ['.mjs', '.js', '.ts']
Expand Down
7 changes: 1 addition & 6 deletions packages/kit/src/api/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
10 changes: 1 addition & 9 deletions packages/kit/src/api/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions packages/kit/src/runtime/app/env.js
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/runtime/app/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { base, assets } from '../internal/singletons';
1 change: 0 additions & 1 deletion packages/kit/src/runtime/app/paths/index.js

This file was deleted.

9 changes: 3 additions & 6 deletions packages/kit/src/runtime/internal/singletons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @type {import('./router').Router} */
/** @type {any} */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this from Router?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the comment still exists once these files have been bundled, but no longer points at anything. If TypeScript were to check that file, because of whatever configuration, it would get confused. Changing it to any doesn't actually impede us in any way, and doesn't affect users because Router and Renderer are a hidden implementation detail

export let router;

/** @type {import('./renderer').Renderer} */
/** @type {any} */
export let renderer;

/** @type {string} */
Expand All @@ -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);
}
Expand Down
31 changes: 0 additions & 31 deletions packages/kit/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
30 changes: 30 additions & 0 deletions packages/kit/types.d.ts
Original file line number Diff line number Diff line change
@@ -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;
};