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

Agnostic Runtime #953

Open
thescientist13 opened this issue Jun 29, 2022 · 8 comments
Open

Agnostic Runtime #953

thescientist13 opened this issue Jun 29, 2022 · 8 comments
Assignees
Labels
CLI feature New feature or request RFC Proposal and changes to workflows, architecture, APIs, etc website Tasks related to the projects website / documentation
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Jun 29, 2022

Type of Change

Feature

Summary

Would like to provide Greenwood with the ability to run on a broad spectrum of runtime environments, not just NodeJS. So for example, being able to run Greenwood in

  • NodeJS
  • Deno (although technically Deno now support npm)
  • Bun
  • CloudFlare Workers
  • etc

This means more Web APIs like fetch, URL, etc and less fs, path, etc. So would like to make the core as agnostic as possible through and through, in preparation for Serverless / Edge cases as per #1008 and #948 .

Details

Things to look out for would be what "Adapter" strategies for anything that is Node specific. This includes

  • fs - alternatives to readFile, existsSync, copy, etc. Use fs.promises.* so we can use URL directly
  • path - get rid of all instances
  • process.cwd() - ???
  • Readable.from
  • Workers
  • os

Also, will want to pull along WCC for this adventure too.

@thescientist13 thescientist13 added RFC Proposal and changes to workflows, architecture, APIs, etc discussion tied to an ongoing discussion or meeting notes labels Jun 29, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Jun 29, 2022
@thescientist13
Copy link
Member Author

superseded by #1008

@thescientist13
Copy link
Member Author

Still need this, separate from adapting for hosting platforms and providers.

@thescientist13 thescientist13 changed the title Runtime Strategies Agnostic Runtime Dec 3, 2022
@thescientist13 thescientist13 self-assigned this Dec 9, 2022
@thescientist13
Copy link
Member Author

thescientist13 commented Dec 11, 2022

So did some initial research on this by trying to "de" Node (🦕 ) WCC and while it seems path.join et al is mostly supplanted by URL now, the last big consideration I anticipated needing to solve for was fs. My hope was that fetch, introducing into Greenwood via #957 would supplant this.

However, it appears that file:// URI types are not in the fetch spec, left up to implementors to manage on their own.

For now, unfortunate as it is, file: URLs are left as an exercise for the reader. When in doubt, return a network error.

Thus, support for it is inconsistent

So we may need to support runtime adapters in the short term it seems 🤕


Some other related links

@thescientist13
Copy link
Member Author

Seems like a conversation around a standard fs implementation is in the works over at the WinterCG.

@thescientist13
Copy link
Member Author

thescientist13 commented Sep 12, 2023

Bun

Did a little testing with Bun 1.0. Got an error related to importing htmlparser

116 | async function trackResourcesForRoute(html, compilation, route) {
117 |   const { context } = compilation;
118 |   const root = htmlparser.parse(html, {
                   ^
TypeError: htmlparser.parse is not a function. (In 'htmlparser.parse(html, {
    script: !0,
    style: !0
  })', 'htmlparser.parse' is undefined)
      at /Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/src/lib/resource-utils.js:118:15
      at trackResourcesForRoute (/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/src/lib/resource-utils.js:116:38)
      at /Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/src/lifecycles/prerender.js:121:10
      at /Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/src/lifecycles/prerender.js:107:37
      at /Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-renderer-puppeteer/src/puppeteer-handler.js:19:18
      at /Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-renderer-puppeteer/src/puppeteer-handler.js:13:23
      at processTicksAndRejections (:1:2602)

Made this change to the import and confirmed it worked in both Bun and Node and so was than able to succesfully build!

// before
import htmlparser from 'node-html-parser';

// after
import * as htmlparser from 'node-html-parser';

However, it looks like the serve and develop commands work, but just show a white page 🤔
Screenshot 2023-09-11 at 8 44 47 PM

@thescientist13
Copy link
Member Author

@thescientist13
Copy link
Member Author

Not sure we'll be able to get this in for 1.0, so deferring to 1.x milestone.

@thescientist13
Copy link
Member Author

I think now with Deno 2.0 and Bun, I bet a lot of this is sorted out now with npm, and so aside from just prefixing everything NodeJS specific with :node I bet it might just work! 🤞

I think this item could still live on as a discussion to extricate the NodeJS parts at that point, but not sure how necessary it will be at that point.

@thescientist13 thescientist13 added website Tasks related to the projects website / documentation CLI and removed discussion tied to an ongoing discussion or meeting notes labels Oct 10, 2024
This was referenced Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI feature New feature or request RFC Proposal and changes to workflows, architecture, APIs, etc website Tasks related to the projects website / documentation
Projects
Development

No branches or pull requests

1 participant