@babylonjs/lite-compat 0.0.1-preview.54961

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.
@@ -0,0 +1,33 @@
1
+ function mapBabylonImport(source) {
2
+ if (/^@babylonjs\/(core|loaders)(\/|$)/.test(source)) {
3
+ return "core";
4
+ }
5
+ if (/^@babylonjs\/addons(\/|$)/.test(source)) {
6
+ return "addons";
7
+ }
8
+ if (/^@recast-navigation\/(core|generators)(\/|$)/.test(source)) {
9
+ return "recast";
10
+ }
11
+ if (/^@babylonjs\/materials(\/|$)/.test(source)) {
12
+ return "materials";
13
+ }
14
+ return null;
15
+ }
16
+ const COMPAT_SPECIFIER = {
17
+ core: "@babylonjs/lite-compat",
18
+ addons: "@babylonjs/lite-compat/navigation",
19
+ recast: "@babylonjs/lite-compat/recast-shim",
20
+ // `GridMaterial` is re-exported from the root barrel, so the materials
21
+ // redirect folds into the main entry rather than carrying its own subpath.
22
+ materials: "@babylonjs/lite-compat"
23
+ };
24
+ function resolveCompatSpecifier(source) {
25
+ const target = mapBabylonImport(source);
26
+ return target ? COMPAT_SPECIFIER[target] : null;
27
+ }
28
+ const COMPAT_SOURCE_FILTER = /^@babylonjs\/|^@recast-navigation\//;
29
+ export {
30
+ COMPAT_SOURCE_FILTER as C,
31
+ resolveCompatSpecifier as r
32
+ };
33
+ //# sourceMappingURL=bundler-resolve-0pEkTP9X.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundler-resolve-0pEkTP9X.js","sources":["../src/bundler-resolve.ts"],"sourcesContent":["/**\n * Shared Babylon.js → `@babylonjs/lite-compat` import-mapping table.\n *\n * This is the single source of truth used by every bundler adapter\n * ([vite.ts](vite.ts), [rollup.ts](rollup.ts), [webpack.ts](webpack.ts),\n * [esbuild.ts](esbuild.ts)) and by the lab's side-by-side dev harness\n * ([../../../lab/vite.config.ts](../../../lab/vite.config.ts)), so the redirect\n * rules can never drift between them. It is a pure, dependency-free mapping,\n * which keeps it trivially unit-testable.\n */\n\n/** The compat module category a Babylon.js import is redirected onto. */\nexport type CompatTarget = \"core\" | \"addons\" | \"recast\" | \"materials\";\n\n/**\n * Map a Babylon.js (or Recast) import specifier onto the compat module category\n * that replaces it, or `null` when the specifier is not remapped.\n *\n * - `@babylonjs/core` / `@babylonjs/loaders` — bare, deep subpaths, and\n * side-effect-only imports → `\"core\"` (the compat barrel).\n * - `@babylonjs/addons` — bare or any subpath → `\"addons\"` (compat navigation\n * wrapper over Babylon Lite's native Recast API; navigation is the only addon\n * currently implemented).\n * - `@recast-navigation/core` / `@recast-navigation/generators` → `\"recast\"`\n * (no-op shim; Lite loads its own Recast wasm).\n * - `@babylonjs/materials` — bare or any subpath → `\"materials\"` (the compat\n * barrel, which re-exports `GridMaterial`; grid is the only material currently\n * implemented).\n */\nexport function mapBabylonImport(source: string): CompatTarget | null {\n if (/^@babylonjs\\/(core|loaders)(\\/|$)/.test(source)) {\n return \"core\";\n }\n if (/^@babylonjs\\/addons(\\/|$)/.test(source)) {\n return \"addons\";\n }\n if (/^@recast-navigation\\/(core|generators)(\\/|$)/.test(source)) {\n return \"recast\";\n }\n if (/^@babylonjs\\/materials(\\/|$)/.test(source)) {\n return \"materials\";\n }\n return null;\n}\n\n/**\n * Public `@babylonjs/lite-compat` specifier each redirect category resolves to.\n * Returning bare specifiers (rather than absolute paths) defers resolution to\n * the package's own `exports` map, so the adapters work whether the package is\n * consumed from source (this monorepo) or from its published `dist` build, and\n * across every bundler's native resolver.\n */\nconst COMPAT_SPECIFIER: Record<CompatTarget, string> = {\n core: \"@babylonjs/lite-compat\",\n addons: \"@babylonjs/lite-compat/navigation\",\n recast: \"@babylonjs/lite-compat/recast-shim\",\n // `GridMaterial` is re-exported from the root barrel, so the materials\n // redirect folds into the main entry rather than carrying its own subpath.\n materials: \"@babylonjs/lite-compat\",\n};\n\n/**\n * Resolve a Babylon.js (or Recast) import specifier to the bare\n * `@babylonjs/lite-compat` specifier that replaces it, or `null` when the\n * specifier is not remapped. Each bundler adapter feeds the returned specifier\n * back into that bundler's own resolver to obtain the final on-disk module.\n */\nexport function resolveCompatSpecifier(source: string): string | null {\n const target = mapBabylonImport(source);\n return target ? COMPAT_SPECIFIER[target] : null;\n}\n\n/**\n * Broad prefix matcher for the specifiers any adapter might remap. Bundlers that\n * filter by `RegExp` (Webpack, esbuild) use this to narrow the hook to plausible\n * candidates; `resolveCompatSpecifier` then makes the precise decision (and\n * returns `null` for non-matches such as `@babylonjs/gui`).\n */\nexport const COMPAT_SOURCE_FILTER = /^@babylonjs\\/|^@recast-navigation\\//;\n"],"names":[],"mappings":"AA6BO,SAAS,iBAAiB,QAAqC;AAClE,MAAI,oCAAoC,KAAK,MAAM,GAAG;AAClD,WAAO;AAAA,EACX;AACA,MAAI,4BAA4B,KAAK,MAAM,GAAG;AAC1C,WAAO;AAAA,EACX;AACA,MAAI,+CAA+C,KAAK,MAAM,GAAG;AAC7D,WAAO;AAAA,EACX;AACA,MAAI,+BAA+B,KAAK,MAAM,GAAG;AAC7C,WAAO;AAAA,EACX;AACA,SAAO;AACX;AASA,MAAM,mBAAiD;AAAA,EACnD,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA;AAAA;AAAA,EAGR,WAAW;AACf;AAQO,SAAS,uBAAuB,QAA+B;AAClE,QAAM,SAAS,iBAAiB,MAAM;AACtC,SAAO,SAAS,iBAAiB,MAAM,IAAI;AAC/C;AAQO,MAAM,uBAAuB;"}
package/esbuild.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ declare interface EsbuildOnResolveResult {
2
+ path?: string;
3
+ external?: boolean;
4
+ namespace?: string;
5
+ errors?: unknown[];
6
+ }
7
+
8
+ declare interface EsbuildPlugin {
9
+ name: string;
10
+ setup(build: EsbuildPluginBuild): void;
11
+ }
12
+
13
+ declare interface EsbuildPluginBuild {
14
+ onResolve(options: {
15
+ filter: RegExp;
16
+ }, callback: (args: EsbuildResolveArgs) => Promise<EsbuildOnResolveResult | null>): void;
17
+ resolve(path: string, options: {
18
+ importer?: string;
19
+ namespace?: string;
20
+ resolveDir?: string;
21
+ kind: string;
22
+ }): Promise<EsbuildResolveResult>;
23
+ }
24
+
25
+ /**
26
+ * A reusable esbuild plugin that lets an existing Babylon.js project run on
27
+ * Babylon Lite **without changing its import statements**. It rewrites
28
+ * `@babylonjs/core`, `@babylonjs/loaders`, `@babylonjs/addons`,
29
+ * `@babylonjs/materials`, and `@recast-navigation/*` imports
30
+ * onto the matching `@babylonjs/lite-compat` modules at resolve time.
31
+ *
32
+ * Usage (`esbuild` build script):
33
+ *
34
+ * ```js
35
+ * import { build } from "esbuild";
36
+ * import { liteCompat } from "@babylonjs/lite-compat/esbuild";
37
+ *
38
+ * await build({
39
+ * plugins: [liteCompat()],
40
+ * });
41
+ * ```
42
+ *
43
+ * The redirect table is shared with every other adapter via
44
+ * [bundler-resolve.ts](bundler-resolve.ts).
45
+ */
46
+ /** Minimal structural types for the slice of the esbuild plugin API used here. */
47
+ declare interface EsbuildResolveArgs {
48
+ path: string;
49
+ importer: string;
50
+ namespace: string;
51
+ resolveDir: string;
52
+ kind: string;
53
+ }
54
+
55
+ declare interface EsbuildResolveResult {
56
+ path: string;
57
+ external: boolean;
58
+ namespace: string;
59
+ errors: unknown[];
60
+ }
61
+
62
+ /**
63
+ * Create the Babylon Lite compat esbuild plugin. Add it to your build's
64
+ * `plugins` array and keep your Babylon.js imports exactly as they are.
65
+ */
66
+ export declare function liteCompat(): EsbuildPlugin;
67
+
68
+ export { }
package/esbuild.js ADDED
@@ -0,0 +1,27 @@
1
+ import { C as COMPAT_SOURCE_FILTER, r as resolveCompatSpecifier } from "./bundler-resolve-0pEkTP9X.js";
2
+ function liteCompat() {
3
+ return {
4
+ name: "babylonjs-lite-compat",
5
+ setup(build) {
6
+ build.onResolve({ filter: COMPAT_SOURCE_FILTER }, async (args) => {
7
+ const specifier = resolveCompatSpecifier(args.path);
8
+ if (!specifier) {
9
+ return null;
10
+ }
11
+ const resolved = await build.resolve(specifier, {
12
+ importer: args.importer,
13
+ resolveDir: args.resolveDir,
14
+ kind: args.kind
15
+ });
16
+ if (resolved.errors.length > 0) {
17
+ return { errors: resolved.errors };
18
+ }
19
+ return { path: resolved.path, external: resolved.external, namespace: resolved.namespace };
20
+ });
21
+ }
22
+ };
23
+ }
24
+ export {
25
+ liteCompat
26
+ };
27
+ //# sourceMappingURL=esbuild.js.map
package/esbuild.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild.js","sources":["../src/esbuild.ts"],"sourcesContent":["/**\n * A reusable esbuild plugin that lets an existing Babylon.js project run on\n * Babylon Lite **without changing its import statements**. It rewrites\n * `@babylonjs/core`, `@babylonjs/loaders`, `@babylonjs/addons`,\n * `@babylonjs/materials`, and `@recast-navigation/*` imports\n * onto the matching `@babylonjs/lite-compat` modules at resolve time.\n *\n * Usage (`esbuild` build script):\n *\n * ```js\n * import { build } from \"esbuild\";\n * import { liteCompat } from \"@babylonjs/lite-compat/esbuild\";\n *\n * await build({\n * plugins: [liteCompat()],\n * });\n * ```\n *\n * The redirect table is shared with every other adapter via\n * [bundler-resolve.ts](bundler-resolve.ts).\n */\n\nimport { resolveCompatSpecifier, COMPAT_SOURCE_FILTER } from \"./bundler-resolve.js\";\n\n/** Minimal structural types for the slice of the esbuild plugin API used here. */\ninterface EsbuildResolveArgs {\n path: string;\n importer: string;\n namespace: string;\n resolveDir: string;\n kind: string;\n}\n\ninterface EsbuildResolveResult {\n path: string;\n external: boolean;\n namespace: string;\n errors: unknown[];\n}\n\ninterface EsbuildOnResolveResult {\n path?: string;\n external?: boolean;\n namespace?: string;\n errors?: unknown[];\n}\n\ninterface EsbuildPluginBuild {\n onResolve(options: { filter: RegExp }, callback: (args: EsbuildResolveArgs) => Promise<EsbuildOnResolveResult | null>): void;\n resolve(path: string, options: { importer?: string; namespace?: string; resolveDir?: string; kind: string }): Promise<EsbuildResolveResult>;\n}\n\ninterface EsbuildPlugin {\n name: string;\n setup(build: EsbuildPluginBuild): void;\n}\n\n/**\n * Create the Babylon Lite compat esbuild plugin. Add it to your build's\n * `plugins` array and keep your Babylon.js imports exactly as they are.\n */\nexport function liteCompat(): EsbuildPlugin {\n return {\n name: \"babylonjs-lite-compat\",\n setup(build) {\n build.onResolve({ filter: COMPAT_SOURCE_FILTER }, async (args) => {\n const specifier = resolveCompatSpecifier(args.path);\n if (!specifier) {\n // Not a remapped specifier (e.g. `@babylonjs/gui`) — let esbuild\n // resolve it normally.\n return null;\n }\n // Re-run esbuild's own resolver on the compat specifier so the\n // package's `exports` map (source vs. dist) is honored. The result\n // does not re-match (`@babylonjs/lite-compat` maps to nothing), so\n // there is no resolution loop.\n const resolved = await build.resolve(specifier, {\n importer: args.importer,\n resolveDir: args.resolveDir,\n kind: args.kind,\n });\n if (resolved.errors.length > 0) {\n return { errors: resolved.errors };\n }\n return { path: resolved.path, external: resolved.external, namespace: resolved.namespace };\n });\n },\n };\n}\n"],"names":[],"mappings":";AA6DO,SAAS,aAA4B;AACxC,SAAO;AAAA,IACH,MAAM;AAAA,IACN,MAAM,OAAO;AACT,YAAM,UAAU,EAAE,QAAQ,qBAAA,GAAwB,OAAO,SAAS;AAC9D,cAAM,YAAY,uBAAuB,KAAK,IAAI;AAClD,YAAI,CAAC,WAAW;AAGZ,iBAAO;AAAA,QACX;AAKA,cAAM,WAAW,MAAM,MAAM,QAAQ,WAAW;AAAA,UAC5C,UAAU,KAAK;AAAA,UACf,YAAY,KAAK;AAAA,UACjB,MAAM,KAAK;AAAA,QAAA,CACd;AACD,YAAI,SAAS,OAAO,SAAS,GAAG;AAC5B,iBAAO,EAAE,QAAQ,SAAS,OAAA;AAAA,QAC9B;AACA,eAAO,EAAE,MAAM,SAAS,MAAM,UAAU,SAAS,UAAU,WAAW,SAAS,UAAA;AAAA,MACnF,CAAC;AAAA,IACL;AAAA,EAAA;AAER;"}