bimba-cli 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/serve.js +24 -14
package/package.json
CHANGED
package/serve.js
CHANGED
|
@@ -753,10 +753,22 @@ export function serve(entrypoint, flags) {
|
|
|
753
753
|
// node_modules: all smart resolution happens here.
|
|
754
754
|
// The import map just maps bare specifiers to /node_modules/pkg/ URLs.
|
|
755
755
|
// This block handles: entry point resolution, conditional exports
|
|
756
|
-
// (CJS→ESM), subpath resolution,
|
|
756
|
+
// (CJS→ESM), subpath resolution, .imba compilation.
|
|
757
757
|
if (pathname.startsWith('/node_modules/')) {
|
|
758
758
|
const filepath = '.' + pathname
|
|
759
759
|
|
|
760
|
+
// Serve a resolved file — compile .imba on the fly, pass JS through
|
|
761
|
+
const serveResolved = async (filePath) => {
|
|
762
|
+
if (filePath.endsWith('.imba')) {
|
|
763
|
+
const out = await compileFile(filePath)
|
|
764
|
+
if (out.errors?.length) return new Response(out.errors.map(e => e.message).join('\n'), { status: 500 })
|
|
765
|
+
return new Response(out.js, { headers: { 'Content-Type': 'application/javascript' } })
|
|
766
|
+
}
|
|
767
|
+
const f = Bun.file(filePath)
|
|
768
|
+
if (await f.exists()) return new Response(f, { headers: { 'Content-Type': 'application/javascript' } })
|
|
769
|
+
return null
|
|
770
|
+
}
|
|
771
|
+
|
|
760
772
|
// Resolve entry point for root package requests (/node_modules/pkg/ or /node_modules/pkg)
|
|
761
773
|
const parts = pathname.slice(1).split('/') // ['node_modules', 'pkg', ...]
|
|
762
774
|
const isScoped = parts[1]?.startsWith('@')
|
|
@@ -765,17 +777,13 @@ export function serve(entrypoint, flags) {
|
|
|
765
777
|
const isRootRequest = subParts.length === 0 || (subParts.length === 1 && subParts[0] === '')
|
|
766
778
|
|
|
767
779
|
if (isRootRequest) {
|
|
768
|
-
// Bare import: resolve entry point from package.json
|
|
769
780
|
const pkgDir = './' + parts.slice(0, pkgParts).join('/')
|
|
770
781
|
const depPkg = await readPkgJson(pkgDir)
|
|
771
782
|
if (depPkg) {
|
|
772
783
|
const entry = resolveEntry(depPkg)
|
|
773
784
|
if (entry) {
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
if (await file.exists()) return new Response(file, {
|
|
777
|
-
headers: { 'Content-Type': 'application/javascript' },
|
|
778
|
-
})
|
|
785
|
+
const resp = await serveResolved(path.join(pkgDir, entry))
|
|
786
|
+
if (resp) return resp
|
|
779
787
|
}
|
|
780
788
|
}
|
|
781
789
|
}
|
|
@@ -783,10 +791,8 @@ export function serve(entrypoint, flags) {
|
|
|
783
791
|
// Subpath: resolve via conditional exports (CJS→ESM)
|
|
784
792
|
const esmPath = await resolveNodeModuleESM(filepath)
|
|
785
793
|
if (esmPath) {
|
|
786
|
-
const
|
|
787
|
-
if (
|
|
788
|
-
headers: { 'Content-Type': 'application/javascript' },
|
|
789
|
-
})
|
|
794
|
+
const resp = await serveResolved(esmPath)
|
|
795
|
+
if (resp) return resp
|
|
790
796
|
}
|
|
791
797
|
}
|
|
792
798
|
|
|
@@ -796,11 +802,15 @@ export function serve(entrypoint, flags) {
|
|
|
796
802
|
const inRoot = Bun.file('.' + pathname)
|
|
797
803
|
if (await inRoot.exists()) return new Response(inRoot)
|
|
798
804
|
|
|
799
|
-
// Try
|
|
805
|
+
// Try extensions for extensionless paths (e.g. node_modules imports)
|
|
800
806
|
const lastSegment = pathname.split('/').pop()
|
|
801
807
|
if (!lastSegment.includes('.')) {
|
|
802
|
-
//
|
|
803
|
-
|
|
808
|
+
// Try .imba first (compile on the fly), then .js/.mjs
|
|
809
|
+
const imbaPath = '.' + pathname + '.imba'
|
|
810
|
+
if (existsSync(imbaPath)) {
|
|
811
|
+
const out = await compileFile(imbaPath)
|
|
812
|
+
if (!out.errors?.length) return new Response(out.js, { headers: { 'Content-Type': 'application/javascript' } })
|
|
813
|
+
}
|
|
804
814
|
for (const ext of ['.js', '.mjs']) {
|
|
805
815
|
const withExt = Bun.file('.' + pathname + ext)
|
|
806
816
|
if (await withExt.exists()) return new Response(withExt, {
|