react-native-ios-widget 0.0.12 → 0.0.13-beta.1
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
|
@@ -26,17 +26,15 @@ export const getWidgetFiles = (
|
|
|
26
26
|
fs.mkdirSync(targetPath, { recursive: true });
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
// Ensure moduleRoot directory exists
|
|
30
29
|
if (!fs.existsSync(moduleRoot)) {
|
|
31
30
|
fs.mkdirSync(moduleRoot, { recursive: true });
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
// Check if Module.swift exists before proceeding
|
|
35
33
|
const moduleSwiftPath = path.join(widgetsPath, "Module.swift");
|
|
36
34
|
if (!fs.existsSync(moduleSwiftPath)) {
|
|
37
35
|
throw new Error(
|
|
38
36
|
`Module.swift not found at ${moduleSwiftPath}. ` +
|
|
39
|
-
|
|
37
|
+
"The widgets folder must contain Module.swift to build ReactNativeWidgetExtension."
|
|
40
38
|
);
|
|
41
39
|
}
|
|
42
40
|
|
|
@@ -73,7 +71,6 @@ export const getWidgetFiles = (
|
|
|
73
71
|
copyFileSync(source, targetPath);
|
|
74
72
|
});
|
|
75
73
|
|
|
76
|
-
// Copy Module.swift to moduleRoot (package ios directory)
|
|
77
74
|
copyFileSync(moduleSwiftPath, path.join(moduleRoot, "Module.swift"));
|
|
78
75
|
|
|
79
76
|
// Copy directories
|
package/plugin/src/withXcode.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConfigPlugin, withXcodeProject } from "expo/config-plugins";
|
|
2
|
+
import * as fs from "fs";
|
|
2
3
|
import * as path from "path";
|
|
3
4
|
|
|
4
5
|
import { addXCConfigurationList } from "./xcode/addXCConfigurationList";
|
|
@@ -18,18 +19,20 @@ export const withXcode: ConfigPlugin<Required<WidgetConfig>> = (
|
|
|
18
19
|
return withXcodeProject(config, (config) => {
|
|
19
20
|
const { platformProjectRoot, projectRoot } = config.modRequest;
|
|
20
21
|
|
|
21
|
-
if (!enabled) {
|
|
22
|
-
return config;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
22
|
const widgetsPath = path.join(projectRoot, widgetsFolder);
|
|
26
|
-
const targetPath = path.join(platformProjectRoot, targetName);
|
|
27
23
|
const moduleRoot = path.join(
|
|
28
24
|
projectRoot,
|
|
29
25
|
"node_modules",
|
|
30
26
|
"react-native-ios-widget",
|
|
31
27
|
"ios"
|
|
32
28
|
);
|
|
29
|
+
|
|
30
|
+
if (!enabled) {
|
|
31
|
+
ensureModuleSwift(widgetsPath, moduleRoot);
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const targetPath = path.join(platformProjectRoot, targetName);
|
|
33
36
|
const widgetFiles = getWidgetFiles(widgetsPath, targetPath, moduleRoot);
|
|
34
37
|
|
|
35
38
|
const xcodeProject = config.modResults;
|
|
@@ -75,3 +78,34 @@ export const withXcode: ConfigPlugin<Required<WidgetConfig>> = (
|
|
|
75
78
|
return config;
|
|
76
79
|
});
|
|
77
80
|
};
|
|
81
|
+
|
|
82
|
+
const ensureModuleSwift = (widgetsPath: string, moduleRoot: string) => {
|
|
83
|
+
// Ensure the pod source dir exists for Module.swift.
|
|
84
|
+
if (!fs.existsSync(moduleRoot)) {
|
|
85
|
+
fs.mkdirSync(moduleRoot, { recursive: true });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Prefer the real Module.swift from widgets if it exists.
|
|
89
|
+
const moduleSwiftPath = path.join(widgetsPath, "Module.swift");
|
|
90
|
+
const targetPath = path.join(moduleRoot, "Module.swift");
|
|
91
|
+
if (fs.existsSync(moduleSwiftPath)) {
|
|
92
|
+
fs.copyFileSync(moduleSwiftPath, targetPath);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// If widgets are disabled and no real Module.swift exists, write a stub
|
|
97
|
+
// so CocoaPods still builds a Swift module and avoids import errors.
|
|
98
|
+
if (!fs.existsSync(targetPath)) {
|
|
99
|
+
const stubModule = [
|
|
100
|
+
"import ExpoModulesCore",
|
|
101
|
+
"",
|
|
102
|
+
"public class ReactNativeWidgetExtensionModule: Module {",
|
|
103
|
+
" public func definition() -> ModuleDefinition {",
|
|
104
|
+
' Name("ReactNativeWidgetExtension")',
|
|
105
|
+
" }",
|
|
106
|
+
"}",
|
|
107
|
+
"",
|
|
108
|
+
].join("\n");
|
|
109
|
+
fs.writeFileSync(targetPath, stubModule);
|
|
110
|
+
}
|
|
111
|
+
};
|