Skip to content

Commit

Permalink
squash! code to test cloudflare/workerd#2131
Browse files Browse the repository at this point in the history
update docs
  • Loading branch information
IgorMinar committed May 20, 2024
1 parent 8e1f76e commit 806211a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@ const mf = new Miniflare({
throw new Error("no specifier provided");
}

// hacky way to resolve url paths - this is good enough for this demo, but likely not good enough for production use
// hacky way to resolve url paths - this is good enough for this demo,
// but not good for production use. In Vite, we'll delegate to Vite's dev server instead
const resolvedSpecifier = rawSpecifier.startsWith('.') ?

// relative imports must be resolved against the referrer, e.g. `./foo.js` or `../
new URL(rawSpecifier, `https://hostname${referrer}`).pathname :

rawSpecifier.startsWith('/') ?

// this must be an absolute import to a user-land module, e.g. `/foo/hello.js`
// TODO: or also package imports in case node_modules: prefix is not supported by workerd.
// this must be an absolute, fully resolved import, e.g. `/foo.js` or `/_vite_external_/...`
rawSpecifier :

// let's check if this is the original bare import or an internal redirect to satisfy it
specifier === modules[`/_vite_bare_/${rawSpecifier}`].redirect ?
// this is an internal redirect from /_vite_bare_/bar to /_vite_bare_/bar/index.js
// this is an internal redirect from /_vite_bare_/bar to
// /_vite_externals_/Users/Dario/project/my-project/node_modules/bar/index.js
specifier :
// this is a package import, resolve it by prefixing the specifier with '/_vite_bare_/`
`/_vite_bare_/${rawSpecifier}`;
Expand Down

0 comments on commit 806211a

Please sign in to comment.