Skip to content

Commit d1e749d

Browse files
committed
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.
1 parent ae864b8 commit d1e749d

File tree

11 files changed

+66
-36
lines changed

11 files changed

+66
-36
lines changed

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'",
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",
1013
"check-ts": "tsc --noEmit && yarn -s tslint",
11-
"clean": "rimraf --glob './src/*.js' './src/**/*.js' './src/**/**/*.js' './test/!**__fixtures__**/**/*.js' || echo 'cleaned'",
14+
"clean": "rimraf cjs esm",
1215
"clean-deps": "rimraf node_modules",
1316
"lint": "eslint --ext .js,.ts,.json, .",
1417
"test": "yarn test-unit",
@@ -45,11 +48,14 @@
4548
"@types/mocha": "9.1.0",
4649
"babel-plugin-tester": "^10.1.0",
4750
"chai": "4.2.0",
48-
"mocha": "7.0.1"
51+
"mocha": "7.0.1",
52+
"rimraf": "6.0.1"
4953
},
5054
"files": [
51-
"src"
55+
"cjs/*",
56+
"esm/*"
5257
],
5358
"types": "src/index.ts",
59+
"module": "esm/index.js",
5460
"nx": {}
5561
}

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import {
2222
setSupportFileAndFolder,
2323
mergeDefaults,
2424
} from '../../src/project/utils'
25+
import { resetIssuedWarnings } from '../../src/browser'
2526
import path from 'node:path'
2627

2728
const debug = Debug('test')
2829

2930
describe('config/src/project/utils', () => {
3031
beforeEach(function () {
3132
delete process.env.CYPRESS_COMMERCIAL_RECOMMENDATIONS
33+
resetIssuedWarnings()
3234
})
3335

3436
before(function () {

packages/config/tsconfig.base.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"include": [
3+
"src/*.ts"
4+
],
5+
"exclude": [
6+
"test"
7+
],
8+
"compilerOptions": {
9+
"strict": true,
10+
"noImplicitAny": true,
11+
"esModuleInterop": true,
12+
"noUnusedLocals": false,
13+
"noUnusedParameters": false,
14+
"allowJs": true,
15+
"noUncheckedIndexedAccess": true,
16+
"ignoreDeprecations": "5.0",
17+
"importsNotUsedAsValues": "error",
18+
"skipLibCheck": true,
19+
"resolveJsonModule": true,
20+
"types": [
21+
"mocha",
22+
"node"
23+
]
24+
}
25+
}

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

packages/config/tsconfig.esm.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": "./esm",
6+
"target": "ES2022",
7+
"module": "ES2022",
8+
"moduleResolution": "node"
9+
}
10+
}

0 commit comments

Comments
 (0)