@dxos/app-framework 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef
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/dist/lib/browser/{capability-BBBBAPDI.mjs → capability-Q5XRXRD2.mjs} +10 -10
- package/dist/lib/browser/{capability-OP63CD5N.mjs → capability-V7LR4LQN.mjs} +11 -11
- package/dist/lib/browser/capability-V7LR4LQN.mjs.map +7 -0
- package/dist/lib/browser/{chunk-T3Y4AEKX.mjs → chunk-23D4SJUE.mjs} +3 -3
- package/dist/lib/browser/{chunk-T3Y4AEKX.mjs.map → chunk-23D4SJUE.mjs.map} +1 -1
- package/dist/lib/browser/{chunk-2CKCJ6PN.mjs → chunk-3JWJXGLK.mjs} +1 -1
- package/dist/lib/browser/{chunk-2CKCJ6PN.mjs.map → chunk-3JWJXGLK.mjs.map} +1 -1
- package/dist/lib/browser/{chunk-GX4TUNM6.mjs → chunk-3ZS2A3DN.mjs} +170 -226
- package/dist/lib/browser/chunk-3ZS2A3DN.mjs.map +7 -0
- package/dist/lib/browser/{chunk-I34GF4NG.mjs → chunk-45CHLTBV.mjs} +2 -2
- package/dist/lib/browser/chunk-5LAIGWLU.mjs +467 -0
- package/dist/lib/browser/chunk-5LAIGWLU.mjs.map +7 -0
- package/dist/lib/browser/{chunk-QSXYHXCE.mjs → chunk-66IXTIVK.mjs} +1 -1
- package/dist/lib/browser/{chunk-QSXYHXCE.mjs.map → chunk-66IXTIVK.mjs.map} +2 -2
- package/dist/lib/browser/{chunk-TGX63LTL.mjs → chunk-FJ4765WW.mjs} +1 -1
- package/dist/lib/browser/{chunk-TGX63LTL.mjs.map → chunk-FJ4765WW.mjs.map} +2 -2
- package/dist/lib/browser/chunk-G7SDBRKH.mjs +1 -0
- package/dist/lib/browser/chunk-JXCBZSBJ.mjs +372 -0
- package/dist/lib/browser/chunk-JXCBZSBJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-MX5DKEJH.mjs +584 -0
- package/dist/lib/browser/chunk-MX5DKEJH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-JKWMHZP6.mjs → chunk-WBHCSOBW.mjs} +2 -2
- package/dist/lib/browser/chunk-WBHCSOBW.mjs.map +7 -0
- package/dist/lib/browser/{chunk-FU4GAFUQ.mjs → chunk-Z55LVAGN.mjs} +80 -15
- package/dist/lib/browser/chunk-Z55LVAGN.mjs.map +7 -0
- package/dist/lib/browser/{chunk-F7FW2RK2.mjs → chunk-ZGJAZSNE.mjs} +7 -32
- package/dist/lib/browser/chunk-ZGJAZSNE.mjs.map +7 -0
- package/dist/lib/browser/cli/index.mjs +11 -27
- package/dist/lib/browser/cli/index.mjs.map +2 -2
- package/dist/lib/browser/common/activation-events.mjs +7 -7
- package/dist/lib/browser/common/capabilities.mjs +7 -7
- package/dist/lib/browser/core/activation-event.mjs +1 -1
- package/dist/lib/browser/core/capability.mjs +1 -1
- package/dist/lib/browser/core/plugin-manager.mjs +6 -4
- package/dist/lib/browser/core/plugin.mjs +10 -2
- package/dist/lib/browser/core/url-loader.mjs +13 -5
- package/dist/lib/browser/index.mjs +22 -18
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{invoker-capability-H5PPENOC.mjs → invoker-capability-LNX4CGIV.mjs} +12 -11
- package/dist/lib/browser/invoker-capability-LNX4CGIV.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +144 -27
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/browser/testing/react.mjs +78 -0
- package/dist/lib/browser/testing/react.mjs.map +7 -0
- package/dist/lib/browser/ui/index.mjs +18 -14
- package/dist/lib/node-esm/{capability-AWBEMRYR.mjs → capability-EW5GJCI6.mjs} +10 -10
- package/dist/lib/node-esm/{capability-WFEG6CIZ.mjs → capability-YKBMMD53.mjs} +11 -11
- package/dist/lib/node-esm/capability-YKBMMD53.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-FKE4Z3D6.mjs → chunk-37Z53PXZ.mjs} +1 -1
- package/dist/lib/node-esm/{chunk-FKE4Z3D6.mjs.map → chunk-37Z53PXZ.mjs.map} +2 -2
- package/dist/lib/node-esm/{chunk-WZCSOX5Q.mjs → chunk-6XW6LET6.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-URWHJQT2.mjs → chunk-D347W3KO.mjs} +7 -32
- package/dist/lib/node-esm/chunk-D347W3KO.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-D5PO2WXX.mjs +373 -0
- package/dist/lib/node-esm/chunk-D5PO2WXX.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ULUEXB7Q.mjs → chunk-HTBJU5FX.mjs} +80 -15
- package/dist/lib/node-esm/chunk-HTBJU5FX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KM2F6GH6.mjs +468 -0
- package/dist/lib/node-esm/chunk-KM2F6GH6.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-EL3R25OQ.mjs → chunk-OZ7DZA5Z.mjs} +1 -1
- package/dist/lib/node-esm/{chunk-BCEOLX47.mjs → chunk-Q7XBFII4.mjs} +170 -226
- package/dist/lib/node-esm/chunk-Q7XBFII4.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-VKHGNEDB.mjs → chunk-SBS2YMPT.mjs} +3 -3
- package/dist/lib/node-esm/{chunk-VKHGNEDB.mjs.map → chunk-SBS2YMPT.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-42KBWDE4.mjs → chunk-SDJ4B2LU.mjs} +1 -1
- package/dist/lib/node-esm/{chunk-42KBWDE4.mjs.map → chunk-SDJ4B2LU.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-G3RTFSNG.mjs → chunk-WFSRZKBP.mjs} +2 -2
- package/dist/lib/node-esm/chunk-WFSRZKBP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WKTLE7MG.mjs +585 -0
- package/dist/lib/node-esm/chunk-WKTLE7MG.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZZ7CKK6W.mjs → chunk-XOCUANHO.mjs} +1 -1
- package/dist/lib/node-esm/{chunk-ZZ7CKK6W.mjs.map → chunk-XOCUANHO.mjs.map} +2 -2
- package/dist/lib/node-esm/cli/index.mjs +11 -27
- package/dist/lib/node-esm/cli/index.mjs.map +2 -2
- package/dist/lib/node-esm/common/activation-events.mjs +7 -7
- package/dist/lib/node-esm/common/capabilities.mjs +7 -7
- package/dist/lib/node-esm/core/activation-event.mjs +1 -1
- package/dist/lib/node-esm/core/capability.mjs +1 -1
- package/dist/lib/node-esm/core/plugin-manager.mjs +6 -4
- package/dist/lib/node-esm/core/plugin.mjs +10 -2
- package/dist/lib/node-esm/core/url-loader.mjs +13 -5
- package/dist/lib/node-esm/index.mjs +22 -18
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{invoker-capability-S3ZA527J.mjs → invoker-capability-O4T5PHLA.mjs} +12 -11
- package/dist/lib/node-esm/invoker-capability-O4T5PHLA.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +144 -27
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/testing/react.mjs +79 -0
- package/dist/lib/node-esm/testing/react.mjs.map +7 -0
- package/dist/lib/node-esm/ui/index.mjs +18 -14
- package/dist/plugin/node-esm/index.mjs +480 -32
- package/dist/plugin/node-esm/index.mjs.map +4 -4
- package/dist/plugin/node-esm/meta.json +1 -1
- package/dist/types/src/common/capabilities.d.ts +2 -1
- package/dist/types/src/common/capabilities.d.ts.map +1 -1
- package/dist/types/src/common/operations.d.ts +1 -1
- package/dist/types/src/common/operations.d.ts.map +1 -1
- package/dist/types/src/core/activation-event.d.ts +4 -4
- package/dist/types/src/core/activation-event.d.ts.map +1 -1
- package/dist/types/src/core/capability-manager.d.ts.map +1 -1
- package/dist/types/src/core/capability.d.ts +2 -2
- package/dist/types/src/core/capability.d.ts.map +1 -1
- package/dist/types/src/core/index.d.ts +2 -0
- package/dist/types/src/core/index.d.ts.map +1 -1
- package/dist/types/src/core/plugin-asset-cache.d.ts +71 -0
- package/dist/types/src/core/plugin-asset-cache.d.ts.map +1 -0
- package/dist/types/src/core/plugin-manager.d.ts +51 -2
- package/dist/types/src/core/plugin-manager.d.ts.map +1 -1
- package/dist/types/src/core/plugin-manifest.d.ts +76 -0
- package/dist/types/src/core/plugin-manifest.d.ts.map +1 -0
- package/dist/types/src/core/plugin-manifest.test.d.ts +2 -0
- package/dist/types/src/core/plugin-manifest.test.d.ts.map +1 -0
- package/dist/types/src/core/plugin.d.ts +107 -6
- package/dist/types/src/core/plugin.d.ts.map +1 -1
- package/dist/types/src/core/url-loader.d.ts +90 -3
- package/dist/types/src/core/url-loader.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/history/capability.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/history/errors.d.ts +6 -6
- package/dist/types/src/plugin-operation/history/errors.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/history/history-tracker.d.ts +1 -1
- package/dist/types/src/plugin-operation/history/history-tracker.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/history/types.d.ts +1 -1
- package/dist/types/src/plugin-operation/history/types.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/history/undo-mapping.d.ts +1 -1
- package/dist/types/src/plugin-operation/history/undo-mapping.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/history/undo-registry.d.ts +1 -1
- package/dist/types/src/plugin-operation/history/undo-registry.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/invoker-capability.d.ts +1 -1
- package/dist/types/src/plugin-operation/invoker-capability.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/testing.d.ts +2 -1
- package/dist/types/src/plugin-operation/testing.d.ts.map +1 -1
- package/dist/types/src/plugin-runtime/capability.d.ts +1 -1
- package/dist/types/src/plugin-runtime/capability.d.ts.map +1 -1
- package/dist/types/src/testing/harness.d.ts +67 -0
- package/dist/types/src/testing/harness.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/react.d.ts +27 -0
- package/dist/types/src/testing/react.d.ts.map +1 -0
- package/dist/types/src/testing/react.test.d.ts +2 -0
- package/dist/types/src/testing/react.test.d.ts.map +1 -0
- package/dist/types/src/testing/service.d.ts.map +1 -1
- package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
- package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
- package/dist/types/src/ui/components/App/App.d.ts.map +1 -1
- package/dist/types/src/ui/components/App/App.stories.d.ts.map +1 -1
- package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts +64 -0
- package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts.map +1 -0
- package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts +19 -0
- package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts.map +1 -0
- package/dist/types/src/ui/components/Placeholder/index.d.ts +2 -0
- package/dist/types/src/ui/components/Placeholder/index.d.ts.map +1 -0
- package/dist/types/src/ui/components/PluginManager/PluginManagerContext.stories.d.ts.map +1 -1
- package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts +16 -4
- package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts.map +1 -1
- package/dist/types/src/ui/components/Surface/SurfaceComponent.stories.d.ts.map +1 -1
- package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts.map +1 -1
- package/dist/types/src/ui/components/Surface/index.d.ts +16 -6
- package/dist/types/src/ui/components/Surface/index.d.ts.map +1 -1
- package/dist/types/src/ui/components/Surface/types.d.ts +110 -9
- package/dist/types/src/ui/components/Surface/types.d.ts.map +1 -1
- package/dist/types/src/ui/components/Surface/types.test.d.ts +2 -0
- package/dist/types/src/ui/components/Surface/types.test.d.ts.map +1 -0
- package/dist/types/src/ui/components/index.d.ts +1 -0
- package/dist/types/src/ui/components/index.d.ts.map +1 -1
- package/dist/types/src/ui/hooks/useApp.d.ts +29 -3
- package/dist/types/src/ui/hooks/useApp.d.ts.map +1 -1
- package/dist/types/src/ui/hooks/useCapabilities.d.ts.map +1 -1
- package/dist/types/src/ui/hooks/useLoading.d.ts.map +1 -1
- package/dist/types/src/ui/hooks/useSettingsState.d.ts.map +1 -1
- package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts +34 -0
- package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/boot-loader/index.d.ts +52 -0
- package/dist/types/src/vite-plugin/boot-loader/index.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/composer/index.d.ts +34 -0
- package/dist/types/src/vite-plugin/composer/index.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/import-map/index.d.ts +28 -0
- package/dist/types/src/vite-plugin/import-map/index.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/index.d.ts +4 -2
- package/dist/types/src/vite-plugin/index.d.ts.map +1 -1
- package/dist/types/src/vite-plugin/manifest.d.ts +37 -0
- package/dist/types/src/vite-plugin/manifest.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/manifest.test.d.ts +2 -0
- package/dist/types/src/vite-plugin/manifest.test.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/packages.d.ts +10 -4
- package/dist/types/src/vite-plugin/packages.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/moon.yml +1 -0
- package/package.json +33 -59
- package/src/common/capabilities.ts +2 -1
- package/src/common/operations.ts +1 -1
- package/src/core/capability.ts +1 -1
- package/src/core/index.ts +2 -0
- package/src/core/plugin-asset-cache.ts +60 -0
- package/src/core/plugin-manager.test.ts +246 -5
- package/src/core/plugin-manager.ts +167 -25
- package/src/core/plugin-manifest.test.ts +48 -0
- package/src/core/plugin-manifest.ts +102 -0
- package/src/core/plugin.ts +135 -10
- package/src/core/url-loader.test.ts +104 -5
- package/src/core/url-loader.ts +226 -37
- package/src/plugin-operation/OperationPlugin.ts +2 -2
- package/src/plugin-operation/history/capability.ts +1 -1
- package/src/plugin-operation/history/history-tracker.test.ts +2 -1
- package/src/plugin-operation/history/history-tracker.ts +1 -1
- package/src/plugin-operation/history/types.ts +1 -1
- package/src/plugin-operation/history/undo-mapping.ts +1 -1
- package/src/plugin-operation/history/undo-registry.ts +1 -1
- package/src/plugin-operation/invoker-capability.ts +2 -1
- package/src/plugin-operation/testing.ts +2 -1
- package/src/plugin-runtime/RuntimePlugin.ts +2 -2
- package/src/testing/harness.ts +229 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/react.test.tsx +48 -0
- package/src/testing/react.tsx +113 -0
- package/src/testing/withPluginManager.stories.tsx +1 -1
- package/src/ui/components/App/App.stories.tsx +1 -1
- package/src/ui/components/App/App.tsx +25 -2
- package/src/ui/components/Placeholder/Placeholder.stories.tsx +77 -0
- package/src/ui/components/Placeholder/Placeholder.tsx +155 -0
- package/src/ui/components/Placeholder/index.ts +5 -0
- package/src/ui/components/PluginManager/PluginManagerContext.stories.tsx +4 -2
- package/src/ui/components/Surface/SurfaceComponent.stories.tsx +1 -1
- package/src/ui/components/Surface/SurfaceComponent.tsx +83 -46
- package/src/ui/components/Surface/index.ts +20 -1
- package/src/ui/components/Surface/types.test.ts +126 -0
- package/src/ui/components/Surface/types.ts +164 -12
- package/src/ui/components/index.ts +1 -0
- package/src/ui/hooks/useApp.tsx +165 -41
- package/src/ui/hooks/useLoading.tsx +14 -6
- package/src/vite-plugin/boot-loader/BootLoader.stories.tsx +263 -0
- package/src/vite-plugin/boot-loader/boot-loader.css +294 -0
- package/src/vite-plugin/boot-loader/boot-loader.js +274 -0
- package/src/vite-plugin/boot-loader/index.ts +112 -0
- package/src/vite-plugin/composer/index.ts +277 -0
- package/src/vite-plugin/import-map/index.ts +524 -0
- package/src/vite-plugin/index.ts +6 -2
- package/src/vite-plugin/manifest.test.ts +24 -0
- package/src/vite-plugin/manifest.ts +50 -0
- package/src/vite-plugin/packages.ts +169 -10
- package/tsconfig.json +9 -0
- package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
- package/dist/lib/browser/capability-OP63CD5N.mjs.map +0 -7
- package/dist/lib/browser/chunk-F7FW2RK2.mjs.map +0 -7
- package/dist/lib/browser/chunk-FU4GAFUQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-GX4TUNM6.mjs.map +0 -7
- package/dist/lib/browser/chunk-JKWMHZP6.mjs.map +0 -7
- package/dist/lib/browser/chunk-LVJW5EFU.mjs +0 -157
- package/dist/lib/browser/chunk-LVJW5EFU.mjs.map +0 -7
- package/dist/lib/browser/chunk-RFSO3JRG.mjs +0 -1
- package/dist/lib/browser/chunk-WPE6AL7I.mjs +0 -905
- package/dist/lib/browser/chunk-WPE6AL7I.mjs.map +0 -7
- package/dist/lib/browser/invoker-capability-H5PPENOC.mjs.map +0 -7
- package/dist/lib/node-esm/capability-WFEG6CIZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4A3ZCMI3.mjs +0 -158
- package/dist/lib/node-esm/chunk-4A3ZCMI3.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BCEOLX47.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-G3RTFSNG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LQKOTNJW.mjs +0 -906
- package/dist/lib/node-esm/chunk-LQKOTNJW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ULUEXB7Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-URWHJQT2.mjs.map +0 -7
- package/dist/lib/node-esm/invoker-capability-S3ZA527J.mjs.map +0 -7
- package/dist/types/src/vite-plugin/composer-plugin.d.ts +0 -18
- package/dist/types/src/vite-plugin/composer-plugin.d.ts.map +0 -1
- package/dist/types/src/vite-plugin/import-map-plugin.d.ts +0 -16
- package/dist/types/src/vite-plugin/import-map-plugin.d.ts.map +0 -1
- package/src/vite-plugin/composer-plugin.ts +0 -128
- package/src/vite-plugin/import-map-plugin.ts +0 -314
- /package/dist/lib/browser/{capability-BBBBAPDI.mjs.map → capability-Q5XRXRD2.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-I34GF4NG.mjs.map → chunk-45CHLTBV.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-RFSO3JRG.mjs.map → chunk-G7SDBRKH.mjs.map} +0 -0
- /package/dist/lib/node-esm/{capability-AWBEMRYR.mjs.map → capability-EW5GJCI6.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-WZCSOX5Q.mjs.map → chunk-6XW6LET6.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-EL3R25OQ.mjs.map → chunk-OZ7DZA5Z.mjs.map} +0 -0
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2026 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { init as initCjsLexer, parse as parseCjs } from 'cjs-module-lexer';
|
|
6
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
-
import { createRequire as nodeCreateRequire } from 'node:module';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import { type Plugin } from 'vite';
|
|
10
|
-
|
|
11
|
-
import { DEFAULT_PACKAGES } from './packages';
|
|
12
|
-
|
|
13
|
-
const require = nodeCreateRequire(import.meta.url);
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
// Import map helpers.
|
|
17
|
-
// These utilities support `importMapPlugin` by resolving package entrypoints,
|
|
18
|
-
// detecting module formats (ESM vs CJS), and extracting named exports from CJS bundles.
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
/** Strips vite query strings (e.g. `?v=123`) from resolved module IDs. */
|
|
22
|
-
const trimQueryString = (id: string) => id.replace(/\?.*$/, '');
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Determines whether a resolved file is an ESM module by checking file extension
|
|
26
|
-
* first (.mjs/.cjs), then walking up to the nearest package.json for `"type": "module"`.
|
|
27
|
-
*/
|
|
28
|
-
const resolvedIdIsEsmModule = (resolvedId: string): boolean => {
|
|
29
|
-
const file = trimQueryString(resolvedId);
|
|
30
|
-
if (file.endsWith('.mjs') || file.endsWith('.mts')) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
if (file.endsWith('.cjs') || file.endsWith('.cts')) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let directory = path.dirname(file);
|
|
38
|
-
while (directory !== path.dirname(directory)) {
|
|
39
|
-
const packageJsonPath = path.join(directory, 'package.json');
|
|
40
|
-
if (existsSync(packageJsonPath)) {
|
|
41
|
-
try {
|
|
42
|
-
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as { type?: string };
|
|
43
|
-
return pkg.type === 'module';
|
|
44
|
-
} catch {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
directory = path.dirname(directory);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return false;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Walks up from a resolved file path to find the package.json whose `"name"` matches
|
|
56
|
-
* the given package name. Returns the path to that package.json, or undefined.
|
|
57
|
-
*/
|
|
58
|
-
const findPackageJsonPath = (resolvedId: string, packageName: string): string | undefined => {
|
|
59
|
-
let directory = path.dirname(trimQueryString(resolvedId));
|
|
60
|
-
|
|
61
|
-
while (directory !== path.dirname(directory)) {
|
|
62
|
-
const packageJsonPath = path.join(directory, 'package.json');
|
|
63
|
-
if (existsSync(packageJsonPath)) {
|
|
64
|
-
try {
|
|
65
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as { name?: string };
|
|
66
|
-
if (packageJson.name === packageName) {
|
|
67
|
-
return packageJsonPath;
|
|
68
|
-
}
|
|
69
|
-
} catch {}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
directory = path.dirname(directory);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return undefined;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/** Resolves a package name to its package.json path using Node's require.resolve. */
|
|
79
|
-
const resolvePackageJsonPath = (packageName: string): string | undefined => {
|
|
80
|
-
try {
|
|
81
|
-
return findPackageJsonPath(require.resolve(packageName), packageName);
|
|
82
|
-
} catch {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Subpath exports that should be excluded from the import map.
|
|
89
|
-
* These are node-only entrypoints (vite plugins, native addons) that shouldn't be pre-bundled for the browser.
|
|
90
|
-
*/
|
|
91
|
-
const importMapExcludedSubpaths: Readonly<Record<string, ReadonlySet<string>>> = {
|
|
92
|
-
'@dxos/app-framework': new Set(['vite-plugin']),
|
|
93
|
-
'@dxos/ui-theme': new Set(['plugin']),
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Reads a package's `exports` field and returns all JS subpath entrypoints as bare specifiers
|
|
98
|
-
* (e.g. `@dxos/client`, `@dxos/client/echo`). Skips wildcard patterns, non-JS assets,
|
|
99
|
-
* and excluded subpaths. Falls back to just the package name if exports is absent or simple.
|
|
100
|
-
*/
|
|
101
|
-
const getPackageEntrypoints = (packageName: string, packageJsonPath: string): string[] => {
|
|
102
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {
|
|
103
|
-
exports?: Record<string, unknown> | string | string[];
|
|
104
|
-
};
|
|
105
|
-
const exportsField = packageJson.exports;
|
|
106
|
-
|
|
107
|
-
if (!exportsField || typeof exportsField === 'string' || Array.isArray(exportsField)) {
|
|
108
|
-
return [packageName];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const exportKeys = Object.keys(exportsField);
|
|
112
|
-
if (!exportKeys.some((key) => key.startsWith('.'))) {
|
|
113
|
-
return [packageName];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const excluded = importMapExcludedSubpaths[packageName];
|
|
117
|
-
const modules = exportKeys.flatMap((key) => {
|
|
118
|
-
if (key === '.') {
|
|
119
|
-
return [packageName];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!key.startsWith('./') || key === './package.json' || key.includes('*')) {
|
|
123
|
-
return [];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const subpath = key.slice(2);
|
|
127
|
-
if (excluded?.has(subpath)) {
|
|
128
|
-
return [];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (/\.(css|pcss|scss|less|json|node|wasm|html|svg|png|jpg)$/.test(subpath)) {
|
|
132
|
-
return [];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return [`${packageName}/${subpath}`];
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
return modules.length > 0 ? modules : [packageName];
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Statically analyzes a CJS file to extract named exports using cjs-module-lexer.
|
|
143
|
-
* Follows re-exports (e.g. react's index.js re-exports from cjs/react.development.js)
|
|
144
|
-
* and deduplicates. Filters out `default` and `__esModule` pseudo-exports.
|
|
145
|
-
*/
|
|
146
|
-
const getCjsNamedExports = (filePath: string, seen = new Set<string>()): string[] => {
|
|
147
|
-
const normalized = trimQueryString(filePath);
|
|
148
|
-
if (seen.has(normalized)) {
|
|
149
|
-
return [];
|
|
150
|
-
}
|
|
151
|
-
seen.add(normalized);
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
const source = readFileSync(normalized, 'utf8');
|
|
155
|
-
const { exports: directExports, reexports } = parseCjs(source);
|
|
156
|
-
|
|
157
|
-
const reexportedNames = reexports.flatMap((reexport) => {
|
|
158
|
-
const resolved = path.resolve(path.dirname(normalized), reexport);
|
|
159
|
-
const candidates = [resolved, `${resolved}.js`, `${resolved}.cjs`];
|
|
160
|
-
const found = candidates.find((candidate) => existsSync(candidate));
|
|
161
|
-
return found ? getCjsNamedExports(found, seen) : [];
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
return [...new Set([...directExports, ...reexportedNames])].filter(
|
|
165
|
-
(name) => name !== 'default' && name !== '__esModule',
|
|
166
|
-
);
|
|
167
|
-
} catch {
|
|
168
|
-
return [];
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Vite plugin for the **host app** (Composer). Generates a browser import map so that
|
|
174
|
-
* shared packages are loaded once and reused by both the host and any remote plugins.
|
|
175
|
-
*
|
|
176
|
-
* In dev mode, maps bare specifiers directly to resolved file paths.
|
|
177
|
-
* In production, emits a dedicated chunk per specifier via virtual wrapper modules,
|
|
178
|
-
* then injects a `<script type="importmap">` tag into the HTML with the chunk URLs.
|
|
179
|
-
*
|
|
180
|
-
* Virtual wrappers are needed because directly emitting chunks for CJS packages loses
|
|
181
|
-
* their named exports due to Rollup's interop. The wrapper re-exports them explicitly.
|
|
182
|
-
*/
|
|
183
|
-
export const importMapPlugin = (options?: { packages?: string[] }): Plugin[] => {
|
|
184
|
-
const packages = options?.packages ?? DEFAULT_PACKAGES;
|
|
185
|
-
const WRAPPER_PREFIX = '\0import-map:';
|
|
186
|
-
const chunkRefIds: Record<string, string> = {};
|
|
187
|
-
const resolvedIds: Record<string, string> = {};
|
|
188
|
-
let imports: Record<string, string> = {};
|
|
189
|
-
let modules: string[] = [];
|
|
190
|
-
let importMapIsDev = false;
|
|
191
|
-
let base = '/';
|
|
192
|
-
|
|
193
|
-
return [
|
|
194
|
-
// Phase 1: Resolve all package entrypoints and emit chunks (or record dev paths).
|
|
195
|
-
{
|
|
196
|
-
name: 'import-map:get-chunk-ref-ids',
|
|
197
|
-
configResolved(config) {
|
|
198
|
-
base = config.base ?? '/';
|
|
199
|
-
},
|
|
200
|
-
async buildStart() {
|
|
201
|
-
importMapIsDev = this.environment.mode === 'dev';
|
|
202
|
-
await initCjsLexer();
|
|
203
|
-
|
|
204
|
-
// Expand each package name into its full set of subpath entrypoints
|
|
205
|
-
// (e.g. '@dxos/client' -> ['@dxos/client', '@dxos/client/echo', ...]).
|
|
206
|
-
modules = [
|
|
207
|
-
...new Set(
|
|
208
|
-
(
|
|
209
|
-
await Promise.all(
|
|
210
|
-
packages.map(async (packageName) => {
|
|
211
|
-
const packageJsonPath = resolvePackageJsonPath(packageName);
|
|
212
|
-
if (!packageJsonPath) {
|
|
213
|
-
this.warn(`Unable to locate package.json for import map package: ${packageName}`);
|
|
214
|
-
return [packageName];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return getPackageEntrypoints(packageName, packageJsonPath);
|
|
218
|
-
}),
|
|
219
|
-
)
|
|
220
|
-
).flat(),
|
|
221
|
-
),
|
|
222
|
-
];
|
|
223
|
-
|
|
224
|
-
for (const specifier of modules) {
|
|
225
|
-
const resolved = await this.resolve(specifier);
|
|
226
|
-
if (!resolved) {
|
|
227
|
-
this.warn(`Import map: unable to resolve "${specifier}"; omitting from import map.`);
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (importMapIsDev) {
|
|
232
|
-
// Dev: map bare specifier directly to the resolved file path.
|
|
233
|
-
imports[specifier] = trimQueryString(resolved.id);
|
|
234
|
-
} else {
|
|
235
|
-
// Prod: emit a virtual wrapper chunk that re-exports from the real module.
|
|
236
|
-
resolvedIds[specifier] = resolved.id;
|
|
237
|
-
chunkRefIds[specifier] = this.emitFile({
|
|
238
|
-
type: 'chunk',
|
|
239
|
-
id: `${WRAPPER_PREFIX}${specifier}`,
|
|
240
|
-
preserveSignature: 'strict',
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
// Intercept virtual wrapper IDs so Rollup doesn't try to resolve them as files.
|
|
247
|
-
resolveId(id) {
|
|
248
|
-
if (id.startsWith(WRAPPER_PREFIX)) {
|
|
249
|
-
return id;
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
// Generate the source for each virtual wrapper module.
|
|
254
|
-
// For CJS packages, explicitly re-export named exports (discovered via static analysis)
|
|
255
|
-
// because Rollup's `export *` interop doesn't preserve them for CJS.
|
|
256
|
-
load(id) {
|
|
257
|
-
if (!id.startsWith(WRAPPER_PREFIX)) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
const specifier = id.slice(WRAPPER_PREFIX.length);
|
|
261
|
-
const resolvedId = resolvedIds[specifier];
|
|
262
|
-
if (!resolvedId) {
|
|
263
|
-
return `export * from ${JSON.stringify(specifier)};\n`;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const filePath = trimQueryString(resolvedId);
|
|
267
|
-
const isCjs = filePath.endsWith('.cjs') || (!filePath.endsWith('.mjs') && !resolvedIdIsEsmModule(filePath));
|
|
268
|
-
|
|
269
|
-
if (isCjs) {
|
|
270
|
-
const named = getCjsNamedExports(filePath);
|
|
271
|
-
if (named.length > 0) {
|
|
272
|
-
return `export { default, ${named.join(', ')} } from ${JSON.stringify(specifier)};\n`;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return `export * from ${JSON.stringify(specifier)};\n`;
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
// After bundling, map each specifier to the URL of its emitted chunk.
|
|
279
|
-
generateBundle() {
|
|
280
|
-
if (importMapIsDev) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
imports = Object.fromEntries(
|
|
285
|
-
modules
|
|
286
|
-
.filter((specifier) => chunkRefIds[specifier] !== undefined)
|
|
287
|
-
.map((specifier) => [specifier, `${base}${this.getFileName(chunkRefIds[specifier])}`]),
|
|
288
|
-
);
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
|
|
292
|
-
// Phase 2: Inject the import map into the HTML as a <script type="importmap"> tag.
|
|
293
|
-
{
|
|
294
|
-
name: 'import-map:transform-index-html',
|
|
295
|
-
enforce: 'post',
|
|
296
|
-
transformIndexHtml(html: string) {
|
|
297
|
-
const tags = [
|
|
298
|
-
{
|
|
299
|
-
tag: 'script',
|
|
300
|
-
attrs: {
|
|
301
|
-
type: 'importmap',
|
|
302
|
-
},
|
|
303
|
-
children: JSON.stringify({ imports }, null, 2),
|
|
304
|
-
},
|
|
305
|
-
];
|
|
306
|
-
|
|
307
|
-
return {
|
|
308
|
-
html,
|
|
309
|
-
tags,
|
|
310
|
-
};
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
];
|
|
314
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|