Skip to content

Commit

Permalink
fix: include .vue files as the project root files (#471)
Browse files Browse the repository at this point in the history
Closes: #452
  • Loading branch information
piotr-oles committed Jul 1, 2020
1 parent ad0eac9 commit 65ab0cc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
34 changes: 34 additions & 0 deletions src/typescript-reporter/extension/TypeScriptEmbeddedExtension.ts
Expand Up @@ -130,6 +130,40 @@ function createTypeScriptEmbeddedExtension({
fileExists: createEmbeddedFileExists(host.fileExists),
};
},
extendParseConfigFileHost<THost extends ts.ParseConfigFileHost>(host: THost): THost {
return {
...host,
readDirectory(
rootDir: string,
extensions: readonly string[],
excludes: readonly string[] | undefined,
includes: readonly string[],
depth?: number
): readonly string[] {
return host
.readDirectory(
rootDir,
[...extensions, ...embeddedExtensions],
excludes,
includes,
depth
)
.map((fileName) => {
const isEmbeddedFile = embeddedExtensions.some((embeddedExtension) =>
fileName.endsWith(embeddedExtension)
);

if (isEmbeddedFile) {
const embeddedSource = getCachedEmbeddedSource(fileName);

return embeddedSource ? `${fileName}${embeddedSource.extension}` : fileName;
} else {
return fileName;
}
});
},
};
},
};
}

Expand Down
1 change: 1 addition & 0 deletions src/typescript-reporter/extension/TypeScriptExtension.ts
Expand Up @@ -20,6 +20,7 @@ interface TypeScriptHostExtension {
host: THost,
parsedCommandLine?: ts.ParsedCommandLine
): THost;
extendParseConfigFileHost?<THost extends ts.ParseConfigFileHost>(host: THost): THost;
}

interface TypeScriptReporterExtension {
Expand Down
20 changes: 14 additions & 6 deletions src/typescript-reporter/reporter/TypeScriptReporter.ts
Expand Up @@ -115,17 +115,25 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
if (!parsedConfiguration) {
const parseConfigurationDiagnostics: ts.Diagnostic[] = [];

let parseConfigFileHost: ts.ParseConfigFileHost = {
...system,
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
parseConfigurationDiagnostics.push(diagnostic);
},
};

extensions.forEach((extension) => {
if (extension.extendParseConfigFileHost) {
parseConfigFileHost = extension.extendParseConfigFileHost(parseConfigFileHost);
}
});

performance.markStart('Parse Configuration');
parsedConfiguration = parseTypeScriptConfiguration(
configuration.configFile,
configuration.context,
configuration.configOverwrite,
{
...system,
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
parseConfigurationDiagnostics.push(diagnostic);
},
}
parseConfigFileHost
);
performance.markEnd('Parse Configuration');

Expand Down
20 changes: 0 additions & 20 deletions test/e2e/TypeScriptVueExtension.spec.ts
Expand Up @@ -61,17 +61,6 @@ describe('TypeScript Vue Extension', () => {
]);

if (vue === '^2.6.11') {
await sandbox.write(
'src/index.ts',
[
"import Vue from 'vue'",
"import App from './App.vue'",
'',
'new Vue({',
' render: h => h(App)',
"}).$mount('#app')",
].join('\n')
);
await sandbox.write(
'src/vue-shim.d.ts',
[
Expand All @@ -82,15 +71,6 @@ describe('TypeScript Vue Extension', () => {
].join('\n')
);
} else {
await sandbox.write(
'src/index.ts',
[
"import { createApp } from 'vue'",
"import App from './App.vue'",
'',
"createApp(App).mount('#app')",
].join('\n')
);
await sandbox.write('src/vue-shim.d.ts', 'declare module "*.vue";');
}

Expand Down
5 changes: 2 additions & 3 deletions test/e2e/fixtures/environment/typescript-vue.fixture
Expand Up @@ -40,8 +40,7 @@
"importsNotUsedAsValues": "preserve"
},
"include": [
"src/**/*.ts",
"src/**/*.vue"
"src",
],
"exclude": [
"node_modules"
Expand All @@ -62,7 +61,7 @@ try {
}

module.exports = {
entry: './src/index.ts',
entry: './src/App.vue',
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
Expand Down
8 changes: 0 additions & 8 deletions test/e2e/fixtures/implementation/typescript-vue.fixture
@@ -1,11 +1,3 @@
/// src/index.ts
import Vue from 'vue'
import App from './App.vue'

new Vue({
render: h => h(App)
}).$mount('#app')

/// src/App.vue
<template>
<logged-in v-if="user" :user="user" @logout="logout"></logged-in>
Expand Down

0 comments on commit 65ab0cc

Please sign in to comment.