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

import attributes for standard module formats; CSS and JSON #923

Closed
3 tasks
thescientist13 opened this issue Apr 1, 2022 · 1 comment · Fixed by #1215 or #1259
Closed
3 tasks

import attributes for standard module formats; CSS and JSON #923

thescientist13 opened this issue Apr 1, 2022 · 1 comment · Fixed by #1215 or #1259
Assignees
Labels
alpha.2 CLI documentation Greenwood specific docs feature New feature or request Plugins Greenwood Plugins sponsorship:eligible SSR v0.30.0
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Apr 1, 2022

Summary

Related to #606 / #878

Currently we have a plugin for being able to import CSS, but it is non standard. Luckily, there is a standard coming for this in browsers and NodeJS! Here is an example and overview

import sheet from './styles.css' assert { type: 'css' };

document.adoptedStyleSheets = [sheet];
shadowRoot.adoptedStyleSheets = [sheet];

Details

Basically, what I would love to do is make this out of the box with Greenwood, or at least support it in plugin-import-css so that the plugin supports the standard syntax, and eventually, when all browser support CSS modules, user's can just stop using the plugin.

Scenarios that need to be handled:

  • NodeJS
  • Rollup - Plan for import assertions and non-JS module types rollup/rollup#3799
  • Acorn - (see above)
  • ES Module Shims - https://twitter.com/guybedford/status/1428451066081730561
  • Move away from type=xxx as it breaks in NodeJS
         Error: the string "TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module \"file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/plugin-import-json/test/cases/exp-build.prerender/package.json?type=json\" needs an import assertion of type \"json\"\n    at new NodeError (node:internal/errors:387:5)\n    at validateAssertions (node:internal/modules/esm/assert:82:15)\n    at defaultLoad (node:internal/modules/esm/load:84:3)\n    at nextLoad (node:internal/modules/esm/loader:165:28)\n    at load (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/loader.js:67:10)\n    at load (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/test/test-loader.js:13:12)\n    at nextLoad (node:internal/modules/esm/loader:165:28)\n    at ESMLoader.load (node:internal/modules/esm/loader:608:26)\n    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:464:22)\n    at new ModuleJob (node:internal/modules/esm/module_job:63:26) {\n  code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING'\n}\n" was thrown, throw an Error :)
      at processTicksAndRej

There is a a repo tracking this across bundlers as well
https://github.com/nicolo-ribaudo/import-attributes-ecosystem-support


If this goes well, we should try and do the same with JSON. Should also document / update any impact this may have on the Import CSS plugin.

This could also clean up the experimental loader, which should be able to just leverage native import assertions now for JSON.

Might also be worth cross-referencing with other custom resource types like TypeScript and GraphQL - #1004


Something to keep in mind re: Rollup support has not landed yet - rollup/rollup#4818

For at least for Rollup 3.x, looks like we could do something like this

Unfortunately that path tops out at 3.x since in 4.x they removed the ability to parse custom syntax using acorn - https://rollupjs.org/migration/#configuration-changes

So I think we'll have to:

  1. Land Rollup 3.x - upgrade Rollup and all plugins to 3.x #1087
  2. For this task, try and use those plugins
  3. Make a tracking ticket for whenever Rollup supports import assertions
@thescientist13 thescientist13 added Plugins Greenwood Plugins CLI feature New feature or request labels Apr 1, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Apr 1, 2022
@thescientist13 thescientist13 mentioned this issue Sep 22, 2022
27 tasks
@thescientist13 thescientist13 changed the title import assertions for CSS Modules import assertions for CSS Modules (and custom resources?) Nov 20, 2022
@thescientist13 thescientist13 changed the title import assertions for CSS Modules (and custom resources?) import assertions for standard module formats (CSS, JSON) Nov 20, 2022
@thescientist13 thescientist13 changed the title import assertions for standard module formats (CSS, JSON) import assertions for standard module formats; CSS and JSON Nov 20, 2022
@thescientist13
Copy link
Member Author

thescientist13 commented May 13, 2023

FWIW, esbuild is working on this for CSS - evanw/esbuild#20

@thescientist13 thescientist13 self-assigned this Mar 1, 2024
@thescientist13 thescientist13 mentioned this issue Mar 9, 2024
39 tasks
@thescientist13 thescientist13 pinned this issue Mar 9, 2024
@thescientist13 thescientist13 added the documentation Greenwood specific docs label Mar 18, 2024
@thescientist13 thescientist13 moved this from 🔖 Ready to 🏗 In progress in [Greenwood] Phase 9 - Standards and Conventions Mar 18, 2024
@thescientist13 thescientist13 changed the title import assertions for standard module formats; CSS and JSON import attributes for standard module formats; CSS and JSON Mar 18, 2024
@thescientist13 thescientist13 moved this from 🏗 In progress to 👀 In review in [Greenwood] Phase 9 - Standards and Conventions Apr 24, 2024
@thescientist13 thescientist13 linked a pull request May 4, 2024 that will close this issue
27 tasks
@thescientist13 thescientist13 linked a pull request Jul 20, 2024 that will close this issue
11 tasks
@thescientist13 thescientist13 unpinned this issue Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.2 CLI documentation Greenwood specific docs feature New feature or request Plugins Greenwood Plugins sponsorship:eligible SSR v0.30.0
Projects
No open projects
1 participant