Skip to content

Commit

Permalink
Switch to a vite based setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Rockwood committed Sep 21, 2022
1 parent 9b21b97 commit 3c9a492
Show file tree
Hide file tree
Showing 11 changed files with 2,399 additions and 34,841 deletions.
37,032 changes: 2,296 additions & 34,736 deletions package-lock.json

Large diffs are not rendered by default.

56 changes: 13 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,36 @@
"name": "@shortwave/trie",
"version": "1.1.0",
"license": "MIT",
"main": "dist/index.js",
"main": "dist/trie.cjs",
"typings": "dist/index.d.ts",
"module": "dist/trie.esm.js",
"module": "dist/trie.mjs",
"files": [
"dist"
"dist",
"src"
],
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=10"
"node": ">=14"
},
"scripts": {
"analyze": "size-limit --why",
"benchmark": "npm run build && NODE_ENV=production 0x -o ./test/benchmark",
"build": "tsdx build",
"lint": "tsdx lint",
"prepack": "tsdx build",
"prepare": "tsdx build",
"release": "np",
"size": "size-limit",
"start": "tsdx watch",
"test": "tsdx test"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
"build": "vite build"
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"size-limit": [
{
"path": "dist/trie.cjs.production.min.js",
"limit": "10 KB"
},
{
"path": "dist/trie.esm.js",
"limit": "10 KB"
}
],
"repository": "github:shortwave/trie",
"devDependencies": {
"@size-limit/preset-small-lib": "^5.0.3",
"@types/benchmark": "^2.1.1",
"@types/lodash": "^4.14.172",
"@types/seedrandom": "^3.0.1",
"0x": "^4.10.2",
"benchmark": "^2.1.4",
"husky": "^7.0.1",
"lodash": "^4.17.21",
"np": "^7.5.0",
"seedrandom": "^3.0.5",
"size-limit": "^5.0.3",
"tsdx": "^0.14.1",
"tslib": "^2.3.1",
"typescript": "^3.9.10"
},
"repository": "github:shortwave/trie"
"typescript": "^4.8.3",
"vite": "^3.1.3",
"vite-dts": "^1.0.4",
"vite-plugin-dts": "^1.5.0",
"vitest": "^0.23.4"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Node from './node';
import { Item, SearchOptions } from './common';
import type { Item, SearchOptions } from './common';

interface TrieOptions {
readonly maxWidth: number;
Expand Down
58 changes: 0 additions & 58 deletions test/benchmark.js

This file was deleted.

52 changes: 52 additions & 0 deletions test/perf.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import contacts from './contacts.json';
import Trie from '../src/index';
import {describe, bench, beforeEach} from 'vitest'

function setup(t: Trie<unknown>) {
contacts.forEach(function(data) {
const email = (data.email || '-').toLowerCase();
const name = data.name.toLowerCase();

const score = data.score;

t.add({
key: email,
score: score,
value: data,
distinct: email + name,
});

t.add({
key: name,
score: score,
value: data,
distinct: email + name,
});
});
}

describe('Trie', () => {
bench('populate', () => {
setup(new Trie());
});


describe('lookupPrefix', () => {

let t = new Trie<unknown>();
beforeEach(() => {
t = new Trie();
setup(t);
});

function addBenchmarkTest(prefix: string, limit: number) {
bench(`(${prefix}, ${limit})`, () => {
t.prefixSearch(prefix, { limit, unique: true });
});
}

addBenchmarkTest('t', 5);
addBenchmarkTest('tee', 3);
addBenchmarkTest('tee', 6);
});
});
1 change: 1 addition & 0 deletions test/perf.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {describe, it, expect} from 'vitest';
import Trie from '../src/index';

describe('Trie Performance', () => {
Expand Down
1 change: 1 addition & 0 deletions test/randomized.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {describe, it, expect} from 'vitest';
import Trie, { Item, SearchOptions } from '../src/index';
import seedrandom from 'seedrandom';
import {
Expand Down
1 change: 1 addition & 0 deletions test/trie.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {describe, it, expect} from 'vitest';
import Trie, { SearchOptions, Item } from '../src/index';

/** A trie that strictly validates it's invariants after every operation. */
Expand Down
1 change: 1 addition & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {describe, it, expect} from 'vitest'
import { filterInPlace } from '../src/utils';

describe('filter in place', () => {
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"include": ["src", "benchmark", "types"],
"include": ["src"],
"compilerOptions": {
"module": "ESNext",
"lib": ["ESNext"],
Expand Down Expand Up @@ -29,7 +29,6 @@
"skipLibCheck": true,
// error out if import and file system have a casing mismatch. Recommended by TS
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true
"noEmit": false
}
}
31 changes: 31 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import path from "path";
import { defineConfig } from "vitest/config";
import dts from 'vite-plugin-dts'

const fileName = {
es: `trie.mjs`,
cjs: `trie.cjs`,
};

export default defineConfig({
plugins: [dts()],
base: "./",
build: {
lib: {
entry: path.resolve(__dirname, "src/index.ts"),
name: "trie",
formats: ["es", "cjs"],
fileName: (format) => fileName[format],
},
rollupOptions: {
output: {
// Since we publish our ./src folder, there's no point
// in bloating sourcemaps with another copy of it.
sourcemapExcludeSources: true,
},
},
sourcemap: true,
target: 'es6',
minify: false,
},
});

0 comments on commit 3c9a492

Please sign in to comment.