I wrote a vscode extension that exposes an API for use by other extensions (by having the activate()
function return a value).
I would like to publish a scoped npm
package that exposes a declaration file (.d.ts
), that would assist developers of extensions to consume my extension.
My issue is that I cannot reuse the extension's package.json
, because it doesn't allow for @
in the package's name (vsce package
fails).
If I create a dedicated package.json
for the purpose of publishing the declaration file to npm
, I end up copying the .d.ts
file and all its dependencies from the extension's out
directory. This approach seems a bit cumbersome.
I couldn't find documentation that describes the proper way for doing this: publishing vscode extension declaration files to npm (scoped or not).
What is the correct approach to doing this?
This is what I ended up doing:
package.json
in it:name
property and suffixed it with-types
for clarity.copy
npm script that copies artifacts from theout
folder of the extension's folder. This script usesncp
for cross platform support.@types/vscode
to thedependencies
property (notdevDependencies
, as noted in publishing declaration files) because my.d.ts
file includes a reference tovscode
..npmignore
file to reinclude theout
folder (using negate:!out
) that was excluded in the.gitignore
file..js
files from theout
folder to avoid errors related to missing transitive dependencies. I could have created anothertsconfig.json
file that emits only.d.ts
files (usingemitDeclarationOnly
), but ended up using.npmignore
to do this.The above works for me, but there must be a better way, right??