diff --git a/index.d.ts b/index.d.ts index 5703fb5fd..2b8395cdb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1 +1 @@ -export * from './dist'; +export * from './dist/index.js'; diff --git a/index.js b/index.js index 9368dd397..2b8395cdb 100644 --- a/index.js +++ b/index.js @@ -1,6 +1 @@ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -exports.__esModule = true; -__export(require("./dist")); +export * from './dist/index.js'; diff --git a/index.ts b/index.ts index 5703fb5fd..2b8395cdb 100644 --- a/index.ts +++ b/index.ts @@ -1 +1 @@ -export * from './dist'; +export * from './dist/index.js'; diff --git a/lib/common/index.ts b/lib/common/index.ts index e3fdecaba..fdead4cb7 100644 --- a/lib/common/index.ts +++ b/lib/common/index.ts @@ -1,2 +1,2 @@ -export * from './typeorm.decorators'; -export * from './typeorm.utils'; +export * from './typeorm.decorators.js'; +export * from './typeorm.utils.js'; diff --git a/lib/common/typeorm-compat.ts b/lib/common/typeorm-compat.ts index ac133e2a9..40a1f4870 100644 --- a/lib/common/typeorm-compat.ts +++ b/lib/common/typeorm-compat.ts @@ -1,3 +1,5 @@ +import { createRequire } from 'node:module'; + /** * Runtime compatibility helpers for accessing TypeORM APIs that were * removed in TypeORM v1.0.0 (notably `Connection` and `AbstractRepository`). @@ -17,9 +19,11 @@ * package. Returns `undefined` when the export is not present (e.g. * TypeORM v1.0.0 has removed it) or when the module fails to load. */ +const require = createRequire(import.meta.url); + function resolveTypeormExport(exportName: string): T | undefined { try { - // Using `require` here (rather than a static import) ensures the + // Using `createRequire(import.meta.url)` here (rather than a static import) ensures the // reference is resolved at runtime and is not included in the // emitted type definitions — which is required for forward // compatibility with TypeORM v1 where these symbols no longer exist. diff --git a/lib/common/typeorm.decorators.ts b/lib/common/typeorm.decorators.ts index 1d24ec6f4..59087516a 100644 --- a/lib/common/typeorm.decorators.ts +++ b/lib/common/typeorm.decorators.ts @@ -1,12 +1,12 @@ import { Inject } from '@nestjs/common'; import { DataSource, DataSourceOptions } from 'typeorm'; -import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type'; -import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants'; +import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type.js'; +import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants.js'; import { getDataSourceToken, getEntityManagerToken, getRepositoryToken, -} from './typeorm.utils'; +} from './typeorm.utils.js'; /** * @publicApi diff --git a/lib/common/typeorm.utils.ts b/lib/common/typeorm.utils.ts index 27c2354ab..fe13654c3 100644 --- a/lib/common/typeorm.utils.ts +++ b/lib/common/typeorm.utils.ts @@ -8,10 +8,10 @@ import { EntitySchema, Repository, } from 'typeorm'; -import { CircularDependencyException } from '../exceptions/circular-dependency.exception'; -import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type'; -import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants'; -import { AbstractRepository } from './typeorm-compat'; +import { CircularDependencyException } from '../exceptions/circular-dependency.exception.js'; +import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type.js'; +import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants.js'; +import { AbstractRepository } from './typeorm-compat.js'; const logger = new Logger('TypeOrmModule'); diff --git a/lib/data-source-name.registry.ts b/lib/data-source-name.registry.ts index aa85b1996..d3eb82080 100644 --- a/lib/data-source-name.registry.ts +++ b/lib/data-source-name.registry.ts @@ -1,4 +1,4 @@ -import { DuplicateDataSourceException } from './exceptions/duplicate-data-source.exception'; +import { DuplicateDataSourceException } from './exceptions/duplicate-data-source.exception.js'; /** * Tracks active data source names at runtime in order to prevent multiple diff --git a/lib/entities-metadata.storage.ts b/lib/entities-metadata.storage.ts index 8fcc6fd5a..5d3102dc9 100644 --- a/lib/entities-metadata.storage.ts +++ b/lib/entities-metadata.storage.ts @@ -1,5 +1,5 @@ import { DataSource, DataSourceOptions } from 'typeorm'; -import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type'; +import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type.js'; type DataSourceToken = DataSource | DataSourceOptions | string; diff --git a/lib/exceptions/duplicate-data-source.exception.ts b/lib/exceptions/duplicate-data-source.exception.ts index f95e61424..7f0271126 100644 --- a/lib/exceptions/duplicate-data-source.exception.ts +++ b/lib/exceptions/duplicate-data-source.exception.ts @@ -1,4 +1,4 @@ -import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants'; +import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants.js'; export class DuplicateDataSourceException extends Error { constructor(dataSourceName: string) { diff --git a/lib/index.ts b/lib/index.ts index e33454079..74c3edae9 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,4 @@ -export * from './common'; -export * from './exceptions/duplicate-data-source.exception'; -export * from './interfaces'; -export * from './typeorm.module'; +export * from './common/index.js'; +export * from './exceptions/duplicate-data-source.exception.js'; +export * from './interfaces/index.js'; +export * from './typeorm.module.js'; diff --git a/lib/interfaces/index.ts b/lib/interfaces/index.ts index ada0e27d1..e4726e41c 100644 --- a/lib/interfaces/index.ts +++ b/lib/interfaces/index.ts @@ -1 +1 @@ -export * from './typeorm-options.interface'; +export * from './typeorm-options.interface.js'; diff --git a/lib/interfaces/typeorm-options.interface.ts b/lib/interfaces/typeorm-options.interface.ts index 734a52de4..aaa6cdf5b 100644 --- a/lib/interfaces/typeorm-options.interface.ts +++ b/lib/interfaces/typeorm-options.interface.ts @@ -64,8 +64,10 @@ export type TypeOrmDataSourceFactory = ( /** * @publicApi */ -export interface TypeOrmModuleAsyncOptions - extends Pick { +export interface TypeOrmModuleAsyncOptions extends Pick< + ModuleMetadata, + 'imports' +> { name?: string; useExisting?: Type; useClass?: Type; diff --git a/lib/typeorm-core.module.ts b/lib/typeorm-core.module.ts index 60d7d8dd4..508fe388e 100644 --- a/lib/typeorm-core.module.ts +++ b/lib/typeorm-core.module.ts @@ -11,23 +11,23 @@ import { import { ModuleRef } from '@nestjs/core'; import { defer, lastValueFrom } from 'rxjs'; import { DataSource, DataSourceOptions } from 'typeorm'; -import { Connection } from './common/typeorm-compat'; +import { Connection } from './common/typeorm-compat.js'; import { generateString, getDataSourceName, getDataSourceToken, getEntityManagerToken, handleRetry, -} from './common/typeorm.utils'; -import { DataSourceNameRegistry } from './data-source-name.registry'; -import { EntitiesMetadataStorage } from './entities-metadata.storage'; +} from './common/typeorm.utils.js'; +import { DataSourceNameRegistry } from './data-source-name.registry.js'; +import { EntitiesMetadataStorage } from './entities-metadata.storage.js'; import { TypeOrmDataSourceFactory, TypeOrmModuleAsyncOptions, TypeOrmModuleOptions, TypeOrmOptionsFactory, -} from './interfaces/typeorm-options.interface'; -import { TYPEORM_MODULE_ID, TYPEORM_MODULE_OPTIONS } from './typeorm.constants'; +} from './interfaces/typeorm-options.interface.js'; +import { TYPEORM_MODULE_ID, TYPEORM_MODULE_OPTIONS } from './typeorm.constants.js'; @Global() @Module({}) diff --git a/lib/typeorm.module.ts b/lib/typeorm.module.ts index 3ff7f128a..1cf391a59 100644 --- a/lib/typeorm.module.ts +++ b/lib/typeorm.module.ts @@ -1,14 +1,14 @@ import { DynamicModule, Module } from '@nestjs/common'; import { DataSource, DataSourceOptions } from 'typeorm'; -import { EntitiesMetadataStorage } from './entities-metadata.storage'; -import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type'; +import { EntitiesMetadataStorage } from './entities-metadata.storage.js'; +import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type.js'; import { TypeOrmModuleAsyncOptions, TypeOrmModuleOptions, -} from './interfaces/typeorm-options.interface'; -import { TypeOrmCoreModule } from './typeorm-core.module'; -import { DEFAULT_DATA_SOURCE_NAME } from './typeorm.constants'; -import { createTypeOrmProviders } from './typeorm.providers'; +} from './interfaces/typeorm-options.interface.js'; +import { TypeOrmCoreModule } from './typeorm-core.module.js'; +import { DEFAULT_DATA_SOURCE_NAME } from './typeorm.constants.js'; +import { createTypeOrmProviders } from './typeorm.providers.js'; /** * @publicApi diff --git a/lib/typeorm.providers.ts b/lib/typeorm.providers.ts index 927d38fa2..1d547ed80 100644 --- a/lib/typeorm.providers.ts +++ b/lib/typeorm.providers.ts @@ -1,7 +1,7 @@ import { Provider } from '@nestjs/common'; import { DataSource, DataSourceOptions, getMetadataArgsStorage } from 'typeorm'; -import { getDataSourceToken, getRepositoryToken } from './common/typeorm.utils'; -import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type'; +import { getDataSourceToken, getRepositoryToken } from './common/typeorm.utils.js'; +import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type.js'; export function createTypeOrmProviders( entities?: EntityClassOrSchema[], diff --git a/package.json b/package.json index 220d5f21c..65ae6e659 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,15 @@ "author": "Kamil Mysliwiec", "license": "MIT", "url": "https://github.com/nestjs/typeorm#readme", + "type": "module", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, "scripts": { "build": "rm -rf dist && tsc -p tsconfig.json", "format": "prettier --write \"**/*.ts\"", diff --git a/tsconfig.json b/tsconfig.json index ead587249..9815db5e0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "module": "commonjs", - "moduleResolution": "bundler", + "module": "NodeNext", + "moduleResolution": "NodeNext", "declaration": true, "strict": true, "removeComments": false,