chore: merge packages into tuono

This commit is contained in:
Valerio Ageno
2024-05-25 14:56:55 +02:00
parent ee092194d1
commit 1d87a78393
65 changed files with 26 additions and 552 deletions
-44
View File
@@ -1,44 +0,0 @@
{
"name": "tuono-router",
"version": "0.0.1",
"description": "",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
},
"./package.json": "./package.json"
},
"sideEffects": false,
"scripts": {
"dev": "vite build --watch",
"build": "vite build",
"lint": "eslint --ext .ts,.tsx ./src -c ../../.eslintrc",
"format": "prettier -u --write '**/*'",
"test": "vitest --watch=false",
"types": "tsc --noEmit"
},
"peerDependencies": {
"react": ">=16.3.0",
"react-dom": ">=16.3.0"
},
"type": "module",
"types": "dist/esm/index.d.ts",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"jsdom": "^24.0.0"
},
"dependencies": {
"zustand": "4.4.7"
}
}
@@ -1,34 +0,0 @@
import { expectTypeOf, test } from 'vitest'
import {
RouterProvider,
createRootRoute,
createRoute,
createRouter,
} from '../../src'
const rootRoute = createRootRoute()
const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
})
const invoicesRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/invoices',
})
const routeTree = rootRoute.addChildren([invoicesRoute, indexRoute])
const defaultRouter = createRouter({
routeTree,
})
type DefaultRouter = typeof defaultRouter
test('can pass default router to the provider', () => {
expectTypeOf(RouterProvider).parameter(0).toMatchTypeOf<{
router: DefaultRouter
routeTree?: DefaultRouter['routeTree']
}>()
})
-28
View File
@@ -1,28 +0,0 @@
/* eslint-disable */
import { describe, it, expect } from 'vitest'
import { getRouteApi, createRoute } from '../src'
describe('getRouteApi', () => {
it('should have the useRouteContext hook', () => {
const api = getRouteApi('foo')
expect(api.useRouteContext).toBeDefined()
})
it('should have the useParams hook', () => {
const api = getRouteApi('foo')
expect(api.useParams).toBeDefined()
})
})
describe('createRoute has the same hooks as getRouteApi', () => {
const routeApi = getRouteApi('foo')
const hookNames = Object.keys(routeApi).filter((key) => key.startsWith('use'))
const route = createRoute({} as any)
it.each(hookNames.map((name) => [name]))(
'should have the "%s" hook defined',
(hookName) => {
expect(route[hookName as keyof typeof route]).toBeDefined()
},
)
})
-7
View File
@@ -1,7 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"jsx": "react-jsx",
},
"include": ["src", "tests", "vite.config.ts"],
}
-20
View File
@@ -1,20 +0,0 @@
import { defineConfig, mergeConfig } from 'vitest/config'
import { tanstackBuildConfig } from '@tanstack/config/build'
import react from '@vitejs/plugin-react'
const config = defineConfig({
plugins: [react()],
test: {
name: 'react-router',
watch: false,
environment: 'jsdom',
},
})
export default mergeConfig(
config,
tanstackBuildConfig({
entry: './src/index.tsx',
srcDir: './src',
}),
)
@@ -1 +0,0 @@
dist/
-48
View File
@@ -1,48 +0,0 @@
# Router generator
This package handle the creation of the routes.
Basically collects and manages them in a single entry point file.
## Generated route file
Currently the generator file is very similar to `@tanstack/router` one but since it does not need the same
configurability is up to strong updates.
```tsx
// This file is auto-generated by Tuono
import { Route as rootRoute } from './routes/__root'
import { Route as AboutImport } from './routes/about'
import { Route as IndexImport } from './routes/index'
// Create/Update Routes
const AboutRoute = AboutImport.update({
path: '/about',
getParentRoute: () => rootRoute,
} as any)
const IndexRoute = IndexImport.update({
path: '/',
getParentRoute: () => rootRoute,
} as any)
// Populate the FileRoutesByPath interface
declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/': {
preLoaderRoute: typeof IndexImport
parentRoute: typeof rootRoute
}
'/about': {
preLoaderRoute: typeof AboutImport
parentRoute: typeof rootRoute
}
}
}
// Create and export the route tree
export const routeTree = rootRoute.addChildren([IndexRoute, AboutRoute])
```
@@ -1,41 +0,0 @@
{
"name": "tuono-routes-generator",
"version": "0.1.0",
"description": "",
"scripts": {
"dev": "vite build --watch",
"build": "vite build",
"lint": "eslint --ext .ts,.tsx ./src -c ../../.eslintrc",
"format": "prettier -u --write '**/*'",
"test": "vitest --watch=false",
"types": "tsc --noEmit"
},
"keywords": [],
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
},
"./package.json": "./package.json"
},
"sideEffects": false,
"files": [
"dist",
"src"
],
"dependencies": {
"prettier": "^3.2.4"
},
"type": "module",
"types": "dist/esm/index.d.ts",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"author": "Valerio Ageno",
"license": "MIT"
}
@@ -1,41 +0,0 @@
import fs from 'fs/promises'
import { describe, it, expect } from 'vitest'
import { routeGenerator } from '../src'
function makeFolderDir(folder: string) {
return process.cwd() + `/tests/generator/${folder}`
}
async function getRouteTreeFileText(folder: string) {
const dir = makeFolderDir(folder)
return await fs.readFile(dir + '/routeTree.gen.ts', 'utf-8')
}
async function getExpectedRouteTreeFileText(folder: string) {
const dir = makeFolderDir(folder)
const location = dir + '/routeTree.expected.ts'
return await fs.readFile(location, 'utf-8')
}
describe('generator works', async () => {
const folderNames = await fs.readdir(process.cwd() + '/tests/generator')
it.each(folderNames.map((folder) => [folder]))(
'should wire-up the routes for a "%s" tree',
async (folderName) => {
const currentFolder = `${process.cwd()}/tests/generator/${folderName}`
await routeGenerator({
folderName: `${currentFolder}/routes`,
generatedRouteTree: `${currentFolder}/routeTree.gen.ts`,
})
const [expectedRouteTree, generatedRouteTree] = await Promise.all([
getExpectedRouteTreeFileText(folderName),
getRouteTreeFileText(folderName),
])
expect(generatedRouteTree).equal(expectedRouteTree)
},
)
})
@@ -1,48 +0,0 @@
// This file is auto-generated by Tuono
import { createRoute } from 'tuono'
import RootImport from './routes/__root'
import AboutImport from './routes/about'
import IndexImport from './routes/index'
import PostsIndexImport from './routes/posts/index'
import PostsPostSlugImport from './routes/posts/post-slug'
const rootRoute = createRoute({ isRoot: true, component: RootImport })
const About = createRoute({ component: AboutImport })
const Index = createRoute({ component: IndexImport })
const PostsIndex = createRoute({ component: PostsIndexImport })
const PostsPostSlug = createRoute({ component: PostsPostSlugImport })
// Create/Update Routes
const AboutRoute = About.update({
path: '/about',
getParentRoute: () => rootRoute,
} as any)
const IndexRoute = Index.update({
path: '/',
getParentRoute: () => rootRoute,
} as any)
const PostsIndexRoute = PostsIndex.update({
path: '/posts/',
getParentRoute: () => rootRoute,
} as any)
const PostsPostSlugRoute = PostsPostSlug.update({
path: '/posts/post-slug',
getParentRoute: () => rootRoute,
} as any)
// Create and export the route tree
export const routeTree = rootRoute.addChildren([
IndexRoute,
AboutRoute,
PostsPostSlugRoute,
PostsIndexRoute,
])
@@ -1,5 +0,0 @@
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/about')({
component: () => <div>Hello /about!</div>,
})
@@ -1,29 +0,0 @@
// This file is auto-generated by Tuono
import { createRoute } from 'tuono'
import RootImport from './routes/__root'
import AboutImport from './routes/about'
import IndexImport from './routes/index'
const rootRoute = createRoute({ isRoot: true, component: RootImport })
const About = createRoute({ component: AboutImport })
const Index = createRoute({ component: IndexImport })
// Create/Update Routes
const AboutRoute = About.update({
path: '/about',
getParentRoute: () => rootRoute,
} as any)
const IndexRoute = Index.update({
path: '/',
getParentRoute: () => rootRoute,
} as any)
// Create and export the route tree
export const routeTree = rootRoute.addChildren([IndexRoute, AboutRoute])
@@ -1,30 +0,0 @@
// This file is auto-generated by Tuono
import { createRoute } from 'tuono'
import RootImport from './routes/__root'
import AboutImport from './routes/about'
import IndexImport from './routes/index'
const rootRoute = createRoute({ isRoot: true, component: RootImport })
const About = createRoute({ component: AboutImport })
const Index = createRoute({ component: IndexImport })
// Create/Update Routes
const AboutRoute = About.update({
path: '/about',
getParentRoute: () => rootRoute,
} as any)
const IndexRoute = Index.update({
path: '/',
getParentRoute: () => rootRoute,
hasHandler: true,
} as any)
// Create and export the route tree
export const routeTree = rootRoute.addChildren([IndexRoute, AboutRoute])
@@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "vite.config.ts"]
}
@@ -1,12 +0,0 @@
import { defineConfig, mergeConfig } from 'vitest/config'
import { tanstackBuildConfig } from '@tanstack/config/build'
const config = defineConfig({})
export default mergeConfig(
config,
tanstackBuildConfig({
entry: './src/index.ts',
srcDir: './src',
}),
)
-2
View File
@@ -1,2 +0,0 @@
dist/
tests/snapshots
-5
View File
@@ -1,5 +0,0 @@
# [Tuono] Vite FS Router
> Strongly inspired by [@tanstack/router/router-vite-plugin](https://github.com/TanStack/router/tree/main/packages/router-vite-plugin)
This is the [vite](https://vitejs.dev/) plugin that automatically handles the file system routing.
-55
View File
@@ -1,55 +0,0 @@
{
"name": "tuono-vite",
"version": "0.0.1",
"description": "",
"main": "dist/cjs/index.cjs",
"types": "dist/esm/index.d.ts",
"module": "dist/esm/index.js",
"scripts": {
"dev": "vite build --watch",
"build": "vite build",
"lint": "eslint --ext .ts,.tsx ./src -c ../../.eslintrc",
"format": "prettier -u --write '**/*'",
"test": "vitest --typecheck --watch=false",
"types": "tsc --noEmit"
},
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
},
"./package.json": "./package.json"
},
"files": [
"dist",
"src/**"
],
"sideEffects": false,
"keywords": [],
"type": "module",
"author": "Valerio Ageno",
"license": "MIT",
"dependencies": {
"@babel/core": "^7.24.4",
"@babel/generator": "^7.23.6",
"@babel/plugin-syntax-jsx": "^7.24.1",
"@babel/plugin-syntax-typescript": "^7.24.1",
"@babel/plugin-transform-react-jsx": "^7.23.4",
"@babel/plugin-transform-typescript": "^7.24.1",
"@babel/template": "^7.24.0",
"@babel/traverse": "^7.24.1",
"@babel/types": "^7.24.0",
"@types/babel__core": "^7.20.5",
"@types/node": "^20.12.7",
"tuono-routes-generator": "workspace:*"
},
"devDependencies": {
"@types/babel-traverse": "^6.25.10"
}
}
-33
View File
@@ -1,33 +0,0 @@
import { readFile, readdir } from 'fs/promises'
import path from 'path'
import { expect, test } from 'vitest'
import { makeCompile, splitFile } from '../src/compiler'
import { SPLIT_PREFIX } from '../src/constants'
async function splitTestFile(opts: { file: string }): Promise<void> {
const code = (
await readFile(path.resolve(__dirname, `./test-files/${opts.file}`))
).toString()
const filename = opts.file.replace(__dirname, '')
const result = await splitFile({
code,
compile: makeCompile({
root: './test-files',
}),
filename: `${filename}?${SPLIT_PREFIX}`,
})
await expect(result.code).toMatchFileSnapshot(
`./snapshots/${filename.replace('.tsx', '')}?split.tsx`,
)
}
test('it compiles and splits', async (): Promise<void> => {
// get the list of files from the /test-files directory
const files = await readdir(path.resolve(__dirname, './test-files'))
for (const file of files) {
await splitTestFile({ file })
}
})
@@ -1,3 +0,0 @@
export const ImportedRoute = (): JSX.Element => {
return <h1>Imported route</h1>
}
@@ -1,3 +0,0 @@
export default function Route(): JSX.Element {
return <h1>Test route</h1>;
}
@@ -1,4 +0,0 @@
function PostsRoute() {
return <h1>Post route</h1>;
}
export default PostsRoute;
@@ -1,2 +0,0 @@
import { ImportedRoute } from '../shared/imported';
export default ImportedRoute;
@@ -1,5 +0,0 @@
import * as React from 'react'
export default function Route(): JSX.Element {
return <h1>Test route</h1>
}
@@ -1,7 +0,0 @@
import * as React from 'react'
function PostsRoute() {
return <h1>Post route</h1>
}
export default PostsRoute
@@ -1,4 +0,0 @@
import * as React from 'react'
import { ImportedRoute } from '../shared/imported'
export default ImportedRoute
-8
View File
@@ -1,8 +0,0 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "vite.config.ts", "tests"],
"exclude": ["tests/test-files/**", "tests/snapshots/**"],
"compilerOptions": {
"jsx": "react"
}
}
-13
View File
@@ -1,13 +0,0 @@
import { defineConfig, mergeConfig } from 'vitest/config'
import { tanstackBuildConfig } from '@tanstack/config/build'
const config = defineConfig({})
export default mergeConfig(
config,
tanstackBuildConfig({
entry: './src/index.ts',
srcDir: './src',
exclude: ['./src/tests/'],
}),
)
+1
View File
@@ -0,0 +1 @@
# Tuono
+21 -3
View File
@@ -48,11 +48,29 @@
"README.md",
"bin/**"
],
"peerDependencies": {
"react": ">=16.3.0",
"react-dom": ">=16.3.0"
},
"dependencies": {
"@babel/core": "^7.24.4",
"@babel/generator": "^7.23.6",
"@babel/plugin-syntax-jsx": "^7.24.1",
"@babel/plugin-syntax-typescript": "^7.24.1",
"@babel/plugin-transform-react-jsx": "^7.23.4",
"@babel/plugin-transform-typescript": "^7.24.1",
"@babel/template": "^7.24.0",
"@babel/traverse": "^7.24.1",
"@babel/types": "^7.24.0",
"@types/babel__core": "^7.20.5",
"@types/node": "^20.12.7",
"@vitejs/plugin-react-swc": "^3.7.0",
"tuono-router": "workspace:*",
"tuono-vite": "workspace:*",
"vite": "^5.2.11"
"prettier": "^3.2.4",
"vite": "^5.2.11",
"zustand": "4.4.7"
},
"devDependencies": {
"@types/babel-traverse": "^6.25.10"
},
"sideEffects": false,
"keywords": [],
+1 -1
View File
@@ -1,6 +1,6 @@
import { build, createServer } from 'vite'
import react from '@vitejs/plugin-react-swc'
import { ViteFsRouter } from 'tuono-vite'
import { ViteFsRouter } from './tuono-vite-plugin'
const BASE_CONFIG = {
silent: true,
@@ -1,5 +1,5 @@
import { fileURLToPath, pathToFileURL } from 'url'
import { routeGenerator } from 'tuono-routes-generator'
import { routeGenerator } from '../routes-generator'
import { normalize } from 'path'
// eslint-disable-next-line sort-imports
+1 -1
View File
@@ -4,6 +4,6 @@ import {
createRouter,
Link,
RouterProvider,
} from 'tuono-router'
} from './router'
export { createRoute, createRootRoute, createRouter, Link, RouterProvider }
@@ -3,6 +3,7 @@ declare global {
__TUONO_SSR__PROPS__: any
}
}
export { RouterProvider } from './components/RouterProvider'
export { default as Link } from './components/Link'
export { createRouter } from './router'