Skip to content
Permalink
Browse files

feat: Rollup@1.0 support (#532)

BREAKING CHANGE: requires rollup@1.0
  • Loading branch information...
tivac committed Jan 1, 2019
1 parent ee1da9a commit 1fab7774474e2163f972f24afb8ad3636811d03a

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -21,7 +21,7 @@
"devDependencies": {
"@modular-css/test-utils": "file:packages/test-utils",
"@modular-css/website": "file:packages/www",
"@tivac/eslint-config": "^2.2.2",
"@tivac/eslint-config": "^2.3.0",
"browserify": "^16.2.3",
"cli-tester": "2.0.0",
"dedent": "0.7.0",
@@ -36,7 +36,7 @@
"lerna": "^3.8.0",
"pegjs": "0.10.0",
"read-dir-deep": "1.0.4",
"rollup": "^0.68.1",
"rollup": "^1.0.0",
"rollup-plugin-svelte": "^5.0.0",
"shelljs": "^0.8.3",
"svelte": "^2.16.0",
@@ -143,6 +143,27 @@ class Processor {
return files;
}

// Mark a file and everything that depends on it as invalid so
// it can be overwritten
invalidate(input) {
if(!input) {
throw new Error("invalidate() requires a file argument");
}

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

if(!this._graph.hasNode(source)) {
throw new Error(`Unknown file: ${input}`);
}

const deps = this.dependents(source);

deps.concat(source).forEach((file) => {
this._files[file].valid = false;
});
}

// Get the dependency order for a file or the entire tree
dependencies(file) {
if(file) {
@@ -345,8 +366,8 @@ class Processor {
// Process files and walk their composition/value dependency tree to find
// new files we need to process
async _walk(name, text) {
// No need to re-process files
if(this._files[name]) {
// No need to re-process files unless they've been marked invalid
if(this._files[name] && this._files[name].valid) {
return;
}

@@ -358,6 +379,7 @@ class Processor {
text,
exports : false,
values : false,
valid : true,
result : this._before.process(
text,
params(this, {
@@ -87,6 +87,62 @@ exports[`/processor.js API .file() should process an absolute file 4`] = `
"
`;

exports[`/processor.js API .invalidate() should invalidate a relative file 1`] = `
Array [
Array [
"simple.css",
false,
],
]
`;

exports[`/processor.js API .invalidate() should invalidate all dependents as well 1`] = `
Array [
Array [
"packages/processor/test/specimens/start.css",
false,
],
Array [
"packages/processor/test/specimens/local.css",
false,
],
Array [
"packages/processor/test/specimens/folder/folder.css",
false,
],
]
`;

exports[`/processor.js API .invalidate() should invalidate an absolute file 1`] = `
Array [
Array [
"packages/processor/test/specimens/simple.css",
false,
],
]
`;

exports[`/processor.js API .invalidate() should reprocess invalidated files 1`] = `
Array [
Array [
"packages/processor/test/specimens/start.css",
true,
],
Array [
"packages/processor/test/specimens/local.css",
true,
],
Array [
"packages/processor/test/specimens/folder/folder.css",
true,
],
]
`;

exports[`/processor.js API .invalidate() should throw if an invalid file is passed 1`] = `"Unknown file: nope.css"`;

exports[`/processor.js API .invalidate() should throw if no file is passed 1`] = `"invalidate() requires a file argument"`;

exports[`/processor.js API .output() should allow for seperate source map output 1`] = `
Object {
"file": "to.css",
@@ -106,6 +106,65 @@ describe("/processor.js", () => {
).toMatchSnapshot();
});
});

describe(".invalidate()", () => {
const status = (source) =>
Object.entries(source).map(([ key, value ]) =>
([ relative([ key ])[0], value.valid ])
);

it("should invalidate a relative file", async () => {
await processor.string(
"./simple.css",
".wooga { }"
);

processor.invalidate("./simple.css");

expect(status(processor.files)).toMatchSnapshot();
});

it("should invalidate an absolute file", async () => {
await processor.string(
"./packages/processor/test/specimens/simple.css",
".wooga { }"
);

processor.invalidate(require.resolve("./specimens/simple.css"));

expect(status(processor.files)).toMatchSnapshot();
});

it("should throw if no file is passed", async () => {
await processor.file("./packages/processor/test/specimens/start.css");

expect(() => processor.invalidate()).toThrowErrorMatchingSnapshot();
});

it("should throw if an invalid file is passed", async () => {
await processor.file("./packages/processor/test/specimens/start.css");

expect(() => processor.invalidate("nope.css")).toThrowErrorMatchingSnapshot();
});

it("should invalidate all dependents as well", async () => {
await processor.file("./packages/processor/test/specimens/start.css");

processor.invalidate("./packages/processor/test/specimens/folder/folder.css");

expect(status(processor.files)).toMatchSnapshot();
});

it("should reprocess invalidated files", async () => {
await processor.file("./packages/processor/test/specimens/start.css");

processor.invalidate("./packages/processor/test/specimens/start.css");

await processor.file("./packages/processor/test/specimens/start.css");

expect(status(processor.files)).toMatchSnapshot();
});
});

describe(".dependencies()", () => {
it("should return the dependencies of the specified file", async () => {
@@ -29,6 +29,6 @@
"slash": "^2.0.0"
},
"peerDependencies": {
"rollup": ">=0.68"
"rollup": "^1"
}
}
@@ -67,11 +67,8 @@ module.exports = (opts) => {

log("file changed", file);

processor.dependents(file).forEach((dep) =>
processor.remove(dep)
);

processor.remove(file);
// TODO: should the file be removed if it's gone?
processor.invalidate(file);
},

async transform(code, id) {
@@ -123,10 +120,11 @@ module.exports = (opts) => {
out.push(`export var styles = ${JSON.stringify(details.result.css)};`);
}

processor.dependencies(id).forEach((dependency) => this.addWatchFile(dependency));

return {
code : out.join("\n"),
map : emptyMappings,
dependencies : processor.dependencies(id),
code : out.join("\n"),
map : emptyMappings,
};
},

@@ -171,9 +169,8 @@ module.exports = (opts) => {
// Keep track of files that are queued to be written
const queued = new Set();


usage.overallOrder().forEach((entry) => {
const { modules, name, fileName } = chunks[entry];
const { modules, name } = chunks[entry];
const css = new Set();
let counter = 1;

@@ -223,8 +220,6 @@ module.exports = (opts) => {

const id = this.emitAsset(`${name}.css`);

log("css output", id);

/* eslint-disable-next-line no-await-in-loop */
const result = await processor.output({
to : to.replace(/\[(name|extname)\]/g, (match, field) =>
@@ -233,6 +228,8 @@ module.exports = (opts) => {
files,
});

log("css output", `${name}.css`);

this.setAssetSource(id, result.css);

if(result.map) {
Oops, something went wrong.

0 comments on commit 1fab777

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