Skip to content

Commit

Permalink
types: organize into folder (#1024)
Browse files Browse the repository at this point in the history
* move and rename types into one folder

* use glob paths to types folder

* update JSDoc type import paths

* update child types import paths

* remove internal types importing from public types

tried to break them up into each categories

also added helper.d.ts to try avoid circular
dependencies between each files imports

* adjust type imports and update to be more explicit

* remove ability to import public types directly

* fix: missed some and pass lint

* what, how

* oh, nice

* change server to endpoint

* change client to page
  • Loading branch information
ignatiusmb authored Apr 16, 2021
1 parent 9d8dd08 commit 1d76d66
Show file tree
Hide file tree
Showing 36 changed files with 287 additions and 294 deletions.
8 changes: 3 additions & 5 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
"files": [
"assets",
"dist",
"types.d.ts",
"types.ambient-modules.d.ts",
"types.internal.d.ts",
"types",
"svelte-kit.js"
],
"scripts": {
Expand Down Expand Up @@ -72,9 +70,9 @@
"import": "./dist/filesystem.js",
"require": "./dist/filesystem.cjs"
},
"./types.d.ts": "./types.d.ts"
"./types": "./types/index.d.ts"
},
"types": "types.d.ts",
"types": "types/index.d.ts",
"engines": {
"node": ">= 12.17.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/adapt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { logger } from '../utils.js';
import { get_utils } from './utils.js';

/**
* @param {import('types.internal').ValidatedConfig} config
* @param {import('types.internal').BuildData} build_data
* @param {import('types/config').ValidatedConfig} config
* @param {import('types/internal').BuildData} build_data
* @param {{ cwd?: string, verbose: boolean }} opts
*/
export async function adapt(config, build_data, { cwd = process.cwd(), verbose }) {
Expand Down
10 changes: 5 additions & 5 deletions packages/kit/src/core/adapt/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const REDIRECT = 3;
/** @param {{
* cwd: string;
* out: string;
* log: import('../../../types.internal').Logger;
* config: import('../../../types.internal').ValidatedConfig;
* build_data: import('../../../types.internal').BuildData;
* log: import('types/internal').Logger;
* config: import('types/config').ValidatedConfig;
* build_data: import('types/internal').BuildData;
* force: boolean; // disregard `export const prerender = true`
* }} opts */
export async function prerender({ cwd, out, log, config, build_data, force }) {
Expand All @@ -61,7 +61,7 @@ export async function prerender({ cwd, out, log, config, build_data, force }) {

const server_root = resolve_path(dir);

/** @type {import('../../../types.internal').App} */
/** @type {import('types/internal').App} */
const app = await import(pathToFileURL(`${server_root}/server/app.js`).href);

app.init({
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function prerender({ cwd, out, log, config, build_data, force }) {
if (seen.has(path)) return;
seen.add(path);

/** @type {Map<string, import('types').Response>} */
/** @type {Map<string, import('types/endpoint').ServerResponse>} */
const dependencies = new Map();

const rendered = await app.render(
Expand Down
10 changes: 5 additions & 5 deletions packages/kit/src/core/adapt/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const __dirname = join(__filename, '..');
/** @param {string} _msg */
const logger = (_msg) => {};

/** @type {import('types.internal').Logger} */
/** @type {import('types/internal').Logger} */
const log = Object.assign(logger, {
info: logger,
minor: logger,
Expand All @@ -26,7 +26,7 @@ const suite = uvu.suite('adapter utils');
suite('copy files', () => {
const cwd = join(__dirname, 'fixtures/basic');

/** @type {import('types.internal').ValidatedConfig} */
/** @type {import('types/config').ValidatedConfig} */
const config = {
kit: {
// @ts-ignore
Expand All @@ -38,7 +38,7 @@ suite('copy files', () => {
}
};

/** @type {import('types.internal').BuildData} */
/** @type {import('types/internal').BuildData} */
const build_data = { client: [], server: [], static: [], entries: [] };

const utils = get_utils({ cwd, config, build_data, log });
Expand All @@ -65,7 +65,7 @@ suite('prerender', async () => {
const cwd = join(__dirname, 'fixtures/prerender');
const prerendered_files = join(__dirname, 'fixtures/prerender/build');

/** @type {import('types.internal').ValidatedConfig} */
/** @type {import('types/config').ValidatedConfig} */
const config = {
extensions: ['.svelte'],
kit: {
Expand All @@ -83,7 +83,7 @@ suite('prerender', async () => {
}
};

/** @type {import('types.internal').BuildData} */
/** @type {import('types/internal').BuildData} */
const build_data = { client: [], server: [], static: [], entries: ['/nested'] };

const utils = get_utils({ cwd, config, build_data, log });
Expand Down
8 changes: 4 additions & 4 deletions packages/kit/src/core/adapt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { prerender } from './prerender.js';
*
* @param {{
* cwd: string;
* config: import('types.internal').ValidatedConfig;
* build_data: import('types.internal').BuildData;
* log: import('types.internal').Logger;
* config: import('types/config').ValidatedConfig;
* build_data: import('types/internal').BuildData;
* log: import('types/internal').Logger;
* }} opts
* @returns {import('types').AdapterUtils}
* @returns {import('types/config').AdapterUtils}
*/
export function get_utils({ cwd, config, build_data, log }) {
return {
Expand Down
16 changes: 8 additions & 8 deletions packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const s = (value) => JSON.stringify(value);
* }>} ClientManifest */

/**
* @param {import('types.internal').ValidatedConfig} config
* @param {import('types/config').ValidatedConfig} config
* @param {{
* cwd?: string;
* runtime?: string;
* }} [opts]
* @returns {Promise<import('types.internal').BuildData>}
* @returns {Promise<import('types/internal').BuildData>}
*/
export async function build(config, { cwd = process.cwd(), runtime = '@sveltejs/kit/ssr' } = {}) {
const build_dir = path.resolve(cwd, '.svelte/build');
Expand Down Expand Up @@ -80,8 +80,8 @@ export async function build(config, { cwd = process.cwd(), runtime = '@sveltejs/
* @param {{
* cwd: string;
* base: string;
* config: import('types.internal').ValidatedConfig
* manifest: import('types.internal').ManifestData
* config: import('types/config').ValidatedConfig
* manifest: import('types/internal').ManifestData
* build_dir: string;
* output_dir: string;
* client_entry_file: string;
Expand Down Expand Up @@ -180,8 +180,8 @@ async function build_client({
* @param {{
* cwd: string;
* base: string;
* config: import('types.internal').ValidatedConfig
* manifest: import('types.internal').ManifestData
* config: import('types/config').ValidatedConfig
* manifest: import('types/internal').ManifestData
* build_dir: string;
* output_dir: string;
* client_entry_file: string;
Expand Down Expand Up @@ -444,8 +444,8 @@ async function build_server(
* @param {{
* cwd: string;
* base: string;
* config: import('types.internal').ValidatedConfig
* manifest: import('types.internal').ManifestData
* config: import('types/config').ValidatedConfig
* manifest: import('types/internal').ManifestData
* build_dir: string;
* output_dir: string;
* client_entry_file: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/create_app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function write_if_changed(file, code) {

const s = JSON.stringify;

/** @typedef {import('../../../types.internal').ManifestData} ManifestData */
/** @typedef {import('types/internal').ManifestData} ManifestData */

/**
* @param {{
Expand Down
8 changes: 4 additions & 4 deletions packages/kit/src/core/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { posixify } from '../utils.js';

/**
* @param {{
* config: import('types.internal').ValidatedConfig;
* config: import('types/config').ValidatedConfig;
* output: string;
* cwd?: string;
* }} opts
* @returns {import('types.internal').ManifestData}
* @returns {import('types/internal').ManifestData}
*/
export default function create_manifest_data({ config, output, cwd = process.cwd() }) {
/**
Expand All @@ -41,7 +41,7 @@ export default function create_manifest_data({ config, output, cwd = process.cwd
/** @type {string[]} */
const components = [];

/** @type {import('types.internal').RouteData[]} */
/** @type {import('types/internal').RouteData[]} */
const routes = [];

const default_layout = posixify(path.relative(cwd, `${output}/components/layout.svelte`));
Expand Down Expand Up @@ -346,7 +346,7 @@ function get_pattern(segments, add_trailing_slash) {
/**
* @param {string} dir
* @param {string} path
* @param {import('types.internal').Asset[]} files
* @param {import('types/internal').Asset[]} files
*/
function list_files(dir, path, files = []) {
fs.readdirSync(dir).forEach((file) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { copy_assets } from '../utils.js';
import svelte from '@sveltejs/vite-plugin-svelte';
import { get_server } from '../server/index.js';

/** @typedef {{ cwd?: string, port: number, host: string, https: boolean, config: import('../../../types.internal').ValidatedConfig }} Options */
/** @typedef {import('../../../types.internal').SSRComponent} SSRComponent */
/** @typedef {{ cwd?: string, port: number, host: string, https: boolean, config: import('types/config').ValidatedConfig }} Options */
/** @typedef {import('types/internal').SSRComponent} SSRComponent */

/** @param {Options} opts */
export function dev(opts) {
Expand Down Expand Up @@ -135,7 +135,7 @@ class Watcher extends EventEmitter {
// handle dynamic requests - i.e. pages and endpoints
const template = fs.readFileSync(this.config.kit.files.template, 'utf-8');

const hooks = /** @type {import('../../../types.internal').Hooks} */ (await this.vite
const hooks = /** @type {import('types/internal').Hooks} */ (await this.vite
.ssrLoadModule(`/${this.config.kit.files.hooks}`)
.catch(() => ({})));

Expand All @@ -156,7 +156,7 @@ class Watcher extends EventEmitter {

const rendered = await ssr(
{
headers: /** @type {import('../../../types.internal').Headers} */ (req.headers),
headers: /** @type {import('types/helper').Headers} */ (req.headers),
method: req.method,
host,
path: parsed.pathname,
Expand Down Expand Up @@ -303,7 +303,7 @@ class Watcher extends EventEmitter {
cwd: this.cwd
});

/** @type {import('../../../types.internal').SSRManifest} */
/** @type {import('types/internal').SSRManifest} */
this.manifest = {
assets: manifest_data.assets,
layout: manifest_data.layout,
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/core/load_config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ export async function load_config({ cwd = process.cwd() } = {}) {
}

/**
* @param {import('../../../types').Config} config
* @returns {import('../../../types.internal.js').ValidatedConfig}
* @param {import('types/config').Config} config
* @returns {import('types/config').ValidatedConfig}
*/
export function validate_config(config) {
/** @type {import('../../../types.internal.js').ValidatedConfig} */
/** @type {import('types/config').ValidatedConfig} */
const validated = validate(options, config, 'config');

// resolve paths
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/core/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const mutable = (dir) =>
* @param {{
* port: number;
* host: string;
* config: import('types.internal').ValidatedConfig;
* config: import('types/config').ValidatedConfig;
* https?: boolean;
* cwd?: string;
* }} opts
*/
export async function start({ port, host, config, https: use_https = false, cwd = process.cwd() }) {
const app_file = resolve(cwd, '.svelte/output/server/app.js');

/** @type {import('types.internal').App} */
/** @type {import('types/internal').App} */
const app = await import(pathToFileURL(app_file).href);

/** @type {import('sirv').RequestHandler} */
Expand All @@ -47,7 +47,7 @@ export async function start({ port, host, config, https: use_https = false, cwd
host: /** @type {string} */ (config.kit.host ||
req.headers[config.kit.hostHeader || 'host']),
method: req.method,
headers: /** @type {import('types.internal').Headers} */ (req.headers),
headers: /** @type {import('types/helper').Headers} */ (req.headers),
path: parsed.pathname,
body: await get_body(req),
query: new URLSearchParams(parsed.query || '')
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function noop() {}

/** @param {{ verbose: boolean }} opts */
export function logger({ verbose }) {
/** @type {import('../../types.internal').Logger} */
/** @type {import('types/internal').Logger} */
const log = (msg) => console.log(msg.replace(/^/gm, ' '));

log.success = (msg) => log(colors.green(`✔ ${msg}`));
Expand Down
16 changes: 8 additions & 8 deletions packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function initial_fetch(resource, opts) {
return fetch(resource, opts);
}

/** @typedef {import('types.internal').CSRComponent} CSRComponent */
/** @typedef {import('types/internal').CSRComponent} CSRComponent */

export class Renderer {
/** @param {{
Expand Down Expand Up @@ -113,7 +113,7 @@ export class Renderer {
* status: number;
* error: Error;
* nodes: Array<Promise<CSRComponent>>;
* page: import('types').Page;
* page: import('types/page').Page;
* }} selected
*/
async start({ status, error, nodes, page }) {
Expand Down Expand Up @@ -337,7 +337,7 @@ export class Renderer {
/**
*
* @param {{
* page: import('types').Page;
* page: import('types/page').Page;
* branch: import('./types').BranchNode[]
* }} opts
*/
Expand Down Expand Up @@ -404,7 +404,7 @@ export class Renderer {
* status?: number;
* error?: Error;
* module: CSRComponent;
* page: import('types').Page;
* page: import('types/page').Page;
* context: Record<string, any>;
* }} options
* @returns
Expand Down Expand Up @@ -439,7 +439,7 @@ export class Renderer {
const session = this.$session;

if (module.load) {
/** @type {import('types.internal').LoadInput | import('types.internal').ErrorLoadInput} */
/** @type {import('types/page').LoadInput | import('types/page').ErrorLoadInput} */
const load_input = {
page: {
host: page.host,
Expand All @@ -465,8 +465,8 @@ export class Renderer {
};

if (error) {
/** @type {import('types.internal').ErrorLoadInput} */ (load_input).status = status;
/** @type {import('types.internal').ErrorLoadInput} */ (load_input).error = error;
/** @type {import('types/page').ErrorLoadInput} */ (load_input).status = status;
/** @type {import('types/page').ErrorLoadInput} */ (load_input).error = error;
}

const loaded = await module.load.call(null, load_input);
Expand Down Expand Up @@ -502,7 +502,7 @@ export class Renderer {
session: this.session_id !== this.current.session_id
};

/** @type {import('types').Page} */
/** @type {import('types/page').Page} */
const page = { host: this.host, path, query, params };

/** @type {import('./types').BranchNode[]} */
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function find_anchor(node) {
export class Router {
/** @param {{
* base: string;
* routes: import('types.internal').CSRRoute[];
* routes: import('types/internal').CSRRoute[];
* }} opts */
constructor({ base, routes }) {
this.base = base;
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/client/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { set_paths } from '../paths.js';
* hydrate: {
* status: number;
* error: Error;
* nodes: Array<Promise<import('types.internal').CSRComponent>>;
* page: import('types').Page;
* nodes: Array<Promise<import('types/internal').CSRComponent>>;
* page: import('types/page').Page;
* };
* }} opts */
export async function start({ paths, target, session, host, route, spa, hydrate }) {
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/client/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CSRComponent, CSRRoute, LoadOutput } from '../../../types.internal';
import { Page } from '../../../types';
import { Page, LoadOutput } from '../../../types/page';
import { CSRComponent, CSRRoute } from '../../../types/internal';

export type NavigationInfo = {
id: string;
Expand Down
Loading

0 comments on commit 1d76d66

Please sign in to comment.