Merge pull request #12623 from matheusccastroo/cordova-commands-release-3.0

Adapt missing parts to async in cordova commands.
This commit is contained in:
Gabriel Grubba
2023-06-02 09:46:18 -03:00
committed by GitHub
17 changed files with 47 additions and 99 deletions

View File

@@ -16,7 +16,6 @@ async function createProjectContext(appDir) {
const projectContext = new ProjectContext({
projectDir: appDir
});
await projectContext.init();
await main.captureAndExit('=> Errors while initializing project:', async () => {
// We're just reading metadata here; we don't need to resolve constraints.
await projectContext.readProjectMetadata();
@@ -148,8 +147,8 @@ main.registerCommand({
name: 'list-platforms',
requiresApp: true,
catalogRefresh: new catalog.Refresh.Never()
}, function (options) {
const projectContext = createProjectContext(options.appDir);
}, async function (options) {
const projectContext = await createProjectContext(options.appDir);
const installedPlatforms = projectContext.platformList.getPlatforms();

View File

@@ -155,7 +155,6 @@ var getTempContext = async function (options) {
explicitlyAddedLocalPackageDirs: currentPackageDir
});
}
await projectContext.init();
// It is possible that we can't process package.js files in our local packages
// and have to exit early. This is unfortunate, but we can't search local

View File

@@ -104,7 +104,6 @@ main.registerCommand({
neverWritePackageMap: true,
allowIncompatibleUpdate: options['allow-incompatible-update']
});
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", async function () {
await projectContext.initializeCatalog();
});
@@ -150,7 +149,6 @@ main.registerCommand({
projectDir: options.appDir,
allowIncompatibleUpdate: options['allow-incompatible-update']
});
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", async function () {
await projectContext.prepareProjectForBuild();
@@ -303,7 +301,6 @@ main.registerCommand({
lintPackageWithSourceRoot: options['no-lint'] ? null : options.packageDir,
});
}
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", async function () {
// Just get up to initializing the catalog. We're going to mutate the
@@ -644,7 +641,6 @@ main.registerCommand({
forceIncludeCordovaUnibuild: true,
allowIncompatibleUpdate: options['allow-incompatible-update']
});
await projectContext.init()
// Just get up to initializing the catalog. We're going to mutate the
// constraints file a bit before we prepare the build.
await main.captureAndExit("=> Errors while initializing project:", async function () {
@@ -863,7 +859,6 @@ main.registerCommand({
// though this temporary directory does not have any cordova platforms
forceIncludeCordovaUnibuild: true
});
await projectContext.init();
// Read metadata and initialize catalog.
await main.captureAndExit("=> Errors while building for release:", async function () {
await projectContext.initializeCatalog();
@@ -1178,7 +1173,6 @@ main.registerCommand({
projectDir: options.appDir,
allowIncompatibleUpdate: options['allow-incompatible-update']
});
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", async function () {
return await projectContext.prepareProjectForBuild();
@@ -1627,7 +1621,6 @@ var maybeUpdateRelease = async function (options) {
alwaysWritePackageMap: true,
allowIncompatibleUpdate: true // disregard `.meteor/versions` if necessary
});
await projectContext.init()
await main.captureAndExit("=> Errors while initializing project:", async function () {
await projectContext.readProjectMetadata();
});
@@ -1837,7 +1830,6 @@ main.registerCommand({
alwaysWritePackageMap: true,
allowIncompatibleUpdate: options["allow-incompatible-update"]
});
await projectContext.init()
await main.captureAndExit("=> Errors while initializing project:", async function () {
await projectContext.readProjectMetadata();
});
@@ -2053,7 +2045,6 @@ main.registerCommand({
projectDir: options.appDir,
allowIncompatibleUpdate: options['allow-incompatible-update']
});
await projectContext.init()
await main.captureAndExit("=> Errors while initializing project:", async function () {
await projectContext.prepareProjectForBuild();
});
@@ -2122,7 +2113,6 @@ main.registerCommand({
// though this temporary directory does not have any cordova platforms
forceIncludeCordovaUnibuild: true
});
await projectContext.init()
// Read metadata and initialize catalog.
await main.captureAndExit("=> Errors while building for release:", async function () {
await projectContext.initializeCatalog();
@@ -2162,8 +2152,6 @@ main.registerCommand({
allowIncompatibleUpdate: options["allow-incompatible-update"]
});
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", async function () {
// We're just reading metadata here --- we're not going to resolve
// constraints until after we've made our changes.
@@ -2371,7 +2359,6 @@ main.registerCommand({
projectDir: options.appDir,
allowIncompatibleUpdate: options["allow-incompatible-update"]
});
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", async function () {
// We're just reading metadata here --- we're not going to resolve

View File

@@ -362,7 +362,6 @@ async function doRunCommand(options) {
lintAppAndLocalPackages: !options['no-lint'],
includePackages: includePackages,
});
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", function () {
// We're just reading metadata here --- we'll wait to do the full build
@@ -500,7 +499,6 @@ main.registerCommand({
var projectContext = new projectContextModule.ProjectContext({
projectDir: options.appDir
});
await projectContext.init();
// Convert to OS path here because shell/server.js doesn't know how to
// convert paths, since it exists in the app and in the tool.
@@ -847,8 +845,6 @@ main.registerCommand({
allowIncompatibleUpdate: true
});
await projectContext.init();
await main.captureAndExit("=> Errors while creating your project", async function () {
await projectContext.readProjectMetadata();
if (buildmessage.jobHasMessages()) {
@@ -1049,7 +1045,6 @@ var buildCommand = async function (options) {
serverArchitectures: _.uniq([bundleArch, archinfo.host()]),
allowIncompatibleUpdate: options['allow-incompatible-update']
});
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", function () {
// TODO Fix the nested Profile.run warning here, without interfering
@@ -1327,7 +1322,6 @@ main.registerCommand({
allowIncompatibleUpdate: options['allow-incompatible-update'],
lintPackageWithSourceRoot: packageDir
});
await projectContext.init()
await main.captureAndExit("=> Errors while setting up package:",
// Read metadata and initialize catalog.
@@ -1353,7 +1347,6 @@ main.registerCommand({
allowIncompatibleUpdate: options['allow-incompatible-update'],
lintAppAndLocalPackages: true
});
await projectContext.init()
}
@@ -1623,7 +1616,6 @@ async function deployCommand(options, { rawOptions }) {
serverArchitectures: _.uniq([buildArch, archinfo.host()]),
allowIncompatibleUpdate: options['allow-incompatible-update']
});
await projectContext.init()
await main.captureAndExit("=> Errors while initializing project:", function () {
// TODO Fix nested Profile.run warning here, too.
return projectContext.prepareProjectForBuild();
@@ -1948,7 +1940,6 @@ async function doTestCommand(options) {
// repeated test-packages calls with some sort of shared or semi-shared
// isopack cache that's specific to test-packages? See #3012.
projectContext = new projectContextModule.ProjectContext(projectContextOptions);
await projectContext.init();
await main.captureAndExit("=> Errors while initializing project:", function () {
// We're just reading metadata here --- we'll wait to do the full build
@@ -2041,7 +2032,6 @@ async function doTestCommand(options) {
await copyDirIntoTestRunnerApp(true, '.meteor', 'local', 'shell');
projectContext = new projectContextModule.ProjectContext(projectContextOptions);
await projectContext.init();
await main.captureAndExit("=> Errors while setting up tests:", async function () {
// Read metadata and initialize catalog.
@@ -2826,7 +2816,7 @@ main.registerCommand({
throw new main.ExitWithCode(2);
}
files.cp_r(assetsPath(), files.pathResolve(scaffoldPath), {
await files.cp_r(assetsPath(), files.pathResolve(scaffoldPath), {
transformFilename: function (f) {
if (options.replaceFn) return userTransformFilenameFn(f);
return transformName(f);

View File

@@ -245,11 +245,11 @@ export class CordovaBuilder {
if (files.exists(controlFilePath)) {
Console.debug('Processing mobile-config.js');
await buildmessage.enterJob({ title: `processing mobile-config.js` }, () => {
await buildmessage.enterJob({ title: `processing mobile-config.js` }, async () => {
const code = files.readFile(controlFilePath, 'utf8');
try {
files.runJavaScript(code, {
await files.runJavaScript(code, {
filename: 'mobile-config.js',
symbols: { App: createAppConfiguration(this) }
});
@@ -260,7 +260,7 @@ export class CordovaBuilder {
}
}
writeConfigXmlAndCopyResources(shouldCopyResources = true) {
async writeConfigXmlAndCopyResources(shouldCopyResources = true) {
let config = XmlBuilder.create({ version: '1.0' }).ele('widget');
// Set the root attributes
@@ -341,7 +341,7 @@ export class CordovaBuilder {
}
if (shouldCopyResources) {
// Prepare the resources folder
files.rm_recursive(this.resourcesPath);
await files.rm_recursive(this.resourcesPath);
files.mkdir_p(this.resourcesPath);
Console.debug('Copying resources for mobile apps');
@@ -614,14 +614,14 @@ export class CordovaBuilder {
return boilerplate.toHTMLAsync();
}
copyBuildOverride() {
async copyBuildOverride() {
const buildOverridePath =
files.pathJoin(this.projectContext.projectDir, 'cordova-build-override');
if (files.exists(buildOverridePath) &&
files.stat(buildOverridePath).isDirectory()) {
Console.debug('Copying over the cordova-build-override directory');
files.cp_r(buildOverridePath, this.projectRoot);
await files.cp_r(buildOverridePath, this.projectRoot);
}
}
}

View File

@@ -41,8 +41,8 @@ export function ensureDevBundleDependencies() {
title: 'Installing Cordova in Meteor tool',
},
async () => {
await require("../cli/dev-bundle-helpers.js")
.ensureDependencies(CORDOVA_DEV_BUNDLE_VERSIONS);
await (require("../cli/dev-bundle-helpers.js")
.ensureDependencies(CORDOVA_DEV_BUNDLE_VERSIONS));
const cordovaNodeModulesDir = pathJoin(
getDevBundle(),

View File

@@ -158,7 +158,7 @@ export class CordovaProject {
outdated platforms`);
// Remove Cordova project directory to start afresh
// and avoid a broken project
files.rm_recursive(this.projectRoot);
await files.rm_recursive(this.projectRoot);
}
}
@@ -195,7 +195,7 @@ outdated platforms`);
}
// Don't copy resources (they will be copied as part of the prepare)
builder.writeConfigXmlAndCopyResources(false);
await builder.writeConfigXmlAndCopyResources(false);
// Create the Cordova project root directory
files.mkdir_p(files.pathDirname(this.projectRoot));
@@ -271,7 +271,7 @@ outdated platforms`);
return;
}
builder.writeConfigXmlAndCopyResources();
await builder.writeConfigXmlAndCopyResources();
await builder.copyWWW(bundlePath);
await this.ensurePluginsAreSynchronized(pluginVersions,
@@ -291,7 +291,7 @@ outdated platforms`);
'LD_RUNPATH_SEARCH_PATHS = @executable_path/Frameworks;');
}
builder.copyBuildOverride();
await builder.copyBuildOverride();
}
async prepareForPlatform(platform, options) {
@@ -348,11 +348,7 @@ ${displayNameForPlatform(platform)}`, async () => {
await this.runCommands(
`running Cordova app for platform \
${displayNameForPlatform(platform)} with options ${options}`,
async () => {
await cordova_lib.run(commandOptions);
}
);
() => cordova_lib.run(commandOptions));
}
// Platforms

View File

@@ -32,7 +32,7 @@ export class iOSRunTarget extends CordovaRunTarget {
await cordovaProject.run(this.platform, this.isDevice, undefined);
// Bring iOS Simulator to front (it is called Simulator in Xcode 7)
execFileAsync('osascript', ['-e',
await execFileAsync('osascript', ['-e',
`tell application "System Events"
set possibleSimulatorNames to {"iOS Simulator", "Simulator"}
repeat with possibleSimulatorName in possibleSimulatorNames
@@ -102,7 +102,7 @@ export class AndroidRunTarget extends CordovaRunTarget {
let target = this.isDevice ? "-d" : "-e";
// Clear logs
execFileAsync('adb', [target, 'logcat', '-c']);
await execFileAsync('adb', [target, 'logcat', '-c']);
await cordovaProject.run(this.platform, this.isDevice);

View File

@@ -73,7 +73,6 @@ export class CordovaRunner {
buildmessage.assertInCapture();
await buildmessage.enterJob({ title: "preparing Cordova project" }, async () => {
// TODO -> Cordova Setup
await this.cordovaProject.prepareFromAppBundle(bundlePath,
pluginVersions, options);

View File

@@ -124,6 +124,7 @@ function ProjectContext(options) {
throw Error("missing projectDir!");
self.originalOptions = options;
self.reset();
}
exports.ProjectContext = ProjectContext;
@@ -139,11 +140,7 @@ var STAGE = {
};
Object.assign(ProjectContext.prototype, {
init: function () {
const self = this;
return self.reset();
},
reset: async function (moreOptions, resetOptions) {
reset: function (moreOptions, resetOptions) {
var self = this;
// Allow overriding some options until the next call to reset;
var options = Object.assign({}, self.originalOptions, moreOptions);

View File

@@ -170,10 +170,6 @@ class Runner {
runLog.log("Started proxy.", { arrow: true });
}
/**
*
* @type {(function(): *)}
*/
var unblockAppRunner = self.appRunner.makeBeforeStartPromise();
function startMongo(tries = 3) {
@@ -185,7 +181,7 @@ class Runner {
const left = tries + (tries === 1 ? " try" : " tries");
Console.log(`Error starting Mongo (${left} left): ${error.message}`);
if (tries > 0) {
await self.mongoRunner.stop();
self.mongoRunner.stop();
setTimeout(() => startMongo(tries), 1000);
} else {
await self.mongoRunner._fail();
@@ -208,9 +204,7 @@ class Runner {
}
if (! self.stopped) {
await buildmessage.enterJob({ title: "starting your app" }, async function () {
await self.appRunner.start();
});
await buildmessage.enterJob({ title: "starting your app" }, () => self.appRunner.start());
if (! self.quiet && ! self.stopped) {
runLog.log("Started your app.", { arrow: true });
}
@@ -402,7 +396,7 @@ exports.run = async function (options) {
var runner = new Runner(runOptions);
await runner.init();
// don't wait this on to finish
runner.start();
setTimeout(() => runner.start(), 0);
var result = await promise;
await runner.stop();

View File

@@ -104,7 +104,7 @@ Object.assign(AppProcess.prototype, {
// Watch for exit and for stdio to be fully closed (so that we don't miss
// log lines).
self.proc.on('close', async function (code, signal) {
self._maybeCallOnExit(code, signal);
await self._maybeCallOnExit(code, signal);
});
self.proc.on('error', async function (err) {
@@ -113,7 +113,7 @@ Object.assign(AppProcess.prototype, {
// node docs say that it might make both an 'error' and a
// 'close' callback, so we use a guard to make sure we only call
// onExit once.
self._maybeCallOnExit();
await self._maybeCallOnExit();
});
// This happens sometimes when we write a keepalive after the app
@@ -123,13 +123,13 @@ Object.assign(AppProcess.prototype, {
self.proc.stdin.on('error', function () {});
},
_maybeCallOnExit: function (code, signal) {
_maybeCallOnExit: async function (code, signal) {
var self = this;
if (self.madeExitCallback) {
return;
}
self.madeExitCallback = true;
self.onExit && self.onExit(code, signal);
self.onExit && await self.onExit(code, signal);
},
// Idempotent. Once stop() returns it is guaranteed that you will
@@ -404,7 +404,9 @@ Object.assign(AppRunner.prototype, {
self.startPromise = self._makePromise("start");
self.isRunning = true;
self._runApp().catch((e) => self._resolvePromise("start", e));
global.asyncLocalStorage.run({}, () =>
self._runApp().catch((e) => self._resolvePromise("start", e))
);
await self.startPromise;
self.startPromise = null;
},
@@ -416,12 +418,6 @@ Object.assign(AppRunner.prototype, {
return this._promiseResolvers[name];
},
_makeIterable : function (name) {
var self = this;
const ee = self._findCachedEE(name);
return on(ee, name);
},
/**
* @param name
* @return {Promise<[any]>}
@@ -527,7 +523,7 @@ Object.assign(AppRunner.prototype, {
// to how the WatchSets are laid out. Might be possible to avoid
// re-building the local catalog at all if packages didn't change
// at all, though.)
await self.projectContext.reset({}, {
self.projectContext.reset({}, {
// Don't forget all Isopack objects; just make sure to check that they
// are up to date.
softRefreshIsopacks: true,
@@ -539,9 +535,7 @@ Object.assign(AppRunner.prototype, {
// shown from the previous solution.
preservePackageMap: true
});
var messages = await buildmessage.capture(async function () {
return await self.projectContext.readProjectMetadata();
});
var messages = await buildmessage.capture(() => self.projectContext.readProjectMetadata());
if (messages.hasMessages()) {
return {
runResult: {
@@ -565,9 +559,7 @@ Object.assign(AppRunner.prototype, {
};
}
messages = await buildmessage.capture(async function () {
return await self.projectContext.prepareProjectForBuild();
});
messages = await buildmessage.capture(() => self.projectContext.prepareProjectForBuild());
if (messages.hasMessages()) {
return {
runResult: {
@@ -591,8 +583,8 @@ Object.assign(AppRunner.prototype, {
});
}
var bundleResult = await Profile.run((firstRun?"B":"Reb")+"uild App", async function() {
return await bundler.bundle({
var bundleResult = await Profile.run((firstRun?"B":"Reb")+"uild App", async () =>
bundler.bundle({
projectContext: self.projectContext,
outputPath: bundlePath,
includeNodeModules: "symlink",
@@ -607,8 +599,7 @@ Object.assign(AppRunner.prototype, {
// None of the targets are used during full rebuilds
// so we can safely build in place on Windows
forceInPlaceBuild: !cachedServerWatchSet
});
});
}));
// Keep the server watch set from the initial bundle, because subsequent
// bundles will not contain a server target.
@@ -685,7 +676,6 @@ Object.assign(AppRunner.prototype, {
if (!cordovaRunner.started) {
const { settingsFile, mobileServerUrl } = self;
const messages = await buildmessage.capture(async () => {
// TODO -> Check cordova
await cordovaRunner.prepareProject(bundlePath, pluginVersions,
{ settingsFile, mobileServerUrl });
});
@@ -728,7 +718,7 @@ Object.assign(AppRunner.prototype, {
var listenPromise = self._makePromise("listen");
// Run the program
options.beforeRun && options.beforeRun();
options.beforeRun && await options.beforeRun();
var appProcess = new AppProcess({
projectContext: self.projectContext,
bundlePath: bundlePath,
@@ -970,7 +960,7 @@ Object.assign(AppRunner.prototype, {
});
firstRun = false;
var wantExit = self.onRunEnd ? !self.onRunEnd(runResult) : false;
var wantExit = self.onRunEnd ? !(await self.onRunEnd(runResult)) : false;
if (wantExit || self.exitPromise || runResult.outcome === "stopped") {
break;
}

View File

@@ -543,7 +543,7 @@ var launchMongo = async function(options) {
require('../tool-env/cleanup.js').onExit(stop);
subHandles.push({ stop });
var procExitHandler = await fiberHelpers.bindEnvironment(async function(code, signal) {
var procExitHandler = fiberHelpers.bindEnvironment(async function(code, signal) {
// Defang subHandle.stop().
proc = null;
@@ -973,7 +973,7 @@ Object.assign(MRp, {
if (self.errorCount < 3) {
// Wait a second, then restart.
self.restartTimer = await setTimeout(
self.restartTimer = setTimeout(
fiberHelpers.bindEnvironment(async function() {
self.restartTimer = null;
await self._startOrRestart();
@@ -1061,10 +1061,10 @@ Object.assign(MRp, {
}
},
_fail: function() {
_fail: async function() {
var self = this;
self.stop();
self.onFailure && self.onFailure();
self.onFailure && await self.onFailure();
self._allowStartupToReturn();
},

View File

@@ -71,7 +71,7 @@ Object.assign(Proxy.prototype, {
allowStart = resolve;
});
self.server.on('error', function (err) {
self.server.on('error', async function (err) {
if (err.code === 'EADDRINUSE') {
var port = self.listenPort;
runLog.log(
@@ -92,7 +92,7 @@ Object.assign(Proxy.prototype, {
} else {
runLog.log('' + err);
}
self.onFailure();
await self.onFailure();
allowStart();
});

View File

@@ -33,8 +33,6 @@ var makeProjectContext = async function (appName) {
projectDir: projectDir
});
await projectContext.init();
await doOrThrow(async function () {
await projectContext.prepareProjectForBuild();
});

View File

@@ -27,7 +27,6 @@ var makeProjectContext = async function (appName) {
var projectContext = new projectContextModule.ProjectContext({
projectDir: projectDir
});
await projectContext.init();
await doOrThrow(async function () {
await projectContext.prepareProjectForBuild();
});

View File

@@ -35,9 +35,9 @@ selftest.define("wipe all packages", ['slow', 'custom-warehouse'], async functio
containsPlugins: false
};
};
var meteorToolBuild = async function (v) {
var meteorToolBuild = function (v) {
return {
buildArchitectures: await archinfo.host(),
buildArchitectures: archinfo.host(),
versionId: 'VID' + v.replace(/\./g, ''),
_id: utils.randomToken()
};
@@ -50,7 +50,7 @@ selftest.define("wipe all packages", ['slow', 'custom-warehouse'], async functio
collections: {
packages: [],
versions: [meteorToolVersion('33.0.1'), meteorToolVersion('33.0.2'), meteorToolVersion('33.0.3')],
builds: [await meteorToolBuild('33.0.1'), await meteorToolBuild('33.0.2'), await meteorToolBuild('33.0.3')],
builds: [meteorToolBuild('33.0.1'), meteorToolBuild('33.0.2'), meteorToolBuild('33.0.3')],
releaseTracks: [],
releaseVersions: []
}