dnt icon indicating copy to clipboard operation
dnt copied to clipboard

Use case: Specifier transformation only

Open jsejcksn opened this issue 2 years ago • 1 comments

I often author TypeScript modules (for use in Deno) which don't use the Deno namespace or any of the Deno NS types (shared utilities which would be useful in non-Deno environments like Node or transpiled for direct ESM usage in a browser). The only thing that prevents me from being able to use these modules in vanilla TypeScript compilation are the specifiers in the import/export statements.

Example:

Input: Existing modules using literal (Deno-style) specifiers:

./deno/add.ts:

/** Next level programming */
export function add (n1: number, n2: number): number {
  return n1 + n2;
}

./deno/math.ts:

export {add} from './add.ts';

export function subtract (n1: number, n2: number): number {
  return n1 - n2;
}

Output: I'd like to have only the specifiers transformed for ESM compatibility, like so:

assuming the output dir is ./compat

./compat/add.mts:

/** Next level programming */
export function add (n1: number, n2: number): number {
  return n1 + n2;
}

./compat/math.mts:

export {add} from './add.mjs';

export function subtract (n1: number, n2: number): number {
  return n1 - n2;
}


Does dnt offer something for this case: transforming only import/export specifiers, but otherwise leaving all other TS(X) source bytes untouched (types, formatting, comments, etc.)?

If so, and I missed it in the documentation, can you point me to the lines where it's described?

If not, does another project exist for this purpose? And will you consider this a feature request?

jsejcksn avatar May 26 '22 04:05 jsejcksn

@dsherret Thoughts on this?

jsejcksn avatar Aug 05 '22 18:08 jsejcksn