chore: upgrade moduleResolution to Node16 (#9269)

This commit is contained in:
Harminder Virk
2024-09-24 17:19:20 +05:30
committed by GitHub
parent d721282600
commit 9e711720dd
216 changed files with 981 additions and 2439 deletions
@@ -0,0 +1,17 @@
import { resolveExports } from "./resolve-exports"
/**
* Utility that should be used instead of either await import() or require()
* to avoid bundling issues. That way we have a single place
* where we manage the strategy to dynamically import a module.
*
* This issue arise from migration to Node16 or NodeNext module resolution as well
* as ts-node not being maintained anymore and throwing deprecation warnings.
* all over the place.
*
* @param path
*/
export async function dynamicImport(path: string): Promise<any> {
const module = require(path)
return resolveExports(module)
}
+2
View File
@@ -72,3 +72,5 @@ export * from "./trim-zeros"
export * from "./upper-case-first"
export * from "./validate-handle"
export * from "./wrap-handler"
export * from "./resolve-exports"
export * from "./dynamic-import"
@@ -0,0 +1,6 @@
export function resolveExports(moduleExports) {
if ("default" in moduleExports && "default" in moduleExports.default) {
return resolveExports(moduleExports.default)
}
return moduleExports
}
@@ -1,7 +1,9 @@
import { ModuleServiceInitializeOptions } from "@medusajs/types"
import { Filter as MikroORMFilter } from "@mikro-orm/core"
import { TSMigrationGenerator } from "@mikro-orm/migrations"
import { ModuleServiceInitializeOptions } from "@medusajs/types"
import { isString } from "../../common"
import { FilterDef } from "@mikro-orm/core/typings"
type FilterDef = Parameters<typeof MikroORMFilter>[0]
export class CustomTsMigrationGenerator extends TSMigrationGenerator {
createStatement(sql: string, padLeft: number): string {
@@ -1,7 +1,11 @@
import { EntityClass, EntityProperty } from "@mikro-orm/core/typings"
import { EntityMetadata, EntitySchema, ReferenceType } from "@mikro-orm/core"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import type { FindOneOptions, FindOptions } from "@mikro-orm/core/drivers"
import type {
FindOptions,
EntityClass,
EntityProperty,
FindOneOptions,
} from "@mikro-orm/core"
export const FreeTextSearchFilterKey = "freeTextSearch"
@@ -16,13 +16,13 @@ import {
ReferenceType,
RequiredEntityData,
} from "@mikro-orm/core"
import { FindOptions as MikroOptions } from "@mikro-orm/core/drivers/IDatabaseDriver"
import {
EntityClass,
EntityName,
EntityProperty,
FindOptions as MikroOptions,
FilterQuery as MikroFilterQuery,
} from "@mikro-orm/core/typings"
} from "@mikro-orm/core"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import {
MedusaError,
@@ -8,10 +8,10 @@ import {
Platform,
Reference,
ReferenceType,
SerializeOptions,
SerializationContext,
Utils,
} from "@mikro-orm/core"
import { SerializeOptions } from "@mikro-orm/core/serialization/EntitySerializer"
function isVisible<T extends object>(
meta: EntityMetadata<T>,
@@ -0,0 +1,8 @@
export * from "./apply-searchable"
export * from "./build-indexes"
export * from "./create-big-number-properties"
export * from "./create-default-properties"
export * from "./define-property"
export * from "./define-relationship"
export * from "./parse-entity-name"
export * from "./query-builder"
+3
View File
@@ -1,3 +1,6 @@
export * from "./entity-builder"
export * from "./entity"
export * from "./helpers/entity-builder/index"
export * from "./helpers/create-mikro-orm-entity"
export * from "./relations/index"
export * from "./properties/index"
@@ -0,0 +1,12 @@
export * from "./array"
export * from "./base"
export * from "./big-number"
export * from "./boolean"
export * from "./date-time"
export * from "./enum"
export * from "./id"
export * from "./json"
export * from "./nullable"
export * from "./number"
export * from "./primary-key"
export * from "./text"
@@ -1,5 +1,5 @@
import { BaseRelationship } from "./base"
import { NullableModifier } from "./nullable"
import { RelationNullableModifier } from "./nullable"
export class BelongsTo<T> extends BaseRelationship<T> {
type = "belongsTo" as const
@@ -12,6 +12,6 @@ export class BelongsTo<T> extends BaseRelationship<T> {
* Apply nullable modifier on the schema
*/
nullable() {
return new NullableModifier<T, BelongsTo<T>>(this)
return new RelationNullableModifier<T, BelongsTo<T>>(this)
}
}
@@ -1,5 +1,5 @@
import { BaseRelationship } from "./base"
import { NullableModifier } from "./nullable"
import { RelationNullableModifier } from "./nullable"
/**
* HasOne relationship defines a relationship between two entities
@@ -22,6 +22,6 @@ export class HasOne<T> extends BaseRelationship<T> {
* Apply nullable modifier on the schema
*/
nullable() {
return new NullableModifier<T, HasOne<T>>(this)
return new RelationNullableModifier<T, HasOne<T>>(this)
}
}
@@ -0,0 +1,6 @@
export * from "./base"
export * from "./belongs-to"
export * from "./has-many"
export * from "./has-one"
export * from "./many-to-many"
export * from "./nullable"
@@ -6,7 +6,7 @@ const IsNullableModifier = Symbol.for("isNullableModifier")
/**
* Nullable modifier marks a schema node as nullable
*/
export class NullableModifier<T, Relation extends RelationshipType<T>>
export class RelationNullableModifier<T, Relation extends RelationshipType<T>>
implements RelationshipType<T | null>
{
[IsNullableModifier]: true = true;
@@ -14,7 +14,7 @@ export class NullableModifier<T, Relation extends RelationshipType<T>>
static isNullableModifier<T>(
modifier: any
): modifier is NullableModifier<T, any> {
): modifier is RelationNullableModifier<T, any> {
return !!modifier?.[IsNullableModifier]
}
@@ -17,3 +17,5 @@ export * from "./mikro-orm-cli-config-builder"
export * from "./module"
export * from "./query-context"
export * from "./query-filter"
export * from "./types/links-config"
export * from "./types/medusa-service"
@@ -9,8 +9,7 @@ import {
PerformedActions,
UpsertWithReplaceConfig,
} from "@medusajs/types"
import { EntitySchema } from "@mikro-orm/core"
import { EntityClass } from "@mikro-orm/core/typings"
import type { EntitySchema, EntityClass } from "@mikro-orm/core"
import {
doNotForceTransaction,
isDefined,
@@ -4,6 +4,7 @@ import { EOL } from "os"
import { resolve } from "path"
import { mikroOrmCreateConnection } from "../../dal"
import { loadDatabaseConfig } from "../load-module-database-config"
import { dynamicImport } from "../../common"
/**
* Utility function to build a seed script that will insert the seed data.
@@ -42,12 +43,14 @@ export function buildSeedScript({
const logger_ = (logger ?? console) as unknown as Logger
logger_.info(`Loading seed data from ${path}...`)
const dataSeed = await import(resolve(process.cwd(), path)).catch((e) => {
logger_.error(
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following productCategoriesData, productsData, variantsData.${EOL}${e}`
)
throw e
})
const dataSeed = await dynamicImport(resolve(process.cwd(), path)).catch(
(e) => {
logger_.error(
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following productCategoriesData, productsData, variantsData.${EOL}${e}`
)
throw e
}
)
const dbData = loadDatabaseConfig(moduleName, options)!
const entities = Object.values(models) as unknown as EntitySchema[]
@@ -1,12 +1,12 @@
import { MikroORMOptions } from "@mikro-orm/core/utils/Configuration"
import { DmlEntity, toMikroOrmEntities } from "../dml"
import { CustomTsMigrationGenerator } from "../dal"
import type {
AnyEntity,
EntityClass,
EntitySchema,
MikroORMOptions,
EntityClassGroup,
} from "@mikro-orm/core/typings"
import type { EntitySchema } from "@mikro-orm/core/metadata/EntitySchema"
} from "@mikro-orm/core"
import { kebabCase } from "../common"
type Options = Partial<Omit<MikroORMOptions, "entities" | "entitiesTs">> & {