Skip to content

Commit

Permalink
[TIMOB-25883] iOS - "Callback was already called." error thrown when …
Browse files Browse the repository at this point in the history
…source contains ES6 error (#9969)

* Fix [TIMOB-25883] iOS - "Callback was already called." error thrown when source contains ES6 error

* Spit out the awesome error message we get from babel as context
  • Loading branch information
sgtcoolguy committed May 1, 2018
1 parent 282d61f commit 745d4f1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 43 deletions.
55 changes: 32 additions & 23 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2718,32 +2718,41 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
// Read the possibly modified file contents
const source = r.contents;
// Analyze Ti API usage, possibly also minify/transpile
const modified = jsanalyze.analyzeJs(source, {
filename: from,
minify: this.minifyJS,
transpile: this.transpile,
targets: {
chrome: this.chromeVersion
}
});
const newContents = modified.contents;
try {
const modified = jsanalyze.analyzeJs(source, {
filename: from,
minify: this.minifyJS,
transpile: this.transpile,
targets: {
chrome: this.chromeVersion
}
});
const newContents = modified.contents;

// we want to sort by the "to" filename so that we correctly handle file overwriting
this.tiSymbols[to] = modified.symbols;
// we want to sort by the "to" filename so that we correctly handle file overwriting
this.tiSymbols[to] = modified.symbols;

const dir = path.dirname(to);
fs.existsSync(dir) || wrench.mkdirSyncRecursive(dir);
const dir = path.dirname(to);
fs.existsSync(dir) || wrench.mkdirSyncRecursive(dir);

if (symlinkFiles && newContents === originalContents) {
this.logger.debug(__('Copying %s => %s', from.cyan, to.cyan));
copyFile.call(this, from, to, cb2);
} else {
// TODO If dest file exists and contents match, don't do anything?
this.logger.debug(__('Writing modified contents to %s', to.cyan));
// if it exists, wipe it first, as it may be a symlink back to the original, and updating that would be BAD.
// See TIMOB-25875
fs.existsSync(to) && fs.unlinkSync(to);
fs.writeFile(to, newContents, cb2);
if (symlinkFiles && newContents === originalContents) {
this.logger.debug(__('Copying %s => %s', from.cyan, to.cyan));
copyFile.call(this, from, to, cb2);
} else {
// TODO If dest file exists and contents match, don't do anything?
this.logger.debug(__('Writing modified contents to %s', to.cyan));
// if it exists, wipe it first, as it may be a symlink back to the original, and updating that would be BAD.
// See TIMOB-25875
fs.existsSync(to) && fs.unlinkSync(to);
fs.writeFile(to, newContents, cb2);
}
} catch (err) {
err.message.split('\n').forEach(this.logger.error);
if (err.codeFrame) { // if we have a nicely formatted pointer to syntax error from babel, use it!
this.logger.log(err.codeFrame);
}
this.logger.log();
process.exit(1);
}
})(r, from, to, cb);
})(from, to, done);
Expand Down
50 changes: 30 additions & 20 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5809,27 +5809,37 @@ iOSBuilder.prototype.copyResources = function copyResources(next) {
analyzeOptions.targets = { ios: this.minSupportedIosSdk }; // if using jscore, target our min ios version
} // if not jscore, just transpile everything down (no target)

const modified = jsanalyze.analyzeJs(source, analyzeOptions);
const newContents = modified.contents;

// we want to sort by the "to" filename so that we correctly handle file overwriting
this.tiSymbols[to] = modified.symbols;

const dir = path.dirname(to);
fs.existsSync(dir) || wrench.mkdirSyncRecursive(dir);

const exists = fs.existsSync(to);
// dest doesn't exist, or new contents differs from existing dest file
if (!exists || newContents !== fs.readFileSync(to).toString()) {
this.logger.debug(__('Copying and minifying %s => %s', from.cyan, to.cyan));
exists && fs.unlinkSync(to);
fs.writeFileSync(to, newContents);
this.jsFilesChanged = true;
} else {
this.logger.trace(__('No change, skipping %s', to.cyan));
try {
const modified = jsanalyze.analyzeJs(source, analyzeOptions);
const newContents = modified.contents;

// we want to sort by the "to" filename so that we correctly handle file overwriting
this.tiSymbols[to] = modified.symbols;

const dir = path.dirname(to);
fs.existsSync(dir) || wrench.mkdirSyncRecursive(dir);

const exists = fs.existsSync(to);
// dest doesn't exist, or new contents differs from existing dest file
if (!exists || newContents !== fs.readFileSync(to).toString()) {
this.logger.debug(__('Copying and minifying %s => %s', from.cyan, to.cyan));
exists && fs.unlinkSync(to);
fs.writeFileSync(to, newContents);
this.jsFilesChanged = true;
} else {
this.logger.trace(__('No change, skipping %s', to.cyan));
}
cb2();
} catch (err) {
err.message.split('\n').forEach(this.logger.error);
if (err.codeFrame) { // if we have a nicely formatted pointer to syntax error from babel, use it!
this.logger.log(err.codeFrame);
}
this.logger.log();
process.exit(1);
} finally {
this.unmarkBuildDirFile(to);
}
this.unmarkBuildDirFile(to);
cb2();
})(r, from, to, cb);
})(info.src, info.dest, next);
} catch (ex) {
Expand Down

0 comments on commit 745d4f1

Please sign in to comment.