Skip to content
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

bug/issue 1199 gracefully handle unresolvable asset URLs during CSS optimization #1235

Conversation

thescientist13
Copy link
Member

@thescientist13 thescientist13 commented May 31, 2024

Related Issue

relates to #1199

Observed that in some cases, like when using postcss-import plugin and having all styles inlined, there will be a "loss" of reference point for where to look for files, when these dependencies use relative paths, e.g.
https://unpkg.com/browse/font-awesome@4.6.3/css/font-awesome.css

@font-face {
  font-family: 'FontAwesome';
  src: url('../fonts/fontawesome-webfont.eot?v=4.6.3');
  src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.6.3') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff2?v=4.6.3') format('woff2'), url('../fonts/fontawesome-webfont.woff?v=4.6.3') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.6.3') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.6.3#fontawesomeregular') format('svg');
  font-weight: normal;
  font-style: normal;
}

Which will then cause Greenwood to fail the build

Error: ENOENT: no such file or directory, open '/Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/src/fonts/fontawesome-webfont.eot'
    at Object.openSync (node:fs:596:3)
    at Object.readFileSync (node:fs:464:35)
    at Object.enter (file:///Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js:56:36)
    at walkNode (file:///Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/node_modules/css-tree/lib/walker/create.js:169:36)
    at List.walkReducer (file:///Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/node_modules/css-tree/lib/walker/create.js:195:61)
    at List.reduce (file:///Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/node_modules/css-tree/lib/utils/List.js:174:22)
    at Object.Value (file:///Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/node_modules/css-tree/lib/walker/create.js:103:31)
    at walkNode (file:///Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/node_modules/css-tree/lib/walker/create.js:180:41)
    at Object.Declaration (file:///Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/node_modules/css-tree/lib/walker/create.js:108:28)
    at walkNode (file:///Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/node_modules/css-tree/lib/walker/create.js:180:41) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/owenbuckley/Workspace/analogstudiosri/www.analogstudios.net/src/fonts/fontawesome-webfont.eot'

Also, needed is to handle data: URLs.
https://unpkg.com/browse/bootstrap@4.0.0-alpha.4/dist/css/bootstrap.css

.has-success .form-control-success {
  background-image: url("data:image/svg+xml;...");
}

Summary of Changes

  1. For url paths Greenwood can't locate, emit a warning
  2. Don't try and optimize data: URLs
  3. Added test cases for both

@thescientist13 thescientist13 added bug Something isn't working alpha.3 v0.30.0 labels May 31, 2024
@thescientist13 thescientist13 added this to the 1.0 milestone May 31, 2024
@thescientist13 thescientist13 changed the title gracefully handle unresolvable assets during CSS optimization bug/issue 1199 gracefully handle unresolvable URLs during CSS optimization May 31, 2024
@thescientist13 thescientist13 changed the title bug/issue 1199 gracefully handle unresolvable URLs during CSS optimization bug/issue 1199 gracefully handle unresolvable asset URLs during CSS optimization May 31, 2024
@thescientist13 thescientist13 force-pushed the bug/issue-1199-gracefully-handle-unresolvable-assets branch from c104068 to 3933f99 Compare June 2, 2024 17:25
@thescientist13 thescientist13 mentioned this pull request Jun 22, 2024
39 tasks
* initial upgrade for test cases

* upgrade CLI and www to Lit v3

* revert static router test case change

* all tests passing

* patch escodegen for better ESM support

* test for lit element hydration script

* refactor rollup config

* update Lit renderer README and apply conditional Lit script hydration

* comments and TODOs cleanup

* minor rebase patches

* WCC v0.12.0 upgrade and removing patches directory

* hydration default documentation and testing for Lit renderer plugin
* intial draft of import attributes support for CSS and JSON

* all test cases passing

* need patch package

* wcc patches for import attributes and CSSStylesheet shim

* bump min NodeJS version for exp specs

* temp disable ESLint

* develop based import assertion specs

* serve based import attributes specs

* add preIntercept resource plugin lifecycle and refactor PostCSS to use it

* all test cases passing for import attributes support

* refactor built in CSS and JSON intercepting

* demo code

* raw plugin docs and package.json updates

* update latest documentation for custom loaders support in NodeJS

* update custom import docs

* upgrade wcc v0.13.0

* only need Node 18 for github actions

* css imports and raw plugin interop with test cases

* lit renderer import attribute test cases and documentation

* refactor matchers support for raw plugin instead of patching and add test cases

* disable describe.only

* update usage for custom resource plugins to showcase usage of import attributes

* document preIntercept lifecycle and convert Babel to use it

* restore ESLint

* enable debug logging for failing specs

* refactor theme pack specs

* fix linting

* remove CSS and JSON packages from being publishable

* clean up console logs and comments

* rename exp test cases to loadersnaming prefix

* fix command in github actions

* remove plugin-import-css callout from plugin-postcss README

* remove demo code from website

* refine PostCSS plugin intercepting
@thescientist13 thescientist13 force-pushed the bug/issue-1199-gracefully-handle-unresolvable-assets branch from b67dfe3 to ed4feb0 Compare June 22, 2024 18:07
@thescientist13 thescientist13 merged commit 575550c into release/0.30.0 Jun 22, 2024
8 checks passed
@thescientist13 thescientist13 deleted the bug/issue-1199-gracefully-handle-unresolvable-assets branch June 22, 2024 18:21
thescientist13 added a commit that referenced this pull request Nov 2, 2024
…ptimization (#1235)

* feature/issue 1197 Lit v3 upgrade and SSR fixes and enhancements (#1201)

* initial upgrade for test cases

* upgrade CLI and www to Lit v3

* revert static router test case change

* all tests passing

* patch escodegen for better ESM support

* test for lit element hydration script

* refactor rollup config

* update Lit renderer README and apply conditional Lit script hydration

* comments and TODOs cleanup

* minor rebase patches

* WCC v0.12.0 upgrade and removing patches directory

* hydration default documentation and testing for Lit renderer plugin

* v0.30.0-alpha.1

* feature/issue 923 native import attributes for CSS and JSON (#1215)

* intial draft of import attributes support for CSS and JSON

* all test cases passing

* need patch package

* wcc patches for import attributes and CSSStylesheet shim

* bump min NodeJS version for exp specs

* temp disable ESLint

* develop based import assertion specs

* serve based import attributes specs

* add preIntercept resource plugin lifecycle and refactor PostCSS to use it

* all test cases passing for import attributes support

* refactor built in CSS and JSON intercepting

* demo code

* raw plugin docs and package.json updates

* update latest documentation for custom loaders support in NodeJS

* update custom import docs

* upgrade wcc v0.13.0

* only need Node 18 for github actions

* css imports and raw plugin interop with test cases

* lit renderer import attribute test cases and documentation

* refactor matchers support for raw plugin instead of patching and add test cases

* disable describe.only

* update usage for custom resource plugins to showcase usage of import attributes

* document preIntercept lifecycle and convert Babel to use it

* restore ESLint

* enable debug logging for failing specs

* refactor theme pack specs

* fix linting

* remove CSS and JSON packages from being publishable

* clean up console logs and comments

* rename exp test cases to loadersnaming prefix

* fix command in github actions

* remove plugin-import-css callout from plugin-postcss README

* remove demo code from website

* refine PostCSS plugin intercepting

* gracefully handle unresolvable assets during CSS optimization

* refactor URL and fs usage

* fix lint

* missed rebase-a-ronis

* missed rebase-a-ronis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.3 bug Something isn't working CLI v0.30.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

support bundling of url properties (like for @font-face + src) during CSS file optimization
1 participant