Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup dead code #21340

Merged
merged 4 commits into from May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/data-context/src/DataContext.ts
Expand Up @@ -366,10 +366,6 @@ export class DataContext {
])
}

get loader () {
return this.util.loader
}

/**
* Resets all of the state for the data context,
* so we can initialize fresh for each E2E test
Expand All @@ -392,7 +388,6 @@ export class DataContext {
return Promise.all([
this.lifecycleManager.destroy(),
this.cloud.reset(),
this.util.disposeLoaders(),
this.actions.project.clearCurrentProject(),
this.actions.dev.dispose(),
])
Expand Down
2 changes: 1 addition & 1 deletion packages/data-context/src/sources/HtmlDataSource.ts
Expand Up @@ -35,7 +35,7 @@ export class HtmlDataSource {
)
} catch (e) {
err = e
await this.ctx.util.delayMs(1000)
await new Promise((resolve) => setTimeout(resolve, 1000))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth just using Bluebird.timeout here and elsewhere in this PR... so when we strip Bluebird out these timeouts are more easily discovered and replaced with a shared helper. Blue and I recently discussed this here: #21328 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we use Bluebird at all in the data-context package currently

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️

}
}

Expand Down
6 changes: 1 addition & 5 deletions packages/data-context/src/sources/ProjectDataSource.ts
Expand Up @@ -357,10 +357,6 @@ export class ProjectDataSource {
return preferences[projectTitle] ?? null
}

frameworkLoader = this.ctx.loader<string, typeof WIZARD_FRAMEWORKS[number] | null>((projectRoots) => {
return Promise.all(projectRoots.map((projectRoot) => Promise.resolve(this.guessFramework(projectRoot))))
})

private guessFramework (projectRoot: string) {
const guess = WIZARD_FRAMEWORKS.find((framework) => {
const lookingForDeps = framework.detectors.map((x) => x.package).reduce(
Expand All @@ -379,7 +375,7 @@ export class ProjectDataSource {

const looseComponentGlob = '*.{js,jsx,ts,tsx,.vue}'

const framework = await this.frameworkLoader.load(this.ctx.currentProject)
const framework = this.guessFramework(this.ctx.currentProject)

return {
component: framework?.glob ?? looseComponentGlob,
Expand Down
9 changes: 0 additions & 9 deletions packages/data-context/src/sources/SettingsDataSource.ts

This file was deleted.

45 changes: 0 additions & 45 deletions packages/data-context/src/sources/UtilDataSource.ts
@@ -1,5 +1,3 @@
import DataLoader from 'dataloader'
import crypto from 'crypto'
import fetch from 'cross-fetch'
import type { DataContext } from '../DataContext'

Expand All @@ -15,49 +13,6 @@ const { agent } = require('@packages/network')
export class UtilDataSource {
constructor (private ctx: DataContext) {}

private _allLoaders: DataLoader<any, any>[] = []

async settleAll<T> (promises: Promise<T>[]) {
const vals = await Promise.allSettled(promises)

return vals.map((v) => v.status === 'fulfilled' ? v.value : this.ensureError(v.reason))
}

/**
* Utility for a promise delay, in milliseconds
*/
async delayMs (ms: number) {
await new Promise((resolve) => setTimeout(resolve, ms))
}

assertAbsolute (val: string) {
if (!this.ctx.path.isAbsolute(val)) {
throw new Error(`Expected ${val} to be an absolute path`)
}
}

ensureError (val: any): Error {
return val instanceof Error ? val : new Error(val)
}

loader = <K, V, C = K>(batchLoadFn: DataLoader.BatchLoadFn<K, V>) => {
const loader = new DataLoader<K, V, C>(batchLoadFn, { cache: false })

this._allLoaders.push(loader)

return loader
}

disposeLoaders () {
for (const loader of this._allLoaders) {
loader.clearAll()
}
}

sha1 (value: string) {
return crypto.createHash('sha1').update(value).digest('hex')
}

fetch (input: RequestInfo | URL, init?: RequestInit) {
// @ts-ignore agent isn't a part of cross-fetch's API since it's not a part of the browser's fetch but it is a part of node-fetch
// which is what will be used here
Expand Down
1 change: 0 additions & 1 deletion packages/data-context/src/sources/index.ts
Expand Up @@ -10,7 +10,6 @@ export * from './GitDataSource'
export * from './HtmlDataSource'
export * from './MigrationDataSource'
export * from './ProjectDataSource'
export * from './SettingsDataSource'
export * from './UtilDataSource'
export * from './VersionsDataSource'
export * from './WizardDataSource'
Expand Down
Expand Up @@ -221,7 +221,8 @@ describe('code-generator', () => {
target,
}

sinon.stub(ctx.project.frameworkLoader, 'load').resolves(WIZARD_FRAMEWORKS[0])
// @ts-ignore
sinon.stub(ctx.project, 'guessFramework').returns(WIZARD_FRAMEWORKS[0])

const newSpecCodeGenOptions = new SpecOptions(ctx, {
codeGenPath: path.join(__dirname, 'files', 'react', 'Button.jsx'),
Expand All @@ -243,7 +244,8 @@ describe('code-generator', () => {
target,
}

sinon.stub(ctx.project.frameworkLoader, 'load').resolves(WIZARD_FRAMEWORKS[1])
// @ts-ignore
sinon.stub(ctx.project, 'guessFramework').returns(WIZARD_FRAMEWORKS[1])

const newSpecCodeGenOptions = new SpecOptions(ctx, {
codeGenPath: path.join(__dirname, 'files', 'vue', 'Button.vue'),
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts
Expand Up @@ -341,7 +341,7 @@ async function makeE2ETasks () {
return { value }
} catch (e: any) {
if (i <= retries) {
await ctx.util.delayMs(obj.options.retryDelay ?? 1000)
await new Promise((resolve) => setTimeout(resolve, obj.options.retryDelay ?? 1000))
}

lastErr = e
Expand Down