Skip to content

Commit

Permalink
Add a script to build the source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Finesse committed Oct 14, 2020
1 parent 5a3b450 commit 71ace0c
Show file tree
Hide file tree
Showing 11 changed files with 687 additions and 19 deletions.
26 changes: 24 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 1,29 @@
{
"name": "@fingerprintjs/fingerprintjs",
"version": "3.0.0-dev",
"version": "3.0.0-beta.2",
"license": "MIT",
"main": "dist/fp.cjs.js",
"module": "dist/fp.esm.js",
"types": "dist/fp.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"scripts": {
"build": "rimraf dist && rollup -c"
},
"dependencies": {
"tslib": "^2.0.1"
},
"devDependencies": {
"typescript": "^4.0.2"
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.28.2",
"rollup-plugin-dts": "^1.4.13",
"rollup-plugin-license": "^2.2.0",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.0.3"
}
}
55 changes: 55 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 1,62 @@
# FingerprintJS

Work in progress, stay tuned.

## Quick start

### In browser

```html
<script>
function onFingerprintJSLoad(fp) {
fp.get().then(({ visitorId }) => console.log(visitorId));
}
</script>
<script
async src="https://cdn.jsdelivr.net/npm/@fingerprintjs/[email protected]/dist/fp.min.js"
onload="FingerprintJS.load().then(onFingerprintJSLoad)"
></script>
```

### Webpack/Rollup/Browserify

```bash
npm i @fingerprintjs/fingerprintjs
```

```js
import * as FPJS from '@fingerprintjs/fingerprintjs';

(async () => {
const fpjs = await FPJS.load();
const { visitorId } = await fpjs.get();
console.log(visitorId)
})();
```

## Version policy

The library doesn't promise same visitor identifier between any versions
but tries to keep them same as much as reasonable.

