Skip to content

Commit

Permalink
chore: run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Oct 6, 2021
1 parent 102451e commit 3b6768c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { transformRequest } from '../server/transformRequest'
// This is a workaround since typescript compiles dynamic imports to `require`.
// Thankfully, when `typescript@4.5.0` lands it won't and this can be removed!
// See #5197 for notes
const nativeImport = eval('u => import(u)');
const nativeImport = eval('u => import(u)')

interface SSRContext {
global: NodeJS.Global
Expand Down Expand Up @@ -97,11 +97,7 @@ async function instantiateModule(

const ssrImport = async (dep: string) => {
if (dep[0] !== '.' && dep[0] !== '/') {
return nodeImport(
dep,
mod.file,
server.config
)
return nodeImport(dep, mod.file, server.config)
}
dep = unwrapId(dep)
if (!isCircular(dep) && !pendingImports.get(dep)?.some(isCircular)) {
Expand Down Expand Up @@ -183,32 +179,36 @@ async function instantiateModule(
async function nodeImport(
id: string,
importer: string | null,
config: ViteDevServer['config'],
config: ViteDevServer['config']
) {
let url: string
// `resolve` doesn't handle `node:` builtins, so handle them directly
if (id.startsWith('node:') || isBuiltin(id)) {
url = id
} else {
url = pathToFileURL(resolve(id, importer, config.root, !!config.resolve.preserveSymlinks)).toString()
url = pathToFileURL(
resolve(id, importer, config.root, !!config.resolve.preserveSymlinks)
).toString()
}
const mod = await nativeImport(url);
return proxyESM(id, mod);
const mod = await nativeImport(url)
return proxyESM(id, mod)
}

// rollup-style default import interop for cjs
function proxyESM(id: string, mod: any) {
return new Proxy(mod, {
get(mod, prop) {
if (prop in mod) {
return mod[prop];
return mod[prop]
}
// commonjs interop: module whose exports are not statically analyzable
if (isObject(mod.default) && prop in mod.default) {
return mod.default[prop]
}
// throw an error like ESM import does
throw new SyntaxError(`The requested module '${id}' does not provide an export named '${prop.toString()}'`)
throw new SyntaxError(
`The requested module '${id}' does not provide an export named '${prop.toString()}'`
)
}
})
}
Expand Down

0 comments on commit 3b6768c

Please sign in to comment.