Skip to content

Commit

Permalink
chore: upgrade typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Nov 9, 2024
1 parent 2caaa10 commit ff2835e
Show file tree
Hide file tree
Showing 38 changed files with 335 additions and 340 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"rehype-external-links": "^3.0.0",
"unocss": "^0.61.8",
"vite-plugin-inspect": "^0.8.5",
"vue-tsc": "^2.0.29"
"vue-tsc": "^2.1.10"
},
"dependencies": {
"@docsearch/css": "^3.6.1",
Expand Down
6 changes: 3 additions & 3 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"baseUrl": ".",
"module": "es2020",
"target": "es2020",
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"allowJs": true,
"jsx": "preserve",
Expand All @@ -13,7 +13,7 @@
"noUnusedLocals": true,
"skipLibCheck": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"lib": ["esnext", "DOM"],
"types": [
"@vue-macros/reactivity-transform/macros-global",
"vite-plugin-pwa/client"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"minimist": "^1.2.8",
"pkg-dir": "^8.0.0",
"semver": "^7.6.3",
"typescript": "5.2.2",
"typescript": "^5.6.3",
"vitest": "^2.0.4"
},
"pnpm": {
Expand Down
4 changes: 2 additions & 2 deletions packages/excerpt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"hast-util-to-string": "^3.0.0"
},
"devDependencies": {
"@types/estree": "^1.0.5",
"@types/estree": "^1.0.6",
"@types/estree-jsx": "^1.0.5",
"@types/hast": "^3.0.4",
"iles": "workspace:*",
"tsup": "8.2.4",
"typescript": "5.2.2",
"typescript": "^5.6.3",
"unified": "^11.0.5"
}
}
4 changes: 2 additions & 2 deletions packages/excerpt/src/recma-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { walk } from 'estree-walker'
import type { Node, Statement, ImportSpecifier, FunctionDeclaration, Program } from 'estree-jsx'
import type { Node, Statement, Program } from 'estree-jsx'
import type { Plugin } from 'unified'

import { ArrayExpression, CallExpression, ConditionalExpression, Expression, Identifier, ObjectExpression, Property, VariableDeclaration } from 'estree'
import type { ArrayExpression, ConditionalExpression, Identifier, ObjectExpression, Property, VariableDeclaration } from 'estree'

