Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of embedded components with vite 3.0 using tsc to compile @jbrowse/core #3092

Merged
merged 1 commit into from
Jul 14, 2022

Conversation

cmdcolin
Copy link
Collaborator

Fixes #3091
Uses tsc instead of babel to compile @jbrowse/core

Outputs module type "commonjs" since it is used under node, and it is difficult to create dual esm/commonjs builds for core (becuase of the "flat" module structure/importing from subpaths)

Simple local testing showed it fixed the vite 3.0.0 build

@github-actions github-actions bot added the needs label triage Needs a label to show in changelog (breaking, enhancement, bug, documentation, or internal) label Jul 14, 2022
@cmdcolin
Copy link
Collaborator Author

tsc compilation of FeatureRendererType

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const operators_1 = require("rxjs/operators");
const util_1 = require("../../util");
const simpleFeature_1 = __importDefault(require("../../util/simpleFeature"));
const dataAdapterCache_1 = require("../../data_adapters/dataAdapterCache");
const ServerSideRendererType_1 = __importDefault(require("./ServerSideRendererType"));
const BaseAdapter_1 = require("../../data_adapters/BaseAdapter");
class FeatureRendererType extends ServerSideRendererType_1.default {
    /**
     * replaces the `displayModel` param (which on the client is a MST model) with
     * a stub that only contains the `selectedFeature`, since this is the only
     * part of the track model that most renderers read. also serializes the
     * config and regions to JSON from MST objects.
     *
     * @param args - the arguments passed to render
     */
    serializeArgsInClient(args) {
        const { displayModel, regions } = args;
        const serializedArgs = {
            ...args,
            displayModel: displayModel && {
                id: displayModel.id,
                selectedFeatureId: displayModel.selectedFeatureId,
            },
            regions: JSON.parse(JSON.stringify(regions)),
        };
        return super.serializeArgsInClient(serializedArgs);
    }
    /**
     * Adds feature deserialization to base server-side result deserialization
     *
     * @param results - the results of the render
     * @param args - the arguments passed to render
     */
    deserializeResultsInClient(result, args) {
        const deserializedFeatures = new Map();
        result.features.forEach(j => {
            const f = simpleFeature_1.default.fromJSON(j);
            deserializedFeatures.set(String(f.id()), f);
        });
        const deserialized = super.deserializeResultsInClient({
            ...result,
            features: deserializedFeatures,
        }, args);
        return {
            ...deserialized,
            blockKey: args.blockKey,
            features: deserializedFeatures,
        };
    }
    /**
     * Adds feature serialization to base server-side result serialization
     *
     * @param result - object containing the results of calling the `render`
     * method
     * @param args - deserialized render args
     */
    serializeResultsInWorker(result, args) {
        const serialized = super.serializeResultsInWorker(result, args);
        const { features } = result;
        return {
            ...serialized,
            features: (0, util_1.iterMap)(features.values(), f => f.toJSON(), features.size),
        };
    }
    /**
     * will expand if soft clipping or feature glyphs are shown
     *
     * @param region - rendering region
     * @param _renderArgs - render args, unused, may be used in deriving classes
     */
    getExpandedRegion(region, _renderArgs) {
        return region;
    }
    /**
     * use the dataAdapter to fetch the features to be rendered
     *
     * @param renderArgs -
     * @returns Map of features as `{ id => feature, ... }`
     */
    async getFeatures(renderArgs) {
        const { signal, regions, sessionId, adapterConfig } = renderArgs;
        const { dataAdapter } = await (0, dataAdapterCache_1.getAdapter)(this.pluginManager, sessionId, adapterConfig);
        if (!(0, BaseAdapter_1.isFeatureAdapter)(dataAdapter)) {
            throw new Error('Adapter does not support retrieving features');
        }
        const features = new Map();
        if (!regions || regions.length === 0) {
            return features;
        }
        const requestRegions = regions.map((r) => {
            // make sure the requested region's start and end are integers, if
            // there is a region specification.
            const requestRegion = { ...r };
            if (requestRegion.start) {
                requestRegion.start = Math.floor(requestRegion.start);
            }
            if (requestRegion.end) {
                requestRegion.end = Math.ceil(requestRegion.end);
            }
            return requestRegion;
        });
        const region = requestRegions[0];
        const featureObservable = requestRegions.length === 1
            ? dataAdapter.getFeatures(this.getExpandedRegion(region, renderArgs), renderArgs)
            : dataAdapter.getFeaturesInMultipleRegions(requestRegions, renderArgs);
        const feats = await featureObservable.pipe((0, operators_1.toArray)()).toPromise();
        (0, util_1.checkAbortSignal)(signal);
        return new Map(feats
            .filter(feat => this.featurePassesFilters(renderArgs, feat))
            .map(feat => [feat.id(), feat]));
    }
    /**
     * @param renderArgs -
     * @param feature -
     * @returns true if this feature passes all configured filters
     */
    featurePassesFilters(renderArgs, feature) {
        if (!renderArgs.filters) {
            return true;
        }
        return renderArgs.filters.passes(feature, renderArgs);
    }
    /**
     * gets features and renders
     *
     * @param props - render args
     */
    async render(props) {
        const features = props.features ||
            (await this.getFeatures(props));
        const result = await super.render({ ...props, features });
        return { ...result, features };
    }
}
exports.default = FeatureRendererType;

