dtsroll 1.7.4 → 1.7.5

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-CcbG5cCp.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.5";
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
 
@@ -4077,8 +4067,11 @@ const transform = (enableSourcemap) => {
4077
4067
  console.log(code);
4078
4068
  console.log(JSON.stringify(converted.ast.body, void 0, 2));
4079
4069
  }
4070
+ if (!enableSourcemap) {
4071
+ return { code, ast: converted.ast };
4072
+ }
4080
4073
  const map = preprocessed.code.generateMap({ hires: true, source: fileName });
4081
- if (enableSourcemap && DTS_EXTENSIONS.test(fileName)) {
4074
+ if (DTS_EXTENSIONS.test(fileName)) {
4082
4075
  pendingSourcemaps.set(fileName, {
4083
4076
  fileName,
4084
4077
  originalCode: code,
@@ -4494,39 +4487,6 @@ const createExternalizePlugin = (configuredExternals) => {
4494
4487
  };
4495
4488
  };
4496
4489
 
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
4490
  const nodeModules = `${path__default.sep}node_modules${path__default.sep}`;
4531
4491
  const removeBundledModulesPlugin = (outputDirectory, sizeRef) => {
4532
4492
  let deleteFiles = [];
@@ -4632,7 +4592,6 @@ const build = async (input, outputDirectory, externals, mode, conditions, source
4632
4592
  externalized,
4633
4593
  getPackageEntryPoint
4634
4594
  } = createExternalizePlugin(externals);
4635
- const { plugin: importChainPlugin, getImportChain } = createImportChainPlugin();
4636
4595
  const sizeRef = {};
4637
4596
  const rollupConfig = {
4638
4597
  input: createInputMap(input, outputDirectory),
@@ -4643,7 +4602,7 @@ const build = async (input, outputDirectory, externals, mode, conditions, source
4643
4602
  chunkFileNames: "_dtsroll-chunks/[hash]-[name].ts"
4644
4603
  },
4645
4604
  plugins: [
4646
- importChainPlugin,
4605
+ importTrace(),
4647
4606
  externalizePlugin,
4648
4607
  removeBundledModulesPlugin(outputDirectory, sizeRef),
4649
4608
  resolveSubpathImportsPlugin(),
@@ -4664,26 +4623,15 @@ const build = async (input, outputDirectory, externals, mode, conditions, source
4664
4623
  })
4665
4624
  ]
4666
4625
  };
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
- }
4626
+ const rollupBuild = await rollup(rollupConfig);
4627
+ const built = await rollupBuild[mode](rollupConfig.output);
4628
+ await rollupBuild.close();
4629
+ return {
4630
+ built,
4631
+ externalized,
4632
+ getPackageEntryPoint,
4633
+ sourceSize: sizeRef.value ?? 0
4634
+ };
4687
4635
  };
4688
4636
 
4689
4637
  const dtsroll = async ({
@@ -4780,4 +4728,4 @@ const dtsroll = async ({
4780
4728
  };
4781
4729
  };
4782
4730
 
4783
- export { DtsrollBuildError as D, black as a, bgYellow as b, dtsroll as d, logOutput as l };
4731
+ 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-CcbG5cCp.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-CcbG5cCp.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.5",
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",