@modular-css/processor
Advanced tools
Comparing version 17.1.2 to 18.0.0
@@ -6,2 +6,18 @@ # Change Log | ||
# [18.0.0](https://github.com/tivac/modular-css/compare/v17.1.2...v18.0.0) (2018-12-22) | ||
### Features | ||
* Rework rollup support ([#531](https://github.com/tivac/modular-css/issues/531)) ([fce87fe](https://github.com/tivac/modular-css/commit/fce87fe)) | ||
### BREAKING CHANGES | ||
* changed rollup plugin CSS output so it better matches rollup output chunk format & bumped minimum rollup version to 0.68.0 | ||
## [17.1.2](https://github.com/tivac/modular-css/compare/v17.1.1...v17.1.2) (2018-11-26) | ||
@@ -8,0 +24,0 @@ |
@@ -14,5 +14,6 @@ "use strict"; | ||
exports.compositions = (cwd, { files }) => { | ||
exports.compositions = ({ options, files }) => { | ||
const { cwd } = options; | ||
const json = {}; | ||
Object.keys(files) | ||
@@ -23,4 +24,4 @@ .sort() | ||
); | ||
return json; | ||
}; |
{ | ||
"name": "@modular-css/processor", | ||
"version": "17.1.2", | ||
"version": "18.0.0", | ||
"description": "A streamlined reinterpretation of CSS Modules", | ||
@@ -34,3 +34,3 @@ "main": "./processor.js", | ||
}, | ||
"gitHead": "8c52345b28bc3f6b3c0710c3b780ef8cb8bb62ff" | ||
"gitHead": "ee1da9a10a7ba171de3a474932e7a0d30d418685" | ||
} |
@@ -6,6 +6,5 @@ "use strict"; | ||
const escape = require("escape-string-regexp"); | ||
const each = require("lodash/forEach"); | ||
const get = require("lodash/get"); | ||
const Graph = require("dependency-graph").DepGraph; | ||
const namespaced = require("./values-namespaced.js"); | ||
@@ -26,4 +25,6 @@ | ||
.forEach((msg) => | ||
each(msg.values, (children, ns) => | ||
each(children, (details, child) => (values[`${ns}.${child}`] = details)) | ||
Object.entries(msg.values).forEach(([ ns, children ]) => | ||
Object.entries(children).forEach(([ child, details ]) => | ||
(values[`${ns}.${child}`] = details) | ||
) | ||
) | ||
@@ -59,3 +60,3 @@ ); | ||
const parsed = value(thing[prop]); | ||
parsed.walk((node) => { | ||
@@ -65,3 +66,3 @@ if(node.type !== "word") { | ||
} | ||
// Replace any value instances | ||
@@ -71,3 +72,3 @@ node.value = node.value.replace(matchRegex, (match) => { | ||
thing.source = values[match].source; | ||
return values[match].value; | ||
@@ -81,3 +82,3 @@ }); | ||
// Walk through all values & build dependency graph | ||
each(values, (details, name) => { | ||
Object.entries(values).forEach(([ name, details ]) => { | ||
graph.addNode(name); | ||
@@ -98,3 +99,3 @@ | ||
const parsed = value(values[name].value); | ||
parsed.walk((node) => { | ||
@@ -101,0 +102,0 @@ if(node.type !== "word" || !values[node.value]) { |
@@ -5,3 +5,3 @@ "use strict"; | ||
const path = require("path"); | ||
const Graph = require("dependency-graph").DepGraph; | ||
@@ -110,12 +110,12 @@ const postcss = require("postcss"); | ||
const id = this._normalize(file); | ||
this._log("file()", id); | ||
return this._add(id, fs.readFileSync(id, "utf8")); | ||
} | ||
// Add a file by name + contents to the dependency graph | ||
async string(file, text) { | ||
const id = this._normalize(file); | ||
this._log("string()", id); | ||
@@ -125,3 +125,3 @@ | ||
} | ||
// Remove a file from the dependency graph | ||
@@ -133,3 +133,3 @@ remove(input) { | ||
.filter((file) => this._graph.hasNode(file)); | ||
if(!files.length) { | ||
@@ -149,3 +149,3 @@ return files; | ||
} | ||
// Get the dependency order for a file or the entire tree | ||
@@ -161,3 +161,3 @@ dependencies(file) { | ||
} | ||
// Get the dependant files for a file | ||
@@ -170,10 +170,10 @@ dependents(file) { | ||
const id = this._normalize(file); | ||
return this._graph.dependantsOf(id); | ||
} | ||
// Get the ultimate output for specific files or the entire tree | ||
async output(args = false) { | ||
let { files } = args; | ||
if(!Array.isArray(files)) { | ||
@@ -185,3 +185,3 @@ files = tiered(this._graph); | ||
files = new Set(files.map(this._normalize)); | ||
// Then turn it back into array because the iteration story is better | ||
@@ -206,4 +206,6 @@ files = [ ...files.values() ]; | ||
const results = []; | ||
for(const dep of files) { | ||
this._log("_after()", dep); | ||
// eslint-disable-next-line no-await-in-loop | ||
@@ -215,3 +217,3 @@ const result = await this._after.process( | ||
this._files[dep].result.root.clone(), | ||
params(this, { | ||
@@ -252,5 +254,5 @@ from : dep, | ||
root.append([ comment ].concat(result.root.nodes)); | ||
const idx = root.index(comment); | ||
// Need to manually insert a newline after the comment, but can only | ||
@@ -265,3 +267,3 @@ // do that via whatever comes after it for some reason? | ||
}); | ||
const result = await this._done.process( | ||
@@ -272,7 +274,9 @@ root, | ||
result.compositions = output.compositions(this._options.cwd, this); | ||
Object.defineProperty(result, "compositions", { | ||
get : () => output.compositions(this) | ||
}); | ||
return result; | ||
} | ||
// Expose files | ||
@@ -288,2 +292,11 @@ get files() { | ||
// Return all the compositions for the files loaded into the processor instance | ||
get compositions() { | ||
// Ensure all files are fully-processed first | ||
return Promise.all( | ||
Object.values(this._files).map(({ result }) => result) | ||
) | ||
.then(() => output.compositions(this)); | ||
} | ||
// Take a file id and some text, walk it for dependencies, then | ||
@@ -302,3 +315,3 @@ // process and return details | ||
if(!file.processed) { | ||
this._log("_add() processing", dep); | ||
this._log("_process()", dep); | ||
@@ -316,5 +329,5 @@ file.processed = this._process.process( | ||
file.result = await file.processed; | ||
const { result } = file; | ||
file.exports = Object.assign( | ||
@@ -358,2 +371,4 @@ Object.create(null), | ||
this._log("_before()", name); | ||
const file = this._files[name] = { | ||
@@ -370,3 +385,3 @@ text, | ||
}; | ||
await file.result; | ||
@@ -388,9 +403,7 @@ | ||
await Promise.all( | ||
this._graph.dependenciesOf(name).reduce((promises, dependency) => { | ||
if(!this._files[dependency]) { | ||
promises.push(this.file(dependency)); | ||
} | ||
return promises; | ||
}, []) | ||
this._graph.dependenciesOf(name).map((dependency) => ( | ||
this._files[dependency] ? | ||
this._files[dependency].result : | ||
this.file(dependency) | ||
)) | ||
); | ||
@@ -397,0 +410,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77598
1921