babel version

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.NewFeatureRendererType = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _operators = require("rxjs/operators");

var _util = require("../../util");

var _simpleFeature = _interopRequireDefault(require("../../util/simpleFeature"));

var _dataAdapterCache = require("../../data_adapters/dataAdapterCache");

var _ServerSideRendererType = _interopRequireDefault(require("./ServerSideRendererType"));

var _BaseAdapter = require("../../data_adapters/BaseAdapter");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var FeatureRendererType = /*#__PURE__*/function (_ServerSideRendererTy) {
  (0, _inherits2.default)(FeatureRendererType, _ServerSideRendererTy);

  var _super = _createSuper(FeatureRendererType);

  function FeatureRendererType() {
    (0, _classCallCheck2.default)(this, FeatureRendererType);
    return _super.apply(this, arguments);
  }

  (0, _createClass2.default)(FeatureRendererType, [{
    key: "serializeArgsInClient",
    value:
    /**
     * replaces the `displayModel` param (which on the client is a MST model) with
     * a stub that only contains the `selectedFeature`, since this is the only
     * part of the track model that most renderers read. also serializes the
     * config and regions to JSON from MST objects.
     *
     * @param args - the arguments passed to render
     */
    function serializeArgsInClient(args) {
      var displayModel = args.displayModel,
          regions = args.regions;

      var serializedArgs = _objectSpread(_objectSpread({}, args), {}, {
        displayModel: displayModel && {
          id: displayModel.id,
          selectedFeatureId: displayModel.selectedFeatureId
        },
        regions: JSON.parse(JSON.stringify(regions))
      });

      return (0, _get2.default)((0, _getPrototypeOf2.default)(FeatureRendererType.prototype), "serializeArgsInClient", this).call(this, serializedArgs);
    }
    /**
     * Adds feature deserialization to base server-side result deserialization
     *
     * @param results - the results of the render
     * @param args - the arguments passed to render
     */

  }, {
    key: "deserializeResultsInClient",
    value: function deserializeResultsInClient(result, args) {
      var deserializedFeatures = new Map();
      result.features.forEach(function (j) {
        var f = _simpleFeature.default.fromJSON(j);

        deserializedFeatures.set(String(f.id()), f);
      });
      var deserialized = (0, _get2.default)((0, _getPrototypeOf2.default)(FeatureRendererType.prototype), "deserializeResultsInClient", this).call(this, _objectSpread(_objectSpread({}, result), {}, {
        features: deserializedFeatures
      }), args);
      return _objectSpread(_objectSpread({}, deserialized), {}, {
        blockKey: args.blockKey,
        features: deserializedFeatures
      });
    }
    /**
     * Adds feature serialization to base server-side result serialization
     *
     * @param result - object containing the results of calling the `render`
     * method
     * @param args - deserialized render args
     */

  }, {
    key: "serializeResultsInWorker",
    value: function serializeResultsInWorker(result, args) {
      var serialized = (0, _get2.default)((0, _getPrototypeOf2.default)(FeatureRendererType.prototype), "serializeResultsInWorker", this).call(this, result, args);
      var features = result.features;
      return _objectSpread(_objectSpread({}, serialized), {}, {
        features: (0, _util.iterMap)(features.values(), function (f) {
          return f.toJSON();
        }, features.size)
      });
    }
    /**
     * will expand if soft clipping or feature glyphs are shown
     *
     * @param region - rendering region
     * @param _renderArgs - render args, unused, may be used in deriving classes
     */

  }, {
    key: "getExpandedRegion",
    value: function getExpandedRegion(region, _renderArgs) {
      return region;
    }
    /**
     * use the dataAdapter to fetch the features to be rendered
     *
     * @param renderArgs -
     * @returns Map of features as `{ id => feature, ... }`
     */

  }, {
    key: "getFeatures",
    value: function () {
      var _getFeatures = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(renderArgs) {
        var _this = this;

        var signal, regions, sessionId, adapterConfig, _yield$getAdapter, dataAdapter, features, requestRegions, region, featureObservable, feats;

        return _regenerator.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                signal = renderArgs.signal, regions = renderArgs.regions, sessionId = renderArgs.sessionId, adapterConfig = renderArgs.adapterConfig;
                _context.next = 3;
                return (0, _dataAdapterCache.getAdapter)(this.pluginManager, sessionId, adapterConfig);

              case 3:
                _yield$getAdapter = _context.sent;
                dataAdapter = _yield$getAdapter.dataAdapter;

                if ((0, _BaseAdapter.isFeatureAdapter)(dataAdapter)) {
                  _context.next = 7;
                  break;
                }

                throw new Error('Adapter does not support retrieving features');

              case 7:
                features = new Map();

                if (!(!regions || regions.length === 0)) {
                  _context.next = 10;
                  break;
                }

                return _context.abrupt("return", features);

              case 10:
                requestRegions = regions.map(function (r) {
                  // make sure the requested region's start and end are integers, if
                  // there is a region specification.
                  var requestRegion = _objectSpread({}, r);

                  if (requestRegion.start) {
                    requestRegion.start = Math.floor(requestRegion.start);
                  }

                  if (requestRegion.end) {
                    requestRegion.end = Math.ceil(requestRegion.end);
                  }

                  return requestRegion;
                });
                region = requestRegions[0];
                featureObservable = requestRegions.length === 1 ? dataAdapter.getFeatures(this.getExpandedRegion(region, renderArgs), renderArgs) : dataAdapter.getFeaturesInMultipleRegions(requestRegions, renderArgs);
                _context.next = 15;
                return featureObservable.pipe((0, _operators.toArray)()).toPromise();

              case 15:
                feats = _context.sent;
                (0, _util.checkAbortSignal)(signal);
                return _context.abrupt("return", new Map(feats.filter(function (feat) {
                  return _this.featurePassesFilters(renderArgs, feat);
                }).map(function (feat) {
                  return [feat.id(), feat];
                })));

              case 18:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function getFeatures(_x) {
        return _getFeatures.apply(this, arguments);
      }

      return getFeatures;
    }()
    /**
     * @param renderArgs -
     * @param feature -
     * @returns true if this feature passes all configured filters
     */

  }, {
    key: "featurePassesFilters",
    value: function featurePassesFilters(renderArgs, feature) {
      if (!renderArgs.filters) {
        return true;
      }

      return renderArgs.filters.passes(feature, renderArgs);
    }
    /**
     * gets features and renders
     *
     * @param props - render args
     */

  }, {
    key: "render",
    value: function () {
      var _render = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(props) {
        var features, result;
        return _regenerator.default.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                _context2.t0 = props.features;

                if (_context2.t0) {
                  _context2.next = 5;
                  break;
                }

                _context2.next = 4;
                return this.getFeatures(props);

              case 4:
                _context2.t0 = _context2.sent;

              case 5:
                features = _context2.t0;
                _context2.next = 8;
                return (0, _get2.default)((0, _getPrototypeOf2.default)(FeatureRendererType.prototype), "render", this).call(this, _objectSpread(_objectSpread({}, props), {}, {
                  features: features
                }));

              case 8:
                result = _context2.sent;
                return _context2.abrupt("return", _objectSpread(_objectSpread({}, result), {}, {
                  features: features
                }));

              case 10:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      function render(_x2) {
        return _render.apply(this, arguments);
      }

      return render;
    }()
  }]);
  return FeatureRendererType;
}(_ServerSideRendererType.default);

exports.default = FeatureRendererType;

var NewFeatureRendererType = /*#__PURE__*/function (_ServerSideRendererTy2) {
  (0, _inherits2.default)(NewFeatureRendererType, _ServerSideRendererTy2);

  var _super2 = _createSuper(NewFeatureRendererType);

  function NewFeatureRendererType() {
    (0, _classCallCheck2.default)(this, NewFeatureRendererType);
    return _super2.apply(this, arguments);
  }

  return (0, _createClass2.default)(NewFeatureRendererType);
}(_ServerSideRendererType.default);

exports.NewFeatureRendererType = NewFeatureRendererType;

@cmdcolin cmdcolin added the bug Something isn't working label Jul 14, 2022
@cmdcolin cmdcolin changed the title Create tsc compilation of @jbrowse/core Fix use of embedded components with vite 3.0 using tsc to compile @jbrowse/core Jul 14, 2022
@cmdcolin cmdcolin removed the needs label triage Needs a label to show in changelog (breaking, enhancement, bug, documentation, or internal) label Jul 14, 2022
@codecov
Copy link

codecov bot commented Jul 14, 2022

Codecov Report

Merging #3092 (a6e3402) into main (f2322b5) will decrease coverage by 0.31%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #3092      +/-   ##
==========================================
- Coverage   61.39%   61.07%   -0.32%     
==========================================
  Files         595      597       +2     
  Lines       27223    27377     +154     
  Branches     6567     6624      +57     
==========================================
+ Hits        16713    16720       +7     
- Misses      10213    10323     +110     
- Partials      297      334      +37     
Impacted Files Coverage Δ
...gableElementTypes/renderers/FeatureRendererType.ts 71.15% <ø> (ø)
packages/core/util/mst-reflection.js 44.26% <0.00%> (-24.97%) ⬇️
...eElementTypes/models/BaseConnectionModelFactory.js 52.17% <0.00%> (-22.83%) ⬇️
packages/core/util/QuickLRU.js 27.83% <0.00%> (-13.71%) ⬇️
products/jbrowse-web/src/util.ts 27.27% <0.00%> (ø)
...ckages/core/util/layouts/PrecomputedMultiLayout.js 0.00% <0.00%> (ø)
packages/core/ReExports/material-ui-colors.js 0.00% <0.00%> (ø)
...ckages/__mocks__/@jbrowse/core/ui/CascadingMenu.js 0.00% <0.00%> (ø)
packages/core/util/layouts/GranularRectLayout.ts 87.28% <0.00%> (+0.42%) ⬆️
...FeatureRenderer/components/ProcessedTranscript.tsx 88.73% <0.00%> (+1.40%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f2322b5...a6e3402. Read the comment docs.

@cmdcolin cmdcolin merged commit c6d5c29 into main Jul 14, 2022
@cmdcolin cmdcolin deleted the tsc_core branch July 14, 2022 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embedded component unable to build using vite 3.0, works in 2.0
1 participant