Skip to content

Commit b859a70

Browse files
authored
chore(esm): Convert the structure package to ESM only (#1391)
1 parent b68afcd commit b859a70

31 files changed

+239
-189
lines changed

packages/cli/src/commands/check.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ export const description =
1111
export const handler = async () => {
1212
recordTelemetryAttributes({ command: 'check' })
1313

14-
const { printDiagnostics } = await import('@cedarjs/structure')
15-
// @ts-expect-error - babel-compiler enum issue. Keeping this as a separate
16-
// import to preserve type information for printDiagnostics
17-
const { DiagnosticSeverity } = (await import('@cedarjs/structure')).default
14+
const { printDiagnostics, DiagnosticSeverity } =
15+
await import('@cedarjs/structure')
1816

1917
printDiagnostics({
2018
getSeverityLabel: (severity) => {

packages/cli/src/telemetry/resource.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ export async function getResources() {
7474
const experiments = Object.keys(getRawConfig()['experimental'] || {})
7575

7676
// Project complexity metric
77-
const project = new RWProject({
78-
projectRoot: getPaths().base,
79-
})
77+
const project = new RWProject()
8078

8179
const routes = project.getRouter().routes
8280
const prerenderedRoutes = routes.filter((route) => route.hasPrerender)

packages/structure/.babelrc.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/structure/package.json

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,67 @@
88
"directory": "packages/structure"
99
},
1010
"license": "MIT",
11+
"type": "module",
12+
"exports": {
13+
".": {
14+
"types": "./dist/index.d.ts",
15+
"default": "./dist/index.js"
16+
},
17+
"./dist/index.js": {
18+
"types": "./dist/index.d.ts",
19+
"default": "./dist/index.js"
20+
},
21+
"./dist/model/RWProject": {
22+
"types": "./dist/model/RWProject.d.ts",
23+
"default": "./dist/model/RWProject.js"
24+
},
25+
"./dist/model/RWProject.js": {
26+
"types": "./dist/model/RWProject.d.ts",
27+
"default": "./dist/model/RWProject.js"
28+
},
29+
"./dist/model/RWRoute": {
30+
"types": "./dist/model/RWRoute.d.ts",
31+
"default": "./dist/model/RWRoute.js"
32+
},
33+
"./dist/model/RWRoute.js": {
34+
"types": "./dist/model/RWRoute.d.ts",
35+
"default": "./dist/model/RWRoute.js"
36+
},
37+
"./dist/model/RWPage.js": {
38+
"types": "./dist/model/RWPage.d.ts",
39+
"default": "./dist/model/RWPage.js"
40+
}
41+
},
1142
"main": "dist/index.js",
1243
"types": "./dist/index.d.ts",
1344
"files": [
1445
"dist"
1546
],
1647
"scripts": {
17-
"build": "yarn build:js && yarn build:types",
18-
"build:js": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx\"",
48+
"build": "tsc -p tsconfig.json",
1949
"build:pack": "yarn pack -o cedarjs-structure.tgz",
20-
"build:types": "tsc --build --verbose",
21-
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"",
50+
"build:watch": "tsc -p tsconfig.json --watch",
2251
"prepublishOnly": "NODE_ENV=production yarn build",
2352
"prettier": "prettier --write './src/**/*.{ts,tsx}'",
2453
"test": "vitest run",
2554
"test:watch": "vitest watch"
2655
},
2756
"dependencies": {
28-
"@babel/runtime-corejs3": "7.29.0",
2957
"@cedarjs/project-config": "workspace:*",
3058
"@prisma/internals": "7.5.0",
3159
"@types/line-column": "1.0.2",
3260
"camelcase": "6.3.0",
33-
"core-js": "3.48.0",
3461
"deepmerge": "4.3.1",
3562
"dotenv-defaults": "5.0.2",
36-
"enquirer": "2.4.1",
3763
"graphql": "16.13.1",
38-
"lazy-get-decorator": "2.2.1",
3964
"line-column": "1.0.2",
4065
"lodash": "4.17.23",
41-
"lodash-decorators": "6.0.1",
4266
"lru-cache": "11.2.7",
4367
"smol-toml": "1.6.0",
4468
"ts-morph": "23.0.0",
4569
"yargs-parser": "21.1.1"
4670
},
4771
"devDependencies": {
48-
"@babel/cli": "7.28.6",
49-
"@babel/core": "^7.26.10",
5072
"@types/lodash": "4.17.24",
5173
"@types/node": "24.10.4",
5274
"typescript": "5.9.3",

packages/structure/src/index.ts

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

3-
export { DiagnosticSeverity } from './x/diagnostics'
4-
export { RWProject, RWRoute } from './model'
5-
export { URL_file } from './x/URL'
6-
import { RWProject } from './model'
7-
import type { GetSeverityLabelFunction } from './x/diagnostics'
8-
import { ExtendedDiagnostic_format, DiagnosticSeverity } from './x/diagnostics'
3+
export { DiagnosticSeverity } from './x/diagnostics.js'
4+
export { RWProject, RWRoute } from './model/index.js'
5+
export { URL_file } from './x/URL.js'
6+
import { RWProject } from './model/index.js'
7+
import type { GetSeverityLabelFunction } from './x/diagnostics.js'
8+
import {
9+
ExtendedDiagnostic_format,
10+
DiagnosticSeverity,
11+
} from './x/diagnostics.js'
912

1013
export function getProject() {
1114
return new RWProject()

packages/structure/src/model/RWCell.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Kind, parse as parseGraphQL } from 'graphql'
22
import * as tsm from 'ts-morph'
33

4-
import { lazy } from '../x/decorators'
5-
import { err, Range_fromNode } from '../x/diagnostics'
6-
import { DiagnosticSeverity } from '../x/diagnostics'
4+
import { lazy } from '../x/decorators.js'
5+
import { err, Range_fromNode } from '../x/diagnostics.js'
6+
import { DiagnosticSeverity } from '../x/diagnostics.js'
77

8-
import { RWComponent } from './RWComponent'
8+
import { RWComponent } from './RWComponent.js'
99

1010
export class RWCell extends RWComponent {
1111
/**

packages/structure/src/model/RWComponent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as tsm from 'ts-morph'
22

3-
import { FileNode } from '../nodes'
4-
import { lazy } from '../x/decorators'
3+
import { FileNode } from '../nodes.js'
4+
import { lazy } from '../x/decorators.js'
55

6-
import type { RWProject } from './RWProject'
6+
import type { RWProject } from './RWProject.js'
77

88
export class RWComponent extends FileNode {
99
constructor(

packages/structure/src/model/RWEnvHelper.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import type * as tsm from 'ts-morph'
77

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

10-
import { BaseNode } from '../nodes'
11-
import { lazy } from '../x/decorators'
12-
import type { ExtendedDiagnostic } from '../x/diagnostics'
10+
import { BaseNode } from '../nodes.js'
11+
import { lazy } from '../x/decorators.js'
12+
import type { ExtendedDiagnostic } from '../x/diagnostics.js'
1313
import {
1414
LocationLike_toHashLink,
1515
LocationLike_toLocation,
16-
} from '../x/diagnostics'
17-
import { DiagnosticSeverity } from '../x/diagnostics'
18-
import type { Location } from '../x/Location'
19-
import { prisma_parseEnvExpressionsInFile } from '../x/prisma'
16+
} from '../x/diagnostics.js'
17+
import { DiagnosticSeverity } from '../x/diagnostics.js'
18+
import type { Location } from '../x/Location.js'
19+
import { prisma_parseEnvExpressionsInFile } from '../x/prisma.js'
2020

21-
import type { RWProject } from './RWProject'
22-
import { process_env_findAll } from './util/process_env'
21+
import type { RWProject } from './RWProject.js'
22+
import { process_env_findAll } from './util/process_env.js'
2323

2424
type EnvVarMap = Record<string, string>
2525

packages/structure/src/model/RWFunction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FileNode } from '../nodes'
1+
import { FileNode } from '../nodes.js'
22

3-
import type { RWProject } from './RWProject'
3+
import type { RWProject } from './RWProject.js'
44
/**
55
* functions exist in the /functions folder
66
*/

packages/structure/src/model/RWLayout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FileNode } from '../nodes'
1+
import { FileNode } from '../nodes.js'
22

3-
import type { RWProject } from './RWProject'
3+
import type { RWProject } from './RWProject.js'
44
/**
55
* layouts live in the src/layouts folder
66
*/

0 commit comments

Comments
 (0)