diff --git a/.eslintrc.js b/.eslintrc.js index 2d51c3c05..57826c457 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -52,7 +52,7 @@ module.exports = { }, }, { - files: ["*.ts"], + files: ["*.ts", "*.mts"], parser: "@typescript-eslint/parser", parserOptions: { sourceType: "module", diff --git a/docs-svelte-kit/.eslintrc.cjs b/docs-svelte-kit/.eslintrc.cjs index bddda3031..20e9b4b96 100644 --- a/docs-svelte-kit/.eslintrc.cjs +++ b/docs-svelte-kit/.eslintrc.cjs @@ -1,4 +1,3 @@ -// eslint-disable-next-line no-undef -- ignore module.exports = { extends: ["plugin:svelte/recommended"], env: { @@ -15,5 +14,6 @@ module.exports = { "svelte/prefer-class-directive": "error", "svelte/prefer-style-directive": "error", "svelte/spaced-html-comment": "error", + "node/file-extension-in-import": "off", }, } diff --git a/docs-svelte-kit/build-system/build.js b/docs-svelte-kit/build-system/build.mts similarity index 70% rename from docs-svelte-kit/build-system/build.js rename to docs-svelte-kit/build-system/build.mts index b071bf50f..3a335ffe1 100644 --- a/docs-svelte-kit/build-system/build.js +++ b/docs-svelte-kit/build-system/build.mts @@ -1,21 +1,28 @@ -const esbuild = require("esbuild") -const path = require("path") -const fs = require("fs") +import esbuild from "esbuild" +import path from "path" +import fs from "fs" // const babelCore = require("@babel/core") // const t = require("@babel/types") +const dirname = path.dirname( + new URL( + // @ts-expect-error -- Cannot change `module` option + import.meta.url, + ).pathname, +) + build( - require.resolve("./src/eslint.mjs"), - path.join(__dirname, "../shim/eslint.mjs"), + path.join(dirname, "./src/eslint.mjs"), + path.join(dirname, "../shim/eslint.mjs"), ["assert", "util"], ) build( - require.resolve("../../node_modules/assert"), - path.join(__dirname, "../shim/assert.mjs"), + path.join(dirname, "../../node_modules/assert"), + path.join(dirname, "../shim/assert.mjs"), ) /** build */ -function build(input, out, injects = []) { +function build(input: string, out: string, injects: string[] = []) { // eslint-disable-next-line no-console -- ignore console.log(`build@ ${input}`) let code = bundle(input, ["path", ...injects]) @@ -24,21 +31,21 @@ function build(input, out, injects = []) { } /** bundle */ -function bundle(entryPoint, externals) { +function bundle(entryPoint: string, externals: string[]) { const result = esbuild.buildSync({ entryPoints: [entryPoint], format: "esm", bundle: true, external: externals, write: false, - inject: [require.resolve("./src/process-shim.mjs")], + inject: [path.join(dirname, "./src/process-shim.mjs")], }) return `${result.outputFiles[0].text}` } /** transform code */ -function transform(code, injects) { +function transform(code: string, injects: string[]) { const newCode = code.replace(/"[a-z]+" = "[a-z]+";/, "") // const newCode = babelCore.transformSync(code, { // babelrc: false, diff --git a/docs-svelte-kit/shim/module.mjs b/docs-svelte-kit/shim/module.mjs index 6f5e094c7..9e4f5c979 100644 --- a/docs-svelte-kit/shim/module.mjs +++ b/docs-svelte-kit/shim/module.mjs @@ -1,7 +1,7 @@ /* eslint require-jsdoc:0 -- shim */ -function createRequire() { +function _createRequire() { return () => null } -export { createRequire } -export default { createRequire } +export { _createRequire as createRequire } +export default { createRequire: _createRequire } diff --git a/docs-svelte-kit/src/lib/eslint/scripts/linter.js b/docs-svelte-kit/src/lib/eslint/scripts/linter.js index 85a34939c..334221494 100644 --- a/docs-svelte-kit/src/lib/eslint/scripts/linter.js +++ b/docs-svelte-kit/src/lib/eslint/scripts/linter.js @@ -1,8 +1,7 @@ -// eslint-disable-next-line node/file-extension-in-import -- ignore import { rules as pluginRules } from "../../../../../src/utils/rules.ts" import { Linter } from "eslint" import * as svelteEslintParser from "svelte-eslint-parser" -// eslint-disable-next-line node/file-extension-in-import -- ignore + export { preprocess, postprocess } from "../../../../../src/processor/index.ts" const linter = new Linter() diff --git a/docs-svelte-kit/src/lib/utils.js b/docs-svelte-kit/src/lib/utils.js index 4e7a09460..5cdc53b9f 100644 --- a/docs-svelte-kit/src/lib/utils.js +++ b/docs-svelte-kit/src/lib/utils.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line node/file-extension-in-import -- ignore import { rules } from "../../../src/utils/rules.ts" import { readable, writable } from "svelte/store" // eslint-disable-next-line node/no-missing-import -- ignore diff --git a/docs-svelte-kit/tools/highlight.mjs b/docs-svelte-kit/tools/highlight.mts similarity index 86% rename from docs-svelte-kit/tools/highlight.mjs rename to docs-svelte-kit/tools/highlight.mts index 0734c43ce..c274aae27 100644 --- a/docs-svelte-kit/tools/highlight.mjs +++ b/docs-svelte-kit/tools/highlight.mts @@ -7,12 +7,12 @@ import "prism-svelte" loadLanguages(["markup", "css", "javascript"]) /** Wrap pre tag */ -function wrapPre(code, lang) { +function wrapPre(code: string, lang: string) { const htmlCode = lang === "text" ? escapeHtml(code) : code return `
${htmlCode}
` } -const EXTENSION_MAPPINGS = { +const EXTENSION_MAPPINGS: Record = { vue: "markup", html: "markup", svelte: "svelte", @@ -28,7 +28,7 @@ const EXTENSION_MAPPINGS = { rs: "rust", } -export default (str, lang) => { +export default (str: string, lang: string): string => { if (!lang) { return wrapPre(str, "text") } diff --git a/docs-svelte-kit/tools/markdown-it-auto-inject-components.mjs b/docs-svelte-kit/tools/markdown-it-auto-inject-components.mts similarity index 79% rename from docs-svelte-kit/tools/markdown-it-auto-inject-components.mjs rename to docs-svelte-kit/tools/markdown-it-auto-inject-components.mts index 0e5c2b1cb..6ec02750e 100644 --- a/docs-svelte-kit/tools/markdown-it-auto-inject-components.mjs +++ b/docs-svelte-kit/tools/markdown-it-auto-inject-components.mts @@ -1,13 +1,15 @@ +import type Md from "markdown-it" +import type Token from "markdown-it/lib/token" /** * @param {import('markdown-it')} md */ -export default (md) => { +export default (md: Md): void => { md.core.ruler.push("auto_inject_components", (state) => { const injected = new Set(extractInjectedComponents(state.tokens)) for (const component of new Set( extractComponents(state.tokens, injected), )) { - const newToken = new state.Token("auto_inject_component") + const newToken = new state.Token("auto_inject_component", "", 0) newToken.content = `` @@ -15,7 +17,7 @@ import ${component} from '$lib/components/${component}.svelte' } /** Extract imported components */ - function* extractInjectedComponents(tokens) { + function* extractInjectedComponents(tokens: Token[]): Iterable { for (const token of tokens) { if ( (token.type === "html_inline" || token.type === "html_block") && @@ -33,7 +35,10 @@ import ${component} from '$lib/components/${component}.svelte' } /** Extract inject components */ - function* extractComponents(tokens, injected) { + function* extractComponents( + tokens: Token[], + injected: Set, + ): Iterable { for (const token of tokens) { if (token.type === "html_inline" || token.type === "html_block") { const match = /<([A-Z][\w$]*)/u.exec(token.content) @@ -47,7 +52,7 @@ import ${component} from '$lib/components/${component}.svelte' } } }) - // eslint-disable-next-line camelcase -- ignore + md.renderer.rules.auto_inject_component = (tokens, idx, _options) => { return tokens[idx].content } diff --git a/docs-svelte-kit/tools/markdown-it-container-option.mjs b/docs-svelte-kit/tools/markdown-it-container-option.mts similarity index 79% rename from docs-svelte-kit/tools/markdown-it-container-option.mjs rename to docs-svelte-kit/tools/markdown-it-container-option.mts index f8dff94f1..f2cabf0cf 100644 --- a/docs-svelte-kit/tools/markdown-it-container-option.mjs +++ b/docs-svelte-kit/tools/markdown-it-container-option.mts @@ -1,8 +1,13 @@ +import type containerPlugin from "markdown-it-container" +type ContainerPluginOption = Parameters[2] /** * Generate markdown-it-container option * @see https://github.com/markdown-it/markdown-it-container */ -export default (type, defaultTitle = type.toUpperCase()) => { +export default ( + type: string, + defaultTitle = type.toUpperCase(), +): ContainerPluginOption => { return { render(tokens, index) { const token = tokens[index] diff --git a/docs-svelte-kit/tools/markdown-it-markdown.mjs b/docs-svelte-kit/tools/markdown-it-markdown.mts similarity index 72% rename from docs-svelte-kit/tools/markdown-it-markdown.mjs rename to docs-svelte-kit/tools/markdown-it-markdown.mts index 17123c999..81b750e74 100644 --- a/docs-svelte-kit/tools/markdown-it-markdown.mjs +++ b/docs-svelte-kit/tools/markdown-it-markdown.mts @@ -1,15 +1,24 @@ import path from "path" import spawn from "cross-spawn" +import type Md from "markdown-it" + +type TreeItem = { + children: TreeItem[] +} +type TreeStack = { item: TreeItem; level: number; upper: TreeStack | null } class TOCRenderer { - constructor(name) { - const item = { children: [] } + private readonly tree: TreeItem + + private stack: TreeStack + + public constructor() { + const item: TreeItem = { children: [] } this.tree = item this.stack = { item, level: 1, upper: null } - this.name = name } - addMenu(level, id, title) { + public addMenu(level: number, id: string, title: string) { if (this.stack.level < level) { const parent = this.stack.item const item = parent.children[parent.children.length - 1] @@ -24,19 +33,19 @@ class TOCRenderer { this.stack.item.children.push(item) } - toc() { + public toc() { return this.tree } } /** * @param {import('markdown-it')} md */ -export default (md) => { +export default (md: Md): void => { md.core.ruler.push("custom_markdown", (state) => { const tokens = state.tokens - tokens.unshift(new state.Token("custom_markdown_data")) + tokens.unshift(new state.Token("custom_markdown_data", "", 0)) }) - // eslint-disable-next-line camelcase -- ignore + md.renderer.rules.custom_markdown_data = ( tokens, _idx, @@ -44,21 +53,20 @@ export default (md) => { env, _self, ) => { - const name = path.basename(env.id).replace(/\.md$/, "") - const renderer = new TOCRenderer(name) + const renderer = new TOCRenderer() for (let idx = 0; idx < tokens.length; idx++) { const token = tokens[idx] if (token.type !== "heading_open") { continue } - let level = Number(token.tag.substr(1)) + const level = Number(token.tag.slice(1)) if (level > 3) { continue } // Aggregate the next token children text. - const title = tokens[idx + 1].children - .filter( + const title = tokens[idx + 1] + .children!.filter( (token) => token.type === "text" || token.type === "emoji" || @@ -66,11 +74,11 @@ export default (md) => { ) .reduce((acc, t) => acc + t.content, "") - let slug = token.attrGet("id") + const slug = token.attrGet("id")! renderer.addMenu(level, slug, title) } - const fileInfo = {} + const fileInfo: { timestamp?: number; lastUpdated?: string } = {} const timestamp = getGitLastUpdatedTimestamp(env.id) if (timestamp) { fileInfo.timestamp = timestamp @@ -85,7 +93,7 @@ export default (md) => { } /** Get last updated timestamp */ -function getGitLastUpdatedTimestamp(filePath) { +function getGitLastUpdatedTimestamp(filePath: string) { let lastUpdated try { lastUpdated = diff --git a/docs-svelte-kit/tools/markdown-it-replace-link.mjs b/docs-svelte-kit/tools/markdown-it-replace-link.mts similarity index 70% rename from docs-svelte-kit/tools/markdown-it-replace-link.mjs rename to docs-svelte-kit/tools/markdown-it-replace-link.mts index a1c612b43..c4d8ebf01 100644 --- a/docs-svelte-kit/tools/markdown-it-replace-link.mjs +++ b/docs-svelte-kit/tools/markdown-it-replace-link.mts @@ -1,17 +1,17 @@ -// eslint-disable-next-line eslint-comments/disable-enable-pair -- ignore -/* eslint-disable camelcase -- ignore */ import path from "path" +import type Md from "markdown-it" +import type Token from "markdown-it/lib/token" -export default (md, options = {}) => { +export default (md: Md, options: { baseUrl: string; root: string }): void => { const base = options.baseUrl const root = path.resolve(options.root) /** Normalize href */ - function normalizeHref(curr, href) { + function normalizeHref(curr: string, href: string) { let absolutePath let hash = "" if (/\.md(?:#.*)?$/.test(href)) { - hash = /\.md(#.*)?$/.exec(href)[1] || "" + hash = /\.md(#.*)?$/.exec(href)![1] || "" absolutePath = path.join( path.dirname(curr), hash ? href.slice(0, -hash.length) : href, @@ -31,23 +31,23 @@ export default (md, options = {}) => { const token = tokens[idx] const hrefIndex = token.attrIndex("href") if (hrefIndex >= 0) { - const link = token.attrs[hrefIndex] + const link = token.attrs![hrefIndex] const href = link[1] if (/^https?:/.test(href)) { const proxyToken = { ...token, - attrs: [...token.attrs, ["target", "_blank"]], - } + attrs: [...token.attrs!, ["target", "_blank"]], + } as Token return self.renderToken([proxyToken], 0, options) } else if (/\.md(?:#.*)?$/.test(href) || /^#.*$/.test(href)) { const proxyToken = { ...token, attrs: [ - ...token.attrs.slice(0, hrefIndex - 1), + ...token.attrs!.slice(0, hrefIndex - 1), [link[0], normalizeHref(env.id, href)], - ...token.attrs.slice(hrefIndex + 1), + ...token.attrs!.slice(hrefIndex + 1), ], - } + } as Token return self.renderToken([proxyToken], 0, options) } } diff --git a/docs-svelte-kit/tools/markdown-it-title.mjs b/docs-svelte-kit/tools/markdown-it-title.mts similarity index 80% rename from docs-svelte-kit/tools/markdown-it-title.mjs rename to docs-svelte-kit/tools/markdown-it-title.mts index 25bda4644..73b9ccac5 100644 --- a/docs-svelte-kit/tools/markdown-it-title.mjs +++ b/docs-svelte-kit/tools/markdown-it-title.mts @@ -1,20 +1,21 @@ +import type Md from "markdown-it" /** * @param {import('markdown-it')} md */ -export default (md) => { +export default (md: Md): void => { const headingOpen = md.renderer.rules.heading_open - // eslint-disable-next-line camelcase -- ignore + md.renderer.rules.heading_open = (tokens, idx, options, env, self) => { const head = headingOpen ? headingOpen(tokens, idx, options, env, self) : self.renderToken(tokens, idx, options) const token = tokens[idx] - let level = Number(token.tag.substr(1)) + const level = Number(token.tag.substr(1)) if (level > 1) { return head } - const title = tokens[idx + 1].children - .filter( + const title = tokens[idx + 1] + .children!.filter( (token) => token.type === "text" || token.type === "emoji" || diff --git a/docs-svelte-kit/tools/vite-plugin-svelte-md-option.mjs b/docs-svelte-kit/tools/vite-plugin-svelte-md-option.mts similarity index 91% rename from docs-svelte-kit/tools/vite-plugin-svelte-md-option.mjs rename to docs-svelte-kit/tools/vite-plugin-svelte-md-option.mts index 1d1a6c4ed..af9ff3fca 100644 --- a/docs-svelte-kit/tools/vite-plugin-svelte-md-option.mjs +++ b/docs-svelte-kit/tools/vite-plugin-svelte-md-option.mts @@ -8,8 +8,9 @@ import titlePlugin from "./markdown-it-title.mjs" import markdownPlugin from "./markdown-it-markdown.mjs" import containerPluginOption from "./markdown-it-container-option.mjs" import slugify from "@sindresorhus/slugify" +import type { Options } from "vite-plugin-svelte-md" -export default (options = {}) => ({ +export default (options: { baseUrl: string; root: string }): Options => ({ wrapperClasses: [], markdownItOptions: { highlight, diff --git a/package.json b/package.json index 90d15a39c..f8f60c441 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "prepublishOnly": "yarn clean && yarn build", "pretest:base": "cross-env DEBUG=eslint-plugin-svelte*", "preversion": "yarn test && git add .", - "svelte-kit": "node --experimental-loader ./svelte-kit-import-hook.mjs node_modules/vite/bin/vite.js --config vite.config.mjs", + "svelte-kit": "node --experimental-loader ./svelte-kit-import-hook.mjs node_modules/vite/bin/vite.js", "test": "yarn mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000", "ts": "node -r esbuild-register", "update": "yarn ts ./tools/update.ts && yarn format-for-gen-file", @@ -74,19 +74,25 @@ "@babel/plugin-proposal-function-bind": "^7.16.7", "@babel/types": "^7.16.0", "@fontsource/fira-mono": "^4.5.0", - "@ota-meshi/eslint-plugin": "^0.11.0", + "@ota-meshi/eslint-plugin": "^0.11.3", "@sindresorhus/slugify": "^2.1.0", "@sveltejs/adapter-static": "^1.0.0-next.26", "@sveltejs/kit": "^1.0.0-next.360", "@types/babel__core": "^7.1.19", + "@types/cross-spawn": "^6.0.2", + "@types/escape-html": "^1.0.2", "@types/eslint": "^8.0.0", "@types/eslint-scope": "^3.7.0", "@types/eslint-visitor-keys": "^1.0.0", "@types/estree": "^0.0.52", "@types/less": "^3.0.3", + "@types/markdown-it": "^12.2.3", + "@types/markdown-it-container": "^2.0.5", + "@types/markdown-it-emoji": "^2.0.2", "@types/mocha": "^9.0.0", "@types/node": "^16.0.0", "@types/postcss-safe-parser": "^5.0.1", + "@types/prismjs": "^1.26.0", "@types/stylus": "^0.48.38", "@typescript-eslint/eslint-plugin": "^5.4.0", "@typescript-eslint/parser": "^5.4.1-0", @@ -119,7 +125,6 @@ "mocha": "^10.0.0", "nyc": "^15.1.0", "pako": "^2.0.3", - "pirates": "^4.0.1", "postcss-nested": "^5.0.6", "prettier": "^2.2.1", "prettier-plugin-pkg": "^0.16.0", @@ -134,8 +139,8 @@ "svelte": "^3.46.1", "svelte-adapter-ghpages": "0.0.2", "typescript": "^4.5.2", - "vite": "^2.9.13", - "vite-plugin-svelte-md": "^0.1.3" + "vite": "^3.0.0-0", + "vite-plugin-svelte-md": "^0.1.5" }, "publishConfig": { "access": "public" diff --git a/svelte-kit-import-hook.mjs b/svelte-kit-import-hook.mjs index 3b0256a22..5fee66968 100644 --- a/svelte-kit-import-hook.mjs +++ b/svelte-kit-import-hook.mjs @@ -2,25 +2,22 @@ import babelCore from "@babel/core" import * as t from "@babel/types" -import pirates from "pirates" - -pirates.addHook(transform, { - exts: [".js", ".mjs"], -}) - /** transform code */ -function transform(code, _filename) { - if (code.includes("import(")) { +function transform(code, filename) { + if ( + filename.includes("/@sveltejs/kit/") && + code.includes("svelte.config.js") + ) { let transformed = false const newCode = babelCore.transformSync(code, { babelrc: false, plugins: [ { visitor: { - CallExpression(path) { - const callee = path.get("callee") - if (callee.type === "Import") { - callee.replaceWith(t.identifier("$$$import")) + StringLiteral(path) { + if (path.node.value === "svelte.config.js") { + // The configuration file loads `svelte.config.mjs`. + path.replaceWith(t.stringLiteral("svelte.config.mjs")) transformed = true } }, @@ -31,25 +28,7 @@ function transform(code, _filename) { if (!transformed) { return code } - return `${newCode.code} -async function $$$import(module, ...args) { - const m = await import(module) - return ________adjustModule(m) -} -function ________adjustModule(m) { - const keys = Object.keys(m); - if(m.default && keys.length === 1 && keys[0] === 'default' && typeof m.default === 'object') { - const result = { - default: ________adjustModule(m.default) - } - for (const key of Object.keys(m.default)) { - result[key] = m.default[key] - } - return result - } - return m -} -` + return `${newCode.code}` } return code @@ -70,7 +49,7 @@ export async function load(url, context, defaultLoad) { const result = await defaultLoad(url, context, defaultLoad) return { format: result.format, - source: transform(`${result.source}`), + source: transform(`${result.source}`, url), } } @@ -90,6 +69,6 @@ export async function transformSource(source, context, defaultTransformSource) { defaultTransformSource, ) return { - source: transform(`${result.source}`), + source: transform(`${result.source}`, context.url), } } diff --git a/svelte.config.js b/svelte.config.js deleted file mode 100644 index 73c8688bc..000000000 --- a/svelte.config.js +++ /dev/null @@ -1,95 +0,0 @@ -"use strict" - -/* !! This project can't be ESM yet, so hack it to get sveltekit to work. !! */ -const esbuild = require("esbuild") -const path = require("path") -const babelCore = require("@babel/core") -const pirates = require("pirates") - -/* -- Build config -- */ -esbuild.buildSync({ - entryPoints: [require.resolve("./svelte.config.esm.mjs")], - outfile: path.join(__dirname, "./svelte.config-dist.js"), - format: "cjs", - bundle: true, - external: [ - "path", - "cross-spawn", - "prismjs", - "os", - "fs", - "stream", - "zlib", - "util", - "./docs-svelte-kit/build-system/build.js", - ], -}) - -/* -- transpile -- */ -const { register } = require("esbuild-register/dist/node") -register({ - format: "cjs", - extensions: [".js", ".mjs", ".cjs", ".ts"], -}) - -/* -- transform '@sveltejs/kit/ssr' path -- */ -pirates.addHook(transformImportSsr, { - exts: [".js", ".mjs"], -}) - -/** transform '@sveltejs/kit/ssr' path */ -function transformImportSsr(code, _filename) { - if (code.includes("@sveltejs/kit/ssr")) { - const resolvedPath = require.resolve( - "./node_modules/@sveltejs/kit/dist/ssr", - ) - let transformed = false - const newCode = babelCore.transformSync(code, { - babelrc: false, - plugins: [ - { - visitor: { - CallExpression(path) { - const callee = path.get("callee") - if ( - callee.type !== "Identifier" || - callee.node.name !== "require" - ) { - return - } - const args = path.get("arguments") - if (args.length !== 1) { - return - } - const arg = args[0] - if ( - arg.type === "StringLiteral" && - arg.node.value === "@sveltejs/kit/ssr" - ) { - arg.node.value = resolvedPath - transformed = true - } - }, - ImportDeclaration(path) { - if (path.node.source.value === "@sveltejs/kit/ssr") { - path.node.source.value = resolvedPath - transformed = true - } - }, - }, - }, - ], - }) - if (!transformed) { - return code - } - return `${newCode.code}` - } - - return code -} - -/* eslint node/no-missing-require: 0 -- ignore */ -const config = require("./svelte.config-dist.js").default - -module.exports = config diff --git a/svelte.config.esm.mjs b/svelte.config.mjs similarity index 65% rename from svelte.config.esm.mjs rename to svelte.config.mjs index 0a27a6952..1bc0e851a 100644 --- a/svelte.config.esm.mjs +++ b/svelte.config.mjs @@ -1,14 +1,18 @@ -/* global __dirname, URL -- __dirname, URL */ import ghpagesAdapter from "svelte-adapter-ghpages" import path from "path" +import fs from "fs" -const dirname = - typeof __dirname !== "undefined" - ? __dirname - : (() => { - const metaUrl = Function(`return import.meta.url`)() - return path.dirname(new URL(metaUrl).pathname) - })() +const dirname = path.dirname(new URL(import.meta.url).pathname) + +// This project can't be ESM yet, so hack it to get svelte-kit to work. +// A hack that treats files in the `.svelte-kit` directory as ESM. +if (!fs.existsSync(path.join(dirname, ".svelte-kit"))) { + fs.mkdirSync(path.join(dirname, ".svelte-kit")) +} +fs.writeFileSync( + path.join(dirname, ".svelte-kit/package.json"), + JSON.stringify({ type: "module" }), +) /** @type {import('@sveltejs/kit').Config} */ const config = { diff --git a/tsconfig.build.json b/tsconfig.build.json index 31b62dbf8..542d743fb 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,6 +1,12 @@ { "extends": "./tsconfig.json", - "exclude": ["tests/**/*", "tools/**/*", "typings/**/*"], + "exclude": [ + "tests/**/*", + "tools/**/*", + "typings/**/*", + "vite.config.mts", + "docs-svelte-kit/**/*.mts" + ], "compilerOptions": { "removeComments": true /* Do not emit comments to output. */ } diff --git a/tsconfig.json b/tsconfig.json index 9c5f25268..f498baa9c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,9 @@ "src/**/*", "tests/src/**/*", "tests/utils/**/*", - "tools/**/*" + "tools/**/*", + "vite.config.mts", + "docs-svelte-kit/**/*.mts" // "typings/**/*" ], "exclude": ["lib/**/*", "tests/fixtures/**/*"] diff --git a/vite.config.mjs b/vite.config.mts similarity index 82% rename from vite.config.mjs rename to vite.config.mts index a9c730e15..9e2c669f5 100644 --- a/vite.config.mjs +++ b/vite.config.mts @@ -1,15 +1,21 @@ -/* global URL -- URL */ +// @ts-expect-error -- Missing type information import { sveltekit } from "@sveltejs/kit/vite" import path from "path" import svelteMd from "vite-plugin-svelte-md" import svelteMdOption from "./docs-svelte-kit/tools/vite-plugin-svelte-md-option.mjs" -import "./docs-svelte-kit/build-system/build.js" +import "./docs-svelte-kit/build-system/build.mts" +import type { UserConfig } from "vite" -const dirname = path.dirname(new URL(import.meta.url).pathname) +const dirname = path.dirname( + new URL( + // @ts-expect-error -- Cannot change `module` option + import.meta.url, + ).pathname, +) /** @type {import('vite').UserConfig} */ -const config = { +const config: UserConfig = { plugins: [ svelteMd( svelteMdOption({