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

provide initialized compilation to custom loader script (and resource plugins) #1273

Closed
thescientist13 opened this issue Sep 2, 2024 · 0 comments · Fixed by #1274
Closed
Assignees
Labels
alpha.6 bug Something isn't working CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins SSR v0.30.0
Milestone

Comments

@thescientist13
Copy link
Member

Summary

As observed in ProjectEvergreen/www.greenwoodjs.dev#84, another item of context was missing from the compilation provided to plugins when pre-rendering / SSR'ing and so we had to patch support for userWorkspace to handle bundling images defined in the our theme.css file, otherwise we got this error

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:405:5)
    at new URL (node:internal/url:676:13)
    at Object.enter (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js:54:13)
    at walkNode (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/css-tree/lib/walker/create.js:169:36)
    at List.walkReducer (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/css-tree/lib/walker/create.js:195:61)
    at List.reduce (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/css-tree/lib/utils/List.js:174:22)
    at Object.Value (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/css-tree/lib/walker/create.js:103:31)
    at walkNode (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/css-tree/lib/walker/create.js:180:41)
    at Object.Declaration (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/css-tree/lib/walker/create.js:108:28)
    at walkNode (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/css-tree/lib/walker/create.js:180:41) {
  input: './assets/link.svg',
  code: 'ERR_INVALID_URL'
}

Further more, the src/ directory had to be hardcoded,

Details

This is not that surprising, as we only provide certain values currently, and are hardcoding them ourselves, so we should probably change that :D

const config = await initConfig();
const resourcePlugins = config.plugins
  .filter(plugin => plugin.type === 'resource')
  .filter(plugin => plugin.name !== 'plugin-node-modules:resource' && plugin.name !== 'plugin-user-workspace')
  .map(plugin => plugin.provider({
    context: {
      outputDir: new URL(`file://${process.cwd()}/public`),
      projectDirectory: new URL(`file://${process.cwd()}/`),
      scratchDir: new URL(`file://${process.cwd()}/.greenwood/`)
    },
    config: {
      devServer: {}
    },
    graph: []
  }));

Based on some initial testing, we should at least be able to full support config and context, since i don't think the graph will be relevant in the context of loading custom JavaScript formats.

const config = await readAndMergeConfig();
const context = await initContext({ config });

const resourcePlugins = config.plugins
  .filter(plugin => plugin.type === 'resource')
  .filter(plugin => plugin.name !== 'plugin-node-modules:resource' && plugin.name !== 'plugin-user-workspace')
  .map(plugin => plugin.provider({
    context,
    config,
    graph: []
  }));
@thescientist13 thescientist13 added bug Something isn't working enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins CLI SSR labels Sep 2, 2024
@thescientist13 thescientist13 added this to the 1.0 milestone Sep 2, 2024
@thescientist13 thescientist13 self-assigned this Sep 2, 2024
@thescientist13 thescientist13 moved this from 🏗 In progress to 👀 In review in [Greenwood] Phase 9 - Standards and Conventions Sep 2, 2024
@thescientist13 thescientist13 changed the title provide fully synced compilation to custom loader script (and resource plugins) provide initialized compilation to custom loader script (and resource plugins) Sep 6, 2024
@thescientist13 thescientist13 mentioned this issue Sep 20, 2024
39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.6 bug Something isn't working CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins SSR v0.30.0
Projects
No open projects
1 participant