Update dependencies
This commit is contained in:
parent
fe65e9e945
commit
2e82538b6e
7 changed files with 68 additions and 54 deletions
24
index.js
24
index.js
|
|
@ -98,7 +98,7 @@ export default function typescriptProvider({negotiateProtocol}) {
|
|||
path.join(protocol.projectDir, from),
|
||||
path.join(protocol.projectDir, to),
|
||||
]);
|
||||
const testFileExtension = new RegExp(`\\.(${extensions.map(extension => escapeStringRegexp(extension)).join('|')})$`);
|
||||
const testFileExtension = new RegExp(String.raw`\.(${extensions.map(extension => escapeStringRegexp(extension)).join('|')})$`, 'v');
|
||||
|
||||
const watchMode = {
|
||||
changeInterpretations,
|
||||
|
|
@ -128,7 +128,7 @@ export default function typescriptProvider({negotiateProtocol}) {
|
|||
}
|
||||
|
||||
// Only recognize .cjs, .mjs and .js files.
|
||||
if (!/\.(c|m)?js$/.test(filePath)) {
|
||||
if (!/\.(c|m)?js$/v.test(filePath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -142,11 +142,11 @@ export default function typescriptProvider({negotiateProtocol}) {
|
|||
|
||||
if (filePath.endsWith('.cjs')) {
|
||||
if (extensions.includes('cjs')) {
|
||||
possibleExtensions.push({replace: /\.cjs$/, extension: 'cjs'});
|
||||
possibleExtensions.push({replace: /\.cjs$/v, extension: 'cjs'});
|
||||
}
|
||||
|
||||
if (extensions.includes('cts')) {
|
||||
possibleExtensions.push({replace: /\.cjs$/, extension: 'cts'});
|
||||
possibleExtensions.push({replace: /\.cjs$/v, extension: 'cts'});
|
||||
}
|
||||
|
||||
if (possibleExtensions.length === 0) {
|
||||
|
|
@ -156,11 +156,11 @@ export default function typescriptProvider({negotiateProtocol}) {
|
|||
|
||||
if (filePath.endsWith('.mjs')) {
|
||||
if (extensions.includes('mjs')) {
|
||||
possibleExtensions.push({replace: /\.mjs$/, extension: 'mjs'});
|
||||
possibleExtensions.push({replace: /\.mjs$/v, extension: 'mjs'});
|
||||
}
|
||||
|
||||
if (extensions.includes('mts')) {
|
||||
possibleExtensions.push({replace: /\.mjs$/, extension: 'mts'});
|
||||
possibleExtensions.push({replace: /\.mjs$/v, extension: 'mts'});
|
||||
}
|
||||
|
||||
if (possibleExtensions.length === 0) {
|
||||
|
|
@ -170,15 +170,15 @@ export default function typescriptProvider({negotiateProtocol}) {
|
|||
|
||||
if (filePath.endsWith('.js')) {
|
||||
if (extensions.includes('js')) {
|
||||
possibleExtensions.push({replace: /\.js$/, extension: 'js'});
|
||||
possibleExtensions.push({replace: /\.js$/v, extension: 'js'});
|
||||
}
|
||||
|
||||
if (extensions.includes('ts')) {
|
||||
possibleExtensions.push({replace: /\.js$/, extension: 'ts'});
|
||||
possibleExtensions.push({replace: /\.js$/v, extension: 'ts'});
|
||||
}
|
||||
|
||||
if (extensions.includes('tsx')) {
|
||||
possibleExtensions.push({replace: /\.js$/, extension: 'tsx'});
|
||||
possibleExtensions.push({replace: /\.js$/v, extension: 'tsx'});
|
||||
}
|
||||
|
||||
if (possibleExtensions.length === 0) {
|
||||
|
|
@ -245,7 +245,7 @@ export default function typescriptProvider({negotiateProtocol}) {
|
|||
|
||||
worker({extensionsToLoadAsModules, state: {extensions, rewritePaths}}) {
|
||||
const importJs = extensionsToLoadAsModules.includes('js');
|
||||
const testFileExtension = new RegExp(`\\.(${extensions.map(extension => escapeStringRegexp(extension)).join('|')})$`);
|
||||
const testFileExtension = new RegExp(String.raw`\.(${extensions.map(extension => escapeStringRegexp(extension)).join('|')})$`, 'v');
|
||||
|
||||
return {
|
||||
canLoad(reference) {
|
||||
|
|
@ -257,10 +257,10 @@ export default function typescriptProvider({negotiateProtocol}) {
|
|||
let rewritten = `${to}${reference.slice(from.length)}`;
|
||||
let useImport = true;
|
||||
if (reference.endsWith('.cts')) {
|
||||
rewritten = rewritten.replace(/\.cts$/, '.cjs');
|
||||
rewritten = rewritten.replace(/\.cts$/v, '.cjs');
|
||||
useImport = false;
|
||||
} else if (reference.endsWith('.mts')) {
|
||||
rewritten = rewritten.replace(/\.mts$/, '.mjs');
|
||||
rewritten = rewritten.replace(/\.mts$/v, '.mjs');
|
||||
} else {
|
||||
rewritten = rewritten.replace(testFileExtension, '.js');
|
||||
useImport = importJs;
|
||||
|
|
|
|||
12
package.json
12
package.json
|
|
@ -24,14 +24,14 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"escape-string-regexp": "^5.0.0",
|
||||
"execa": "^9.6.0"
|
||||
"execa": "^9.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^6.4.0",
|
||||
"c8": "^10.1.3",
|
||||
"del": "^8.0.0",
|
||||
"typescript": "^5.8.3",
|
||||
"xo": "^1.1.0"
|
||||
"ava": "^7.0.0",
|
||||
"c8": "^11.0.0",
|
||||
"del": "^8.0.1",
|
||||
"typescript": "^6.0.2",
|
||||
"xo": "^2.0.2"
|
||||
},
|
||||
"volta": {
|
||||
"node": "24.14.1",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "typescript/compiled",
|
||||
"lib": [
|
||||
"es2022"
|
||||
]
|
||||
"outDir": "./typescript/compiled",
|
||||
"rootDir": "./typescript",
|
||||
"tsBuildInfoFile": "./typescript/compiled/.tsbuildinfo"
|
||||
},
|
||||
"include": [
|
||||
"typescript"
|
||||
|
|
|
|||
|
|
@ -6,8 +6,16 @@ import {execaNode} from 'execa';
|
|||
import createProviderMacro from './_with-provider.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const withProvider = createProviderMacro('ava-6', '6.0.0', path.join(__dirname, 'fixtures'));
|
||||
const withAltProvider = createProviderMacro('ava-6', '6.0.0', path.join(__dirname, 'broken-fixtures'));
|
||||
const withProvider = createProviderMacro(
|
||||
'ava-6',
|
||||
'6.0.0',
|
||||
path.join(__dirname, 'fixtures'),
|
||||
);
|
||||
const withAltProvider = createProviderMacro(
|
||||
'ava-6',
|
||||
'6.0.0',
|
||||
path.join(__dirname, 'broken-fixtures'),
|
||||
);
|
||||
|
||||
test.before('deleting compiled files', async t => {
|
||||
t.log(await deleteAsync('test/fixtures/typescript/compiled'));
|
||||
|
|
@ -15,36 +23,48 @@ test.before('deleting compiled files', async t => {
|
|||
});
|
||||
|
||||
const compile = async provider => ({
|
||||
state: await provider.main({
|
||||
config: {
|
||||
rewritePaths: {
|
||||
'ts/': 'typescript/',
|
||||
'compiled/': 'typescript/compiled/',
|
||||
state: await provider
|
||||
.main({
|
||||
config: {
|
||||
rewritePaths: {
|
||||
'ts/': 'typescript/',
|
||||
'compiled/': 'typescript/compiled/',
|
||||
},
|
||||
compile: 'tsc',
|
||||
},
|
||||
compile: 'tsc',
|
||||
},
|
||||
}).compile(),
|
||||
})
|
||||
.compile(),
|
||||
});
|
||||
|
||||
test('worker(): load rewritten paths files', withProvider, async (t, provider) => {
|
||||
const {state} = await compile(provider);
|
||||
const {stdout, stderr} = await execaNode(
|
||||
path.join(__dirname, 'fixtures/install-and-load'),
|
||||
[JSON.stringify({state}), path.join(__dirname, 'fixtures/ts', 'file.ts')],
|
||||
{cwd: path.join(__dirname, 'fixtures')},
|
||||
);
|
||||
if (stderr.length > 0) {
|
||||
t.log(stderr);
|
||||
}
|
||||
test(
|
||||
'worker(): load rewritten paths files',
|
||||
withProvider,
|
||||
async (t, provider) => {
|
||||
const {state} = await compile(provider);
|
||||
const {stdout, stderr} = await execaNode(
|
||||
path.join(__dirname, 'fixtures/install-and-load'),
|
||||
[
|
||||
JSON.stringify({state}),
|
||||
path.join(__dirname, 'fixtures/ts', 'file.ts'),
|
||||
],
|
||||
{cwd: path.join(__dirname, 'fixtures')},
|
||||
);
|
||||
if (stderr.length > 0) {
|
||||
t.log(stderr);
|
||||
}
|
||||
|
||||
t.snapshot(stdout);
|
||||
});
|
||||
t.snapshot(stdout);
|
||||
},
|
||||
);
|
||||
|
||||
test('worker(): runs compiled files', withProvider, async (t, provider) => {
|
||||
const {state} = await compile(provider);
|
||||
const {stdout, stderr} = await execaNode(
|
||||
path.join(__dirname, 'fixtures/install-and-load'),
|
||||
[JSON.stringify({state}), path.join(__dirname, 'fixtures/compiled', 'index.ts')],
|
||||
[
|
||||
JSON.stringify({state}),
|
||||
path.join(__dirname, 'fixtures/compiled', 'index.ts'),
|
||||
],
|
||||
{cwd: path.join(__dirname, 'fixtures')},
|
||||
);
|
||||
if (stderr.length > 0) {
|
||||
|
|
|
|||
2
test/fixtures/load/compiled/index.js
vendored
2
test/fixtures/load/compiled/index.js
vendored
|
|
@ -1,2 +1,2 @@
|
|||
"use strict";
|
||||
console.log('logged in fixtures/load/index.ts');
|
||||
export {};
|
||||
|
|
|
|||
2
test/fixtures/load/tsconfig.json
vendored
2
test/fixtures/load/tsconfig.json
vendored
|
|
@ -1,7 +1,5 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"strictNullChecks": true,
|
||||
"module": "node18",
|
||||
"outDir": "compiled"
|
||||
},
|
||||
"include": [
|
||||
|
|
|
|||
9
test/fixtures/tsconfig.json
vendored
9
test/fixtures/tsconfig.json
vendored
|
|
@ -1,11 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"strictNullChecks": true,
|
||||
"lib": [
|
||||
"es2022",
|
||||
"dom"
|
||||
],
|
||||
"outDir": "typescript/compiled"
|
||||
"outDir": "./typescript/compiled",
|
||||
"rootDir": "./typescript",
|
||||
"tsBuildInfoFile": "./typescript/compiled/.tsbuildinfo"
|
||||
},
|
||||
"include": [
|
||||
"typescript"
|
||||
|
|
|
|||
Loading…
Reference in a new issue