GoogleChromeLabs / dictation_support

This SDK allows web-based apps/pages to interact with dictation devices
Apache License 2.0
12 stars 6 forks source link

NPM package #8

Closed kbalazs-ms closed 1 year ago

kbalazs-ms commented 1 year ago

Hi there!

We are integrating Philips device support into our web application, and aim to use dictation_support. Our issue is that there is no available NPM package (preferably published in the NPM registry) with appropriate Typescript typings in it, that we could just easily add to our project.

The supplied (generated) index.d.ts file follows the "module" logic (declares modules) but when including said modules in for example a WebPack based bundled project, the modules are not found ("moduleResolution": "node",), there are no corresponding module folder structure.

Example imports with the supplied index.d.ts:

import { DictationSupport } from 'dictation_support';
import { DictationDevice } from 'dictation_support/dictation_device';
import { ButtonEvent } from 'dictation_support/dictation_device_base';
import { DictationDeviceManager } from 'dictation_support/dictation_device_manager';

The buid process fails with module 'dictation_support' not found without aliasing the resolved imports

So in order to use the build index.d.ts, we have to either:

  1. Create a custom folder for the device-control library and either create a package.json pointing to the sdk.js or rename it to index.js
configureWebpack: {
    resolve: {
      alias: {
        dictation_support$: path.resolve('./packages/device-control-google-sdk'),
      },
    },
  },
  1. Or build a custom d.ts file with a declared namespace for DictationSupport and put everything from every declare module 'xyz' into that declared namespace, and register it globally, in order to use the types for the library correctly from a Typescript project.

Although the above approaches are workable, they require extensive manual maintenance if anything gets updated in this library and completely lack versioning.

I think it would be really beneficial for the ease-of-use and maintaining aspects of this project if it would have an appropriate NPM package released and constantly updated with changes. All integrators would have a much easier (and standard) way of using the package and would probably help with the adoption rate as well!

Thanks in advance!

alex292 commented 1 year ago

I have created https://github.com/GoogleChromeLabs/dictation_support/pull/9 as fix and will push as npm package once reviewed and landed. That should fix your issues and allow the package to be used as you intend.

Initially, we only had usage by including the precompiled SDK directly in mind, but you have a totally valid usage scenario here.

rpriewasser-sps commented 1 year ago

I´ll re-open this until we have an NPM package with appropriate Typescript typings in it

rpriewasser-sps commented 1 year ago

I´m closing this issue as done. npm package has been created, and it has been linked to this github repo. We can handle the request for automated npm publishing in another issue (if needed)