Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript types #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

adamhjk
Copy link

@adamhjk adamhjk commented Sep 17, 2019

  • Covers the syntax for Search Primitives
  • Covers the exported functions from the searchjs module
  • Uses generics to ensure the input and output types are correct.

This commit does not include wiring the types in to the npm distribution, as I'm uncertain of how to do that correctly with rollup. If you point me in an acceptable direction, I'm happy to update this PR with the code; otherwise, I'm stoked to learn how you do it. ;)

Thank you!

* Covers the syntax for Search Primitives
* Covers the exported functions from the searchjs module
* Uses generics to ensure the input and output types are correct.
@codecov-io
Copy link

Codecov Report

Merging #57 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master      #57   +/-   ##
=======================================
  Coverage   97.32%   97.32%           
=======================================
  Files           3        3           
  Lines         187      187           
=======================================
  Hits          182      182           
  Misses          5        5

@deitch
Copy link
Owner

deitch commented Sep 18, 2019

Hey Adam; thanks for pulling this into the TypeScript world.

I had a few questions:

  • why the tags line in .gitignore here?
  • I see you put the bindings in src/index.d.ts. I had thought that the bindings needed to be in the same filename as the main entrypoint for regular js, just alternate filename (index.js => index.d.ts), but the main entrypoint is lib/searchjs.js, see here. Did I misunderstand it? How would src/index.d.ts work? Further, because the publishing is limited to lib/ (see here), would src/index.d.ts even get published?
  • rollup is just running through the tree and combining it into a single file in lib/ (while lib/, in turn is in .gitignore). In our case, it is combining the three source files and running them through babel, since node still only has experimental support for es6 modules.

rollup does support multiple file conversions. I think the right approach is to leave it in src/, but add a separate entry in rollup config.

Let's do the following:

  1. Please add something to the README that typescript is supported with types defined.
  2. I will post here the updated rollup config (it is just a straight copy of the file), which you can add to your PR.

Then we can merge it in.

@deitch
Copy link
Owner

deitch commented Sep 18, 2019

Updated rollup.config.js should be:

import babel from 'rollup-plugin-babel';
import copy from 'rollup-plugin-copy'
import pkg from './package.json'

export default {
	input: 'src/searchjs.js',
	output: {
		file: pkg.main,
		name: 'SEARCHJS',
		format: 'umd',
		banner: `/* @license searchjs | (c) Searchjs Team and other contributors | https://github.com/deitch/searchjs */`
	},
	plugins: [babel({
		presets: [['@babel/preset-env', {
			modules: false
		}],
		],
	}),
        copy({
          targets: [{ src: 'src/index.d.ts', dest: 'lib/' }]
        })
    ]
};

And you need to install rollup-plugin-copy via:

npm i --save-dev rollup-plugin-copy

With that, the build process should include it in what is published to npm and make it available at the default path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants