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

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

Conversation

thescientist13
Copy link
Member

@thescientist13 thescientist13 commented Mar 23, 2024

Related Issue

resolves #923

Summary of Changes

  1. Add support for Import Attributes for JSON / CSS inside the CLI and added test cases
  2. Had to add a preIntercept lifecycle hook for Resource plugins (for PostCSS to run prior to Greenwood transforming the CSS. Also updated Babel plugin to use it)
  3. Created a "raw" plugin to support legacy import behaviors
  4. Update minimum Node version to be 18.20.0
  5. Had to adjust ESLint based on markdown plugin not working with custom parsers 😢 - Doesn't work with custom parser eslint/eslint-plugin-markdown#221
  6. Rename custom loaders naming convention from exp-* -> loaders-* and updated GitHub actions and the like accordingly

TL;DR

Without any plugins, you will be able to do this in Greenwood automatically

import sheet from './some.css' with { type: 'css' }; // you will get back a Constructable Stylesheet
import data from './some.json' with { type: 'json' }; // you will get back a JSON object

See #1216 for future thoughts / enhancements

TODO

  1. Fix failing build (patch package failing to patch changes)
  2. Restore ESLint (it doesn't support Import Attributes yet)
  3. Windows tests are now failing (seems to be fine when running locally on parallels 🤔 )
  4. Pattern for establishing import attributes in resource plugins as a request + header and / or URL + query params - Isomorphic (Reflected) Import Attributes Support #1216
    • Can / should greenwood convert import attributes to query params or some other signal from the browser that it is an fetch / ESM request
    • type=??? - query params are bad for node / URLs
    • fetch-sec-dest header is supported in all browsers now! - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Dest
    • refactor all standard plugins to follow the new convention
  5. what is the right Content-Type to return for an import attribute? - Isomorphic (Reflected) Import Attributes Support #1216
  6. Create a "raw" / text import plugin for backwards compat or to import anything as just a string
    • initial implementation
    • package.json / README
    • test cases (+matchers)
    • resolve / rewrite refactor and remove patch for eve-container.css
  7. Figure out support policy for non-standard imports, e.g. import css from './eve-button.css';
    • raw loader accepts a matcher option
    • should we discourage it in anyway?
  8. Minimum Node version (21.x) - - Upgrade to Node 20.x (latest LTS) #1202
  9. test if we still need type !== 'json' check for greenwood-meta-import-url plugin
  10. WCC Upstreams
  11. See if we can not require bundling for CSS / JSON through rollup at least - Isomorphic (Reflected) Import Attributes Support #1216
    • emit import attributes as assets
    • might need acornInjectPlugins for API routes and SSR pages rollup configs
  12. Any custom plugins should should adopt these new conventions (using import attributes and no longer needing ?type=xxx)
    • JSX
    • GraphQL
  13. Documentation
  14. (nice to have) test with Lit renderer plugin
  15. deprecate CSS / JSON import plugins and remove from website docs
  16. clean up console logs / TODOs / remove demo code

Questions / Follow Up Tasks

  1. rename shouldIntercept -> shouldTransform / shouldProcess?
  2. Seems odd we don't actually need the acorn-import-attributes plugin for Rollup?
  3. Track not needing an acorn plugin - Import Attributes support in Acorn #1218
  4. Should greenwood not bundle, e.g. just return text instead of CSSStylesheet? - Isomorphic (Reflected) Import Attributes Support #1216
  5. best way to stub out compilation in src/loader.js? - can worry about it later if needed
  6. Is it experimental? - it is not!
    • technically yes because of NodeJS I suppose, even though the syntax isn't?
    • update test names if we consider it not experimental
  7. Track an issue (or discussion) to refactor all plugins to use Sec-Fetch-Dest where applicable - leverage Sec-Fetch-Dest header for better filtering within Greenwood resource plugins #1222
  8. Track HTML Modules support / HTML import cleanup - https://github.com/ProjectEvergreen/greenwood/issues/new
  9. refactor duplicate loops over shouldIntercept, etc (good first issue)
  10. Track a discussion on how to allow Greenwood to self-invoke custom loader flag - Self Invoking Custom Import Loader(s) #1217
  11. See how would these changes impact a CSS modules plugin implementation - ProjectEvergreen/www.greenwoodjs.dev@e2e5fd2

@thescientist13 thescientist13 added question Further information is requested website Tasks related to the projects website / documentation documentation Greenwood specific docs Plugins Greenwood Plugins CLI feature New feature or request breaking labels Mar 23, 2024
@thescientist13 thescientist13 changed the title Feature/issue 923 native import attributes css json feature/issue 923 native import attributes for CSS and JSON Mar 28, 2024
@thescientist13 thescientist13 self-assigned this Apr 9, 2024
@thescientist13 thescientist13 force-pushed the feature/issue-923-native-import-attributes-css-json branch from 203c876 to f642d86 Compare April 22, 2024 21:19
@thescientist13 thescientist13 marked this pull request as ready for review April 24, 2024 22:08
const templateLocation = isInstalled
? new URL(`./node_modules/${name}/dist/layouts/`, import.meta.url)
: new URL('./fixtures/layouts/', import.meta.url);
const templateLocation = options.__isDevelopment
Copy link
Member Author

@thescientist13 thescientist13 Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just better aligns with our docs per https://www.greenwoodjs.io/guides/theme-packs/#development as it looks like in recent versions of NodeJS ls.stdout to string behaves differently apparently on Windows, hence why the tests were failing
Screenshot 2024-04-26 at 12 15 25 PM

This was working on Node 18.20.0 and GitHub Actions was running on 18.20.2 and so I think this is the issue in question
https://github.com/nodejs/node/releases/tag/v18.20.2

@thescientist13 thescientist13 merged commit b420c5c into release/0.30.0 Apr 29, 2024
8 checks passed
@thescientist13 thescientist13 deleted the feature/issue-923-native-import-attributes-css-json branch April 29, 2024 19:33
@thescientist13 thescientist13 linked an issue May 4, 2024 that may be closed by this pull request
3 tasks
thescientist13 added a commit that referenced this pull request Jun 1, 2024
* 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 added a commit that referenced this pull request Jun 2, 2024
* 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 added a commit that referenced this pull request Jun 2, 2024
* 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 added a commit that referenced this pull request Jun 2, 2024
* 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 added a commit that referenced this pull request Jun 22, 2024
* feature/discussion 1117 Isolation Mode (v1) (#1206)

* isolation mode for SSR pages and API routes for greenwood serve

* documentation for isolation mode option and global config test case

* misc refactoring

* set isolation mode to true for Lit renderer plugin

* set isolation mode to true for Lit renderer plugin

* enhancement/Issue-1118: Single File Bundles for SSR and API routes (#1186)

* Issue-1118: Refactor rollup config generation for APIs

* Issue-1118: Refactor rollup config generation for SSR

* Issue-1118: Refactor forEach to use for-in for the ssr config generation

* Issue-1118: Convert forEach to for..in

* Issue-1118: Remove unused code

* refactor away bundling work arounds and add comments

* refactor SSR page bundling to avoid hacky entry point placeholder hack

* patch custom element registry check from wcc

* refactor SSR page output name from .entry to .route

* document breaking changes for adapter plugins

* refactor import meta relative asset path escaping

* refactor API routes and adapters for mapped API bundles

* misc refactoring and docs update

* latest WCC patches

* windows compatibility

* update adapter docs example

* remove patches

---------

Co-authored-by: Owen Buckley <[email protected]>

* 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

* first pass on resource tracking and bundling refactor with lit polyfills removal from CLI

* interim work around to solve double rendering and undefined WCC bugs

* refactor frontmatter for graph and standard html plugin for SSR

* rename templates directory to layouts

* refactor over bundling of static script assets in bundleSsrPages

* handle bundling styles within bundleSsrPages

* post rebase tweaks

* custom elements as layouts

* post rebase tweaks

* WCC patched support for TS pages

* support and tests for API routes as a custom dynamic format

* restore TS tests and make servePage default

* document custom page format support

* fix lint

* patch latest WCC TypeScript changes

* cleanup default app layout content

* handle rollup circular dependency warnings for API routes

* rename test cases from templates to layout

* collapse API routes directory into pages directory

* bump to wc-compiler 0.14.0

---------

Co-authored-by: Paul Barry <[email protected]>
thescientist13 added a commit that referenced this pull request Jun 22, 2024
* 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 added a commit that referenced this pull request Jun 22, 2024
… integrations (#1234)

* feature/discussion 1117 Isolation Mode (v1) (#1206)

* isolation mode for SSR pages and API routes for greenwood serve

* documentation for isolation mode option and global config test case

* misc refactoring

* set isolation mode to true for Lit renderer plugin

* set isolation mode to true for Lit renderer plugin

* v0.30.0-alpha.0

* 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

* general enhancements and fixes for custom resource plugin integrations

* misc clean up validation testing
thescientist13 added a commit that referenced this pull request Jun 22, 2024
* 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 added a commit that referenced this pull request Jun 22, 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
breaking CLI documentation Greenwood specific docs feature New feature or request Plugins Greenwood Plugins question Further information is requested website Tasks related to the projects website / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import attributes for standard module formats; CSS and JSON
1 participant