-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from XaveScor/11-direct-typescript-use
11: direct typescript calls instead of rollup/typescript-plugin
- Loading branch information
Showing
9 changed files
with
229 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
export {}; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as path from "node:path"; | ||
import * as process from "node:process"; | ||
import * as fs from "node:fs"; | ||
|
||
type BuildTypesOptions = { | ||
sourceDir: string; | ||
files: string[]; | ||
outDir: string; | ||
}; | ||
|
||
export async function buildTypes({ | ||
sourceDir, | ||
files, | ||
outDir, | ||
}: BuildTypesOptions) { | ||
const ts = await import("typescript"); | ||
const configPath = path.join(sourceDir, "tsconfig.json"); | ||
const configFile = ts.readConfigFile(configPath, ts.sys.readFile); | ||
|
||
const parsedCommandLine = ts.parseJsonConfigFileContent( | ||
configFile.config, | ||
ts.sys, | ||
sourceDir, | ||
{ | ||
declaration: true, | ||
emitDeclarationOnly: true, | ||
strict: false, | ||
strictNullChecks: false, | ||
strictFunctionTypes: false, | ||
strictPropertyInitialization: false, | ||
skipLibCheck: true, | ||
skipDefaultLibCheck: true, | ||
}, | ||
configPath, | ||
); | ||
|
||
const host = ts.createCompilerHost(parsedCommandLine.options); | ||
|
||
const sourceToDtsMap = new Map<string, string>(); | ||
const program = ts.createProgram(files, parsedCommandLine.options, host); | ||
program.emit(undefined, (fileName, data) => { | ||
const relativePath = path.relative(sourceDir, fileName); | ||
const finalPath = path.join(outDir, relativePath); | ||
const sourceFileName = fileName.replace(/\.d\.ts$/, ".ts"); // Assuming source files have .ts extension | ||
sourceToDtsMap.set(sourceFileName, finalPath); | ||
fs.writeFileSync(finalPath, data); | ||
}); | ||
|
||
return sourceToDtsMap; | ||
} |
Oops, something went wrong.