Skip to content

Commit d318e9a

Browse files
authored
fix: normalize paths in get-options-overrides (#331)
- the `outDir` was not normalized after the `/placeholder` part was added to `cacheRoot` - `cacheRoot` could have `\` directory separators on it on Windows, which caused some tests to fail on Windows before - tests have been normalized now too - `expandIncludeWithDirs` used `path.join` without normalizing after - `path.join` uses the OS's native separators (`posix.join` would do POSIX separators only), so when the paths were already normalized and then `path.join`ed, this would cause mixed separators on Windows - this fixes the current CI failure on Windows in the `createFilter` tests (`rootDirs` and `projectReferences`, which use `expandIncludeWithDirs`) - c.f. https://github.com/ezolenko/rollup-plugin-typescript2/runs/6516149780?check_suite_focus=true
1 parent e8240ae commit d318e9a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

__tests__/get-options-overrides.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getOptionsOverrides, createFilter } from "../src/get-options-overrides"
1111

1212
setTypescriptModule(ts);
1313

14-
const local = (x: string) => path.resolve(__dirname, x);
14+
const local = (x: string) => normalize(path.resolve(__dirname, x));
1515
const cacheDir = local("__temp/get-options-overrides");
1616

1717
// filter expects an absolute path and resolves include/exclude to process.cwd() by default: https://github.com/ezolenko/rollup-plugin-typescript2/pull/321#discussion_r873077874
@@ -51,7 +51,7 @@ const forcedOptions: ts.CompilerOptions = {
5151
noEmit: false,
5252
noEmitHelpers: false,
5353
noResolve: false,
54-
outDir: `${cacheDir}/placeholder`, // TODO: fix get-options-overrides.ts on Windows by normalizing the path: https://github.com/ezolenko/rollup-plugin-typescript2/pull/321#discussion_r869710856
54+
outDir: `${cacheDir}/placeholder`,
5555
};
5656

5757
const defaultPreParsedTsConfig: ts.ParsedCommandLine = {

src/get-options-overrides.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { createFilter as createRollupFilter} from "@rollup/pluginutils";
1+
import { createFilter as createRollupFilter, normalizePath as normalize } from "@rollup/pluginutils";
22
import { tsModule } from "./tsproxy";
33
import * as tsTypes from "typescript";
44
import { IOptions } from "./ioptions";
5-
import { join } from "path";
5+
import * as path from "path";
66
import { IContext } from "./context";
77

88
export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IOptions, preParsedTsconfig?: tsTypes.ParsedCommandLine): tsTypes.CompilerOptions
@@ -13,7 +13,7 @@ export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IO
1313
noResolve: false,
1414
noEmit: false,
1515
inlineSourceMap: false,
16-
outDir: `${cacheRoot}/placeholder`, // need an outdir that is different from source or tsconfig parsing trips up. https://github.com/Microsoft/TypeScript/issues/24715
16+
outDir: normalize(`${cacheRoot}/placeholder`), // need an outdir that is different from source or tsconfig parsing trips up. https://github.com/Microsoft/TypeScript/issues/24715
1717
moduleResolution: tsModule.ModuleResolutionKind.NodeJs,
1818
allowNonTsExtensions: true,
1919
};
@@ -42,9 +42,9 @@ function expandIncludeWithDirs(include: string | string[], dirs: string[])
4242

4343
dirs.forEach(root => {
4444
if (include instanceof Array)
45-
include.forEach(x => newDirs.push(join(root, x)));
45+
include.forEach(x => newDirs.push(normalize(path.join(root, x))));
4646
else
47-
newDirs.push(join(root, include));
47+
newDirs.push(normalize(path.join(root, include)));
4848
});
4949
return newDirs;
5050
}

0 commit comments

Comments
 (0)