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)

This commit is contained in:
Bill Glesias
2025-10-01 15:45:44 -04:00
committed by GitHub
parent 2cf1b06bf6
commit bb8d9aebda
12 changed files with 55 additions and 51 deletions

View File

@@ -37,7 +37,7 @@
- [ ] packages/data-context **PARTIAL** - entry point is JS
- [x] packages/driver ✅ **COMPLETED** - source complete, cypress tests need migration
- [x] packages/electron ✅ **COMPLETED**
- [ ] packages/error **PARTIAL** - entry point is JS
- [x] packages/error **COMPLETED**
- [x] packages/eslint-config ✅ **COMPLETED**
- [ ] packages/example
- [ ] packages/extension

2
packages/errors/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
cjs
esm

View File

@@ -1,12 +0,0 @@
// The errors package is always compiled in a production build, but when we're developing locally,
// there's a chance we can run into a situation where we're requiring the
// @packages/errors from the child process in a non-ts project, and we need to build this JIT.
// Otherwise the error will incorrectly be shown as "cannot find module ./src" instead of
// the actual error. Double check that we can require './src', and if not install ts-node
try {
require.resolve('./src')
} catch (e) {
require('@packages/ts/register')
}
module.exports = require('./src')

View File

@@ -2,18 +2,23 @@
"name": "@packages/errors",
"version": "0.0.0-development",
"description": "Error definitions and utilities for Cypress",
"main": "index.js",
"browser": "src/index.ts",
"main": "cjs/index.js",
"module": "esm/index.js",
"browser": "esm/index.js",
"files": [
"cjs/*",
"esm/*"
],
"types": "src/index.ts",
"scripts": {
"build": "../../scripts/run-if-ci.sh tsc || echo 'type errors'",
"build-prod": "tsc",
"check-ts": "tsc --noEmit && yarn -s tslint",
"clean": "rimraf --glob './src/*.js' './src/**/*.js' './src/**/**/*.js' './test/**/*.js' || echo 'cleaned'",
"clean-deps": "rimraf node_modules",
"build": "yarn build:esm && yarn build:cjs",
"build-prod": "yarn build",
"build:cjs": "rimraf cjs && tsc -p tsconfig.cjs.json",
"build:esm": "rimraf esm && tsc -p tsconfig.esm.json",
"check-ts": "tsc -p tsconfig.cjs.json --noEmit && yarn -s tslint -p tsconfig.cjs.json",
"clean": "rimraf cjs esm",
"lint": "eslint",
"pretest": "yarn clean",
"test": "yarn test-unit",
"posttest": "yarn build",
"test-unit": "vitest run",
"test-debug": "vitest --inspect-brk --no-file-parallelism --test-timeout=0",
"tslint": "tslint --config ../ts/tslint.json --project ."
@@ -31,8 +36,6 @@
"@packages/server": "0.0.0-development",
"@packages/ts": "0.0.0-development",
"@packages/types": "0.0.0-development",
"@types/chai": "4.2.15",
"@types/mocha": "8.2.2",
"@types/node": "22.18.0",
"@types/pngjs": "^6.0.1",
"ansi-styles": "^5",
@@ -45,11 +48,6 @@
"vitest": "^3.2.4",
"xvfb-maybe": "^0.2.1"
},
"files": [
"src",
"dist"
],
"types": "src/index.ts",
"lint-staged": {
"**/*.{js,jsx,ts,tsx,json}": "eslint --fix"
},

View File

@@ -1572,7 +1572,7 @@ export const getError = function <Type extends keyof AllCypressErrorObj> (type:
return err
}
export const logWarning = function <Type extends keyof AllCypressErrorObj> (type: Type, ...args: Parameters<AllCypressErrorObj[Type]>) {
export const logWarning = function <Type extends keyof AllCypressErrorObj> (type: Type, ...args: Parameters<AllCypressErrorObj[Type]>): null {
const err = getError(type, ...args)
logError(err, 'magenta')

View File

@@ -99,7 +99,7 @@ describe('visual error templates', () => {
const consoleLogOutput = getConsoleLogOutput()
expect(consoleLogOutput).toMatchFileSnapshot(`./__snapshots__/${filename}.ansi`)
await expect(consoleLogOutput).toMatchFileSnapshot(`./__snapshots__/${filename}.ansi`)
})
}
}

View File

@@ -1,5 +1,4 @@
{
"extends": "../ts/tsconfig.json",
"include": [
"src",
],
@@ -8,5 +7,8 @@
"noImplicitAny": true,
"noImplicitReturns": false,
"noUncheckedIndexedAccess": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"esModuleInterop": true
}
}

View File

@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./cjs",
"target": "ES2022",
"module": "CommonJS",
"moduleResolution": "node"
}
}

View File

@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./esm",
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "node"
}
}

View File

@@ -1,17 +1,17 @@
import _ from 'lodash'
const Promise = require('bluebird')
const pkg = require('@packages/root')
const api = require('./api').default
const user = require('./user')
const system = require('../util/system')
const { stripPath } = require('./strip_path')
import Bluebird from 'bluebird'
import pkg from '@packages/root'
import api from './api'
import user from './user'
import system from '../util/system'
import { stripPath } from './strip_path'
export = {
getErr (err: Error) {
return {
name: stripPath(err.name),
message: stripPath(err.message),
stack: stripPath(err.stack),
stack: stripPath(err.stack as string),
}
},
@@ -42,7 +42,7 @@ export = {
}
try {
const [body, authToken] = await Promise.all([
const [body, authToken] = await Bluebird.all([
this.getBody(err),
this.getAuthToken(),
])

View File

@@ -1,6 +0,0 @@
#!/bin/bash
# If we're in CI, exit early
if [[ $CI == '' ]]; then exit 0; fi
# otherwise, run the supplied command
"${@:1}"

View File

@@ -8570,11 +8570,6 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.0.3.tgz#51b21b6acb6d1b923bbdc7725c38f9f455166402"
integrity sha512-vyxR57nv8NfcU0GZu8EUXZLTbCMupIUwy95LJ6lllN+JRPG25CwMHoB1q5xKh8YKhQnHYRAn4yW2yuHbf/5xgg==
"@types/mocha@8.2.2", "@types/mocha@^8.0.2", "@types/mocha@^8.0.3":
version "8.2.2"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.2.2.tgz#91daa226eb8c2ff261e6a8cbf8c7304641e095e0"
integrity sha512-Lwh0lzzqT5Pqh6z61P3c3P5nm6fzQK/MMHl9UKeneAeInVflBSz1O2EkX6gM6xfJd7FBXBY5purtLx7fUiZ7Hw==
"@types/mocha@9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.0.0.tgz#3205bcd15ada9bc681ac20bef64e9e6df88fd297"
@@ -8585,6 +8580,11 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.1.0.tgz#baf17ab2cca3fcce2d322ebc30454bff487efad5"
integrity sha512-QCWHkbMv4Y5U9oW10Uxbr45qMMSzl4OzijsozynUAgx3kEHUdXB00udx2dWDQ7f2TU2a2uuiFaRZjCe3unPpeg==
"@types/mocha@^8.0.2", "@types/mocha@^8.0.3":
version "8.2.2"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.2.2.tgz#91daa226eb8c2ff261e6a8cbf8c7304641e095e0"
integrity sha512-Lwh0lzzqT5Pqh6z61P3c3P5nm6fzQK/MMHl9UKeneAeInVflBSz1O2EkX6gM6xfJd7FBXBY5purtLx7fUiZ7Hw==
"@types/ms@*":
version "0.7.31"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"