Skip to content

Commit 4f8bec0

Browse files
committed
Also resolve JSON modules
1 parent a24708e commit 4f8bec0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/transpilation/resolve.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ function resolveDependency(
160160
// Check if file is a file in the project
161161
const resolvedPath = path.resolve(fileDirectory, dependency);
162162

163+
if (isProjectFile(resolvedPath)) {
164+
// JSON files need their extension as part of the import path, caught by this branch
165+
return resolvedPath;
166+
}
167+
163168
const resolvedFile = resolvedPath + ".ts";
164169
if (isProjectFile(resolvedFile)) {
165170
return resolvedFile;

test/unit/file.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ describe("JSON", () => {
1010
.setMainFileName("main.json")
1111
.expectToEqual(new util.ExecutionError("Unexpected end of JSON input"));
1212
});
13+
14+
test("JSON modules can be imported", () => {
15+
util.testModule`
16+
import * as jsonData from "./jsonModule.json";
17+
export const result = jsonData;
18+
`
19+
.addExtraFile("jsonModule.json", '{ "jsonField1": "hello, this is JSON", "jsonField2": ["a", "b", "c"] }')
20+
.expectToEqual({
21+
result: {
22+
jsonField1: "hello, this is JSON",
23+
jsonField2: ["a", "b", "c"],
24+
},
25+
});
26+
});
1327
});
1428

1529
describe("shebang", () => {

0 commit comments

Comments
 (0)