Skip to content

Commit

Permalink
fix: Avoid reading plist files twice
Browse files Browse the repository at this point in the history
This will also allow us to drop the read-chunk dependency.
  • Loading branch information
dpogue committed Aug 23, 2024
1 parent 0e08dae commit b1383dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion spec/ConfigChanges/ConfigChanges.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ describe('config-changes module', function () {

const munger = new configChanges.PlatformMunger('ios', temp, platformJson, pluginInfoProvider);
munger.process(plugins_dir);
expect(spy).toHaveBeenCalledWith(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'), 'utf8');
expect(spy).toHaveBeenCalledWith(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'));
});

it('Test 026 : should move successfully installed plugins from queue to installed plugins section, and include/retain vars if applicable', function () {
Expand Down
18 changes: 10 additions & 8 deletions src/ConfigChanges/ConfigFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

const fs = require('node:fs');
const path = require('node:path');
const util = require('node:util');
const readChunk = require('read-chunk');

// Use delay loading to ensure plist and other node modules to not get loaded
Expand Down Expand Up @@ -73,13 +74,13 @@ class ConfigFile {
} else {
// plist file
this.type = 'plist';
// TODO: isBinaryPlist() reads the file and then parse re-reads it again.
// We always write out text plist, not binary.
// Do we still need to support binary plist?
// If yes, use plist.parseStringSync() and read the file once.
this.data = isBinaryPlist(filepath)
? modules.bplist.parseBuffer(fs.readFileSync(filepath))[0]
: modules.plist.parse(fs.readFileSync(filepath, 'utf8'));

const fileData = fs.readFileSync(filepath);
if (fileData.toString('utf8', 0, 6) === 'bplist') {
this.data = modules.bplist.parseBuffer(fileData)[0];
} else {
this.data = modules.plist.parse(fileData.toString('utf8'));
}
}
}

Expand Down Expand Up @@ -273,11 +274,12 @@ function getIOSProjectname (project_dir) {

// determine if a plist file is binary
// i.e. they start with the magic header "bplist"
// TODO: Remove in next major
function isBinaryPlist (filename) {
return readChunk.sync(filename, 0, 6).toString() === 'bplist';
}

module.exports = ConfigFile;
module.exports.isBinaryPlist = isBinaryPlist;
module.exports.isBinaryPlist = util.deprecate(isBinaryPlist, 'isBinaryPlist is deprecated');
module.exports.getIOSProjectname = getIOSProjectname;
module.exports.resolveConfigFilePath = resolveConfigFilePath;

0 comments on commit b1383dc

Please sign in to comment.