mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
feat(bundler): add Aliases option for spec import resolution
Specs import from "@uatu/spec"; the bundler maps that to the vendored pkg/spec-api/src/index.ts via esbuild's Alias map.
This commit is contained in:
1 parent
8c6a3171d7
commit
7aa75f3d9f
2 files changed
+27
No files matched your search
@@ -14,6 +14,7 @@ import (
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
EntryFile string
|
EntryFile string
|
||||||
Defines map[string]string
|
Defines map[string]string
|
||||||
|
Aliases map[string]string
|
||||||
Sourcemap bool
|
Sourcemap bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ func Bundle(options Options) (Result, error) {
|
|||||||
Target: esbuild.ES2020,
|
Target: esbuild.ES2020,
|
||||||
Platform: esbuild.PlatformNeutral,
|
Platform: esbuild.PlatformNeutral,
|
||||||
Define: defines,
|
Define: defines,
|
||||||
|
Alias: options.Aliases,
|
||||||
Sourcemap: sourcemap,
|
Sourcemap: sourcemap,
|
||||||
Write: false,
|
Write: false,
|
||||||
LogLevel: esbuild.LogLevelSilent,
|
LogLevel: esbuild.LogLevelSilent,
|
||||||
|
|||||||
@@ -164,3 +164,28 @@ func TestBundle_SourcemapInlinedWhenRequested(t *testing.T) {
|
|||||||
t.Errorf("expected inline sourcemap")
|
t.Errorf("expected inline sourcemap")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBundle_AliasResolvesPackageImport(t *testing.T) {
|
||||||
|
directory := t.TempDir()
|
||||||
|
aliasTarget := filepath.Join(directory, "aliased.ts")
|
||||||
|
entryPath := filepath.Join(directory, "entry.ts")
|
||||||
|
if err := os.WriteFile(aliasTarget, []byte(`export const aliasMagic = "alias-resolved";`), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(entryPath, []byte(`
|
||||||
|
import { aliasMagic } from "@example/aliased";
|
||||||
|
console.log(aliasMagic);
|
||||||
|
`), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
result, err := Bundle(Options{
|
||||||
|
EntryFile: entryPath,
|
||||||
|
Aliases: map[string]string{"@example/aliased": aliasTarget},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !strings.Contains(string(result.JavaScript), "alias-resolved") {
|
||||||
|
t.Errorf("alias target should be inlined: %s", result.JavaScript)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user