The documented JS API follows [Semantic Versioning](https://semver.org).
Using undocumented features is at you own risk.

## Contribution

### How to build

```bash
# Make sure you have Yarn installed
yarn install
yarn build
```

### How to publish

1. Bump the version. Changing the number in [package.json](package.json) is enough.
2. Build the project.
3. Run
```bash
yarn publish --access public # Add '--tag beta' (without the quotes) if you release a beta version
```
5 changes: 5 additions & 0 deletions resources/license_banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
FingerprintJS v<%= pkg.version %> - Copyright (c) FingerprintJS, Inc, <%= new Date().getFullYear() %> (https://fingerprintjs.com)
Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.

This software contains code from open-source projects:
MurmurHash3 by Karan Lyons (https://github.com/karanlyons/murmurHash3.js)
106 changes: 106 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 1,106 @@
const path = require('path')
const jsonPlugin = require('@rollup/plugin-json')
const nodeResolvePlugin = require('@rollup/plugin-node-resolve').nodeResolve
const typescriptPlugin = require('@rollup/plugin-typescript')
const terserPlugin = require('rollup-plugin-terser').terser
const dtsPlugin = require('rollup-plugin-dts').default
const licensePlugin = require('rollup-plugin-license')
const { dependencies } = require('./package.json')

const outputDirectory = 'dist'

const commonBanner = licensePlugin({
banner: {
content: {
file: path.join(__dirname, 'resources', 'license_banner.txt'),
},
},
})

const commonInput = {
input: './src/index.ts',
plugins: [
nodeResolvePlugin(),
jsonPlugin(),
typescriptPlugin({
declaration: false,
}),
commonBanner,
],
}

const commonOutput = {
name: 'FingerprintJS',
}

const commonTerser = terserPlugin({
format: {
comments: false,
},
safari10: true,
})

module.exports = [
// Browser bundles. They have all the dependencies included for convenience.
{
...commonInput,
output: [
// IIFE for users who use Require.js or Electron and want to just call `window.FingerprintJS.load()`
{
...commonOutput,
file: `${outputDirectory}/fp.js`,
format: 'iife',
},
{
...commonOutput,
file: `${outputDirectory}/fp.min.js`,
format: 'iife',
plugins: [commonTerser],
},

// UMD for users who use Require.js or Electron and want to leverage them
{
...commonOutput,
file: `${outputDirectory}/fp.umd.js`,
format: 'umd',
},
{
...commonOutput,
file: `${outputDirectory}/fp.umd.min.js`,
format: 'umd',
plugins: [commonTerser],
},
],
},

// NPM bundles. They have all the dependencies excluded for end code size optimization.
{
...commonInput,
external: Object.keys(dependencies),
output: [
// CJS for usage with `require()`
{
...commonOutput,
file: `${outputDirectory}/fp.cjs.js`,
format: 'cjs',
},

// ESM for usage with `import`
{
...commonOutput,
file: `${outputDirectory}/fp.esm.js`,
format: 'es',
},
],
},

// TypeScript definition
{
...commonInput,
plugins: [dtsPlugin(), commonBanner],
output: {
file: `${outputDirectory}/fp.d.ts`,
format: 'es',
},
},
]
2 changes: 1 addition & 1 deletion src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
import { version } from '../package.json' // todo: Check that nothing else from package.json gets into the bundles
import { version } from '../package.json'
import { requestIdleCallbackIfAvailable } from './utils/async'
import { x64hash128 } from './utils/hashing'
import getBuiltinComponents, { BuiltinComponents, UnknownComponents } from './sources'
Expand Down
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 1,5 @@
import { x64hash128 } from './utils/hashing'

export {
load,
Agent,
Expand All @@ -8,12 10,11 @@ export {
componentsToDebugString,
} from './agent'
export { Component, UnknownComponents, BuiltinComponents } from './sources'
export { x64hash128 as getHash } from './utils/hashing'
export const getHash: (input: string) => string = x64hash128

/*
* The exports below are out of Semantic Versioning. Their usage is at your own risk.
*/
// The exports below are for private usage. They may change unexpectedly. Usage is at your own risk.

/** Not documented, out of Semantic Versioning, usage is at your own risk */
export const murmurX64Hash128 = x64hash128
export { getComponents, SourcesToComponents } from './sources'
export { x64hash128 as murmurX64Hash128 } from './utils/hashing'
export { isIEOrOldEdge, isChromium, isGecko, isDesktopSafari } from './utils/browser'
1 change: 0 additions & 1 deletion src/sources/empty_eval_length.ts
Original file line number Diff line number Diff line change
@@ -1,4 1,3 @@
export default function getEmptyEvalLength(): number {
// todo: Check that `eval` doesn't prevent Terser from replacing identifiers
return eval.toString().length
}
8 changes: 7 additions & 1 deletion src/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 104,10 @@ export type Component<T> = ({
export type UnknownComponents = Record<string, Component<unknown>>

/**
* Converts an entropy source list type to a corresponding component list type
* Converts an entropy source list type to a corresponding component list type.
*
* Warning for package users:
* This type is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
*/
export type SourcesToComponents<TSources extends UnknownSources<any>> = {
[K in keyof TSources]: Component<SourceValue<TSources[K]>>
Expand All @@ -122,6 125,9 @@ export type BuiltinComponents = SourcesToComponents<typeof sources>

/**
* Gets a components list from the given list of entropy sources.
*
* Warning for package users:
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
*/
export async function getComponents<TSourceOptions, TSources extends UnknownSources<TSourceOptions>, TExclude extends string>(
sources: TSources,
Expand Down
21 changes: 18 additions & 3 deletions src/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,10 @@ const n = navigator
const d = document

/**
* Checks whether the browser is Internet Explorer or pre-Chromium Edge without using user-agent
* Checks whether the browser is Internet Explorer or pre-Chromium Edge without using user-agent.
*
* Warning for package users:
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
*/
export function isIEOrOldEdge(): boolean {
// The properties are checked to be in IE 10, IE 11 and Edge 18 and not to be in other browsers
Expand All @@ -21,7 24,10 @@ export function isIEOrOldEdge(): boolean {
}

/**
* Checks whether the browser is based on Chromium without using user-agent
* Checks whether the browser is based on Chromium without using user-agent.
*
* Warning for package users:
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
*/
export function isChromium(): boolean {
// Based on research in September 2020
Expand Down Expand Up @@ -52,12 58,21 @@ export function isWebKit(): boolean {
]) >= 4
}

/**
* Checks whether the WebKit browser is a desktop Safari.
*
* Warning for package users:
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
*/
export function isDesktopSafari(): boolean {
return 'safari' in w
}

/**
* Checks whether the browser is based on Gecko (Firefox engine) without using user-agent
* Checks whether the browser is based on Gecko (Firefox engine) without using user-agent.
*
* Warning for package users:
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
*/
export function isGecko(): boolean {
// Based on research in September 2020
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 1,8 @@
{
"compilerOptions": {
"outDir": "dist/",
"module": "esnext",
"moduleResolution": "node",
"target": "es6",
"declaration": true,
"removeComments": false,
"resolveJsonModule": true,
"noErrorTruncation": true,
Expand Down
Loading

0 comments on commit 71ace0c

Please sign in to comment.