Skip to content

Commit

Permalink
refactor(processor): add dupewarn option and no longer resolve path c…
Browse files Browse the repository at this point in the history
…ase (#582)

BREAKING CHANGE:

It was causing massive slowdowns to synchronously resolve files using `true-case-path`, and making it async wasn't a guaranteed win either. So it's removed, which should solve #581 pretty neatly.

Instead now there's a warning if two files are included that differ in case only. It can be disabled by setting `dupewarn : false` as part of the config object.
  • Loading branch information
tivac committed May 8, 2019
1 parent a06ec9b commit 01581f9
Show file tree
Hide file tree
Showing 28 changed files with 1,614 additions and 567 deletions.
1,701 changes: 1,353 additions & 348 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@
"cssnano": "^4.1.10",
"dedent": "0.7.0",
"dentist": "1.0.3",
"env-cmd": "^8.0.2",
"env-cmd": "^9.0.1",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-jest": "^22.5.1",
"factor-bundle": "2.5.0",
"from2-string": "1.1.0",
"jest": "^24.7.0",
"jest-cli": "^24.7.0",
"jest": "^24.8.0",
"jest-cli": "^24.8.0",
"jest-runner-eslint": "^0.7.3",
"lerna": "^3.13.1",
"lerna": "^3.13.4",
"pegjs": "0.10.0",
"read-dir-deep": "^4.0.3",
"rollup": "^1.7.4",
"read-dir-deep": "^5.0.0",
"rollup": "^1.11.3",
"rollup-plugin-hypothetical": "^2.1.0",
"rollup-plugin-svelte": "^5.0.3",
"shelljs": "^0.8.3",
"snapshot-diff": "^0.5.1",
"sugarss": "^2.0.0",
"svelte": "^2.16.1",
"watchify": "^3.11.1",
"webpack": "^4.29.6"
"webpack": "^4.30.0"
},
"dependencies": {
"@modular-css/browserify": "file:packages/browserify",
Expand Down
2 changes: 1 addition & 1 deletion packages/browserify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@modular-css/processor": "file:../processor",
"mkdirp": "^0.5.1",
"p-each-series": "^1.0.0",
"p-each-series": "^2.0.0",
"sink-transform": "^2.0.0",
"through2": "^2.0.3"
}
Expand Down
9 changes: 2 additions & 7 deletions packages/processor/lib/normalize.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
"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;

return path.normalize(file);
};
7 changes: 1 addition & 6 deletions packages/processor/lib/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const path = require("path");
const resolve = require("resolve-from").silent;
const pathcase = require("true-case-path");

exports.resolve = (src, file) => resolve(path.dirname(src), file);

Expand All @@ -16,10 +15,6 @@ exports.resolvers = (resolvers) => {
(result = fn(src, file, exports.resolve))
);

if(!result) {
throw new Error(`Unable to locate "${file}" from "${src}"`);
}

return pathcase(result);
return result;
};
};
5 changes: 2 additions & 3 deletions packages/processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
],
"dependencies": {
"dependency-graph": "^0.8.0",
"escape-string-regexp": "^1.0.5",
"escape-string-regexp": "^2.0.0",
"lodash": "^4.17.0",
"postcss": "^7.0.0",
"postcss-selector-parser": "^6.0.2",
"postcss-url": "^8.0.0",
"postcss-value-parser": "^3.3.0",
"resolve-from": "^4.0.0",
"true-case-path": "^1.0.2",
"resolve-from": "^5.0.0",
"unique-slug": "^2.0.0"
},
"peerDependencies": {
Expand Down
23 changes: 20 additions & 3 deletions packages/processor/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Processor {
verbose : false,
resolvers : [],
postcss : {},
dupewarn : true,
},
opts
);
Expand Down Expand Up @@ -74,6 +75,7 @@ class Processor {

this._files = Object.create(null);
this._graph = new Graph();
this._ids = new Map();

this._before = postcss([
...(options.before || []),
Expand Down Expand Up @@ -174,10 +176,12 @@ class Processor {

const deps = this.dependents(source);

deps.concat(source).forEach((file) => {
[ ...deps, source ].forEach((file) => {
this._log("invalidate()", file);

this._files[file].valid = false;

this._ids.delete(file.toLowerCase());
});
}

Expand Down Expand Up @@ -280,7 +284,7 @@ class Processor {
),
});

root.append([ comment ].concat(result.root.nodes));
root.append([ comment, ...result.root.nodes ]);

const idx = root.index(comment);

Expand Down Expand Up @@ -333,11 +337,24 @@ class Processor {
// Take a file id and some text, walk it for dependencies, then
// process and return details
async _add(id, text) {
const check = id.toLowerCase();

// Warn about potential dupes if an ID goes past we've seen before
if(this._options.dupewarn) {
const other = this._ids.get(check);

if(other && other !== id) {
console.warn(`POTENTIAL DUPLICATE FILES:\n\t${relative(this._options.cwd, other)}\n\t${relative(this._options.cwd, id)}`);
}
}

this._ids.set(check, id);

this._log("_add()", id);

await this._walk(id, text);

const deps = this._graph.dependenciesOf(id).concat(id);
const deps = [ ...this._graph.dependenciesOf(id), id ];

for(const dep of deps) {
const file = this._files[dep];
Expand Down
10 changes: 10 additions & 0 deletions packages/processor/test/__snapshots__/options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ exports[`/processor.js options lifecycle options done should run sync postcss pl
a {}"
`;

exports[`/processor.js options lifecycle options dupewarn should warn on potentially duplicate file paths 1`] = `
Array [
Array [
"POTENTIAL DUPLICATE FILES:
packages/processor/test/specimens/start.css
packages/processor/test/specimens/START.css",
],
]
`;

exports[`/processor.js options lifecycle options processing should include exports from 'modular-css-export' modules 1`] = `
Object {
"a": true,
Expand Down
10 changes: 5 additions & 5 deletions packages/processor/test/composition.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ describe("/processor.js", () => {
],
});

const file = require.resolve("./specimens/composes.css");

try {
await processor.file(file);
} catch({ message }) {
await processor.file(require.resolve("./specimens/composes.css"));
} catch(e) {
const { message } = e;

expect(message).toMatch(
`Unable to locate "./folder/folder2.css" from "${file}"`
`no such file or directory, open '${require.resolve("./specimens/folder/folder2.css")}a'`
);
}
});
Expand Down

This file was deleted.

33 changes: 0 additions & 33 deletions packages/processor/test/issues/issue-191.test.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/processor/test/issues/specimens/191/start.css

This file was deleted.

5 changes: 0 additions & 5 deletions packages/processor/test/issues/specimens/191/values.css

This file was deleted.

Loading

0 comments on commit 01581f9

Please sign in to comment.