-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(ts-plugin): Enable in memory EVMts typeserver (#466)
## Description - Update @evmts/bundler to take a file-access-object as a param instead of using `fs` - Update @evmts/bun-plugin to pass in a file-access-object using native bun methods for peformance - Update @evmts/ts-plugin to pass in Ts server files as the file-access-object Bun is faster from using native bun files instead of normal files. In future we should make the async methods truly async for even better peformance. Ts-plugin will now work without clicking save since files are accessed through ts-server instead of file system ## Testing Existing unit tests and more testing for newly implemented features ## 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
1 parent
ce27a61
commit 1c4cbd2
Showing
35 changed files
with
499 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
"@evmts/bundler": patch | ||
--- | ||
|
||
Updated @evmts/bundler to take a fileAccessObject as a parameter | ||
|
||
### Context | ||
@evmts/bundler is the internal bundler for all other bundlers and the language server. We changed it to take fileAccessObject as a parameter instead of using `fs` and `fs/promises` | ||
|
||
### Impact | ||
By taking in a file-access-object instead of using `fs` we can implement important features. | ||
|
||
- the ability to use virtual files in the typescript lsp before the user saves the file. | ||
- the ability to use more peformant bun file read methods | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@evmts/ts-plugin": patch | ||
--- | ||
|
||
Updated @evmts/ts-plugin to use LSP to get files | ||
|
||
Previously EVMts relied on `fs.readFileSync` to implement the LSP. By replacing this with using `typescriptLanguageServer.readFile` we are able to rely on the LSP to get the file instead of the file system | ||
|
||
In future versions of EVMts when we add a vscode plugin this will make the LSP smart enough to update before the user even clicks `save` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@evmts/bun-plugin": patch | ||
--- | ||
|
||
Updated Bun to use native Bun.file api which is more peformant than using `fs` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { file } from 'bun' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { file } from './bunFile' | ||
import { bunFileAccesObject } from './bunFileAccessObject' | ||
import * as fsPromises from 'fs/promises' | ||
import { join } from 'path' | ||
import { type Mock, beforeEach, describe, expect, it } from 'vitest' | ||
import { vi } from 'vitest' | ||
|
||
const licensePath = join(__dirname, '../LICENSE') | ||
|
||
vi.mock('./bunFile', () => ({ | ||
file: vi.fn(), | ||
})) | ||
|
||
const mockFile = file as Mock | ||
|
||
describe('bunFileAccessObject', () => { | ||
beforeEach(() => { | ||
mockFile.mockImplementation((filePath: string) => ({ | ||
exists: () => true, | ||
text: () => fsPromises.readFile(filePath, 'utf8'), | ||
})) | ||
}) | ||
describe(bunFileAccesObject.readFileSync.name, () => { | ||
it('reads a file', () => { | ||
const result = bunFileAccesObject.readFileSync(licensePath, 'utf8') | ||
expect(result).toMatchInlineSnapshot(` | ||
"(The MIT License) | ||
Copyright 2020-2022 | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
\\"Software\\"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED \\"AS IS\\", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
" | ||
`) | ||
}) | ||
}) | ||
|
||
describe(bunFileAccesObject.exists.name, () => { | ||
it('returns true if a file exists', async () => { | ||
const result = await bunFileAccesObject.exists(licensePath) | ||
expect(result).toBe(true) | ||
}) | ||
}) | ||
|
||
describe(bunFileAccesObject.readFile.name, () => { | ||
it('reads a file', async () => { | ||
const result = await bunFileAccesObject.readFile(licensePath, 'utf8') | ||
expect(result).toMatchInlineSnapshot(` | ||
"(The MIT License) | ||
Copyright 2020-2022 | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
\\"Software\\"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED \\"AS IS\\", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
" | ||
`) | ||
}) | ||
}) | ||
|
||
describe(bunFileAccesObject.existsSync.name, () => { | ||
it('returns true if a file exists', () => { | ||
const result = bunFileAccesObject.existsSync(licensePath) | ||
expect(result).toBe(true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { file } from './bunFile' | ||
import type { FileAccessObject } from '@evmts/bundler' | ||
import { existsSync, readFileSync } from 'fs' | ||
|
||
export const bunFileAccesObject: FileAccessObject & { | ||
exists: (filePath: string) => Promise<boolean> | ||
} = { | ||
existsSync, | ||
exists: (filePath: string) => { | ||
const bunFile = file(filePath) | ||
return bunFile.exists() | ||
}, | ||
readFile: (filePath: string) => { | ||
const bunFile = file(filePath) | ||
return bunFile.text() | ||
}, | ||
readFileSync, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ export default defineConfig({ | |
splitting: false, | ||
sourcemap: true, | ||
clean: true, | ||
bundle: false, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
1c4cbd2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
evmts-docs – ./
evmts-docs-evmts.vercel.app
evmts-docs-git-main-evmts.vercel.app
evmts.dev