-
Notifications
You must be signed in to change notification settings - Fork 98
Conversation
This is great, @kaishin! Thanks for taking this on. By the way, feel free to develop on a swift-doc branch instead of a fork. That'll make it easier for folks to collaborate on new features. To that end, I just added a small patch to manage generated files according to this great article by @clarkbw. It should go a long way to cutting down on diff churn during code review. Trying to get this running locally, I'm hitting a runtime error:
Any ideas about what might be causing this?
|
Unfortunately, no. As far as I can tell, this will require package resources, coming in Swift 5.3. Though, if don't mind taking an insecure, unsustainable approach in the interim, we could download the CSS asset over the web during document generation. |
Thanks for adding
I will look into this. I personally use
My preference too. I tried but couldn't actually. Mind looking into it?
I thought of that as well. How about we link to a remote CSS file instead? It's not the best approach, but it's an alternative to consider. Another option would be to specify a CSS path argument when running the command and defaulting to the remote file otherwise (would even come with the benefit of opening the door to custom styling). |
The last commit should fix the issue. Remove |
Nice! Pulling the most recent commit and re-running By the way — I just updated the repository settings, so you should be able to create branches as a team member for future feature work. |
Now onto some bikeshedding... @kaishin What do you think about this layout?
So, all web stuff goes into |
How about renaming Resources to Static? It’s not obvious at first glance what’s compiled into what... I think Resources/Static works as well. |
Oh I guess that’s already decided in SPM? In that case no objections. |
Looking at the accepted proposal, the feature doesn't make any assumptions about where resources are located. But following the convention of a target's Regarding |
@mattt Any thoughts about this? This PR is still a draft because it broke functionality that it hasn't restored yet.
|
Apologies for not responding sooner. I've been heads-down the last few days working on 1.0.0-beta.2 (I wanted to cut a new release before all of this lands).
My first thought was to write that off as hacky, but I think there's a lot of merit to this approach — especially in light of your point about it providing a customization point for end users. I'm concerned about network access being limited in certain environments, and the security implications of downloading assets, but I think we can reach a good compromise by doing the following:
|
@kaishin Also, curious to know how you've setup your editor to work with PostCSS. The only real change I want from standard SCSS-style rule nesting. Would it make more sense to formally adopt SCSS syntax with postcss-scss or use the postcss-nested to postprocessor? Have you found a reasonable configuration that allows for save-on-format and linting in VSCode? |
I can share those once I am back to my computer, but it’s nothing fancy. I use format-on-save and open all CSS files as PostCSS.
This PR uses the nesting syntax that comes with postcss-presets-env, which is an implementation of this draft spec. I personally would recommend using this syntax instead of the SCSS, but changing it would take 5 minutes tops. |
The marketplace has a bunch of VSCode extensions that are entirely indistinguishable to me, and none of them do a great job explaining exactly what combination of plugins they support. So any guidance here would be really helpful — something to document, even. |
@mattt Here is my VS Code setup for CSS/PostCSS!
I have other things for colors and whatnot but these 3 are the main ones I rely on for CSS. |
Since I don't expect others to use |
Mark Assets/index.css and package-lock.json as generated files, and treat them as binary for the purposes of diffing and merging.
Updated for Node and VS Code
@mattt For the SHA256 digest, were you thinking of pulling swift-crypto as a dependency? I can do that in this PR, or we can leave it to a separate one. |
I added code for downloading and writing the CSS file—pointing to the fork URL for now. I can also preemptively add the final URL from Couple of annoyances:
|
@@ -43,3 +41,11 @@ func path(for symbol: Symbol) -> String { | |||
func path(for identifier: CustomStringConvertible) -> String { | |||
return "\(identifier)".replacingOccurrences(of: ".", with: "_") | |||
} | |||
|
|||
func writeFile(_ data: Data, to url: URL) throws { |
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.
Perhaps writeFile(with data...
would have been better. Or write(_ data
but that one gave me some errors I wasn't able to track.
Thinking about the size of that dependency, I'm starting to have second thoughts. I care quite a bit about security, but I know a lot of folks don't (no judgment here — I get it). So I worry about adding a heavy dependency to do one thing that most people see as optional. 💡 IdeaIt occurred to me that our downloading a CSS file and verifying its content is duplicating what a browser does with SRI for a I found a WebPack plugin that generates an asset manifest with SRI digests (I don't know if Parcel has something similar, but I imagine that we could write a plugin ourselves as needed). When loading resources locally (including, eventually, JS), we could read the SRI digests from the JSON file and plug those right into the markup — no swift-crypto required. But that's getting ahead of myself. To get this PR merged, how about we do this:
Yes, let's do that to avoid the extra follow-up PR.
Related: #65 (comment)
I think this can be solved by generating and committing an Xcode project that removes |
Indeed. I wasn't quite sold on the return on investment in this particular instance, not until we introduce JavaScript at least, where the security concerns are many-folds more serious than CSS. I am more than happy to look into SRI after this PR.
了解! For the other items you listed, it'd be easier to have issues for them. I can create them if you're ok with it. |
Remove name and version field from package.json
Turns out, the generated project doesn't link libxml2 correctly. Also, I'm pretty sure that we'd need to regenerate the file whenever a dependency is added or removed. I posted a message on the Swift Forums about the Xcode issue here: https://forums.swift.org/t/hiding-ignoring-directories-from-xcode-when-opening-swift-packages/35431 How bad to you think the current setup is? Do you consider this a blocker?
That would be great, thanks! |
If I've switched to VS Code for this project (and other non-Apple platform projects) and it's been good so far. But it's worthwhile to do this work so as to not impact the Xcode development experience. Give me 👍 or 👎 so that I can go forward with the |
@kaishin Great idea! I'd like to continue using Xcode as my primary IDE for this project (and allow others to as well), so this is perfect. |
The last commit is quite a departure from what we discussed above. I'll elaborate.
The solution:
|
The file structure inside .node is as follows:
|
@kaishin That sounds like quite the ordeal. I can't thank you enough for braving the trash fire that is the JavaScript ecosystem to make this asset pipeline happen. Since your last commit, I made a small edit to the Development section of the README and added a changelog entry. (I also applied a fast-follow patch with 7705c4f to address some differences with the original CSS) My next steps will be to take the original source and split it across a few different files, and looking into generating inlined, Base64-encoded SVG images. Also, experimenting with package resources in the latest Swift 5.3 preview. |
@mattt Don't mention it. Thanks for your patience, as well. 😉 If you break things down into tasks I'd be happy to pick some of them up, including splitting up the CSS, Base64-encoded SVG images, etc. For |
Closes #44
Notable decisions:
./Sources/web/css
. Hesitated with folder name casing..../Assets
Pending questions:
The
swift-doc
utility needs to know the path of the CSS file to copy over inside ofrun()
, is that something we can do today with the current SPM limitations? Perhaps I am missing something.