[Pkg-javascript-commits] [node-invariant] 01/04: Import Upstream version 2.2.2

Paolo Greppi paolog-guest at moszumanska.debian.org
Fri Dec 2 15:48:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

paolog-guest pushed a commit to branch master
in repository node-invariant.

commit 9ebed1d4e805abbe08d09d45bf5eafa236da5d37
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Fri Dec 2 15:30:49 2016 +0000

    Import Upstream version 2.2.2
---
 .gitignore                  |  3 +++
 .travis.yml                 |  9 ++++++++
 CHANGELOG.md                | 33 ++++++++++++++++++++++++++++
 LICENSE                     | 27 +++++++++++++++++++++++
 README.md                   | 37 +++++++++++++++++++++++++++++++
 browser.js                  | 51 +++++++++++++++++++++++++++++++++++++++++++
 invariant.js                | 53 +++++++++++++++++++++++++++++++++++++++++++++
 invariant.js.flow           |  7 ++++++
 package.json                | 35 ++++++++++++++++++++++++++++++
 test/flow/.flowconfig       | 11 ++++++++++
 test/flow/index.js          |  5 +++++
 test/package/development.js | 19 ++++++++++++++++
 test/package/production.js  | 19 ++++++++++++++++
 test/test.js                | 41 +++++++++++++++++++++++++++++++++++
 14 files changed, 350 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5f23cc6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+npm-debug.log
