Socket
Socket
Sign inDemoInstall

@ava/typescript

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ava/typescript - npm Package Compare versions

Comparing version 3.0.1 to 4.0.0

40

index.js

@@ -5,3 +5,3 @@ import fs from 'node:fs';

import escapeStringRegexp from 'escape-string-regexp';
import execa from 'execa';
import {execa} from 'execa';

@@ -87,3 +87,3 @@ const pkg = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)));

const {
extensions = ['ts'],
extensions = ['ts', 'cts', 'mts'],
rewritePaths: relativeRewritePaths,

@@ -123,3 +123,3 @@ compile,

resolveTestFile(testfile) {
resolveTestFile(testfile) { // Used under AVA 3.2 protocol by legacy watcher implementation.
if (!testFileExtension.test(testfile)) {

@@ -135,4 +135,10 @@ return testfile;

const [from, to] = rewrite;
// TODO: Support JSX preserve mode — https://www.typescriptlang.org/docs/handbook/jsx.html
return `${to}${testfile.slice(from.length)}`.replace(testFileExtension, '.js');
let newExtension = '.js';
if (testfile.endsWith('.cts')) {
newExtension = '.cjs';
} else if (testfile.endsWith('.mts')) {
newExtension = '.mjs';
}
return `${to}${testfile.slice(from.length)}`.replace(testFileExtension, newExtension);
},

@@ -149,3 +155,7 @@

...ignoredByWatcherPatterns,
...Object.values(relativeRewritePaths).map(to => `${to}**/*.js.map`),
...Object.values(relativeRewritePaths).flatMap(to => [
`${to}**/*.js.map`,
`${to}**/*.cjs.map`,
`${to}**/*.mjs.map`,
]),
],

@@ -158,3 +168,3 @@ };

worker({extensionsToLoadAsModules, state: {extensions, rewritePaths}}) {
const useImport = extensionsToLoadAsModules.includes('js');
const importJs = extensionsToLoadAsModules.includes('js');
const testFileExtension = new RegExp(`\\.(${extensions.map(ext => escapeStringRegexp(ext)).join('|')})$`);

@@ -169,5 +179,15 @@

const [from, to] = rewritePaths.find(([from]) => ref.startsWith(from));
// TODO: Support JSX preserve mode — https://www.typescriptlang.org/docs/handbook/jsx.html
const rewritten = `${to}${ref.slice(from.length)}`.replace(testFileExtension, '.js');
return useImport ? import(pathToFileURL(rewritten)) : requireFn(rewritten); // eslint-disable-line node/no-unsupported-features/es-syntax
let rewritten = `${to}${ref.slice(from.length)}`;
let useImport = true;
if (ref.endsWith('.cts')) {
rewritten = rewritten.replace(/\.cts$/, '.cjs');
useImport = false;
} else if (ref.endsWith('.mts')) {
rewritten = rewritten.replace(/\.mts$/, '.mjs');
} else {
rewritten = rewritten.replace(testFileExtension, '.js');
useImport = importJs;
}
return useImport ? import(pathToFileURL(rewritten)) : requireFn(rewritten);
},

@@ -174,0 +194,0 @@ };

{
"name": "@ava/typescript",
"version": "3.0.1",
"version": "4.0.0",
"description": "TypeScript provider for AVA",
"engines": {
"node": ">=12.22 <13 || >=14.17 <15 || >=16.4 <17 || >=17"
"node": ">=14.19 <15 || >=16.15 <17 || >=18"
},

@@ -27,10 +27,10 @@ "files": [

"escape-string-regexp": "^5.0.0",
"execa": "^5.1.1"
"execa": "^7.1.0"
},
"devDependencies": {
"ava": "4.0.0-rc.1",
"c8": "^7.10.0",
"del": "^6.0.0",
"typescript": "^4.4.4",
"xo": "^0.46.3"
"ava": "^5.2.0",
"c8": "^7.13.0",
"del": "^7.0.0",
"typescript": "^4.9.5",
"xo": "^0.53.1"
},

@@ -56,5 +56,6 @@ "c8": {

"ignores": [
"test/broken-fixtures"
"test/broken-fixtures",
"test/fixtures/**/compiled/**"
]
}
}
# @ava/typescript
Adds [TypeScript](https://www.typescriptlang.org/) support to [AVA 4](https://avajs.dev).
Adds [TypeScript](https://www.typescriptlang.org/) support to [AVA](https://avajs.dev).

@@ -9,12 +9,2 @@ This is designed to work for projects that precompile TypeScript. It allows AVA to load the compiled JavaScript, while configuring AVA to treat the TypeScript files as test files.

## For AVA 3 users
Use version 2:
```console
npm install --save-dev @ava/typescript@2
```
Note that v2 does not support ES modules. This requires v3 and AVA 4.
## Enabling TypeScript support

@@ -51,3 +41,3 @@

AVA searches your entire project for `*.js`, `*.cjs`, `*.mjs` and `*.ts` files (or other extensions you've configured). It will ignore such files found in the `rewritePaths` targets (e.g. `build/`). If you use more specific paths, for instance `build/main/`, you may need to change AVA's `files` configuration to ignore other directories.
AVA searches your entire project for `*.js`, `*.cjs`, `*.mjs`, `*.ts`, `*.cts` and `*.mts` files (or other extensions you've configured). It will ignore such files found in the `rewritePaths` targets (e.g. `build/`). If you use more specific paths, for instance `build/main/`, you may need to change AVA's `files` configuration to ignore other directories.

@@ -80,4 +70,6 @@ ## ES Modules

If you use the [`allowJs` TypeScript option](https://www.typescriptlang.org/tsconfig/allowJs.html) you'll have to specify the `js`, `cjs` and `mjs` extensions for them to be rewritten.
See also AVA's [`extensions` option](https://github.com/avajs/ava/blob/master/docs/06-configuration.md#options).
† Note that the [*preserve* mode for JSX](https://www.typescriptlang.org/docs/handbook/jsx.html) is not (yet) supported.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc