Skip to content

Commit 2e81887

Browse files
authored
chore: make the @packages/config 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. (#32612)
1 parent bb8d9ae commit 2e81887

File tree

12 files changed

+60
-38
lines changed

12 files changed

+60
-38
lines changed

guides/esm-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
##### Binary Packages
3434

3535
- [ ] packages/app **PARTIAL** - low priority: frontend package
36-
- [ ] packages/config **PARTIAL** - entry point is JS
36+
- [x] packages/config **COMPLETED**
3737
- [ ] packages/data-context **PARTIAL** - entry point is JS
3838
- [x] packages/driver ✅ **COMPLETED** - source complete, cypress tests need migration
3939
- [x] packages/electron ✅ **COMPLETED**

packages/config/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
**/cjs
2+
**/esm
13
**/dist
24
**/*.d.ts
35
**/package-lock.json

packages/config/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
src/**/*.js
1+
cjs/
2+
esm/

packages/config/index.js

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

packages/config/package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
"version": "0.0.0-development",
44
"description": "Config contains the configuration types and validation function used in the cypress electron application.",
55
"private": true,
6-
"main": "index.js",
7-
"browser": "src/browser.ts",
6+
"main": "cjs/index.js",
7+
"browser": "esm/browser.js",
88
"scripts": {
9-
"build-prod": "tsc || echo 'built, with errors'",
10-
"check-ts": "tsc --noEmit && yarn -s tslint",
11-
"clean": "rimraf --glob './src/*.js' './src/**/*.js' './src/**/**/*.js' './test/!**__fixtures__**/**/*.js' || echo 'cleaned'",
9+
"build": "yarn build:esm && yarn build:cjs",
10+
"build-prod": "yarn build",
11+
"build:cjs": "rimraf cjs && tsc -p tsconfig.cjs.json",
12+
"build:esm": "rimraf esm && tsc -p tsconfig.esm.json",
13+
"check-ts": "tsc -p tsconfig.cjs.json --noEmit && yarn -s tslint -p tsconfig.cjs.json",
14+
"clean": "rimraf cjs esm",
1215
"clean-deps": "rimraf node_modules",
1316
"lint": "eslint --ext .js,.ts,.json, .",
1417
"test": "yarn test-unit",
@@ -42,11 +45,14 @@
4245
"@packages/ts": "0.0.0-development",
4346
"@packages/types": "0.0.0-development",
4447
"babel-plugin-tester": "^10.1.0",
48+
"rimraf": "6.0.1",
4549
"vitest": "^3.2.4"
4650
},
4751
"files": [
48-
"src"
52+
"cjs/*",
53+
"esm/*"
4954
],
5055
"types": "src/index.ts",
56+
"module": "esm/index.js",
5157
"nx": {}
5258
}

packages/config/src/ast-utils/addToCypressConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function addToCypressConfig (filePath: string, code: string, toAdd:
4949
traverse(ast, addToCypressConfigPlugin(toAdd).visitor)
5050

5151
return print(ast).code
52-
} catch (e) {
52+
} catch (e: any) {
5353
debug(`Error adding properties to %s: %s`, filePath, e.stack)
5454
throw new Error(`Unable to automerge with the config file`)
5555
}
@@ -125,7 +125,7 @@ export async function addTestingTypeToCypressConfig (options: AddTestingTypeToCy
125125
return {
126126
result: resultStatus,
127127
}
128-
} catch (e) {
128+
} catch (e: any) {
129129
return {
130130
result: 'NEEDS_MERGE',
131131
error: e,

packages/config/src/options.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os from 'os'
22
import path from 'path'
3-
4-
// @ts-ignore
53
import pkg from '@packages/root'
64
import type { AllCypressErrorNames } from '@packages/errors'
75
import type { TestingType } from '@packages/types'
@@ -485,7 +483,7 @@ const runtimeOptions: Array<RuntimeConfigOption> = [
485483
// having the final config that has the e2e property flattened/compacted
486484
// we may not be able to get the value to ignore.
487485
name: 'additionalIgnorePattern',
488-
defaultValue: (options: Record<string, any> = {}) => options.testingType === 'component' ? defaultSpecPattern.e2e : [],
486+
defaultValue: (options: Record<string, any> = {}): string | any[] => options.testingType === 'component' ? defaultSpecPattern.e2e : [],
489487
validation: validate.isStringOrArrayOfStrings,
490488
isInternal: true,
491489
}, {

packages/config/test/project/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import {
2020
setSupportFileAndFolder,
2121
mergeDefaults,
2222
} from '../../src/project/utils'
23+
import { resetIssuedWarnings } from '../../src/browser'
2324
import path from 'node:path'
2425
import { Config } from '../../src/project/types'
25-
import { resetIssuedWarnings } from '../../src/browser'
2626

2727
const debug = Debug('test')
2828

packages/config/tsconfig.base.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"include": [
3+
"src/*.ts"
4+
],
5+
"exclude": [
6+
"test"
7+
],
8+
"compilerOptions": {
9+
"strict": true,
10+
"noImplicitAny": true,
11+
"esModuleInterop": true,
12+
"noUncheckedIndexedAccess": true,
13+
"skipLibCheck": true,
14+
"resolveJsonModule": true,
15+
"types": [
16+
"node"
17+
]
18+
}
19+
}

packages/config/tsconfig.cjs.json

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+
}

0 commit comments

Comments
 (0)