+/node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..4a007f5
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,9 @@
+sudo: false
+language: node_js
+node_js:
+  - "0.10"
+  - "0.12"
+  - "4.0"
+  - "5"
+  - "6"
+  - "7"
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..5326f1a
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,33 @@
+2.1.1 / 2015-09-20
+==================
+
+  * Use correct SPDX license.
+  * Test "browser.js" using browserify.
+  * Switch from "envify" to "loose-envify".
+
+2.1.0 / 2015-06-03
+==================
+
+  * Add "envify" as a dependency.
+  * Fixed license field in "package.json".
+
+2.0.0 / 2015-02-21
+==================
+
+  * Switch to using the "browser" field. There are now browser and server versions that respect the "format" in production.
+
+1.0.2 / 2014-09-24
+==================
+
+  * Added tests, npmignore and gitignore.
+  * Clarifications in README.
+
+1.0.1 / 2014-09-24
+==================
+
+  * Actually include 'invariant.js'.
+
+1.0.0 / 2014-09-24
+==================
+
+  * Initial release.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..35b4e8f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2016, Andres Suarez
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+* Neither the name of invariant nor the names of its
+  contributors may be used to endorse or promote products derived from
+  this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..96aac6d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,37 @@
+# invariant
+
+[![Build Status](https://travis-ci.org/zertosh/invariant.svg?branch=master)](https://travis-ci.org/zertosh/invariant)
+
+A mirror of Facebook's `invariant` (e.g. [React](https://github.com/facebook/react/blob/v0.13.3/src/vendor/core/invariant.js), [flux](https://github.com/facebook/flux/blob/2.0.2/src/invariant.js)).
+
+A way to provide descriptive errors in development but generic errors in production.
+
+## Install
+
+With [npm](http://npmjs.org) do:
+
+```sh
+npm install invariant
+```
+
+## `invariant(condition, message)`
+
+```js
+var invariant = require('invariant');
+
+invariant(someTruthyVal, 'This will not throw');
+// No errors
+
+invariant(someFalseyVal, 'This will throw an error with this message');
+// Error: Invariant Violation: This will throw an error with this message
+```
+
+**Note:** When `process.env.NODE_ENV` is not `production`, the message is required. If omitted, `invariant` will throw regardless of the truthiness of the condition. When `process.env.NODE_ENV` is `production`, the message is optional – so they can be minified away.
+
+### Browser
+
+When used with [browserify](https://github.com/substack/node-browserify), it'll use `browser.js` (instead of `invariant.js`) and the [envify](https://github.com/hughsk/envify) transform will inline the value of `process.env.NODE_ENV`.
+
+### Node
+
+The node version is optimized around the performance implications of accessing `process.env`. The value of `process.env.NODE_ENV` is cached, and repeatedly used instead of reading `proces.env`. See [Server rendering is slower with npm react #812](https://github.com/facebook/react/issues/812)
diff --git a/browser.js b/browser.js
new file mode 100644
index 0000000..29ead50
--- /dev/null
+++ b/browser.js
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2013-2015, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+'use strict';
+
+/**
+ * Use invariant() to assert state which your program assumes to be true.
+ *
+ * Provide sprintf-style format (only %s is supported) and arguments
+ * to provide information about what broke and what you were
+ * expecting.
+ *
+ * The invariant message will be stripped in production, but the invariant
+ * will remain to ensure logic does not differ in production.
+ */
+
+var invariant = function(condition, format, a, b, c, d, e, f) {
+  if (process.env.NODE_ENV !== 'production') {
+    if (format === undefined) {
+      throw new Error('invariant requires an error message argument');
+    }
+  }
+
+  if (!condition) {
+    var error;
+    if (format === undefined) {
+      error = new Error(
+        'Minified exception occurred; use the non-minified dev environment ' +
+        'for the full error message and additional helpful warnings.'
+      );
+    } else {
+      var args = [a, b, c, d, e, f];
+      var argIndex = 0;
+      error = new Error(
+        format.replace(/%s/g, function() { return args[argIndex++]; })
+      );
+      error.name = 'Invariant Violation';
+    }
+
+    error.framesToPop = 1; // we don't care about invariant's own frame
+    throw error;
+  }
+};
+
+module.exports = invariant;
diff --git a/invariant.js b/invariant.js
new file mode 100644
index 0000000..1859a2a
--- /dev/null
+++ b/invariant.js
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2013-2015, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+'use strict';
+
+/**
+ * Use invariant() to assert state which your program assumes to be true.
+ *
+ * Provide sprintf-style format (only %s is supported) and arguments
+ * to provide information about what broke and what you were
+ * expecting.
+ *
+ * The invariant message will be stripped in production, but the invariant
+ * will remain to ensure logic does not differ in production.
+ */
+
+var NODE_ENV = process.env.NODE_ENV;
+
+var invariant = function(condition, format, a, b, c, d, e, f) {
+  if (NODE_ENV !== 'production') {
+    if (format === undefined) {
+      throw new Error('invariant requires an error message argument');
+    }
+  }
+
+  if (!condition) {
+    var error;
+    if (format === undefined) {
+      error = new Error(
+        'Minified exception occurred; use the non-minified dev environment ' +
+        'for the full error message and additional helpful warnings.'
+      );
+    } else {
+      var args = [a, b, c, d, e, f];
+      var argIndex = 0;
+      error = new Error(
+        format.replace(/%s/g, function() { return args[argIndex++]; })
+      );
+      error.name = 'Invariant Violation';
+    }
+
+    error.framesToPop = 1; // we don't care about invariant's own frame
+    throw error;
+  }
+};
+
+module.exports = invariant;
diff --git a/invariant.js.flow b/invariant.js.flow
new file mode 100644
index 0000000..361c519
--- /dev/null
+++ b/invariant.js.flow
@@ -0,0 +1,7 @@
+/* @flow */
+
+declare module.exports: (
+  condition: any,
+  format?: string,
+  ...args: Array<any>
+) => void;
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e4b9672
--- /dev/null
+++ b/package.json
@@ -0,0 +1,35 @@
+{
+  "name": "invariant",
+  "version": "2.2.2",
+  "description": "invariant",
+  "keywords": [
+    "test",
+    "invariant"
+  ],
+  "license": "BSD-3-Clause",
+  "author": "Andres Suarez <zertosh at gmail.com>",
+  "files": [
+    "browser.js",
+    "invariant.js",
+    "invariant.js.flow"
+  ],
+  "repository": "https://github.com/zertosh/invariant",
+  "scripts": {
+    "test": "NODE_ENV=production tap test/*.js && NODE_ENV=development tap test/*.js"
+  },
+  "dependencies": {
+    "loose-envify": "^1.0.0"
+  },
+  "devDependencies": {
+    "browserify": "^11.0.1",
+    "flow-bin": "^0.35.0",
+    "tap": "^1.4.0"
+  },
+  "main": "invariant.js",
+  "browser": "browser.js",
+  "browserify": {
+    "transform": [
+      "loose-envify"
+    ]
+  }
+}
diff --git a/test/flow/.flowconfig b/test/flow/.flowconfig
new file mode 100644
index 0000000..cede7d6
--- /dev/null
+++ b/test/flow/.flowconfig
@@ -0,0 +1,11 @@
+[include]
+../../
+
+[ignore]
+
+[libs]
+
+[options]
+
+[version]
+0.35.0
diff --git a/test/flow/index.js b/test/flow/index.js
new file mode 100644
index 0000000..a11f4c3
--- /dev/null
+++ b/test/flow/index.js
@@ -0,0 +1,5 @@
+// @flow
+
+var invariant = require('../..');
+
+invariant(true);
diff --git a/test/package/development.js b/test/package/development.js
new file mode 100644
index 0000000..0840691
--- /dev/null
+++ b/test/package/development.js
@@ -0,0 +1,19 @@
+module.exports = function(t) {
+  var invariant = require('../../');
+
+  t.doesNotThrow(function() {
+    invariant(true, 'invariant message');
+  });
+
+  t.throws(function() {
+    invariant(false, 'invariant message');
+  }, /invariant message/);
+
+  t.throws(function() {
+    invariant(true);
+  }, /requires an error/i);
+
+  t.throws(function() {
+    invariant(false);
+  }, /requires an error/i);
+};
diff --git a/test/package/production.js b/test/package/production.js
new file mode 100644
index 0000000..efef0f0
--- /dev/null
+++ b/test/package/production.js
@@ -0,0 +1,19 @@
+module.exports = function(t) {
+  var invariant = require('../../');
+
+  t.doesNotThrow(function() {
+    invariant(true, 'invariant message');
+  });
+
+  t.throws(function() {
+    invariant(false, 'invariant message');
+  }, /invariant message/);
+
+  t.doesNotThrow(function() {
+    invariant(true);
+  });
+
+  t.throws(function() {
+    invariant(false);
+  }, /minified exception occurred/i);
+};
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..4ad480c
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,41 @@
+'use strict';
+
+var browserify = require('browserify');
+var test = require('tap').test;
+var vm = require('vm');
+var flow = require('flow-bin');
+var execFile = require('child_process').execFile;
+var path = require('path');
+
+var file = __dirname + '/package/' + process.env.NODE_ENV + '.js';
+
+test('node', function(t) {
+  t.plan(4);
+  require(file)(t);
+});
+
+test('browserify', function(t) {
+  t.plan(7);
+  var b = browserify({
+    entries: file,
+    standalone: 'package'
+  });
+  b.bundle(function(err, src) {
+    t.notOk(err);
+    t.notMatch(String(src), /\bprocess\.env\.NODE_ENV\b/);
+    t.notMatch(String(src), /__DEV__/);
+    var c = {};
+    vm.runInNewContext(src, c);
+    c.package(t);
+  });
+});
+
+test('flow', function(t) {
+  t.plan(1);
+  execFile(flow, ['coverage', 'index.js'], {
+    cwd: path.join(__dirname, 'flow')
+  }, function (err, stdout) {
+    // If the types are broken, we'd have coverage below 100%
+    t.equal(stdout.trim(), 'Covered: 100.00% (5 of 5 expressions)');
+  });
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-invariant.git



More information about the Pkg-javascript-commits mailing list