diff --git a/.npmignore b/.npmignore index 905aa28..eab5ee3 100644 --- a/.npmignore +++ b/.npmignore @@ -14,3 +14,4 @@ renovate.json node_modules tsconfig*.json !dist/**/* +dist/example diff --git a/example/multiple-modules/app.module.ts b/example/multiple-modules/app.module.ts deleted file mode 100644 index f69b581..0000000 --- a/example/multiple-modules/app.module.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Module } from '@nestjs/common' -import { Feature1Module } from './feature1/feature1.module' -import { Feature2Module } from './feature2/feature2.module' - -@Module({ - imports: [Feature1Module, Feature2Module], -}) -export class AppModule {} diff --git a/example/multiple-modules/feature1/feature1.module.ts b/example/multiple-modules/feature1/feature1.module.ts deleted file mode 100644 index e9e8b7c..0000000 --- a/example/multiple-modules/feature1/feature1.module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Module } from '@nestjs/common' -import { resolve } from 'path' -import { TsxViewsModule } from '../../../src/tsx-views.module' -import { Feature1Controller } from './feature1.controller' - -@Module({ - imports: [ - TsxViewsModule.register({ - viewsDirectory: resolve(__dirname, './views'), - prettify: true, - - forRoutes: [Feature1Controller], - }), - ], - controllers: [Feature1Controller], -}) -export class Feature1Module {} diff --git a/example/multiple-modules/feature2/feature2.module.ts b/example/multiple-modules/feature2/feature2.module.ts deleted file mode 100644 index d82d7e7..0000000 --- a/example/multiple-modules/feature2/feature2.module.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Module } from '@nestjs/common' -import { resolve } from 'path' -import { TsxViewsModule } from '../../../src/tsx-views.module' -import { Feature2Controller } from './feature2.controller' - -@Module({ - imports: [ - TsxViewsModule.register({ - viewsDirectory: resolve(__dirname, './views'), - forRoutes: [Feature2Controller], - }), - ], - controllers: [Feature2Controller], -}) -export class Feature2Module {} diff --git a/index.ts b/index.ts deleted file mode 100644 index 6f39cd4..0000000 --- a/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './src' diff --git a/package.json b/package.json index bcd4a40..db5b82c 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "nestjs-tsx-views", - "version": "1.2.6", + "version": "2.0.0-beta.0", "main": "dist/index.js", - "types": "dist/index.d.ts", "description": "Server-side JSX/TSX rendering for your NestJS application 🚀", "author": "Philipp Busse", + "type": "module", "bugs": { "url": "https://github.com/pmb0/nestjs-tsx-views/issues" }, @@ -43,7 +43,7 @@ "@types/node": "^16", "@types/react": "^18.0.28", "cross-fetch": "^3.1.4", - "express-tsx-views": "^1.3.1", + "express-tsx-views": "^2.0.0-beta.1", "graphql": "^15.5.1", "husky": "^7.0.0", "jest": "^27.0.0", @@ -56,13 +56,13 @@ "semantic-release": "^18.0.0", "ts-jest": "^27.0.0", "ts-node": "^10.1.0", - "typescript": "^4.0.0" + "typescript": "^5.1.6" }, "peerDependencies": { "@nestjs/common": "*", "@nestjs/core": "*", "express": "^4.17.1", - "express-tsx-views": ">= 1.3.1", + "express-tsx-views": ">= 2.0.0-beta.0", "react": "*", "reflect-metadata": "*" }, @@ -72,11 +72,11 @@ "clean": "rimraf dist", "lint": "eslint --cache .", "prebuild": "yarn clean", - "start:basic": "nodemon --exec ts-node --files example/basic/main.ts", - "start:graphql": "nodemon --exec ts-node --files example/graphql/main.ts", - "start:multiple-modules": "nodemon --exec ts-node --files example/multiple-modules/main.ts", + "start:basic": "nodemon dist/example/basic/main.ts", + "start:graphql": "nodemon dist/example/graphql/main.ts", + "start:multiple-modules": "nodemon dist/example/multiple-modules/main.ts", "test": "jest", - "_postinstall": "is-ci || husky install", + "postinstall": "is-ci || husky install", "prepublish": "pinst --disable", "postpublish": "pinst --enable" }, diff --git a/example/basic/app.controller.ts b/src/example/basic/app.controller.ts similarity index 78% rename from example/basic/app.controller.ts rename to src/example/basic/app.controller.ts index de9133f..b7ba828 100644 --- a/example/basic/app.controller.ts +++ b/src/example/basic/app.controller.ts @@ -1,7 +1,7 @@ import { Controller, Get, Render } from '@nestjs/common' -import { TsxViewsService } from '../../src/tsx-views.service' -import { MyContext } from './views/my-context' -import { MyViewProps } from './views/my-view' +import { TsxViewsService } from '../../index.js' +import { MyContext } from './views/my-context.js' +import { MyViewProps } from './views/my-view.js' @Controller() export class AppController { diff --git a/example/basic/app.module.ts b/src/example/basic/app.module.ts similarity index 53% rename from example/basic/app.module.ts rename to src/example/basic/app.module.ts index beddeb7..b7af4cb 100644 --- a/example/basic/app.module.ts +++ b/src/example/basic/app.module.ts @@ -1,16 +1,18 @@ import { Module } from '@nestjs/common' +import { fileURLToPath, URL } from 'node:url' import { resolve } from 'path' -import { TsxViewsModule } from '../../src' -import { AppController } from './app.controller' +import { TsxViewsModule } from '../../index.js' +import { AppController } from './app.controller.js' + +const dirname = fileURLToPath(new URL('.', import.meta.url)) @Module({ imports: [ TsxViewsModule.registerAsync({ useFactory: () => ({ - viewsDirectory: resolve(__dirname, './views'), + viewsDirectory: resolve(dirname, './views'), prettify: true, exclude: ['/throws-exception'], - forRoutes: [AppController], }), }), ], diff --git a/example/basic/main.ts b/src/example/basic/main.ts similarity index 51% rename from example/basic/main.ts rename to src/example/basic/main.ts index ecbf04f..45cbf73 100644 --- a/example/basic/main.ts +++ b/src/example/basic/main.ts @@ -1,11 +1,12 @@ import { NestFactory } from '@nestjs/core' -import { AppModule } from './app.module' +import { AppModule } from './app.module.js' const DEFAULT_PORT = 3000 async function bootstrap() { const app = await NestFactory.create(AppModule) - await app.listenAsync(process.env.PORT || DEFAULT_PORT) + await app.listen(process.env.PORT || DEFAULT_PORT) + console.log(`Application is running on: ${await app.getUrl()}`) } void bootstrap() diff --git a/example/basic/views/layouts/main.tsx b/src/example/basic/views/layouts/main.tsx similarity index 100% rename from example/basic/views/layouts/main.tsx rename to src/example/basic/views/layouts/main.tsx diff --git a/example/basic/views/my-context.tsx b/src/example/basic/views/my-context.tsx similarity index 100% rename from example/basic/views/my-context.tsx rename to src/example/basic/views/my-context.tsx diff --git a/example/basic/views/my-view.tsx b/src/example/basic/views/my-view.tsx similarity index 81% rename from example/basic/views/my-view.tsx rename to src/example/basic/views/my-view.tsx index d9792ac..d785197 100644 --- a/example/basic/views/my-view.tsx +++ b/src/example/basic/views/my-view.tsx @@ -1,6 +1,6 @@ import React, { ReactElement, useContext } from 'react' -import { MainLayout } from './layouts/main' -import { MyContext } from './my-context' +import { MainLayout } from './layouts/main.js' +import { MyContext } from './my-context.js' export interface MyViewProps { name: string diff --git a/example/graphql/app.controller.ts b/src/example/graphql/app.controller.ts similarity index 89% rename from example/graphql/app.controller.ts rename to src/example/graphql/app.controller.ts index de1b3f9..97e5fba 100644 --- a/example/graphql/app.controller.ts +++ b/src/example/graphql/app.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get, Render } from '@nestjs/common' -import { MyViewProps } from './views/my-view' +import { MyViewProps } from './views/my-view.js' @Controller() export class AppController { diff --git a/example/graphql/app.module.ts b/src/example/graphql/app.module.ts similarity index 66% rename from example/graphql/app.module.ts rename to src/example/graphql/app.module.ts index d1a8c4d..1588040 100644 --- a/example/graphql/app.module.ts +++ b/src/example/graphql/app.module.ts @@ -1,16 +1,21 @@ -import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client' +import { InMemoryCache } from '@apollo/client/cache/index.js' +import { ApolloClient } from '@apollo/client/core/index.js' +import { createHttpLink } from '@apollo/client/link/http/index.js' import { Module } from '@nestjs/common' import { fetch } from 'cross-fetch' -import { ApolloRenderMiddleware } from 'express-tsx-views/dist/apollo' +import { ApolloRenderMiddleware } from 'express-tsx-views/dist/apollo.js' +import { fileURLToPath, URL } from 'node:url' import { resolve } from 'path' -import { TsxViewsModule } from '../../src' -import { AppController } from './app.controller' +import { TsxViewsModule } from '../../index.js' +import { AppController } from './app.controller.js' + +const dirname = fileURLToPath(new URL('.', import.meta.url)) @Module({ imports: [ TsxViewsModule.registerAsync({ useFactory: (apollo: ApolloClient) => ({ - viewsDirectory: resolve(__dirname, './views'), + viewsDirectory: resolve(dirname, './views'), prettify: true, exclude: ['/throws-exception'], forRoutes: [AppController], diff --git a/example/multiple-modules/main.ts b/src/example/graphql/main.ts similarity index 63% rename from example/multiple-modules/main.ts rename to src/example/graphql/main.ts index ecbf04f..e431897 100644 --- a/example/multiple-modules/main.ts +++ b/src/example/graphql/main.ts @@ -1,11 +1,11 @@ import { NestFactory } from '@nestjs/core' -import { AppModule } from './app.module' +import { AppModule } from './app.module.js' const DEFAULT_PORT = 3000 async function bootstrap() { const app = await NestFactory.create(AppModule) - await app.listenAsync(process.env.PORT || DEFAULT_PORT) + await app.listen(process.env.PORT || DEFAULT_PORT) } void bootstrap() diff --git a/example/graphql/views/layouts/main.tsx b/src/example/graphql/views/layouts/main.tsx similarity index 100% rename from example/graphql/views/layouts/main.tsx rename to src/example/graphql/views/layouts/main.tsx diff --git a/example/graphql/views/my-view.tsx b/src/example/graphql/views/my-view.tsx similarity index 75% rename from example/graphql/views/my-view.tsx rename to src/example/graphql/views/my-view.tsx index 4c91eac..0feae0f 100644 --- a/example/graphql/views/my-view.tsx +++ b/src/example/graphql/views/my-view.tsx @@ -1,6 +1,7 @@ -import { gql, useQuery } from '@apollo/client' +import { gql } from '@apollo/client/core/index.js' +import { useQuery } from '@apollo/client/react/hooks/index.js' import React, { ReactElement } from 'react' -import { MainLayout } from './layouts/main' +import { MainLayout } from './layouts/main.js' export interface Film { id: string @@ -41,6 +42,8 @@ const MyView = (props: MyViewProps): ReactElement => { return (

Films:

+ {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */} + {/* @ts-ignore */} {data?.allFilms.films.map((film) => (