Skip to content

Commit bb4def8

Browse files
committed
chore: make the @packages/data-context an independent bundle without needed ts-node to register entrypoint. Both ESM and CJS distributions are built and types are used as source to be compatible with older styles of commonjs bundling. Types are not shipped with the package.
1 parent ddbbe22 commit bb4def8

File tree

11 files changed

+71
-37
lines changed

11 files changed

+71
-37
lines changed

guides/esm-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
3838

3939
- [ ] packages/app **PARTIAL** - low priority: frontend package
4040
- [x] packages/config ✅ **COMPLETED**
41-
- [ ] packages/data-context **PARTIAL** - entry point is JS
41+
- [x] packages/data-context **COMPLETED**
4242
- [x] packages/driver ✅ **COMPLETED** - source complete, cypress tests need migration
4343
- [x] packages/electron ✅ **COMPLETED**
4444
- [x] packages/error ✅ **COMPLETED**

packages/data-context/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cjs/
2+
esm/

packages/data-context/index.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/data-context/package.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"name": "@packages/data-context",
33
"version": "0.0.0-development",
44
"description": "Centralized data access for the Cypress application",
5-
"main": "index.js",
6-
"browser": "src/index.ts",
5+
"main": "cjs/index.js",
76
"scripts": {
8-
"build": "node ./scripts/build.js",
9-
"build-prod": "tsc || echo 'built, with errors'",
10-
"check-ts": "tsc --noEmit && yarn -s tslint",
11-
"clean": "rimraf --glob \"./{src,test}/**/*.js\"",
7+
"build": "yarn build:schema && yarn build:cjs && yarn build:esm",
8+
"build-prod": "yarn build",
9+
"build:cjs": "rimraf cjs && tsc -p tsconfig.cjs.json",
10+
"build:esm": "rimraf esm && tsc -p tsconfig.esm.json",
11+
"build:schema": "tsx ./scripts/build.ts",
12+
"check-ts": "tsc -p tsconfig.cjs.json --noEmit && yarn -s tslint -p tsconfig.cjs.json",
13+
"clean": "rimraf esm cjs",
1214
"clean-deps": "rimraf node_modules",
1315
"lint": "eslint --ext .js,.ts,.json, .",
1416
"test": "yarn test-unit",
@@ -95,14 +97,19 @@
9597
"mocha-junit-reporter": "2.2.0",
9698
"mocha-multi-reporters": "1.5.1",
9799
"nexus": "^1.2.0-next.15",
100+
"rimraf": "6.0.1",
98101
"sinon": "13.0.2",
99102
"sinon-chai": "3.7.0",
100-
"tslint": "^6.1.3"
103+
"tslint": "^6.1.3",
104+
"tsx": "4.20.5",
105+
"typescript": "5.9.2"
101106
},
102107
"files": [
103-
"src"
108+
"cjs/*",
109+
"esm/*"
104110
],
105111
"types": "src/index.ts",
112+
"module": "esm/index.js",
106113
"nx": {
107114
"targets": {
108115
"build": {

packages/data-context/scripts/build.js renamed to packages/data-context/scripts/build.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const fs = require('fs-extra')
2-
const { buildSchema, introspectionFromSchema } = require('graphql')
3-
const path = require('path')
4-
const { minifyIntrospectionQuery } = require('@urql/introspection')
1+
import fs from 'fs-extra'
2+
import { buildSchema, introspectionFromSchema } from 'graphql'
3+
import path from 'path'
4+
import { minifyIntrospectionQuery } from '@urql/introspection'
55

66
const graphQlPackageRoot = path.join(__dirname, '..', '..', 'graphql')
77
const dataContextRoot = path.join(__dirname, '..')

packages/data-context/src/actions/DataEmitterActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class DataEmitterActions extends DataEmitterEvents {
310310
[Symbol.asyncIterator] () {
311311
return iterator
312312
},
313-
}
313+
} as unknown as AsyncGenerator<T>
314314

315315
return iterator
316316
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"include": [
3+
"src"
4+
],
5+
"exclude": [
6+
"src/gen"
7+
],
8+
"compilerOptions": {
9+
"lib": [
10+
"esnext"
11+
],
12+
"allowJs": false,
13+
"noImplicitAny": true,
14+
"noUncheckedIndexedAccess": true,
15+
"resolveJsonModule": true,
16+
"skipLibCheck": true,
17+
"types": [
18+
"cypress",
19+
"mocha",
20+
"node"
21+
],
22+
"esModuleInterop": true,
23+
"forceConsistentCasingInFileNames": true,
24+
"strict": true,
25+
"useUnknownInCatchVariables": false
26+
}
27+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"outDir": "./cjs",
6+
"target": "ES2022",
7+
"module": "CommonJS",
8+
"moduleResolution": "node"
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"outDir": "./esm",
6+
"target": "ES2022",
7+
"module": "ES2022",
8+
"moduleResolution": "node"
9+
}
10+
}

packages/data-context/tsconfig.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)