Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@feature-hub/core

Package Overview
Dependencies
Maintainers
5
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feature-hub/core - npm Package Compare versions

Comparing version 2.9.0-alpha.1 to 2.9.0

lib/cjs/__tests__/create-feature-hub.test.d.ts

16

CHANGELOG.md

@@ -6,2 +6,18 @@ # Change Log

# [2.9.0](https://github.com/sinnerschrader/feature-hub/compare/v2.8.1...v2.9.0) (2021-07-12)
### Bug Fixes
* **all:** handle module type during hydration ([5cd3373](https://github.com/sinnerschrader/feature-hub/commit/5cd3373bd84466a187177be22f68fb0d27029e94))
### Features
* **core:** enhance module loader with module type ([ed56640](https://github.com/sinnerschrader/feature-hub/commit/ed5664083c02a2e2f849e1ab914b7253074a7ea2))
## [2.8.1](https://github.com/sinnerschrader/feature-hub/compare/v2.8.0...v2.8.1) (2020-11-14)

@@ -8,0 +24,0 @@

9

lib/cjs/create-feature-hub.d.ts

@@ -38,6 +38,7 @@ import { ProvidedExternals } from './externals-validator';

/**
* For the [[FeatureAppManager]] to be able to load Feature Apps from a
* remote location, a module loader must be provided, (e.g. the
* `@feature-hub/module-loader-amd` package or the
* `@feature-hub/module-loader-commonjs` package).
* For the `FeatureAppManager` to be able to load Feature Apps from a remote
* location, a module loader must be provided. This can either be one of the
* module loaders that are provided by @feature-hub, i.e.
* `@feature-hub/module-loader-amd`, `@feature-hub/module-loader-federation`,
* and `@feature-hub/module-loader-commonjs`, or a custom loader.
*/

@@ -44,0 +45,0 @@ readonly moduleLoader?: ModuleLoader;

@@ -38,3 +38,11 @@ import { AsyncValue } from './async-value';

}
export declare type ModuleLoader = (url: string) => Promise<unknown>;
/**
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This can be used to choose different loading strategies based on the module
* type of the Feature App.
*/
export declare type ModuleLoader = (url: string, moduleType?: string) => Promise<unknown>;
export interface FeatureAppScope<TFeatureApp> {

@@ -79,5 +87,6 @@ readonly featureApp: TFeatureApp;

* For the `FeatureAppManager` to be able to load Feature Apps from a remote
* location, a module loader must be provided, (e.g. the
* `@feature-hub/module-loader-amd` package or the
* `@feature-hub/module-loader-commonjs` package).
* location, a module loader must be provided. This can either be one of the
* module loaders that are provided by @feature-hub, i.e.
* `@feature-hub/module-loader-amd`, `@feature-hub/module-loader-federation`,
* and `@feature-hub/module-loader-commonjs`, or a custom loader.
*/

@@ -116,12 +125,16 @@ readonly moduleLoader?: ModuleLoader;

*
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a
* module format compatible with the module loader.
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This value can be used by the provided
* [[FeatureAppManagerOptions.moduleLoader]].
*
* @returns An [[AsyncValue]] containing a promise that resolves with the
* loaded [[FeatureAppDefinition]]. If called again with the same URL it
* returns the same [[AsyncValue]]. The promise rejects when loading
* fails, or when the loaded bundle doesn't export a [[FeatureAppDefinition]]
* as default.
* returns the same [[AsyncValue]]. The promise rejects when loading fails, or
* when the loaded bundle doesn't export a [[FeatureAppDefinition]] as
* default.
*/
getAsyncFeatureAppDefinition(url: string): AsyncValue<FeatureAppDefinition<unknown>>;
getAsyncFeatureAppDefinition(url: string, moduleType?: string): AsyncValue<FeatureAppDefinition<unknown>>;
/**

@@ -158,5 +171,10 @@ * Create a [[FeatureAppScope]] which includes validating externals, binding

*
* @see [[getAsyncFeatureAppDefinition]] for further information.
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This value can be used by the provided
* [[FeatureAppManagerOptions.moduleLoader]].
*/
preloadFeatureApp(url: string): Promise<void>;
preloadFeatureApp(url: string, moduleType?: string): Promise<void>;
private createAsyncFeatureAppDefinition;

@@ -163,0 +181,0 @@ private registerOwnFeatureServices;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureAppManager = void 0;
const async_value_1 = require("./async-value");
const Messages = __importStar(require("./internal/feature-app-manager-messages"));
const is_feature_app_module_1 = require("./internal/is-feature-app-module");

@@ -24,16 +44,21 @@ /**

*
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a
* module format compatible with the module loader.
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This value can be used by the provided
* [[FeatureAppManagerOptions.moduleLoader]].
*
* @returns An [[AsyncValue]] containing a promise that resolves with the
* loaded [[FeatureAppDefinition]]. If called again with the same URL it
* returns the same [[AsyncValue]]. The promise rejects when loading
* fails, or when the loaded bundle doesn't export a [[FeatureAppDefinition]]
* as default.
* returns the same [[AsyncValue]]. The promise rejects when loading fails, or
* when the loaded bundle doesn't export a [[FeatureAppDefinition]] as
* default.
*/
getAsyncFeatureAppDefinition(url) {
let asyncFeatureAppDefinition = this.asyncFeatureAppDefinitions.get(url);
getAsyncFeatureAppDefinition(url, moduleType) {
const key = `${url}${moduleType}`;
let asyncFeatureAppDefinition = this.asyncFeatureAppDefinitions.get(key);
if (!asyncFeatureAppDefinition) {
asyncFeatureAppDefinition = this.createAsyncFeatureAppDefinition(url);
this.asyncFeatureAppDefinitions.set(url, asyncFeatureAppDefinition);
asyncFeatureAppDefinition = this.createAsyncFeatureAppDefinition(url, moduleType);
this.asyncFeatureAppDefinitions.set(key, asyncFeatureAppDefinition);
}

@@ -88,8 +113,13 @@ return asyncFeatureAppDefinition;

*
* @see [[getAsyncFeatureAppDefinition]] for further information.
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This value can be used by the provided
* [[FeatureAppManagerOptions.moduleLoader]].
*/
async preloadFeatureApp(url) {
await this.getAsyncFeatureAppDefinition(url).promise;
async preloadFeatureApp(url, moduleType) {
await this.getAsyncFeatureAppDefinition(url, moduleType).promise;
}
createAsyncFeatureAppDefinition(url) {
createAsyncFeatureAppDefinition(url, moduleType) {
const { moduleLoader: loadModule } = this.options;

@@ -99,5 +129,5 @@ if (!loadModule) {

}
return new async_value_1.AsyncValue(loadModule(url).then((featureAppModule) => {
return new async_value_1.AsyncValue(loadModule(url, moduleType).then((featureAppModule) => {
if (!is_feature_app_module_1.isFeatureAppModule(featureAppModule)) {
throw new Error(`The Feature App module at the url ${JSON.stringify(url)} is invalid. A Feature App module must have a Feature App definition as default export. A Feature App definition is an object with at least a \`create\` method.`);
throw new Error(Messages.invalidFeatureAppModule(url, moduleType, this.options.moduleLoader));
}

@@ -104,0 +134,0 @@ this.logger.info(`The Feature App module at the url ${JSON.stringify(url)} has been successfully loaded.`);

@@ -38,6 +38,7 @@ import { ProvidedExternals } from './externals-validator';

/**
* For the [[FeatureAppManager]] to be able to load Feature Apps from a
* remote location, a module loader must be provided, (e.g. the
* `@feature-hub/module-loader-amd` package or the
* `@feature-hub/module-loader-commonjs` package).
* For the `FeatureAppManager` to be able to load Feature Apps from a remote
* location, a module loader must be provided. This can either be one of the
* module loaders that are provided by @feature-hub, i.e.
* `@feature-hub/module-loader-amd`, `@feature-hub/module-loader-federation`,
* and `@feature-hub/module-loader-commonjs`, or a custom loader.
*/

@@ -44,0 +45,0 @@ readonly moduleLoader?: ModuleLoader;

@@ -38,3 +38,11 @@ import { AsyncValue } from './async-value';

}
export declare type ModuleLoader = (url: string) => Promise<unknown>;
/**
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This can be used to choose different loading strategies based on the module
* type of the Feature App.
*/
export declare type ModuleLoader = (url: string, moduleType?: string) => Promise<unknown>;
export interface FeatureAppScope<TFeatureApp> {

@@ -79,5 +87,6 @@ readonly featureApp: TFeatureApp;

* For the `FeatureAppManager` to be able to load Feature Apps from a remote
* location, a module loader must be provided, (e.g. the
* `@feature-hub/module-loader-amd` package or the
* `@feature-hub/module-loader-commonjs` package).
* location, a module loader must be provided. This can either be one of the
* module loaders that are provided by @feature-hub, i.e.
* `@feature-hub/module-loader-amd`, `@feature-hub/module-loader-federation`,
* and `@feature-hub/module-loader-commonjs`, or a custom loader.
*/

@@ -116,12 +125,16 @@ readonly moduleLoader?: ModuleLoader;

*
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a
* module format compatible with the module loader.
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This value can be used by the provided
* [[FeatureAppManagerOptions.moduleLoader]].
*
* @returns An [[AsyncValue]] containing a promise that resolves with the
* loaded [[FeatureAppDefinition]]. If called again with the same URL it
* returns the same [[AsyncValue]]. The promise rejects when loading
* fails, or when the loaded bundle doesn't export a [[FeatureAppDefinition]]
* as default.
* returns the same [[AsyncValue]]. The promise rejects when loading fails, or
* when the loaded bundle doesn't export a [[FeatureAppDefinition]] as
* default.
*/
getAsyncFeatureAppDefinition(url: string): AsyncValue<FeatureAppDefinition<unknown>>;
getAsyncFeatureAppDefinition(url: string, moduleType?: string): AsyncValue<FeatureAppDefinition<unknown>>;
/**

@@ -158,5 +171,10 @@ * Create a [[FeatureAppScope]] which includes validating externals, binding

*
* @see [[getAsyncFeatureAppDefinition]] for further information.
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This value can be used by the provided
* [[FeatureAppManagerOptions.moduleLoader]].
*/
preloadFeatureApp(url: string): Promise<void>;
preloadFeatureApp(url: string, moduleType?: string): Promise<void>;
private createAsyncFeatureAppDefinition;

@@ -163,0 +181,0 @@ private registerOwnFeatureServices;

import { AsyncValue } from './async-value';
import * as Messages from './internal/feature-app-manager-messages';
import { isFeatureAppModule } from './internal/is-feature-app-module';

@@ -21,16 +22,21 @@ /**

*
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a
* module format compatible with the module loader.
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This value can be used by the provided
* [[FeatureAppManagerOptions.moduleLoader]].
*
* @returns An [[AsyncValue]] containing a promise that resolves with the
* loaded [[FeatureAppDefinition]]. If called again with the same URL it
* returns the same [[AsyncValue]]. The promise rejects when loading
* fails, or when the loaded bundle doesn't export a [[FeatureAppDefinition]]
* as default.
* returns the same [[AsyncValue]]. The promise rejects when loading fails, or
* when the loaded bundle doesn't export a [[FeatureAppDefinition]] as
* default.
*/
getAsyncFeatureAppDefinition(url) {
let asyncFeatureAppDefinition = this.asyncFeatureAppDefinitions.get(url);
getAsyncFeatureAppDefinition(url, moduleType) {
const key = `${url}${moduleType}`;
let asyncFeatureAppDefinition = this.asyncFeatureAppDefinitions.get(key);
if (!asyncFeatureAppDefinition) {
asyncFeatureAppDefinition = this.createAsyncFeatureAppDefinition(url);
this.asyncFeatureAppDefinitions.set(url, asyncFeatureAppDefinition);
asyncFeatureAppDefinition = this.createAsyncFeatureAppDefinition(url, moduleType);
this.asyncFeatureAppDefinitions.set(key, asyncFeatureAppDefinition);
}

@@ -85,8 +91,13 @@ return asyncFeatureAppDefinition;

*
* @see [[getAsyncFeatureAppDefinition]] for further information.
* @param url A URL pointing to a [[FeatureAppDefinition]] bundle in a module
* format compatible with the module loader.
*
* @param moduleType The module type of the [[FeatureAppDefinition]] bundle.
* This value can be used by the provided
* [[FeatureAppManagerOptions.moduleLoader]].
*/
async preloadFeatureApp(url) {
await this.getAsyncFeatureAppDefinition(url).promise;
async preloadFeatureApp(url, moduleType) {
await this.getAsyncFeatureAppDefinition(url, moduleType).promise;
}
createAsyncFeatureAppDefinition(url) {
createAsyncFeatureAppDefinition(url, moduleType) {
const { moduleLoader: loadModule } = this.options;

@@ -96,5 +107,5 @@ if (!loadModule) {

}
return new AsyncValue(loadModule(url).then((featureAppModule) => {
return new AsyncValue(loadModule(url, moduleType).then((featureAppModule) => {
if (!isFeatureAppModule(featureAppModule)) {
throw new Error(`The Feature App module at the url ${JSON.stringify(url)} is invalid. A Feature App module must have a Feature App definition as default export. A Feature App definition is an object with at least a \`create\` method.`);
throw new Error(Messages.invalidFeatureAppModule(url, moduleType, this.options.moduleLoader));
}

@@ -101,0 +112,0 @@ this.logger.info(`The Feature App module at the url ${JSON.stringify(url)} has been successfully loaded.`);

{
"name": "@feature-hub/core",
"version": "2.9.0-alpha.1",
"version": "2.9.0",
"description": "Create scalable web applications using micro frontends.",

@@ -41,3 +41,3 @@ "keywords": [

},
"gitHead": "4adcc69fce921150cfef6a67c91abafe755928fa"
"gitHead": "78d90b0cbb29515ced062046680793aed4513309"
}

@@ -20,3 +20,3 @@ # @feature-hub/core

### Using NPM
### Using npm

@@ -29,3 +29,3 @@ ```sh

Copyright (c) 2018-2019 SinnerSchrader Deutschland GmbH. Released under the
Copyright (c) 2018-2021 SinnerSchrader Deutschland GmbH. Released under the
terms of the [MIT License][license].

@@ -32,0 +32,0 @@

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc