Skip to content

Commit

Permalink
♻️ chore(ts-plugin): Migrate ts-plugin to NodeNext (#572)
Browse files Browse the repository at this point in the history
## Description

Migrate TS Plugin to NodeNext

## Testing

Explain the quality checks that have been done on the code changes

## Additional Information

- [ ] I read the [contributing docs](../docs/contributing.md) (if this
is your first contribution)

Your ENS/address:

---------

Co-authored-by: Will Cory <[email protected]>
  • Loading branch information
roninjin10 and Will Cory authored Oct 16, 2023
1 parent 1d6716a commit eee7e7f
Show file tree
Hide file tree
Showing 35 changed files with 88 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-chairs-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@evmts/ts-plugin": patch
---

Updated @evmts/ts-plugin to NodeNext. This will improve compatibility
6 changes: 3 additions & 3 deletions docs/reference/ts-plugin/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

### Functions

- [export&#x3D;](/reference/ts-plugin/modules.md#export&#x3D;)
- [default](/reference/ts-plugin/modules.md#default)

## Functions

### export&#x3D;
### default

**export=**(`mod`): `PluginModule`
**default**(`mod`): `PluginModule`

[Typescript plugin factory](https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin)

Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/src/decorators/getDefinitionAtPosition.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDefinitionServiceDecorator } from './getDefinitionAtPosition'
import { getDefinitionServiceDecorator } from './getDefinitionAtPosition.js'
import { FileAccessObject } from '@evmts/bundler'
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'
import { beforeEach, describe, expect, it, vi } from 'vitest'

// TODO these tests are awful this should be tested e2e against real fixtures
Expand Down
12 changes: 6 additions & 6 deletions ts-plugin/src/decorators/getDefinitionAtPosition.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Logger } from '../factories'
import { findNode } from '../utils'
import { Logger } from '../factories/logger.js'
import { findNode } from '../utils/index.js'
import {
convertSolcAstToTsDefinitionInfo,
findContractDefinitionFileNameFromEvmtsNode,
} from '../utils'
} from '../utils/index.js'
import { Cache, FileAccessObject, bundler } from '@evmts/bundler'
import { ResolvedCompilerConfig } from '@evmts/config'
import { Node } from 'solidity-ast/node'
import { findAll } from 'solidity-ast/utils'
import typescript from 'typescript/lib/tsserverlibrary'
import { Node } from 'solidity-ast/node.js'
import { findAll } from 'solidity-ast/utils.js'
import typescript from 'typescript/lib/tsserverlibrary.js'

// TODO make me to a normal decorator
// is a woneoff decorator becuase this decorates the language service not the Host
Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/src/decorators/getScriptKind.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getScriptKindDecorator } from '.'
import { getScriptKindDecorator } from './getScriptKind.js'
import { FileAccessObject } from '@evmts/bundler'
import { CompilerConfig, defaultConfig, defineConfig } from '@evmts/config'
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'
import { beforeEach, describe, expect, it, vi } from 'vitest'

type TestAny = any
Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/src/decorators/getScriptKind.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHostDecorator } from '../factories'
import { isSolidity } from '../utils'
import { createHostDecorator } from '../factories/index.js'
import { isSolidity } from '../utils/index.js'

