Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Got example optimizer runs working

  • Loading branch information...
commit 7561347fcdea832dab17fc9e06875b285f1456b5 1 parent 2d69ee7
James Burke authored June 29, 2012
21  README.md
Source Rendered
@@ -66,7 +66,14 @@ is sufficient:
66 66
 
67 67
 Circular references that do import * on each other will not work.
68 68
 
69  
-3) Using identifiers for "inline modules" is not supported:
  69
+3) import * does not work in build
  70
+
  71
+Using r.js to optimize a set of hm modules to a concatenated list of AMD
  72
+modules works for everything except import *, since the build does not actually
  73
+run the * module as part of the build, since it may accesss environment-specific
  74
+information, like `window` or `navigator` which do not exist in Node.
  75
+
  76
+4) Using identifiers for "inline modules" is not supported:
70 77
 
71 78
     module Bar {}
72 79
 
@@ -108,6 +115,18 @@ require(['hm!main'], function (main) {
108 115
 });
109 116
 ```
110 117
 
  118
+## Doing Builds
  119
+
  120
+See `tests/build` for example build files (the X.build.js files).
  121
+
  122
+The AMD version of the modules are placed in the built file, so the `hm` and
  123
+`esprima` modules do not need to be included in the build file.
  124
+
  125
+See the build files for more details.
  126
+
  127
+If any .hm files will be loaded dynamically after a build, then the source
  128
+versions of `hm` and `esprima` should stay in the build.
  129
+
111 130
 ## Running Tests
112 131
 
113 132
 ### In Browser
8  esprima.js
@@ -40,12 +40,12 @@ parseStatement: true, parseSourceElement: true, parseModuleBlock: true, parseCon
40 40
 
41 41
 (function (factory) {
42 42
     'use strict';
43  
-    if (typeof exports !== 'undefined') {
44  
-        // Node/CommonJS
45  
-        factory(exports);
46  
-    } else if (typeof define === 'function' && define.amd) {
  43
+    if (typeof define === 'function' && define.amd) {
47 44
         // AMD
48 45
         define(['exports'], factory);
  46
+    } else if (typeof exports !== 'undefined') {
  47
+        // Node/CommonJS
  48
+        factory(exports);
49 49
     } else {
50 50
         // Browser globals
51 51
         factory((esprima = {}));
48  tests/build/export-tests-built.js
... ...
@@ -0,0 +1,48 @@
  1
+
  2
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
  3
+define('hm!funcs',['require','exports','module'],function (require, exports, module) {
  4
+var oneName = 'one';
  5
+
  6
+exports.one = function  () {
  7
+    return oneName;
  8
+};
  9
+
  10
+exports._helloWorld = function (value){
  11
+        return 'hello ' + value
  12
+    };
  13
+
  14
+
  15
+});
  16
+define('hm!vars',['require','exports','module'],function (require, exports, module) {
  17
+
  18
+exports.foo =
  19
+    'foo';
  20
+
  21
+exports.bar = 'bar'
  22
+
  23
+});
  24
+require({
  25
+    baseUrl: require.isBrowser ? '.' : 'export',
  26
+    paths: {
  27
+        hm: '../../hm',
  28
+        esprima: '../../esprima'
  29
+    }
  30
+});
  31
+
  32
+require(["hm!funcs", "hm!vars"],
  33
+function (funcs,   vars) {
  34
+    doh.register(
  35
+        "exportTests",
  36
+        [
  37
+            function exportTests(t){
  38
+                t.is("one", funcs.one());
  39
+                t.is("hello des moines", funcs._helloWorld('des moines'));
  40
+                t.is("foo", vars.foo);
  41
+                t.is("bar", vars.bar);
  42
+            }
  43
+        ]
  44
+    );
  45
+    doh.run();
  46
+});
  47
+
  48
+define("export-tests", function(){});
48  tests/build/export-tests-expected.js
... ...
@@ -0,0 +1,48 @@
  1
+
  2
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
  3
+define('hm!funcs',['require','exports','module'],function (require, exports, module) {
  4
+var oneName = 'one';
  5
+
  6
+exports.one = function  () {
  7
+    return oneName;
  8
+};
  9
+
  10
+exports._helloWorld = function (value){
  11
+        return 'hello ' + value
  12
+    };
  13
+
  14
+
  15
+});
  16
+define('hm!vars',['require','exports','module'],function (require, exports, module) {
  17
+
  18
+exports.foo =
  19
+    'foo';
  20
+
  21
+exports.bar = 'bar'
  22
+
  23
+});
  24
+require({
  25
+    baseUrl: require.isBrowser ? '.' : 'export',
  26
+    paths: {
  27
+        hm: '../../hm',
  28
+        esprima: '../../esprima'
  29
+    }
  30
+});
  31
+
  32
+require(["hm!funcs", "hm!vars"],
  33
+function (funcs,   vars) {
  34
+    doh.register(
  35
+        "exportTests",
  36
+        [
  37
+            function exportTests(t){
  38
+                t.is("one", funcs.one());
  39
+                t.is("hello des moines", funcs._helloWorld('des moines'));
  40
+                t.is("foo", vars.foo);
  41
+                t.is("bar", vars.bar);
  42
+            }
  43
+        ]
  44
+    );
  45
+    doh.run();
  46
+});
  47
+
  48
+define("export-tests", function(){});
17  tests/build/export.build.js
... ...
@@ -0,0 +1,17 @@
  1
+{
  2
+    baseUrl: '../export',
  3
+    paths: {
  4
+        hm: '../../hm',
  5
+        esprima: '../../esprima'
  6
+    },
  7
+    name: 'export-tests',
  8
+    //Do not need esprima after the build.
  9
+    exclude: ['esprima'],
  10
+    out: 'export-tests-built.js',
  11
+    optimize: 'none',
  12
+    //Stub out hm the build. Need to keep
  13
+    //the plugin stub in the build since
  14
+    //loader will want to check it for any
  15
+    //normalize method.
  16
+    stubModules: ['hm']
  17
+}
61  tests/build/import-tests-built.js
... ...
@@ -0,0 +1,61 @@
  1
+
  2
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
  3
+define('hm!gamma',['require','exports','module'],function (require, exports, module) {
  4
+
  5
+exports.name = 'gamma';
  6
+
  7
+});
  8
+define('hm!beta',['require','exports','module'],function (require, exports, module) {
  9
+
  10
+// Simple module and a text comment that mentions module
  11
+exports.name = 'beta';
  12
+
  13
+exports.func = function () {
  14
+    return 'beta function';
  15
+}
  16
+
  17
+exports.uniqueBeta = 'uniqueBeta';
  18
+
  19
+});
  20
+define('hm!alpha',['require','exports','module','hm!gamma','hm!beta','hm!beta','hm!beta'],function (require, exports, module) {
  21
+
  22
+var gamma = require("hm!gamma");
  23
+
  24
+var gammaName = gamma.name;
  25
+var betaName = require("hm!beta").name;
  26
+var betaFunc = require("hm!beta").func;
  27
+var uniqueBeta = require("hm!beta").uniqueBeta;
  28
+exports.gammaName = gammaName;
  29
+
  30
+exports.betaName = betaName;
  31
+
  32
+exports.betaFunc = betaFunc;
  33
+
  34
+exports.uniqueBeta = uniqueBeta;
  35
+
  36
+});
  37
+require({
  38
+    baseUrl: require.isBrowser ? '.' : 'import',
  39
+    paths: {
  40
+        hm: '../../hm',
  41
+        esprima: '../../esprima'
  42
+    }
  43
+});
  44
+
  45
+require(["hm!alpha"],
  46
+function (alpha) {
  47
+    doh.register(
  48
+        "importTests",
  49
+        [
  50
+            function importTests(t){
  51
+                t.is("gamma", alpha.gammaName);
  52
+                t.is("beta", alpha.betaName);
  53
+                t.is("beta function", alpha.betaFunc());
  54
+                t.is("uniqueBeta", alpha.uniqueBeta);
  55
+            }
  56
+        ]
  57
+    );
  58
+    doh.run();
  59
+});
  60
+
  61
+define("import-tests", function(){});
61  tests/build/import-tests-expected.js
... ...
@@ -0,0 +1,61 @@
  1
+
  2
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
  3
+define('hm!gamma',['require','exports','module'],function (require, exports, module) {
  4
+
  5
+exports.name = 'gamma';
  6
+
  7
+});
  8
+define('hm!beta',['require','exports','module'],function (require, exports, module) {
  9
+
  10
+// Simple module and a text comment that mentions module
  11
+exports.name = 'beta';
  12
+
  13
+exports.func = function () {
  14
+    return 'beta function';
  15
+}
  16
+
  17
+exports.uniqueBeta = 'uniqueBeta';
  18
+
  19
+});
  20
+define('hm!alpha',['require','exports','module','hm!gamma','hm!beta','hm!beta','hm!beta'],function (require, exports, module) {
  21
+
  22
+var gamma = require("hm!gamma");
  23
+
  24
+var gammaName = gamma.name;
  25
+var betaName = require("hm!beta").name;
  26
+var betaFunc = require("hm!beta").func;
  27
+var uniqueBeta = require("hm!beta").uniqueBeta;
  28
+exports.gammaName = gammaName;
  29
+
  30
+exports.betaName = betaName;
  31
+
  32
+exports.betaFunc = betaFunc;
  33
+
  34
+exports.uniqueBeta = uniqueBeta;
  35
+
  36
+});
  37
+require({
  38
+    baseUrl: require.isBrowser ? '.' : 'import',
  39
+    paths: {
  40
+        hm: '../../hm',
  41
+        esprima: '../../esprima'
  42
+    }
  43
+});
  44
+
  45
+require(["hm!alpha"],
  46
+function (alpha) {
  47
+    doh.register(
  48
+        "importTests",
  49
+        [
  50
+            function importTests(t){
  51
+                t.is("gamma", alpha.gammaName);
  52
+                t.is("beta", alpha.betaName);
  53
+                t.is("beta function", alpha.betaFunc());
  54
+                t.is("uniqueBeta", alpha.uniqueBeta);
  55
+            }
  56
+        ]
  57
+    );
  58
+    doh.run();
  59
+});
  60
+
  61
+define("import-tests", function(){});
17  tests/build/import.build.js
... ...
@@ -0,0 +1,17 @@
  1
+{
  2
+    baseUrl: '../import',
  3
+    paths: {
  4
+        hm: '../../hm',
  5
+        esprima: '../../esprima'
  6
+    },
  7
+    name: 'import-tests',
  8
+    //Do not need esprima after the build.
  9
+    exclude: ['esprima'],
  10
+    out: 'import-tests-built.js',
  11
+    optimize: 'none',
  12
+    //Stub out hm the build. Need to keep
  13
+    //the plugin stub in the build since
  14
+    //loader will want to check it for any
  15
+    //normalize method.
  16
+    stubModules: ['hm']
  17
+}
70  tests/build/importstar-tests-built.js
... ...
@@ -0,0 +1,70 @@
  1
+
  2
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
  3
+define('hm!theta',['require','exports','module'],function (require, exports, module) {
  4
+
  5
+exports.thetaOne = 'thetaOne'
  6
+exports.thetaTwo = 'thetaTwo'
  7
+
  8
+});
  9
+define('hm!sigma',['require','exports','module'],function (require, exports, module) {
  10
+
  11
+var sigmaNumber = 4;
  12
+
  13
+function sigmaFunc() {
  14
+    return 'sigma function';
  15
+}
  16
+
  17
+exports.sigmaNumber = sigmaNumber;
  18
+exports.sigmaFunc = sigmaFunc;
  19
+
  20
+});
  21
+define('hm!epsilon',['require','exports','module'],function (require, exports, module) {
  22
+
  23
+/*
  24
+Fake comment to try to break the hm parser.
  25
+module bad = 'bad';
  26
+*/
  27
+
  28
+//import {bad2} from 'bad2'
  29
+
  30
+
  31
+
  32
+exports.thetaOne = thetaOne;
  33
+
  34
+exports.thetaTwo = thetaTwo;
  35
+
  36
+exports.sigmaFunc = sigmaFunc;
  37
+
  38
+exports.sigmaNumber = sigmaNumber;
  39
+
  40
+});
  41
+require({
  42
+    baseUrl: require.isBrowser ? '.' : 'import',
  43
+    paths: {
  44
+        hm: '../../hm',
  45
+        esprima: '../../esprima'
  46
+    },
  47
+    config: {
  48
+        hm: {
  49
+            logTransform: require.isBrowser
  50
+        }
  51
+    }
  52
+});
  53
+
  54
+require(["hm!epsilon"],
  55
+function (epsilon) {
  56
+    doh.register(
  57
+        "importStarTests",
  58
+        [
  59
+            function importStarTests(t){
  60
+                t.is("thetaOne", epsilon.thetaOne);
  61
+                t.is("thetaTwo", epsilon.thetaTwo);
  62
+                t.is("sigma function", epsilon.sigmaFunc());
  63
+                t.is("4", epsilon.sigmaNumber);
  64
+            }
  65
+        ]
  66
+    );
  67
+    doh.run();
  68
+});
  69
+
  70
+define("importstar-tests", function(){});
17  tests/build/importstar.build.js
... ...
@@ -0,0 +1,17 @@
  1
+{
  2
+    baseUrl: '../import',
  3
+    paths: {
  4
+        hm: '../../hm',
  5
+        esprima: '../../esprima'
  6
+    },
  7
+    name: 'importstar-tests',
  8
+    //Do not need esprima after the build.
  9
+    exclude: ['esprima'],
  10
+    out: 'importstar-tests-built.js',
  11
+    optimize: 'none',
  12
+    //Stub out hm the build. Need to keep
  13
+    //the plugin stub in the build since
  14
+    //loader will want to check it for any
  15
+    //normalize method.
  16
+    stubModules: ['hm']
  17
+}
58  tests/build/module-tests-built.js
... ...
@@ -0,0 +1,58 @@
  1
+
  2
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
  3
+define('hm!two',['require','exports','module'],function (require, exports, module) {
  4
+
  5
+exports.name = 'two';
  6
+
  7
+exports.func = function () {
  8
+    return 'two function';
  9
+}
  10
+});
  11
+define('hm!three',['require','exports','module'],function (require, exports, module) {
  12
+
  13
+exports.name = 'three';
  14
+});
  15
+define('four',{
  16
+    name: 'four'
  17
+});
  18
+
  19
+define('hm!one',['require','exports','module','hm!two','hm!three','four'],function (require, exports, module) {
  20
+
  21
+//Ask for some modules, use AMD module for four.
  22
+var two = require("hm!two");
  23
+var three = require("hm!three");
  24
+var four = require("four");
  25
+
  26
+exports.twoName = two.name;
  27
+
  28
+exports.twoFunction = two.func;
  29
+
  30
+exports.threeName = three.name;
  31
+
  32
+exports.fourName = four.name;
  33
+});
  34
+require({
  35
+    baseUrl: require.isBrowser ? '.' : 'module',
  36
+    paths: {
  37
+        hm: '../../hm',
  38
+        esprima: '../../esprima'
  39
+    }
  40
+});
  41
+
  42
+require(["hm!one"],
  43
+function (one) {
  44
+    doh.register(
  45
+        "moduleTests",
  46
+        [
  47
+            function moduleTests(t){
  48
+                t.is("two", one.twoName);
  49
+                t.is("two function", one.twoFunction());
  50
+                t.is("three", one.threeName);
  51
+                t.is("four", one.fourName);
  52
+            }
  53
+        ]
  54
+    );
  55
+    doh.run();
  56
+});
  57
+
  58
+define("module-tests", function(){});
58  tests/build/module-tests-expected.js
... ...
@@ -0,0 +1,58 @@
  1
+
  2
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
  3
+define('hm!two',['require','exports','module'],function (require, exports, module) {
  4
+
  5
+exports.name = 'two';
  6
+
  7
+exports.func = function () {
  8
+    return 'two function';
  9
+}
  10
+});
  11
+define('hm!three',['require','exports','module'],function (require, exports, module) {
  12
+
  13
+exports.name = 'three';
  14
+});
  15
+define('four',{
  16
+    name: 'four'
  17
+});
  18
+
  19
+define('hm!one',['require','exports','module','hm!two','hm!three','four'],function (require, exports, module) {
  20
+
  21
+//Ask for some modules, use AMD module for four.
  22
+var two = require("hm!two");
  23
+var three = require("hm!three");
  24
+var four = require("four");
  25
+
  26
+exports.twoName = two.name;
  27
+
  28
+exports.twoFunction = two.func;
  29
+
  30
+exports.threeName = three.name;
  31
+
  32
+exports.fourName = four.name;
  33
+});
  34
+require({
  35
+    baseUrl: require.isBrowser ? '.' : 'module',
  36
+    paths: {
  37
+        hm: '../../hm',
  38
+        esprima: '../../esprima'
  39
+    }
  40
+});
  41
+
  42
+require(["hm!one"],
  43
+function (one) {
  44
+    doh.register(
  45
+        "moduleTests",
  46
+        [
  47
+            function moduleTests(t){
  48
+                t.is("two", one.twoName);
  49
+                t.is("two function", one.twoFunction());
  50
+                t.is("three", one.threeName);
  51
+                t.is("four", one.fourName);
  52
+            }
  53
+        ]
  54
+    );
  55
+    doh.run();
  56
+});
  57
+
  58
+define("module-tests", function(){});
17  tests/build/module.build.js
... ...
@@ -0,0 +1,17 @@
  1
+{
  2
+    baseUrl: '../module',
  3
+    paths: {
  4
+        hm: '../../hm',
  5
+        esprima: '../../esprima'
  6
+    },
  7
+    name: 'module-tests',
  8
+    //Do not need esprima after the build.
  9
+    exclude: ['esprima'],
  10
+    out: 'module-tests-built.js',
  11
+    optimize: 'none',
  12
+    //Stub out hm the build. Need to keep
  13
+    //the plugin stub in the build since
  14
+    //loader will want to check it for any
  15
+    //normalize method.
  16
+    stubModules: ['hm']
  17
+}

0 notes on commit 7561347

Please sign in to comment.
Something went wrong with that request. Please try again.