fix: Fixes broken windows tests (#607)

This commit is contained in:
Tim Griesser 2020-11-04 13:07:49 -05:00 committed by GitHub
parent f60938079a
commit 6e06f8f3c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -177,21 +177,23 @@ export class TypegenPrinter {
)
}
if (isNodeModule(rootTypePath)) {
if (path.isAbsolute(rootTypePath)) {
if (!fs.existsSync(rootTypePath)) {
throw new Error(`Root typing path ${rootTypePath} for the type ${typeName} does not exist`)
}
} else {
try {
require.resolve(rootTypePath)
} catch (e) {
throw new Error(`Module ${rootTypePath} for the type ${typeName} does not exist`)
}
} else if (!fs.existsSync(rootTypePath)) {
throw new Error(`Root typing path ${rootTypePath} for the type ${typeName} does not exist`)
}
const importPath = isNodeModule(rootTypePath)
? rootTypePath
: relativePathTo(rootTypePath, outputPath)
const importPath = path.isAbsolute(rootTypePath)
? relativePathTo(rootTypePath, outputPath)
.replace(/(\.d)?\.ts/, '')
.replace(/\\+/g, '/')
: rootTypePath
importMap[importPath] = importMap[importPath] || new Set()
importMap[importPath].add(rootType.alias ? `${rootType.name} as ${rootType.alias}` : rootType.name)