Merge pull request #29656 from overleaf/revert-29521-ar-models-es-conversion
Revert "[web] Convert models and self-referential test files to ESM " GitOrigin-RevId: 5455cccbb513bd9ca36ce526ff1553065f83d233
This commit is contained in:
@@ -3,7 +3,7 @@ import minimist from 'minimist'
|
||||
import { parse } from 'csv'
|
||||
import Stream from 'node:stream/promises'
|
||||
import { ObjectId } from '../app/src/infrastructure/mongodb.js'
|
||||
import { Subscription } from '../app/src/models/Subscription.mjs'
|
||||
import { Subscription } from '../app/src/models/Subscription.js'
|
||||
import { scriptRunner } from './lib/ScriptRunner.mjs'
|
||||
|
||||
function usage() {
|
||||
|
||||
@@ -3,7 +3,7 @@ import minimist from 'minimist'
|
||||
import { parse } from 'csv'
|
||||
import Stream from 'node:stream/promises'
|
||||
import SubscriptionGroupHandler from '../app/src/Features/Subscription/SubscriptionGroupHandler.mjs'
|
||||
import { Subscription } from '../app/src/models/Subscription.mjs'
|
||||
import { Subscription } from '../app/src/models/Subscription.js'
|
||||
import { InvalidEmailError } from '../app/src/Features/Errors/Errors.js'
|
||||
|
||||
function usage() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import GoogleBigQueryHelper from './helpers/GoogleBigQueryHelper.mjs'
|
||||
import { Subscription } from '../../app/src/models/Subscription.mjs'
|
||||
import { Subscription } from '../../app/src/models/Subscription.js'
|
||||
import AnalyticsManager from '../../app/src/Features/Analytics/AnalyticsManager.mjs'
|
||||
import { DeletedSubscription } from '../../app/src/models/DeletedSubscription.mjs'
|
||||
import { DeletedSubscription } from '../../app/src/models/DeletedSubscription.js'
|
||||
import minimist from 'minimist'
|
||||
import _ from 'lodash'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @ts-check
|
||||
import '../app/src/models/User.mjs'
|
||||
import '../app/src/models/User.js'
|
||||
import { batchedUpdateWithResultHandling } from '@overleaf/mongo-utils/batchedUpdate.js'
|
||||
import { promiseMapWithLimit } from '@overleaf/promise-utils'
|
||||
import { getQueue } from '../app/src/infrastructure/Queues.js'
|
||||
|
||||
@@ -8,7 +8,7 @@ import path from 'node:path'
|
||||
import _ from 'lodash'
|
||||
import parseArgs from 'minimist'
|
||||
import OError from '@overleaf/o-error'
|
||||
import { User } from '../app/src/models/User.mjs'
|
||||
import { User } from '../app/src/models/User.js'
|
||||
import ProjectCreationHandler from '../app/src/Features/Project/ProjectCreationHandler.mjs'
|
||||
import ProjectEntityUpdateHandler from '../app/src/Features/Project/ProjectEntityUpdateHandler.mjs'
|
||||
import ProjectEntityHandler from '../app/src/Features/Project/ProjectEntityHandler.mjs'
|
||||
|
||||
@@ -8,7 +8,7 @@ import mongodb from 'mongodb-legacy'
|
||||
import { db } from '../app/src/infrastructure/mongodb.js'
|
||||
import Errors from '../app/src/Features/Errors/Errors.js'
|
||||
import ProjectEntityMongoUpdateHandler from '../app/src/Features/Project/ProjectEntityMongoUpdateHandler.mjs'
|
||||
import { iterablePaths } from '../app/src/Features/Project/IterablePath.mjs'
|
||||
import { iterablePaths } from '../app/src/Features/Project/IterablePath.js'
|
||||
import { scriptRunner } from './lib/ScriptRunner.mjs'
|
||||
import HistoryManager from '../app/src/Features/History/HistoryManager.mjs'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Subscription } from '../app/src/models/Subscription.mjs'
|
||||
import { Subscription } from '../app/src/models/Subscription.js'
|
||||
import SubscriptionUpdater from '../app/src/Features/Subscription/SubscriptionUpdater.mjs'
|
||||
import minimist from 'minimist'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { User } from '../app/src/models/User.mjs'
|
||||
import { User } from '../app/src/models/User.js'
|
||||
import UserController from '../app/src/Features/User/UserController.mjs'
|
||||
import Logger from '@overleaf/logger'
|
||||
import pLimit from 'p-limit'
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* in the migrations directory.
|
||||
*/
|
||||
|
||||
import { User } from '../../app/src/models/User.mjs'
|
||||
import { User } from '../../app/src/models/User.js'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
// const somePackage = require('some-package')
|
||||
|
||||
@@ -2,7 +2,7 @@ import { scriptRunner } from './lib/ScriptRunner.mjs'
|
||||
import * as csv from 'csv'
|
||||
import fs from 'node:fs'
|
||||
import minimist from 'minimist'
|
||||
import { User } from '../app/src/models/User.mjs'
|
||||
import { User } from '../app/src/models/User.js'
|
||||
|
||||
/**
|
||||
* This script extracts users who churned after day 1 - ie. their last session was within 24 hours of registering
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { scriptRunner } from './lib/ScriptRunner.mjs'
|
||||
import * as csv from 'csv'
|
||||
import fs from 'node:fs'
|
||||
import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.mjs'
|
||||
import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.js'
|
||||
|
||||
/**
|
||||
* This script extracts the OnboardingDataCollection collection from the database
|
||||
|
||||
@@ -2,8 +2,8 @@ import { scriptRunner } from './lib/ScriptRunner.mjs'
|
||||
import * as csv from 'csv'
|
||||
import fs from 'node:fs'
|
||||
import minimist from 'minimist'
|
||||
import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.mjs'
|
||||
import { User } from '../app/src/models/User.mjs'
|
||||
import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.js'
|
||||
import { User } from '../app/src/models/User.js'
|
||||
import SubscriptionLocator from '../app/src/Features/Subscription/SubscriptionLocator.mjs'
|
||||
import Settings from '@overleaf/settings'
|
||||
import { fetchJson } from '@overleaf/fetch-utils'
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
/* eslint-disable */
|
||||
import { extractImports, findJSAndImports } from './esm-check-migration.mjs'
|
||||
import path from 'node:path'
|
||||
import fs from 'node:fs'
|
||||
|
||||
const imports = await findJSAndImports(
|
||||
['app', 'modules'].map(dir => path.resolve(dir))
|
||||
)
|
||||
|
||||
const entryPoint = fs.existsSync('app.js') ? 'app.js' : 'app.mjs'
|
||||
imports.set(path.resolve(entryPoint), extractImports(entryPoint))
|
||||
|
||||
const moduleImports = new Map()
|
||||
imports.forEach((deps, module) => {
|
||||
for (const dep of deps) {
|
||||
if (!moduleImports.has(dep)) {
|
||||
moduleImports.set(dep, new Set())
|
||||
}
|
||||
moduleImports.set(dep, moduleImports.get(dep).add(module))
|
||||
}
|
||||
})
|
||||
|
||||
const soloImports = new Map()
|
||||
moduleImports.forEach((importedBy, module) => {
|
||||
if (importedBy.size === 1) {
|
||||
soloImports.set(module, [...importedBy][0])
|
||||
}
|
||||
})
|
||||
|
||||
console.log(soloImports)
|
||||
|
||||
for (const [module, importedBy] of soloImports) {
|
||||
if (!moduleImports.has(importedBy)) {
|
||||
console.log(
|
||||
`${module} is only imported by ${importedBy}, which has no other imports`
|
||||
)
|
||||
}
|
||||
if (soloImports.has(importedBy)) {
|
||||
console.log(
|
||||
`${module} is only imported by ${importedBy}, which is only imported by ${soloImports.get(importedBy)}`
|
||||
)
|
||||
}
|
||||
const chains = findDependencyChainsToTarget(imports, module)
|
||||
const conversionsToMake = chains.reduce((conversions, chain) => {
|
||||
chain.forEach(dep => {
|
||||
conversions.add(dep)
|
||||
})
|
||||
return conversions
|
||||
}, new Set())
|
||||
|
||||
if (conversionsToMake.length < 10) {
|
||||
console.log(
|
||||
`To convert ${module}, would need to convert: ${[...conversionsToMake].length}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// --- Circular dependency detection ---
|
||||
function findCircularDependencies(importsMap) {
|
||||
const cycles = []
|
||||
const visited = new Set()
|
||||
const stack = []
|
||||
|
||||
function dfs(file, pathStack) {
|
||||
if (pathStack.includes(file)) {
|
||||
// Cycle detected
|
||||
const cycleStart = pathStack.indexOf(file)
|
||||
cycles.push(pathStack.slice(cycleStart).concat(file))
|
||||
return
|
||||
}
|
||||
if (!importsMap.has(file)) return
|
||||
pathStack.push(file)
|
||||
for (const imp of importsMap.get(file)) {
|
||||
const resolvedImp = path.resolve(imp)
|
||||
dfs(resolvedImp, pathStack)
|
||||
}
|
||||
pathStack.pop()
|
||||
}
|
||||
|
||||
for (const file of importsMap.keys()) {
|
||||
dfs(file, [])
|
||||
}
|
||||
return cycles
|
||||
}
|
||||
|
||||
const cycles = findCircularDependencies(imports)
|
||||
if (cycles.length > 0) {
|
||||
console.log('Circular dependencies found:')
|
||||
for (const cycle of cycles) {
|
||||
console.log(' ' + cycle.join(' -> '))
|
||||
}
|
||||
} else {
|
||||
console.log('No circular dependencies detected.')
|
||||
}
|
||||
|
||||
// --- Find all chains of dependencies to a target file ---
|
||||
function findDependencyChainsToTarget(importsMap, targetPath) {
|
||||
const chains = []
|
||||
const resolvedTarget = path.resolve(targetPath)
|
||||
|
||||
function dfs(current, pathStack) {
|
||||
if (pathStack.includes(current)) return // avoid cycles
|
||||
pathStack.push(current)
|
||||
if (current === resolvedTarget) {
|
||||
chains.push([...pathStack])
|
||||
pathStack.pop()
|
||||
return
|
||||
}
|
||||
if (!importsMap.has(current)) {
|
||||
pathStack.pop()
|
||||
return
|
||||
}
|
||||
for (const imp of importsMap.get(current)) {
|
||||
const resolvedImp = path.resolve(imp)
|
||||
dfs(resolvedImp, pathStack)
|
||||
}
|
||||
pathStack.pop()
|
||||
}
|
||||
|
||||
for (const file of importsMap.keys()) {
|
||||
if (file === resolvedTarget) continue // skip self
|
||||
dfs(file, [])
|
||||
}
|
||||
return chains
|
||||
}
|
||||
|
||||
// Example usage: set your target file path here
|
||||
const targetFile =
|
||||
'/Users/arumble/Documents/Projects/internal/services/web/app/src/Features/Analytics/AnalyticsManager.js' // <-- change to your target
|
||||
const chains = findDependencyChainsToTarget(imports, targetFile)
|
||||
if (chains.length > 0) {
|
||||
console.log(`Dependency chains leading to ${targetFile}:`)
|
||||
for (const chain of chains) {
|
||||
console.log(' ' + chain.join(' -> '))
|
||||
}
|
||||
} else {
|
||||
console.log(`No dependency chains found leading to ${targetFile}.`)
|
||||
}
|
||||
|
||||
const conversionsToMake = chains.reduce((conversions, chain) => {
|
||||
chain.forEach(dep => {
|
||||
conversions.add(dep)
|
||||
})
|
||||
return conversions
|
||||
}, new Set())
|
||||
|
||||
console.log([...conversionsToMake].join(' '))
|
||||
@@ -10,7 +10,7 @@ import Errors from '../app/src/Features/Errors/Errors.js'
|
||||
import UserGetter from '../app/src/Features/User/UserGetter.mjs'
|
||||
import { READ_PREFERENCE_SECONDARY } from '@overleaf/mongo-utils/batchedUpdate.js'
|
||||
import UserUpdater from '../app/src/Features/User/UserUpdater.mjs'
|
||||
import EmailHelper from '../app/src/Features/Helpers/EmailHelper.mjs'
|
||||
import EmailHelper from '../app/src/Features/Helpers/EmailHelper.js'
|
||||
import AsyncLocalStorage from '../app/src/infrastructure/AsyncLocalStorage.js'
|
||||
import AnalyticsManager from '../app/src/Features/Analytics/AnalyticsManager.mjs'
|
||||
import UserAuditLogHandler from '../app/src/Features/User/UserAuditLogHandler.mjs'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Subscription } from '../../app/src/models/Subscription.mjs'
|
||||
import { Subscription } from '../../app/src/models/Subscription.js'
|
||||
import RecurlyWrapper from '../../app/src/Features/Subscription/RecurlyWrapper.mjs'
|
||||
import SubscriptionUpdater from '../../app/src/Features/Subscription/SubscriptionUpdater.mjs'
|
||||
import minimist from 'minimist'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Subscription } from '../../app/src/models/Subscription.mjs'
|
||||
import { Subscription } from '../../app/src/models/Subscription.js'
|
||||
import RecurlyWrapper from '../../app/src/Features/Subscription/RecurlyWrapper.mjs'
|
||||
import SubscriptionUpdater from '../../app/src/Features/Subscription/SubscriptionUpdater.mjs'
|
||||
import minimist from 'minimist'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OauthApplication } from '../app/src/models/OauthApplication.mjs'
|
||||
import { OauthApplication } from '../app/src/models/OauthApplication.js'
|
||||
import parseArgs from 'minimist'
|
||||
import OError from '@overleaf/o-error'
|
||||
import { scriptRunner } from './lib/ScriptRunner.mjs'
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
import minimist from 'minimist'
|
||||
import { ObjectId } from '../app/src/infrastructure/mongodb.js'
|
||||
import { User } from '../app/src/models/User.mjs'
|
||||
import { Subscription } from '../app/src/models/Subscription.mjs'
|
||||
import { User } from '../app/src/models/User.js'
|
||||
import { Subscription } from '../app/src/models/Subscription.js'
|
||||
import UserAuditLogHandler from '../app/src/Features/User/UserAuditLogHandler.mjs'
|
||||
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Settings from '@overleaf/settings'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
import { Project } from '../app/src/models/Project.mjs'
|
||||
import { Project } from '../app/src/models/Project.js'
|
||||
import { scriptRunner } from './lib/ScriptRunner.mjs'
|
||||
|
||||
const { ObjectId } = mongodb
|
||||
|
||||
@@ -3,8 +3,9 @@ import { db } from '../app/src/infrastructure/mongodb.js'
|
||||
|
||||
const MODEL_NAME = process.argv.pop()
|
||||
|
||||
// Todo: handle mjs file once models have been converted to ES module
|
||||
const { [MODEL_NAME]: Model } = await import(
|
||||
`../app/src/models/${MODEL_NAME}.mjs`
|
||||
`../app/src/models/${MODEL_NAME}.js`
|
||||
)
|
||||
|
||||
function processBatch(batch) {
|
||||
|
||||
Reference in New Issue
Block a user