/**
* A plugin that splits MDXContent into before/after excerpt separator, and
Expand Down
2 changes: 1 addition & 1 deletion packages/feed/src/render-feed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStaticVNode, defineComponent, PropType, defineAsyncComponent, h } from 'vue'
import { createStaticVNode, defineComponent, type PropType, defineAsyncComponent, h } from 'vue'
import { useVueRenderer } from 'iles'
import type { FeedOptions, FeedFormat, FeedItem, Author, Extension, ResolvedItem } from './types'

Expand Down
2 changes: 1 addition & 1 deletion packages/feed/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { VueRenderable } from 'iles'

export type AsyncContent = string | VueRenderable

export { FeedOptions, ResolvedItem, Author, Extension }
export type { FeedOptions, ResolvedItem, Author, Extension }

export interface FeedItem extends Omit<ResolvedItem, 'description' | 'content'> {
description?: AsyncContent
Expand Down
2 changes: 1 addition & 1 deletion packages/headings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"iles": "workspace:*",
"slugo": "^0.4.0",
"tsup": "8.2.4",
"typescript": "5.2.2",
"typescript": "^5.6.3",
"unified": "^11.0.5"
}
}
6 changes: 2 additions & 4 deletions packages/headings/src/headings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { Program, VariableDeclarator } from 'estree'
import type { Pluggable, Plugin } from 'unified'
import type { Data, Parent } from 'unist'
import type { Plugin } from 'unified'
import type { Parent } from 'unist'
import type { IlesModule } from 'iles'

import type { Node } from 'hast'
import { toString } from 'hast-util-to-string'
import { headingRank } from 'hast-util-heading-rank'
import slugo from 'slugo'
Expand Down
2 changes: 1 addition & 1 deletion packages/hydration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"solid-js": "^1.8.19",
"svelte": "^4.2.18",
"tsup": "8.2.4",
"typescript": "5.2.2",
"typescript": "^5.6.3",
"vite": "^5.3.5",
"vue": "^3.4.34"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hydration/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"module": "ESNext",
"target": "es2020",
"lib": ["ESNext", "DOM"],
"module": "esnext",
"target": "esnext",
"lib": ["esnext", "DOM"],
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/hydration/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Options } from 'tsup'
export const tsup: Options = {
clean: true,
dts: true,
target: 'es2020',
target: 'esnext',
splitting: true,
format: ['esm'],
external: [
Expand Down
28 changes: 15 additions & 13 deletions packages/iles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@
"tsconfig.json"
],
"scripts": {
"dev": "rm -rf dist && npm run dev-shared && npm run dev-start",
"dev-start": "run-p dev-client dev-node dev-cjs dev-watch",
"dev-client": "npm run build-client -- --watch",
"dev-node": "npm run build-node -- --watch",
"dev-cjs": "npm run build-cjs -- --watch",
"dev-shared": "node scripts/copyShared",
"dev-watch": "node scripts/watchAndCopy",
"build-node": "tsup --config tsup.config.ts src/node",
"build-cjs": "tsup src/node/publicUtils.ts --config tsup-cjs.config.ts",
"build-client": "rm -rf dist/client && node scripts/copyClient && tsc -p src/client",
"build": "rm -rf dist && node scripts/copyShared && npm run build-client && npm run build-node && npm run build-cjs && node scripts/copyClient",
"dev": "rm -rf dist && npm run dev:shared && npm run dev:start",
"dev:start": "run-p dev:client dev:node dev:cjs dev:watch",
"dev:client": "npm run build:client -- --watch",
"dev:node": "npm run build:node -- --watch",
"dev:cjs": "npm run build:cjs -- --watch",
"dev:shared": "node scripts/copyShared",
"dev:watch": "node scripts/watchAndCopy",
"build": "pnpm build:prepare && pnpm build:client && pnpm build:node && pnpm build:cjs",
"build:prepare": "rm -rf dist && node scripts/copyShared",
"build:client": "vue-tsc --noEmit -p src/client && tsc -p src/client && node scripts/copyClient",
"build:node": "tsup --config tsup.config.ts src/node",
"build:cjs": "tsup src/node/publicUtils.ts --config tsup-cjs.config.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
Expand Down Expand Up @@ -111,8 +112,9 @@
"semver": "^7.6.3",
"tinyglobby": "0.2.6",
"tsup": "8.2.4",
"typescript": "5.2.2",
"typescript": "^5.6.3",
"vfile": "^6.0.2",
"vite-plugin-solid": "^2.10.2"
"vite-plugin-solid": "^2.10.2",
"vue-tsc": "^2.1.10"
}
}
7 changes: 4 additions & 3 deletions packages/iles/scripts/copyClient.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import fs from 'fs-extra'
import { copy } from 'fs-extra'
import { globSync } from 'tinyglobby'

function toDest(file) {
return file.replace(/src\//, 'dist/')
}

globSync(['src/client/**/!(*.ts|tsconfig.json|*.vue)']).forEach((file) => {
fs.copy(file, toDest(file)).catch(() => {})
globSync(['src/client/**']).forEach((file) => {
if (/(\.ts|tsconfig\.json)$/.test(file)) return
copy(file, toDest(file))
})
10 changes: 6 additions & 4 deletions packages/iles/scripts/copyShared.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import fs from 'fs-extra'
import { copy } from 'fs-extra'
import { globSync } from 'tinyglobby'

