11ty / webc

Single File Web Components
MIT License
1.33k stars 38 forks source link

Different expectations for paths provided to `defineComponents` and `setInputPath` #92

Open okmanideep opened 1 year ago

okmanideep commented 1 year ago

⚠️Disclaimer: I am a JS Noob

defineComponents passes the glob path directly to fast-glob which expects normalized unixy path setInputPath accepts windows paths just fine (it normalizes internally)

Both seem to be accepting paths which are relative to the current working directory and not relative to the script file where WebC().functionName() is being invoked. Not sure what the standards are in the JS ecosystem regarding this. I am writing code like the following to get my code to work.

// src/server/page-renderer-webc.js
import * as url from 'url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

let pageInputPath = path.resolve(__dirname, 'page.webc') // = "full/path/to/src/server/page.webc"
let webC = new WebC({file: pageInputPath})

Is this normal?

zachleat commented 1 year ago

Honestly, I’m not sure! I do think the way you’ve proposed is more ergonomic to have in the core library!