Skip to content

Commit

Permalink
Warn instead of throwing on dependency cycles. Fixes #67
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed Aug 2, 2020
1 parent 015c850 commit cbbaf6d
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 201 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { fileURLToPath } = require('url');
const { resolve, relative } = require('path');
const { outputFile } = require('fs-extra');
const AssetGraph = require('assetgraph');
Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = {
const pathMap = new Map();

for (const asset of graph.findAssets({ isLoaded: true, isInline: false })) {
pathMap.set(asset, asset.url.replace('file://', '').split('?')[0]);
pathMap.set(asset, fileURLToPath(asset.url));
}

await hashfiles(graph, { trimmedStaticDir });
Expand All @@ -44,7 +45,7 @@ module.exports = {

for (const asset of graph.findAssets({ isLoaded: true, isInline: false })) {
const from = pathMap.get(asset);
const to = asset.url.replace('file://', '').split('?')[0];
const to = fileURLToPath(asset.url);

if (from !== to) {
result.push({
Expand Down
566 changes: 369 additions & 197 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"cdn"
],
"dependencies": {
"assetgraph": "^6.0.3",
"assetgraph-hashfiles": "^1.0.1",
"assetgraph": "6.1.3",
"assetgraph-hashfiles": "1.1.1",
"fs-extra": "9.0.1"
},
"devDependencies": {
Expand Down
57 changes: 57 additions & 0 deletions test/cycles/debug.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions test/cycles/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build]
publish = "dist"
command = "npx rimraf dist && npx cpy src dist"

[[plugins]]
package = "../../"
5 changes: 5 additions & 0 deletions test/cycles/src/dependency.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'main.css';

h1 {
color: blue;
}
19 changes: 19 additions & 0 deletions test/cycles/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello world</title>

<link rel="stylesheet" href="main.css">
</head>

<body>

<h1>Hello World!</h1>

</body>

</html>
5 changes: 5 additions & 0 deletions test/cycles/src/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'dependency.css';

h1 {
color: red;
}
22 changes: 22 additions & 0 deletions test/netlify-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,26 @@ describe('netlify-build', () => {
'main.js.map ==> static/main.js.e2c404d6d5.map',
]);
});

it('should warn when encountering cyclic relations', async () => {
const result = await build({
cwd: resolve(__dirname, 'cycles'),
buffer: true,
});

expect(result, 'to satisfy', {
success: true,
});

expect(
unlogify(result.logs.stderr),
'to contain',
' ⚠ WARN: moveAssetsInOrder: Cyclic dependencies detected. All files could not be moved'
);
expect(
unlogify(result.logs.stdout),
'to contain',
'** hashfiles moved no files **'
);
});
});

0 comments on commit cbbaf6d

Please sign in to comment.