@@ -4,7 +4,7 @@ import { importSnippet } from "./import-snippet"
44import { resolveFilePath } from "lib/runner/resolveFilePath"
55import { resolveNodeModule } from "lib/utils/resolve-node-module"
66import { importNodeModule } from "./import-node-module"
7- import { importNpmPackage } from "./import-npm-package"
7+ import { importNpmPackageFromCdn } from "./import-npm-package-from-cdn "
88import {
99 getTsConfig ,
1010 matchesTsconfigPathPattern ,
@@ -24,7 +24,6 @@ export async function importEvalPath(
2424 depth = 0 ,
2525 opts : {
2626 cwd ?: string
27- fromJsDelivr ?: boolean
2827 } = { } ,
2928) {
3029 debug ( "importEvalPath called with:" , {
@@ -97,12 +96,8 @@ export async function importEvalPath(
9796 `Cannot find module "${ pkgName } ". The package is not available in the local environment.\n\n${ ctx . logger . stringifyLogs ( ) } ` ,
9897 )
9998 }
100- ctx . logger . info ( `importNpmPackage("${ pkgName } ")` )
101- // /npm/ paths are always transitive dependencies from jsDelivr
102- await importNpmPackage (
103- { importName : pkgName , depth, fromJsDelivr : true } ,
104- ctx ,
105- )
99+ ctx . logger . info ( `importNpmPackageFromCdn("${ pkgName } ")` )
100+ await importNpmPackageFromCdn ( { importName : pkgName , depth } , ctx )
106101 const pkg = preSuppliedImports [ pkgName ]
107102 if ( pkg ) {
108103 preSuppliedImports [ importName ] = pkg
@@ -198,41 +193,38 @@ export async function importEvalPath(
198193 }
199194
200195 if ( ! importName . startsWith ( "." ) && ! importName . startsWith ( "/" ) ) {
201- // Validation steps for node modules (before jsDelivr fallback)
202- if ( ! opts . fromJsDelivr ) {
203- // Step 1: Check if package is declared in package.json
204- if ( ! isPackageDeclaredInPackageJson ( importName , ctx . fsMap ) ) {
205- throw new Error (
206- `Node module imported but not in package.json "${ importName } "\n\n${ ctx . logger . stringifyLogs ( ) } ` ,
207- )
208- }
196+ // Step 1: Check if package is declared in package.json
197+ if ( ! isPackageDeclaredInPackageJson ( importName , ctx . fsMap ) ) {
198+ throw new Error (
199+ `Node module imported but not in package.json "${ importName } "\n\n${ ctx . logger . stringifyLogs ( ) } ` ,
200+ )
201+ }
209202
210- // Step 2: Check if node_modules directory exists (only if not found locally yet)
211- // Only validate if CDN loading is disabled (i.e., no fallback to jsDelivr available)
212- const nodeModuleDir = getNodeModuleDirectory ( importName , ctx . fsMap )
213- if ( ! nodeModuleDir && disableCdnLoading ) {
203+ // Step 2: Check if node_modules directory exists (only if not found locally yet)
204+ // Only validate if CDN loading is disabled (i.e., no fallback to jsDelivr available)
205+ const nodeModuleDir = getNodeModuleDirectory ( importName , ctx . fsMap )
206+ if ( ! nodeModuleDir && disableCdnLoading ) {
207+ throw new Error (
208+ `Node module "${ importName } " has no files in the node_modules directory\n\n${ ctx . logger . stringifyLogs ( ) } ` ,
209+ )
210+ }
211+
212+ // Step 3: Check if main entrypoint is a TypeScript file (only if dir exists)
213+ if ( nodeModuleDir ) {
214+ const entrypoint = getPackageJsonEntrypoint ( importName , ctx . fsMap )
215+ if ( isTypeScriptEntrypoint ( entrypoint ) ) {
214216 throw new Error (
215- `Node module "${ importName } " has no files in the node_modules directory \n\n${ ctx . logger . stringifyLogs ( ) } ` ,
217+ `Node module "${ importName } " has a typescript entrypoint that is unsupported \n\n${ ctx . logger . stringifyLogs ( ) } ` ,
216218 )
217219 }
218220
219- // Step 3: Check if main entrypoint is a TypeScript file (only if dir exists)
220- if ( nodeModuleDir ) {
221- const entrypoint = getPackageJsonEntrypoint ( importName , ctx . fsMap )
222- if ( isTypeScriptEntrypoint ( entrypoint ) ) {
221+ // Step 4: Check if dist directory is empty when main points to dist
222+ if ( entrypoint ?. startsWith ( "dist/" ) ) {
223+ if ( isDistDirEmpty ( importName , ctx . fsMap ) ) {
223224 throw new Error (
224- `Node module "${ importName } " has a typescript entrypoint that is unsupported \n\n${ ctx . logger . stringifyLogs ( ) } ` ,
225+ `Node module "${ importName } " has no files in dist, did you forget to transpile? \n\n${ ctx . logger . stringifyLogs ( ) } ` ,
225226 )
226227 }
227-
228- // Step 4: Check if dist directory is empty when main points to dist
229- if ( entrypoint && entrypoint . startsWith ( "dist/" ) ) {
230- if ( isDistDirEmpty ( importName , ctx . fsMap ) ) {
231- throw new Error (
232- `Node module "${ importName } " has no files in dist, did you forget to transpile?\n\n${ ctx . logger . stringifyLogs ( ) } ` ,
233- )
234- }
235- }
236228 }
237229 }
238230
@@ -241,11 +233,8 @@ export async function importEvalPath(
241233 `Cannot find module "${ importName } ". The package is not available in the local environment.\n\n${ ctx . logger . stringifyLogs ( ) } ` ,
242234 )
243235 }
244- ctx . logger . info ( `importNpmPackage("${ importName } ")` )
245- return importNpmPackage (
246- { importName, depth, fromJsDelivr : opts . fromJsDelivr } ,
247- ctx ,
248- )
236+ ctx . logger . info ( `importNpmPackageFromCdn("${ importName } ")` )
237+ return importNpmPackageFromCdn ( { importName, depth } , ctx )
249238 }
250239
251240 throw new Error (
0 commit comments