Skip to content
Permalink
Browse files

fix: support circular dependencies (#541)

Fixes #539
  • Loading branch information...
tivac committed Jan 18, 2019
1 parent e1e25b9 commit b8dce99243f0370abcd394c5a670edc9ac04b748
@@ -170,7 +170,7 @@ module.exports = (opts) => {

// Build chunk dependency graph so it can be walked in order later to
// Allow for outputting CSS alongside chunks as optimally as possible
const usage = new Graph();
const usage = new Graph({ circular : true });

Object.entries(chunks).forEach(([ entry, chunk ]) => {
const { imports, dynamicImports } = chunk;
@@ -180,6 +180,49 @@ Array [
]
`;

exports[`/rollup.js code splitting should support circular JS dependencies 1`] = `
Array [
Object {
"file": "a.js",
"text": "import b from './b.js';

var css = {
\\"a\\": \\"a\\"
};

console.log(css, b);

var a$1 = \\"a\\";

export default a$1;
",
},
Object {
"file": "assets/common.css",
"text": "/* packages/rollup/test/specimens/circular-dependencies/a.css */
.a { color: aqua; }
/* packages/rollup/test/specimens/circular-dependencies/b.css */
.b { color: blue; }
",
},
Object {
"file": "b.js",
"text": "import a from './a.js';

var css = {
\\"b\\": \\"b\\"
};

console.log(css, a);

var b$1 = \\"b\\";

export default b$1;
",
},
]
`;

exports[`/rollup.js code splitting should support dynamic imports 1`] = `
Array [
Object {
@@ -0,0 +1 @@
.a { color: aqua; }
@@ -0,0 +1,6 @@
import b from "./b.js";
import css from "./a.css";

console.log(css, b);

export default "a";
@@ -0,0 +1 @@
.b { color: blue; }
@@ -0,0 +1,6 @@
import a from "./a.js";
import css from "./b.css";

console.log(css, a);

export default "b";
@@ -315,5 +315,41 @@ describe("/rollup.js", () => {

expect(dir("./multiple-chunks-hashed/assets")).toMatchSnapshot();
});

it("should support circular JS dependencies", async () => {
const bundle = await rollup({
onwarn(warning, handler) {
if(warning.code === "CIRCULAR_DEPENDENCY") {
return;
}

handler(warning);
},

input : [
require.resolve("./specimens/circular-dependencies/a.js"),
require.resolve("./specimens/circular-dependencies/b.js"),
],

plugins : [
plugin({
namer,
map,
}),
],
});

await bundle.write({
format,
sourcemap,

assetFileNames,
chunkFileNames,

dir : prefix(`./output/circular-dependencies`)
});

expect(dir(`./circular-dependencies`)).toMatchSnapshot();
});
});
});

0 comments on commit b8dce99

Please sign in to comment.
You can’t perform that action at this time.