dtsroll 1.3.0 → 1.4.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.
package/README.md CHANGED
@@ -1,11 +1,13 @@
1
- # dtsroll
2
-
3
- _dtsroll_ is a CLI tool for bundling TypeScript declaration (`.d.ts`) files.
4
-
5
1
  <p align="center">
6
- <img width="600" src="./.github/screenshot.webp">
2
+ <img width="150" src="./.github/logo.webp">
7
3
  </p>
8
4
 
5
+ <h2 align="center">
6
+ dtsroll
7
+ </h2>
8
+
9
+ _dtsroll_ is a CLI tool for bundling TypeScript declaration (`.d.ts`) files.
10
+
9
11
  ### Why bundle `.d.ts` files?
10
12
 
11
13
  - **Smaller distribution**
@@ -20,6 +22,11 @@ _dtsroll_ is a CLI tool for bundling TypeScript declaration (`.d.ts`) files.
20
22
 
21
23
  Flattens multiple files into one, reducing TypeScript's file resolution for type checking.
22
24
 
25
+ <p align="center">
26
+ <img width="600" src="./.github/screenshot.webp">
27
+ </p>
28
+
29
+
23
30
  ## Install
24
31
  ```
25
32
  npm install --save-dev dtsroll
@@ -86,6 +93,13 @@ To fix this, _dtsroll_ will display a warning suggesting you move the `@types/*`
86
93
 
87
94
  ## CLI
88
95
 
96
+ ### Usage
97
+ ```sh
98
+ dtsroll [-flags] [...entry dts files]
99
+ ```
100
+
101
+ The default usage is to run `dtsroll` without any flags/arguments in a directory containing a `package.json` file. This allows the configuration to be inferred automatically.
102
+
89
103
  ### --help, -h
90
104
  Display usage instructions.
91
105
 
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
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 } from './index-0B0-hvfH.mjs';
3
+ import { b as bgYellow, a as black, d as dtsroll, l as logOutput } from './index-C9-38zEa.mjs';
4
4
  import 'node:path';
5
5
  import 'node:fs/promises';
6
6
  import 'rollup';
@@ -9,7 +9,7 @@ import '@rollup/plugin-node-resolve';
9
9
  import 'byte-size';
10
10
 
11
11
  var name = "dtsroll";
12
- var version = "1.3.0";
12
+ var version = "1.4.1";
13
13
  var description = "Bundle dts files";
14
14
 
15
15
  const argv = cli({
@@ -291,11 +291,41 @@ const getPackageName = (id) => {
291
291
  return id.slice(0, indexOfSlash);
292
292
  };
293
293
 
294
+ const getAllFiles = async (directoryPath, dontShortenPath) => {
295
+ const directoryFiles = await fs.readdir(directoryPath, { withFileTypes: true });
296
+ const fileTree = await Promise.all(
297
+ directoryFiles.map(async (entry) => {
298
+ const filePath = path.join(directoryPath, entry.name);
299
+ if (entry.isDirectory()) {
300
+ const files = await getAllFiles(filePath, true);
301
+ return dontShortenPath ? files : files.map((file) => `./${path.relative(directoryPath, file)}`);
302
+ }
303
+ return dontShortenPath ? filePath : `./${path.relative(directoryPath, filePath)}`;
304
+ })
305
+ );
306
+ return fileTree.flat();
307
+ };
308
+
294
309
  const readPackageJson = async (filePath) => {
295
310
  const packageJsonString = await fs.readFile(filePath, "utf8");
296
311
  return JSON.parse(packageJsonString);
297
312
  };
298
- const getDtsEntryPoints = (packageJson, packageJsonDirectory) => {
313
+ const traverseExports = (exportValue, propertyPath) => {
314
+ if (typeof exportValue === "string") {
315
+ return [[exportValue, propertyPath]];
316
+ }
317
+ if (Array.isArray(exportValue)) {
318
+ return exportValue.flatMap((value, index) => traverseExports(value, `${propertyPath}[${index}]`));
319
+ }
320
+ if (typeof exportValue === "object" && exportValue !== null) {
321
+ return Object.entries(exportValue).flatMap(([property, value]) => {
322
+ const newProperty = propertyNeedsQuotes(property) ? `["${property}"]` : `.${property}`;
323
+ return traverseExports(value, propertyPath + newProperty);
324
+ });
325
+ }
326
+ return [];
327
+ };
328
+ const getDtsEntryPoints = async (packageJson, packageJsonDirectory) => {
299
329
  const entryPoints = {};
300
330
  const addEntry = (subpath, from) => {
301
331
  if (!isDts(subpath)) {
@@ -313,19 +343,23 @@ const getDtsEntryPoints = (packageJson, packageJsonDirectory) => {
313
343
  addEntry(packageJson.typings, "typings");
314
344
  }
315
345
  if (packageJson.exports) {
316
- (function gather(exportValue, propertyPath) {
317
- if (typeof exportValue === "string") {
318
- addEntry(exportValue, propertyPath);
319
- } else if (Array.isArray(exportValue)) {
320
- exportValue.forEach((value, index) => gather(value, `${propertyPath}[${index}]`));
346
+ const subpaths = traverseExports(packageJson.exports, "exports");
347
+ let packageFiles;
348
+ for (const [subpath, fromProperty] of subpaths) {
349
+ if (!subpath.includes("*")) {
350
+ addEntry(subpath, fromProperty);
351
+ continue;
321
352
  }
322
- if (typeof exportValue === "object" && exportValue) {
323
- for (const [property, value] of Object.entries(exportValue)) {
324
- const newProperty = propertyNeedsQuotes(property) ? `["${property}"]` : `.${property}`;
325
- gather(value, propertyPath + newProperty);
353
+ if (!packageFiles) {
354
+ packageFiles = await getAllFiles(packageJsonDirectory);
355
+ }
356
+ const [prefix, suffix] = subpath.split("*", 2);
357
+ for (const file of packageFiles) {
358
+ if (file.startsWith(prefix) && file.endsWith(suffix)) {
359
+ addEntry(file, fromProperty);
326
360
  }
327
361
  }
328
- })(packageJson.exports, "exports");
362
+ }
329
363
  }
330
364
  return entryPoints;
331
365
  };
@@ -514,7 +548,7 @@ const build = async (input, outputDirectory, externals, mode, conditions) => {
514
548
  // sourcemap: true,
515
549
  dir: outputDirectory,
516
550
  entryFileNames: "[name]",
517
- chunkFileNames: "_dtsroll-chunks/[name].ts"
551
+ chunkFileNames: "_dtsroll-chunks/[hash]-[name].ts"
518
552
  },
519
553
  plugins: [
520
554
  externalizePlugin,
@@ -566,7 +600,7 @@ const dtsroll = async ({
566
600
  }
567
601
  const manualInput = inputs && inputs.length > 0;
568
602
  const validatedInputs = await validateInput(
569
- manualInput ? inputs.map((file) => path.resolve(file)) : pkgJson?.getDtsEntryPoints()
603
+ manualInput ? inputs.map((file) => path.resolve(file)) : await pkgJson?.getDtsEntryPoints()
570
604
  );
571
605
  const inputFiles = validatedInputs.filter((input) => !input[2]).map(([file]) => file);
572
606
  if (inputFiles.length === 0) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'node:path';
2
- export { d as dtsroll } from './index-0B0-hvfH.mjs';
2
+ export { d as dtsroll } from './index-C9-38zEa.mjs';
3
3
  import 'node:fs/promises';
4
4
  import 'rollup';
5
5
  import 'rollup-plugin-dts';
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { d as dtsroll, l as logOutput } from './index-0B0-hvfH.mjs';
1
+ import { d as dtsroll, l as logOutput } from './index-C9-38zEa.mjs';
2
2
  import 'node:path';
3
3
  import 'node:fs/promises';
4
4
  import 'rollup';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtsroll",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Bundle dts files",
5
5
  "keywords": [
6
6
  "bundle",