[Pkg-javascript-commits] [node-umd] 08/10: Uglify as a pre-publish step and use brfs to work in browserify

Bastien Roucariès rouca at moszumanska.debian.org
Mon Apr 17 07:38:13 UTC 2017


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

rouca pushed a commit to annotated tag 3.0.0
in repository node-umd.

commit a32c7fb3823ee1c3885ef315386ba398b3960136
Author: Forbes Lindesay <forbes at lindesay.co.uk>
Date:   Wed Feb 4 14:10:18 2015 +0000

    Uglify as a pre-publish step and use brfs to work in browserify
    
    This removes the need to depend on uglify as part of the module, making
    it way smaller.  It also means that this module could easily be used in
    the browser.
---
 .gitignore            |  3 +++
 .npmignore            |  4 ----
 package.json          | 19 ++++++++++++-------
 index.js => source.js | 20 ++++++++------------
 template.js           |  2 +-
 5 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/.gitignore b/.gitignore
index 699b5d4..dc156b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,6 @@ results
 npm-debug.log
 
 node_modules
+
+/template.min.js
+/index.js
diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index b0a0925..0000000
--- a/.npmignore
+++ /dev/null
@@ -1,4 +0,0 @@
-node_modules
-examples
-.gitignore
-UMD.png
diff --git a/package.json b/package.json
index 6f4b9e4..854c9ab 100644
--- a/package.json
+++ b/package.json
@@ -4,22 +4,27 @@
   "description": "Universal Module Definition for use in automated build systems",
   "bin": "./bin/cli.js",
   "dependencies": {
-    "rfile": "~1.0.0",
-    "through": "~2.3.4",
-    "uglify-js": "~2.4.0"
+    "through": "~2.3.4"
   },
   "devDependencies": {
+    "brfs": "^1.3.0",
     "linify": "~1.0.1",
-    "mocha": "*"
+    "mocha": "*",
+    "uglify-js": "~2.4.0"
   },
   "scripts": {
-    "test": "mocha -R spec",
-    "prepublish": "linify transform bin"
+    "build": "uglifyjs template.js > template.min.js && brfs source.js > index.js",
+    "test": "npm run build && mocha -R spec",
+    "prepublish": "npm run build && linify transform bin"
   },
+  "files": [
+    "index.js",
+    "bin/cli.js"
+  ],
   "repository": {
     "type": "git",
     "url": "https://github.com/ForbesLindesay/umd.git"
   },
   "author": "ForbesLindesay",
   "license": "MIT"
-}
\ No newline at end of file
+}
diff --git a/index.js b/source.js
similarity index 80%
rename from index.js
rename to source.js
index f3cfad3..28784e4 100644
--- a/index.js
+++ b/source.js
@@ -1,9 +1,8 @@
 'use strict';
 
+var fs = require('fs');
 var through = require('through');
-var rfile = require('rfile');
-var uglify = require('uglify-js');
-var templateSTR = rfile('./template.js');
+var templateSTR = fs.readFileSync(__dirname + '/template.min.js', 'utf8');
 
 function template(moduleName, options) {
   if (typeof options === 'boolean') {
@@ -11,9 +10,7 @@ function template(moduleName, options) {
   } else if (!options) {
     options = {};
   }
-  var str = uglify.minify(
-    templateSTR.replace(/\{\{defineNamespace\}\}/g, compileNamespace(moduleName)),
-    {fromString: true}).code
+  var str = templateSTR.replace(/defineNamespace\(\)/g, compileNamespace(moduleName))
     .split('source()')
   str[0] = str[0].trim();
   //make sure these are undefined so as to not get confused if modules have inner UMD systems
@@ -85,14 +82,13 @@ function compileNamespace(name) {
   // Worst case, too many namespaces to care about
   } else {
     var valueContainer = names.pop()
-    return names.reduce(compileNamespaceStep, ['var ref$ = g'])
-                .concat(['ref$.' + camelCase(valueContainer) + ' = f()'])
-                .join(';\n    ');
+    return names.map(compileNamespaceStep)
+                .concat(['g.' + camelCase(valueContainer) + ' = f()'])
+                .join(';');
   }
 }
 
-function compileNamespaceStep(code, name, i, names) {
+function compileNamespaceStep(name) {
   name = camelCase(name);
-  code.push('ref$ = (ref$.' + name + ' || (ref$.' + name + ' = {}))')
-  return code
+  return 'g=(g.' + name + '||(g.' + name + ' = {}))';
 }
diff --git a/template.js b/template.js
index 24833e7..c9ecf2f 100644
--- a/template.js
+++ b/template.js
@@ -22,7 +22,7 @@
       // seee https://github.com/facebook/react/issues/3037
       g = this;
     }
-    {{defineNamespace}};
+    defineNamespace()
   }
 
 })(function () {

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



More information about the Pkg-javascript-commits mailing list