text: "use strict";
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = detectPackage;
  
  var _assert = _interopRequireDefault(require("./assert"));
  
  var _string = _interopRequireDefault(require("./is/string"));
  
  // Copyright 2017-2020 @polkadot/util authors & contributors
  // This software may be modified and distributed under the terms
  // of the Apache-2.0 license. See the LICENSE file for details.
  function expandPath(path) {
    return !path || path.length < 5 ? '<unknown>' : path;
  }
  /** @internal */
  
  
  function flattenVersions(_all) {
    const all = _all.map(version => (0, _string.default)(version) ? {
      version
    } : version);
  
    const verLength = all.reduce((max, {
      version
    }) => Math.max(max, version.length), 0);
    return all.map(({
      path,
      version
    }) => `\t${version.padEnd(verLength)}\t${expandPath(path)}`).join('\n');
  }
  /**
   * @name detectPackage
   * @summary Checks that a specific package is only imported once
   */
  
  
  function detectPackage({
    name,
    version
  }, path) {
    const _global = typeof window !== 'undefined' ? window : global;
  
    if (!_global.__polkadotjs) {
      _global.__polkadotjs = {};
    }
  
    (0, _assert.default)(name.startsWith('@polkadot'), `Invalid package descriptor ${name}`);
    _global.__polkadotjs[name] = [...(_global.__polkadotjs[name] || []), {
      path: path || '',
      version
    }];
  
    if (_global.__polkadotjs[name].length !== 1) {
      const versions = flattenVersions(_global.__polkadotjs[name]);
      console.warn(`Multiple instances of ${name} detected, ensure that there is only one package in your dependency tree.\n${versions}`);
    }
  }