dtsroll 1.7.4 → 1.7.6

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/README.md CHANGED
@@ -1,7 +1,10 @@
1
- <p align="center">
2
- <img width="200" src="./.github/logo.webp">
3
- </p>
4
- <h2 align="center">dtsroll</h2>
1
+ <h2 align="center">
2
+ <img width="180" src="./.github/logo.webp">
3
+ <br>
4
+ dtsroll
5
+ <br><br>
6
+ <a href="https://npm.im/dtsroll"><img src="https://badgen.net/npm/v/dtsroll"></a> <a href="https://npm.im/dtsroll"><img src="https://badgen.net/npm/dm/dtsroll"></a>
7
+ </h2>
5
8
 
6
9
  Are you publishing a TypeScript project where consumers encounter type-checking errors like:
7
10
 
package/dist/cli.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { cli } from 'cleye';
3
- import { b as bgYellow, a as black, d as dtsroll, l as logOutput, D as DtsrollBuildError } from './index-DJ_g9wqZ.mjs';
3
+ import { b as bgYellow, a as black, d as dtsroll, l as logOutput } from './index-CqO1yLQ_.mjs';
4
+ import { patchErrorWithTrace } from 'rollup-plugin-import-trace';
4
5
  import 'node:path';
5
6
  import 'node:fs/promises';
6
7
  import 'rollup';
@@ -13,7 +14,7 @@ import 'resolve-pkg-maps';
13
14
  import 'byte-size';
14
15
 
15
16
  var name = "dtsroll";
16
- var version = "1.7.4";
17
+ var version = "1.7.6";
17
18
  var description = "Bundle dts files";
18
19
 
