Skip to content

Commit 434cb93

Browse files
committed
fixes
1 parent 540f637 commit 434cb93

File tree

8 files changed

+34
-20
lines changed

8 files changed

+34
-20
lines changed

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ function isValidRewritePaths(rewritePaths) {
2424
});
2525
}
2626

27-
function isValidPrecompile(precompile) {
28-
return typeof precompile === 'boolean' || precompile === undefined;
27+
function isValidCompile(compile) {
28+
return typeof compile === 'boolean' || compile === undefined;
2929
}
3030

3131
async function compileTypeScript(projectDir) {
32-
return execa.command(`npx tsc --build ${projectDir}/../tsconfig.json`);
32+
return execa('tsc', ['--build', path.resolve(projectDir, 'tsconfig.json')], {preferLocal: true, cwd: projectDir});
3333
}
3434

3535
module.exports = ({negotiateProtocol}) => {
@@ -43,11 +43,11 @@ module.exports = ({negotiateProtocol}) => {
4343
let valid = false;
4444
if (isPlainObject(config)) {
4545
const keys = Object.keys(config);
46-
if (keys.every(key => key === 'extensions' || key === 'rewritePaths' || key === 'precompile')) {
46+
if (keys.every(key => key === 'extensions' || key === 'rewritePaths' || key === 'compile')) {
4747
valid =
4848
(config.extensions === undefined || isValidExtensions(config.extensions)) &&
4949
isValidRewritePaths(config.rewritePaths) &&
50-
isValidPrecompile(config.precompile);
50+
isValidCompile(config.compile);
5151
}
5252
}
5353

@@ -58,7 +58,7 @@ module.exports = ({negotiateProtocol}) => {
5858
const {
5959
extensions = ['ts'],
6060
rewritePaths: relativeRewritePaths,
61-
precompile = true
61+
compile: relativeCompile = true
6262
} = config;
6363

6464
const rewritePaths = Object.entries(relativeRewritePaths).map(([from, to]) => [
@@ -69,14 +69,14 @@ module.exports = ({negotiateProtocol}) => {
6969

7070
return {
7171
async compile() {
72-
if (precompile) {
72+
if (relativeCompile) {
7373
await compileTypeScript(protocol.projectDir);
7474
}
7575

7676
return {
7777
extensions: extensions.slice(),
7878
rewritePaths: rewritePaths.slice(),
79-
precompile
79+
compile: Boolean(relativeCompile)
8080
};
8181
},
8282

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"typescript"
1717
],
1818
"scripts": {
19-
"test": "xo && nyc ava"
19+
"test": "del-cli test/fixtures/compiled && xo && nyc ava"
2020
},
2121
"dependencies": {
2222
"escape-string-regexp": "^2.0.0",
@@ -25,6 +25,7 @@
2525
},
2626
"devDependencies": {
2727
"ava": "^3.0.0",
28+
"del-cli": "^3.0.0",
2829
"nyc": "^15.0.0",
2930
"typescript": "^3.7.5",
3031
"xo": "^0.25.3"

test/fixtures/compiled/typescript.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('logged in typescript.ts');

test/protocol-ava-3.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ test('main() config validation: config may not be an empty object', withProvider
5555
validateConfig(t, provider, {});
5656
});
5757

58+
test('main() config validation: throw when config.compile is not a boolean nor undefined', withProvider, (t, provider) => {
59+
validateConfig(t, provider, {rewritePaths: {'src/': 'build/'}, compile: 1});
60+
});
61+
5862
test('main() config validation: rewrite paths must end in a /', withProvider, (t, provider) => {
5963
validateConfig(t, provider, {rewritePaths: {src: 'build/'}});
6064
validateConfig(t, provider, {rewritePaths: {'src/': 'build'}});
@@ -101,7 +105,7 @@ test('worker(): load rewritten paths files', withProvider, async (t, provider) =
101105
t.snapshot(stdout);
102106
});
103107

104-
test('worker(): runs precompiled files', withProvider, async (t, provider) => {
108+
test('worker(): runs compiled files', withProvider, async (t, provider) => {
105109
const {state} = await compile(provider);
106110
const {stdout, stderr} = await execa.node(
107111
path.join(__dirname, 'fixtures/install-and-load'),

test/snapshots/protocol-ava-3.js.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ Generated by [AVA](https://avajs.dev).
6060
message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.',
6161
}
6262

63+
## main() config validation: throw when config.compile is not a boolean nor undefined
64+
65+
> Snapshot 1
66+
67+
Error {
68+
message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.',
69+
}
70+
6371
## main() config validation: throw when config.extensions contains duplicates
6472

6573
> Snapshot 1
@@ -90,8 +98,8 @@ Generated by [AVA](https://avajs.dev).
9098
9199
'logged in file.js'
92100

93-
## worker(): runs precompiled files
101+
## worker(): runs compiled files
94102

95103
> Snapshot 1
96104
97-
''
105+
'logged in typescript.ts'

test/snapshots/protocol-ava-3.js.snap

35 Bytes
Binary file not shown.

test/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "fixtures/compiled"
4+
},
5+
"include": [
6+
"fixtures"
7+
]
8+
}

tsconfig.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)