Skip to content

Commit bb8d9ae

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

File tree

12 files changed

+55
-51
lines changed

12 files changed

+55
-51
lines changed

guides/esm-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
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**
40-
- [ ] packages/error **PARTIAL** - entry point is JS
40+
- [x] packages/error **COMPLETED**
4141
- [x] packages/eslint-config ✅ **COMPLETED**
4242
- [ ] packages/example
4343
- [ ] packages/extension

packages/errors/.gitignore

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

packages/errors/index.js

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

packages/errors/package.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22
"name": "@packages/errors",
33
"version": "0.0.0-development",
44
"description": "Error definitions and utilities for Cypress",
5-
"main": "index.js",
6-
"browser": "src/index.ts",
5+
"main": "cjs/index.js",
6+
"module": "esm/index.js",
7+
"browser": "esm/index.js",
8+
"files": [
9+
"cjs/*",
10+
"esm/*"
11+
],
12+
"types": "src/index.ts",
713
"scripts": {
8-
"build": "../../scripts/run-if-ci.sh tsc || echo 'type errors'",
9-
"build-prod": "tsc",
10-
"check-ts": "tsc --noEmit && yarn -s tslint",
11-
"clean": "rimraf --glob './src/*.js' './src/**/*.js' './src/**/**/*.js' './test/**/*.js' || echo 'cleaned'",
12-
"clean-deps": "rimraf node_modules",
14+
"build": "yarn build:esm && yarn build:cjs",
15+
"build-prod": "yarn build",
16+
"build:cjs": "rimraf cjs && tsc -p tsconfig.cjs.json",
17+
"build:esm": "rimraf esm && tsc -p tsconfig.esm.json",
18+
"check-ts": "tsc -p tsconfig.cjs.json --noEmit && yarn -s tslint -p tsconfig.cjs.json",
19+
"clean": "rimraf cjs esm",
1320
"lint": "eslint",
14-
"pretest": "yarn clean",
1521
"test": "yarn test-unit",
16-
"posttest": "yarn build",
1722
"test-unit": "vitest run",
1823
"test-debug": "vitest --inspect-brk --no-file-parallelism --test-timeout=0",
1924
"tslint": "tslint --config ../ts/tslint.json --project ."
@@ -31,8 +36,6 @@
3136
"@packages/server": "0.0.0-development",
3237
"@packages/ts": "0.0.0-development",
3338
"@packages/types": "0.0.0-development",
34-
"@types/chai": "4.2.15",
35-
"@types/mocha": "8.2.2",
3639
"@types/node": "22.18.0",
3740
"@types/pngjs": "^6.0.1",
3841
"ansi-styles": "^5",
@@ -45,11 +48,6 @@
4548
"vitest": "^3.2.4",
4649
"xvfb-maybe": "^0.2.1"
4750
},
48-
"files": [
49-
"src",
50-
"dist"
51-
],
52-
"types": "src/index.ts",
5351
"lint-staged": {
5452
"**/*.{js,jsx,ts,tsx,json}": "eslint --fix"
5553
},

packages/errors/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ export const getError = function <Type extends keyof AllCypressErrorObj> (type:
15721572
return err
15731573
}
15741574

1575-
export const logWarning = function <Type extends keyof AllCypressErrorObj> (type: Type, ...args: Parameters<AllCypressErrorObj[Type]>) {
1575+
export const logWarning = function <Type extends keyof AllCypressErrorObj> (type: Type, ...args: Parameters<AllCypressErrorObj[Type]>): null {
15761576
const err = getError(type, ...args)
15771577

15781578
logError(err, 'magenta')

packages/errors/test/visualSnapshotErrors.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('visual error templates', () => {
9999

100100
const consoleLogOutput = getConsoleLogOutput()
101101

102-
expect(consoleLogOutput).toMatchFileSnapshot(`./__snapshots__/${filename}.ansi`)
102+
await expect(consoleLogOutput).toMatchFileSnapshot(`./__snapshots__/${filename}.ansi`)
103103
})
104104
}
105105
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"extends": "../ts/tsconfig.json",
32
"include": [
43
"src",
54
],
@@ -8,5 +7,8 @@
87
"noImplicitAny": true,
98
"noImplicitReturns": false,
109
"noUncheckedIndexedAccess": true,
10+
"skipLibCheck": true,
11+
"resolveJsonModule": true,
12+
"esModuleInterop": true
1113
}
1214
}

packages/errors/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/errors/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+
}

packages/server/lib/cloud/exception.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import _ from 'lodash'
2-
const Promise = require('bluebird')
3-
const pkg = require('@packages/root')
4-
const api = require('./api').default
5-
const user = require('./user')
6-
const system = require('../util/system')
7-
const { stripPath } = require('./strip_path')
2+
import Bluebird from 'bluebird'
3+
import pkg from '@packages/root'
4+
import api from './api'
5+
import user from './user'
6+
import system from '../util/system'
7+
import { stripPath } from './strip_path'
88

99
export = {
1010
getErr (err: Error) {
1111
return {
1212
name: stripPath(err.name),
1313
message: stripPath(err.message),
14-
stack: stripPath(err.stack),
14+
stack: stripPath(err.stack as string),
1515
}
1616
},
1717

@@ -42,7 +42,7 @@ export = {
4242
}
4343

4444
try {
45-
const [body, authToken] = await Promise.all([
45+
const [body, authToken] = await Bluebird.all([
4646
this.getBody(err),
4747
this.getAuthToken(),
4848
])

0 commit comments

Comments
 (0)