rolldown-plugin-dts 0.5.0 → 0.5.2
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/index.d.ts +1 -1
- package/dist/index.js +27 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IsolatedDeclarationsOptions } from "oxc-transform";
|
|
2
|
-
import { CompilerOptions } from "typescript";
|
|
3
2
|
import { Plugin } from "rolldown";
|
|
3
|
+
import { CompilerOptions } from "typescript";
|
|
4
4
|
|
|
5
5
|
//#region src/fake-js.d.ts
|
|
6
6
|
declare function createFakeJsPlugin({ dtsInput }: Pick<Options, "dtsInput">): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { MagicStringAST } from "magic-string-ast";
|
|
2
|
-
import {
|
|
2
|
+
import { parseSync } from "oxc-parser";
|
|
3
3
|
import path, { basename, extname } from "node:path";
|
|
4
4
|
import { createResolver } from "dts-resolver";
|
|
5
5
|
import { getTsconfig } from "get-tsconfig";
|
|
6
6
|
import { isolatedDeclaration } from "oxc-transform";
|
|
7
|
-
import
|
|
8
|
-
import * as ts from "typescript";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
9
8
|
|
|
10
9
|
//#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
|
11
10
|
var WalkerBase = class {
|
|
@@ -251,8 +250,8 @@ function createFakeJsPlugin({ dtsInput }) {
|
|
|
251
250
|
},
|
|
252
251
|
transform: {
|
|
253
252
|
filter: { id: RE_DTS },
|
|
254
|
-
|
|
255
|
-
const { program, comments } =
|
|
253
|
+
handler(code, id) {
|
|
254
|
+
const { program, comments } = parseSync(id, code);
|
|
256
255
|
const preserved = collectReferenceDirectives(comments);
|
|
257
256
|
preserveMap.set(id, preserved);
|
|
258
257
|
const s = new MagicStringAST(code);
|
|
@@ -303,9 +302,9 @@ function createFakeJsPlugin({ dtsInput }) {
|
|
|
303
302
|
return str;
|
|
304
303
|
}
|
|
305
304
|
},
|
|
306
|
-
|
|
305
|
+
renderChunk(code, chunk) {
|
|
307
306
|
if (!RE_DTS.test(chunk.fileName)) return;
|
|
308
|
-
const { program } =
|
|
307
|
+
const { program } = parseSync(chunk.fileName, code);
|
|
309
308
|
const s = new MagicStringAST(code);
|
|
310
309
|
const comments = new Set();
|
|
311
310
|
for (const id of chunk.moduleIds) {
|
|
@@ -438,6 +437,17 @@ function importNamespace(s, source, imported, getIdentifierIndex) {
|
|
|
438
437
|
|
|
439
438
|
//#endregion
|
|
440
439
|
//#region src/utils/tsc.ts
|
|
440
|
+
let ts;
|
|
441
|
+
let formatHost;
|
|
442
|
+
function initTs() {
|
|
443
|
+
const require = createRequire(import.meta.url);
|
|
444
|
+
ts = require("typescript");
|
|
445
|
+
formatHost = {
|
|
446
|
+
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
447
|
+
getNewLine: () => ts.sys.newLine,
|
|
448
|
+
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
449
|
+
};
|
|
450
|
+
}
|
|
441
451
|
const defaultCompilerOptions = {
|
|
442
452
|
declaration: true,
|
|
443
453
|
noEmit: false,
|
|
@@ -447,14 +457,9 @@ const defaultCompilerOptions = {
|
|
|
447
457
|
declarationMap: false,
|
|
448
458
|
skipLibCheck: true,
|
|
449
459
|
preserveSymlinks: true,
|
|
450
|
-
target:
|
|
460
|
+
target: 99,
|
|
451
461
|
resolveJsonModule: true
|
|
452
462
|
};
|
|
453
|
-
const formatHost = {
|
|
454
|
-
getCurrentDirectory: () => ts$1.sys.getCurrentDirectory(),
|
|
455
|
-
getNewLine: () => ts$1.sys.newLine,
|
|
456
|
-
getCanonicalFileName: ts$1.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
457
|
-
};
|
|
458
463
|
function createOrGetTsModule(programs, compilerOptions, id, code, isEntry) {
|
|
459
464
|
const tsProgram = programs.find(({ program }) => {
|
|
460
465
|
if (isEntry) return program.getRootFileNames().includes(id);
|
|
@@ -478,7 +483,7 @@ function createTsProgram(compilerOptions, id, code) {
|
|
|
478
483
|
...loadTsconfig(id),
|
|
479
484
|
...compilerOptions
|
|
480
485
|
};
|
|
481
|
-
const host = ts
|
|
486
|
+
const host = ts.createCompilerHost(options, true);
|
|
482
487
|
const { readFile: _readFile, fileExists: _fileExists } = host;
|
|
483
488
|
host.fileExists = (fileName) => {
|
|
484
489
|
if (files.has(fileName)) return true;
|
|
@@ -488,9 +493,9 @@ function createTsProgram(compilerOptions, id, code) {
|
|
|
488
493
|
if (files.has(fileName)) return files.get(fileName);
|
|
489
494
|
return _readFile(fileName);
|
|
490
495
|
};
|
|
491
|
-
const program = ts
|
|
496
|
+
const program = ts.createProgram([id], {
|
|
492
497
|
...compilerOptions,
|
|
493
|
-
moduleResolution: ts
|
|
498
|
+
moduleResolution: ts.ModuleResolutionKind.Node10,
|
|
494
499
|
declaration: true,
|
|
495
500
|
emitDeclarationOnly: true,
|
|
496
501
|
outDir: void 0,
|
|
@@ -508,13 +513,13 @@ function createTsProgram(compilerOptions, id, code) {
|
|
|
508
513
|
}
|
|
509
514
|
const tsconfigCache = new Map();
|
|
510
515
|
function loadTsconfig(id) {
|
|
511
|
-
const configPath = ts
|
|
516
|
+
const configPath = ts.findConfigFile(path.dirname(id), ts.sys.fileExists);
|
|
512
517
|
if (!configPath) return {};
|
|
513
518
|
if (tsconfigCache.has(configPath)) return tsconfigCache.get(configPath);
|
|
514
|
-
const { config, error } = ts
|
|
515
|
-
if (error) throw ts
|
|
516
|
-
const configContents = ts
|
|
517
|
-
if (configContents.errors.length) throw ts
|
|
519
|
+
const { config, error } = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
520
|
+
if (error) throw ts.formatDiagnostic(error, formatHost);
|
|
521
|
+
const configContents = ts.parseJsonConfigFileContent(config, ts.sys, path.dirname(configPath));
|
|
522
|
+
if (configContents.errors.length) throw ts.formatDiagnostics(configContents.errors, formatHost);
|
|
518
523
|
tsconfigCache.set(configPath, configContents.options);
|
|
519
524
|
return configContents.options;
|
|
520
525
|
}
|
|
@@ -535,6 +540,7 @@ function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDe
|
|
|
535
540
|
const { config } = getTsconfig(options.cwd) || {};
|
|
536
541
|
if (config?.compilerOptions?.isolatedDeclarations) isolatedDeclaration$1 = { stripInternal: !!config?.compilerOptions.stripInternal };
|
|
537
542
|
}
|
|
543
|
+
if (!isolatedDeclaration$1) initTs();
|
|
538
544
|
},
|
|
539
545
|
options({ input }) {
|
|
540
546
|
if (isPlainObject(input)) inputOption = { ...input };
|