Skip to content

Commit daaff5f

Browse files
committed
chore(post-script): skip view manager updates when views dir is missing
Add fs.stat import and wrap view-manager processing in a try/catch to detect when the generated views directory doesn't exist. This prevents errors for modules without views and makes the Android workaround more robust.
1 parent 2ae7691 commit daaff5f

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

post-script.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
const path = require('node:path')
1010
const { writeFile, readFile } = require('node:fs/promises')
1111
const { readdir } = require('node:fs/promises')
12+
const { stat } = require('node:fs/promises')
1213

1314
const updateViewManagerFiles = async (file) => {
1415
const viewManagerFile = path.join(
@@ -34,24 +35,33 @@ const androidWorkaround = async () => {
3435
'SensitiveInfoOnLoad.cpp'
3536
)
3637

37-
const viewManagerDir = await readdir(
38-
path.join(
39-
process.cwd(),
40-
'nitrogen/generated/android/kotlin/com/margelo/nitro/sensitiveinfo/views'
41-
)
42-
)
43-
const viewManagerFiles = viewManagerDir.filter((file) =>
44-
file.endsWith('Manager.kt')
45-
)
46-
const res = await Promise.allSettled(
47-
viewManagerFiles.map(updateViewManagerFiles)
38+
const viewManagerDirPath = path.join(
39+
process.cwd(),
40+
'nitrogen/generated/android/kotlin/com/margelo/nitro/sensitiveinfo/views'
4841
)
4942

50-
if (res.some((r) => r.status === 'rejected')) {
51-
throw new Error(`Error updating view manager files: ${res}`)
43+
// Check if views directory exists (only for modules with views)
44+
try {
45+
await stat(viewManagerDirPath)
46+
// Views directory exists, process view manager files
47+
const viewManagerDir = await readdir(viewManagerDirPath)
48+
const viewManagerFiles = viewManagerDir.filter((file) =>
49+
file.endsWith('Manager.kt')
50+
)
51+
const res = await Promise.allSettled(
52+
viewManagerFiles.map(updateViewManagerFiles)
53+
)
54+
55+
if (res.some((r) => r.status === 'rejected')) {
56+
throw new Error(`Error updating view manager files: ${res}`)
57+
}
58+
} catch (error) {
59+
// Views directory doesn't exist, skip view manager processing
60+
console.log('No views directory found, skipping view manager updates')
5261
}
5362

5463
const str = await readFile(androidOnLoadFile, { encoding: 'utf8' })
5564
await writeFile(androidOnLoadFile, str.replace(/margelo\/nitro\//g, ''))
5665
}
66+
5767
androidWorkaround()

0 commit comments

Comments
 (0)