rolldown-plugin-dts 0.5.0 → 0.5.1

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { MagicStringAST } from "magic-string-ast";
2
- import { parseAsync } from "oxc-parser";
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 * as ts$1 from "typescript";
8
7
  import * as ts from "typescript";
8
+ import { createRequire } from "node:module";
9
9
 
10
10
  //#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
11
11
  var WalkerBase = class {
@@ -251,8 +251,8 @@ function createFakeJsPlugin({ dtsInput }) {
251
251
  },
252
252
  transform: {
253
253
  filter: { id: RE_DTS },
254
- async handler(code, id) {
255
- const { program, comments } = await parseAsync(id, code);
254
+ handler(code, id) {
255
+ const { program, comments } = parseSync(id, code);
256
256
  const preserved = collectReferenceDirectives(comments);
257
257
  preserveMap.set(id, preserved);
258
258
  const s = new MagicStringAST(code);
@@ -303,9 +303,9 @@ function createFakeJsPlugin({ dtsInput }) {
303
303
  return str;
304
304
  }
305
305
  },
306
- async renderChunk(code, chunk) {
306
+ renderChunk(code, chunk) {
307
307
  if (!RE_DTS.test(chunk.fileName)) return;
308
- const { program } = await parseAsync(chunk.fileName, code);
308
+ const { program } = parseSync(chunk.fileName, code);
309
309
  const s = new MagicStringAST(code);
310
310
  const comments = new Set();
311
311
  for (const id of chunk.moduleIds) {
@@ -438,6 +438,17 @@ function importNamespace(s, source, imported, getIdentifierIndex) {
438
438
 
439
439
  //#endregion
440
440
  //#region src/utils/tsc.ts
441
+ let ts$1;
442
+ let formatHost;
443
+ function initTs() {
444
+ const require = createRequire(import.meta.url);
445
+ ts$1 = require("typescript");
446
+ formatHost = {
447
+ getCurrentDirectory: () => ts$1.sys.getCurrentDirectory(),
448
+ getNewLine: () => ts$1.sys.newLine,
449
+ getCanonicalFileName: ts$1.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
450
+ };
451
+ }
441
452
  const defaultCompilerOptions = {
442
453
  declaration: true,
443
454
  noEmit: false,
@@ -447,14 +458,9 @@ const defaultCompilerOptions = {
447
458
  declarationMap: false,
448
459
  skipLibCheck: true,
449
460
  preserveSymlinks: true,
450
- target: ts$1.ScriptTarget.ESNext,
461
+ target: 99,
451
462
  resolveJsonModule: true
452
463
  };
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
464
  function createOrGetTsModule(programs, compilerOptions, id, code, isEntry) {
459
465
  const tsProgram = programs.find(({ program }) => {
460
466
  if (isEntry) return program.getRootFileNames().includes(id);
@@ -535,6 +541,7 @@ function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDe
535
541
  const { config } = getTsconfig(options.cwd) || {};
536
542
  if (config?.compilerOptions?.isolatedDeclarations) isolatedDeclaration$1 = { stripInternal: !!config?.compilerOptions.stripInternal };
537
543
  }
544
+ if (!isolatedDeclaration$1) initTs();
538
545
  },
539
546
  options({ input }) {
540
547
  if (isPlainObject(input)) inputOption = { ...input };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",