@ava/typescript
Advanced tools
Comparing version 4.1.0 to 5.0.0
211
index.js
@@ -7,4 +7,4 @@ import fs from 'node:fs'; | ||
const pkg = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url))); | ||
const help = `See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md`; | ||
const package_ = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url))); | ||
const help = `See https://github.com/avajs/typescript/blob/v${package_.version}/README.md`; | ||
@@ -40,4 +40,4 @@ function isPlainObject(x) { | ||
async function compileTypeScript(projectDir) { | ||
return execa('tsc', ['--incremental'], {preferLocal: true, cwd: projectDir}); | ||
async function compileTypeScript(projectDirectory) { | ||
return execa('tsc', ['--incremental'], {preferLocal: true, cwd: projectDirectory}); | ||
} | ||
@@ -67,3 +67,3 @@ | ||
&& extensions.length > 0 | ||
&& extensions.every(ext => typeof ext === 'string' && ext !== '') | ||
&& extensions.every(extension => typeof extension === 'string' && extension !== '') | ||
&& new Set(extensions).size === extensions.length; | ||
@@ -81,3 +81,3 @@ }, | ||
export default function typescriptProvider({negotiateProtocol}) { | ||
const protocol = negotiateProtocol(['ava-6', 'ava-3.2'], {version: pkg.version}); | ||
const protocol = negotiateProtocol(['ava-6'], {version: package_.version}); | ||
if (protocol === null) { | ||
@@ -105,140 +105,109 @@ return; | ||
]); | ||
const testFileExtension = new RegExp(`\\.(${extensions.map(ext => escapeStringRegexp(ext)).join('|')})$`); | ||
const testFileExtension = new RegExp(`\\.(${extensions.map(extension => escapeStringRegexp(extension)).join('|')})$`); | ||
const watchMode = protocol.identifier === 'ava-3.2' | ||
? { | ||
ignoreChange(filePath) { | ||
if (!testFileExtension.test(filePath)) { | ||
return false; | ||
const watchMode = { | ||
changeInterpretations, | ||
interpretChange(filePath) { | ||
if (config.compile === false) { | ||
for (const [from] of rewritePaths) { | ||
if (testFileExtension.test(filePath) && filePath.startsWith(from)) { | ||
return changeInterpretations.waitForOutOfBandCompilation; | ||
} | ||
} | ||
} | ||
return rewritePaths.some(([from]) => filePath.startsWith(from)); | ||
}, | ||
resolveTestFile(testfile) { // Used under AVA 3.2 protocol by legacy watcher implementation. | ||
if (!testFileExtension.test(testfile)) { | ||
return testfile; | ||
if (config.compile === 'tsc') { | ||
for (const [, to] of rewritePaths) { | ||
if (filePath.startsWith(to)) { | ||
return changeInterpretations.ignoreCompiled; | ||
} | ||
} | ||
} | ||
const rewrite = rewritePaths.find(([from]) => testfile.startsWith(from)); | ||
if (rewrite === undefined) { | ||
return testfile; | ||
} | ||
return changeInterpretations.unspecified; | ||
}, | ||
const [from, to] = rewrite; | ||
let newExtension = '.js'; | ||
if (testfile.endsWith('.cts')) { | ||
newExtension = '.cjs'; | ||
} else if (testfile.endsWith('.mts')) { | ||
newExtension = '.mjs'; | ||
resolvePossibleOutOfBandCompilationSources(filePath) { | ||
if (config.compile !== false) { | ||
return null; | ||
} | ||
// Only recognize .cjs, .mjs and .js files. | ||
if (!/\.(c|m)?js$/.test(filePath)) { | ||
return null; | ||
} | ||
for (const [from, to] of rewritePaths) { | ||
if (!filePath.startsWith(to)) { | ||
continue; | ||
} | ||
return `${to}${testfile.slice(from.length)}`.replace(testFileExtension, newExtension); | ||
}, | ||
} | ||
: { | ||
changeInterpretations, | ||
interpretChange(filePath) { | ||
if (config.compile === false) { | ||
for (const [from] of rewritePaths) { | ||
if (testFileExtension.test(filePath) && filePath.startsWith(from)) { | ||
return changeInterpretations.waitForOutOfBandCompilation; | ||
} | ||
const rewritten = `${from}${filePath.slice(to.length)}`; | ||
const possibleExtensions = []; | ||
if (filePath.endsWith('.cjs')) { | ||
if (extensions.includes('cjs')) { | ||
possibleExtensions.push({replace: /\.cjs$/, extension: 'cjs'}); | ||
} | ||
} | ||
if (config.compile === 'tsc') { | ||
for (const [, to] of rewritePaths) { | ||
if (filePath.startsWith(to)) { | ||
return changeInterpretations.ignoreCompiled; | ||
} | ||
if (extensions.includes('cts')) { | ||
possibleExtensions.push({replace: /\.cjs$/, extension: 'cts'}); | ||
} | ||
if (possibleExtensions.length === 0) { | ||
return null; | ||
} | ||
} | ||
return changeInterpretations.unspecified; | ||
}, | ||
if (filePath.endsWith('.mjs')) { | ||
if (extensions.includes('mjs')) { | ||
possibleExtensions.push({replace: /\.mjs$/, extension: 'mjs'}); | ||
} | ||
resolvePossibleOutOfBandCompilationSources(filePath) { | ||
if (config.compile !== false) { | ||
return null; | ||
} | ||
if (extensions.includes('mts')) { | ||
possibleExtensions.push({replace: /\.mjs$/, extension: 'mts'}); | ||
} | ||
// Only recognize .cjs, .mjs and .js files. | ||
if (!/\.(c|m)?js$/.test(filePath)) { | ||
return null; | ||
if (possibleExtensions.length === 0) { | ||
return null; | ||
} | ||
} | ||
for (const [from, to] of rewritePaths) { | ||
if (!filePath.startsWith(to)) { | ||
continue; | ||
if (filePath.endsWith('.js')) { | ||
if (extensions.includes('js')) { | ||
possibleExtensions.push({replace: /\.js$/, extension: 'js'}); | ||
} | ||
const rewritten = `${from}${filePath.slice(to.length)}`; | ||
const possibleExtensions = []; | ||
if (filePath.endsWith('.cjs')) { | ||
if (extensions.includes('cjs')) { | ||
possibleExtensions.push({replace: /\.cjs$/, extension: 'cjs'}); | ||
} | ||
if (extensions.includes('cts')) { | ||
possibleExtensions.push({replace: /\.cjs$/, extension: 'cts'}); | ||
} | ||
if (possibleExtensions.length === 0) { | ||
return null; | ||
} | ||
if (extensions.includes('ts')) { | ||
possibleExtensions.push({replace: /\.js$/, extension: 'ts'}); | ||
} | ||
if (filePath.endsWith('.mjs')) { | ||
if (extensions.includes('mjs')) { | ||
possibleExtensions.push({replace: /\.mjs$/, extension: 'mjs'}); | ||
} | ||
if (extensions.includes('mts')) { | ||
possibleExtensions.push({replace: /\.mjs$/, extension: 'mts'}); | ||
} | ||
if (possibleExtensions.length === 0) { | ||
return null; | ||
} | ||
if (extensions.includes('tsx')) { | ||
possibleExtensions.push({replace: /\.js$/, extension: 'tsx'}); | ||
} | ||
if (filePath.endsWith('.js')) { | ||
if (extensions.includes('js')) { | ||
possibleExtensions.push({replace: /\.js$/, extension: 'js'}); | ||
} | ||
if (extensions.includes('ts')) { | ||
possibleExtensions.push({replace: /\.js$/, extension: 'ts'}); | ||
} | ||
if (extensions.includes('tsx')) { | ||
possibleExtensions.push({replace: /\.js$/, extension: 'tsx'}); | ||
} | ||
if (possibleExtensions.length === 0) { | ||
return null; | ||
} | ||
if (possibleExtensions.length === 0) { | ||
return null; | ||
} | ||
} | ||
const possibleDeletedFiles = []; | ||
for (const {replace, extension} of possibleExtensions) { | ||
const possibleFilePath = rewritten.replace(replace, `.${extension}`); | ||
const possibleDeletedFiles = []; | ||
for (const {replace, extension} of possibleExtensions) { | ||
const possibleFilePath = rewritten.replace(replace, `.${extension}`); | ||
// Pick the first file path that exists. | ||
if (fs.existsSync(possibleFilePath)) { | ||
return [possibleFilePath]; | ||
} | ||
possibleDeletedFiles.push(possibleFilePath); | ||
// Pick the first file path that exists. | ||
if (fs.existsSync(possibleFilePath)) { | ||
return [possibleFilePath]; | ||
} | ||
return possibleDeletedFiles; | ||
possibleDeletedFiles.push(possibleFilePath); | ||
} | ||
return null; | ||
}, | ||
}; | ||
return possibleDeletedFiles; | ||
} | ||
return null; | ||
}, | ||
}; | ||
return { | ||
@@ -284,17 +253,17 @@ ...watchMode, | ||
const importJs = extensionsToLoadAsModules.includes('js'); | ||
const testFileExtension = new RegExp(`\\.(${extensions.map(ext => escapeStringRegexp(ext)).join('|')})$`); | ||
const testFileExtension = new RegExp(`\\.(${extensions.map(extension => escapeStringRegexp(extension)).join('|')})$`); | ||
return { | ||
canLoad(ref) { | ||
return testFileExtension.test(ref) && rewritePaths.some(([from]) => ref.startsWith(from)); | ||
canLoad(reference) { | ||
return testFileExtension.test(reference) && rewritePaths.some(([from]) => reference.startsWith(from)); | ||
}, | ||
async load(ref, {requireFn}) { | ||
const [from, to] = rewritePaths.find(([from]) => ref.startsWith(from)); | ||
let rewritten = `${to}${ref.slice(from.length)}`; | ||
async load(reference, {requireFn}) { | ||
const [from, to] = rewritePaths.find(([from]) => reference.startsWith(from)); | ||
let rewritten = `${to}${reference.slice(from.length)}`; | ||
let useImport = true; | ||
if (ref.endsWith('.cts')) { | ||
if (reference.endsWith('.cts')) { | ||
rewritten = rewritten.replace(/\.cts$/, '.cjs'); | ||
useImport = false; | ||
} else if (ref.endsWith('.mts')) { | ||
} else if (reference.endsWith('.mts')) { | ||
rewritten = rewritten.replace(/\.mts$/, '.mjs'); | ||
@@ -301,0 +270,0 @@ } else { |
{ | ||
"name": "@ava/typescript", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"description": "TypeScript provider for AVA", | ||
"engines": { | ||
"node": "^14.19 || ^16.15 || ^18 || ^20" | ||
"node": "^18.18 || ^20.8 || ^21 || ^22" | ||
}, | ||
@@ -27,10 +27,10 @@ "files": [ | ||
"escape-string-regexp": "^5.0.0", | ||
"execa": "^7.1.1" | ||
"execa": "^8.0.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^5.3.1", | ||
"c8": "^8.0.0", | ||
"del": "^7.0.0", | ||
"typescript": "^5.1.3", | ||
"xo": "^0.54.2" | ||
"ava": "^6.1.2", | ||
"c8": "^9.1.0", | ||
"del": "^7.1.0", | ||
"typescript": "^5.4.5", | ||
"xo": "^0.58.0" | ||
}, | ||
@@ -48,6 +48,8 @@ "c8": { | ||
], | ||
"ignoredByWatcher": [ | ||
"test/fixtures/**", | ||
"test/broken-fixtures/**" | ||
], | ||
"watcher": { | ||
"ignoreChanges": [ | ||
"test/fixtures/**", | ||
"test/broken-fixtures/**" | ||
] | ||
}, | ||
"timeout": "60s" | ||
@@ -54,0 +56,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12243
227
+ Addedexeca@8.0.1(transitive)
+ Addedget-stream@8.0.1(transitive)
+ Addedhuman-signals@5.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
- Removedexeca@7.2.0(transitive)
- Removedget-stream@6.0.1(transitive)
- Removedhuman-signals@4.3.1(transitive)
- Removedsignal-exit@3.0.7(transitive)
Updatedexeca@^8.0.1