Skip to content

Commit 5201506

Browse files
committed
cut over runtime packages (not tests except npm packages) to tsx
1 parent b2b1e11 commit 5201506

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+108
-72
lines changed

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
require('@packages/ts/register')
1+
require('tsx/cjs')
22
require('./scripts/gulp/gulpfile')

npm/puppeteer/.mocharc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"watch-ignore": [
33
"node_modules"
44
],
5-
"require": "ts-node/register",
5+
"require": "tsx/cjs",
66
"exit": true
77
}

npm/puppeteer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"semantic-release": "22.0.12",
3131
"sinon": "^13.0.1",
3232
"sinon-chai": "^3.7.0",
33-
"ts-node": "^10.9.2",
33+
"tsx": "^4.19.3",
3434
"typescript": "5.4.5"
3535
},
3636
"peerDependencies": {

npm/puppeteer/test/unit/setup.spec.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { expect, use } from 'chai'
22
import chaiAsPromised from 'chai-as-promised'
3-
import type { PuppeteerNode, Browser } from 'puppeteer-core'
3+
import type { PuppeteerNode, Browser, Page } from 'puppeteer-core'
44
import sinon from 'sinon'
55
import sinonChai from 'sinon-chai'
66
import { MessageHandler } from '../../src/plugin/setup'
77
import { setup } from '../../src/plugin'
8-
import * as activateMainTabExport from '../../src/plugin/activateMainTab'
98

109
use(chaiAsPromised)
1110
use(sinonChai)
1211

1312
type StubbedMessageHandler = sinon.SinonStub<Parameters<MessageHandler>, ReturnType<MessageHandler>>
1413

1514
describe('#setup', () => {
15+
let mockPage: Partial<Page>
1616
let mockBrowser: Partial<Browser>
1717
let mockPuppeteer: Pick<PuppeteerNode, 'connect'>
1818
let on: sinon.SinonStub
@@ -30,9 +30,13 @@ describe('#setup', () => {
3030
}
3131

3232
beforeEach(() => {
33-
sinon.stub(activateMainTabExport, 'activateMainTab')
33+
mockPage = {
34+
evaluate: sinon.stub().resolves(),
35+
}
36+
3437
mockBrowser = {
3538
disconnect: sinon.stub().resolves(),
39+
pages: sinon.stub().resolves([mockPage]),
3640
}
3741

3842
mockPuppeteer = {
@@ -50,8 +54,6 @@ describe('#setup', () => {
5054

5155
afterEach(() => {
5256
sinon.reset()
53-
54-
;(activateMainTabExport.activateMainTab as sinon.SinonStub).restore()
5557
})
5658

5759
it('registers `after:browser:launch` and `task` handlers', () => {
@@ -229,19 +231,18 @@ describe('#setup', () => {
229231
)
230232
})
231233

232-
it('calls activateMainTab if there is a page in the browser', async () => {
233-
(activateMainTabExport.activateMainTab as sinon.SinonStub).withArgs(mockBrowser).resolves()
234+
it('calls page.evaluate() if there is a page in the browser', async () => {
234235
setup({ on, onMessage, puppeteer: mockPuppeteer as PuppeteerNode })
235236
const task = getTask()
236237

237238
simulateBrowserLaunch()
238239
await task({ name: testTask, args: [] })
239240

240-
expect(activateMainTabExport.activateMainTab).to.be.calledWith(mockBrowser)
241+
expect(mockPage.evaluate).to.be.calledWith(sinon.match.func, 2000)
241242
})
242243

243244
it('returns an error object if activateMainTab rejects', async () => {
244-
(activateMainTabExport.activateMainTab as sinon.SinonStub).withArgs(mockBrowser).rejects()
245+
mockBrowser.pages = sinon.stub().rejects(new Error('Failed to get pages'))
245246

246247
setup({ on, onMessage, puppeteer: mockPuppeteer as PuppeteerNode })
247248
simulateBrowserLaunch()
@@ -263,7 +264,7 @@ describe('#setup', () => {
263264

264265
await task({ name: testTask, args: [] })
265266

266-
expect(activateMainTabExport.activateMainTab).not.to.be.called
267+
expect(mockPage.evaluate).not.to.be.called
267268
})
268269

269270
it('does not try to activate main tab when the browser is electron', async () => {
@@ -272,7 +273,7 @@ describe('#setup', () => {
272273
const task = getTask()
273274

274275
await task({ name: testTask, args: [] })
275-
expect(activateMainTabExport.activateMainTab).not.to.be.called
276+
expect(mockPage.evaluate).not.to.be.called
276277
})
277278
})
278279

npm/vite-dev-server/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
1212
"lint": "eslint --ext .js,.ts,.json, .",
1313
"test": "yarn test-unit",
14-
"test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js",
14+
"test-unit": "mocha -r tsx/cjs --config ./test/.mocharc.js",
1515
"watch": "tsc -w"
1616
},
1717
"dependencies": {
@@ -26,7 +26,7 @@
2626
"dedent": "^0.7.0",
2727
"mocha": "^9.2.2",
2828
"sinon": "^13.0.1",
29-
"ts-node": "^10.9.2",
29+
"tsx": "^4.19.3",
3030
"vite-4": "npm:vite@^4.5.3",
3131
"vite-5": "npm:vite@^5.2.8",
3232
"vite-6": "npm:vite@^6.0.0",

npm/vite-dev-server/src/dynamic-import.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// is used (e.g. module=node16). To change this, we would also have to change the ts-node behavior when requiring the
33
// Cypress config file. This hack for keeping dynamic imports from being converted works across all
44
// of our supported node versions
5+
// TODO: IS THIS STILL VALID???
56
const _dynamicImport = new Function('specifier', 'return import(specifier)')
67

78
export const dynamicImport = <T>(module: string) => _dynamicImport(module) as Promise<T>

npm/webpack-dev-server/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dev": "tsc --watch",
1515
"lint": "eslint --ext .js,.ts,.json, .",
1616
"test": "yarn test-unit",
17-
"test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js"
17+
"test-unit": "mocha -r tsx/cjs --config ./test/.mocharc.js"
1818
},
1919
"dependencies": {
2020
"find-up": "6.3.0",
@@ -38,7 +38,7 @@
3838
"proxyquire": "2.1.3",
3939
"sinon": "^13.0.1",
4040
"snap-shot-it": "^7.9.6",
41-
"ts-node": "^10.9.2",
41+
"tsx": "^4.19.3",
4242
"webpack": "npm:webpack@^5",
4343
"webpack-4": "npm:webpack@^4",
4444
"webpack-dev-server-4": "npm:webpack-dev-server@^4"
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {}
1+
export {}

npm/webpack-preprocessor/.mocharc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"./test/_test-output",
44
"node_modules"
55
],
6-
"require": "ts-node/register",
6+
"require": "tsx/cjs",
77
"exit": true
88
}

npm/webpack-preprocessor/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as events from 'events'
55
import * as path from 'path'
66
import webpack from 'webpack'
77
import utils from './lib/utils'
8-
import { overrideSourceMaps } from './lib/typescript-overrides'
8+
import overrides from './lib/typescript-overrides'
99

1010
const debug = Debug('cypress:webpack')
1111
const debugStats = Debug('cypress:webpack:stats')
@@ -211,7 +211,7 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
211211
.tap((opts) => {
212212
if (opts.devtool === false) {
213213
// disable any overrides if we've explicitly turned off sourcemaps
214-
overrideSourceMaps(false, options.typescript)
214+
overrides.overrideSourceMaps(false, options.typescript)
215215

216216
return
217217
}
@@ -221,7 +221,7 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
221221
opts.devtool = 'inline-source-map'
222222

223223
// override typescript to always generate proper source maps
224-
overrideSourceMaps(true, options.typescript)
224+
overrides.overrideSourceMaps(true, options.typescript)
225225

226226
// To support dynamic imports, we have to disable any code splitting.
227227
debug('Limiting number of chunks to 1')

npm/webpack-preprocessor/lib/typescript-overrides.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const getProgramOptions = (rootNamesOrOptions: CreateProgramOptions, options: Co
99
return _.isArray(rootNamesOrOptions) ? options : rootNamesOrOptions.options
1010
}
1111

12-
export const overrideSourceMaps = (sourceMap: boolean, typescriptPath?: string) => {
12+
const overrideSourceMaps = (sourceMap: boolean, typescriptPath?: string) => {
1313
try {
1414
if (patched) {
1515
debug('typescript.createProgram() already overridden')
@@ -59,3 +59,7 @@ export const overrideSourceMaps = (sourceMap: boolean, typescriptPath?: string)
5959
return err
6060
}
6161
}
62+
63+
export default {
64+
overrideSourceMaps,
65+
}

npm/webpack-preprocessor/test/unit/index.spec.js renamed to npm/webpack-preprocessor/test/unit/index.spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
const chai = require('chai')
42
const mockery = require('mockery')
53
const Promise = require('bluebird')
@@ -23,7 +21,7 @@ mockery.enable({
2321
mockery.registerMock('webpack', webpack)
2422

2523
const preprocessor = require('../../index')
26-
const typescriptOverrides = require('../../lib/typescript-overrides')
24+
const typescriptOverrides = require('../../lib/typescript-overrides').default
2725

2826
describe('webpack preprocessor', function () {
2927
beforeEach(function () {

npm/webpack-preprocessor/test/unit/typescript-overrides.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('./lib/typescript-overrides', () => {
2121
it('it sets sourceMap: true', () => {
2222
const typescriptOverrides = proxyquire('../../lib/typescript-overrides', {
2323
typescript,
24-
})
24+
}).default
2525

2626
typescriptOverrides.overrideSourceMaps(true)
2727

@@ -43,7 +43,7 @@ describe('./lib/typescript-overrides', () => {
4343
it('it sets sourceMap: false', () => {
4444
const typescriptOverrides = proxyquire('../../lib/typescript-overrides', {
4545
typescript,
46-
})
46+
}).default
4747

4848
typescriptOverrides.overrideSourceMaps(false)
4949

@@ -65,7 +65,7 @@ describe('./lib/typescript-overrides', () => {
6565
it('sets options when given an array', () => {
6666
const typescriptOverrides = proxyquire('../../lib/typescript-overrides', {
6767
typescript,
68-
})
68+
}).default
6969

7070
typescriptOverrides.overrideSourceMaps(true)
7171

@@ -83,7 +83,7 @@ describe('./lib/typescript-overrides', () => {
8383
it('require "default" typescript if typescript option not specified', () => {
8484
const typescriptOverrides = proxyquire('../../lib/typescript-overrides', {
8585
typescript,
86-
})
86+
}).default
8787

8888
typescriptOverrides.overrideSourceMaps(true)
8989

@@ -104,7 +104,7 @@ describe('./lib/typescript-overrides', () => {
104104
const typescriptOverrides = proxyquire('../../lib/typescript-overrides', {
105105
typescript,
106106
'/path/to/user/typescript': userTypescript,
107-
})
107+
}).default
108108

109109
typescriptOverrides.overrideSourceMaps(true, '/path/to/user/typescript')
110110

@@ -121,7 +121,7 @@ describe('./lib/typescript-overrides', () => {
121121
const typescriptOverrides = proxyquire('../../lib/typescript-overrides', {
122122
typescript,
123123
'/path/to/user/typescript': null,
124-
})
124+
}).default
125125

126126
typescriptOverrides.overrideSourceMaps(true)
127127

@@ -142,7 +142,7 @@ describe('./lib/typescript-overrides', () => {
142142
it('gracefully returns error when typescript cannot be required', () => {
143143
const typescriptOverrides = proxyquire('../../lib/typescript-overrides', {
144144
typescript: null,
145-
})
145+
}).default
146146

147147
const err = typescriptOverrides.overrideSourceMaps(true)
148148

packages/config/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
2-
require('@packages/ts/registerDir')(__dirname)
2+
require('tsx/cjs')
33
}
44

55
module.exports = require('./src')

packages/data-context/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
2-
require('@packages/ts/register')
2+
require('tsx/cjs')
33
}
44

55
module.exports = require('./src')

packages/driver/cypress/plugins/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// only required to read in webpack config, since it is .ts
2-
require('@packages/ts/register')
2+
require('tsx/cjs')
33
require('./server')
44
const _ = require('lodash')
55
const path = require('path')

packages/errors/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
try {
77
require.resolve('./src')
88
} catch (e) {
9-
require('@packages/ts/register')
9+
require('tsx/cjs')
1010
}
1111

1212
module.exports = require('./src')

packages/frontend-shared/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
2-
require('@packages/ts/register')
2+
require('tsx/cjs')
33
}
44

55
module.exports = require('./src')
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
require('@packages/ts/register')
1+
require('tsx/cjs')
22
module.exports = require('./codegen-type-map-ts').default
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
require('@packages/ts/register')
1+
require('tsx/cjs')
22
module.exports = require('./generate-shiki-theme-ts').default
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
require('@packages/ts/register')
1+
require('tsx/cjs')
22
module.exports = require('./generate-stub-specs-ts').default

packages/graphql/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
2-
require('@packages/ts/register')
2+
require('tsx/cjs')
33
}
44

55
module.exports = require('./src')

packages/graphql/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"clean-deps": "rimraf node_modules",
1313
"postinstall": "echo '@packages/graphql needs: yarn build'",
1414
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
15-
"nexus-build": "ts-node ./scripts/nexus-build.ts",
15+
"nexus-build": "node --import tsx ./scripts/nexus-build.ts",
1616
"test-integration": "mocha -r @packages/ts/register test/integration/**/*.spec.ts --config ./test/.mocharc.js --exit",
1717
"test-unit": "mocha -r @packages/ts/register test/unit/**/*.spec.ts --config ./test/.mocharc.js --exit",
1818
"tslint": "tslint --config ../ts/tslint.json --project . --exclude ./src/gen/nxs.gen.ts"

packages/graphql/src/utils/nexusTypegenUtils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ export async function nexusTypegen (cfg: NexusTypegenCfg) {
5454
}
5555

5656
const nodeCmd = `node${process.platform === 'win32' ? '.cmd' : ''}`
57-
const out = spawn(nodeCmd, ['-r', '@packages/ts/register', cfg.filePath], {
57+
const out = spawn(nodeCmd, ['--import', 'tsx', cfg.filePath], {
5858
cwd: cfg.cwd,
5959
env: {
6060
...process.env,
6161
CYPRESS_INTERNAL_NEXUS_CODEGEN: 'true',
62-
TS_NODE_CACHE: 'false',
6362
},
6463
...process.platform === 'win32' ? { shell: true } : {},
6564
})

packages/icons/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"private": true,
66
"main": "index.js",
77
"scripts": {
8-
"build": "ts-node ./scripts/build.ts && ts-node ./scripts/ico.ts",
8+
"build": "tsx ./scripts/build.ts && tsx ./scripts/ico.ts",
99
"check-ts": "tsc --noEmit && yarn -s tslint",
1010
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
1111
"test": "yarn test-unit",

packages/network/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
2-
require('@packages/ts/register')
2+
require('tsx/cjs')
33
}
44

55
module.exports = require('./lib')

packages/proxy/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
2-
require('@packages/ts/register')
2+
require('tsx/cjs')
33
}
44

55
module.exports = require('./lib')

packages/resolve-dist/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
2-
require('@packages/ts/register')
2+
require('tsx/cjs')
33
}
44

55
module.exports = require('./lib')

0 commit comments

Comments
 (0)