Skip to content

Commit d9881f6

Browse files
simonhaenischmanucorporat
authored andcommitted
feat(compiler): warn about typescript imports (#1576)
1 parent d68a478 commit d9881f6

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/compiler/rollup-plugins/in-memory-fs-read.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as d from '../../declarations';
22
import { normalizePath } from '@utils';
3+
import { Plugin } from 'rollup';
34

4-
5-
export function inMemoryFsRead(config: d.Config, compilerCtx: d.CompilerCtx) {
5+
export function inMemoryFsRead(config: d.Config, compilerCtx: d.CompilerCtx): Plugin {
66
const path = config.sys.path;
77
return {
88
name: 'inMemoryFsRead',
@@ -28,8 +28,8 @@ export function inMemoryFsRead(config: d.Config, compilerCtx: d.CompilerCtx) {
2828
// 1. load(importee)
2929
let accessData = await compilerCtx.fs.accessData(importee);
3030
if (accessData.exists && accessData.isFile) {
31-
// exact importee file path exists
32-
return importee;
31+
// exact importee file path exists
32+
return importee;
3333
}
3434

3535
// 2. load(importee.js)
@@ -64,6 +64,12 @@ export function inMemoryFsRead(config: d.Config, compilerCtx: d.CompilerCtx) {
6464
},
6565

6666
async load(sourcePath: string) {
67+
if (/\.tsx?/i.test(sourcePath)) {
68+
this.warn({
69+
message: `An import was resolved to a Tyepscript file (${sourcePath}) but Rollup treated it as Javascript. You should instead resolve to the absolute path of its transpiled Javascript equivalent (${path.resolve(sourcePath.replace(/\.tsx?/i, '.js'))}).`,
70+
});
71+
}
72+
6773
return compilerCtx.fs.readFile(sourcePath);
6874
}
6975
};

0 commit comments

Comments
 (0)