Skip to content
Permalink
Browse files

fix: ignore external modules (#555)

  • Loading branch information...
tivac committed Jan 27, 2019
1 parent ffd29d9 commit 5a6fcd9599ba59a28411e764f0dfd64d80e9bc3f
@@ -158,7 +158,7 @@ class Processor {
if(!input) {
throw new Error("invalidate() requires a file argument");
}

// Only want files actually in the array
const source = this._normalize(input);

@@ -380,7 +380,7 @@ class Processor {
return;
}

this._graph.addNode(name);
this._graph.addNode(name, 0);

this._log("_before()", name);

@@ -407,7 +407,7 @@ class Processor {

const dep = this._normalize(dependency);

this._graph.addNode(dep);
this._graph.addNode(dep, 0);
this._graph.addDependency(name, dep);
});

@@ -169,15 +169,18 @@ module.exports = (opts) => {
Object.entries(bundle).forEach(([ entry, chunk ]) => {
const { imports, dynamicImports } = chunk;

const statics = imports.filter((dep) => dep in bundle);
const dynamics = dynamicImports.filter((dep) => dep in bundle);

// Add all the nodes first, tagging them with their type for later
imports.forEach((dep) => usage.addNode(dep, "static"));
dynamicImports.forEach((dep) => usage.addNode(dep, "dynamic"));
statics.forEach((dep) => usage.addNode(dep, "static"));
dynamics.forEach((dep) => usage.addNode(dep, "dynamic"));

// Then tag the entry node
usage.addNode(entry, "entry");

// And then add all the dependency links
[ ...dynamicImports, ...imports ].forEach((dep) =>
[ ...dynamics, ...statics ].forEach((dep) =>
usage.addDependency(entry, dep)
);
});
@@ -189,8 +192,8 @@ module.exports = (opts) => {
const queued = new Set();

usage.overallOrder().forEach((entry) => {
const { modules, name, fileName, isEntry } = bundle[entry];
const css = new Set();
const { modules, name, fileName, isEntry } = bundle[entry];

// Get CSS files being used by this chunk
const styles = Object.keys(modules).filter((file) => processor.has(file));
@@ -204,6 +207,7 @@ module.exports = (opts) => {
css.add(style);
});

// How does Set not have .filter yet ಠ_ಠ
const included = [ ...css ].filter((file) => !queued.has(file));

if(!included.length) {
@@ -337,10 +341,8 @@ module.exports = (opts) => {

const meta = {};

Object.entries(bundle).forEach(([ entry, { dynamicAssets = false, assets = false }]) => {
if(!assets && !dynamicAssets) {
return;
}
out.forEach((value, entry) => {
const { assets, dynamicAssets } = bundle[entry];

meta[entry] = {
assets,
@@ -324,6 +324,12 @@ Array [
Object {
"file": "metadata.json",
"text": "{
\\"chunk2.js\\": {
\\"assets\\": [],
\\"dynamicAssets\\": [
\\"assets/chunk.css\\"
]
},
\\"a.js\\": {
\\"assets\\": [
\\"assets/a.css\\"
@@ -335,12 +341,6 @@ Array [
\\"assets/b.css\\"
],
\\"dynamicAssets\\": []
},
\\"chunk2.js\\": {
\\"assets\\": [],
\\"dynamicAssets\\": [
\\"assets/chunk.css\\"
]
}
}",
},
@@ -370,6 +370,12 @@ Array [
Object {
"file": "chunks.json",
"text": "{
\\"chunk2.js\\": {
\\"assets\\": [],
\\"dynamicAssets\\": [
\\"assets/chunk.css\\"
]
},
\\"a.js\\": {
\\"assets\\": [
\\"assets/a.css\\"
@@ -381,12 +387,6 @@ Array [
\\"assets/b.css\\"
],
\\"dynamicAssets\\": []
},
\\"chunk2.js\\": {
\\"assets\\": [],
\\"dynamicAssets\\": [
\\"assets/chunk.css\\"
]
}
}",
},
@@ -186,6 +186,26 @@ describe("/rollup.js", () => {

expect(exists("./output/no-css/assets/no-css.css")).toBe(false);
});

it("should ignore external modules", async () => {
const bundle = await rollup({
input : require.resolve("./specimens/external.js"),
plugins : [
plugin({
namer,
}),
],
external : [
require.resolve("./specimens/simple.js"),
],
});

await bundle.generate({
format,
assetFileNames,
file : prefix(`./output/no-css/no-css.js`),
});
});

it("should generate JSON", async () => {
const bundle = await rollup({
@@ -0,0 +1,3 @@
import simple from "./simple.js";

console.log(simple);

0 comments on commit 5a6fcd9

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