Repository: payloadcms/payload
File: packages/drizzle/src/utilities/blocksToJsonMigrator.ts (TypeScript)

Code before:
      this.adapter.payload.logger.info(
        `Temp folder preserved at ${this.tempFolderPath} (clearBatches: false)`,
      )
    }
  }

  setTempFolder(tempFolderPath: string): void {
    this.tempFolderPath = tempFolderPath
  }

  async updatePayloadConfigFile(): Promise<void> {
    let configPath: string

    try {
      configPath = findConfig()
    } catch {
      this.adapter.payload.logger.info(
        'updatePayloadConfigFile failed - could not find the payload config. Please set the blocksAsJSON DB adapter property manually to "true"',
      )
      return
    }

    const configFile = readFileSync(configPath, 'utf-8')

    // eslint-disable-next-line @typescript-eslint/consistent-type-imports
    const ts = await dynamicImport<typeof import('typescript')>('typescript')

    const source = ts.createSourceFile(configPath, configFile, ts.ScriptTarget.ESNext)

    let hadChanges = false

    const result = ts.transform(source, [
      (ctx) => (sourceFile) => {
        const factory = ctx.factory

        const visit: ts.Visitor = (node) => {
          if (
            ts.isPropertyAssignment(node) &&
            ts.isIdentifier(node.name) &&
            node.name.text === 'db' &&
            ts.isCallExpression(node.initializer) &&
            node.initializer.arguments.length > 0 &&
            ts.isObjectLiteralExpression(node.initializer.arguments[0])
          ) {
            const call = node.initializer
            const obj = node.initializer.arguments[0]

            const filteredProps = obj.properties.filter((prop) => {
              if (!ts.isPropertyAssignment(prop)) {
                return true
              }

Review comment (suggestion):
Since you have `import type ts from 'typescript'` at the top, could just pass that as a generic. I'm scared that `typeof import` behaves differently in terms of type stripping than type imports

Code after:
      this.adapter.payload.logger.info(
        `Temp folder preserved at ${this.tempFolderPath} (clearBatches: false)`,
      )
    }
  }

  setTempFolder(tempFolderPath: string): void {
    this.tempFolderPath = tempFolderPath
  }

  async updatePayloadConfigFile(): Promise<void> {
    let configPath: string

    try {
      configPath = findConfig()
    } catch {
      this.adapter.payload.logger.info(
        'updatePayloadConfigFile failed - could not find the payload config. Please set the blocksAsJSON DB adapter property manually to "true"',
      )
      return
    }

    const configFile = readFileSync(configPath, 'utf-8')

    const ts = await dynamicImport<typeof tsTypes>('typescript')

    const source = ts.createSourceFile(configPath, configFile, ts.ScriptTarget.ESNext)

    let hadChanges = false

    const result = ts.transform(source, [
      (ctx) => (sourceFile) => {
        const factory = ctx.factory

        const visit: tsTypes.Visitor = (node) => {
          if (
            ts.isPropertyAssignment(node) &&
            ts.isIdentifier(node.name) &&
            node.name.text === 'db' &&
            ts.isCallExpression(node.initializer) &&
            node.initializer.arguments.length > 0 &&
            ts.isObjectLiteralExpression(node.initializer.arguments[0])
          ) {
            const call = node.initializer
            const obj = node.initializer.arguments[0]

            const filteredProps = obj.properties.filter((prop) => {
              if (!ts.isPropertyAssignment(prop)) {
                return true
              }