Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
feat: auto transform esm modules that are not correctly configured fo…
Browse files Browse the repository at this point in the history
…r native Node esm
  • Loading branch information
Akryum committed Dec 10, 2021
1 parent c5f612b commit 397cf8f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/peeky-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"happy-dom": "^2.24.4",
"lodash": "^4.17.21",
"memfs": "^3.2.0",
"mlly": "^0.3.15",
"pragma": "^1.0.0",
"reactive-fs": "^0.4.1",
"shortid": "^2.2.16",
Expand Down
11 changes: 6 additions & 5 deletions packages/peeky-runner/src/runtime/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ViteDevServer, InlineConfig, createServer, mergeConfig } from 'vite'
import chalk from 'chalk'
import shortid from 'shortid'
import isEqual from 'lodash/isEqual.js'
import { isValidNodeImport } from 'mlly'
import type { ModuleFilterOption } from '@peeky/config'
import { slash } from '@peeky/utils'
import { moduleCache } from './module-cache.js'
Expand Down Expand Up @@ -126,7 +127,7 @@ export async function executeWithVite (file: string, executionContext: Record<st
* @param executionContext Globals to pass to the execution VM
* @returns Executed module exports
*/
function cachedRequest (rawId: string, callstack: string[], deps: Set<string>, executionContext: Record<string, any>, root: string): Promise<any> {
async function cachedRequest (rawId: string, callstack: string[], deps: Set<string>, executionContext: Record<string, any>, root: string): Promise<any> {
if (builtinModules.includes(rawId)) {
return import(rawId)
}
Expand All @@ -142,14 +143,14 @@ function cachedRequest (rawId: string, callstack: string[], deps: Set<string>, e
return Promise.resolve(stubbedRequests[id])
}

if (shouldExternalize(realPath)) {
return import(realPath)
}

if (moduleCache.has(realPath)) {
return moduleCache.get(realPath)
}

if (shouldExternalize(realPath) && (await isValidNodeImport(realPath))) {
return import(realPath)
}

const promise = rawRequest(realPath, realPath, callstack, deps, executionContext, root)
moduleCache.set(realPath, promise)
return promise
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 397cf8f

Please sign in to comment.