-
Notifications
You must be signed in to change notification settings - Fork 152
Flatten entry array & resolve files without extension #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { TemplateTypes } from "@opticss/template-api"; | ||
import { ObjectDictionary, objectValues } from "@opticss/util"; | ||
import { ObjectDictionary, objectValues, whatever } from "@opticss/util"; | ||
import * as debugGenerator from "debug"; | ||
import { postcss } from "opticss"; | ||
import * as path from "path"; | ||
|
@@ -114,7 +114,7 @@ export class CssBlocksPlugin | |
entries = webpackEntry; | ||
} | ||
else if (typeof webpackEntry === "object") { | ||
entries = objectValues(webpackEntry); | ||
entries = flatten(objectValues(webpackEntry)) as string[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the signature below this doesn’t need to be cast. |
||
} | ||
|
||
let pending: PendingResult = this.analyzer.analyze(...entries) | ||
|
@@ -322,3 +322,7 @@ export class CssBlocksPlugin | |
this.applyPluginsAsync("block-compilation-complete", result, cb); | ||
} | ||
} | ||
|
||
function flatten(arr: whatever[]): whatever[] { | ||
return arr.reduce((acc, val) => (acc as whatever[]).concat(Array.isArray(val) ? flatten(val) : val), []) as whatever[]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A better signature for this is: function flatten<T extends whatever>(arr: T[] | T[][]): T[]; Then no casting will be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with that I'm getting
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok this was a bit tricky. The type of reduce wasn't smart enough to let the type checker work out what was going on. Also, the definition I provided was only two levels of arrays, but the code would handle it recursively. I refactored that function and made it part of our opticss utilities: linkedin/opticss@f104638 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this change caused a few failing tests – what was the intent here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Totally possible that its a problem with our test harness 🙂 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah probably caused the failing tests, the problem is it currently doesn't resolve files without extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
know of a better way?