diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index 0989b61..0000000
--- a/.npmignore
+++ /dev/null
@@ -1,3 +0,0 @@
-.travis.yml
-test/
-tools/
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index e6f02ee..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-language: node_js
-node_js:
- - 6
- - 8
- - 10
- - 12
diff --git a/README.md b/README.md
deleted file mode 100644
index e52c722..0000000
--- a/README.md
+++ /dev/null
@@ -1,78 +0,0 @@
-# funding [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
-
-### Let's get open source maintainers paid ✨
-
-[travis-image]: https://img.shields.io/travis/feross/funding/master.svg
-[travis-url]: https://travis-ci.org/feross/funding
-[npm-image]: https://img.shields.io/npm/v/funding.svg
-[npm-url]: https://npmjs.org/package/funding
-[downloads-image]: https://img.shields.io/npm/dm/funding.svg
-[downloads-url]: https://npmjs.org/package/funding
-[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
-[standard-url]: https://standardjs.com
-
-### UPDATE: The experiment is over – Feross posted [a recap](https://feross.org/funding-experiment-recap/) on his blog
-
-This is an open source funding experiment! The current model of sustaining open source is not working. We desperately need more experimentation. This is one such experiment.
-
-## Install
-
-```bash
-npm install funding
-```
-
-### UPDATE: The experiment is over – Feross posted [a recap](https://feross.org/funding-experiment-recap/) on his blog
-
-## What is this?
-
-This is an open source funding experiment! ✨
-
-Whenever users install open source software, this package will display a message from a company that supports open source. The sponsorship pays directly for maintainer time. That is, writing new features, fixing bugs, answering user questions, and improving documentation.
-
-The goal is to make sure that packages are well-maintained now and for the foreseeable future, with regular releases, improved reliability, and timely security patches. Healthy open source packages benefit users and maintainers alike.
-
-## What does this code do?
-
-You can take a look! All the code is open source in this GitHub repository. Essentially, it calls `console.log()` on some text. **There is no tracking or data collecting — and it will always stay this way.** You can look at the code to verify – indeed, this is the beauty of open source!
-
-## Where is this experiment running?
-
-This experiment is currently running on a few open source projects that [Feross](https://github.com/feross) maintains:
-
-- [`standard`](https://standardjs.com)
-
-### UPDATE: The experiment is over – Feross posted [a recap](https://feross.org/funding-experiment-recap/) on his blog
-
-## Who is Feross?
-
-Hey there, I'm Feross!
-
-
-
-I'm an open source author, maintainer, and mad scientist. I maintain [100+ packages on npm](https://www.npmjs.com/~feross) which are downloaded 100+ million times per month. All my code is [freely accessible on GitHub](https://github.com/feross).
-
-I work on innovative projects like [WebTorrent](https://github.com/webtorrent/webtorrent), a streaming torrent client for the web, [WebTorrent Desktop](https://github.com/webtorrent/webtorrent-desktop), a slick torrent app for Mac/Windows/Linux, and [StandardJS](https://github.com/standard/standard), a JavaScript style guide, linter, and automatic code fixer. I also work on fun projects like [BitMidi](https://bitmidi.com), a free MIDI database, and [Play](https://play.cash), a music video app.
-
-I wrote and maintain several popular browserify + webpack ecosystem packages like [buffer](https://github.com/feross/buffer) (38M downloads/month) and [safe-buffer](https://github.com/feross/safe-buffer) (64M downloads/month). Some of my favorite npm packages that I've written are [simple-get](https://github.com/feross/simple-get) (4M downloads/month), [run-parallel](https://github.com/feross/run-parallel) (1.6M downloads/month), and [simple-peer](https://github.com/feross/simple-peer) (32K downloads/month).
-
-In the past, I was on the Node.js Board of Directors, representing individual Node.js users like you! It was an unpaid position, but I was happy to play some small part in making things better for everyone. Just for fun, a couple years ago I helped organize [ArcticJS](https://arcticjs.club/2017/), an impromptu JavaScript conference in Svalbard, the northern-most human settlement on Earth, with some amazing friends.
-
-## What is the long-term goal?
-
-My goal with this experiment is to make StandardJS healthier. If we learn that the experiment works, perhaps we can help make all open source healthier, too. For complex reasons, companies are generally hesitant or unwilling to fund open source directly. When it does happen, it's never enough and it never reaches packages which are transitive dependencies (i.e. packages that no one installs explicitly and therefore no one knows exists). Essentially, we have a public good which is consumed by huge numbers of users, but which almost no one pays for. Fortunately, there exists a funding model that usually works for public goods like this – ads. The goal of this experiment is to answer the question: Can we use ethical ads – ads that don't track users or collect data – to fund open source software?
-
-## What will the funds be used for?
-
-The funds raised so far ($2,000) have paid for Feross's time to [release Standard 14](https://standardjs.com/changelog.html#1400---2019-08-19) which has taken around five days. If we are able to raise additional funds, the next thing we'd like to focus on is out-of-the-box TypeScript support in StandardJS (one of the most common feature requests!) and modernizing the various text editor plugins (many of which are currently unmaintained).
-
-## Where can I provide feedback about this experiment?
-
-You can open an issue. But please be kind. I'm a human with feelings. ❤️
-
-## How can I disable this?
-
-Just to be super clear: **This package does no tracking or data collecting — and it will always stay this way.** It's just a fancy `console.log()`.
-
-If you support open source through direct contributions, donations, or however else you see fit, you can permanently silence `funding` by adding an environment variable `OPEN_SOURCE_CONTRIBUTOR=true` to your terminal environment.
-
-Note, `funding` also respects npm's `loglevel` setting, so e.g. `npm install --silent` and `npm install --quiet` will be respected.
diff --git a/bin/funding.js b/bin/funding.js
deleted file mode 100755
index f7c327e..0000000
--- a/bin/funding.js
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env node
-
-/**
- * This file must run in all recent versions of Node.js (0.12, 4, 6, 8, 10, 12).
- * Avoid using modern JavaScript syntax.
- */
-
-var funding
-
-try {
- funding = require('../')
-} catch (err) {
- // Silently ignore syntax errors in Node.js 0.12 and 4.
-}
-
-try {
- if (funding) {
- funding.printMessage()
- }
-} catch (err) {
- console.error(err.stack || err.message || err)
- console.error('\nReport this issue: https://github.com/feross/funding\n')
-}
diff --git a/index.js b/index.js
old mode 100644
new mode 100755
index 629d5c2..53ad29d
--- a/index.js
+++ b/index.js
@@ -1,119 +1,44 @@
-const boxen = require('boxen')
-const chalk = require('chalk')
-
-const {
- isHyper,
- isITerm,
- isCI,
- isSilentMode
-} = require('./lib/detect')
-
-const { isShownRecently, markShown } = require('./lib/limit')
-
-const { checkMessage } = require('./lib/check')
-const messages = require('./messages.json')
-const wrap = require('./lib/wrap')
-
-function formatTitle (title) {
- title = wrap(title)
-
- if (!isCI()) {
- title = chalk.black(title)
- }
-
- if (!isHyper() && !isITerm()) {
- title = chalk.bold(title)
- }
-
- return title
+#!/usr/bin/env node
+const path = require('path')
+const os = require('os')
+const fs = require('fs')
+const util = require('util')
+const _exec = require('child_process').execSync
+const exec = (cmd) => _exec(cmd, {encoding: 'utf8'}).trim()
+
+if (require.main !== module) return
+
+if (!process.argv[2] || process.argv[3]) {
+ const example = `${os.homedir}/Library/Application Support/BraveSoftware/Brave-Browser/Default`
+ console.warn(`
+Usage: funding
+ (eg '${example}' on OSX)
+
+ This will monkey-patch your npm to add any node modules you install to the
+ contribution list in Brave Rewards.
+`.trim())
+
+ process.exit(1)
}
-function formatText (text) {
- text = wrap(text)
-
- text = text.replace(
- /{{([^}]*?)}}/g,
- (match, url) => chalk.blue.underline(url)
- )
-
- if (!isCI()) {
- text = chalk.black(text)
- }
+const PROFILE = process.argv[2]
- return text
-}
-
-function formatUrl (url) {
- url = wrap(url, { cut: true })
- return chalk.blue.underline(url)
-}
+console.log('Monkeying around with npm-lifecycle...')
+const npmRoot = exec('npm root -g')
+process.chdir(path.join(npmRoot, 'npm', 'node_modules', 'npm-lifecycle'))
-function formatMessage (message) {
- const { title, text, url } = message
+console.log('Installing sqlite (this might take a while)...')
+exec('npm install better-sqlite3')
- const coloredMessage = formatTitle(title) + '\n\n' + formatText(text) +
- '\n\n' + formatUrl(url)
+console.log('Writing global hook...')
+const template = fs.readFileSync(path.join(__dirname, 'patch.template.js'), 'utf8')
+fs.writeFileSync('./index-patch.js', template.replace('{{PROFILE}}', PROFILE))
- const opts = {
- align: 'center',
- borderStyle: {
- topLeft: ' ',
- topRight: ' ',
- bottomLeft: ' ',
- bottomRight: ' ',
- horizontal: ' ',
- vertical: ' '
- },
- float: 'center',
- margin: 0,
- padding: {
- top: 1,
- right: 4,
- bottom: 1,
- left: 4
- }
- }
+console.log('Patching package.json...')
+const pkg = JSON.parse(fs.readFileSync('./package.json'))
+pkg.main = 'index-patch.js'
+fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))
- if (!isCI()) {
- Object.assign(opts, {
- backgroundColor: 'white'
- })
- }
+console.log('Reticulating splines...')
- return boxen(coloredMessage, opts)
-}
-
-function printMessage () {
- // Do not print message when npm is run in silent mode
- if (isSilentMode()) return
-
- // Do not print message when one has been shown recently
- if (isShownRecently()) return
-
- // Skip running if no messages are available
- if (messages.length === 0) return
-
- // Select a random message
- const i = Math.floor(Math.random() * messages.length)
- const message = messages[i]
-
- // Check if the strings are safe to print to the terminal. Specifically, the
- // string should be plain ASCII, excluding control characters. This is
- // paranoid and not strictly necessary since (1) we curate the messages.json
- // file by hand and will never include non-ASCII text, and (2) we check the
- // strings at package publish time (see test/messages.js). But it doesn't hurt
- // to check again in the client and assert that messages are plain ASCII. This
- // is the security principle of defense-in-depth.
- checkMessage(message)
-
- // Format the message and print it
- const formattedMessage = formatMessage(message)
- console.log(formattedMessage + '\n')
-
- // Limit the frequency that messages are shown
- markShown()
-}
-
-module.exports = {
- printMessage
-}
+console.log('Done!')
diff --git a/lib/check.js b/lib/check.js
deleted file mode 100644
index 67abf63..0000000
--- a/lib/check.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Check if the given string, str, is safe to print to the terminal.
- * Specifically, the string should be plain ASCII excluding control characters
- * (except for newline which is allowed). Throws if the string is not safe.
- * Otherwise, does nothing.
- */
-function checkString (str) {
- if (typeof str !== 'string') {
- throw new Error('Typeof object must be a string')
- }
- for (var i = 0; i < str.length; i++) {
- var ch = str.charCodeAt(i)
- if (ch <= 9 || (ch >= 11 && ch <= 31) || ch >= 127) {
- throw new Error(
- 'String must be plain ASCII text. No Unicode, emojis, or control characters allowed.'
- )
- }
- }
-}
-
-function checkMessage (message) {
- const { title, text, url } = message
-
- checkString(title)
- checkString(text)
- checkString(url)
-}
-
-module.exports = {
- checkString,
- checkMessage
-}
diff --git a/lib/detect.js b/lib/detect.js
deleted file mode 100644
index f4a2226..0000000
--- a/lib/detect.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Functions to detect information about the environment, e.g. which Terminal
- * emulator is in use, or whether silent mode is enabled.
- */
-
-const ciInfo = require('ci-info')
-
-const {
- TERM_PROGRAM,
- npm_config_loglevel: NPM_CONFIG_LOGLEVEL,
- OPEN_SOURCE_CONTRIBUTOR
-} = process.env
-
-// Is Hyper (Mac)?
-const isHyper = () => TERM_PROGRAM === 'Hyper'
-
-// Is iTerm.app (Mac)?
-const isITerm = () => TERM_PROGRAM === 'iTerm.app'
-
-// Is Terminal.app (Mac)?
-const isTerminalApp = () => TERM_PROGRAM === 'Apple_Terminal'
-
-// Is CI?
-const isCI = () => ciInfo.isCI
-
-// Is silent mode enabled?
-const isSilentMode = () => (
- ['silent', 'error'].includes(NPM_CONFIG_LOGLEVEL) ||
- (NPM_CONFIG_LOGLEVEL === 'warn' && !process.version.startsWith('v6.')) ||
- isEnabled(OPEN_SOURCE_CONTRIBUTOR)
-)
-
-function isEnabled (value) {
- return !!value && value !== '0' && value !== 'false'
-}
-
-module.exports = {
- isHyper,
- isITerm,
- isTerminalApp,
- isCI,
- isSilentMode
-}
diff --git a/lib/limit.js b/lib/limit.js
deleted file mode 100644
index 82ac88d..0000000
--- a/lib/limit.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Functions to limit the frequency that messages are shown.
- */
-
-const { tmpdir } = require('os')
-const { statSync, unlinkSync, writeFileSync } = require('fs')
-const { join } = require('path')
-
-const LIMIT_FILE_PATH = join(tmpdir(), 'funding-message-shown')
-const LIMIT_TIMEOUT = 60 * 1000 // 1 minute
-
-function isShownRecently () {
- try {
- const { mtime: lastShown } = statSync(LIMIT_FILE_PATH)
- return Date.now() - lastShown < LIMIT_TIMEOUT
- } catch (e) {}
- return false
-}
-
-function markShown () {
- try {
- writeFileSync(LIMIT_FILE_PATH, '')
- } catch (err) {}
-}
-
-// Only used in tests
-function clearShown () {
- try {
- unlinkSync(LIMIT_FILE_PATH)
- } catch (err) {}
-}
-
-module.exports = {
- isShownRecently,
- markShown,
- clearShown
-}
diff --git a/lib/wrap.js b/lib/wrap.js
deleted file mode 100644
index 3c86680..0000000
--- a/lib/wrap.js
+++ /dev/null
@@ -1,19 +0,0 @@
-const wordWrap = require('word-wrap')
-const termSize = require('term-size')
-
-const MAX_WIDTH = 100
-
-/**
- * Wrap text so it fits within the terminal window width while respecting word
- * boundaries.
- */
-function wrap (str, opts) {
- const columns = Math.min(MAX_WIDTH, termSize().columns)
- opts = Object.assign({
- width: columns - 15, // Leave room for padding and margin
- indent: ''
- }, opts)
- return wordWrap(str, opts)
-}
-
-module.exports = wrap
diff --git a/messages.json b/messages.json
deleted file mode 100644
index 5b5f7a3..0000000
--- a/messages.json
+++ /dev/null
@@ -1,7 +0,0 @@
-[
- {
- "title": "npm install funding",
- "text": "I appreciate the thoughtful discussion and feedback from the community. I shared some thoughts about how this experiment went from my perspective.",
- "url": "https://feross.org/funding-experiment-recap/"
- }
-]
diff --git a/package.json b/package.json
index b1e85cd..19237e9 100644
--- a/package.json
+++ b/package.json
@@ -1,29 +1,17 @@
{
"name": "funding",
- "description": "Get open source maintainers paid",
- "version": "1.0.9",
+ "description": "Get open source maintainers paid?",
+ "version": "2.0.0",
"author": {
- "name": "Feross Aboukhadijeh",
- "email": "feross@feross.org",
- "url": "https://feross.org"
+ "name": "Sam Gentle",
+ "email": "sam@samgentle.com"
},
"bin": {
- "funding": "bin/funding.js"
+ "funding": "index.js"
},
"bugs": {
"url": "https://github.com/feross/funding/issues"
},
- "dependencies": {
- "boxen": "^3.2.0",
- "chalk": "^2.4.2",
- "ci-info": "^2.0.0",
- "term-size": "^2.1.0",
- "word-wrap": "^1.2.3"
- },
- "devDependencies": {
- "standard": "*",
- "tape": "^4.11.0"
- },
"homepage": "https://github.com/feross/funding",
"keywords": [
"funding",
@@ -36,10 +24,5 @@
"repository": {
"type": "git",
"url": "git://github.com/feross/funding.git"
- },
- "scripts": {
- "postinstall": "node bin/funding.js",
- "start": "node tools/clear.js && node bin/funding.js",
- "test": "standard && npm start && tape test/*.js"
}
}
diff --git a/patch.template.js b/patch.template.js
new file mode 100644
index 0000000..be22024
--- /dev/null
+++ b/patch.template.js
@@ -0,0 +1,54 @@
+const lifecycle = require('./index.js')
+const path = require('path')
+const fs = require('fs')
+let sqlite3
+try {
+ sqlite3 = require('better-sqlite3')
+}
+catch {
+ module.exports = lifecycle
+ return
+}
+
+const PROFILE = '{{PROFILE}}'
+
+const dbfile = path.join(PROFILE, 'publisher_info_db')
+const db = sqlite3(dbfile);
+
+const ledgerfile = path.join(PROFILE, 'ledger_state')
+const ledger = JSON.parse(fs.readFileSync(ledgerfile))
+const {reconcileStamp} = ledger
+
+const addActivity = db.prepare(`
+ INSERT INTO activity_info (publisher_id, reconcile_stamp, visits, duration, score, weight, percent)
+ VALUES (?, ?, ?, ?, ?, ?, ?)
+ ON CONFLICT(publisher_id, reconcile_stamp) DO UPDATE
+ SET visits = visits + excluded.visits,
+ duration = (duration + excluded.duration),
+ score = (score + excluded.score),
+ weight = (weight + excluded.weight),
+ percent = (percent + excluded.percent)
+`)
+
+const addPublisher = db.prepare(`
+ INSERT OR IGNORE INTO publisher_info (publisher_id, name, url, provider, favIcon)
+ VALUES (?, ?, ?, ?, ?)
+`)
+
+
+const updatePackage = (name) => {
+ const id = `npm#channel:${name}`
+ const url = `https://www.npmjs.com/package/${name}`
+
+ addPublisher.run(id, name, url, '', '')
+ addActivity.run(id, reconcileStamp, 1, 10, 1, 1, 1)
+}
+
+module.exports = (...args) => {
+ const [pkg, stage, wd, opts] = args
+ const name = pkg.name
+ if (name && stage === 'postinstall') {
+ updatePackage(name)
+ }
+ return lifecycle(...args)
+}
diff --git a/test/check.js b/test/check.js
deleted file mode 100644
index 7913ab7..0000000
--- a/test/check.js
+++ /dev/null
@@ -1,147 +0,0 @@
-const test = require('tape')
-const { checkString } = require('../lib/check')
-
-test('checkString() accepts valid strings', t => {
- t.doesNotThrow(() => {
- checkString('')
- })
- t.doesNotThrow(() => {
- checkString('support open source')
- })
- t.doesNotThrow(() => {
- checkString('support open source\nbe a part of history')
- })
- t.doesNotThrow(() => {
- checkString('support open source\nbe a part of history\nmaintainers unite')
- })
- t.doesNotThrow(() => {
- checkString('!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~')
- })
- t.end()
-})
-
-test('checkString() behaves as expected on first 127 characters', t => {
- // control characters not allowed
- t.throws(() => { checkString('\u0000') })
- t.throws(() => { checkString('\u0001') })
- t.throws(() => { checkString('\u0002') })
- t.throws(() => { checkString('\u0003') })
- t.throws(() => { checkString('\u0004') })
- t.throws(() => { checkString('\u0005') })
- t.throws(() => { checkString('\u0006') })
- t.throws(() => { checkString('\u0007') })
- t.throws(() => { checkString('\u0008') })
- t.throws(() => { checkString('\u0009') })
-
- // newline is allowed
- t.doesNotThrow(() => { checkString('\u000a') })
-
- // control characters not allowed
- t.throws(() => { checkString('\u000b') })
- t.throws(() => { checkString('\u000c') })
- t.throws(() => { checkString('\u000d') })
- t.throws(() => { checkString('\u000e') })
- t.throws(() => { checkString('\u000f') })
- t.throws(() => { checkString('\u0010') })
- t.throws(() => { checkString('\u0011') })
- t.throws(() => { checkString('\u0012') })
- t.throws(() => { checkString('\u0013') })
- t.throws(() => { checkString('\u0014') })
- t.throws(() => { checkString('\u0015') })
- t.throws(() => { checkString('\u0016') })
- t.throws(() => { checkString('\u0017') })
- t.throws(() => { checkString('\u0018') })
- t.throws(() => { checkString('\u0019') })
- t.throws(() => { checkString('\u001a') })
- t.throws(() => { checkString('\u001b') })
- t.throws(() => { checkString('\u001c') })
- t.throws(() => { checkString('\u001d') })
- t.throws(() => { checkString('\u001e') })
- t.throws(() => { checkString('\u001f') })
-
- // normal characters are allowed
- for (let i = 0x20; i < 0x7f; i++) {
- t.doesNotThrow(() => { checkString(Buffer.from([i]).toString()) })
- }
-
- // del is not allowed
- t.throws(() => { checkString('\u007f') })
-
- t.end()
-})
-
-test('checkString() rejects high code points', t => {
- // char codes 128-255 are not allowed
- for (let i = 0x80; i <= 0xff; i++) {
- t.throws(() => { checkString(Buffer.from([i]).toString()) })
- }
-
- // emojis are not allowed
- t.throws(() => { checkString('💩') })
- t.throws(() => { checkString('❤️') })
- t.throws(() => { checkString('✨') })
-
- // ansi escape sequences are not allowed
- t.throws(() => { checkString('\u001B') })
- t.throws(() => { checkString('\u001B[4mfoo\u001B[24m') })
- t.throws(() => { checkString('\u001B[31mfoo\u001B[39m') })
- t.throws(() => { checkString('\u001B[41mfoo\u001B[49m') })
- t.throws(() => { checkString('\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39m') })
- t.throws(() => { checkString('\u001B[31mfoo\u001B[4m\u001B[44mbar\u001B[49m\u001B[24m!\u001B[39m') })
- t.throws(() => { checkString('\u001B[31ma\u001B[33mb\u001B[32mc\u001B[33mb\u001B[31mc\u001B[39m') })
- t.throws(() => { checkString('\u001B[90mhello\u001B[39m\n\u001B[90mworld\u001B[39m') })
-
- t.end()
-})
-
-test('checkString() accepts valid strings', t => {
- // 20 lines, with 20 line max
- t.doesNotThrow(() => {
- checkString('a\nb\nc\nd\ne\nf\ng\nh\ni\nj\na\nb\nc\nd\ne\nf\ng\nh\ni\nj', 20)
- })
-
- t.end()
-})
-
-test('checkString() rejects invalid strings', t => {
- // 3 character line, followed by line with unsafe characters
- t.throws(() => {
- checkString('abc\ndef💩gih')
- })
-
- // two lines with invalid characters
- t.throws(() => {
- checkString('🌟\ndef💩gih')
- })
-
- t.end()
-})
-
-test('checkString() rejects non-strings', t => {
- // function argument
- t.throws(() => {
- checkString(() => {})
- })
-
- // object argument
- t.throws(() => {
- checkString({})
- })
-
- // number argument
- t.throws(() => {
- checkString(42)
- })
-
- // null argument
- t.throws(() => {
- checkString(null)
- })
-
- // undefined argument
- t.throws(() => {
- checkString(undefined)
- })
-
- t.end()
-})
diff --git a/test/funding.js b/test/funding.js
deleted file mode 100644
index a4fdda0..0000000
--- a/test/funding.js
+++ /dev/null
@@ -1,115 +0,0 @@
-const test = require('tape')
-const cp = require('child_process')
-const path = require('path')
-
-const { clearShown } = require('../lib/limit')
-
-const FUNDING_BIN_PATH = path.join(__dirname, '..', 'bin', 'funding.js')
-
-test('Sanity check bin/funding.js output', t => {
- t.plan(4)
-
- clearShown()
-
- cp.execFile(FUNDING_BIN_PATH, (err, stdout, stderr) => {
- t.error(err)
- t.ok(stdout.length > 0, 'there exists some stdout ouput')
- t.ok(!stdout.match(/error/gi), 'stdout output is not an error')
- t.equal(stderr, '', 'no stderr output')
- })
-})
-
-test('`npm --silent` or `npm --loglevel silent` prevents output', t => {
- t.plan(3)
-
- clearShown()
-
- const opts = {
- env: Object.assign({}, process.env, {
- npm_config_loglevel: 'silent'
- })
- }
-
- cp.execFile(FUNDING_BIN_PATH, [], opts, (err, stdout, stderr) => {
- t.error(err)
- t.equal(stdout, '', 'no stdout ouput')
- t.equal(stderr, '', 'no stderr output')
- })
-})
-
-test('`npm --quiet` or `npm --loglevel warn` prevents output', t => {
- if (process.version.startsWith('v6.')) {
- t.pass('Ignore `--loglevel warn` on Node 6 (it is the default)')
- return t.end()
- }
-
- t.plan(3)
-
- clearShown()
-
- const opts = {
- env: Object.assign({}, process.env, {
- npm_config_loglevel: 'warn'
- })
- }
-
- cp.execFile(FUNDING_BIN_PATH, [], opts, (err, stdout, stderr) => {
- t.error(err)
- t.equal(stdout, '', 'no stdout ouput')
- t.equal(stderr, '', 'no stderr output')
- })
-})
-
-test('`npm --loglevel error` prevents output', t => {
- t.plan(3)
-
- clearShown()
-
- const opts = {
- env: Object.assign({}, process.env, {
- npm_config_loglevel: 'error'
- })
- }
-
- cp.execFile(FUNDING_BIN_PATH, [], opts, (err, stdout, stderr) => {
- t.error(err)
- t.equal(stdout, '', 'no stdout ouput')
- t.equal(stderr, '', 'no stderr output')
- })
-})
-
-test('deduplication / rate-limiting', t => {
- t.plan(7)
-
- clearShown()
-
- cp.execFile(FUNDING_BIN_PATH, (err, stdout, stderr) => {
- t.error(err)
- t.ok(stdout.length > 0, 'there exists some stdout ouput')
- t.ok(!stdout.match(/error/gi), 'stdout output is not an error')
- t.equal(stderr, '', 'no stderr output')
-
- // Second run should print nothing, since it was recently shown
- cp.execFile(FUNDING_BIN_PATH, (err, stdout, stderr) => {
- t.error(err)
- t.equal(stdout, '', 'no stdout ouput')
- t.equal(stderr, '', 'no stderr output')
- })
- })
-})
-
-test('OPEN_SOURCE_CONTRIBUTOR=true prevents output', t => {
- t.plan(3)
-
- const opts = {
- env: Object.assign({}, process.env, {
- OPEN_SOURCE_CONTRIBUTOR: 'true'
- })
- }
-
- cp.execFile(FUNDING_BIN_PATH, [], opts, (err, stdout, stderr) => {
- t.error(err)
- t.equal(stdout.length, 0, 'no stdout ouput')
- t.equal(stderr.length, 0, 'no stderr output')
- })
-})
diff --git a/test/limit.js b/test/limit.js
deleted file mode 100644
index 8daaab5..0000000
--- a/test/limit.js
+++ /dev/null
@@ -1,16 +0,0 @@
-const test = require('tape')
-
-const { isShownRecently, markShown, clearShown } = require('../lib/limit')
-
-test('shown file works', t => {
- clearShown()
- t.ok(!isShownRecently(), 'initially, not shown recently')
-
- markShown()
- t.ok(isShownRecently(), 'after markShown(), is shown recently')
-
- clearShown()
- t.ok(!isShownRecently(), 'after clearShown(), not shown recently')
-
- t.end()
-})
diff --git a/test/messages.js b/test/messages.js
deleted file mode 100644
index 7e5606b..0000000
--- a/test/messages.js
+++ /dev/null
@@ -1,37 +0,0 @@
-const test = require('tape')
-
-const { checkString, checkMessage } = require('../lib/check')
-const messages = require('../messages.json')
-
-test('Messages is in the expected shape', t => {
- t.ok(Array.isArray(messages), 'messages is an array')
- t.ok(messages.length > 0, 'messages.length is greater than 0')
-
- t.end()
-})
-
-test('Check all messages with check()', t => {
- messages.forEach(message => {
- t.equal(typeof message.title, 'string')
- t.equal(typeof message.text, 'string')
- t.equal(typeof message.url, 'string')
-
- t.doesNotThrow(() => {
- checkString(message.title)
- }, 'checkString(message.title)')
-
- t.doesNotThrow(() => {
- checkString(message.text)
- }, 'checkString(message.text)')
-
- t.doesNotThrow(() => {
- checkString(message.url)
- }, 'checkString(message.url)')
-
- t.doesNotThrow(() => {
- checkMessage(message)
- }, 'checkMessage(message)')
- })
-
- t.end()
-})
diff --git a/tools/clear.js b/tools/clear.js
deleted file mode 100755
index 1fc1fea..0000000
--- a/tools/clear.js
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/env node
-
-const { clearShown } = require('../lib/limit')
-
-clearShown()