npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@scalprum/core

v0.9.0

Published

Includes core functions for scalprum scaffolding.

Downloads

76,908

Readme

@scalprum/core

Framework-agnostic core for micro-frontend module federation

The @scalprum/core package provides the foundational module federation capabilities for Scalprum. It's a framework-agnostic library that handles dynamic module loading, caching, and manifest processing - making it compatible with any JavaScript framework, not just React.

Installation

npm install @scalprum/core

Key Features

  • Framework Agnostic: Works with any JavaScript framework or vanilla JS
  • Dynamic Module Loading: Load remote modules at runtime with caching
  • Manifest Processing: Support for both plugin manifests and custom formats
  • Shared Scope Management: Integration with webpack's module federation shared scopes
  • Shared Stores: Event-driven state management for micro-frontends
  • Built-in Caching: Intelligent module caching with configurable timeout
  • Error Handling: Robust error handling for network and module loading failures

Basic Usage

import { initialize, getModule, AppsConfig } from '@scalprum/core';

// Configure your remote modules
const config: AppsConfig = {
  myRemoteApp: {
    name: 'myRemoteApp',
    manifestLocation: 'http://localhost:3001/plugin-manifest.json'
  }
};

// Initialize Scalprum
const scalprum = initialize({
  appsConfig: config,
  api: { /* shared context */ }
});

// Load a module dynamically
const MyComponent = await getModule('myRemoteApp', 'MyComponent');

API Reference

Core Functions

initialize(options)

Initializes the Scalprum instance with configuration.

Parameters:

  • appsConfig: AppsConfig - Configuration for remote modules
  • api?: any - Shared API context available to all modules
  • options?: Partial<ScalprumOptions> - Optional configuration
  • pluginStoreFeatureFlags?: FeatureFlags - Feature flags for plugin store
  • pluginLoaderOptions?: PluginLoaderOptions - Options for plugin loader
  • pluginStoreOptions?: PluginStoreOptions - Options for plugin store

Returns: Scalprum instance

getModule<T>(scope, module, importName?)

Loads a module from a remote container.

Parameters:

  • scope: string - The remote container name
  • module: string - The module name to load
  • importName?: string - Specific export name (defaults to 'default')

Returns: Promise<T> - The loaded module

getScalprum()

Gets the current Scalprum instance.

Returns: Scalprum instance

Throws: Error if Scalprum hasn't been initialized

Configuration Types

AppsConfig

interface AppsConfig<T = {}> {
  [key: string]: AppMetadata<T>;
}

type AppMetadata<T = {}> = T & {
  name: string;
  appId?: string;
  elementId?: string;
  rootLocation?: string;
  scriptLocation?: string;
  manifestLocation?: string;
  pluginManifest?: PluginManifest;
};

ScalprumOptions

interface ScalprumOptions {
  cacheTimeout: number;        // Cache timeout in seconds (default: 120)
  enableScopeWarning: boolean; // Enable duplicate package warnings
}

Advanced Usage

Preloading Modules

import { preloadModule } from '@scalprum/core';

// Preload a module without importing it
await preloadModule('myRemoteApp', 'MyComponent');

// With custom manifest processor
await preloadModule('myRemoteApp', 'MyComponent', (manifest) => manifest.assets.js);

// Later, get the cached module instantly
const MyComponent = await getModule('myRemoteApp', 'MyComponent');

Custom Manifest Processing

const processor = (manifest: any) => {
  // Extract entry scripts from custom manifest format
  return manifest.assets.js;
};

await processManifest(
  'http://localhost:3001/custom-manifest.json',
  'myScope',
  'MyModule',
  processor
);

Module Caching

import { getCachedModule } from '@scalprum/core';

// Check if module is cached
const { cachedModule, prefetchPromise } = getCachedModule('myScope', 'MyModule');

if (cachedModule) {
  // Module is cached and ready
  const component = cachedModule.default;
}

Shared Scope Integration

Scalprum integrates with webpack's module federation shared scopes:

import { initSharedScope, getSharedScope } from '@scalprum/core';

// Initialize shared scope
await initSharedScope();

// Get shared scope object
const sharedScope = getSharedScope(true); // true enables duplicate warnings

Error Handling

try {
  const module = await getModule('myScope', 'NonExistentModule');
} catch (error) {
  if (error.message.includes('Module not initialized')) {
    // Module wasn't found in the remote container
    console.error('Module not available:', error);
  } else if (error.message.includes('Manifest location not found')) {
    // Scope configuration is missing manifestLocation
    console.error('Configuration error:', error);
  }
}

Build Tool Compatibility

This package is compatible with:

  • Webpack 5 with Module Federation
  • Rspack with Module Federation support
  • Module Federation Runtime for any bundler

Shared Stores

The createSharedStore function enables event-driven state management across microfrontends. See the comprehensive Shared Stores Guide for detailed documentation.

Quick Example:

import { createSharedStore } from '@scalprum/core';

const EVENTS = ['UPDATE_USER', 'LOGOUT'] as const;

const store = createSharedStore({
  initialState: { user: null, isAuthenticated: false },
  events: EVENTS,
  onEventChange: (state, event, payload) => {
    switch (event) {
      case 'UPDATE_USER':
        return { ...state, user: payload.user, isAuthenticated: true };
      case 'LOGOUT':
        return { user: null, isAuthenticated: false };
      default:
        return state;
    }
  },
});

// Update state
store.updateState('UPDATE_USER', { user: { id: '123', name: 'John' } });

// Subscribe to changes
const unsubscribe = store.subscribeAll(() => {
  console.log('State changed:', store.getState());
});

For React integration, use with useGetState and useSubscribeStore from @scalprum/react-core. See Shared Stores Documentation for complete guide.

Related Packages