@use-voltra/compiler 2.2.0 → 2.3.0

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.
Files changed (43) hide show
  1. package/build/cjs/index.js +11 -0
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/react-native/android.js +22 -0
  4. package/build/cjs/react-native/android.js.map +1 -0
  5. package/build/cjs/react-native/ios.js +22 -0
  6. package/build/cjs/react-native/ios.js.map +1 -0
  7. package/build/cjs/react-native/platform.js +40 -0
  8. package/build/cjs/react-native/platform.js.map +1 -0
  9. package/build/cjs/react-native/shim.js +133 -0
  10. package/build/cjs/react-native/shim.js.map +1 -0
  11. package/build/cjs/widget-module/loader.js +223 -0
  12. package/build/cjs/widget-module/loader.js.map +1 -0
  13. package/build/cjs/widget-module/policy.js +138 -0
  14. package/build/cjs/widget-module/policy.js.map +1 -0
  15. package/build/esm/index.js +2 -0
  16. package/build/esm/index.js.map +1 -1
  17. package/build/esm/react-native/android.js +5 -0
  18. package/build/esm/react-native/android.js.map +1 -0
  19. package/build/esm/react-native/ios.js +5 -0
  20. package/build/esm/react-native/ios.js.map +1 -0
  21. package/build/esm/react-native/platform.js +37 -0
  22. package/build/esm/react-native/platform.js.map +1 -0
  23. package/build/esm/react-native/shim.js +130 -0
  24. package/build/esm/react-native/shim.js.map +1 -0
  25. package/build/esm/widget-module/loader.js +184 -0
  26. package/build/esm/widget-module/loader.js.map +1 -0
  27. package/build/esm/widget-module/policy.js +130 -0
  28. package/build/esm/widget-module/policy.js.map +1 -0
  29. package/build/types/index.d.ts +4 -0
  30. package/build/types/index.d.ts.map +1 -1
  31. package/build/types/react-native/android.d.ts +3 -0
  32. package/build/types/react-native/android.d.ts.map +1 -0
  33. package/build/types/react-native/ios.d.ts +3 -0
  34. package/build/types/react-native/ios.d.ts.map +1 -0
  35. package/build/types/react-native/platform.d.ts +20 -0
  36. package/build/types/react-native/platform.d.ts.map +1 -0
  37. package/build/types/react-native/shim.d.ts +79 -0
  38. package/build/types/react-native/shim.d.ts.map +1 -0
  39. package/build/types/widget-module/loader.d.ts +30 -0
  40. package/build/types/widget-module/loader.d.ts.map +1 -0
  41. package/build/types/widget-module/policy.d.ts +57 -0
  42. package/build/types/widget-module/policy.d.ts.map +1 -0
  43. package/package.json +21 -2
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Widget module import policy.
3
+ *
4
+ * Widget source is evaluated in three different environments:
5
+ *
6
+ * - the Voltra CLI's `apply` pipeline (Node VM),
7
+ * - the Expo config plugins' prebuild prerender (Node VM),
8
+ * - Metro, when bundling a Dynamic Widget for the device.
9
+ *
10
+ * All three must agree on what a widget file is allowed to import and what each
11
+ * specifier resolves to, otherwise a widget that prerenders successfully can still
12
+ * fail to bundle — or worse, render differently on device than it did at build time.
13
+ * This module is the single source of truth for that contract.
14
+ */
15
+ /**
16
+ * Client packages carry the native bridge and app-side runtime. They cannot be
17
+ * evaluated outside the app, so widget code that imports them is served the
18
+ * matching rendering package instead.
19
+ */
20
+ const PACKAGE_ALIASES = {
21
+ '@use-voltra/ios-client': '@use-voltra/ios',
22
+ '@use-voltra/android-client': '@use-voltra/android',
23
+ };
24
+ /** Package that hosts the `react-native` shim served to widget code. */
25
+ export const WIDGET_REACT_NATIVE_SHIM_PACKAGE = '@use-voltra/compiler';
26
+ /** Specifier of the `react-native` shim for a given platform. */
27
+ export function getWidgetReactNativeShimSpecifier(platform) {
28
+ return `${WIDGET_REACT_NATIVE_SHIM_PACKAGE}/react-native/${platform}`;
29
+ }
30
+ /** Symbols the `react-native` shim implements. Anything else is rejected. */
31
+ export const SUPPORTED_REACT_NATIVE_EXPORTS = ['Platform', 'StyleSheet'];
32
+ /**
33
+ * React Native exports widget code is most likely to reach for by mistake.
34
+ *
35
+ * The Node loader rejects *any* unimplemented symbol, but a Metro bundle resolves the shim
36
+ * file directly and has no such interception point. Naming these explicitly means a widget
37
+ * that slips one past build-time evaluation still fails loudly on device with the same
38
+ * message, rather than silently reading `undefined`.
39
+ */
40
+ export const REJECTED_REACT_NATIVE_EXPORTS = [
41
+ 'ActivityIndicator',
42
+ 'Alert',
43
+ 'Animated',
44
+ 'AppRegistry',
45
+ 'AppState',
46
+ 'Appearance',
47
+ 'Button',
48
+ 'DeviceEventEmitter',
49
+ 'Dimensions',
50
+ 'Easing',
51
+ 'FlatList',
52
+ 'I18nManager',
53
+ 'Image',
54
+ 'ImageBackground',
55
+ 'InteractionManager',
56
+ 'Keyboard',
57
+ 'KeyboardAvoidingView',
58
+ 'LayoutAnimation',
59
+ 'Linking',
60
+ 'Modal',
61
+ 'NativeEventEmitter',
62
+ 'NativeModules',
63
+ 'PanResponder',
64
+ 'PermissionsAndroid',
65
+ 'PixelRatio',
66
+ 'Pressable',
67
+ 'SafeAreaView',
68
+ 'ScrollView',
69
+ 'SectionList',
70
+ 'Share',
71
+ 'StatusBar',
72
+ 'Switch',
73
+ 'Text',
74
+ 'TextInput',
75
+ 'ToastAndroid',
76
+ 'TouchableHighlight',
77
+ 'TouchableOpacity',
78
+ 'TouchableWithoutFeedback',
79
+ 'TurboModuleRegistry',
80
+ 'UIManager',
81
+ 'Vibration',
82
+ 'View',
83
+ 'VirtualizedList',
84
+ 'findNodeHandle',
85
+ 'processColor',
86
+ 'requireNativeComponent',
87
+ 'useColorScheme',
88
+ 'useWindowDimensions',
89
+ ];
90
+ function isReactNativeRoot(specifier) {
91
+ return specifier === 'react-native';
92
+ }
93
+ function isReactNativeDeepImport(specifier) {
94
+ return specifier.startsWith('react-native/');
95
+ }
96
+ /** Whether a specifier reaches for React Native, either its entry point or a deep path. */
97
+ export function isReactNativeImport(specifier) {
98
+ return isReactNativeRoot(specifier) || isReactNativeDeepImport(specifier);
99
+ }
100
+ /** Decide how a bare import from widget code should be resolved. */
101
+ export function resolveWidgetImport(specifier, platform) {
102
+ if (isReactNativeRoot(specifier)) {
103
+ return { kind: 'alias', specifier: getWidgetReactNativeShimSpecifier(platform) };
104
+ }
105
+ if (isReactNativeDeepImport(specifier)) {
106
+ return { kind: 'blocked', reason: describeBlockedWidgetImport(specifier) };
107
+ }
108
+ const aliasedPackage = PACKAGE_ALIASES[specifier];
109
+ if (aliasedPackage) {
110
+ return {
111
+ kind: 'alias',
112
+ specifier: aliasedPackage,
113
+ warning: `Widget code imported '${specifier}'. Using '${aliasedPackage}' instead.`,
114
+ };
115
+ }
116
+ return { kind: 'passthrough' };
117
+ }
118
+ /** Message shown when widget code imports something it cannot use. */
119
+ export function describeBlockedWidgetImport(specifier) {
120
+ return (`Voltra widget code cannot import '${specifier}'. ` +
121
+ `Only ${SUPPORTED_REACT_NATIVE_EXPORTS.join(' and ')} are available from 'react-native'; ` +
122
+ "use the components exported by '@use-voltra/ios' or '@use-voltra/android' for everything else.");
123
+ }
124
+ /** Message shown when widget code reaches for a `react-native` symbol the shim does not implement. */
125
+ export function describeUnsupportedReactNativeExport(symbol) {
126
+ return (`'${symbol}' is not available to Voltra widget code. ` +
127
+ `Only ${SUPPORTED_REACT_NATIVE_EXPORTS.join(' and ')} are available from 'react-native'; ` +
128
+ "use the components exported by '@use-voltra/ios' or '@use-voltra/android' for everything else.");
129
+ }
130
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../src/widget-module/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH;;;;GAIG;AACH,MAAM,eAAe,GAAqC;IACxD,wBAAwB,EAAE,iBAAiB;IAC3C,4BAA4B,EAAE,qBAAqB;CACpD,CAAA;AAED,wEAAwE;AACxE,MAAM,CAAC,MAAM,gCAAgC,GAAG,sBAAsB,CAAA;AAEtE,iEAAiE;AACjE,MAAM,UAAU,iCAAiC,CAAC,QAA8B;IAC9E,OAAO,GAAG,gCAAgC,iBAAiB,QAAQ,EAAE,CAAA;AACvE,CAAC;AAED,6EAA6E;AAC7E,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,UAAU,EAAE,YAAY,CAAU,C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B,CAAC,SAAS,CAAC,EAAE,CAAC;QACvC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,2BAA2B,CAAC,SAAS,CAAC,EAAE,CAAA;IAC5E,CAAC;IAED,MAAM,cAAc,GAAG,eAAe,CAAC,SAAS,CAAC,CAAA;IAEjD,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO;YACL,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,cAAc;YACzB,OAAO,EAAE,yBAAyB,SAAS,aAAa,cAAc,YAAY;SACnF,CAAA;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;AAChC,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,2BAA2B,CAAC,SAAiB;IAC3D,OAAO,CACL,qCAAqC,SAAS,KAAK;QACnD,QAAQ,8BAA8B,CAAC,IAAI,CAAC,OAAO,CAAC,sCAAsC;QAC1F,gGAAgG,CACjG,CAAA;AACH,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,oCAAoC,CAAC,MAAc;IACjE,OAAO,CACL,IAAI,MAAM,4CAA4C;QACtD,QAAQ,8BAA8B,CAAC,IAAI,CAAC,OAAO,CAAC,sCAAsC;QAC1F,gGAAgG,CACjG,CAAA;AACH,CAAC"}
@@ -8,4 +8,8 @@ export declare function scanVoltraDirectives({ filePath, source, }: {
8
8
  filePath: string;
9
9
  source: string;
10
10
  }): VoltraDirectiveWidget[];