globSync(['src/shared/**/*.ts']).forEach((file) => {
fs.copy(file, file.replace(/src\/shared\//, 'src/node/')).catch(() => {})
fs.copy(file, file.replace(/src\/shared\//, 'src/client/')).catch(() => {})
globSync(['src/shared/**/*.ts']).forEach(async (file) => {
await Promise.all([
copy(file, file.replace(/^src\/shared\//, 'src/node/')),
copy(file, file.replace(/^src\/shared\//, 'src/client/'))
])
})
28 changes: 14 additions & 14 deletions packages/iles/scripts/watchAndCopy.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import fs from 'fs-extra'
import chokidar from 'chokidar'
import { copy, remove } from 'fs-extra'
import { watch } from 'chokidar'
import { normalizePath } from 'vite'

function toClientAndNode (method, file) {
file = normalizePath(file)
if (method === 'copy') {
fs.copy(file, file.replace(/^src\/shared\//, 'src/node/'))
fs.copy(file, file.replace(/^src\/shared\//, 'src/client/'))
copy(file, file.replace(/^src\/shared\//, 'src/node/'))
copy(file, file.replace(/^src\/shared\//, 'src/client/'))
}
else if (method === 'remove') {
fs.remove(file.replace(/^src\/shared\//, 'src/node/'))
fs.remove(file.replace(/^src\/shared\//, 'src/client/'))
remove(file.replace(/^src\/shared\//, 'src/node/'))
remove(file.replace(/^src\/shared\//, 'src/client/'))
}
}

function toDist (file) {
return file.replace(/^src\//, 'dist/')
return normalizePath(file).replace(/^src\//, 'dist/')
}

// copy shared files to the client and node directory whenever they change.
chokidar
.watch('src/shared/**/*.ts')
watch('src/shared/**/*.ts')
.on('change', file => toClientAndNode('copy', file))
.on('add', file => toClientAndNode('copy', file))
.on('unlink', file => toClientAndNode('remove', file))

// copy non ts files, such as an html or css, to the dist directory whenever
// they change.
chokidar
.watch('src/client/**/!(*.ts|tsconfig.json|*.vue)')
.on('change', file => fs.copy(file, toDist(file)))
.on('add', file => fs.copy(file, toDist(file)))
.on('unlink', file => fs.remove(toDist(file)))
watch('src/client/**/!(*.ts|tsconfig.json)')
.on('change', file => copy(file, toDist(file)))
.on('add', file => copy(file, toDist(file)))
.on('unlink', file => remove(toDist(file)))
1 change: 1 addition & 0 deletions packages/iles/src/client/client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../types/client'
6 changes: 4 additions & 2 deletions packages/iles/src/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"compilerOptions": {
"baseUrl": ".",
"outDir": "../../dist/client",
"paths": {
"iles": ["index.ts"]
}
},
"include": [".", "../../**/*.d.ts", "../../types/shared.d.ts"],
"exclude": ["dist", "../../dist/**/*"]
"include": ["."]
}
6 changes: 4 additions & 2 deletions packages/iles/src/node/plugin/remarkWrapIslands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ function extractImports (nodes: MdxjsEsm[]) {
return imports
}

function importedName (specifier: ImportDeclaration['specifiers'][number]) {
function importedName (specifier: ImportDeclaration['specifiers'][number]): string {
switch (specifier.type) {
case 'ImportDefaultSpecifier': return 'default'
case 'ImportNamespaceSpecifier': return '*'
default: return specifier.imported.name
default:
if ('name' in specifier.imported) return specifier.imported.name
throw Error(`Unpexected literal in import declaration: ${specifier.imported}`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/iles/src/node/plugin/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function wrapIslandsInSFC (config: AppConfig, code: string, filenam
if (scriptClient) { throw new Error(`Vue components with <script client:...> must define a template containing at least one tag. No valid template found in ${filename}`) }
return
}
const sfcRootNode = template.ast as SfcRootNode
const sfcRootNode = template.ast as any as SfcRootNode

const s = new MagicString(code)
const components: ComponentsApi = config.namedPlugins.components.api
Expand Down
5 changes: 3 additions & 2 deletions packages/iles/src/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"lib": ["esnext", "dom", "dom.iterable"]
},
"include": [".", "../../**/*.d.ts", "../../types/shared.d.ts"]
"include": ["."]
}
2 changes: 1 addition & 1 deletion packages/iles/tests/__snapshots__/build.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`building docs site > headers 1`] = `
"/assets/*
Expand Down
2 changes: 1 addition & 1 deletion packages/iles/tests/__snapshots__/site.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`site > with site url 1`] = `
"
Expand Down
8 changes: 4 additions & 4 deletions packages/iles/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"baseUrl": ".",
"module": "es2020",
"target": "es2020",
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"strict": true,
Expand All @@ -11,8 +11,8 @@
"skipLibCheck": true,
"esModuleInterop": true,
"useUnknownInCatchVariables": false,
"lib": ["ESNext", "DOM"],
"types": ["node", "vitest"],
"lib": ["esnext", "DOM"],
"types": ["node", "vite/client", "vitest"],
"paths": {
"src/*": ["src/*"],
"@components/*": ["src/client/app/components/*"],
Expand Down
45 changes: 45 additions & 0 deletions packages/iles/types/client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type {
PageFrontmatter,
PageMeta,
UserSite,
StaticPath,
Router,
RouteLocationNormalizedLoaded,
} from './shared'

declare module 'vue-router' {
interface RouteMeta {
layout?: import('vue').Ref<import('vue').DefineComponent | false>
pathVariants?: import('vue').Ref<StaticPath[]>
pathVariantsPromise?: import('vue').ComputedRef<Promise<StaticPath[]>>
}
}

declare module '@vue/runtime-core' {
export interface ComponentCustomProperties {
/**
* The frontmatter of the current page.
*/
$frontmatter: PageFrontmatter
/**
* Information about the current page, including href and filename.
*/
$meta: PageMeta
/**
* Information about the site as exported in src/site.ts
*/
$site: UserSite
/**
* Normalized current location. See {@link RouteLocationNormalizedLoaded}.
*/
$route: RouteLocationNormalizedLoaded
/**
* {@link Router} instance used by the application.
*/
$router: Router
}
}

declare global {
interface Window {}
}
Loading

0 comments on commit ff2835e

Please sign in to comment.