dnt icon indicating copy to clipboard operation
dnt copied to clipboard

Way to put `import type` only dependencies into `devDependencies`?

Open baoshan opened this issue 2 years ago • 2 comments

There’re several modules in my import_map.json from where I import some types like:

import type { Foo } from "bar"

I wonder if there is a way to put such modules in the devDependencies section of the generated package.json. It doesn’t need to be done automatically, manual configuration is fine.

Thanks.

baoshan avatar Jul 01 '22 07:07 baoshan

Hmmm... it would be hard to do this automatically. Manual configuration sounds better, but I'm not sure at the moment how this configuration would look. Do you have any ideas?

For now, one workaround to get this to work (I THINK) would be to add an npm dev dependency like:

await build({
  // ...etc...
  package: {
    // ...etc...
    devDependencies: {
      "npm_bar": "npm:[email protected]",
    },
  }
});

...then create a deno and node specific file https://github.com/denoland/dnt#node-and-deno-specific-modules where the deno file re-exports the types from the module found in the import map (export type { Foo } from "bar") and the node file re-exports the types from npm (export type { Foo } from "npm_bar")... I haven't tested it to know if it will work though.

dsherret avatar Jul 04 '22 17:07 dsherret

Maintaining separate files for deno and node seems like overkill for this case? How about simply putting bar into devDependencies, like:

  • import_map.json
{
  "imports": {
    "bar": "https://esm.sh/[email protected]"
  }
}
  • build_npm.ts
await build({
  // ...etc...
  package: {
    // ...etc...
    devDependencies: {
      "bar": "",
    },
  }
});

baoshan avatar Jul 06 '22 14:07 baoshan