19
20
  const argv = cli({
@@ -66,19 +67,9 @@ dtsroll({
66
67
  }
67
68
  ).catch(
68
69
  (error) => {
69
- let errorMessage = "\nFailed to build";
70
- if (error instanceof DtsrollBuildError) {
71
- errorMessage += `
72
- File: ${error.id}`;
73
- if (error.importChain.length > 1) {
74
- errorMessage += "\n\n Import chain:\n ";
75
- errorMessage += error.importChain.join("\n \u2192 ");
76
- }
77
- }
78
- errorMessage += `
79
-
80
- ${error instanceof Error ? error.message : String(error)}`;
81
- console.error(errorMessage);
70
+ console.error("\nFailed to build\n");
71
+ patchErrorWithTrace(error);
72
+ console.error(error instanceof Error ? error.message : String(error));
82
73
  process.exitCode = 1;
83
74
  }
84
75
  );
@@ -6,6 +6,7 @@ import ts from 'typescript';
6
6
  import { createRequire } from 'node:module';
7
7
  import convert$1 from 'convert-source-map';
8
8
  import nodeResolve from '@rollup/plugin-node-resolve';
9
+ import { importTrace } from 'rollup-plugin-import-trace';
9
10
  import { up } from 'empathic/find';
10
11
  import { resolveImports } from 'resolve-pkg-maps';
11
12
  import byteSize from 'byte-size';
@@ -176,17 +177,6 @@ ${moduleIds.sort().map((moduleId, index) => {
176
177
  }
177
178
  };
178
179
 
179
- class DtsrollBuildError extends Error {
180
- id;
181
- importChain;
182
- constructor(message, id, importChain) {
183
- super(message);
184
- this.name = "DtsrollBuildError";
185
- this.id = id;
186
- this.importChain = importChain;
187
- }
188
- }
189
-
190
180
  const dtsExtensions = [".d.ts", ".d.cts", ".d.mts"];
191
181
  const isDts = (fileName) => dtsExtensions.some((extension) => fileName.endsWith(extension));
192
182
 
@@ -3142,6 +3132,23 @@ declare const ${defaultExport}: {`,
3142
3132
  }
3143
3133
  code.remove(start, end);
3144
3134
  }
3135
+ const fullText = sourceFile.getFullText();
3136
+ const eofTrivia = ts.getLeadingCommentRanges(fullText, sourceFile.endOfFileToken.getFullStart());
3137
+ const lastStatement = sourceFile.statements[sourceFile.statements.length - 1];
3138
+ const trailingTrivia = lastStatement ? ts.getTrailingCommentRanges(fullText, lastStatement.getEnd()) : void 0;
3139
+ for (const comment of [...eofTrivia ?? [], ...trailingTrivia ?? []]) {
3140
+ if (comment.kind !== ts.SyntaxKind.SingleLineCommentTrivia)
3141
+ continue;
3142
+ const text = fullText.slice(comment.pos, comment.end);
3143
+ if (!/\/\/[#@]\s*sourceMappingURL=/.test(text))
3144
+ continue;
3145
+ let start = comment.pos;
3146
+ if (start > 0 && fullText[start - 1] === "\n") {
3147
+ start -= 1;
3148
+ }
3149
+ code.remove(start, comment.end);
3150
+ break;
3151
+ }
3145
3152
  return {
3146
3153
  code,
3147
3154
  typeReferences,
@@ -4065,6 +4072,7 @@ const transform = (enableSourcemap) => {
4065
4072
  const moduleId = Array.from(moduleIds).find((id) => trimExtension(id) === name);
4066
4073
  const isEntry = Boolean(moduleId && this.getModuleInfo(moduleId)?.isEntry);
4067
4074
  const isJSON = Boolean(moduleId && JSON_EXTENSIONS.test(moduleId));
4075
+ const rawCode = code;
4068
4076
  let sourceFile = parse(fileName, code);
4069
4077
  const preprocessed = preProcess({ sourceFile, isEntry, isJSON });
4070
4078
  allTypeReferences.set(sourceFile.fileName, preprocessed.typeReferences);
@@ -4077,11 +4085,14 @@ const transform = (enableSourcemap) => {
4077
4085
  console.log(code);
4078
4086
  console.log(JSON.stringify(converted.ast.body, void 0, 2));
4079
4087
  }
4088
+ if (!enableSourcemap) {
4089
+ return { code, ast: converted.ast };
4090
+ }
4080
4091
  const map = preprocessed.code.generateMap({ hires: true, source: fileName });
4081
- if (enableSourcemap && DTS_EXTENSIONS.test(fileName)) {
4092
+ if (DTS_EXTENSIONS.test(fileName)) {
4082
4093
  pendingSourcemaps.set(fileName, {
4083
4094
  fileName,
4084
- originalCode: code,
4095
+ originalCode: rawCode,
4085
4096
  inputMapText
4086
4097
  });
4087
4098
  }
@@ -4494,39 +4505,6 @@ const createExternalizePlugin = (configuredExternals) => {
4494
4505
  };
4495
4506
  };
4496
4507
 
4497
- const createImportChainPlugin = () => {
4498
- const importerMap = /* @__PURE__ */ new Map();
4499
- const plugin = {
4500
- name: "import-chain-tracker",
4501
- buildStart: () => {
4502
- importerMap.clear();
4503
- },
4504
- async resolveId(source, importer) {
4505
- if (!importer) {
4506
- return null;
4507
- }
4508
- const resolved = await this.resolve(source, importer, { skipSelf: true });
4509
- if (resolved && !resolved.external && !importerMap.has(resolved.id)) {
4510
- importerMap.set(resolved.id, importer);
4511
- }
4512
- return null;
4513
- }
4514
- };
4515
- const getImportChain = (errorFileId) => {
4516
- const chain = [];
4517
- let current = errorFileId;
4518
- while (current) {
4519
- chain.unshift(current);
4520
- current = importerMap.get(current);
4521
- }
4522
- return chain;
4523
- };
4524
- return {
4525
- plugin,
4526
- getImportChain
4527
- };
4528
- };
4529
-
4530
4508
  const nodeModules = `${path__default.sep}node_modules${path__default.sep}`;
4531
4509
  const removeBundledModulesPlugin = (outputDirectory, sizeRef) => {
4532
4510
  let deleteFiles = [];
@@ -4632,7 +4610,6 @@ const build = async (input, outputDirectory, externals, mode, conditions, source
4632
4610
  externalized,
4633
4611
  getPackageEntryPoint
4634
4612
  } = createExternalizePlugin(externals);
4635
- const { plugin: importChainPlugin, getImportChain } = createImportChainPlugin();
4636
4613
  const sizeRef = {};
4637
4614
  const rollupConfig = {
4638
4615
  input: createInputMap(input, outputDirectory),
@@ -4643,7 +4620,7 @@ const build = async (input, outputDirectory, externals, mode, conditions, source
4643
4620
  chunkFileNames: "_dtsroll-chunks/[hash]-[name].ts"
4644
4621
  },
4645
4622
  plugins: [
4646
- importChainPlugin,
4623
+ importTrace(),
4647
4624
  externalizePlugin,
4648
4625
  removeBundledModulesPlugin(outputDirectory, sizeRef),
4649
4626
  resolveSubpathImportsPlugin(),
@@ -4664,26 +4641,15 @@ const build = async (input, outputDirectory, externals, mode, conditions, source
4664
4641
  })
4665
4642
  ]
4666
4643
  };
4667
- try {
4668
- const rollupBuild = await rollup(rollupConfig);
4669
- const built = await rollupBuild[mode](rollupConfig.output);
4670
- await rollupBuild.close();
4671
- return {
4672
- built,
4673
- externalized,
4674
- getPackageEntryPoint,
4675
- sourceSize: sizeRef.value ?? 0
4676
- };
4677
- } catch (error) {
4678
- if (error instanceof Error && "id" in error && typeof error.id === "string") {
4679
- throw new DtsrollBuildError(
4680
- error.message,
4681
- error.id,
4682
- getImportChain(error.id)
4683
- );
4684
- }
4685
- throw error;
4686
- }
4644
+ const rollupBuild = await rollup(rollupConfig);
4645
+ const built = await rollupBuild[mode](rollupConfig.output);
4646
+ await rollupBuild.close();
4647
+ return {
4648
+ built,
4649
+ externalized,
4650
+ getPackageEntryPoint,
4651
+ sourceSize: sizeRef.value ?? 0
4652
+ };
4687
4653
  };
4688
4654
 
4689
4655
  const dtsroll = async ({
@@ -4780,4 +4746,4 @@ const dtsroll = async ({
4780
4746
  };
4781
4747
  };
4782
4748
 
4783
- export { DtsrollBuildError as D, black as a, bgYellow as b, dtsroll as d, logOutput as l };
4749
+ export { black as a, bgYellow as b, dtsroll as d, logOutput as l };
package/dist/index.mjs CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import 'node:path';
3
- export { d as dtsroll } from './index-DJ_g9wqZ.mjs';
3
+ export { d as dtsroll } from './index-CqO1yLQ_.mjs';
4
4
  import 'node:fs/promises';
5
5
  import 'rollup';
6
6
  import 'typescript';
7
7
  import 'node:module';
8
8
  import 'convert-source-map';
9
9
  import '@rollup/plugin-node-resolve';
10
+ import 'rollup-plugin-import-trace';
10
11
  import 'empathic/find';
11
12
  import 'resolve-pkg-maps';
12
13
  import 'byte-size';
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { d as dtsroll, l as logOutput } from './index-DJ_g9wqZ.mjs';
2
+ import { d as dtsroll, l as logOutput } from './index-CqO1yLQ_.mjs';
3
3
  import 'node:path';
4
4
  import 'node:fs/promises';
5
5
  import 'rollup';
@@ -7,6 +7,7 @@ import 'typescript';
7
7
  import 'node:module';
8
8
  import 'convert-source-map';
9
9
  import '@rollup/plugin-node-resolve';
10
+ import 'rollup-plugin-import-trace';
10
11
  import 'empathic/find';
11
12
  import 'resolve-pkg-maps';
12
13
  import 'byte-size';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtsroll",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "description": "Bundle dts files",
5
5
  "keywords": [
6
6
  "bundle",
@@ -43,7 +43,8 @@
43
43
  "convert-source-map": "^2.0.0",
44
44
  "empathic": "^2.0.0",
45
45
  "resolve-pkg-maps": "^1.0.0",
46
- "rollup": "^4.55.3"
46
+ "rollup": "^4.55.3",
47
+ "rollup-plugin-import-trace": "^1.0.0"
47
48
  },
48
49
  "peerDependencies": {
49
50
  "typescript": "^4.5 || ^5.0",