Skip to content

Commit

Permalink
fix(module-loader-commonjs): remove unused moduleType from signature
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Jul 7, 2021
1 parent c4edc8d commit f39cd0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 0 additions & 1 deletion packages/module-loader-commonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"module": "lib/esm/index.js",
"typings": "lib/cjs/index.d.ts",
"dependencies": {
"@feature-hub/core": "^2.8.1",
"node-fetch": "^2.6.0"
},
"devDependencies": {
Expand Down
25 changes: 22 additions & 3 deletions packages/module-loader-commonjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import {ModuleLoader} from '@feature-hub/core';
import fetch, {RequestInit} from 'node-fetch';

export interface Externals {
readonly [externalName: string]: unknown;
}

/**
* @param externals An object with shared npm dependencies that the integrator
* wants to provide to Feature Apps. The keys are the names of the dependencies
* that are used in import/require statements. The values are the modules.
*
* @param requestInit An object containing any custom settings that should be
* applied to the request when fetching a module with node-fetch.
*
* @returns A function that accepts a URL pointing to a bundle that was built as
* a CommonJS module, and that returns a promise that resolves with the loaded
* module, or is rejected if the module can not be loaded.
*/
export function createCommonJsModuleLoader(
externals: Externals = {},
requestInit?: RequestInit
): ModuleLoader {
): (url: string) => Promise<unknown> {
return async (url: string): Promise<unknown> => {
const response = await fetch(url, requestInit);
const source = await response.text();
Expand All @@ -30,4 +41,12 @@ export function createCommonJsModuleLoader(
};
}

export const loadCommonJsModule: ModuleLoader = createCommonJsModuleLoader();
/**
* @param url A URL pointing to a bundle that was built as a CommonJS module.
*
* @returns A promise that resolves with the loaded module, or is rejected if
* the module can not be loaded.
*/
export const loadCommonJsModule: (
url: string
) => Promise<unknown> = createCommonJsModuleLoader();
3 changes: 1 addition & 2 deletions packages/module-loader-commonjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"compilerOptions": {
"outDir": "lib/cjs",
"rootDir": "src"
},
"references": [{"path": "../core"}]
}
}

0 comments on commit f39cd0d

Please sign in to comment.