11
+ export { createWidgetModuleLoader } from './widget-module/loader.js';
12
+ export type { CreateWidgetModuleLoaderOptions, WidgetModuleLoader } from './widget-module/loader.js';
13
+ export { describeBlockedWidgetImport, describeUnsupportedReactNativeExport, getWidgetReactNativeShimSpecifier, isReactNativeImport, resolveWidgetImport, SUPPORTED_REACT_NATIVE_EXPORTS, WIDGET_REACT_NATIVE_SHIM_PACKAGE, } from './widget-module/policy.js';
14
+ export type { WidgetImportResolution, WidgetModulePlatform } from './widget-module/policy.js';
11
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAsLD,wBAAgB,oBAAoB,CAAC,EACnC,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf,GAAG,qBAAqB,EAAE,CAyC1B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAsLD,wBAAgB,oBAAoB,CAAC,EACnC,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf,GAAG,qBAAqB,EAAE,CAyC1B;AAED,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AACpE,YAAY,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AACpG,OAAO,EACL,2BAA2B,EAC3B,oCAAoC,EACpC,iCAAiC,EACjC,mBAAmB,EACnB,mBAAmB,EACnB,8BAA8B,EAC9B,gCAAgC,GACjC,MAAM,2BAA2B,CAAA;AAClC,YAAY,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const Platform: import("./platform.js").WidgetPlatform;
2
+ export * from './shim.js';
3
+ //# sourceMappingURL=android.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../../src/react-native/android.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,wCAA4B,CAAA;AACjD,cAAc,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const Platform: import("./platform.js").WidgetPlatform;
2
+ export * from './shim.js';
3
+ //# sourceMappingURL=ios.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../../src/react-native/ios.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,wCAAwB,CAAA;AAC7C,cAAc,WAAW,CAAA"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `Platform` as widget code sees it.
3
+ *
4
+ * Kept out of `shim.ts` so that module holds only the widget-visible surface and the
5
+ * per-platform entry points can re-export it wholesale.
6
+ */
7
+ import { type WidgetModulePlatform } from '../widget-module/policy.js';
8
+ export type WidgetPlatform = {
9
+ readonly OS: WidgetModulePlatform;
10
+ select<T>(specifics: PlatformSelectSpec<T>): T | undefined;
11
+ };
12
+ type PlatformSelectSpec<T> = {
13
+ ios?: T;
14
+ android?: T;
15
+ native?: T;
16
+ default?: T;
17
+ };
18
+ export declare function createPlatform(platform: WidgetModulePlatform): WidgetPlatform;
19
+ export {};
20
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../../src/react-native/platform.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAwC,KAAK,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAM5G,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,EAAE,EAAE,oBAAoB,CAAA;IACjC,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;CAC3D,CAAA;AAED,KAAK,kBAAkB,CAAC,CAAC,IAAI;IAC3B,GAAG,CAAC,EAAE,CAAC,CAAA;IACP,OAAO,CAAC,EAAE,CAAC,CAAA;IACX,MAAM,CAAC,EAAE,CAAC,CAAA;IACV,OAAO,CAAC,EAAE,CAAC,CAAA;CACZ,CAAA;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,oBAAoB,GAAG,cAAc,CA2B7E"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The `react-native` surface available to Voltra widget code.
3
+ *
4
+ * Widget code does not run against the React Native runtime: at build time it is
5
+ * evaluated in a Node VM, and on device it runs in a separate JS engine with no
6
+ * bridge and no native modules. Only the parts of `react-native` that are pure
7
+ * data manipulation can be honoured, so this shim implements `StyleSheet` and
8
+ * `Platform` and rejects everything else with an actionable message instead of
9
+ * silently handing back `undefined`.
10
+ */
11
+ type Style = Record<string, unknown>;
12
+ type StyleInput = Style | false | null | undefined | ReadonlyArray<StyleInput>;
13
+ declare function flatten(style: StyleInput): Style;
14
+ /**
15
+ * `StyleSheet` is an identity mapping in Voltra: widget styles are plain objects that
16
+ * are serialized into the widget payload, so there is no registry to allocate ids in.
17
+ */
18
+ export declare const StyleSheet: Readonly<{
19
+ create<T extends Record<string, Style>>(styles: T): T;
20
+ flatten: typeof flatten;
21
+ compose(first: StyleInput, second: StyleInput): StyleInput;
22
+ absoluteFill: Style;
23
+ absoluteFillObject: Style;
24
+ /**
25
+ * Widgets are rendered by the host OS, which does not expose a screen scale to the
26
+ * widget process, so the thinnest expressible line is a single point.
27
+ */
28
+ hairlineWidth: 1;
29
+ }>;
30
+ export declare const ActivityIndicator: any;
31
+ export declare const Alert: any;
32
+ export declare const Animated: any;
33
+ export declare const AppRegistry: any;
34
+ export declare const AppState: any;
35
+ export declare const Appearance: any;
36
+ export declare const Button: any;
37
+ export declare const DeviceEventEmitter: any;
38
+ export declare const Dimensions: any;
39
+ export declare const Easing: any;
40
+ export declare const FlatList: any;
41
+ export declare const I18nManager: any;
42
+ export declare const Image: any;
43
+ export declare const ImageBackground: any;
44
+ export declare const InteractionManager: any;
45
+ export declare const Keyboard: any;
46
+ export declare const KeyboardAvoidingView: any;
47
+ export declare const LayoutAnimation: any;
48
+ export declare const Linking: any;
49
+ export declare const Modal: any;
50
+ export declare const NativeEventEmitter: any;
51
+ export declare const NativeModules: any;
52
+ export declare const PanResponder: any;
53
+ export declare const PermissionsAndroid: any;
54
+ export declare const PixelRatio: any;
55
+ export declare const Pressable: any;
56
+ export declare const SafeAreaView: any;
57
+ export declare const ScrollView: any;
58
+ export declare const SectionList: any;
59
+ export declare const Share: any;
60
+ export declare const StatusBar: any;
61
+ export declare const Switch: any;
62
+ export declare const Text: any;
63
+ export declare const TextInput: any;
64
+ export declare const ToastAndroid: any;
65
+ export declare const TouchableHighlight: any;
66
+ export declare const TouchableOpacity: any;
67
+ export declare const TouchableWithoutFeedback: any;
68
+ export declare const TurboModuleRegistry: any;
69
+ export declare const UIManager: any;
70
+ export declare const Vibration: any;
71
+ export declare const View: any;
72
+ export declare const VirtualizedList: any;
73
+ export declare const findNodeHandle: any;
74
+ export declare const processColor: any;
75
+ export declare const requireNativeComponent: any;
76
+ export declare const useColorScheme: any;
77
+ export declare const useWindowDimensions: any;
78
+ export {};
79
+ //# sourceMappingURL=shim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shim.d.ts","sourceRoot":"","sources":["../../../src/react-native/shim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACpC,KAAK,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,aAAa,CAAC,UAAU,CAAC,CAAA;AAwC9E,iBAAS,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAoBzC;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU;WACd,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC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AAA;AAClD,eAAO,MAAM,SAAS,KAAoC,CAAA;AAC1D,eAAO,MAAM,MAAM,KAAiC,CAAA;AACpD,eAAO,MAAM,IAAI,KAA+B,CAAA;AAChD,eAAO,MAAM,SAAS,KAAoC,CAAA;AAC1D,eAAO,MAAM,YAAY,KAAuC,CAAA;AAChE,eAAO,MAAM,kBAAkB,KAA6C,CAAA;AAC5E,eAAO,MAAM,gBAAgB,KAA2C,CAAA;AACxE,eAAO,MAAM,wBAAwB,KAAmD,CAAA;AACxF,eAAO,MAAM,mBAAmB,KAA8C,CAAA;AAC9E,eAAO,MAAM,SAAS,KAAoC,CAAA;AAC1D,eAAO,MAAM,SAAS,KAAoC,CAAA;AAC1D,eAAO,MAAM,IAAI,KAA+B,CAAA;AAChD,eAAO,MAAM,eAAe,KAA0C,CAAA;AACtE,eAAO,MAAM,cAAc,KAAyC,CAAA;AACpE,eAAO,MAAM,YAAY,KAAuC,CAAA;AAChE,eAAO,MAAM,sBAAsB,KAAiD,CAAA;AACpF,eAAO,MAAM,cAAc,KAAyC,CAAA;AACpE,eAAO,MAAM,mBAAmB,KAA8C,CAAA"}
@@ -0,0 +1,30 @@
1
+ import { type WidgetModulePlatform } from './policy.js';
2
+ export interface CreateWidgetModuleLoaderOptions {
3
+ /** Root of the app project. Bare imports and Babel configuration resolve from here. */
4
+ projectRoot: string;
5
+ /** Platform the widget is being loaded for. Drives `Platform.OS` in widget code. */
6
+ platform: WidgetModulePlatform;
7
+ /** Called once per distinct message when an import is served from somewhere else. */
8
+ onWarning?: (message: string) => void;
9
+ /** Wraps loader failures so callers can surface them as their own error type. */
10
+ createError?: (message: string) => Error;
11
+ }
12
+ export interface WidgetModuleLoader {
13
+ /** Evaluate `entryPath` and return its exports object. */
14
+ load<TExports = unknown>(entryPath: string): TExports;
15
+ /** Evaluate `entryPath` and return its default export, falling back to the exports object. */
16
+ loadDefaultExport<TExport = unknown>(entryPath: string): TExport;
17
+ }
18
+ /**
19
+ * Create a loader that evaluates widget source the way Voltra's build steps need it.
20
+ *
21
+ * Relative imports are transpiled with the project's Babel setup and evaluated in a
22
+ * Node VM; bare imports go through {@link resolveWidgetImport} so that build-time
23
+ * evaluation and the on-device Metro bundle agree on what widget code may import.
24
+ *
25
+ * Each `load` call gets a fresh module cache, matching Node's behaviour of evaluating a
26
+ * dependency graph once per entry point. Warnings are deduplicated across the loader's
27
+ * lifetime so a project-wide message is reported once, not once per widget.
28
+ */
29
+ export declare function createWidgetModuleLoader({ projectRoot, platform, onWarning, createError, }: CreateWidgetModuleLoaderOptions): WidgetModuleLoader;
30
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/widget-module/loader.ts"],"names":[],"mappings":"AASA,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAA;AAapB,MAAM,WAAW,+BAA+B;IAC9C,uFAAuF;IACvF,WAAW,EAAE,MAAM,CAAA;IACnB,oFAAoF;IACpF,QAAQ,EAAE,oBAAoB,CAAA;IAC9B,qFAAqF;IACrF,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IACrC,iFAAiF;IACjF,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAA;CACzC;AAED,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAA;IACrD,8FAA8F;IAC9F,iBAAiB,CAAC,OAAO,GAAG,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAA;CACjE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,WAAW,EACX,QAAQ,EACR,SAAS,EACT,WAA6C,GAC9C,EAAE,+BAA+B,GAAG,kBAAkB,CAwHtD"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Widget module import policy.
3
+ *
4
+ * Widget source is evaluated in three different environments:
5
+ *
6
+ * - the Voltra CLI's `apply` pipeline (Node VM),
7
+ * - the Expo config plugins' prebuild prerender (Node VM),
8
+ * - Metro, when bundling a Dynamic Widget for the device.
9
+ *
10
+ * All three must agree on what a widget file is allowed to import and what each
11
+ * specifier resolves to, otherwise a widget that prerenders successfully can still
12
+ * fail to bundle — or worse, render differently on device than it did at build time.
13
+ * This module is the single source of truth for that contract.
14
+ */
15
+ /** Platform a widget module is being loaded or bundled for. */
16
+ export type WidgetModulePlatform = 'ios' | 'android';
17
+ /** Package that hosts the `react-native` shim served to widget code. */
18
+ export declare const WIDGET_REACT_NATIVE_SHIM_PACKAGE = "@use-voltra/compiler";
19
+ /** Specifier of the `react-native` shim for a given platform. */
20
+ export declare function getWidgetReactNativeShimSpecifier(platform: WidgetModulePlatform): string;
21
+ /** Symbols the `react-native` shim implements. Anything else is rejected. */
22
+ export declare const SUPPORTED_REACT_NATIVE_EXPORTS: readonly ["Platform", "StyleSheet"];
23
+ /**
24
+ * React Native exports widget code is most likely to reach for by mistake.
25
+ *
26
+ * The Node loader rejects *any* unimplemented symbol, but a Metro bundle resolves the shim
27
+ * file directly and has no such interception point. Naming these explicitly means a widget
28
+ * that slips one past build-time evaluation still fails loudly on device with the same
29
+ * message, rather than silently reading `undefined`.
30
+ */
31
+ export declare const REJECTED_REACT_NATIVE_EXPORTS: readonly ["ActivityIndicator", "Alert", "Animated", "AppRegistry", "AppState", "Appearance", "Button", "DeviceEventEmitter", "Dimensions", "Easing", "FlatList", "I18nManager", "Image", "ImageBackground", "InteractionManager", "Keyboard", "KeyboardAvoidingView", "LayoutAnimation", "Linking", "Modal", "NativeEventEmitter", "NativeModules", "PanResponder", "PermissionsAndroid", "PixelRatio", "Pressable", "SafeAreaView", "ScrollView", "SectionList", "Share", "StatusBar", "Switch", "Text", "TextInput", "ToastAndroid", "TouchableHighlight", "TouchableOpacity", "TouchableWithoutFeedback", "TurboModuleRegistry", "UIManager", "Vibration", "View", "VirtualizedList", "findNodeHandle", "processColor", "requireNativeComponent", "useColorScheme", "useWindowDimensions"];
32
+ /** How an import from widget code should be handled. */
33
+ export type WidgetImportResolution =
34
+ /** Resolve the specifier as written. */
35
+ {
36
+ kind: 'passthrough';
37
+ }
38
+ /** Resolve `specifier` instead of the requested one. */
39
+ | {
40
+ kind: 'alias';
41
+ specifier: string;
42
+ warning?: string;
43
+ }
44
+ /** Reject the import with `reason`. */
45
+ | {
46
+ kind: 'blocked';
47
+ reason: string;
48
+ };
49
+ /** Whether a specifier reaches for React Native, either its entry point or a deep path. */
50
+ export declare function isReactNativeImport(specifier: string): boolean;
51
+ /** Decide how a bare import from widget code should be resolved. */
52
+ export declare function resolveWidgetImport(specifier: string, platform: WidgetModulePlatform): WidgetImportResolution;
53
+ /** Message shown when widget code imports something it cannot use. */
54
+ export declare function describeBlockedWidgetImport(specifier: string): string;
55
+ /** Message shown when widget code reaches for a `react-native` symbol the shim does not implement. */
56
+ export declare function describeUnsupportedReactNativeExport(symbol: string): string;
57
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/widget-module/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,+DAA+D;AAC/D,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,SAAS,CAAA;AAYpD,wEAAwE;AACxE,eAAO,MAAM,gCAAgC,yBAAyB,CAAA;AAEtE,iEAAiE;AACjE,wBAAgB,iCAAiC,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAExF;AAED,6EAA6E;AAC7E,eAAO,MAAM,8BAA8B,qCAAsC,CAAA;AAEjF;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,+vBAiDhC,CAAA;AAEV,wDAAwD;AACxD,MAAM,MAAM,sBAAsB;AAChC,wCAAwC;AACtC;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE;AACzB,wDAAwD;GACtD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE;AACxD,uCAAuC;GACrC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAUvC,2FAA2F;AAC3F,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED,oEAAoE;AACpE,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,GAAG,sBAAsB,CAoB7G;AAED,sEAAsE;AACtE,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAMrE;AAED,sGAAsG;AACtG,wBAAgB,oCAAoC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAM3E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@use-voltra/compiler",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Shared Voltra source analysis utilities",
5
5
  "main": "build/cjs/index.js",
