adblocker icon indicating copy to clipboard operation
adblocker copied to clipboard

Typescript declarations in cts and mts formats

Open chrmod opened this issue 1 year ago • 1 comments
trafficstars

This draft updates one package for purpose of demonstrating the direction. If accepted, all packages will be updated in this PR.

Fixes #4054

Typescript assumes that type delacrations for commonjs files will have .cts file extension.

To achieve that, we had to:

  • remove tsc from the build step
  • let rollup compile Typescript with @rollup/plugin-typescript
  • find a workaround rollup not being able to emit declarations
  • copy declarations entry point to new file extension with rollup-plugin-copy

As a byproduct of the workaround, the /dist file structure was flatten and now all esm, commonjs and declarations files are next to each other. One positive outcome of that change is that declarations can be automatically picked up without package.json referencing them explicitly. We have however kept those references for clarity.

New flatten file structure looks like this:

dist/types
dist/types/adblocker.d.cts
dist/types/adblocker.d.ts
dist/types/src
dist/types/src/parse.d.ts
dist/types/src/extended.d.ts
dist/types/src/types.d.ts
dist/types/src/eval.d.ts
dist/adblocker.cjs
dist/adblocker.js
dist/adblocker.umd.min.js
dist/adblocker.umd.min.js.map
dist/adblocker.cjs.map
dist/adblocker.js.map
dist/src
dist/src/extended.js
dist/src/types.js
dist/src/types.js.map
dist/src/eval.cjs.map
dist/src/eval.js.map
dist/src/types.cjs
dist/src/extended.cjs
dist/src/parse.js.map
dist/src/parse.cjs
dist/src/parse.js
dist/src/eval.js
dist/src/eval.cjs
dist/src/extended.cjs.map
dist/src/extended.js.map
dist/src/types.cjs.map
dist/src/parse.cjs.map

chrmod avatar Jul 02 '24 13:07 chrmod