-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add correct-ts-specifiers
#7
Conversation
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.
Okay frist review. mostly code style
import assert from 'node:assert/strict'; | ||
import { type Mock, afterEach, before, describe, it, mock } from 'node:test'; | ||
import { fileURLToPath } from 'node:url'; |
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.
import assert from 'node:assert/strict'; | |
import { type Mock, afterEach, before, describe, it, mock } from 'node:test'; | |
import { fileURLToPath } from 'node:url'; | |
import assert from 'node:assert/strict'; | |
import { afterEach, before, describe, it, mock } from 'node:test'; | |
import { fileURLToPath } from 'node:url'; | |
import type { Mock } from 'node:test' |
I recommend separating js import and type import
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.
Not opposed, but why?
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.
but why?
So it's a bit stupid, but on the one hand you have an import of code (js) that will be executed and on the other hand the typing (ts/d.ts) that will be removed by the transpiler.
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.
Hmm, I think combining them is better because it's easier to grok and realise A and type B are coming from the same place. Also, separating them rather significantly increases size.
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.
That's true. I think they're both equally good. We'll have to see what the rest of the team thinks.
import assert from 'node:assert/strict'; | ||
import path from 'node:path'; | ||
import { type Mock, after, afterEach, before, describe, it, mock } from 'node:test'; | ||
import { fileURLToPath } from 'node:url'; |
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.
import assert from 'node:assert/strict'; | |
import path from 'node:path'; | |
import { type Mock, after, afterEach, before, describe, it, mock } from 'node:test'; | |
import { fileURLToPath } from 'node:url'; | |
import assert from 'node:assert/strict'; | |
import path from 'node:path'; | |
import { after, afterEach, before, describe, it, mock } from 'node:test'; | |
import { fileURLToPath } from 'node:url'; | |
import type { Mock } from 'node:test'; |
import type { FSAbsolutePath, NodeModSpecifier, ResolvedSpecifier, Specifier } from './index.d.ts'; | ||
import { type DExt, type JSExt, type TSExt, extSets, suspectExts } from './exts.ts'; | ||
import { fexists } from './fexists.ts'; | ||
import { logger } from './logger.ts'; | ||
import { isDir } from './is-dir.ts'; |
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.
import type { FSAbsolutePath, NodeModSpecifier, ResolvedSpecifier, Specifier } from './index.d.ts'; | |
import { type DExt, type JSExt, type TSExt, extSets, suspectExts } from './exts.ts'; | |
import { fexists } from './fexists.ts'; | |
import { logger } from './logger.ts'; | |
import { isDir } from './is-dir.ts'; | |
import type { FSAbsolutePath, NodeModSpecifier, ResolvedSpecifier, Specifier } from './index.d.ts'; | |
import type { DExt, JSExt, TSExt } from './exts.ts'; | |
import { extSets, suspectExts } from './exts.ts'; | |
import { fexists } from './fexists.ts'; | |
import { logger } from './logger.ts'; | |
import { isDir } from './is-dir.ts'; |
@@ -0,0 +1,56 @@ | |||
import { type Api, api } from '@codemod.com/workflow'; |
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.
import { type Api, api } from '@codemod.com/workflow'; | |
import { api } from '@codemod.com/workflow'; | |
import type { Api } from '@codemod.com/workflow'; |
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.
Copilot reviewed 76 out of 79 changed files in this pull request and generated no suggestions.
Files not reviewed (3)
- recipes/correct-ts-specifiers/package.json: Language not supported
- recipes/correct-ts-specifiers/src/fixtures/ambiguous.ts: Evaluated as low risk
- recipes/correct-ts-specifiers/src/fixtures/bar.js: Evaluated as low risk
Comments skipped due to low confidence (1)
recipes/correct-ts-specifiers/src/fexists.test.ts:120
- [nitpick] The test description is duplicated. Consider renaming it to 'should return
false
for a relative specifier with query parameter'.
it('should return `false` for a relative specifier', async () => {
9da4e56
to
1e8ec00
Compare
65c9502
to
87c6a1f
Compare
import { mapImports } from './map-imports.ts'; | ||
import type { FSAbsolutePath } from './index.d.ts'; | ||
|
||
module.register('@nodejs-loaders/alias', import.meta.url); |
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.
you can just import register because it's the only api we use on this file
module.register('@nodejs-loaders/alias', import.meta.url); | |
register('@nodejs-loaders/alias', import.meta.url); |
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.
I thought of that. I went with module.register
to make it more clear what is happening (lots of APIs have register
).
Is there a perf improvement to this or is it just 4 characters fewer?
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.
Is there a perf improvement to this or is it just 4 characters fewer?
normally importing whole api isn't a issue, except when it's a big JS module
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.
I don't feel strongly, maybe 6/10. If you feel stronger, we can go with that. Otherwise, meh, let's just leave it.
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.
I think we can leave it like that. And yes, I ask a lot of questions, but this is the first codemod we've done, so we have to lay the foundations.
6fcffc0
to
037e5e0
Compare
let hasError = false; | ||
|
||
for (const [sourceFile, fileLog] of logs.entries()) { | ||
console.log('[Codemod: correct-ts-specifiers]:', sourceFile); |
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.
maybe use styleText
to have something coooollll
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.
MVP first 😜 been working on this thing since like June
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.
Oh yeah, holly molly macaroni
037e5e0
to
3d93029
Compare
Depends on #6