@ohos-ports/react-native-navigation 8.9.0-beta.2 → 8.9.0-beta.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohos-ports/react-native-navigation",
3
- "version": "8.9.0-beta.2",
3
+ "version": "8.9.0-beta.4",
4
4
  "description": "React Native Navigation - truly native navigation for iOS and Android (HarmonyOS port)",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -30,9 +30,13 @@
30
30
  },
31
31
  "files": [
32
32
  "lib",
33
+ "scripts",
33
34
  "README.md",
34
35
  "LICENSE"
35
36
  ],
37
+ "scripts": {
38
+ "postinstall": "node scripts/setup-esm-shim.js"
39
+ },
36
40
  "peerDependencies": {
37
41
  "react": "*",
38
42
  "@ohos-ports/react-native": "^0.87.1-beta.1"
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Postinstall: creates ESM shim at package-local node_modules/react-native/
4
+ * so that `import { X } from 'react-native'` resolves named exports from
5
+ * the CJS @ohos-ports/react-native via createRequire.
6
+ *
7
+ * __dirname = node_modules/@ohos-ports/react-native-navigation/scripts/
8
+ * Target = node_modules/@ohos-ports/react-native-navigation/node_modules/react-native/
9
+ */
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ const RN_SHIM_DIR = path.join(__dirname, '..', 'node_modules', 'react-native');
14
+
15
+ let ohosPortsRN;
16
+ try {
17
+ ohosPortsRN = require.resolve('@ohos-ports/react-native');
18
+ } catch (e) {
19
+ process.exit(0);
20
+ }
21
+
22
+ fs.mkdirSync(RN_SHIM_DIR, { recursive: true });
23
+
24
+ const shimPkg = {
25
+ name: 'react-native',
26
+ version: '0.0.0-shim',
27
+ type: 'module',
28
+ main: './index.mjs',
29
+ exports: { '.': { default: './index.mjs' }, './package.json': './package.json' }
30
+ };
31
+ fs.writeFileSync(path.join(RN_SHIM_DIR, 'package.json'), JSON.stringify(shimPkg, null, 2));
32
+
33
+ const shim = `// ESM shim for @ohos-ports/react-native (auto-generated)
34
+ import { createRequire } from 'module';
35
+ const require = createRequire(import.meta.url);
36
+ const rn = require('@ohos-ports/react-native');
37
+ function safeGet(o,k){try{return o[k]}catch(e){return undefined}}
38
+ const _D=rn.Dimensions;
39
+ export const Dimensions={get(n){try{const v=_D.get(n);if(v)return v}catch(e){}return{width:375,height:812,scale:1,fontScale:1}},addEventListener:_D?.addEventListener?.bind(_D),removeEventListener:_D?.removeEventListener?.bind(_D),set:_D?.set?.bind(_D)};
40
+ export const AppRegistry=rn.AppRegistry;
41
+ export const DynamicColorIOS=rn.DynamicColorIOS;export const Image=rn.Image;export const Linking=rn.Linking;
42
+ export const NativeEventEmitter=rn.NativeEventEmitter;export const NativeModules=rn.NativeModules;
43
+ export const Platform=rn.Platform;export const StyleSheet=rn.StyleSheet;
44
+ export const TouchableNativeFeedback=rn.TouchableNativeFeedback;export const TouchableOpacity=rn.TouchableOpacity;
45
+ export const TouchableWithoutFeedback=rn.TouchableWithoutFeedback;export const TurboModuleRegistry=rn.TurboModuleRegistry;
46
+ export const View=rn.View;export const findNodeHandle=rn.findNodeHandle;export const processColor=rn.processColor;
47
+ export const Button=safeGet(rn,'Button')||(()=>null);
48
+ export const Text=safeGet(rn,'Text')||(()=>null);
49
+ export const requireNativeComponent=safeGet(rn,'requireNativeComponent')||((n)=>({displayName:n}));
50
+ export default rn;
51
+ `;
52
+ fs.writeFileSync(path.join(RN_SHIM_DIR, 'index.mjs'), shim);
53
+ console.log('@ohos-ports/react-native-navigation: ESM shim created');