Skip to content

Commit

Permalink
Three improvements for the price of one (#291)
Browse files Browse the repository at this point in the history
* Cleanup build

Partial: Requires next commit for a proper version!

* Port tests to the Jest framework

* Fix typings and cover them in a test

This should resolve #261 as long as the system of the test is being used. That being said, this system allows for a fully typed configuration with IDE support

TypeScript usage is further described in the documentation, so please accept that PR if this one is accepted.

* Run standard-format

* Remove duplicate types field from package
  • Loading branch information
favna authored and krisk committed Mar 7, 2019
1 parent 2b81492 commit 48e55f7
Show file tree
Hide file tree
Showing 22 changed files with 6,729 additions and 10,647 deletions.
5 changes: 1 addition & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"presets": ["@babel/preset-env"],
"plugins": [
"babel-plugin-add-module-exports"
]
"presets": ["@babel/preset-env", "@babel/preset-typescript"]
}
16 changes: 14 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Filter node stuff
node_modules/
npm-debug.log
*.log

# Filter MacOS folder store
.DS_Store
.idea

# Filter IDE settings
.idea/
.vs/
.vscode/

# Only publish 1 type of lockfile
package-lock.json

# Filter test runner
runner.js
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 3.4.3

- Fixed #261
- Rewrote tests to Jest framework
- Wrote tests for TypeScript typings
- Cleanup build

# Version 3.4.2

- Fixed #288
Expand Down
32 changes: 32 additions & 0 deletions configs/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const webpack = require('webpack')
const path = require('path')
const fs = require('fs')
const pckg = require('../package.json')

const LIBRARY_NAME = 'fuse'
const VERSION = pckg.version
const AUTHOR = pckg.author
const HOMEPAGE = pckg.homepage

const copyright = fs.readFileSync(path.resolve(__dirname, '../COPYRIGHT.txt'), 'UTF8')

module.exports = {
entry: path.resolve(__dirname, '../src/index.js'),
plugins: [
new webpack.BannerPlugin({
banner: copyright
.replace('{VERSION}', `v${VERSION}`)
.replace('{AUTHOR_URL}', `${AUTHOR.url}`)
.replace('{HOMEPAGE}', `${HOMEPAGE}`),
entryOnly: true
})
],
output: {
path: path.resolve(__dirname, '../dist'),
filename: `${LIBRARY_NAME}.js`,
library: 'Fuse',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: 'this'
}
}
7 changes: 7 additions & 0 deletions configs/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const merge = require('webpack-merge')
const common = require('./webpack.common.js')

module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map'
})
19 changes: 19 additions & 0 deletions configs/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const merge = require('webpack-merge')
const path = require('path')
const common = require('./webpack.common.js')
const TerserPlugin = require('terser-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')

module.exports = merge(common, {
mode: 'production',
devtool: false,
plugins: [
new CopyPlugin([{
from: path.resolve(__dirname, '../src/typings.d.ts'),
to: path.resolve(__dirname, '../dist/fuse.d.ts')
}])
],
optimization: {
minimizer: [new TerserPlugin()]
}
})
2 changes: 1 addition & 1 deletion index.d.ts → dist/fuse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface SearchOpts {
limit?: number
}

declare class Fuse<T, O extends Fuse.FuseOptions<T> = Fuse.FuseOptions<T>> {
declare class Fuse<T, O extends Fuse.FuseOptions<any> = Fuse.FuseOptions<any>> {
constructor(list: ReadonlyArray<T>, options?: O)
search(pattern: string, opts?: SearchOpts): O extends { id: keyof T } ?
O extends ({ includeMatches: true; } | { includeScore: true; }) ? Fuse.FuseResult<string>[] : string[] :
Expand Down
Loading

0 comments on commit 48e55f7

Please sign in to comment.