Skip to content

Commit 20f2acc

Browse files
committed
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.
1 parent 73cb5d9 commit 20f2acc

File tree

8 files changed

+41
-28
lines changed

8 files changed

+41
-28
lines changed

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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
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
"comparison": "node -r @packages/ts/register test/support/error-comparison-tool.ts",
1421
"lint": "eslint",
1522
"test": "yarn test-unit",
@@ -48,11 +55,6 @@
4855
"terminal-banner": "^1.1.0",
4956
"xvfb-maybe": "^0.2.1"
5057
},
51-
"files": [
52-
"src",
53-
"dist"
54-
],
55-
"types": "src/index.ts",
5658
"lint-staged": {
5759
"**/*.{js,jsx,ts,tsx,json}": "eslint --fix"
5860
},

packages/errors/src/errors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,6 @@ export const AllCypressErrors = {
15531553
},
15541554
} as const
15551555

1556-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
15571556
const _typeCheck: Record<keyof AllCypressErrorObj, (...args: any[]) => ErrTemplateResult> = AllCypressErrors
15581557

15591558
export type AllCypressErrorObj = typeof AllCypressErrors
@@ -1608,7 +1607,7 @@ export const getError = function <Type extends keyof AllCypressErrorObj> (type:
16081607
return err
16091608
}
16101609

1611-
export const logWarning = function <Type extends keyof AllCypressErrorObj> (type: Type, ...args: Parameters<AllCypressErrorObj[Type]>) {
1610+
export const logWarning = function <Type extends keyof AllCypressErrorObj> (type: Type, ...args: Parameters<AllCypressErrorObj[Type]>): null {
16121611
const err = getError(type, ...args)
16131612

16141613
logError(err, 'magenta')
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/types/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import semverMajor from 'semver/functions/major'
2-
import packageInfo from '../../../package.json'
2+
import packageInfo from '@packages/root'
33

44
import type { SpecFile } from './spec'
55

0 commit comments

Comments
 (0)