Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Fix dts-localize script for windows #18664

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions scripts/dts-localize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */
import path from 'path';
import path, { dirname, isAbsolute, join, resolve } from 'path';
import fs from 'fs-extra';
import { sync } from 'read-pkg-up';
import slash from 'slash';
Expand All @@ -14,8 +14,8 @@ const parseConfigHost = {
};

function getAbsolutePath(fileName: string, cwd?: string) {
if (!path.isAbsolute(fileName)) {
fileName = path.join(cwd !== undefined ? cwd : process.cwd(), fileName);
if (!isAbsolute(fileName)) {
fileName = join(cwd !== undefined ? cwd : process.cwd(), fileName);
}

return fileName;
Expand All @@ -28,7 +28,7 @@ function getCompilerOptions(inputFileNames: string[], preferredConfigPath?: stri
const compilerOptionsParseResult = ts.parseJsonConfigFileContent(
configParseResult.config,
parseConfigHost,
path.resolve(path.dirname(configFileName)),
resolve(dirname(configFileName)),
undefined,
getAbsolutePath(configFileName)
);
Expand Down Expand Up @@ -107,17 +107,17 @@ export const run = async (entrySourceFiles: string[], outputPath: string, option

*/

if (relative.includes('node_modules/')) {
const [, ...parts] = relative.split('node_modules/');
const filename = parts.join('node_modules/').split('/').join('-');
newPath = path.join(outputPath, '_modules', filename);
} else if (relative.includes('dist/ts-tmp/')) {
const [, ...parts] = relative.split('dist/ts-tmp/');
const filename = parts.join('').split('/').join('-');
newPath = path.join(outputPath, filename);
if (relative.includes(`node_modules${path.sep}`)) {
const [, ...parts] = relative.split(`node_modules${path.sep}`);
const filename = parts.join(`node_modules${path.sep}`).split(path.sep).join('-');
newPath = join(outputPath, '_modules', filename);
} else if (relative.includes(join('dist', `ts-tmp${path.sep}`))) {
const [, ...parts] = relative.split(join('dist', `ts-tmp${path.sep}`));
const filename = parts.join('').split(path.sep).join('-');
newPath = join(outputPath, filename);
} else {
const filename = relative.split('/').join('-');
newPath = path.join(outputPath, filename);
const filename = relative.split(path.sep).join('-');
newPath = join(outputPath, filename);
}
return newPath;
}
Expand Down