Skip to content

Commit 1152e8c

Browse files
committed
fix(e2e): use CLI subprocess for diff instead of in-process require
The in-process require of lib/diff.js + calling diffCommands.hdiff() was hanging because yauzl's async entry callbacks don't keep the Node.js event loop alive properly when called from a script that has no other active handles. Switched to running diff commands as CLI subprocesses via runPushy(), matching the pattern already used for bundleTo(). Each diff command runs in its own node process with a proper event loop. Also removed the DiffCommandRunner type and lib/diff.js require since they're no longer needed.
1 parent 1f715b4 commit 1152e8c

1 file changed

Lines changed: 15 additions & 71 deletions

File tree

Example/e2etest/scripts/prepare-local-update-artifacts.ts

Lines changed: 15 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@ import {
99
LOCAL_UPDATE_LABELS,
1010
} from '../e2e/localUpdateConfig';
1111

12-
type DiffCommandRunner = {
13-
hdiff: (options: {
14-
args: [string, string];
15-
options: {
16-
output: string;
17-
customDiff: (...args: unknown[]) => unknown;
18-
};
19-
}) => Promise<void>;
20-
hdiffFromApk: (options: {
21-
args: [string, string];
22-
options: {
23-
output: string;
24-
customDiff: (...args: unknown[]) => unknown;
25-
};
26-
}) => Promise<void>;
27-
};
28-
2912
const projectRoot = process.cwd();
3013
const platform = process.env.E2E_PLATFORM || 'ios';
3114
const artifactsRoot = path.join(projectRoot, '.e2e-artifacts');
@@ -65,9 +48,6 @@ if (!binRelative) {
6548
);
6649
}
6750
const cliEntry = path.join(cliRoot, binRelative);
68-
const { diffCommands } = require(path.join(cliRoot, 'lib/diff.js')) as {
69-
diffCommands: DiffCommandRunner;
70-
};
7151

7252
if (!['ios', 'android'].includes(platform)) {
7353
throw new Error(`Unsupported E2E_PLATFORM: ${platform}`);
@@ -100,41 +80,6 @@ function runPushy(args: string[], cwd: string) {
10080
}
10181
}
10282

103-
function ensureHdiffModule() {
104-
const modulePath = path.join(cliRoot, 'node_modules/node-hdiffpatch');
105-
if (!fs.existsSync(modulePath)) {
106-
console.log('node-hdiffpatch not found, installing...');
107-
const result = spawnSync(
108-
'npm',
109-
[
110-
'install',
111-
'--no-save',
112-
'--package-lock=false',
113-
'--legacy-peer-deps',
114-
'node-hdiffpatch',
115-
],
116-
{
117-
cwd: cliRoot,
118-
stdio: 'inherit',
119-
env: process.env,
120-
},
121-
);
122-
123-
if (result.status !== 0) {
124-
throw new Error(
125-
`npm install node-hdiffpatch failed with exit code ${result.status}`,
126-
);
127-
}
128-
}
129-
if (!fs.existsSync(modulePath)) {
130-
throw new Error(`Failed to install node-hdiffpatch under: ${cliRoot}`);
131-
}
132-
const hdiffModule = require(modulePath) as {
133-
diff?: (...args: unknown[]) => unknown;
134-
} & ((...args: unknown[]) => unknown);
135-
return hdiffModule.diff || hdiffModule;
136-
}
137-
13883
function prepareDir() {
13984
fs.rmSync(artifactsDir, { recursive: true, force: true });
14085
fs.mkdirSync(artifactsDir, { recursive: true });
@@ -171,16 +116,11 @@ async function main() {
171116
bundleTo('e2e/entry.v2.ts', v2);
172117
bundleTo('e2e/entry.v3.ts', v3);
173118

174-
const customDiff = ensureHdiffModule();
175-
176119
console.log('Generating ppk diff...');
177-
await diffCommands.hdiff({
178-
args: [v1, v2],
179-
options: {
180-
output: ppkDiff,
181-
customDiff,
182-
},
183-
});
120+
runPushy(
121+
['hdiff', v1, v2, '--output', ppkDiff, '--no-interactive'],
122+
projectRoot,
123+
);
184124
console.log('Ppk diff generated.');
185125

186126
if (platform === 'android') {
@@ -197,13 +137,17 @@ async function main() {
197137

198138
fs.copyFileSync(apkPath, path.join(artifactsDir, LOCAL_UPDATE_FILES.apk));
199139
console.log('Generating package diff...');
200-
await diffCommands.hdiffFromApk({
201-
args: [apkPath, v3],
202-
options: {
203-
output: path.join(artifactsDir, LOCAL_UPDATE_FILES.packageDiff),
204-
customDiff,
205-
},
206-
});
140+
runPushy(
141+
[
142+
'hdiffFromApk',
143+
apkPath,
144+
v3,
145+
'--output',
146+
path.join(artifactsDir, LOCAL_UPDATE_FILES.packageDiff),
147+
'--no-interactive',
148+
],
149+
projectRoot,
150+
);
207151
console.log('Package diff generated.');
208152
}
209153

0 commit comments

Comments
 (0)