MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / emitDtsPlugin

Function emitDtsPlugin

packages/tooling/src/vite.plugin.emit-dts.ts:112–228  ·  view source on GitHub ↗
(options: EmitDtsOptions)

Source from the content-addressed store, hash-verified

110const emitCache = new Map<string, boolean>();
111
112export function emitDtsPlugin(options: EmitDtsOptions): Plugin {
113 const tsconfigPath = options.tsconfigPath ?? path.resolve(options.projectDir, 'tsconfig.json');
114 const declarationDir = path.resolve(options.projectDir, options.declarationDir ?? 'dist/types');
115 const cacheKey = `${options.projectDir}::${declarationDir}`;
116
117 return {
118 name: 'alphatab:emit-dts',
119 async buildStart() {
120 if (emitCache.get(cacheKey)) {
121 return;
122 }
123
124 const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
125 if (configFile.error) {
126 this.error(ts.flattenDiagnosticMessageText(configFile.error.messageText, '\n'));
127 }
128
129 const srcDir = path.resolve(options.projectDir, 'src');
130 const parsed = ts.parseJsonConfigFileContent(
131 configFile.config,
132 ts.sys,
133 path.dirname(tsconfigPath),
134 {
135 declaration: true,
136 emitDeclarationOnly: true,
137 declarationDir,
138 noEmit: false,
139 declarationMap: false,
140 // root the emit at src/ so paths mirror the source tree
141 // (src/Foo.ts -> dist/types/Foo.d.ts).
142 rootDir: srcDir
143 },
144 tsconfigPath
145 );
146
147 if (parsed.errors.length > 0) {
148 for (const diagnostic of parsed.errors) {
149 this.warn(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
150 }
151 }
152
153 const program = ts.createProgram({
154 rootNames: parsed.fileNames,
155 options: parsed.options,
156 projectReferences: parsed.projectReferences
157 });
158
159 const transformers: ts.TransformerFactory<ts.SourceFile | ts.Bundle>[] = [
160 ...(options.afterDeclarations ?? []),
161 dtsPathsTransformer()
162 ];
163
164 // confine emit to `declarationDir`; TS would otherwise also write
165 // `.d.ts` next to any source outside `rootDir` (cross-package
166 // imports in monorepos).
167 const declarationDirPrefix = declarationDir + path.sep;
168 const filteredWriteFile: ts.WriteFileCallback = (
169 fileName,

Callers 2

addDtsFunction · 0.90
defineEsmLibConfigFunction · 0.90

Calls 1

resolveMethod · 0.45

Tested by

no test coverage detected