-
Notifications
You must be signed in to change notification settings - Fork 96
Remove ts-node in favor of native Node.js TypeScript support #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3
Are you sure you want to change the base?
Changes from all commits
150f2b7
f922a27
f4a1692
c7c787d
702b53e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "type": "major", | ||
| "comment": "Remove `enableTypeScript`, `tsconfig`, and `transpileOnly` options from `nodeExecTask` and `webpack*` tasks; remove `getTsNodeEnv` helper", | ||
| "packageName": "just-scripts", | ||
| "email": "email not defined", | ||
| "dependentChangeType": "patch" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "type": "major", | ||
| "comment": "Remove `ts-node` support and `--esm` CLI option; require Node.js 22.18+ native TypeScript type-stripping", | ||
| "packageName": "just-task", | ||
| "email": "email not defined", | ||
| "dependentChangeType": "patch" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| import * as path from 'path'; | ||
| import * as fs from 'fs'; | ||
| export const packageJson = fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'); | ||
| export const packageJson = fs.readFileSync(path.join(import.meta.dirname, '../package.json'), 'utf-8'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import * as path from 'path'; | |
| import { getMockScript } from '../../__tests__/getMockScript'; | ||
| import { MockOutputStream } from '../../__tests__/MockOutputStream'; | ||
| import * as execModule from '../../utils/exec'; | ||
| import { nodeExecTask, type NodeExecTaskOptions } from '../nodeExecTask'; | ||
| import { nodeExecTask } from '../nodeExecTask'; | ||
| import { callTaskForTest } from './callTaskForTest'; | ||
| import { getNormalizedSpawnArgs } from './getNormalizedSpawnArgs'; | ||
|
|
||
|
|
@@ -32,18 +32,8 @@ describe('nodeExecTask', () => { | |
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| describe.each(['javascript', 'typescript (ts-node)'])('%s', fileType => { | ||
| const isTS = fileType !== 'javascript'; | ||
| const ext = isTS ? 'ts' : 'js'; | ||
| const maybeTsAutoArgs = isTS ? ['-r', '${repoRoot}/node_modules/ts-node/register/index.js'] : []; | ||
|
|
||
| /** Include appropriate TypeScript options with the task if needed */ | ||
| function wrapNodeExecTask(options: NodeExecTaskOptions) { | ||
| return nodeExecTask({ | ||
| ...(isTS && { enableTypeScript: true, transpileOnly: true }), | ||
| ...options, | ||
| }); | ||
| } | ||
| describe.each(['javascript', 'typescript'])('%s', fileType => { | ||
| const ext = fileType !== 'javascript' ? 'ts' : 'js'; | ||
|
|
||
| /** Wrap a test that should be successful with extra logging in case it fails */ | ||
| async function wrapCallTask(task: TaskFunction, options?: { expectError?: boolean }) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this helper back to this location in the file
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved |
||
|
|
@@ -71,17 +61,15 @@ describe('nodeExecTask', () => { | |
| } | ||
| } | ||
|
|
||
| // These tests get expensive due to the IPC and especially with ts-node, so combine the basic | ||
| // success cases (args, default env) | ||
| // These tests get expensive due to the IPC, so combine the basic success cases (args, default env) | ||
| it('runs a script', async () => { | ||
| const task = wrapNodeExecTask({ | ||
| const task = nodeExecTask({ | ||
| args: ['--max-old-space-size=4096', getMockScript(`mock-success.${ext}`), '--', 'arg1', 'arg2'], | ||
| }); | ||
| await wrapCallTask(task); | ||
|
|
||
| expect(getNormalizedSpawnArgs(spawnSpy)).toEqual([ | ||
| '${nodeExecPath}', | ||
| ...maybeTsAutoArgs, | ||
| '--max-old-space-size=4096', | ||
| `\${packageRoot}/src/__tests__/mock-success.${ext}`, | ||
| '--', | ||
|
|
@@ -95,16 +83,10 @@ describe('nodeExecTask', () => { | |
| // Just verify one value we expect to be present. | ||
| expect(process.env.JEST_WORKER_ID).toBeTruthy(); | ||
| expect(output).toContain(`JEST_WORKER_ID=${process.env.JEST_WORKER_ID}`); | ||
|
|
||
| if (isTS) { | ||
| expect(output).toContain('TS_NODE_'); | ||
| } else { | ||
| expect(output).not.toContain('TS_NODE_'); | ||
| } | ||
| }); | ||
|
|
||
| it('handles a script that fails', async () => { | ||
| const task = wrapNodeExecTask({ | ||
| const task = nodeExecTask({ | ||
| args: [getMockScript(`mock-fail.${ext}`)], | ||
| }); | ||
| try { | ||
|
|
@@ -118,7 +100,7 @@ describe('nodeExecTask', () => { | |
| }); | ||
|
|
||
| it('passes specified env only', async () => { | ||
| const task = wrapNodeExecTask({ | ||
| const task = nodeExecTask({ | ||
| args: [getMockScript(`mock-success.${ext}`)], | ||
| env: { FOO: 'foo value', BAR: 'bar value' }, | ||
| }); | ||
|
|
@@ -131,18 +113,11 @@ describe('nodeExecTask', () => { | |
| // verify a value we expect to be present in the current process isn't passed through | ||
| expect(process.env.JEST_WORKER_ID).toBeTruthy(); | ||
| expect(output).not.toContain('JEST_WORKER_ID'); | ||
|
|
||
| // In TS it would have failed if these were missed, but check anyway | ||
| if (isTS) { | ||
| expect(output).toContain('TS_NODE_'); | ||
| } else { | ||
| expect(output).not.toContain('TS_NODE_'); | ||
| } | ||
| }); | ||
|
|
||
| it('errors if file not found', async () => { | ||
| const script = path.join(__dirname, `nope.${ext}`); | ||
| const task = wrapNodeExecTask({ | ||
| const task = nodeExecTask({ | ||
| args: [script], | ||
| }); | ||
| try { | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.