Don't apply async-await plugin and don't modify promise functions.

This commit is contained in:
Matheus Castro
2022-10-13 23:06:55 -03:00
parent 60fb986fc3
commit d93c7568ab
3 changed files with 28 additions and 22 deletions

View File

@@ -185,11 +185,13 @@ function getDefaultsForNode8(features) {
// Ensure that async functions run in a Fiber, while also taking
// full advantage of native async/await support in Node 8.
combined.plugins.push([require("./plugins/async-await.js"), {
// Do not transform `await x` to `Promise.await(x)`, since Node
// 8 has native support for await expressions.
useNativeAsyncAwait: false
}]);
if (!process.env.DISABLE_FIBERS) {
combined.plugins.push([require("./plugins/async-await.js"), {
// Do not transform `await x` to `Promise.await(x)`, since Node
// 8 has native support for await expressions.
useNativeAsyncAwait: false
}]);
}
// Enable async generator functions proposal.
combined.plugins.push(require("@babel/plugin-proposal-async-generator-functions"));

View File

@@ -11,19 +11,21 @@ Module.prototype.resolve = function (id) {
require("@meteorjs/reify/lib/runtime").enable(Module.prototype);
require("meteor-promise").makeCompatible(
global.Promise = global.Promise ||
require("promise/lib/es6-extensions"),
require("fibers")
);
if (!process.env.DISABLE_FIBERS) {
require("meteor-promise").makeCompatible(
global.Promise = global.Promise ||
require("promise/lib/es6-extensions"),
require("fibers")
);
// If Promise.asyncApply is defined, use it to wrap calls to
// regeneratorRuntime.async so that the entire async function will run in
// its own Fiber, not just the code that comes after the first await.
if (typeof Promise.asyncApply === "function") {
var regeneratorRuntime = require("@babel/runtime/regenerator");
var realAsync = regeneratorRuntime.async;
regeneratorRuntime.async = function (innerFn) {
return Promise.asyncApply(realAsync, regeneratorRuntime, arguments);
};
if (typeof Promise.asyncApply === "function") {
var regeneratorRuntime = require("@babel/runtime/regenerator");
var realAsync = regeneratorRuntime.async;
regeneratorRuntime.async = function (innerFn) {
return Promise.asyncApply(realAsync, regeneratorRuntime, arguments);
};
}
}

View File

@@ -1,11 +1,13 @@
require("./extensions.js");
require("meteor-promise").makeCompatible(
Promise,
// Allow every Promise callback to run in a Fiber drawn from a pool of
// reusable Fibers.
require("fibers")
);
if (!process.env.DISABLE_FIBERS) {
require("meteor-promise").makeCompatible(
Promise,
// Allow every Promise callback to run in a Fiber drawn from a pool of
// reusable Fibers.
require("fibers")
);
}
// Reference: https://caniuse.com/#feat=promises
require("meteor/modern-browsers").setMinimumBrowserVersions({