Skip to content

Commit

Permalink
chore: update types resolution setup (#10997)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
bluwy and benmccann authored Nov 9, 2023
1 parent dba649f commit 43c5f2c
Show file tree
Hide file tree
Showing 61 changed files with 143 additions and 149 deletions.
5 changes: 2 additions & 3 deletions packages/adapter-auto/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"module": "esnext",
"target": "esnext",
"skipLibCheck": true,
"target": "es2022",
"module": "node16",
"moduleResolution": "node16",
"baseUrl": "."
},
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { fileURLToPath } from 'node:url';
* }} WranglerConfig
*/

/** @type {import('.').default} */
/** @type {import('./index.js').default} */
export default function ({ config = 'wrangler.toml' } = {}) {
return {
name: '@sveltejs/adapter-cloudflare-workers',
Expand Down
5 changes: 3 additions & 2 deletions packages/adapter-cloudflare-workers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"module": "es2020",
"moduleResolution": "node",
"target": "es2022",
"module": "node16",
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as esbuild from 'esbuild';

/** @type {import('.').default} */
/** @type {import('./index.js').default} */
export default function (options = {}) {
return {
name: '@sveltejs/adapter-cloudflare',
Expand Down Expand Up @@ -67,8 +67,8 @@ export default function (options = {}) {
/**
* @param {import('@sveltejs/kit').Builder} builder
* @param {string[]} assets
* @param {import('./index').AdapterOptions['routes']} routes
* @returns {import('.').RoutesJSONSpec}
* @param {import('./index.js').AdapterOptions['routes']} routes
* @returns {import('./index.js').RoutesJSONSpec}
*/
function get_routes_json(builder, assets, { include = ['/*'], exclude = ['<all>'] }) {
if (!Array.isArray(include) || !Array.isArray(exclude)) {
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions packages/adapter-cloudflare/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"module": "es2020",
"moduleResolution": "node",
"target": "es2022",
"module": "node16",
"moduleResolution": "node16",
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["index.js", "placeholders.ts", "src/worker.js"]
"include": ["index.js", "placeholders.d.ts", "src/worker.js"]
}
2 changes: 1 addition & 1 deletion packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const edge_set_in_env_var =

const FUNCTION_PREFIX = 'sveltekit-';

/** @type {import('.').default} */
/** @type {import('./index.js').default} */
export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
return {
name: '@sveltejs/adapter-netlify',
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/src/serverless.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './shims';
import { Server } from '0SERVER';
import { split_headers } from './headers';
import { split_headers } from './headers.js';

/**
* @param {import('@sveltejs/kit').SSRManifest} manifest
Expand Down
4 changes: 3 additions & 1 deletion packages/adapter-netlify/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"module": "es2022",
"target": "es2022",
"module": "es2022",
// `@netlify/function` > `@netlify/serverless-functions-api` types are not compatible,
// so using this moduleResolution for now
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import json from '@rollup/plugin-json';

const files = fileURLToPath(new URL('./files', import.meta.url).href);

/** @type {import('.').default} */
/** @type {import('./index.js').default} */
export default function (opts = {}) {
const { out = 'build', precompress, envPrefix = '', polyfill = true } = opts;

Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
"prepublishOnly": "pnpm build"
},
"devDependencies": {
"@polka/url": "^1.0.0-next.21",
"@polka/url": "^1.0.0-next.23",
"@sveltejs/kit": "workspace:^",
"@types/node": "^16.18.6",
"c8": "^8.0.0",
"polka": "^1.0.0-next.22",
"polka": "^1.0.0-next.23",
"sirv": "^2.0.3",
"typescript": "^4.9.4",
"vitest": "^0.34.5"
Expand Down
7 changes: 5 additions & 2 deletions packages/adapter-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
"noEmit": true,
"noImplicitAny": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"target": "es2022",
"module": "es2022",
"target": "es2017",
// Can't use moduleResolution: node16 because of these issues:
// https://github.com/rollup/plugins/issues/1329
// https://github.com/lukeed/polka/issues/199
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-static/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import { platforms } from './platforms.js';

/** @type {import('.').default} */
/** @type {import('./index.js').default} */
export default function (options) {
return {
name: '@sveltejs/adapter-static',
Expand Down Expand Up @@ -56,7 +56,7 @@ See https://kit.svelte.dev/docs/page-options#prerender for more details`
assets = pages,
fallback,
precompress
} = options ?? platform?.defaults ?? /** @type {import('./index').AdapterOptions} */ ({});
} = options ?? platform?.defaults ?? /** @type {import('./index.js').AdapterOptions} */ ({});

builder.rimraf(assets);
builder.rimraf(pages);
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-static/platforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'node:fs';
* @typedef {{
* name: string;
* test: () => boolean;
* defaults: import('./index').AdapterOptions;
* defaults: import('./index.js').AdapterOptions;
* done: (builder: import('@sveltejs/kit').Builder) => void;
* }}
* Platform */
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-static/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"module": "es2022",
"target": "es2022",
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-vercel/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"strict": true,
"noEmit": true,
"noImplicitAny": true,
"module": "es2022",
"moduleResolution": "node",
"target": "es2022",
"module": "node16",
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
Expand Down
16 changes: 8 additions & 8 deletions packages/create-svelte/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'node:fs';
import path from 'node:path';
import { mkdirp, copy, dist } from './utils.js';

/** @type {import('./types/index').create} */
/** @type {import('./types/index.js').create} */
export async function create(cwd, options) {
mkdirp(cwd);

Expand All @@ -22,7 +22,7 @@ function write_template_files(template, types, name, cwd) {
copy(`${dir}/package.json`, `${cwd}/package.json`);

const manifest = `${dir}/files.types=${types}.json`;
const files = /** @type {import('./types/internal').File[]} */ (
const files = /** @type {import('./types/internal.js').File[]} */ (
JSON.parse(fs.readFileSync(manifest, 'utf-8'))
);

Expand All @@ -37,12 +37,12 @@ function write_template_files(template, types, name, cwd) {
/**
*
* @param {string} cwd
* @param {import('./types/internal').Options} options
* @param {import('./types/internal.js').Options} options
* @param {string} name
*/
function write_common_files(cwd, options, name) {
const shared = dist('shared.json');
const { files } = /** @type {import('./types/internal').Common} */ (
const { files } = /** @type {import('./types/internal.js').Common} */ (
JSON.parse(fs.readFileSync(shared, 'utf-8'))
);

Expand Down Expand Up @@ -73,8 +73,8 @@ function write_common_files(cwd, options, name) {
}

/**
* @param {import('./types/internal').Condition} condition
* @param {import('./types/internal').Options} options
* @param {import('./types/internal.js').Condition} condition
* @param {import('./types/internal.js').Options} options
* @returns {boolean}
*/
function matches_condition(condition, options) {
Expand Down Expand Up @@ -134,8 +134,8 @@ function sort_keys(obj) {
* Sort files so that those which apply more generically come first so they
* can be overwritten by files for more precise cases later.
*
* @param files {import('./types/internal').Common['files']}
* */
* @param {import('./types/internal.js').Common['files']} files
*/
function sort_files(files) {
return files.sort((f1, f2) => {
const f1_more_generic =
Expand Down
9 changes: 4 additions & 5 deletions packages/create-svelte/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"allowJs": true,
"checkJs": true,
"noEmit": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"target": "es2022",
"module": "node16",
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"strict": true,
"skipLibCheck": true
"strict": true
},
"include": ["./scripts/**/*", "./test/*.js", "./*.js"]
}
2 changes: 1 addition & 1 deletion packages/create-svelte/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options } from './internal';
import { Options } from './internal.js';

/**
* Create a new SvelteKit project.
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'node:path';

/** @typedef {import('./types').Validator} Validator */
/** @typedef {import('./types.js').Validator} Validator */

const directives = object({
'child-src': string_array(),
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
* @param {string} file
* @param {string[]} component_extensions
* @param {string[]} module_extensions
* @returns {import('./types').RouteFile}
* @returns {import('./types.js').RouteFile}
*/
function analyze(project_relative, file, component_extensions, module_extensions) {
const component_extension = component_extensions.find((ext) => file.endsWith(ext));
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { normalizePath } from 'vite';
* @param {import('types').ManifestData} manifest_data
* @param {import('vite').Manifest} server_manifest
* @param {import('vite').Manifest | null} client_manifest
* @param {import('rollup').OutputAsset[] | null} css
* @param {import('vite').Rollup.OutputAsset[] | null} css
*/
export function build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, css) {
mkdirp(`${out}/server/nodes`);
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/graph_analysis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function is_illegal(id, dirs) {

/**
* Creates a guard that checks that no id imports a module that is not allowed to be imported into client-side code.
* @param {import('rollup').PluginContext} context
* @param {import('vite').Rollup.PluginContext} context
* @param {{ cwd: string; lib: string }} paths
*/
export function module_guard(context, { cwd, lib }) {
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/graph_analysis/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { module_guard } from './index.js';
*/
function check(graph, expected_error) {
// @ts-expect-error
const context = /** @type {import('rollup').PluginContext} */ ({
const context = /** @type {import('vite').Rollup.PluginContext} */ ({
/** @param {string} id */
getModuleInfo(id) {
return {
Expand Down
8 changes: 4 additions & 4 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

const cwd = process.cwd();

/** @type {import('./types').EnforcedConfig} */
/** @type {import('./types.js').EnforcedConfig} */
const enforced_config = {
appType: true,
base: true,
Expand Down Expand Up @@ -702,7 +702,7 @@ function kit({ svelte_config }) {

secondary_build_started = true;

const { output } = /** @type {import('rollup').RollupOutput} */ (
const { output } = /** @type {import('vite').Rollup.RollupOutput} */ (
await vite.build({
configFile: vite_config.configFile,
// CLI args
Expand Down Expand Up @@ -742,7 +742,7 @@ function kit({ svelte_config }) {
};

const css = output.filter(
/** @type {(value: any) => value is import('rollup').OutputAsset} */
/** @type {(value: any) => value is import('vite').Rollup.OutputAsset} */
(value) => value.type === 'asset' && value.fileName.endsWith('.css')
);

Expand Down Expand Up @@ -863,7 +863,7 @@ function warn_overridden_config(config, resolved_config) {
/**
* @param {Record<string, any>} config
* @param {Record<string, any>} resolved_config
* @param {import('./types').EnforcedConfig} enforced_config
* @param {import('./types.js').EnforcedConfig} enforced_config
* @param {string} path
* @param {string[]} out used locally to compute the return value
*/
Expand Down
5 changes: 1 addition & 4 deletions packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import { not_found } from '../utils.js';
/** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */

/**
* @param {{
* middlewares: import('connect').Server;
* httpServer: import('http').Server;
* }} vite
* @param {{ middlewares: import('connect').Server }} vite
* @param {import('vite').ResolvedConfig} vite_config
* @param {import('types').ValidatedConfig} svelte_config
*/
Expand Down
Loading

0 comments on commit 43c5f2c

Please sign in to comment.