@shopify/async
Advanced tools
Comparing version 2.2.6 to 3.0.0
@@ -1,15 +0,6 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = asyncBabelPlugin; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var DEFAULT_PACKAGES_TO_PROCESS = { | ||
const DEFAULT_PACKAGES_TO_PROCESS = { | ||
'@shopify/alpaql/async': ['createAsyncQuery'], | ||
@@ -20,33 +11,16 @@ '@shopify/async': ['createResolver'], | ||
}; | ||
function asyncBabelPlugin(_ref) { | ||
var t = _ref.types; | ||
function asyncBabelPlugin({ | ||
types: t | ||
}) { | ||
return { | ||
visitor: { | ||
Program: function (_Program) { | ||
function Program(_x, _x2) { | ||
return _Program.apply(this, arguments); | ||
} | ||
Program.toString = function () { | ||
return _Program.toString(); | ||
}; | ||
return Program; | ||
}(function (_path, state) { | ||
Program(_path, state) { | ||
state.processPackages = new Map(Object.entries(state.opts && state.opts.packages || DEFAULT_PACKAGES_TO_PROCESS)); | ||
}), | ||
ImportDeclaration: function (_ImportDeclaration) { | ||
function ImportDeclaration(_x3, _x4) { | ||
return _ImportDeclaration.apply(this, arguments); | ||
} | ||
}, | ||
ImportDeclaration.toString = function () { | ||
return _ImportDeclaration.toString(); | ||
}; | ||
ImportDeclaration(path, state) { | ||
const { | ||
processPackages | ||
} = state; | ||
return ImportDeclaration; | ||
}(function (path, state) { | ||
var processPackages = state.processPackages; | ||
if (!(processPackages instanceof Map)) { | ||
@@ -56,4 +30,4 @@ return; | ||
var source = path.node.source.value; | ||
var processImports = processPackages.get(source) || []; | ||
const source = path.node.source.value; | ||
const processImports = processPackages.get(source) || []; | ||
@@ -64,8 +38,6 @@ if (processImports.length === 0) { | ||
var importSpecifiersToProcess = path.get('specifiers').filter(function (specifier) { | ||
return specifier.isImportSpecifier() && processImports.some(function (name) { | ||
return specifier.get('imported').isIdentifier({ | ||
name: name | ||
}); | ||
}); | ||
const importSpecifiersToProcess = path.get('specifiers').filter(specifier => { | ||
return specifier.isImportSpecifier() && processImports.some(name => specifier.get('imported').isIdentifier({ | ||
name | ||
})); | ||
}); | ||
@@ -77,21 +49,12 @@ | ||
var _iterator = _createForOfIteratorHelper(importSpecifiersToProcess), | ||
_step; | ||
for (const importSpecifier of importSpecifiersToProcess) { | ||
const bindingName = importSpecifier.node.local.name; | ||
const binding = path.scope.getBinding(bindingName); | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var importSpecifier = _step.value; | ||
var bindingName = importSpecifier.node.local.name; | ||
var binding = path.scope.getBinding(bindingName); | ||
if (binding != null) { | ||
addIdOption(binding, t, state.opts); | ||
} | ||
if (binding != null) { | ||
addIdOption(binding, t, state.opts); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
}) | ||
} | ||
} | ||
@@ -101,10 +64,8 @@ }; | ||
function addIdOption(binding, t) { | ||
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
_ref2$webpack = _ref2.webpack, | ||
webpack = _ref2$webpack === void 0 ? true : _ref2$webpack; | ||
function addIdOption(binding, t, { | ||
webpack = true | ||
} = {}) { | ||
binding.referencePaths.forEach(refPath => { | ||
const callExpression = refPath.parentPath; | ||
binding.referencePaths.forEach(function (refPath) { | ||
var callExpression = refPath.parentPath; | ||
if (!callExpression.isCallExpression()) { | ||
@@ -114,3 +75,3 @@ return; | ||
var args = callExpression.get('arguments'); | ||
const args = callExpression.get('arguments'); | ||
@@ -121,3 +82,3 @@ if (args.length === 0) { | ||
var options = args[0]; | ||
const options = args[0]; | ||
@@ -128,5 +89,5 @@ if (!options.isObjectExpression()) { | ||
var properties = options.get('properties'); | ||
var propertiesMap = {}; | ||
properties.forEach(function (property) { | ||
const properties = options.get('properties'); | ||
const propertiesMap = {}; | ||
properties.forEach(property => { | ||
if (!property.isObjectMember() || property.node.computed) { | ||
@@ -136,3 +97,3 @@ return; | ||
var key = property.get('key'); | ||
const key = property.get('key'); | ||
@@ -145,4 +106,6 @@ if (!key.isIdentifier()) { | ||
}); | ||
var id = propertiesMap.id, | ||
loadProperty = propertiesMap.load; | ||
const { | ||
id, | ||
load: loadProperty | ||
} = propertiesMap; | ||
@@ -153,10 +116,10 @@ if (id != null || loadProperty == null) { | ||
var loaderMethod = loadProperty.isObjectProperty() ? loadProperty.get('value') : loadProperty.get('body'); | ||
var dynamicImports = []; | ||
const loaderMethod = loadProperty.isObjectProperty() ? loadProperty.get('value') : loadProperty.get('body'); | ||
const dynamicImports = []; | ||
if (!Array.isArray(loaderMethod)) { | ||
loaderMethod.traverse({ | ||
Import: function Import(_ref3) { | ||
var parentPath = _ref3.parentPath; | ||
Import({ | ||
parentPath | ||
}) { | ||
if (parentPath.isCallExpression()) { | ||
@@ -166,2 +129,3 @@ dynamicImports.push(parentPath); | ||
} | ||
}); | ||
@@ -180,2 +144,4 @@ } | ||
}); | ||
} | ||
} | ||
exports.default = asyncBabelPlugin; |
@@ -1,31 +0,16 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _types = require("./types.js"); | ||
var types = require('./types.js'); | ||
var resolver = require('./resolver.js'); | ||
Object.keys(_types).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _types[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _types[key]; | ||
} | ||
}); | ||
}); | ||
var _resolver = require("./resolver.js"); | ||
Object.keys(_resolver).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _resolver[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _resolver[key]; | ||
} | ||
}); | ||
}); | ||
Object.defineProperty(exports, 'DeferTiming', { | ||
enumerable: true, | ||
get: function () { | ||
return types.DeferTiming; | ||
} | ||
}); | ||
exports.createResolver = resolver.createResolver; |
@@ -1,25 +0,15 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createResolver = createResolver; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function createResolver(_ref) { | ||
var id = _ref.id, | ||
load = _ref.load; | ||
var resolved = null; | ||
var resolvePromise = null; | ||
var hasTriedSyncResolve = false; | ||
var resolvedId = id && id(); | ||
function createResolver({ | ||
id, | ||
load | ||
}) { | ||
let resolved = null; | ||
let resolvePromise = null; | ||
let hasTriedSyncResolve = false; | ||
const resolvedId = id && id(); | ||
return { | ||
@@ -40,28 +30,11 @@ get id() { | ||
resolve: function () { | ||
var _resolve2 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
resolvePromise = resolvePromise || _resolve(load); | ||
_context.next = 3; | ||
return resolvePromise; | ||
var _ref = _rollupPluginBabelHelpers.asyncToGenerator(function* () { | ||
resolvePromise = resolvePromise || resolve(load); | ||
resolved = yield resolvePromise; | ||
return resolved; | ||
}); | ||
case 3: | ||
resolved = _context.sent; | ||
return _context.abrupt("return", resolved); | ||
case 5: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
function resolve() { | ||
return _resolve2.apply(this, arguments); | ||
} | ||
return resolve; | ||
return function resolve() { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}() | ||
@@ -71,28 +44,12 @@ }; | ||
function _resolve(_x) { | ||
return _resolve3.apply(this, arguments); | ||
function resolve(_x) { | ||
return _resolve.apply(this, arguments); | ||
} | ||
function _resolve3() { | ||
_resolve3 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee2(load) { | ||
var resolved; | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return load(); | ||
case 2: | ||
resolved = _context2.sent; | ||
return _context2.abrupt("return", normalize(resolved)); | ||
case 4: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
})); | ||
return _resolve3.apply(this, arguments); | ||
function _resolve() { | ||
_resolve = _rollupPluginBabelHelpers.asyncToGenerator(function* (load) { | ||
const resolved = yield load(); | ||
return normalize(resolved); | ||
}); | ||
return _resolve.apply(this, arguments); | ||
} | ||
@@ -105,3 +62,3 @@ | ||
var value = _typeof(module) === 'object' && 'default' in module ? module["default"] : module; | ||
const value = typeof module === 'object' && 'default' in module ? module.default : module; | ||
return value == null ? null : value; | ||
@@ -122,4 +79,4 @@ } | ||
// the global require function. | ||
var requireKey = 'require'; | ||
var nodeRequire = (typeof global === "undefined" ? "undefined" : _typeof(global)) === 'object' && typeof global[requireKey] === 'function' && global[requireKey] || (typeof module === "undefined" ? "undefined" : _typeof(module)) === 'object' && typeof module[requireKey] === 'function' && module[requireKey] || undefined; // If we have an ID, we try to first use Webpack’s internal stuff | ||
const requireKey = 'require'; | ||
const nodeRequire = typeof global === 'object' && typeof global[requireKey] === 'function' && global[requireKey] || typeof module === 'object' && typeof module[requireKey] === 'function' && module[requireKey] || undefined; // If we have an ID, we try to first use Webpack’s internal stuff | ||
// to resolve the module. If those don’t exist, we know we aren’t | ||
@@ -130,3 +87,3 @@ // inside of a Webpack bundle, so we try to use Node’s native resolution | ||
function tryRequire(id) { | ||
if (typeof __webpack_require__ === 'function' && (typeof __webpack_modules__ === "undefined" ? "undefined" : _typeof(__webpack_modules__)) === 'object' && __webpack_modules__[id]) { | ||
if (typeof __webpack_require__ === 'function' && typeof __webpack_modules__ === 'object' && __webpack_modules__[id]) { | ||
try { | ||
@@ -148,2 +105,4 @@ return normalize(__webpack_require__(id)); | ||
return tryRequire(id) || null; | ||
} | ||
} | ||
exports.createResolver = createResolver; |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.DeferTiming = void 0; | ||
var DeferTiming; | ||
exports.DeferTiming = DeferTiming; | ||
@@ -14,2 +11,2 @@ (function (DeferTiming) { | ||
DeferTiming[DeferTiming["InViewport"] = 2] = "InViewport"; | ||
})(DeferTiming || (exports.DeferTiming = DeferTiming = {})); | ||
})(exports.DeferTiming || (exports.DeferTiming = {})); |
@@ -10,2 +10,8 @@ # Changelog | ||
## 3.0.0 - 2021-05-21 | ||
### Breaking Change | ||
- Update minimum supported node version to 12.14.0. Add engines field to help enforce usage of this version. [#1906](https://github.com/Shopify/quilt/pull/1906) | ||
## 2.2.4 - 2021-04-13 | ||
@@ -12,0 +18,0 @@ |
{ | ||
"name": "@shopify/async", | ||
"version": "2.2.6", | ||
"version": "3.0.0", | ||
"license": "MIT", | ||
@@ -23,2 +23,5 @@ "description": "Primitives for loading parts of an application asynchronously", | ||
"homepage": "https://github.com/Shopify/quilt/blob/main/packages/async/README.md", | ||
"engines": { | ||
"node": ">=12.14.0" | ||
}, | ||
"devDependencies": { | ||
@@ -61,3 +64,3 @@ "@babel/core": ">=7.0.0", | ||
}, | ||
"gitHead": "4324f27f72ae7b1800ec6bde9087af4ed89b3833" | ||
"gitHead": "40de4af181104f298cbab42d2d3d68e228a9a31a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43278
38
715