diff --git a/packages/webapp/.npm/package/npm-shrinkwrap.json b/packages/webapp/.npm/package/npm-shrinkwrap.json index d76c33b1dc..da6538edb6 100644 --- a/packages/webapp/.npm/package/npm-shrinkwrap.json +++ b/packages/webapp/.npm/package/npm-shrinkwrap.json @@ -404,11 +404,6 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" }, - "posix": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/posix/-/posix-4.2.0.tgz", - "integrity": "sha512-JbxfT0Fxy/SG10LSkKX1C75iULYfAJqYCwwmM6J0+zh2vl/bE51CqaqvSpdZWg7YAwiuDIoBI6j7in+n3GgXSw==" - }, "promise-polyfill": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-1.1.6.tgz", diff --git a/scripts/build-dev-bundle-common.sh b/scripts/build-dev-bundle-common.sh index 6928825c20..21429dce98 100644 --- a/scripts/build-dev-bundle-common.sh +++ b/scripts/build-dev-bundle-common.sh @@ -40,6 +40,8 @@ elif [ "$UNAME" == "Darwin" ] ; then echo "Meteor only supports x86_64 for now." exit 1 fi + else + NODE_BUILD_NUMBER="${NODE_BUILD_NUMBER:="187"}" fi OS="macos" diff --git a/tools/cli/commands-packages.js b/tools/cli/commands-packages.js index c0b04dce47..3c5f7b70e8 100644 --- a/tools/cli/commands-packages.js +++ b/tools/cli/commands-packages.js @@ -36,12 +36,12 @@ import { updateMeteorToolSymlink } from "../packaging/updater.js"; // Specifically, it returns an object with the following keys: // - record : (a package or version record) // - isRelease : true if it is a release instead of a package. -var getReleaseOrPackageRecord = function(name) { - var rec = catalog.official.getPackage(name); +var getReleaseOrPackageRecord = async function(name) { + var rec = await catalog.official.getPackage(name); var rel = false; if (!rec) { // Not a package! But is it a release track? - rec = catalog.official.getReleaseTrack(name); + rec = await catalog.official.getReleaseTrack(name); if (rec) { rel = true; } @@ -51,8 +51,9 @@ var getReleaseOrPackageRecord = function(name) { // Seriously, this dies if it can't refresh. Only call it if you're sure you're // OK that the command doesn't work while offline. -var refreshOfficialCatalogOrDie = function (options) { - if (!catalog.refreshOrWarn(options)) { +var refreshOfficialCatalogOrDie = async function (options) { + const isUpToDate = await catalog.refreshOrWarn(options); + if (!isUpToDate) { Console.error( "This command requires an up-to-date package catalog. Exiting."); throw new main.ExitWithCode(1); @@ -175,7 +176,7 @@ var updatePackageMetadata = async function (packageSource, conn) { // You can't change the metadata of a record that doesn't exist. var existingRecord = - catalog.official.getVersion(name, version); + await catalog.official.getVersion(name, version); if (! existingRecord) { Console.error( "You can't call", Console.command("`meteor publish --update`"), @@ -219,7 +220,7 @@ var updatePackageMetadata = async function (packageSource, conn) { "outside the current project directory."); // Refresh, so that we actually learn about the thing we just published. - refreshOfficialCatalogOrDie(); + await refreshOfficialCatalogOrDie(); return 0; }; @@ -302,7 +303,6 @@ main.registerCommand({ lintPackageWithSourceRoot: options['no-lint'] ? null : options.packageDir, }); } - await projectContext.init(); await main.captureAndExit("=> Errors while initializing project:", async function () { @@ -311,10 +311,11 @@ main.registerCommand({ await projectContext.initializeCatalog(); }); + let conn; if (!process.env.METEOR_TEST_NO_PUBLISH) { // Connect to the package server and log in. try { - var conn = packageClient.loggedInPackagesConnection(); + conn = await packageClient.loggedInPackagesConnection(); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; @@ -363,7 +364,7 @@ main.registerCommand({ // Fail early if the package record exists, but we don't think that it does // and are passing in the --create flag! if (options.create) { - var packageInfo = catalog.official.getPackage(packageName); + var packageInfo = await catalog.official.getPackage(packageName); if (packageInfo) { Console.error( "Package already exists. To create a new version of an existing "+ @@ -413,7 +414,7 @@ main.registerCommand({ // package's test and all the test's dependencies. if (!options['no-lint']) { - const warnings = projectContext.getLintingMessagesForLocalPackages(); + const warnings = await projectContext.getLintingMessagesForLocalPackages(); if (warnings && warnings.hasMessages()) { Console.arrowError( "Errors linting your package; run with --no-lint to ignore."); @@ -461,7 +462,7 @@ main.registerCommand({ // We are only publishing one package, so we should close the connection, and // then exit with the previous error code. - conn.close(); + await conn.close(); // Warn the user if their package is not good for all architectures. if (binary && options['existing-version']) { @@ -491,7 +492,7 @@ main.registerCommand({ } // Refresh, so that we actually learn about the thing we just published. - refreshOfficialCatalogOrDie(); + await refreshOfficialCatalogOrDie(); return 0; }); @@ -517,7 +518,7 @@ main.registerCommand({ var name = all[0]; var versionString = all[1]; - var packageInfo = catalog.official.getPackage(name); + var packageInfo = await catalog.official.getPackage(name); if (! packageInfo) { Console.error( "You can't call " + Console.command("`meteor publish-for-arch`") + @@ -532,7 +533,7 @@ main.registerCommand({ return 1; } - var pkgVersion = catalog.official.getVersion(name, versionString); + var pkgVersion = await catalog.official.getVersion(name, versionString); if (! pkgVersion) { Console.error( "You can't call", Console.command("`meteor publish-for-arch`"), @@ -595,8 +596,8 @@ main.registerCommand({ // or we're running from the same release as the published package. // Download the source to the package. - var sourceTarball = buildmessage.enterJob("downloading package source", function () { - return httpHelpers.getUrlWithResuming({ + var sourceTarball = await buildmessage.enterJob("downloading package source", async function () { + return await httpHelpers.getUrlWithResuming({ url: pkgVersion.source.url, encoding: null }); @@ -607,9 +608,9 @@ main.registerCommand({ } var sourcePath = files.mkdtemp('package-source'); - buildmessage.enterJob("extracting package source", () => { + await buildmessage.enterJob("extracting package source", async () => { // XXX check tarballHash! - files.extractTarGz(sourceTarball, sourcePath); + await files.extractTarGz(sourceTarball, sourcePath); }); // XXX Factor out with packageClient.bundleSource so that we don't @@ -643,6 +644,7 @@ 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 () { @@ -664,7 +666,7 @@ main.registerCommand({ var conn; try { - conn = packageClient.loggedInPackagesConnection(); + conn = await packageClient.loggedInPackagesConnection(); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; @@ -682,7 +684,7 @@ main.registerCommand({ Console.info('Published ' + name + '@' + versionString + '.'); - refreshOfficialCatalogOrDie(); + await refreshOfficialCatalogOrDie(); return 0; }); @@ -709,10 +711,11 @@ main.registerCommand({ }, catalogRefresh: new catalog.Refresh.OnceAtStart({ ignoreErrors: false }) }, async function (options) { + let conn try { - var conn = packageClient.loggedInPackagesConnection(); + conn = await packageClient.loggedInPackagesConnection(); } catch (err) { - packageClient.handlePackageServerConnectionError(err); + await packageClient.handlePackageServerConnectionError(err); return 1; } @@ -800,7 +803,7 @@ main.registerCommand({ // authorized to publish before we do any complicated/long operations, and // before we publish its packages. if (! options['create-track']) { - var trackRecord = catalog.official.getReleaseTrack(relConf.track); + var trackRecord = await catalog.official.getReleaseTrack(relConf.track); if (!trackRecord) { Console.error( 'There is no release track named ' + relConf.track + @@ -810,7 +813,7 @@ main.registerCommand({ // Check with the server to see if we're organized (we can't due this // locally due to organizations). - if (!packageClient.amIAuthorized(relConf.track,conn, true)) { + if (!await packageClient.amIAuthorized(relConf.track, conn, true)) { Console.error('You are not an authorized maintainer of ' + relConf.track + "."); Console.error('Only authorized maintainers may publish new versions.'); @@ -860,7 +863,7 @@ 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(); @@ -888,9 +891,9 @@ main.registerCommand({ relConf.packages = {}; var toPublish = []; - await main.captureAndExit("=> Errors in release packages:", function () { - _.each(allPackages, function (packageName) { - buildmessage.enterJob("checking consistency of " + packageName, function () { + await main.captureAndExit("=> Errors in release packages:", async function () { + for (const packageName of allPackages) { + await buildmessage.enterJob("checking consistency of " + packageName, async function () { var packageSource = projectContext.localCatalog.getPackageSource( packageName); if (! packageSource) { @@ -907,7 +910,7 @@ main.registerCommand({ // Let's get the server version that this local package is // overwriting. If such a version exists, we will need to make sure // that the contents are the same. - var oldVersionRecord = catalog.official.getVersion( + var oldVersionRecord = await catalog.official.getVersion( packageName, packageSource.version); // Include this package in our release. @@ -943,7 +946,7 @@ main.registerCommand({ // First try with the non-simplified build architecture // list, which is likely to be something like // os+web.browser+web.browser.legacy+web.cordova: - catalog.official.getBuildWithPreciseBuildArchitectures( + await catalog.official.getBuildWithPreciseBuildArchitectures( oldVersionRecord, isopk.buildArchitectures(), ) || @@ -951,7 +954,7 @@ main.registerCommand({ // list (e.g. os+web.browser+web.cordova), to match packages // published before the web.browser.legacy architecture was // introduced (in Meteor 1.7). - catalog.official.getBuildWithPreciseBuildArchitectures( + await catalog.official.getBuildWithPreciseBuildArchitectures( oldVersionRecord, isopk.buildArchitectures(true), ); @@ -972,7 +975,7 @@ main.registerCommand({ // new release is being published. packageName === "meteor-tool") { // Save the isopack, just to get its hash. - var bundleBuildResult = packageClient.bundleBuild( + var bundleBuildResult = await packageClient.bundleBuild( isopk, projectContext.isopackCache, ); @@ -988,7 +991,7 @@ main.registerCommand({ } } }); - }); + } }); if (options['dry-run']) { @@ -1003,11 +1006,11 @@ main.registerCommand({ // We now have an object of packages that have new versions on disk that // don't exist in the server catalog. Publish them. var unfinishedBuilds = {}; - _.each(toPublish, async function (packageName) { + for (const packageName of toPublish) { await main.captureAndExit( "=> Errors while publishing:", "publishing package " + packageName, - function () { + async function () { var isopk = projectContext.isopackCache.getIsopack(packageName); if (! isopk) { throw Error("no isopack for " + packageName); @@ -1019,17 +1022,16 @@ main.registerCommand({ } var binary = isopk.platformSpecific(); - packageClient.publishPackage({ + await packageClient.publishPackage({ projectContext: projectContext, packageSource: packageSource, connection: conn, - new: ! catalog.official.getPackage(packageName), + new: ! await catalog.official.getPackage(packageName), doNotPublishBuild: binary }); if (buildmessage.jobHasMessages()) { return; } - Console.info( 'Published ' + packageName + '@' + packageSource.version + '.'); @@ -1037,7 +1039,7 @@ main.registerCommand({ unfinishedBuilds[packageName] = packageSource.version; } }); - }); + } // Set the remaining release information. For now, when we publish from // checkout, we always set 'meteor-tool' as the tool. We don't include the @@ -1054,16 +1056,16 @@ main.registerCommand({ if (options['create-track']) { // XXX maybe this job title should be left on the screen too? some sort // of enterJob/progress option that lets you do that? - await buildmessage.enterJob("creating a new release track", function () { - packageClient.callPackageServerBM( - conn, 'createReleaseTrack', { name: relConf.track } ); + await buildmessage.enterJob("creating a new release track", async function () { + await packageClient.callPackageServerBM( + conn, 'createReleaseTrack', { name: relConf.track }); }); if (buildmessage.jobHasMessages()) { return; } } - await buildmessage.enterJob("creating a new release version", function () { + await buildmessage.enterJob("creating a new release version", async function () { var record = { track: relConf.track, version: relConf.version, @@ -1075,10 +1077,10 @@ main.registerCommand({ }; if (relConf.patchFrom) { - packageClient.callPackageServerBM( + await packageClient.callPackageServerBM( conn, 'createPatchReleaseVersion', record, relConf.patchFrom); } else { - packageClient.callPackageServerBM( + await packageClient.callPackageServerBM( conn, 'createReleaseVersion', record); } }); @@ -1086,7 +1088,7 @@ main.registerCommand({ ); // Learn about it. - refreshOfficialCatalogOrDie(); + await refreshOfficialCatalogOrDie(); Console.info("Done creating " + relConf.track + "@" + relConf.version + "!"); Console.info(); @@ -1103,13 +1105,13 @@ main.registerCommand({ Console.info("Skipping git tag: bad format for git."); } else { Console.info("Creating git tag " + gitTag); - utils.runGitInCheckout('tag', gitTag); + await utils.runGitInCheckout('tag', gitTag); var fail = false; try { Console.info( "Pushing git tag (this should fail if you are not from Meteor Software)"); - utils.runGitInCheckout('push', 'git@github.com:meteor/meteor.git', - 'refs/tags/' + gitTag); + await utils.runGitInCheckout('push', 'git@github.com:meteor/meteor.git', + 'refs/tags/' + gitTag); } catch (err) { Console.error( "Failed to push git tag. Please push git tag manually!"); @@ -1167,8 +1169,8 @@ main.registerCommand({ }); await projectContext.init(); - await main.captureAndExit("=> Errors while initializing project:", function () { - return projectContext.prepareProjectForBuild(); + await main.captureAndExit("=> Errors while initializing project:", async function () { + return await projectContext.prepareProjectForBuild(); }); // No need to display the PackageMapDelta here, since we're about to list all @@ -1493,7 +1495,7 @@ var maybeUpdateRelease = async function (options) { // XXX better error checking on release.current.name // XXX add a method to release.current. var releaseTrack = release.current ? - release.current.getReleaseTrack() : catalog.DEFAULT_TRACK; + await release.current.getReleaseTrack() : catalog.DEFAULT_TRACK; // Unless --release was passed (in which case we ought to already have // springboarded to that release), go get the latest release and switch to @@ -1612,6 +1614,7 @@ 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(); }); @@ -1647,7 +1650,7 @@ var maybeUpdateRelease = async function (options) { "Cannot patch update unless a release is set."); return 1; } - var record = catalog.official.getReleaseVersion( + var record = await catalog.official.getReleaseVersion( projectContext.releaseFile.releaseTrack, projectContext.releaseFile.releaseVersion); if (!record) { @@ -1661,7 +1664,7 @@ var maybeUpdateRelease = async function (options) { "You are at the latest patch version."); return 0; } - var patchRecord = catalog.official.getReleaseVersion( + var patchRecord = await catalog.official.getReleaseVersion( projectContext.releaseFile.releaseTrack, updateTo); // It looks like you are not at the latest patch version, // technically. But, in practice, we cannot update you to the latest patch @@ -1686,7 +1689,7 @@ var maybeUpdateRelease = async function (options) { // We are not doing a patch update, or a specific release update, so we need // to try all recommended releases on our track, whose order key is greater // than the app's. - releaseVersion = getLaterReleaseVersions( + releaseVersion = await getLaterReleaseVersions( projectContext.releaseFile.releaseTrack, projectContext.releaseFile.releaseVersion)[0]; @@ -1714,7 +1717,7 @@ var maybeUpdateRelease = async function (options) { // Update every package in .meteor/packages to be (semver)>= the version // set for that package in the release we are updating to - var releaseRecord = catalog.official.getReleaseVersion(releaseTrack, releaseVersion); + var releaseRecord = await catalog.official.getReleaseVersion(releaseTrack, releaseVersion); projectContext.projectConstraintsFile.updateReleaseConstraints(releaseRecord); // Download and build packages and write the new versions to .meteor/versions. @@ -1750,12 +1753,12 @@ var maybeUpdateRelease = async function (options) { return 0; }; -function getLaterReleaseVersions(releaseTrack, releaseVersion) { - var releaseInfo = catalog.official.getReleaseVersion( +async function getLaterReleaseVersions(releaseTrack, releaseVersion) { + var releaseInfo = await catalog.official.getReleaseVersion( releaseTrack, releaseVersion); var orderKey = (releaseInfo && releaseInfo.orderKey) || null; - return catalog.official.getSortedRecommendedReleaseVersions( + return await catalog.official.getSortedRecommendedReleaseVersions( releaseTrack, orderKey); } @@ -1818,6 +1821,7 @@ main.registerCommand({ alwaysWritePackageMap: true, allowIncompatibleUpdate: options["allow-incompatible-update"] }); + await projectContext.init() await main.captureAndExit("=> Errors while initializing project:", async function () { await projectContext.readProjectMetadata(); }); @@ -1868,7 +1872,7 @@ main.registerCommand({ var releaseRecordForConstraints = null; if (! files.inCheckout() && projectContext.releaseFile.normalReleaseSpecified()) { - releaseRecordForConstraints = catalog.official.getReleaseVersion( + releaseRecordForConstraints = await catalog.official.getReleaseVersion( projectContext.releaseFile.releaseTrack, projectContext.releaseFile.releaseVersion); if (! releaseRecordForConstraints) { @@ -1906,7 +1910,7 @@ main.registerCommand({ } // Try to resolve constraints, allowing the given packages to be upgraded. - projectContext.reset({ + await projectContext.reset({ releaseForConstraints: releaseRecordForConstraints, upgradePackageNames: upgradePackageNames, upgradeIndirectDepPatchVersions: upgradeIndirectDepPatchVersions @@ -2033,6 +2037,7 @@ 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(); }); @@ -2056,7 +2061,7 @@ main.registerCommand({ hidden: true, catalogRefresh: new catalog.Refresh.Never() }, async function (options) { - updater.tryToDownloadUpdate({ + await updater.tryToDownloadUpdate({ showBanner: true, printErrors: true }); @@ -2101,7 +2106,7 @@ 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(); @@ -2112,14 +2117,14 @@ main.registerCommand({ Console.info("Listing packages where the checkout version doesn't match the", "latest version on the package server."); - _.each(allPackages, function (packageName) { - var checkoutVersion = projectContext.localCatalog.getLatestVersion(packageName).version; - var remoteLatestVersion = catalog.official.getLatestVersion(packageName).version; + for (const packageName of allPackages) { + var checkout = projectContext.localCatalog.getLatestVersion(packageName); + var remote = await catalog.official.getLatestVersion(packageName); - if (checkoutVersion !== remoteLatestVersion) { - Console.info(packageName, checkoutVersion, remoteLatestVersion); + if (checkout.version !== remote.version) { + Console.info(packageName, checkout.version, remote.version); } - }); + } }); /////////////////////////////////////////////////////////////////////////////// @@ -2143,10 +2148,10 @@ main.registerCommand({ await projectContext.init(); - await main.captureAndExit("=> Errors while initializing project:", function () { + 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. - return projectContext.initializeCatalog(); + return await projectContext.initializeCatalog(); }); let exitCode = 0; @@ -2352,10 +2357,10 @@ main.registerCommand({ }); await projectContext.init(); - await main.captureAndExit("=> Errors while initializing project:", function () { + 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. - return projectContext.readProjectMetadata(); + return await projectContext.readProjectMetadata(); }); let exitCode = 0; @@ -2493,12 +2498,12 @@ main.registerCommand({ } // Now let's get down to business! Fetching the thing. - var fullRecord = getReleaseOrPackageRecord(name); + var fullRecord = await getReleaseOrPackageRecord(name); var record = fullRecord.record; if (!options.list) { try { - var conn = packageClient.loggedInPackagesConnection(); + var conn = await packageClient.loggedInPackagesConnection(); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; @@ -2508,19 +2513,19 @@ main.registerCommand({ if (options.add) { Console.info("Adding a maintainer to " + name + "..."); if (fullRecord.release) { - packageClient.callPackageServer( + await packageClient.callPackageServer( conn, 'addReleaseMaintainer', name, options.add); } else { - packageClient.callPackageServer( + await packageClient.callPackageServer( conn, 'addMaintainer', name, options.add); } } else if (options.remove) { Console.info("Removing a maintainer from " + name + "..."); if (fullRecord.release) { - packageClient.callPackageServer( + await packageClient.callPackageServer( conn, 'removeReleaseMaintainer', name, options.remove); } else { - packageClient.callPackageServer( + await packageClient.callPackageServer( conn, 'removeMaintainer', name, options.remove); } Console.info("Success."); @@ -2533,8 +2538,8 @@ main.registerCommand({ // Update the catalog so that we have this information, and find the record // again so that the message below is correct. - refreshOfficialCatalogOrDie(); - fullRecord = getReleaseOrPackageRecord(name); + await refreshOfficialCatalogOrDie(); + fullRecord = await getReleaseOrPackageRecord(name); record = fullRecord.record; } @@ -2605,7 +2610,7 @@ main.registerCommand({ var toolPackage = toolPackageVersion.package; var toolVersion = toolPackageVersion.version; - var toolPkgBuilds = catalog.official.getAllBuilds( + var toolPkgBuilds = await catalog.official.getAllBuilds( toolPackage, toolVersion); if (!toolPkgBuilds) { // XXX this could also mean package unknown. @@ -2672,11 +2677,11 @@ main.registerCommand({ var tmpDataFile = files.pathJoin(dataTmpdir, 'packages.data.db'); var tmpCatalog = new catalogRemote.RemoteCatalog(); - tmpCatalog.initialize({ + await tmpCatalog.initialize({ packageStorage: tmpDataFile }); try { - packageClient.updateServerPackageData(tmpCatalog, null); + await packageClient.updateServerPackageData(tmpCatalog, null); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 2; @@ -2686,8 +2691,8 @@ main.registerCommand({ // so we should ensure that once it is downloaded, it knows it is recommended // rather than having a little identity crisis and thinking that a past // release is the latest recommended until it manages to sync. - tmpCatalog.forceRecommendRelease(releaseTrack, releaseVersion); - tmpCatalog.closePermanently(); + await tmpCatalog.forceRecommendRelease(releaseTrack, releaseVersion); + await tmpCatalog.closePermanently(); if (files.exists(tmpDataFile + '-wal')) { throw Error("Write-ahead log still exists for " + tmpDataFile + " so the data file will be incomplete!"); @@ -2746,9 +2751,9 @@ main.registerCommand({ 'meteor')); if (options.unpacked) { - files.cp_r(tmpTropo.root, outputDirectory); + await files.cp_r(tmpTropo.root, outputDirectory); } else { - files.createTarball( + await files.createTarball( tmpTropo.root, files.pathJoin(outputDirectory, 'meteor-bootstrap-' + osArch + '.tar.gz')); @@ -2784,14 +2789,14 @@ main.registerCommand({ } try { - var conn = packageClient.loggedInPackagesConnection(); + var conn = await packageClient.loggedInPackagesConnection(); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; } try { - packageClient.callPackageServer( + await packageClient.callPackageServer( conn, 'setBannersOnReleases', bannersData.track, bannersData.banners); } catch (e) { @@ -2800,7 +2805,7 @@ main.registerCommand({ } // Refresh afterwards. - refreshOfficialCatalogOrDie(); + await refreshOfficialCatalogOrDie(); return 0; }); @@ -2825,7 +2830,7 @@ main.registerCommand({ } // Now let's get down to business! Fetching the thing. - var record = catalog.official.getReleaseTrack(name); + var record = await catalog.official.getReleaseTrack(name); if (!record) { Console.error(); Console.error('There is no release track named ' + name); @@ -2842,13 +2847,13 @@ main.registerCommand({ try { if (options.unrecommend) { Console.info("Unrecommending " + name + "@" + version + "..."); - packageClient.callPackageServer( + await packageClient.callPackageServer( conn, 'unrecommendVersion', name, version); Console.info("Success."); Console.info(name + "@" + version, "is no longer a recommended release"); } else { Console.info("Recommending " + options.args[0] + "..."); - packageClient.callPackageServer(conn, 'recommendVersion', name, version); + await packageClient.callPackageServer(conn, 'recommendVersion', name, version); Console.info("Success."); Console.info(name + "@" + version, "is now a recommended release"); } @@ -2856,8 +2861,8 @@ main.registerCommand({ packageClient.handlePackageServerConnectionError(err); return 1; } - conn.close(); - refreshOfficialCatalogOrDie(); + await conn.close(); + await refreshOfficialCatalogOrDie(); return 0; }); @@ -2876,7 +2881,7 @@ main.registerCommand({ var url = options.args[1]; // Now let's get down to business! Fetching the thing. - var record = catalog.official.getPackage(name); + var record = await catalog.official.getPackage(name); if (!record) { Console.error(); Console.error('There is no package named ' + name); @@ -2884,7 +2889,7 @@ main.registerCommand({ } try { - var conn = packageClient.loggedInPackagesConnection(); + var conn = await packageClient.loggedInPackagesConnection(); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; @@ -2894,15 +2899,15 @@ main.registerCommand({ Console.rawInfo( "Changing homepage on " + name + " to " + url + "...\n"); - packageClient.callPackageServer(conn, - '_changePackageHomepage', name, url); + await packageClient.callPackageServer(conn, + '_changePackageHomepage', name, url); Console.info(" done"); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; } - conn.close(); - refreshOfficialCatalogOrDie(); + await conn.close(); + await refreshOfficialCatalogOrDie(); return 0; }); @@ -2934,7 +2939,7 @@ main.registerCommand({ } try { - var conn = packageClient.loggedInPackagesConnection(); + var conn = await packageClient.loggedInPackagesConnection(); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; @@ -2958,7 +2963,7 @@ main.registerCommand({ return 1; } conn.close(); - refreshOfficialCatalogOrDie(); + await refreshOfficialCatalogOrDie(); return 0; }); diff --git a/tools/cli/commands.js b/tools/cli/commands.js index 2e09b59734..fc87019683 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -187,8 +187,8 @@ main.registerCommand({ requiresRelease: false, pretty: false, catalogRefresh: new catalog.Refresh.Never() -}, async function () { - Console.rawInfo(await archinfo.host() + "\n"); +}, function () { + Console.rawInfo(archinfo.host() + "\n"); }); // Prints the current release in use. Note that if there is not @@ -1041,11 +1041,11 @@ var buildCommand = async function (options) { showInvalidArchMsg(options.architecture); return 1; } - var bundleArch = options.architecture || await archinfo.host(); + var bundleArch = options.architecture || archinfo.host(); var projectContext = new projectContextModule.ProjectContext({ projectDir: options.appDir, - serverArchitectures: _.uniq([bundleArch, await archinfo.host()]), + serverArchitectures: _.uniq([bundleArch, archinfo.host()]), allowIncompatibleUpdate: options['allow-incompatible-update'] }); await projectContext.init(); @@ -1325,6 +1325,7 @@ 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. @@ -1346,7 +1347,7 @@ main.registerCommand({ if (! projectContext && appDir) { projectContext = new projectContextModule.ProjectContext({ projectDir: appDir, - serverArchitectures: [await archinfo.host()], + serverArchitectures: [archinfo.host()], allowIncompatibleUpdate: options['allow-incompatible-update'], lintAppAndLocalPackages: true }); @@ -1379,7 +1380,7 @@ main.registerCommand({ Console.warn(bundle.warnings.formatMessages()); return 1; } - + console.log(green`=> Done linting.`); return 0; }); @@ -1545,17 +1546,17 @@ main.registerCommand({ }, catalogRefresh: new catalog.Refresh.Never() }, async function (...args) { - return Profile.run( + return await Profile.run( "meteor deploy", - () => Promise.await(deployCommand(...args)) + async () => await deployCommand(...args) ); }); -function deployCommand(options, { rawOptions }) { +async function deployCommand(options, { rawOptions }) { const site = options.args[0]; if (options.delete) { - return deploy.deleteApp(site); + return await deploy.deleteApp(site); } if (options.password) { @@ -1572,7 +1573,8 @@ function deployCommand(options, { rawOptions }) { Console.error( "You must be logged in to deploy, just enter your email address."); Console.error(); - if (! auth.registerOrLogIn()) { + const isRegistered = await auth.registerOrLogIn(); + if (! isRegistered) { return 1; } } @@ -1585,18 +1587,18 @@ function deployCommand(options, { rawOptions }) { "OVERRIDING DEPLOY ARCHITECTURE WITH LOCAL ARCHITECTURE.", "If your app contains binary code, it may break in unexpected " + "and terrible ways."); - buildArch = archinfo.host(); + buildArch = archinfo.host(); } const projectContext = new projectContextModule.ProjectContext({ projectDir: options.appDir, - serverArchitectures: _.uniq([buildArch, archinfo.host()]), + serverArchitectures: _.uniq([buildArch, archinfo.host()]), allowIncompatibleUpdate: options['allow-incompatible-update'] }); - - main.captureAndExit("=> Errors while initializing project:", function () { + await projectContext.init() + await main.captureAndExit("=> Errors while initializing project:", function () { // TODO Fix nested Profile.run warning here, too. - projectContext.prepareProjectForBuild(); + return projectContext.prepareProjectForBuild(); }); projectContext.packageMapDelta.displayOnConsole(); @@ -1623,7 +1625,7 @@ function deployCommand(options, { rawOptions }) { const isBuildOnly = !!options['build-only']; const waitForDeploy = !options['no-wait']; - const deployResult = deploy.bundleAndDeploy({ + const deployResult = await deploy.bundleAndDeploy({ projectContext, site, settingsFile: options.settings, @@ -1642,12 +1644,12 @@ function deployCommand(options, { rawOptions }) { }); if (deployResult === 0) { - auth.maybePrintRegistrationLink({ + await auth.maybePrintRegistrationLink({ leadingNewline: true, // If the user was already logged in at the beginning of the // deploy, then they've already been prompted to set a password // at least once before, so we use a slightly different message. - firstTime: ! loggedIn + firstTime: !loggedIn }); } @@ -1848,7 +1850,7 @@ async function doTestCommand(options) { // Download packages for our architecture, and for the deploy server's // architecture if we're deploying. - const archInfoHost = await archinfo.host(); + const archInfoHost = archinfo.host(); var serverArchitectures = [archInfoHost]; if (options.deploy && DEPLOY_ARCH !== archInfoHost) { serverArchitectures.push(DEPLOY_ARCH); @@ -2251,23 +2253,23 @@ main.registerCommand({ // organizations /////////////////////////////////////////////////////////////////////////////// -var loggedInAccountsConnectionOrPrompt = function (action) { +var loggedInAccountsConnectionOrPrompt = async function (action) { var token = auth.getSessionToken(config.getAccountsDomain()); if (! token) { Console.error("You must be logged in to " + action + "."); - auth.doUsernamePasswordLogin({ retry: true }); + await auth.doUsernamePasswordLogin({ retry: true }); Console.info(); } token = auth.getSessionToken(config.getAccountsDomain()); - var conn = auth.loggedInAccountsConnection(token); + var conn = await auth.loggedInAccountsConnection(token); if (conn === null) { // Server rejected our token. Console.error("You must be logged in to " + action + "."); - auth.doUsernamePasswordLogin({ retry: true }); + await auth.doUsernamePasswordLogin({ retry: true }); Console.info(); token = auth.getSessionToken(config.getAccountsDomain()); - conn = auth.loggedInAccountsConnection(token); + conn = await auth.loggedInAccountsConnection(token); } return conn; @@ -2280,18 +2282,18 @@ main.registerCommand({ maxArgs: 0, pretty: false, catalogRefresh: new catalog.Refresh.Never() -}, function (options) { +}, async function (options) { var token = auth.getSessionToken(config.getAccountsDomain()); if (! token) { Console.error("You must be logged in to list your organizations."); - auth.doUsernamePasswordLogin({ retry: true }); + await auth.doUsernamePasswordLogin({ retry: true }); Console.info(); } var url = config.getAccountsApiUrl() + "/organizations"; try { - var result = httpHelpers.request({ + var result = await httpHelpers.request({ url: url, method: "GET", useSessionHeader: true, @@ -2340,7 +2342,7 @@ main.registerCommand({ return options.add || options.remove; }, catalogRefresh: new catalog.Refresh.Never() -}, function (options) { +}, async function (options) { if (options.add && options.remove) { Console.error( @@ -2350,13 +2352,13 @@ main.registerCommand({ var username = options.add || options.remove; - var conn = loggedInAccountsConnectionOrPrompt( + var conn = await loggedInAccountsConnectionOrPrompt( username ? "edit organizations" : "show an organization's members"); if (username ) { // Adding or removing members try { - conn.call( + await conn.callAsync( options.add ? "addOrganizationMember": "removeOrganizationMember", options.args[0], username); } catch (err) { @@ -2372,7 +2374,7 @@ main.registerCommand({ } else { // Showing the members of an org try { - var result = conn.call("showOrganization", options.args[0]); + var result = await conn.callAsync("showOrganization", options.args[0]); } catch (err) { Console.error("Error showing organization: " + err.reason); return 1; diff --git a/tools/cli/main.js b/tools/cli/main.js index 987e643446..da950062b2 100644 --- a/tools/cli/main.js +++ b/tools/cli/main.js @@ -495,7 +495,7 @@ var springboard = async function (rel, options) { }); if (!toolRecord) { - throw Error("missing tool for " + await archinfo.host() + " in " + + throw Error("missing tool for " + archinfo.host() + " in " + toolsPkg + "@" + toolsVersion); } @@ -1557,7 +1557,8 @@ makeGlobalAsyncLocalStorage().run({}, async function () { } else if (e instanceof main.ExitWithCode) { process.exit(e.code); } else { - throw e; + console.error(e); + process.exit(1); } } diff --git a/tools/fs/files.ts b/tools/fs/files.ts index 3dcf3d9b71..80e17fe774 100644 --- a/tools/fs/files.ts +++ b/tools/fs/files.ts @@ -4,28 +4,12 @@ /// (such as testing whether an directory is a meteor app) /// -import fs, { PathLike, Stats, Dirent } from "fs"; +import fs, { Dirent, PathLike, Stats } from "fs"; import os from "os"; import { execFile } from "child_process"; import { EventEmitter } from "events"; import { Slot } from "@wry/context"; import { dep } from "optimism"; - -const _ = require('underscore'); - -const rimraf = require('rimraf'); -const sourcemap = require('source-map'); -const sourceMapRetrieverStack = require('../tool-env/source-map-retriever-stack.js'); - -const utils = require('../utils/utils.js'); -const cleanup = require('../tool-env/cleanup.js'); -const buildmessage = require('../utils/buildmessage.js'); -const fiberHelpers = require('../utils/fiber-helpers.js'); -const colonConverter = require('../utils/colon-converter.js'); - -const Profile = require('../tool-env/profile').Profile; - -export * from '../static-assets/server/mini-files'; import { convertToOSPath, convertToPosixPath, @@ -43,6 +27,22 @@ import { pathSep, } from "../static-assets/server/mini-files"; +const _ = require('underscore'); + +const rimraf = require('rimraf'); +const sourcemap = require('source-map'); +const sourceMapRetrieverStack = require('../tool-env/source-map-retriever-stack.js'); + +const utils = require('../utils/utils.js'); +const cleanup = require('../tool-env/cleanup.js'); +const buildmessage = require('../utils/buildmessage.js'); +const fiberHelpers = require('../utils/fiber-helpers.js'); +const colonConverter = require('../utils/colon-converter.js'); + +const Profile = require('../tool-env/profile').Profile; + +export * from '../static-assets/server/mini-files'; + const { hasOwnProperty } = Object.prototype; const parsedSourceMaps: Record = {}; @@ -360,17 +360,10 @@ export const rm_recursive = Profile("files.rm_recursive", async (path: string) = export function fileHash(filename: string) { const crypto = require('crypto'); const hash = crypto.createHash('sha256'); - hash.setEncoding('base64'); - const rs = createReadStream(filename); - return new Promise(function (resolve) { - rs.on('end', function () { - rs.close(); - resolve(hash.digest('base64')); - }); - rs.pipe(hash, { end: false }); - }).await(); + const fileBuff = readFile(filename); + hash.update(fileBuff); + return hash.digest('base64'); } - // This is the result of running fileHash on a blank file. export const blankHash = "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="; @@ -385,9 +378,9 @@ export function treeHash(root: string, optionsParams: { ...optionsParams, }; - const hash = require('crypto').createHash('sha256'); + function traverse(relativePath: string) { + const hash = require('crypto').createHash('sha256'); - function traverse(relativePath: string) { if (options.ignore(relativePath)) { return; } @@ -406,8 +399,9 @@ export function treeHash(root: string, optionsParams: { if (!relativePath) { throw Error("must call files.treeHash on a directory"); } + const fileHashed = fileHash(absPath); hash.update('file ' + JSON.stringify(relativePath) + ' ' + - stat?.size + ' ' + fileHash(absPath) + '\n'); + stat?.size + ' ' + fileHashed + '\n'); // @ts-ignore if (stat.mode & 0o100) { @@ -421,9 +415,11 @@ export function treeHash(root: string, optionsParams: { JSON.stringify(readlink(absPath)) + '\n'); } // ignore anything weirder + + return hash } - traverse(''); + const hash = traverse(''); return hash.digest('base64'); } @@ -506,7 +502,7 @@ export async function cp_r(from: string, to: string, options: { if (stat.isDirectory()) { mkdir_p(to, 0o755); - for (const f of readdir(from)) { + for (let f of readdir(from)) { if (options.ignore && options.ignore.some(pattern => f.match(pattern))) { return; diff --git a/tools/fs/safe-watcher.ts b/tools/fs/safe-watcher.ts index 80e5b8b785..cea3d74d7b 100644 --- a/tools/fs/safe-watcher.ts +++ b/tools/fs/safe-watcher.ts @@ -372,9 +372,7 @@ function watchLibraryWatch(absPath: string, callback: EntryCallback) { let suggestedRaisingWatchLimit = false; -// This function is async so that archinfo.host() (which may call -// utils.execFileSync) will run in a Fiber. -async function maybeSuggestRaisingWatchLimit(error: Error & { errno: number }) { +function maybeSuggestRaisingWatchLimit(error: Error & { errno: number }) { var constants = require('constants'); var archinfo = require('../utils/archinfo'); if (! suggestedRaisingWatchLimit && @@ -388,7 +386,7 @@ async function maybeSuggestRaisingWatchLimit(error: Error & { errno: number }) { // proposed PR, which had a slightly different interface). error.errno === constants.ENOSPC && // The only suggestion we currently have is for Linux. - archinfo.matches(await archinfo.host(), 'os.linux')) { + archinfo.matches(archinfo.host(), 'os.linux')) { // Check suggestedRaisingWatchLimit again because archinfo.host() may // have yielded. diff --git a/tools/isobuild/bundler.js b/tools/isobuild/bundler.js index b38da99c78..b1f7a5db33 100644 --- a/tools/isobuild/bundler.js +++ b/tools/isobuild/bundler.js @@ -951,7 +951,7 @@ class Target { if (p.testOnly && this.buildMode !== 'test') { continue; } - const unibuild = await p.getUnibuildAtArch(this.arch); + const unibuild = p.getUnibuildAtArch(this.arch); unibuild && rootUnibuilds.push(unibuild); } @@ -2594,7 +2594,7 @@ class JsImage { ret.arch = json.arch; // Rebuild binary npm packages if host arch matches image arch. - const rebuildBinaries = archinfo.matches(await archinfo.host(), ret.arch); + const rebuildBinaries = archinfo.matches(archinfo.host(), ret.arch); for (const item of json.load) { rejectBadPath(item.path); @@ -3209,7 +3209,7 @@ async function bundle({ }) { buildOptions = buildOptions || {}; - var serverArch = buildOptions.serverArch || await archinfo.host(); + var serverArch = buildOptions.serverArch || archinfo.host(); var webArchs; if (buildOptions.webArchs) { // Don't attempt to build web.cordova when platforms have been removed @@ -3596,7 +3596,7 @@ exports.buildJsImage = Profile("bundler.buildJsImage", async function (options) // cross-bundling, not cross-package-building, and this function is only // used to build plugins (during package build) and for isopack.load // (which always wants to build for the current host). - arch: await archinfo.host() + arch: archinfo.host() }); await target.make({ packages: [isopack] }); diff --git a/tools/isobuild/compiler-plugin.js b/tools/isobuild/compiler-plugin.js index a14c5e79b6..3f368886c9 100644 --- a/tools/isobuild/compiler-plugin.js +++ b/tools/isobuild/compiler-plugin.js @@ -1110,7 +1110,7 @@ export class PackageSourceBatch { self.useMeteorInstall = _.isString(self.sourceRoot) && - await self.processor.isopackCache.uses( + self.processor.isopackCache.uses( self.unibuild.pkg, "modules", self.unibuild.arch diff --git a/tools/isobuild/compiler.js b/tools/isobuild/compiler.js index 477d0aba0b..d9ce37a067 100644 --- a/tools/isobuild/compiler.js +++ b/tools/isobuild/compiler.js @@ -675,7 +675,7 @@ api.addAssets('${relPath}', 'client').`); var arch = inputSourceArch.arch; if (arch === "os" && ! isPortable) { // Contains non-portable compiled npm modules, so set arch correctly - arch = await archinfo.host(); + arch = archinfo.host(); } let nodeModulesDirsOrUndefined = nodeModulesDirectories; @@ -733,7 +733,7 @@ async function runLinters({inputSourceArch, isopackCache, sources, // exists instead of failing because a dependency does not have an 'os' // unibuild. const whichArch = inputSourceArch.arch === 'os' - ? await archinfo.host() : inputSourceArch.arch; + ? archinfo.host() : inputSourceArch.arch; // For linters, figure out what are the global imports from other packages // that we use directly, or are implied. @@ -897,7 +897,7 @@ export async function getActivePluginPackages(isopk, { // and because plugins always have to run on the host architecture. await compiler.eachUsedUnibuild({ dependencies: uses, - arch: await archinfo.host(), + arch: archinfo.host(), isopackCache: isopackCache, skipUnordered: true // implicitly skip weak deps by not specifying acceptableWeakPackages option @@ -971,7 +971,7 @@ compiler.eachUsedUnibuild = async function ( continue; } - var unibuild = await usedPackage.getUnibuildAtArch(arch); + var unibuild = usedPackage.getUnibuildAtArch(arch); if (!unibuild) { // The package exists but there's no unibuild for us. A buildmessage has // already been issued. Recover by skipping. diff --git a/tools/isobuild/isopack-cache.js b/tools/isobuild/isopack-cache.js index 287209aa67..3ae3104dab 100644 --- a/tools/isobuild/isopack-cache.js +++ b/tools/isobuild/isopack-cache.js @@ -140,7 +140,7 @@ export class IsopackCache { return null; } - async uses(isopack, name, arch) { + uses(isopack, name, arch) { if (! isopack) { return false; } @@ -150,13 +150,13 @@ export class IsopackCache { return true; } - const unibuild = await isopack.getUnibuildAtArch(arch); + const unibuild = isopack.getUnibuildAtArch(arch); if (! unibuild) { return false; } for (const use of unibuild.uses) { - const implies = await this.implies( + const implies = this.implies( this._isopacks[use.package], name, arch, @@ -166,7 +166,7 @@ export class IsopackCache { } } - async implies(isopack, name, arch) { + implies(isopack, name, arch) { if (! isopack) { return false; } @@ -176,13 +176,13 @@ export class IsopackCache { return true; } - const unibuild = await isopack.getUnibuildAtArch(arch); + const unibuild = isopack.getUnibuildAtArch(arch); if (! unibuild) { return false; } for (const imp of unibuild.implies) { - const implies = await this.implies( + const implies = this.implies( this._isopacks[imp.package], name, arch, diff --git a/tools/isobuild/isopack.js b/tools/isobuild/isopack.js index af98519409..b1925feaf4 100644 --- a/tools/isobuild/isopack.js +++ b/tools/isobuild/isopack.js @@ -401,7 +401,7 @@ Object.assign(Isopack.prototype, { // Return the unibuild of the package to use for a given target architecture // (eg, 'os.linux.x86_64' or 'web'), or throw an exception if that // packages can't be loaded under these circumstances. - getUnibuildAtArch: Profile("Isopack#getUnibuildAtArch", async function (arch) { + getUnibuildAtArch: Profile("Isopack#getUnibuildAtArch", function (arch) { var self = this; let chosenArch = archinfo.mostSpecificMatch( @@ -412,7 +412,7 @@ Object.assign(Isopack.prototype, { // are processing a local package with binary npm deps). Search // again for the host version, which might find the Mac version. chosenArch = - archinfo.mostSpecificMatch(await archinfo.host(), _.pluck(self.unibuilds, 'arch')); + archinfo.mostSpecificMatch(archinfo.host(), _.pluck(self.unibuilds, 'arch')); } if (! chosenArch) { buildmessage.error( @@ -453,7 +453,7 @@ Object.assign(Isopack.prototype, { for (const [name, pluginsByArch] of Object.entries(self.plugins)) { var arch = archinfo.mostSpecificMatch( - await archinfo.host(), Object.keys(pluginsByArch)); + archinfo.host(), Object.keys(pluginsByArch)); if (! arch) { buildmessage.error("package `" + name + "` is built for incompatible " + "architecture"); @@ -1009,6 +1009,9 @@ Object.assign(Isopack.prototype, { // of this flag is allow us to optimize cases that never need to write the // older format, such as the per-app isopack cache.) // - isopackCache: isopack cache in which this isopack is registered + /** + * @return {Promise} + */ saveToPath: Profile("Isopack#saveToPath", async function (outputDir, { includePreCompilerPluginIsopackVersions, includeIsopackBuildInfo, @@ -1444,7 +1447,7 @@ Object.assign(Isopack.prototype, { }); // Set up builder to write to the correct directory - var toolPath = 'mt-' + await archinfo.host(); + var toolPath = 'mt-' + archinfo.host(); builder = await builder.enter(toolPath); const sourceRootDir = files.getCurrentToolsDir(); @@ -1524,7 +1527,7 @@ Object.assign(Isopack.prototype, { return [{ name: 'meteor', - arch: await archinfo.host(), + arch: archinfo.host(), path: toolPath }]; }), diff --git a/tools/isobuild/unibuild.js b/tools/isobuild/unibuild.js index acd5772413..b6cbc1e7de 100644 --- a/tools/isobuild/unibuild.js +++ b/tools/isobuild/unibuild.js @@ -213,7 +213,7 @@ export class Unibuild { packageName: isopack.name, sourceRoot: unibuildBasePath, // Rebuild binary npm packages if unibuild arch matches host arch. - rebuildBinaries: archinfo.matches(await archinfo.host(), arch) + rebuildBinaries: archinfo.matches(archinfo.host(), arch) }); return new this(isopack, { diff --git a/tools/meteor-services/auth-client.js b/tools/meteor-services/auth-client.js index ef751671c4..382645f387 100644 --- a/tools/meteor-services/auth-client.js +++ b/tools/meteor-services/auth-client.js @@ -50,10 +50,10 @@ exports.handleConnectionError = function (error, label) { // domain: the domain (ex: packages.meteor.com) // sessionType: the name of the connection (ex: "package-server") // -exports.loggedInConnection = function (url, domain, sessionType) { +exports.loggedInConnection = async function (url, domain, sessionType) { // Make sure that we are logged in with Meteor Accounts so that we can // do an OAuth flow. - if (auth.maybePrintRegistrationLink({onlyAllowIfRegistered: true})) { + if (await auth.maybePrintRegistrationLink({ onlyAllowIfRegistered: true })) { // Oops, we're logged in but with a deferred-registration account. // Message has already been printed. throw new exports.AlreadyPrintedMessageError; @@ -65,13 +65,13 @@ exports.loggedInConnection = function (url, domain, sessionType) { "Please log in with your Meteor developer account.", "If you don't have one,", "you can quickly create one at www.meteor.com."); - auth.doUsernamePasswordLogin({ retry: true }); + await auth.doUsernamePasswordLogin({ retry: true }); } - var conn = exports.openServiceConnection(url); - var accountsConfiguration = auth.getAccountsConfiguration(conn); + var conn = await exports.openServiceConnection(url); + var accountsConfiguration = await auth.getAccountsConfiguration(conn); try { - auth.loginWithTokenOrOAuth( + await auth.loginWithTokenOrOAuth( conn, accountsConfiguration, url, @@ -86,8 +86,8 @@ exports.loggedInConnection = function (url, domain, sessionType) { "It looks like you have been logged out!", "Please log in with your Meteor developer account. If you don't have", "one, you can quickly create one at www.meteor.com."); - auth.doUsernamePasswordLogin({ retry: true }); - auth.loginWithTokenOrOAuth( + await auth.doUsernamePasswordLogin({ retry: true }); + await auth.loginWithTokenOrOAuth( conn, accountsConfiguration, url, diff --git a/tools/meteor-services/auth.js b/tools/meteor-services/auth.js index c4d32a8364..50bc2a42d9 100644 --- a/tools/meteor-services/auth.js +++ b/tools/meteor-services/auth.js @@ -46,6 +46,11 @@ var withAccountsConnection = function (f) { // // XXX if we reconnect we won't reauthenticate. Fix that before using // this for long-lived connections. +/** + * + * @param token + * @return {Promise<*>} + */ var loggedInAccountsConnection = async function (token) { var connection = (await loadDDP()).connect( config.getAuthDDPUrl() diff --git a/tools/meteor-services/deploy.js b/tools/meteor-services/deploy.js index ff82422fa0..ca722ec7bb 100644 --- a/tools/meteor-services/deploy.js +++ b/tools/meteor-services/deploy.js @@ -230,7 +230,7 @@ async function authedRpc(options) { suppressErrorMessage: true }; if (await doInteractivePasswordLogin(loginOptions)) { - return authedRpc(options); + return await authedRpc(options); } else { return { statusCode: 403, @@ -241,7 +241,7 @@ async function authedRpc(options) { if (infoResult.statusCode === 404) { // Doesn't exist, therefore not protected. - return preflight ? { } : deployRpc(rpcOptions); + return preflight ? { } : await deployRpc(rpcOptions); } if (infoResult.errorMessage) { @@ -253,7 +253,7 @@ async function authedRpc(options) { // Not protected. // // XXX should prompt the user to claim the app (only if deploying?) - return preflight ? { } : deployRpc(rpcOptions); + return preflight ? { } : await deployRpc(rpcOptions); } if (info.protection === "account") { @@ -281,7 +281,7 @@ async function authedRpc(options) { authorized: info.authorized }; } else { - return deployRpc(rpcOptions); + return await deployRpc(rpcOptions); } } @@ -409,7 +409,7 @@ async function pollForDeploy(pollingState, versionId, site, deployWithTokenProps } = pollingState; // Do a call to the version-status endpoint for the specified versionId - const versionStatusResult = deployRpc({ + const versionStatusResult = await deployRpc({ method: 'GET', operation: 'version-status', site, @@ -509,14 +509,14 @@ export async function bundleAndDeploy(options) { // they'll get an email prompt instead of a username prompt because // the command-line tool didn't have time to learn about their // username before the credential was expired. - pollForRegistrationCompletion({ + await pollForRegistrationCompletion({ noLogout: true }); const promptIfAuthFails = (loggedInUsername() !== null); // Check auth up front, rather than after the (potentially lengthy) // bundling process. - const preflight = authedRpc({ + const preflight = await authedRpc({ site: site, preflight: true, promptIfAuthFails: promptIfAuthFails, @@ -625,7 +625,7 @@ export async function bundleAndDeploy(options) { } if (options.recordPackageUsage) { - recordPackages({ + await recordPackages({ what: "sdk.deploy", projectContext: options.projectContext, site: site @@ -645,10 +645,10 @@ export async function bundleAndDeploy(options) { }; Console.info('Preparing to upload your app...'); - const result = buildmessage.enterJob({ + const result = await buildmessage.enterJob({ title: "uploading" - }, Profile("upload bundle", function () { - return authedRpc({ + }, Profile("upload bundle", async function () { + return await authedRpc({ method: 'POST', operation: 'deploy', site: site, @@ -701,13 +701,13 @@ export async function bundleAndDeploy(options) { return 0; }; -export function deleteApp(site) { +export async function deleteApp(site) { site = canonicalizeSite(site); if (! site) { return 1; } - var result = authedRpc({ + var result = await authedRpc({ method: 'DELETE', operation: 'deploy', site: site, diff --git a/tools/packaging/package-client.js b/tools/packaging/package-client.js index ff6b29de2a..0a10007e06 100644 --- a/tools/packaging/package-client.js +++ b/tools/packaging/package-client.js @@ -49,17 +49,17 @@ var saveReadmeToTmp = async function (readmeInfo) { // Given a connection, makes a call to the package server. (Checks to see if // the connection is connected, and reconnects if needed -- a workaround for // the fact that connections in the tool do not reconnect) -exports.callPackageServer = function (conn, ...args) { +exports.callPackageServer = async function (conn, ...args) { // XXX This is broken since it doesn't actually replace the conn in the // caller, so it'll happen on every subsequent call if (!conn.connected) { conn.close(); - conn = exports.loggedInPackagesConnection(); + conn = await exports.loggedInPackagesConnection(); } return conn.call(...args); }; -var callPackageServerBM = exports.callPackageServerBM = function (...args) { +var callPackageServerBM = exports.callPackageServerBM = async function (...args) { buildmessage.assertInJob(); try { return exports.callPackageServer.apply(null, args); @@ -102,7 +102,7 @@ var loadRemotePackageData = async function (conn, syncToken, options) { if (options && options.compressCollections) { syncOpts.compressCollections = options.compressCollections; } - return conn.call('syncNewPackageData', syncToken, syncOpts); + return await conn.call('syncNewPackageData', syncToken, syncOpts); }; // Contacts the package server to get the latest diff and writes changes to @@ -124,9 +124,9 @@ var loadRemotePackageData = async function (conn, syncToken, options) { // `config.getPackageServerUrl()`) // - useShortPages: Boolean. Request short pages of ~3 records from the // server, instead of ~100 that it would send otherwise -exports.updateServerPackageData = function (dataStore, options) { - return buildmessage.enterJob('updating package catalog', function () { - return _updateServerPackageData(dataStore, options); +exports.updateServerPackageData = async function (dataStore, options) { + return await buildmessage.enterJob('updating package catalog', async function () { + return await _updateServerPackageData(dataStore, options); }); }; @@ -149,7 +149,6 @@ var _updateServerPackageData = async function (dataStore, options) { useProgressbar && buildmessage.reportProgress(state); var conn = await openPackageServerConnection(options.packageServerUrl); - // Provide some progress indication for connection // XXX though it is just a hack state.current = 1; @@ -178,6 +177,7 @@ var _updateServerPackageData = async function (dataStore, options) { compressCollections: compress }); + // Is the remote server telling us to ignore everything we've heard before? // OK, we can do that. if (remoteData.resetData) { @@ -230,15 +230,19 @@ var _updateServerPackageData = async function (dataStore, options) { return ret; }; -_updateServerPackageData = Profile('package-client _updateServerPackageData', - _updateServerPackageData); +_updateServerPackageData = + Profile('package-client _updateServerPackageData', _updateServerPackageData); // Returns a logged-in DDP connection to the package server, or null if // we cannot log in. If an error unrelated to login occurs // (e.g. connection to package server times out), then it will be // thrown. -exports.loggedInPackagesConnection = function () { - return authClient.loggedInConnection( +/** + * + * @return {Promise<*>} + */ +exports.loggedInPackagesConnection = async function () { + return await authClient.loggedInConnection( config.getPackageServerUrl(), config.getPackageServerDomain(), "package-server" @@ -248,7 +252,7 @@ exports.loggedInPackagesConnection = function () { // XXX this is missing a few things. In retrospect a better approach here might // be to actually make "save source somewhere else" or perhaps "add source // to tarball" be part of the package build itself... -var bundleSource = function (isopack, includeSources, packageDir) { +var bundleSource = async function (isopack, includeSources, packageDir) { buildmessage.assertInJob(); var name = isopack.name; @@ -299,14 +303,14 @@ var bundleSource = function (isopack, includeSources, packageDir) { var packageMapFile = new projectContextModule.PackageMapFile({ filename: packageMapFilename }); - packageMapFile.write(pluginProviderPackageMap); + await packageMapFile.write(pluginProviderPackageMap); // We put this inside the temp dir because mkdtemp makes sure that the // temp dir gets cleaned up on process exit, so we don't have to worry // about cleaning up our tarball (or our copied source files) // ourselves. var sourceTarball = files.pathJoin(tempDir, packageTarName + '.tgz'); - files.createTarball(dirToTar, sourceTarball); + await files.createTarball(dirToTar, sourceTarball); var tarballHash = files.fileHash(sourceTarball); var treeHash = files.treeHash(dirToTar); @@ -321,13 +325,13 @@ var bundleSource = function (isopack, includeSources, packageDir) { // Uploads a file at a filepath to the HTTP put URL. // // Returns true on success and false on failure. -var uploadFile = function (putUrl, filepath) { +var uploadFile = async function (putUrl, filepath) { buildmessage.assertInJob(); var size = files.stat(filepath).size; var rs = files.createReadStream(filepath); try { // Use getUrl instead of request, to throw on 4xx/5xx. - httpHelpers.getUrl({ + await httpHelpers.getUrl({ method: 'PUT', url: putUrl, headers: { @@ -350,7 +354,7 @@ var uploadFile = function (putUrl, filepath) { exports.uploadFile = uploadFile; -export function bundleBuild(isopack, isopackCache) { +export async function bundleBuild(isopack, isopackCache) { buildmessage.assertInJob(); var tempDir = files.mkdtemp('bp-'); @@ -361,7 +365,7 @@ export function bundleBuild(isopack, isopackCache) { // disk in an IsopackCache, because we don't want to include // isopack-buildinfo.json. (We don't include it because we're not passing // includeIsopackBuildInfo to saveToPath here.) - isopack.saveToPath(tarInputDir, { + await isopack.saveToPath(tarInputDir, { // When publishing packages that don't use new registerCompiler plugins, // make sure that old Meteors can use it too includePreCompilerPluginIsopackVersions: true, @@ -369,11 +373,10 @@ export function bundleBuild(isopack, isopackCache) { }); var buildTarball = files.pathJoin(tempDir, packageTarName + '.tgz'); + await files.createTarball(tarInputDir, buildTarball); - files.createTarball(tarInputDir, buildTarball); - - var tarballHash = files.fileHash(buildTarball); - var treeHash = files.treeHash(tarInputDir, { + var tarballHash = files.fileHash(buildTarball); + var treeHash = files.treeHash(tarInputDir, { // We don't include any package.json from an npm module in the tree hash, // because npm isn't super consistent about what it puts in there (eg, does // it include the "readme" field)? This ends up leading to spurious @@ -393,15 +396,15 @@ export function bundleBuild(isopack, isopackCache) { }; } -function createBuiltPackage(isopack, isopackCache) { +async function createBuiltPackage(isopack, isopackCache) { buildmessage.assertInJob(); var name = isopack.name; // Note: we really want to do this before createPackageBuild, because the URL // we get from createPackageBuild will expire! var bundleResult; - buildmessage.enterJob("bundling build for " + name, function () { - bundleResult = bundleBuild(isopack, isopackCache); + await buildmessage.enterJob("bundling build for " + name, async function () { + bundleResult = await bundleBuild(isopack, isopackCache); }); if (buildmessage.jobHasMessages()) { return; @@ -410,13 +413,13 @@ function createBuiltPackage(isopack, isopackCache) { return bundleResult; } -var publishBuiltPackage = function (conn, isopack, bundleResult) { +var publishBuiltPackage = async function (conn, isopack, bundleResult) { buildmessage.assertInJob(); var name = isopack.name; var uploadInfo; - buildmessage.enterJob('creating package build for ' + name, function () { - uploadInfo = callPackageServerBM(conn, 'createPackageBuild', { + await buildmessage.enterJob('creating package build for ' + name, async function () { + uploadInfo = await callPackageServerBM(conn, 'createPackageBuild', { packageName: isopack.name, version: isopack.version, buildArchitectures: isopack.buildArchitectures() @@ -426,30 +429,34 @@ var publishBuiltPackage = function (conn, isopack, bundleResult) { return; } - buildmessage.enterJob("uploading build", function () { - uploadFile(uploadInfo.uploadUrl, - bundleResult.buildTarball); + await buildmessage.enterJob("uploading build", async function () { + await uploadFile(uploadInfo.uploadUrl, + bundleResult.buildTarball); }); if (buildmessage.jobHasMessages()) { return; } - buildmessage.enterJob('publishing package build for ' + name, function () { - callPackageServerBM(conn, 'publishPackageBuild', - uploadInfo.uploadToken, - bundleResult.tarballHash, - bundleResult.treeHash); + await buildmessage.enterJob('publishing package build for ' + name, async function () { + try { + await callPackageServerBM(conn, 'publishPackageBuild', + uploadInfo.uploadToken, + bundleResult.tarballHash, + bundleResult.treeHash); + } catch (e) { + buildmessage.error(e.message); + } }); if (buildmessage.jobHasMessages()) { return; } }; -export function createAndPublishBuiltPackage(conn, isopack, isopackCache) { - publishBuiltPackage( +export async function createAndPublishBuiltPackage(conn, isopack, isopackCache) { + await publishBuiltPackage( conn, isopack, - createBuiltPackage(isopack, isopackCache), + await createBuiltPackage(isopack, isopackCache), ); } @@ -469,7 +476,7 @@ exports.handlePackageServerConnectionError = function (error) { // package server. DO NOT CLOSE this connection here. // // Return true on success and an error code otherwise. -exports.updatePackageMetadata = function (options) { +exports.updatePackageMetadata = async function (options) { buildmessage.assertInJob(); var packageSource = options.packageSource; @@ -520,8 +527,8 @@ exports.updatePackageMetadata = function (options) { // Update the general metadata. var versionIdentifier = { packageName: name, version: version }; - buildmessage.enterJob('updating metadata', function () { - callPackageServerBM( + await buildmessage.enterJob('updating metadata', async function () { + await callPackageServerBM( conn, "changeVersionMetadata", versionIdentifier, dataToUpdate); }); if (buildmessage.jobHasMessages()) { @@ -529,17 +536,17 @@ exports.updatePackageMetadata = function (options) { } // Upload the new Readme. - buildmessage.enterJob('uploading documentation', function () { + await buildmessage.enterJob('uploading documentation', async function () { var readmePath = saveReadmeToTmp(readmeInfo); var uploadInfo = - callPackageServerBM(conn, "createReadme", versionIdentifier); - if (! uploadInfo) { + await callPackageServerBM(conn, "createReadme", versionIdentifier); + if (!uploadInfo) { return; } - if (! uploadFile(uploadInfo.url, readmePath)) { + if (!await uploadFile(uploadInfo.url, readmePath)) { return; } - callPackageServerBM( + await callPackageServerBM( conn, "publishReadme", uploadInfo.uploadToken, { hash: readmeInfo.hash }); }); if (buildmessage.jobHasMessages()) { @@ -566,7 +573,7 @@ exports.updatePackageMetadata = function (options) { // - doNotPublishBuild: do not publish the build of this package. // // Return true on success and an error code otherwise. -exports.publishPackage = function (options) { +exports.publishPackage = async function (options) { buildmessage.assertInJob(); var packageSource = options.packageSource; var conn = options.connection; @@ -609,15 +616,14 @@ exports.publishPackage = function (options) { // Check that we are an authorized maintainer of this package. if (!options['new']) { - var packRecord = catalog.official.getPackage(name); + var packRecord = await catalog.official.getPackage(name); if (! packRecord) { buildmessage.error( 'There is no package named ' + name + '. If you are creating a new package, use the --create flag.'); return; } - - if (!exports.amIAuthorized(name, conn, false)) { + if (!await exports.amIAuthorized(name, conn, false)) { buildmessage.error( 'You are not an authorized maintainer of ' + name + '. Only ' + 'authorized maintainers may publish new versions.'); @@ -626,7 +632,7 @@ exports.publishPackage = function (options) { // Check that our documentation exists (or we know that it doesn't) and has // been filled out. - var readmeInfo = buildmessage.enterJob( + var readmeInfo = await buildmessage.enterJob( "processing documentation", function () { return packageSource.processReadme(); @@ -657,10 +663,9 @@ exports.publishPackage = function (options) { if (! readmeInfo) { readmeInfo = generateBlankReadme(); } - var readmePath = saveReadmeToTmp(readmeInfo); + var readmePath = await saveReadmeToTmp(readmeInfo); var packageDeps = packageSource.getDependencyMetadata(); - // Check that the package does not have any unconstrained references. _.each(packageDeps, function(refs, label) { if (refs.constraint == null) { @@ -696,6 +701,7 @@ exports.publishPackage = function (options) { } var isopack = projectContext.isopackCache.getIsopack(name); + if (! isopack) { throw Error("no isopack " + name); } @@ -737,18 +743,18 @@ exports.publishPackage = function (options) { } var sourceBundleResult; - buildmessage.enterJob("bundling source for " + name, function () { - sourceBundleResult = bundleSource( + await buildmessage.enterJob("bundling source for " + name, async function () { + sourceBundleResult = await bundleSource( isopack, sourceFiles, packageSource.sourceRoot); }); + if (buildmessage.jobHasMessages()) { return; } - // Create the package. Check that the metadata exists. if (options.new) { - buildmessage.enterJob("creating package " + name, function () { - callPackageServerBM(conn, 'createPackage', { + await buildmessage.enterJob("creating package " + name, async function () { + await callPackageServerBM(conn, 'createPackage', { name: packageSource.name }); }); @@ -758,7 +764,7 @@ exports.publishPackage = function (options) { } if (options.existingVersion) { - var existingRecord = catalog.official.getVersion(name, version); + var existingRecord = await catalog.official.getVersion(name, version); if (! existingRecord) { buildmessage.error("Version does not exist."); return; @@ -769,7 +775,7 @@ exports.publishPackage = function (options) { } if (! options.doNotPublishBuild) { - createAndPublishBuiltPackage( + await createAndPublishBuiltPackage( conn, isopack, projectContext.isopackCache); if (buildmessage.jobHasMessages()) { @@ -780,7 +786,7 @@ exports.publishPackage = function (options) { // XXX check that we're actually providing something new? } else { var uploadInfo; - buildmessage.enterJob("pre-publishing package " + name, function () { + await buildmessage.enterJob("pre-publishing package " + name, async function () { var uploadRec = { packageName: packageSource.name, version: version, @@ -800,7 +806,7 @@ exports.publishPackage = function (options) { releaseName: release.current.name, dependencies: packageDeps }; - uploadInfo = callPackageServerBM(conn, 'createPackageVersion', uploadRec); + uploadInfo = await callPackageServerBM(conn, 'createPackageVersion', uploadRec); }); if (buildmessage.jobHasMessages()) { return; @@ -811,26 +817,28 @@ exports.publishPackage = function (options) { // publish a new build. // Documentation is smaller than the source. Upload it first, to minimize // the chances of PUT URLs expiring. (XXX: in the far future, parallelize this) - buildmessage.enterJob("uploading documentation", function () { - uploadFile(uploadInfo.readmeUrl, readmePath); + await buildmessage.enterJob("uploading documentation", async function () { + await uploadFile(uploadInfo.readmeUrl, readmePath); }); + if (buildmessage.jobHasMessages()) { return; } - buildmessage.enterJob("uploading source", function () { - uploadFile(uploadInfo.uploadUrl, sourceBundleResult.sourceTarball); + await buildmessage.enterJob("uploading source", async function () { + await uploadFile(uploadInfo.uploadUrl, sourceBundleResult.sourceTarball); }); + if (buildmessage.jobHasMessages()) { return; } if (! options.doNotPublishBuild) { - var bundleResult = createBuiltPackage( + + var bundleResult = await createBuiltPackage( isopack, projectContext.isopackCache, ); - if (buildmessage.jobHasMessages()) { return; } @@ -841,8 +849,8 @@ exports.publishPackage = function (options) { treeHash: sourceBundleResult.treeHash, readmeHash: readmeInfo.hash }; - buildmessage.enterJob("publishing package version", function () { - callPackageServerBM( + await buildmessage.enterJob("publishing package version", async function () { + await callPackageServerBM( conn, 'publishPackageVersion', uploadInfo.uploadToken, hashes); }); if (buildmessage.jobHasMessages()) { @@ -850,7 +858,7 @@ exports.publishPackage = function (options) { } if (! options.doNotPublishBuild) { - publishBuiltPackage(conn, isopack, bundleResult); + await publishBuiltPackage(conn, isopack, bundleResult); if (buildmessage.jobHasMessages()) { return; } @@ -867,12 +875,12 @@ exports.publishPackage = function (options) { // // If this returns FALSE, then we are NOT authorized. // Otherwise, return true. -exports.amIAuthorized = function (name, conn, isRelease) { +exports.amIAuthorized = async function (name, conn, isRelease) { var methodName = "amIAuthorized" + (isRelease ? "Release" : "Package"); try { - exports.callPackageServer(conn, methodName, name); + await exports.callPackageServer(conn, methodName, name); } catch (err) { if (err.error === 401) { return false; diff --git a/tools/packaging/tropohouse.js b/tools/packaging/tropohouse.js index ae39b314ac..69fe2ad17c 100644 --- a/tools/packaging/tropohouse.js +++ b/tools/packaging/tropohouse.js @@ -40,7 +40,7 @@ exports.default = new exports.Tropohouse(defaultWarehouseDir()); * Extract a package tarball, and on Windows convert file paths and metadata * @param {String} packageTarball path to tarball * @param {Boolean} forceConvert Convert paths even on unix, for testing - * @return {String} Temporary directory with contents of package + * @return {Promise} Temporary directory with contents of package */ exports._extractAndConvert = async function (packageTarball, forceConvert) { var targetDirectory = files.mkdtemp(); @@ -552,7 +552,7 @@ Object.assign(exports.Tropohouse.prototype, { var self = this; buildmessage.assertInCapture(); options = options || {}; - var serverArchs = options.serverArchitectures || [await archinfo.host()]; + var serverArchs = options.serverArchitectures || [archinfo.host()]; var downloader; var downloaders = []; diff --git a/tools/project-context.js b/tools/project-context.js index ea1355a78b..9dd2a752cf 100644 --- a/tools/project-context.js +++ b/tools/project-context.js @@ -157,7 +157,7 @@ Object.assign(ProjectContext.prototype, { self._serverArchitectures = options.serverArchitectures || []; // We always need to download host versions of packages, at least for // plugins. - self._serverArchitectures.push(await archinfo.host()); + self._serverArchitectures.push(archinfo.host()); self._serverArchitectures = _.uniq(self._serverArchitectures); // test-packages overrides this to load local packages from your real app @@ -601,7 +601,6 @@ Object.assign(ProjectContext.prototype, { _resolveConstraints: Profile('_resolveConstraints', async function () { var self = this; buildmessage.assertInJob(); - var depsAndConstraints = await self._getRootDepsAndConstraints(); // If this is in the runner and we have reset this ProjectContext for a // rebuild, use the versions we calculated last time in this process (which @@ -826,9 +825,8 @@ Object.assign(ProjectContext.prototype, { _initializeCatalog: Profile('_initializeCatalog', async function () { var self = this; buildmessage.assertInJob(); - - await catalog.runAndRetryWithRefreshIfHelpful(function () { - return buildmessage.enterJob( + await catalog.runAndRetryWithRefreshIfHelpful(async function () { + return await buildmessage.enterJob( "scanning local packages", async function () { self.localCatalog = new catalogLocal.LocalCatalog(); diff --git a/tools/tests/colon-converter-tests.js b/tools/tests/colon-converter-tests.js index 5f2fa7a8f4..de3efee2c1 100644 --- a/tools/tests/colon-converter-tests.js +++ b/tools/tests/colon-converter-tests.js @@ -82,7 +82,7 @@ if (process.platform !== "win32") { // This test is only for unixy platforms if (process.platform !== "win32") { - selftest.define("package with colons is unpacked as-is on unix", function () { + selftest.define("package with colons is unpacked as-is on unix", async function () { // We have a built package tarball in the git repo var tarballPath = files.pathJoin(files.convertToStandardPath(__dirname), "built-packages", "has-colons.tgz"); @@ -97,8 +97,8 @@ if (process.platform !== "win32") { var targetDirectory = tropohouse._extractAndConvert(tarball); // Now, compare all of the filepaths and file contents - var startingTreeHash = files.treeHash(extractPath); - var finalTreeHash = files.treeHash(targetDirectory); + var startingTreeHash = files.treeHash(extractPath); + var finalTreeHash = files.treeHash(targetDirectory); // Nothing should be different selftest.expectEqual(finalTreeHash, startingTreeHash); @@ -108,7 +108,7 @@ if (process.platform !== "win32") { // Tests step 3: check if old packages are converted properly to have no weird // paths for Windows -selftest.define("package with colons is converted on Windows", function () { +selftest.define("package with colons is converted on Windows", async function () { // We have a built package tarball in the git repo var tarballPath = files.pathJoin(files.convertToStandardPath(__dirname), "built-packages", "has-colons.tgz"); @@ -117,7 +117,7 @@ selftest.define("package with colons is converted on Windows", function () { var tarball = files.readFile(tarballPath); // Force conversion of file paths with second argument - var targetDirectory = tropohouse._extractAndConvert(tarball, true); + var targetDirectory = await tropohouse._extractAndConvert(tarball, true); // Uncomment below to check results // console.log(files.getPathsInDir(targetDirectory, { diff --git a/tools/tests/galaxy.js b/tools/tests/galaxy.js index f6c6eb747c..7a60d2289f 100644 --- a/tools/tests/galaxy.js +++ b/tools/tests/galaxy.js @@ -210,7 +210,7 @@ selftest.define('galaxy self-signed cert', ['galaxy'], async function () { // Create a signed certificate for the app. // createSelfSignedCertificateForApp: function (appId, options) { var appRecord = galaxyUtils.getAppRecordByName(appName); - var conn = galaxyUtils.loggedInGalaxyAPIConnection(); + var conn = await galaxyUtils.loggedInGalaxyAPIConnection(); var certIds = []; for (let range = 0; range <= 14; range++) { certIds.push(await galaxyUtils.callGalaxyAPI( diff --git a/tools/tests/tarball.js b/tools/tests/tarball.js index dcf10652de..d9f15a5f49 100644 --- a/tools/tests/tarball.js +++ b/tools/tests/tarball.js @@ -19,7 +19,7 @@ selftest.define("create and extract tarball with long paths", async function () // Make the tarball var tarballOutputDir = files.mkdtemp("tarball"); var tarballOutputFile = files.pathJoin(tarballOutputDir, "out.tar.gz"); - files.createTarball(tarballInputDir, tarballOutputFile); + await files.createTarball(tarballInputDir, tarballOutputFile); // Extract the tarball and verify that the single file we created is // present with the expected contents. diff --git a/tools/tool-env/isopackets.js b/tools/tool-env/isopackets.js index 9bd6037291..d2c21afd6d 100644 --- a/tools/tool-env/isopackets.js +++ b/tools/tool-env/isopackets.js @@ -98,7 +98,7 @@ export async function loadIsopackage(packageName, isopacketName = "combined") { // it yields the first time we call it, which is a problem for the // fiberHelpers.noYieldsAllowed block below. Calling it here ensures the // result is cached, so no yielding occurs later. - assert.strictEqual((await archinfo.host()).split(".", 1)[0], "os"); + assert.strictEqual((archinfo.host()).split(".", 1)[0], "os"); async function load() { if (_.has(loadedIsopackets, isopacketName)) { diff --git a/tools/tool-testing/sandbox.js b/tools/tool-testing/sandbox.js index 1f77b052fd..2a1b8efa3d 100644 --- a/tools/tool-testing/sandbox.js +++ b/tools/tool-testing/sandbox.js @@ -489,7 +489,7 @@ export default class Sandbox { // XXX this is hacky await files.linkToMeteorScript( files.pathJoin(this.warehouse, packagesDirectoryName, "meteor-tool", toolPackageVersion, - 'mt-' + await archInfoHost(), 'meteor'), + 'mt-' + archInfoHost(), 'meteor'), files.pathJoin(this.warehouse, 'meteor')); } } diff --git a/tools/utils/archinfo.ts b/tools/utils/archinfo.ts index df524781b9..08ce68955f 100644 --- a/tools/utils/archinfo.ts +++ b/tools/utils/archinfo.ts @@ -135,22 +135,22 @@ export const VALID_ARCHITECTURES: Record = { }; // Returns the fully qualified arch of this host -- something like -// "os.linux.x86_32" or "os.osx.x86_64". Must be called inside -// a fiber. Throws an error if it's not a supported architecture. +// "os.linux.x86_32" or "os.osx.x86_64". +// Throws an error if it's not a supported architecture. // // If you change this, also change scripts/admin/launch-meteor let _host: string | null = null; // memoize -export async function host() { +export function host() { if (!_host) { - const run = async function (...args: Array) { - const result = (await utils.execFile(args[0], args.slice(1))).stdout; + const run = function (...args: Array) { + const result = utils.execFileSync(args[0], args.slice(1)).stdout; if (! result) { throw new Error(`Can't get arch with ${args.join(" ")}?`); } - return result.replace(/\s*$/, ''); // trailing whitespace + return result.replace(/\s*$/, ''); // remove trailing whitespace }; const platform = os.platform(); @@ -158,10 +158,10 @@ export async function host() { if (platform === "darwin") { // Can't just test uname -m = x86_64, because Snow Leopard can // return other values. - const arch = await run('uname', '-p'); + const arch = run('uname', '-p'); if ((arch !== "i386" && arch !== "arm") || - await run('sysctl', '-n', 'hw.cpu64bit_capable') !== "1") { + run('sysctl', '-n', 'hw.cpu64bit_capable') !== "1") { throw new Error("Only 64-bit Intel and M1 processors are supported on OS X"); } if(arch === "arm"){ @@ -170,7 +170,7 @@ export async function host() { _host = "os.osx.x86_64"; } } else if (platform === "linux") { - const machine = await run('uname', '-m'); + const machine = run('uname', '-m'); if (["x86_64", "amd64", "ia64"].includes(machine)) { _host = "os.linux.x86_64"; } else { diff --git a/tools/utils/utils.js b/tools/utils/utils.js index 63eb667e1b..8ccd4f5b5a 100644 --- a/tools/utils/utils.js +++ b/tools/utils/utils.js @@ -135,7 +135,7 @@ exports.getHost = async function (...args) { } }; - if (archinfo.matches(await archinfo.host(), 'os.osx')) { + if (archinfo.matches(archinfo.host(), 'os.osx')) { // On OSX, to get the human-readable hostname that the user chose, // we call: // scutil --get ComputerName @@ -146,8 +146,8 @@ exports.getHost = async function (...args) { } } - if (archinfo.matches(await archinfo.host(), 'os.osx') || - archinfo.matches(await archinfo.host(), 'os.linux')) { + if (archinfo.matches(archinfo.host(), 'os.osx') || + archinfo.matches(archinfo.host(), 'os.linux')) { // On Unix-like platforms, try passing -s to hostname to strip off // the domain name, to reduce the extent to which the output // varies with DNS. @@ -181,7 +181,7 @@ exports.getAgentInfo = async function () { ret.agent = "Meteor"; ret.agentVersion = files.inCheckout() ? "checkout" : files.getToolsVersion(); - ret.arch = await archinfo.host(); + ret.arch = archinfo.host(); return ret; }; @@ -512,6 +512,36 @@ exports.isValidVersion = function (version, {forCordova}) { || (forCordova ? exports.isUrlWithSha(version): exports.isNpmUrl(version)); }; +exports.execFileSync = function (file, args, opts) { + var child_process = require('child_process'); + + opts = opts || {}; + if (!_.has(opts, 'maxBuffer')) { + opts.maxBuffer = 1024 * 1024 * 10; + } + + if (!_.has(opts, 'encoding')) { + opts.encoding = 'utf8'; + } + + let result; + try { + result = child_process.execFileSync(file, args, opts); + } catch (error) { + return { + success: false, + stdout: error.stdout, + stderr: error.stderr + }; + } + + return { + stdout: result, + success: true, + stderr: '' + }; +} + exports.execFile = async function (file, args, opts) { var child_process = require('child_process');