Skip to content

Commit a201e38

Browse files
committed
feat: compare plistUpdates and id options to only change if needs to
Helps prevent unnecessary full native build (only a webpack build which is quicker).
1 parent fa79964 commit a201e38

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

packages/nx/src/executors/build/executor.ts

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,42 @@ export default async function runExecutor(options: BuildBuilderSchema, context:
220220
});
221221
};
222222

223-
const checkOptions = function () {
224-
if (options.id) {
225-
// set custom app bundle id before running the app
226-
const child = childProcess.spawn(/^win/.test(process.platform) ? 'ns.cmd' : 'ns', ['config', 'set', `${options.platform}.id`, options.id], {
223+
const checkAppId = function () {
224+
return new Promise((resolve) => {
225+
const child = childProcess.spawn(/^win/.test(process.platform) ? 'ns.cmd' : 'ns', ['config', 'get', `id`], {
227226
cwd: projectCwd,
228-
stdio: 'inherit',
227+
});
228+
child.stdout.setEncoding('utf8');
229+
child.stdout.on('data', function (data) {
230+
// ensure no newline chars at the end
231+
const appId = (data || '').toString().replace('\n', '').replace('\r', '');
232+
// console.log('existing app id:', appId);
233+
resolve(appId);
229234
});
230235
child.on('close', (code) => {
231236
child.kill('SIGKILL');
232-
runCommand();
233237
});
238+
});
239+
};
240+
241+
const checkOptions = function () {
242+
if (options.id) {
243+
// only modify app id if doesn't match (modifying nativescript.config will cause full native build)
244+
checkAppId().then(id => {
245+
if (options.id !== id) {
246+
// set custom app bundle id before running the app
247+
const child = childProcess.spawn(/^win/.test(process.platform) ? 'ns.cmd' : 'ns', ['config', 'set', `${options.platform}.id`, options.id], {
248+
cwd: projectCwd,
249+
stdio: 'inherit',
250+
});
251+
child.on('close', (code) => {
252+
child.kill('SIGKILL');
253+
runCommand();
254+
});
255+
} else {
256+
runCommand();
257+
}
258+
})
234259
} else {
235260
runCommand();
236261
}
@@ -252,12 +277,32 @@ export default async function runExecutor(options: BuildBuilderSchema, context:
252277
}
253278
const plistFile = parse(readFileSync(plistPath, 'utf8'));
254279
const plistUpdates = options.plistUpdates[filepath];
280+
// check if updates are needed to avoid native build if not needed
281+
let needsUpdate = false;
255282
for (const key in plistUpdates) {
256-
plistFile[key] = plistUpdates[key];
257-
console.log(`Updating ${filepath}: ${key}=${plistFile[key]}`);
283+
if (Array.isArray(plistUpdates[key])) {
284+
try {
285+
// compare stringified
286+
const plistString = JSON.stringify(plistFile[key] || {});
287+
const plistUpdateString = JSON.stringify(plistUpdates[key]);
288+
if (plistString !== plistUpdateString) {
289+
plistFile[key] = plistUpdates[key];
290+
console.log(`Updating ${filepath}: ${key}=`, plistFile[key]);
291+
needsUpdate = true;
292+
}
293+
} catch (err) {
294+
console.log(`plist file parse error:`, err);
295+
}
296+
} else if (plistFile[key] !== plistUpdates[key]) {
297+
plistFile[key] = plistUpdates[key];
298+
console.log(`Updating ${filepath}: ${key}=${plistFile[key]}`);
299+
needsUpdate = true;
300+
}
301+
}
302+
if (needsUpdate) {
303+
writeFileSync(plistPath, build(plistFile));
304+
console.log(`Updated: ${plistPath}`);
258305
}
259-
writeFileSync(plistPath, build(plistFile));
260-
console.log(`Updated: ${plistPath}`);
261306
}
262307
}
263308

0 commit comments

Comments
 (0)