diff --git a/lib/slim/checks/circular_dependencies.js b/lib/slim/checks/circular_dependencies.js deleted file mode 100644 index 414d3b29..00000000 --- a/lib/slim/checks/circular_dependencies.js +++ /dev/null @@ -1,40 +0,0 @@ -var some = require("lodash/some"); -var values = require("lodash/values"); -var includes = require("lodash/includes"); - -/** - * Checks whether there are circular dependencies in the graph - * @param {Object} steal - The dependency graph object - * @throws if circular dependencies are found - */ -module.exports = function(graph) { - var nodes = values(graph); - - if (some(nodes, hasCircularDependencies)) { - throw new Error( - `Cannot create slim build. Circular dependencies are not supported` - ); - } -}; - -/** - * Whether the node has a circular dependency - * @param {Object} - A node from the dependency graph - * @param {number} - The index of the node in the (array) graph - * @param {Array.[Object]} - A list of nodes - * @return `true` if a circular dependency is found - */ -function hasCircularDependencies(node, index, nodes) { - for (var i = index + 1; i < nodes.length; i += 1) { - var nextNode = nodes[i]; - - if ( - includes(node.dependencies, nextNode.load.name) && - includes(nextNode.dependencies, node.load.name) - ) { - return true; - } - } - - return false; -} diff --git a/lib/stream/check_slim_support.js b/lib/stream/check_slim_support.js index 376d091a..833c40b2 100644 --- a/lib/stream/check_slim_support.js +++ b/lib/stream/check_slim_support.js @@ -4,7 +4,6 @@ var through = require("through2"); var checkStealAndLoader = require("../slim/checks/steal_and_loader"); var checkStealConditional = require("../slim/checks/steal_conditional"); var checkProductionEnvConfig = require("../slim/checks/production_env_config"); -var checkCircularDependencies = require("../slim/checks/circular_dependencies"); module.exports = function() { return through.obj(function(data, enc, done) { @@ -22,7 +21,6 @@ function checkSupport(data) { checkStealAndLoader(configMain, data.graph); checkStealConditional(data.graph[configMain]); checkProductionEnvConfig(data.steal); - checkCircularDependencies(data.graph); return data; } diff --git a/package.json b/package.json index a1f5b96f..17e10ead 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "through2": "^2.0.0", "tmp": "0.0.31", "traceur": "0.0.111", - "transpile": "2.4.0-pre.0", + "transpile": "^2.4.0-pre.1", "uglify-js": "~2.8.22", "urix": "^0.1.0", "winston": "^2.2.0", diff --git a/test/circular/slim.html b/test/circular/slim.html new file mode 100644 index 00000000..8fd79007 --- /dev/null +++ b/test/circular/slim.html @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/test/slim/progressive/baz-size.snap b/test/slim/progressive/baz-size.snap index 30b2659b..953af214 100644 --- a/test/slim/progressive/baz-size.snap +++ b/test/slim/progressive/baz-size.snap @@ -1 +1 @@ -module.exports = 159; \ No newline at end of file +module.exports = 158; \ No newline at end of file diff --git a/test/slim_build_test.js b/test/slim_build_test.js index 49ef19e0..81e3d092 100644 --- a/test/slim_build_test.js +++ b/test/slim_build_test.js @@ -342,20 +342,23 @@ describe("slim builds", function() { }); }); - it("errors out with circular dependencies", function(done) { + it("*supports circular dependencies", function() { var base = path.join(__dirname, "circular"); var config = { config: path.join(base, "package.json!npm") }; - rmdir(path.join(base, "dist")) + return rmdir(path.join(base, "dist")) .then(function() { return optimize(config, { minify: false, quiet: true }); }) .then(function() { - done(new Error("should not build the app")); + return open(path.join("test", "circular", "slim.html")); }) - .catch(function(err) { - assert(/Cannot create slim build/.test(err.message)); - done(); + .then(function(args) { + return Promise.all([args.close, find(args.browser, "circularWorks")]); + }) + .then(function(data) { + assert.ok(data[1], "circularWork should be true"); + data[0](); // close(); }); }); @@ -386,8 +389,14 @@ describe("slim builds", function() { }) .then(function() { return Promise.all([ - checkSizeSnapshot(path.join(base, "dist", "bundles", "main.js"), base), - checkSizeSnapshot(path.join(base, "dist", "bundles", "baz.js"), base) + checkSizeSnapshot( + path.join(base, "dist", "bundles", "main.js"), + base + ), + checkSizeSnapshot( + path.join(base, "dist", "bundles", "baz.js"), + base + ) ]); }); }); @@ -421,7 +430,9 @@ describe("slim builds", function() { return optimize(config, { minify: false, quiet: true }); }) .then(function() { - return open(path.join("test", "slim", "esm_named_imports", "index.html")); + return open( + path.join("test", "slim", "esm_named_imports", "index.html") + ); }) .then(function(args) { return Promise.all([args.close, find(args.browser, "result")]);