mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-28 12:01:37 -04:00
* test: use `import type` in more places Several tests are failing because a module isn't being mocked. This is due to the mocked module being imported before the mock being set up. Switching to `import type` should elide the import fully. * build: replace ts-jest with simple transformer * chore: remove `ts-jest` * chore: remove babel dependencies from root project * ci: use Node.js 22.13.0 (instead of 22.12.0) Node.js 22.13.0 introduces the `stripTypeScriptTypes` function * fix: copilot feedback
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
import { stripTypeScriptTypes } from 'node:module'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { transformSync } from '@babel/core'
|
|
|
|
// This file was created referencing:
|
|
// https://github.com/jestjs/jest/issues/15443
|
|
|
|
export default {
|
|
process(sourceText, sourcePath) {
|
|
const code = stripTypeScriptTypes(sourceText, { mode: 'strip' })
|
|
|
|
// Using the presence of the DisposableStack global to feature detect
|
|
// whether the current Node.js runtime supports explicit resource
|
|
// management. If it exists, we don't need to do any more work.
|
|
if (typeof DisposableStack !== 'undefined') {
|
|
return { code }
|
|
}
|
|
|
|
// Node.js 24.0.0 introduces explicit resource management:
|
|
// https://nodejs.org/en/blog/release/v24.0.0#v8-136
|
|
//
|
|
// When running tests on Node.js before version 24, we'll need to transpile
|
|
// the "using" keyword. Otherwise Jest will fail to recognize this syntax
|
|
// and show confusing errors when running some tests.
|
|
//
|
|
// This can be deleted when pnpm no longer needs to support Node.js v22.
|
|
return babel(code, sourcePath)
|
|
}
|
|
}
|
|
|
|
function babel (code, sourceFileName) {
|
|
return transformSync(code, {
|
|
babelrc: false,
|
|
configFile: false,
|
|
sourceFileName,
|
|
plugins: [fileURLToPath(import.meta.resolve('@babel/plugin-transform-explicit-resource-management'))]
|
|
})
|
|
}
|