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

feat: add correct-ts-specifiers #7

Merged
merged 22 commits into from
Dec 20, 2024
Merged

Conversation

JakobJingleheimer
Copy link
Member

Depends on #6

Copy link
Member

@AugustinMauroy AugustinMauroy left a 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

recipes/correct-ts-specifiers/README.md Outdated Show resolved Hide resolved
recipes/correct-ts-specifiers/package.json Outdated Show resolved Hide resolved
recipes/correct-ts-specifiers/src/exts.ts Show resolved Hide resolved
recipes/correct-ts-specifiers/src/exts.ts Show resolved Hide resolved
Comment on lines +1 to +3
import assert from 'node:assert/strict';
import { type Mock, afterEach, before, describe, it, mock } from 'node:test';
import { fileURLToPath } from 'node:url';
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member Author

Choose a reason for hiding this comment

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

Not opposed, but why?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Comment on lines +1 to +4
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';
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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';

Comment on lines +3 to +7
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';
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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';
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import { type Api, api } from '@codemod.com/workflow';
import { api } from '@codemod.com/workflow';
import type { Api } from '@codemod.com/workflow';

@JakobJingleheimer JakobJingleheimer marked this pull request as ready for review December 11, 2024 10:29
@AugustinMauroy AugustinMauroy requested review from a team and Copilot December 11, 2024 10:33

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 () => {
@JakobJingleheimer JakobJingleheimer force-pushed the feat/correct-ts-specifiers branch from 9da4e56 to 1e8ec00 Compare December 11, 2024 10:43
@JakobJingleheimer JakobJingleheimer force-pushed the feat/correct-ts-specifiers branch from 65c9502 to 87c6a1f Compare December 12, 2024 21:26
import { mapImports } from './map-imports.ts';
import type { FSAbsolutePath } from './index.d.ts';

module.register('@nodejs-loaders/alias', import.meta.url);
Copy link
Member

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

Suggested change
module.register('@nodejs-loaders/alias', import.meta.url);
register('@nodejs-loaders/alias', import.meta.url);

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 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?

Copy link
Member

@AugustinMauroy AugustinMauroy Dec 13, 2024

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

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 feel strongly, maybe 6/10. If you feel stronger, we can go with that. Otherwise, meh, let's just leave it.

Copy link
Member

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.

@JakobJingleheimer JakobJingleheimer force-pushed the feat/correct-ts-specifiers branch from 6fcffc0 to 037e5e0 Compare December 16, 2024 22:21
let hasError = false;

for (const [sourceFile, fileLog] of logs.entries()) {
console.log('[Codemod: correct-ts-specifiers]:', sourceFile);
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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

@JakobJingleheimer JakobJingleheimer force-pushed the feat/correct-ts-specifiers branch from 037e5e0 to 3d93029 Compare December 18, 2024 19:42
@JakobJingleheimer JakobJingleheimer merged commit 33bb235 into main Dec 20, 2024
7 checks passed
@JakobJingleheimer JakobJingleheimer deleted the feat/correct-ts-specifiers branch December 20, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants