Skip to content

Commit

Permalink
ESLint, rollup powered build, Travis CI
Browse files Browse the repository at this point in the history
- building cjs, esm and umd-min flavours
- removing `dist` from git repo
- updating example
- fine tuning `.npmignore` to reduce tarball size
  • Loading branch information
vladimyr committed Jun 30, 2019
1 parent 06530b3 commit 08b557d
Show file tree
Hide file tree
Showing 16 changed files with 1,933 additions and 190 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import('eslint').Linter.Config} */
const config = {
extends: 'semistandard',
rules: {
'prefer-const': 'error',
'space-before-function-paren': ['error', {
anonymous: 'always',
named: 'never'
}]
},
env: {
browser: true
}
};

module.exports = config;
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ yarn-debug.log*
yarn-error.log*
node_modules/
.npm

# Build artifacts
dist/
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.editorconfig
.travis.yml
.eslint*
*.config.js
index.test-d.ts
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand Down
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- '8'
- '10'
- lts/*
- node

script:
- yarn run lint
- yarn test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ npm install is-incognito-mode --save
import isIncognito from 'is-incognito-mode';

// CommonJS modules
const isIncognito = require('is-incognito-mode').default;
const isIncognito = require('is-incognito-mode');

/*
Function returns Promise, which could be:
Expand Down
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/preset-env']
};
1 change: 0 additions & 1 deletion dist/isIncognito.js

This file was deleted.

4 changes: 2 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Is incognito</title>
</head>
<script src="../dist/isIncognito.js"></script>
<script src="../dist/isIncognito.umd.min.js"></script>
<body style="height: 100%; display: flex; align-items: center; justify-content: center;">
<div id="text" style="font-size: 40px; font-weight: 600; text-align: center;"></div>
</body>
<script>
const element = document.querySelector('#text');
window.isIncognito.default()
window.isIncognito()
.then(isPrivate => {
if (isPrivate) {
element.innerHTML = 'There is no porn!<br /><br /><br />Why are you using Incognito mode?';
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isIncognito(): Promise<boolean>;
export = isIncognito;
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { browsers, detect } from 'get-browser';
import getBrowser from 'get-browser';
const { browsers, detect } = getBrowser;

const UNUSUAL_KEY = 'cd1394e6-3fd1-4a2d-ae60-c9ae01f7ee89';
const CANNOT_IDENTIFY_ERROR = new Error('Cannot identify whether incognito mode is active');
Expand Down Expand Up @@ -45,11 +46,11 @@ export default function isIncognito() {
window.openDatabase(null, null, null, null);
} catch (e) {
return yes();
};
}

return no();
}

return unknown();
});
};
}
4 changes: 4 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expectType } from 'tsd';
import isIncognito from '.';

expectType<boolean>(await isIncognito());
36 changes: 31 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,46 @@
"version": "1.1.0",
"description": "Function to identify whether user is in incognito mode",
"main": "./dist/isIncognito.js",
"module": "./dist/isIncognito.esm.js",
"repository": "git@github.com:yankouskia/is-incognito-mode.git",
"types": "index.d.ts",
"author": "yankouskia <aleksandr.yankovskiy@gmail.com>",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@types/eslint": "^4.16.6",
"babel-loader": "^8.0.6",
"webpack": "^4.32.0",
"webpack-cli": "^3.3.2"
"del-cli": "^2.0.0",
"eslint": "^6.0.0",
"eslint-config-semistandard": "^13.0.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"rollup": "^1.16.3",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.0.0",
"tsd": "^0.7.3",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.5"
},
"dependencies": {
"get-browser": "^1.0.2"
},
"scripts": {
"build": "NODE_ENV=production webpack -p"
"lint": "eslint .",
"prebuild": "del-cli dist",
"build": "rollup -c rollup.config.js",
"test": "tsd",
"prepublishOnly": "yarn run build"
},
"tsd": {
"compilerOptions": {
"esModuleInterop": true
}
}
}
48 changes: 48 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

const babel = require('rollup-plugin-babel');
const { builtinModules } = require('module');
const commonjs = require('rollup-plugin-commonjs');
const path = require('path');
const pkg = require('./package.json');
const resolve = require('rollup-plugin-node-resolve');
const { terser } = require('rollup-plugin-terser');

/** @type {import('rollup').RollupOptions} */
const baseConfig = {
input: './index.js',
external: Object.keys(pkg.dependencies).concat(builtinModules),
plugins: [
resolve(),
commonjs(),
babel({
exclude: ['node_modules/**']
})
]
};

/** @type {Array<import('rollup').RollupOptions>} */
const config = [{
...baseConfig,
output: {
format: 'esm',
file: path.join(__dirname, './dist/isIncognito.esm.js')
}
}, {
...baseConfig,
output: {
format: 'cjs',
file: path.join(__dirname, './dist/isIncognito.js')
}
}, {
...baseConfig,
output: {
format: 'umd',
name: 'isIncognito',
file: path.join(__dirname, './dist/isIncognito.umd.min.js')
},
external: [],
plugins: baseConfig.plugins.concat(terser())
}];

module.exports = config;
32 changes: 0 additions & 32 deletions webpack.config.js

This file was deleted.

Loading

0 comments on commit 08b557d

Please sign in to comment.