Skip to content

Commit 91b4a33

Browse files
authored
chore(codemods): Convert from CJS to ESM (#1303)
This is safe as no one imports this package. It's always run as a bin
1 parent 007f493 commit 91b4a33

File tree

56 files changed

+116
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+116
-91
lines changed

packages/codemods/build.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { build } from '@cedarjs/framework-tools'
1+
import { buildEsm } from '@cedarjs/framework-tools'
22

3-
await build()
3+
await buildEsm()

packages/codemods/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"directory": "packages/codemods"
99
},
1010
"license": "MIT",
11-
"type": "commonjs",
11+
"type": "module",
1212
"bin": "./dist/codemods.js",
1313
"files": [
1414
"dist"

packages/codemods/src/codemods.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

3-
import yargs from 'yargs'
3+
import { hideBin } from 'yargs/helpers'
4+
import yargs from 'yargs/yargs'
45

56
import * as v2TsconfigForRouteHooks from './codemods/redwood/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.yargs.js'
67
import * as v2ConfigureFastify from './codemods/redwood/v2.x.x/configureFastify/configureFastify.yargs.js'
@@ -25,7 +26,7 @@ import * as v2MoveGeneratorTemplates from './codemods/v2.3.x/moveGeneratorTempla
2526
import * as v2PrismaV7Prep from './codemods/v2.7.x/prismaV7Prep/prismaV7Prep.yargs.js'
2627

2728
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
28-
yargs
29+
yargs(hideBin(process.argv))
2930
.scriptName('')
3031
.command(v2MoveGeneratorTemplates)
3132
.command(v2PrismaV7Prep)

packages/codemods/src/codemods/list.yargs.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import fs from 'node:fs'
22
import path from 'path'
33

4-
import type yargs from 'yargs'
4+
import type { Argv } from 'yargs'
55
import { decamelize } from 'yargs-parser'
66

77
export const command = 'list <rwVersion>'
88
export const description = 'List available codemods for a specific version'
99

1010
export const aliases = ['ls']
1111

12-
export const builder = (yargs: yargs.Argv) => {
12+
export const builder = (yargs: Argv) => {
1313
yargs.positional('rwVersion', {
1414
type: 'string',
1515
required: true,
16-
choices: fs
17-
.readdirSync(__dirname)
18-
.filter((file) => !fs.statSync(path.join(__dirname, file)).isFile()), // Only list the folders
16+
choices: fs.readdirSync(import.meta.dirname).filter(
17+
// Only list the folders
18+
(file) => !fs.statSync(path.join(import.meta.dirname, file)).isFile(),
19+
),
1920
})
2021
}
2122

@@ -24,7 +25,9 @@ export const handler = ({ rwVersion }: { rwVersion: string }) => {
2425

2526
console.log()
2627

27-
const modsForVersion = fs.readdirSync(path.join(__dirname, rwVersion))
28+
const modsForVersion = fs.readdirSync(
29+
path.join(import.meta.dirname, rwVersion),
30+
)
2831

2932
modsForVersion.forEach((codemod) => {
3033
// Use decamelize to match the usual yargs names,

packages/codemods/src/codemods/redwood/v2.3.x/tsconfigForRouteHooks/__tests__/tsconfigForRouteHooks.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it } from 'vitest'
22

3-
import { matchFolderTransform } from '../../../../../testUtils/matchFolderTransform'
4-
import addApiAliasToTsConfig from '../tsconfigForRouteHooks'
3+
import { matchFolderTransform } from '../../../../../testUtils/matchFolderTransform.js'
4+
import addApiAliasToTsConfig from '../tsconfigForRouteHooks.js'
55

66
describe('tsconfigForRouteHooks', () => {
77
it('Adds $api to web/tsconfig.json', async () => {

packages/codemods/src/codemods/redwood/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getPaths } from '@cedarjs/project-config'
22

3-
import prettify from '../../../../lib/prettify'
3+
import prettify from '../../../../lib/prettify.js'
44

55
export default async function addApiAliasToTsConfig() {
66
// Ts is a heavy import, lets do it dynamically

packages/codemods/src/codemods/redwood/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.yargs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import task from 'tasuku'
22

3-
import addApiAliasToTsConfig from './tsconfigForRouteHooks'
3+
import addApiAliasToTsConfig from './tsconfigForRouteHooks.js'
44

55
export const command = 'tsconfig-for-route-hooks'
66
export const description =

packages/codemods/src/codemods/redwood/v2.x.x/configureFastify/__tests__/configureFastify.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it } from 'vitest'
22

3-
import { matchTransformSnapshot } from '../../../../../testUtils/matchTransformSnapshot'
3+
import { matchTransformSnapshot } from '../../../../../testUtils/matchTransformSnapshot.js'
44

55
describe('configureFastify', () => {
66
it('Converts module.exports to { config }', async () => {

packages/codemods/src/codemods/redwood/v2.x.x/configureFastify/configureFastify.yargs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import task from 'tasuku'
77

88
import { getPaths } from '@cedarjs/project-config'
99

10-
import prettify from '../../../../lib/prettify'
11-
import runTransform from '../../../../lib/runTransform'
10+
import prettify from '../../../../lib/prettify.js'
11+
import runTransform from '../../../../lib/runTransform.js'
1212

1313
export const command = 'configure-fastify'
1414
export const description =
@@ -23,7 +23,7 @@ export const handler = () => {
2323

2424
if (fs.existsSync(API_SERVER_CONFIG_PATH)) {
2525
await runTransform({
26-
transformPath: path.join(__dirname, 'configureFastify.js'),
26+
transformPath: path.join(import.meta.dirname, 'configureFastify.js'),
2727
targetPaths: [API_SERVER_CONFIG_PATH],
2828
})
2929

packages/codemods/src/codemods/redwood/v2.x.x/updateResolverTypes/__tests__/updateResolverTypes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it } from 'vitest'
22

3-
import { matchTransformSnapshot } from '../../../../../testUtils/matchTransformSnapshot'
3+
import { matchTransformSnapshot } from '../../../../../testUtils/matchTransformSnapshot.js'
44

55
describe('updateResolverTypes', () => {
66
it('Converts PostResolvers to PostRelationResolvers>', async () => {

0 commit comments

Comments
 (0)