Skip to content
Permalink
Browse files

fix: path casing (#528)

* rework processor

Moved logic from `.string()` to `._add()` so that it can be shared with `.file()`, and extra calls to `._normalize()` can be avoided.

Also updated some of the verbose output, so lots of snapshot changes.

* remove my wonky file deduping

`true-case-path` handles it better than I could anyways
  • Loading branch information...
tivac committed Nov 20, 2018
1 parent 147c926 commit 2d4af90239d03a0e53a9da83921daba76780eb7f
@@ -1,49 +1,13 @@
"use strict";

var fs = require("fs");

function uniqueGraph(graph) {
var clone = graph.clone(),
missing = 0,
nodes = {};

// Unique the list of nodes by using their inode value as a key in an object
graph.overallOrder().forEach((node) => {
var stat, key;

try {
stat = fs.lstatSync(node);

// Can't just use stat.ino, see https://github.com/tivac/modular-css/issues/242
key = Object.keys(stat)
.map((name) => (name !== "ctime" && name !== "mtime" ? stat[name] : false))
.filter(Boolean)
.join("-");
} catch(e) {
key = `key-${missing++}`;
}

if(key in nodes) {
clone.removeNode(node);
}

nodes[key] = true;
});

return clone;
}

function leaves(graph) {
return graph.overallOrder(true);
}
const leaves = (graph) => graph.overallOrder(true);

// Clone the graph and break the graph into tiers for further processing
module.exports = (graph) => {
var clone = uniqueGraph(graph),
tiers = [],
tier;

tier = leaves(clone);
const clone = graph.clone();
const tiers = [];

let tier = leaves(clone);

while(tier.length) {
tier.forEach((node) => {
@@ -0,0 +1,16 @@
"use strict";

const path = require("path");
const filecase = require("true-case-path");

module.exports = (cwd, file) => {
if(!path.isAbsolute(file)) {
file = path.join(cwd, file);
}

file = path.normalize(file);

// If the file doesn't exist filecase() returns undefined, so in that
// instance just use whatever was sent
return filecase(file) || file;
};
@@ -1,33 +1,39 @@
"use strict";

var selector = require("postcss-selector-parser"),
const selector = require("postcss-selector-parser");

parser = require("../parsers/parser.js");
const parser = require("../parsers/parser.js");

function parse(options, rule, value) {
var parsed, file;

try {
parsed = parser.parse(value);
} catch(e) {
throw rule.error(e.toString(), {
word : value.substring(e.location.start.offset, e.location.end.offset),
});
}

if(!parsed.source) {
return;
}

file = options.resolve(options.from, parsed.source);

// Add any compositions to the dependency graph
options.graph.addNode(file);
options.graph.addDependency(options.from, file);
}
const plugin = "modular-css-graph-nodes";

module.exports = (css, result) => {
var externals, current;

const parse = (rule, value) => {
const { opts } = result;
let parsed;

try {
parsed = parser.parse(value);
} catch(e) {
throw rule.error(e.toString(), {
word : value.substring(e.location.start.offset, e.location.end.offset),
});
}

if(!parsed.source) {
return;
}

const dependency = opts.resolve(opts.from, parsed.source);

result.messages.push({
type : "modular-css",

plugin,
dependency,
});
};

externals = selector((selectors) =>
selectors.walkPseudos((pseudo) => {
@@ -36,15 +42,15 @@ module.exports = (css, result) => {
return;
}

parse(result.opts, current, pseudo.nodes.toString());
parse(current, pseudo.nodes.toString());
})
);

// @value <value> from <file>
css.walkAtRules("value", (rule) => parse(result.opts, rule, rule.params));
css.walkAtRules("value", (rule) => parse(rule, rule.params));

// { composes: <rule> from <file> }
css.walkDecls("composes", (rule) => parse(result.opts, rule, rule.value));
css.walkDecls("composes", (rule) => parse(rule, rule.value));

// :external(<rule> from <file>) { ... }
// Have to assign to current so postcss-selector-parser can reference the right thing
@@ -56,4 +62,4 @@ module.exports = (css, result) => {
});
};

module.exports.postcssPlugin = "modular-css-graph-nodes";
module.exports.postcssPlugin = plugin;
Oops, something went wrong.

0 comments on commit 2d4af90

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