Skip to content

Commit

Permalink
fix(path-mapping): fix an issue where path mapping for other baseUrls…
Browse files Browse the repository at this point in the history
… than '.' didn't work. Fixes #96
  • Loading branch information
wessberg committed Jul 9, 2020
1 parent 15d6ee7 commit 7f6c429
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export function getForcedCompilerOptions(options: GetForcedCompilerOptionsOption
...getForcedModuleKindOption(options),
...getForcedScriptTargetOption(options),
outDir: getOutDir(options.pluginOptions.cwd, options.rollupOutputOptions),
baseUrl: ".",
// Rollup, not Typescript, is the decider of where to put files
outFile: undefined,
// Always generate SourceMaps. Rollup will then decide if it wants to use them or not
Expand Down
9 changes: 9 additions & 0 deletions src/util/get-parsed-command-line/get-parsed-command-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ export function getParsedCommandLine(options: GetParsedCommandLineOptions): Pars
}
}

// Ensure that the parsed command line, as well as the original CompilerOptions has a base URL
if (parsedCommandLine.options.baseUrl == null) {
parsedCommandLine.options.baseUrl = ".";
}

if (originalCompilerOptions.baseUrl == null) {
originalCompilerOptions.baseUrl = ".";
}

// Remove all non-declaration files from the default file names since these will be handled separately by Rollup
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(file => file.endsWith(D_TS_EXTENSION));

Expand Down
42 changes: 42 additions & 0 deletions test/path-mapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,45 @@ test("Supports path mapping. #5", async (t, {typescript}) => {
`)
);
});

test("Supports path mapping. #6", async (t, {typescript}) => {
const bundle = await generateRollupBundle(
[
{
entry: true,
fileName: "index.ts",
text: `\
export * from "~utils/foo";
`
},
{
entry: false,
fileName: "src/utils/foo.ts",
text: `\
export const Foo = 2;
`
}
],
{
typescript,
transpileOnly: true,
tsconfig: {
baseUrl: "src",
paths: {
"~utils/*": ["utils/*"]
}
}
}
);
const {
declarations: [file]
} = bundle;

t.deepEqual(
formatCode(file.code),
formatCode(`\
declare const Foo = 2;
export { Foo };
`)
);
});

0 comments on commit 7f6c429

Please sign in to comment.