@reliverse/build 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/impl/assets.d.ts +28 -0
- package/dist/impl/assets.js +188 -0
- package/dist/impl/cache.d.ts +25 -0
- package/dist/impl/cache.js +209 -0
- package/dist/impl/constants.d.ts +44 -0
- package/dist/impl/constants.js +45 -0
- package/dist/impl/debug.d.ts +30 -0
- package/dist/impl/debug.js +150 -0
- package/dist/impl/dependency-tracker.d.ts +23 -0
- package/dist/impl/dependency-tracker.js +113 -0
- package/dist/impl/dev-server.d.ts +24 -0
- package/dist/impl/dev-server.js +360 -0
- package/dist/impl/dts-generator.d.ts +26 -0
- package/dist/impl/dts-generator.js +514 -0
- package/dist/impl/go-build.d.ts +10 -0
- package/dist/impl/go-build.js +350 -0
- package/dist/impl/html-processor.d.ts +21 -0
- package/dist/impl/html-processor.js +167 -0
- package/dist/impl/impl.d.ts +0 -0
- package/dist/impl/impl.js +0 -0
- package/dist/impl/plugins/asset-optimization.d.ts +2 -0
- package/dist/impl/plugins/asset-optimization.js +114 -0
- package/dist/impl/plugins/bundle-analyzer.d.ts +2 -0
- package/dist/impl/plugins/bundle-analyzer.js +156 -0
- package/dist/impl/plugins/css-modules.d.ts +2 -0
- package/dist/impl/plugins/css-modules.js +19 -0
- package/dist/impl/plugins/index.d.ts +21 -0
- package/dist/impl/plugins/index.js +65 -0
- package/dist/impl/plugins/performance.d.ts +2 -0
- package/dist/impl/plugins/performance.js +62 -0
- package/dist/impl/plugins/react-refresh.d.ts +2 -0
- package/dist/impl/plugins/react-refresh.js +33 -0
- package/dist/impl/plugins/svg-as-react.d.ts +2 -0
- package/dist/impl/plugins/svg-as-react.js +18 -0
- package/dist/impl/plugins/typescript-declarations.d.ts +2 -0
- package/dist/impl/plugins/typescript-declarations.js +48 -0
- package/dist/impl/plugins/worker.d.ts +2 -0
- package/dist/impl/plugins/worker.js +20 -0
- package/dist/impl/presets.d.ts +10 -0
- package/dist/impl/presets.js +196 -0
- package/dist/impl/providers/mkdist/loader.d.ts +4 -0
- package/dist/impl/providers/mkdist/loader.js +26 -0
- package/dist/impl/providers/mkdist/loaders/js.d.ts +2 -0
- package/dist/impl/providers/mkdist/loaders/js.js +50 -0
- package/dist/impl/providers/mkdist/loaders/loaders-mod.d.ts +9 -0
- package/dist/impl/providers/mkdist/loaders/loaders-mod.js +22 -0
- package/dist/impl/providers/mkdist/make.d.ts +11 -0
- package/dist/impl/providers/mkdist/make.js +230 -0
- package/dist/impl/providers/mkdist/utils/dts.d.ts +11 -0
- package/dist/impl/providers/mkdist/utils/dts.js +117 -0
- package/dist/impl/providers/mkdist/utils/fs.d.ts +1 -0
- package/dist/impl/providers/mkdist/utils/fs.js +15 -0
- package/dist/impl/providers/mkdist-dts.d.ts +24 -0
- package/dist/impl/providers/mkdist-dts.js +8 -0
- package/dist/impl/tsconfig-validator.d.ts +35 -0
- package/dist/impl/tsconfig-validator.js +184 -0
- package/dist/impl/type-guards.d.ts +20 -0
- package/dist/impl/type-guards.js +147 -0
- package/dist/impl/types.d.ts +322 -0
- package/dist/impl/types.js +0 -0
- package/dist/impl/utils/go-build-handler.d.ts +12 -0
- package/dist/impl/utils/go-build-handler.js +83 -0
- package/dist/impl/utils/log-extraction.d.ts +25 -0
- package/dist/impl/utils/log-extraction.js +24 -0
- package/dist/impl/utils/package-filtering.d.ts +5 -0
- package/dist/impl/utils/package-filtering.js +22 -0
- package/dist/impl/utils/rebuild-queue.d.ts +38 -0
- package/dist/impl/utils/rebuild-queue.js +110 -0
- package/dist/impl/validation.d.ts +9 -0
- package/dist/impl/validation.js +332 -0
- package/dist/impl/watch.d.ts +21 -0
- package/dist/impl/watch.js +144 -0
- package/dist/mod.d.ts +17 -0
- package/dist/mod.js +1390 -0
- package/package.json +42 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
writeFileSync
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import { join, resolve } from "node:path";
|
|
9
|
+
import { logger } from "@reliverse/relinka";
|
|
10
|
+
import { readTSConfig } from "@reliverse/typerso";
|
|
11
|
+
import { getDeclarations } from "./providers/mkdist-dts.js";
|
|
12
|
+
export async function generateDeclarations(options) {
|
|
13
|
+
const { package: pkg, dtsOptions, format = "esm", outputDir } = options;
|
|
14
|
+
try {
|
|
15
|
+
if (dtsOptions.enable === false) {
|
|
16
|
+
return { success: true };
|
|
17
|
+
}
|
|
18
|
+
const dtsOutputDir = resolveDtsOutputDir(pkg, dtsOptions, outputDir);
|
|
19
|
+
if (!existsSync(dtsOutputDir)) {
|
|
20
|
+
mkdirSync(dtsOutputDir, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
const tsconfig = await readTSConfig(pkg.path);
|
|
23
|
+
if (!tsconfig) {
|
|
24
|
+
return {
|
|
25
|
+
success: false,
|
|
26
|
+
error: "No tsconfig.json found"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const enforcedOptions = enforceDeclarationOptions(
|
|
30
|
+
tsconfig,
|
|
31
|
+
dtsOptions,
|
|
32
|
+
format
|
|
33
|
+
);
|
|
34
|
+
const provider = dtsOptions.provider || "dts-bundle-generator";
|
|
35
|
+
switch (provider) {
|
|
36
|
+
case "dts-bundle-generator":
|
|
37
|
+
return await generateWithDtsBundleGenerator(
|
|
38
|
+
pkg,
|
|
39
|
+
dtsOptions,
|
|
40
|
+
dtsOutputDir,
|
|
41
|
+
enforcedOptions
|
|
42
|
+
);
|
|
43
|
+
case "api-extractor":
|
|
44
|
+
return await generateBundledDeclarations(
|
|
45
|
+
pkg,
|
|
46
|
+
dtsOptions,
|
|
47
|
+
dtsOutputDir,
|
|
48
|
+
enforcedOptions
|
|
49
|
+
);
|
|
50
|
+
case "typescript":
|
|
51
|
+
return await generateBundlelessDeclarations(
|
|
52
|
+
pkg,
|
|
53
|
+
dtsOptions,
|
|
54
|
+
dtsOutputDir,
|
|
55
|
+
enforcedOptions
|
|
56
|
+
);
|
|
57
|
+
case "mkdist":
|
|
58
|
+
return await generateWithMkdist(
|
|
59
|
+
pkg,
|
|
60
|
+
dtsOptions,
|
|
61
|
+
dtsOutputDir,
|
|
62
|
+
enforcedOptions
|
|
63
|
+
);
|
|
64
|
+
default:
|
|
65
|
+
if (dtsOptions.bundle) {
|
|
66
|
+
return await generateBundledDeclarations(
|
|
67
|
+
pkg,
|
|
68
|
+
dtsOptions,
|
|
69
|
+
dtsOutputDir,
|
|
70
|
+
enforcedOptions
|
|
71
|
+
);
|
|
72
|
+
} else {
|
|
73
|
+
return await generateBundlelessDeclarations(
|
|
74
|
+
pkg,
|
|
75
|
+
dtsOptions,
|
|
76
|
+
dtsOutputDir,
|
|
77
|
+
enforcedOptions
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
83
|
+
if (dtsOptions.abortOnError !== false) {
|
|
84
|
+
return {
|
|
85
|
+
success: false,
|
|
86
|
+
error: errorMessage
|
|
87
|
+
};
|
|
88
|
+
} else {
|
|
89
|
+
logger.warn(`\u26A0\uFE0F Declaration generation failed for ${pkg.name}:`);
|
|
90
|
+
logger.warn(` Error: ${errorMessage}`);
|
|
91
|
+
logger.warn(
|
|
92
|
+
` Provider: ${dtsOptions.provider || "dts-bundle-generator"}`
|
|
93
|
+
);
|
|
94
|
+
logger.warn(` Output directory: ${outputDir}`);
|
|
95
|
+
return { success: true };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function resolveDtsOutputDir(pkg, dtsOptions, buildOutputDir) {
|
|
100
|
+
if (dtsOptions.distPath) {
|
|
101
|
+
return resolve(pkg.path, dtsOptions.distPath);
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const tsconfig = readFileSync(join(pkg.path, "tsconfig.json"), "utf-8");
|
|
105
|
+
const parsed = JSON.parse(tsconfig);
|
|
106
|
+
if (parsed.compilerOptions?.declarationDir) {
|
|
107
|
+
return resolve(pkg.path, parsed.compilerOptions.declarationDir);
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
return buildOutputDir;
|
|
112
|
+
}
|
|
113
|
+
function enforceDeclarationOptions(tsconfig, dtsOptions, format) {
|
|
114
|
+
const enforced = {
|
|
115
|
+
...tsconfig,
|
|
116
|
+
compilerOptions: {
|
|
117
|
+
...tsconfig.compilerOptions,
|
|
118
|
+
// Required options for declaration generation
|
|
119
|
+
noEmit: false,
|
|
120
|
+
declaration: true,
|
|
121
|
+
emitDeclarationOnly: true
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
if (dtsOptions.bundle !== true) {
|
|
125
|
+
enforced.compilerOptions.declarationMap = true;
|
|
126
|
+
}
|
|
127
|
+
if (dtsOptions.autoExtension !== false) {
|
|
128
|
+
switch (format) {
|
|
129
|
+
case "cjs":
|
|
130
|
+
enforced.compilerOptions.declarationDir = enforced.compilerOptions.declarationDir || "dist";
|
|
131
|
+
break;
|
|
132
|
+
case "esm":
|
|
133
|
+
enforced.compilerOptions.declarationDir = enforced.compilerOptions.declarationDir || "dist";
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
enforced.compilerOptions.declarationDir = enforced.compilerOptions.declarationDir || "dist";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return enforced;
|
|
140
|
+
}
|
|
141
|
+
async function generateBundlelessDeclarations(pkg, _dtsOptions, outputDir, tsconfig) {
|
|
142
|
+
try {
|
|
143
|
+
const ts = await import("typescript");
|
|
144
|
+
const program = ts.createProgram(
|
|
145
|
+
pkg.entryPoints.filter(
|
|
146
|
+
(ep) => ep.endsWith(".ts") && !ep.endsWith(".d.ts")
|
|
147
|
+
),
|
|
148
|
+
{
|
|
149
|
+
...tsconfig.compilerOptions,
|
|
150
|
+
outDir: outputDir
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
const emitResult = program.emit(void 0, void 0, void 0, true);
|
|
154
|
+
if (emitResult.diagnostics.length > 0) {
|
|
155
|
+
const errors = emitResult.diagnostics.filter((d) => d.category === ts.DiagnosticCategory.Error).map((d) => ts.flattenDiagnosticMessageText(d.messageText, "\n"));
|
|
156
|
+
if (errors.length > 0) {
|
|
157
|
+
return {
|
|
158
|
+
success: false,
|
|
159
|
+
error: `TypeScript compilation errors:
|
|
160
|
+
${errors.join("\n")}`
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const generatedFiles = getGeneratedDeclarationFiles(outputDir);
|
|
165
|
+
logger.info(
|
|
166
|
+
`\u2705 Generated ${generatedFiles.length} declaration files for ${pkg.name}`
|
|
167
|
+
);
|
|
168
|
+
return {
|
|
169
|
+
success: true,
|
|
170
|
+
outputDir,
|
|
171
|
+
files: generatedFiles
|
|
172
|
+
};
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return {
|
|
175
|
+
success: false,
|
|
176
|
+
error: `Bundleless declaration generation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function generateBundledDeclarations(pkg, dtsOptions, outputDir, tsconfig) {
|
|
181
|
+
try {
|
|
182
|
+
let apiExtractor;
|
|
183
|
+
try {
|
|
184
|
+
apiExtractor = await import("@microsoft/api-extractor");
|
|
185
|
+
} catch {
|
|
186
|
+
return {
|
|
187
|
+
success: false,
|
|
188
|
+
error: "API Extractor not found. Install @microsoft/api-extractor for bundled declarations."
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const bundlelessResult = await generateBundlelessDeclarations(
|
|
192
|
+
pkg,
|
|
193
|
+
dtsOptions,
|
|
194
|
+
outputDir,
|
|
195
|
+
tsconfig
|
|
196
|
+
);
|
|
197
|
+
if (!bundlelessResult.success) {
|
|
198
|
+
return bundlelessResult;
|
|
199
|
+
}
|
|
200
|
+
const apiExtractorConfig = createApiExtractorConfig(pkg, outputDir);
|
|
201
|
+
const extractorConfig = apiExtractor.ExtractorConfig.loadFileAndPrepare(apiExtractorConfig);
|
|
202
|
+
const extractorResult = apiExtractor.Extractor.invoke(extractorConfig, {
|
|
203
|
+
localBuild: true,
|
|
204
|
+
showVerboseMessages: false
|
|
205
|
+
});
|
|
206
|
+
if (!extractorResult.succeeded) {
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
error: "API Extractor failed to bundle declarations"
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
logger.info(`\u2705 Generated bundled declaration file for ${pkg.name}`);
|
|
213
|
+
return {
|
|
214
|
+
success: true,
|
|
215
|
+
outputDir,
|
|
216
|
+
files: [join(outputDir, `${pkg.name.split("/").pop() || "index"}.d.ts`)]
|
|
217
|
+
};
|
|
218
|
+
} catch (error) {
|
|
219
|
+
return {
|
|
220
|
+
success: false,
|
|
221
|
+
error: `Bundled declaration generation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function createApiExtractorConfig(pkg, outputDir) {
|
|
226
|
+
const configPath = join(pkg.path, "api-extractor.json");
|
|
227
|
+
const config = {
|
|
228
|
+
$schema: "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
229
|
+
mainEntryPointFilePath: join(outputDir, "index.d.ts"),
|
|
230
|
+
bundledPackages: [],
|
|
231
|
+
compiler: {
|
|
232
|
+
tsconfigFilePath: join(pkg.path, "tsconfig.json")
|
|
233
|
+
},
|
|
234
|
+
apiReport: {
|
|
235
|
+
enabled: false
|
|
236
|
+
},
|
|
237
|
+
docModel: {
|
|
238
|
+
enabled: false
|
|
239
|
+
},
|
|
240
|
+
dtsRollup: {
|
|
241
|
+
enabled: true,
|
|
242
|
+
untrimmedFilePath: join(
|
|
243
|
+
outputDir,
|
|
244
|
+
`${pkg.name.split("/").pop() || "index"}.d.ts`
|
|
245
|
+
)
|
|
246
|
+
},
|
|
247
|
+
tsdocMetadata: {
|
|
248
|
+
enabled: false
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
252
|
+
return configPath;
|
|
253
|
+
}
|
|
254
|
+
function getGeneratedDeclarationFiles(outputDir) {
|
|
255
|
+
const files = [];
|
|
256
|
+
function scanDirectory(dir) {
|
|
257
|
+
try {
|
|
258
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
259
|
+
for (const entry of entries) {
|
|
260
|
+
const fullPath = join(dir, entry.name);
|
|
261
|
+
if (entry.isDirectory()) {
|
|
262
|
+
scanDirectory(fullPath);
|
|
263
|
+
} else if (entry.name.endsWith(".d.ts")) {
|
|
264
|
+
files.push(fullPath);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} catch {
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
scanDirectory(outputDir);
|
|
271
|
+
return files;
|
|
272
|
+
}
|
|
273
|
+
async function generateWithDtsBundleGenerator(pkg, dtsOptions, outputDir, _tsconfig) {
|
|
274
|
+
try {
|
|
275
|
+
let dtsBundleGenerator;
|
|
276
|
+
try {
|
|
277
|
+
dtsBundleGenerator = await import("dts-bundle-generator");
|
|
278
|
+
} catch {
|
|
279
|
+
return {
|
|
280
|
+
success: false,
|
|
281
|
+
error: "dts-bundle-generator not found. Install dts-bundle-generator for this provider."
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
const tsconfig = await readTSConfig(pkg.path);
|
|
285
|
+
if (!tsconfig) {
|
|
286
|
+
return {
|
|
287
|
+
success: false,
|
|
288
|
+
error: "No tsconfig.json found"
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const entryPoints = pkg.entryPoints.filter((ep) => ep.endsWith(".ts") && !ep.endsWith(".d.ts")).map((filePath) => ({
|
|
292
|
+
filePath
|
|
293
|
+
}));
|
|
294
|
+
if (entryPoints.length === 0) {
|
|
295
|
+
return {
|
|
296
|
+
success: false,
|
|
297
|
+
error: "No valid TypeScript entry points found"
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
const config = {
|
|
301
|
+
preferredConfigPath: dtsOptions.dtsBundleGenerator?.preferredConfigPath || join(pkg.path, "tsconfig.json"),
|
|
302
|
+
...dtsOptions.dtsBundleGenerator
|
|
303
|
+
};
|
|
304
|
+
const result = dtsBundleGenerator.generateDtsBundle(entryPoints, config);
|
|
305
|
+
const generatedFiles = [];
|
|
306
|
+
for (let i = 0; i < entryPoints.length; i++) {
|
|
307
|
+
const entryPoint = entryPoints[i];
|
|
308
|
+
const content = result[i];
|
|
309
|
+
if (!entryPoint || !content) {
|
|
310
|
+
logger.warn(`\u26A0\uFE0F No declaration content generated for entry point ${i}`);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
let relativePath = entryPoint.filePath.replace(`${pkg.path}/`, "").replace(`${pkg.path}\\`, "");
|
|
314
|
+
if (relativePath.startsWith("src/") || relativePath.startsWith("src\\")) {
|
|
315
|
+
relativePath = relativePath.substring(4);
|
|
316
|
+
}
|
|
317
|
+
const destPath = join(outputDir, relativePath).replace(/\.ts$/, ".d.ts");
|
|
318
|
+
const destDir = join(destPath, "..");
|
|
319
|
+
if (!existsSync(destDir)) {
|
|
320
|
+
mkdirSync(destDir, { recursive: true });
|
|
321
|
+
}
|
|
322
|
+
writeFileSync(destPath, content);
|
|
323
|
+
generatedFiles.push(destPath);
|
|
324
|
+
logger.info(
|
|
325
|
+
`\u2705 Generated declaration file: ${destPath} (${content.length} bytes)`
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
if (generatedFiles.length === 0) {
|
|
329
|
+
return {
|
|
330
|
+
success: false,
|
|
331
|
+
error: "No declaration files were generated"
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
logger.info(
|
|
335
|
+
`\u2705 Generated ${generatedFiles.length} declaration files for ${pkg.name} using dts-bundle-generator`
|
|
336
|
+
);
|
|
337
|
+
return {
|
|
338
|
+
success: true,
|
|
339
|
+
outputDir,
|
|
340
|
+
files: generatedFiles
|
|
341
|
+
};
|
|
342
|
+
} catch (error) {
|
|
343
|
+
return {
|
|
344
|
+
success: false,
|
|
345
|
+
error: `dts-bundle-generator failed: ${error instanceof Error ? error.message : String(error)}`
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function generateWithMkdist(pkg, dtsOptions, outputDir, _tsconfig) {
|
|
350
|
+
try {
|
|
351
|
+
if (!existsSync(outputDir)) {
|
|
352
|
+
mkdirSync(outputDir, { recursive: true });
|
|
353
|
+
}
|
|
354
|
+
const vfs = /* @__PURE__ */ new Map();
|
|
355
|
+
const readErrors = [];
|
|
356
|
+
for (const entryPoint of pkg.entryPoints) {
|
|
357
|
+
if (entryPoint.endsWith(".ts") && !entryPoint.endsWith(".d.ts")) {
|
|
358
|
+
try {
|
|
359
|
+
const content = readFileSync(entryPoint, "utf-8");
|
|
360
|
+
const hasExports = /export\s+(?:default\s+)?(?:function|class|interface|type|const|let|var|enum|namespace|\*|\{[^}]*\})/m.test(
|
|
361
|
+
content
|
|
362
|
+
);
|
|
363
|
+
if (!hasExports) {
|
|
364
|
+
logger.warn(
|
|
365
|
+
`\u26A0\uFE0F Entry point ${entryPoint} appears to have no exports - this may cause declaration generation to fail`
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
vfs.set(entryPoint, content);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
const errorMsg = `Failed to read entry point ${entryPoint}: ${error instanceof Error ? error.message : String(error)}`;
|
|
371
|
+
readErrors.push(errorMsg);
|
|
372
|
+
logger.warn(`\u26A0\uFE0F ${errorMsg}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (vfs.size === 0) {
|
|
377
|
+
return {
|
|
378
|
+
success: false,
|
|
379
|
+
error: "No valid TypeScript entry points found for mkdist provider"
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
const mkdistOptions = dtsOptions.mkdist || {};
|
|
383
|
+
const declarations = await getDeclarations(
|
|
384
|
+
vfs,
|
|
385
|
+
pkg,
|
|
386
|
+
dtsOptions,
|
|
387
|
+
outputDir,
|
|
388
|
+
mkdistOptions
|
|
389
|
+
);
|
|
390
|
+
const generatedFiles = [];
|
|
391
|
+
let hasErrors = false;
|
|
392
|
+
for (const [filename, result] of Object.entries(declarations)) {
|
|
393
|
+
if (!result.contents) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
const destPath = filename.replace(/\.ts$/, ".d.ts");
|
|
397
|
+
const destDir = join(destPath, "..");
|
|
398
|
+
if (!existsSync(destDir)) {
|
|
399
|
+
mkdirSync(destDir, { recursive: true });
|
|
400
|
+
}
|
|
401
|
+
try {
|
|
402
|
+
writeFileSync(destPath, result.contents);
|
|
403
|
+
generatedFiles.push(destPath);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
logger.error(
|
|
406
|
+
`Failed to write declaration file ${destPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
407
|
+
);
|
|
408
|
+
hasErrors = true;
|
|
409
|
+
}
|
|
410
|
+
if (result.errors && result.errors.length > 0) {
|
|
411
|
+
hasErrors = true;
|
|
412
|
+
for (const error of result.errors) {
|
|
413
|
+
logger.warn(`\u26A0\uFE0F Declaration error in ${filename}: ${error.message}`);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
logger.info(
|
|
417
|
+
`\u2705 Generated declaration file: ${destPath} (${result.contents.length} bytes)`
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
if (generatedFiles.length === 0) {
|
|
421
|
+
const diagnosticInfo = [];
|
|
422
|
+
if (vfs.size === 0) {
|
|
423
|
+
diagnosticInfo.push("No TypeScript files found in entry points");
|
|
424
|
+
if (readErrors.length > 0) {
|
|
425
|
+
diagnosticInfo.push(`File read errors: ${readErrors.length}`);
|
|
426
|
+
diagnosticInfo.push(...readErrors.map((error) => ` - ${error}`));
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
diagnosticInfo.push(`Found ${vfs.size} TypeScript files in VFS`);
|
|
430
|
+
if (readErrors.length > 0) {
|
|
431
|
+
diagnosticInfo.push(`File read errors: ${readErrors.length}`);
|
|
432
|
+
diagnosticInfo.push(...readErrors.map((error) => ` - ${error}`));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const declarationFiles = Array.from(vfs.keys()).filter(
|
|
436
|
+
(key) => key.endsWith(".d.ts")
|
|
437
|
+
);
|
|
438
|
+
if (declarationFiles.length > 0) {
|
|
439
|
+
diagnosticInfo.push(
|
|
440
|
+
`Generated ${declarationFiles.length} declaration files in VFS but failed to write them`
|
|
441
|
+
);
|
|
442
|
+
diagnosticInfo.push(
|
|
443
|
+
`Declaration files: ${declarationFiles.join(", ")}`
|
|
444
|
+
);
|
|
445
|
+
} else {
|
|
446
|
+
diagnosticInfo.push("No declaration files were generated in VFS");
|
|
447
|
+
}
|
|
448
|
+
const hasCompilationErrors = Object.values(declarations).some(
|
|
449
|
+
(result) => result.errors && result.errors.length > 0
|
|
450
|
+
);
|
|
451
|
+
if (hasCompilationErrors) {
|
|
452
|
+
diagnosticInfo.push("TypeScript compilation errors detected");
|
|
453
|
+
}
|
|
454
|
+
const validEntryPoints = pkg.entryPoints.filter(
|
|
455
|
+
(ep) => ep.endsWith(".ts") && !ep.endsWith(".d.ts")
|
|
456
|
+
);
|
|
457
|
+
diagnosticInfo.push(`Entry points processed: ${validEntryPoints.length}`);
|
|
458
|
+
if (validEntryPoints.length > 0) {
|
|
459
|
+
diagnosticInfo.push(`Entry points: ${validEntryPoints.join(", ")}`);
|
|
460
|
+
}
|
|
461
|
+
const errorMessage = [
|
|
462
|
+
"No declaration files were generated by mkdist provider",
|
|
463
|
+
"",
|
|
464
|
+
"Diagnostic information:",
|
|
465
|
+
...diagnosticInfo.map((info) => ` \u2022 ${info}`),
|
|
466
|
+
"",
|
|
467
|
+
"Troubleshooting suggestions:",
|
|
468
|
+
" \u2022 Ensure your TypeScript files have proper exports",
|
|
469
|
+
" \u2022 Check for TypeScript compilation errors in your source files",
|
|
470
|
+
" \u2022 Verify that your tsconfig.json has 'declaration: true'",
|
|
471
|
+
" \u2022 Try using a different DTS provider (e.g., 'typescript' or 'dts-bundle-generator')",
|
|
472
|
+
" \u2022 Check if your entry points contain valid TypeScript code"
|
|
473
|
+
].join("\n");
|
|
474
|
+
return {
|
|
475
|
+
success: false,
|
|
476
|
+
error: errorMessage
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
if (hasErrors) {
|
|
480
|
+
logger.warn(
|
|
481
|
+
`\u26A0\uFE0F mkdist generated ${generatedFiles.length} declaration files with some errors`
|
|
482
|
+
);
|
|
483
|
+
} else {
|
|
484
|
+
logger.info(
|
|
485
|
+
`\u2705 Generated ${generatedFiles.length} declaration files for ${pkg.name} using mkdist provider`
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
success: true,
|
|
490
|
+
outputDir,
|
|
491
|
+
files: generatedFiles
|
|
492
|
+
};
|
|
493
|
+
} catch (error) {
|
|
494
|
+
return {
|
|
495
|
+
success: false,
|
|
496
|
+
error: `mkdist declaration generation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
export async function generateWithTsgo(pkg, dtsOptions, outputDir) {
|
|
501
|
+
try {
|
|
502
|
+
logger.warn(
|
|
503
|
+
"\u26A0\uFE0F tsgo support is experimental and not yet implemented, falling back to TypeScript Compiler API"
|
|
504
|
+
);
|
|
505
|
+
return await generateBundlelessDeclarations(pkg, dtsOptions, outputDir, {
|
|
506
|
+
compilerOptions: {}
|
|
507
|
+
});
|
|
508
|
+
} catch (error) {
|
|
509
|
+
return {
|
|
510
|
+
success: false,
|
|
511
|
+
error: `tsgo declaration generation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GoBuildOptions } from "@reliverse/config/impl/build";
|
|
2
|
+
interface GoBuildResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
errors: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Build Go binaries for a package
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildGo(packagePath: string, packageName: string, config?: GoBuildOptions): Promise<GoBuildResult>;
|
|
10
|
+
export {};
|