6
6
  "module": "build/esm/index.js",
@@ -12,6 +12,18 @@
12
12
  "import": "./build/esm/index.js",
13
13
  "default": "./build/esm/index.js"
14
14
  },
15
+ "./react-native/ios": {
16
+ "types": "./build/types/react-native/ios.d.ts",
17
+ "require": "./build/cjs/react-native/ios.js",
18
+ "import": "./build/esm/react-native/ios.js",
19
+ "default": "./build/esm/react-native/ios.js"
20
+ },
21
+ "./react-native/android": {
22
+ "types": "./build/types/react-native/android.d.ts",
23
+ "require": "./build/cjs/react-native/android.js",
24
+ "import": "./build/esm/react-native/android.js",
25
+ "default": "./build/esm/react-native/android.js"
26
+ },
15
27
  "./package.json": "./package.json"
16
28
  },
17
29
  "files": [
@@ -19,6 +31,7 @@
19
31
  "README.md"
20
32
  ],
21
33
  "dependencies": {
34
+ "@babel/core": "^7.27.4",
22
35
  "@babel/parser": "^7.27.4",
23
36
  "@babel/types": "^7.27.4"
24
37
  },
@@ -38,11 +51,17 @@
38
51
  },
39
52
  "license": "MIT",
40
53
  "homepage": "https://use-voltra.dev",
54
+ "devDependencies": {
55
+ "@babel/runtime": "^7.27.4",
56
+ "@react-native/babel-preset": "0.83.2",
57
+ "@types/babel__core": "^7.20.5",
58
+ "tsx": "^4.19.0"
59
+ },
41
60
  "scripts": {
42
61
  "build": "node ../../scripts/build-package.mjs packages/compiler",
43
62
  "clean": "rm -rf build",
44
63
  "lint": "oxlint src",
45
64
  "typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
46
- "test": "node --test"
65
+ "test": "node --import tsx --test"
47
66
  }
48
67
  }