Skip to content
This repository was archived by the owner on Dec 1, 2018. It is now read-only.

Commit d68817d

Browse files
committed
Workaround for broken TypeScript findConfigFilepath under Windows
1 parent 7b7ab15 commit d68817d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Portions of this project are heavily based on parts of [vueify](https://github.c
2626
},
2727
```
2828

29+
* Make sure a suitable `tsconfig.json` is present to specify your required TypeScript compiler options
2930
* Write a test for a Vue.js component
3031
```typescript
3132
/// <reference path='../node_modules/@types/jest/index.d.ts' />
@@ -74,10 +75,12 @@ describe('counter-ts.vue', () => {
7475
* Use jest as usual, e.g., `npm test -- --watch`
7576

7677
### Notes
78+
* This project looks for `tsconfig.json` starting in the directory of the source file and continuing up in the directory tree
79+
* Only the `compilerOptions` subtree of `tsconfig.json` is used
7780
* To use `import` with `*.vue` files in TypeScript code, cf. <https://github.com/locoslab/vue-typescript-import-dts>
7881
* To use TypeScript classes as Vue.js components, cf.
7982
<https://github.com/locoslab/vue-typescript-component>
80-
* TypeScript code inline in a `*.vue` file is not supported. We prefer separate files to make use of existing IDE/editor and tooling support for TypeScript files. Instead, import the TypeScript module as follows
83+
* Inline TypeScript code in a `*.vue` file is not supported. We prefer separate files to make use of existing IDE/editor and tooling support for TypeScript files. Instead, import the TypeScript module as follows
8184
```html
8285
<template>
8386
...

preprocessor.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
const fs = require('fs')
2+
const path = require('path')
23

34
var defaultBabelOptions = {
45
presets: ['es2015'],
56
plugins: ['transform-runtime']
67
}
78

89
function ts(src, filePath) {
10+
// Microsoft's ts.findConfigFilepath does not work under Windows (hard coded '/' as directory separator)
11+
// https://github.com/Microsoft/TypeScript/pull/9625 probably fixes this but is open since July 11th
12+
function findConfigFile(filePath) {
13+
const testPath = path.join(filePath, 'tsconfig.json')
14+
if (fs.existsSync(testPath)) {
15+
return testPath
16+
} else {
17+
const parent = path.dirname(filePath)
18+
return parent !== filePath ? findConfigFile(parent) : undefined
19+
}
20+
}
921
const ts = require('typescript')
10-
const tsConfigPath = ts.findConfigFile(filePath, fs.existsSync)
22+
const tsConfigPath = findConfigFile(filePath)
23+
if (!tsConfigPath) {
24+
throw 'tsconfig.json not found for ' + filePath
25+
}
1126
const tsOptions = require(tsConfigPath)
1227
const options = {
1328
compilerOptions: tsOptions.compilerOptions,

0 commit comments

Comments
 (0)