/**
* Decorate `LangaugeServerHost.getScriptKind` to return TS type for `.sol` files
Expand Down
6 changes: 3 additions & 3 deletions ts-plugin/src/decorators/getScriptSnapshot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getScriptSnapshotDecorator } from '.'
import { Logger } from '../factories'
import { Logger } from '../factories/logger.js'
import { getScriptSnapshotDecorator } from './getScriptSnapshot.js'
import { FileAccessObject } from '@evmts/bundler'
import { CompilerConfig, defaultConfig, defineConfig } from '@evmts/config'
import { existsSync, readFileSync } from 'fs'
import { readFile } from 'fs/promises'
import path from 'path'
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest'

const forgeProject = path.join(__dirname, '../..')
Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/src/decorators/getScriptSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHostDecorator } from '../factories'
import { isSolidity } from '../utils'
import { createHostDecorator } from '../factories/index.js'
import { isSolidity } from '../utils/index.js'
import { Cache, bundler } from '@evmts/bundler'
import { existsSync } from 'fs'

Expand Down
6 changes: 3 additions & 3 deletions ts-plugin/src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './getScriptKind'
export * from './getScriptSnapshot'
export * from './resolveModuleNameLiterals'
export * from './getScriptKind.js'
export * from './getScriptSnapshot.js'
export * from './resolveModuleNameLiterals.js'
6 changes: 3 additions & 3 deletions ts-plugin/src/decorators/resolveModuleNameLiterals.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { resolveModuleNameLiteralsDecorator } from '.'
import { solidityModuleResolver } from '../utils'
import { solidityModuleResolver } from '../utils/index.js'
import { resolveModuleNameLiteralsDecorator } from './resolveModuleNameLiterals.js'
import { FileAccessObject } from '@evmts/bundler'
import { CompilerConfig, defaultConfig, defineConfig } from '@evmts/config'
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'
import { MockedFunction, describe, expect, it, vi } from 'vitest'

const { remappings, ...compilerOptions } = defaultConfig
Expand Down
6 changes: 3 additions & 3 deletions ts-plugin/src/decorators/resolveModuleNameLiterals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createHostDecorator } from '../factories'
import { solidityModuleResolver } from '../utils'
import { invariant } from '../utils/invariant'
import { createHostDecorator } from '../factories/index.js'
import { solidityModuleResolver } from '../utils/index.js'
import { invariant } from '../utils/invariant.js'

/**
* Decorate `LangaugeServerHost.resolveModuleNameLiterals` to return config object to resolve `.sol` files
Expand Down
6 changes: 3 additions & 3 deletions ts-plugin/src/factories/decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
PartialHostDecorator,
createHostDecorator,
decorateHost,
} from '.'
} from './index.js'
import { FileAccessObject } from '@evmts/bundler'
import { CompilerConfig, defaultConfig, defineConfig } from '@evmts/config'
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'
import { describe, expect, it, vi } from 'vitest'

type TestAny = any
Expand Down Expand Up @@ -44,7 +44,7 @@ const createProxy = <T extends object>(instance: T, proxy: Partial<T>): T => {
describe(createHostDecorator.name, () => {
it('should define a decorator by passing a functiont hat returns a partial tsserver object', () => {
const decoratorFn: PartialHostDecorator = (createInfo, ts, logger) => ({
getScriptKind: (fileName) => {
getScriptKind: (fileName: string) => {
if (fileName.endsWith('.json')) {
return ts.ScriptKind.JSON
} else {
Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/src/factories/decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Logger } from './logger'
import type { Logger } from './logger.js'
import { FileAccessObject } from '@evmts/bundler'
import { ResolvedCompilerConfig } from '@evmts/config'
import type typescript from 'typescript/lib/tsserverlibrary'
import type typescript from 'typescript/lib/tsserverlibrary.js'

/**
* Internal type representing a leangauge service host decorator.
Expand Down
2 changes: 1 addition & 1 deletion ts-plugin/src/factories/fileAccessObject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createFileAccessObject } from './fileAccessObject'
import { createFileAccessObject } from './fileAccessObject.js'
import { LanguageServiceHost } from 'typescript'
import { describe, expect, it, vi } from 'vitest'

Expand Down
2 changes: 1 addition & 1 deletion ts-plugin/src/factories/fileAccessObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileAccessObject } from '@evmts/bundler'
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'

export const createFileAccessObject = (
lsHost: typescript.LanguageServiceHost,
Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/src/factories/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './logger'
export * from './decorator'
export * from './logger.js'
export * from './decorator.js'
2 changes: 1 addition & 1 deletion ts-plugin/src/factories/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createLogger } from '.'
import { createLogger } from './logger.js'
import { beforeEach, describe, expect, it, vi } from 'vitest'

type TestAny = any
Expand Down
2 changes: 1 addition & 1 deletion ts-plugin/src/factories/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type typescript from 'typescript/lib/tsserverlibrary'
import type typescript from 'typescript/lib/tsserverlibrary.js'

/**
* The logger used internally within the package
Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { tsPlugin } from './tsPlugin'
import { tsPlugin } from './tsPlugin.js'

export = tsPlugin
export default tsPlugin
4 changes: 2 additions & 2 deletions ts-plugin/src/tsPlugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tsPlugin from '.'
import tsPlugin from './index.js'
import { CompilerConfig } from '@evmts/config'
import path from 'path'
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'
import { Mock, describe, expect, it, vi } from 'vitest'

type TestAny = any
Expand Down
12 changes: 6 additions & 6 deletions ts-plugin/src/tsPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { getDefinitionServiceDecorator } from './decorators/getDefinitionAtPosition.js'
import {
getScriptKindDecorator,
getScriptSnapshotDecorator,
resolveModuleNameLiteralsDecorator,
} from './decorators'
import { getDefinitionServiceDecorator } from './decorators/getDefinitionAtPosition'
import { createLogger, decorateHost } from './factories'
import { createFileAccessObject } from './factories/fileAccessObject'
import { isSolidity } from './utils'
} from './decorators/index.js'
import { createFileAccessObject } from './factories/fileAccessObject.js'
import { createLogger, decorateHost } from './factories/index.js'
import { isSolidity } from './utils/index.js'
import { createCache } from '@evmts/bundler'
import { loadConfig } from '@evmts/config'
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'

/**
* [Typescript plugin factory](https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin)
Expand Down
8 changes: 4 additions & 4 deletions ts-plugin/src/utils/convertSolcAstToTsDefinitionInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Node } from 'solidity-ast/node'
import * as ts from 'typescript/lib/tsserverlibrary'
import { Node } from 'solidity-ast/node.js'
import ts from 'typescript/lib/tsserverlibrary.js'
import { describe, expect, it, vi } from 'vitest'

// Mock readFileSync to return a specific length of content
Expand All @@ -11,8 +11,8 @@ vi.mock('fs', async () => {
})

// Now, import your function under test
import { convertSolcAstToTsDefinitionInfo } from '../utils/convertSolcAstToTsDefinitionInfo'
import { SolcInput } from 'solidity-ast/solc'
import { convertSolcAstToTsDefinitionInfo } from '../utils/convertSolcAstToTsDefinitionInfo.js'
import { SolcInput } from 'solidity-ast/solc.js'
import { ScriptElementKind } from 'typescript'

describe('convertSolcAstToTsDefinitionInfo', () => {
Expand Down
6 changes: 3 additions & 3 deletions ts-plugin/src/utils/convertSolcAstToTsDefinitionInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from 'fs'
import { Node } from 'solidity-ast/node'
import { SolcInput } from 'solidity-ast/solc'
import typescript from 'typescript/lib/tsserverlibrary'
import { Node } from 'solidity-ast/node.js'
import { SolcInput } from 'solidity-ast/solc.js'
import typescript from 'typescript/lib/tsserverlibrary.js'

/**
* Adapter from solc to typescript
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { findContractDefinitionFileNameFromEvmtsNode } from './findContractDefinitionFileNameFromEvmtsNode'
import { findNode } from './findNode'
import * as ts from 'typescript/lib/tsserverlibrary'
import { findContractDefinitionFileNameFromEvmtsNode } from './findContractDefinitionFileNameFromEvmtsNode.js'
import { findNode } from './findNode.js'
import ts from 'typescript/lib/tsserverlibrary.js'
import { MockedFunction, describe, expect, it, vi } from 'vitest'

const mockContractFile = '/path/to/ContractDefinitionFile.sol'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'

export function findContractDefinitionFileNameFromEvmtsNode(
node: typescript.Node,
Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/src/utils/findNode.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findNode } from './findNode'
import * as ts from 'typescript/lib/tsserverlibrary'
import { findNode } from './findNode.js'
import * as ts from 'typescript/lib/tsserverlibrary.js'
import { describe, expect, it } from 'vitest'

describe('findNode', () => {
Expand Down
2 changes: 1 addition & 1 deletion ts-plugin/src/utils/findNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typescript from 'typescript/lib/tsserverlibrary'
import typescript from 'typescript/lib/tsserverlibrary.js'

/**
* Find the typescript node at the given position in the AST
Expand Down
14 changes: 7 additions & 7 deletions ts-plugin/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './isRelativeSolidity'
export * from './isSolidity'
export * from './solidityModuleResolver'
export * from './findNode'
export * from './invariant'
export * from './convertSolcAstToTsDefinitionInfo'
export * from './findContractDefinitionFileNameFromEvmtsNode'
export * from './isRelativeSolidity.js'
export * from './isSolidity.js'
export * from './solidityModuleResolver.js'
export * from './findNode.js'
export * from './invariant.js'
export * from './convertSolcAstToTsDefinitionInfo.js'
export * from './findContractDefinitionFileNameFromEvmtsNode.js'
2 changes: 1 addition & 1 deletion ts-plugin/src/utils/invariant.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invariant } from './invariant'
import { invariant } from './invariant.js'
import { describe, expect, expectTypeOf, it } from 'vitest'

describe(invariant.name, () => {
Expand Down
2 changes: 1 addition & 1 deletion ts-plugin/src/utils/isRelativeSolidity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isRelativeSolidity } from '.'
import { isRelativeSolidity } from './isRelativeSolidity.js'
import { describe, expect, it } from 'vitest'

describe(isRelativeSolidity.name, () => {
Expand Down
2 changes: 1 addition & 1 deletion ts-plugin/src/utils/isRelativeSolidity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSolidity } from './isSolidity'
import { isSolidity } from './isSolidity.js'

const isRelative = (fileName: string) =>
fileName.startsWith('./') || fileName.startsWith('../')
Expand Down
2 changes: 1 addition & 1 deletion ts-plugin/src/utils/isSolidity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSolidity } from '.'
import { isSolidity } from './isSolidity.js'
import { describe, expect, it } from 'vitest'

describe(isSolidity.name, () => {
Expand Down
6 changes: 3 additions & 3 deletions ts-plugin/src/utils/solidityModuleResolver.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { solidityModuleResolver } from './solidityModuleResolver'
import { solidityModuleResolver } from './solidityModuleResolver.js'
import path from 'path'
import typescript from 'typescript/lib/tsserverlibrary'
import { describe, expect, it, vi } from 'vitest'
import typescript from 'typescript/lib/tsserverlibrary.js'
import { describe, expect, it } from 'vitest'

describe('solidityModuleResolver', () => {
it('should resolve relative solidity modules', () => {
Expand Down
6 changes: 3 additions & 3 deletions ts-plugin/src/utils/solidityModuleResolver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isRelativeSolidity } from './isRelativeSolidity'
import { isSolidity } from './isSolidity'
import { isRelativeSolidity } from './isRelativeSolidity.js'
import { isSolidity } from './isSolidity.js'
import { createRequire } from 'module'
import path from 'path'
import type typescript from 'typescript/lib/tsserverlibrary'
import type typescript from 'typescript/lib/tsserverlibrary.js'

/**
* Resolves a Solidity module to a file path and Dts extension.
Expand Down
4 changes: 2 additions & 2 deletions ts-plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["esnext", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"outDir": "types",
Expand Down

1 comment on commit eee7e7f

@vercel
Copy link

@vercel vercel bot commented on eee7e7f Oct 16, 2023

Choose a reason for hiding this comment

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

Deployment failed with the following error:

Resource is limited - try again in 28 minutes (more than 100, code: "api-deployments-free-per-day").

Please sign in to comment.