add an npm build script that creates the different dist files through rollup
MODIFY
.gitignore
.gitignore
@@ -59,3 +59,6 @@ typings/
# next.js build output
.next
+
+# dist
+dist/

DELETE
index-commonjs.js
-'use strict';
-
-// Copyright (C) 2011 Google Inc.
-// Copyright (C) 2018 Agoric
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-/**
- * Is allegedNum a number in the contiguous range of exactly and
- * unambiguously representable natural numbers (non-negative integers)?
- *
- * <p>See <a href=
- * "https://code.google.com/p/google-caja/issues/detail?id=1801"
- * >Issue 1801: Nat must include at most (2**53)-1</a>
- * and <a href=
- * "https://mail.mozilla.org/pipermail/es-discuss/2013-July/031716.html"
- * >Allen Wirfs-Brock's suggested phrasing</a> on es-discuss.
- */
-
-function Nat(allegedNum) {
- if (!Number.isSafeInteger(allegedNum)) {
- throw new RangeError('not a safe integer');
- }
-
- if (allegedNum < 0) {
- throw new RangeError('negative');
- }
-
- return allegedNum;
-}
-
-module.exports = Nat;

MODIFY
package.json
package.json
"name": "@agoric/nat",
"version": "2.0.0",
"description": "Ensures that a number is within the natural numbers (0, 1, 2...) or throws a RangeError",
- "main": "index-commonjs.js",
- "module": "index.js",
+ "main": "dist/nat.cjs.js",
+ "module": "dist/nat.esm.js",
+ "browser": "dist/nat.umd.js",
"scripts": {
"test": "node test/test.js",
- "create-cjs": "rollup index.js --file index-commonjs.js --format cjs",
+ "build": "rollup -c",
"lint-fix": "eslint --fix '**/*.{js,jsx}'",
"lint-check": "eslint '**/*.{js,jsx}'"
},
"integer",
"int",
"overflow"
+ ],
+ "files": [
+ "dist"
]
}

ADD
rollup.config.js
+export default [
+ {
+ input: 'src/index.js',
+ output: [
+ {
+ file: 'dist/nat.umd.js',
+ format: 'umd',
+ name: 'Nat',
+ },
+ {
+ file: 'dist/nat.esm.js',
+ format: 'esm',
+ },
+ {
+ file: 'dist/nat.cjs.js',
+ format: 'cjs',
+ },
+ ],
+ },
+];

RENAME
index.js
src/index.js
add an npm build script that creates the different dist files through rollup