Skip to content

Commit

Permalink
Merge pull request #1358 from opencomponents/p-limit-esm
Browse files Browse the repository at this point in the history
move to p-limit await import. node 18 and improve plugin type
  • Loading branch information
ricardo-devis-agullo authored Feb 26, 2024
2 parents 1562053 + 7c5b316 commit aa8d5e8
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 23 deletions.
51 changes: 39 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prepare": "husky install"
},
"engines": {
"node": ">=16"
"node": ">=18"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -71,7 +71,7 @@
"minimist": "^1.2.8",
"mocha": "^9.1.3",
"node-emoji": "^1.11.0",
"p-limit": "^3.1.0",
"p-limit": "^5.0.0",
"prettier": "^3.2.4",
"rimraf": "^3.0.2",
"semver-sort": "^1.0.0",
Expand Down Expand Up @@ -128,4 +128,4 @@
"universalify": "^2.0.0",
"yargs": "^17.7.2"
}
}
}
3 changes: 2 additions & 1 deletion src/registry/domain/components-cache/components-list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import semver from 'semver';
import pLimit from 'p-limit';
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
import { StorageAdapter } from 'oc-storage-adapters-utils';
import eventsHandler from '../events-handler';
Expand Down Expand Up @@ -40,6 +39,7 @@ export default function componentsList(conf: Config, cdn: StorageAdapter) {
const unCheckedVersions = allVersions.filter(
version => !jsonList?.components[componentName]?.includes(version)
);
const { default: pLimit } = await import('p-limit');
const limit = pLimit(cdn.maxConcurrentRequests);
const invalidVersions = (
await Promise.all(
Expand Down Expand Up @@ -76,6 +76,7 @@ export default function componentsList(conf: Config, cdn: StorageAdapter) {
const components = await cdn.listSubDirectories(
conf.storage.options.componentsDir
);
const { default: pLimit } = await import('p-limit');
const limit = pLimit(cdn.maxConcurrentRequests);

const versions = await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion src/registry/domain/components-details.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pLimit from 'p-limit';
import _ from 'lodash';
import eventsHandler from './events-handler';
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
Expand Down Expand Up @@ -42,6 +41,7 @@ export default function componentsDetails(conf: Config, cdn: StorageAdapter) {
});
});

const { default: pLimit } = await import('p-limit');
const limit = pLimit(cdn.maxConcurrentRequests);

await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion src/registry/domain/plugins-initialiser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pLimit from 'p-limit';
import _ from 'lodash';
import { DepGraph } from 'dependency-graph';
import { promisify } from 'util';
Expand Down Expand Up @@ -117,6 +116,7 @@ export async function init(
return registered;
};

const { default: pLimit } = await import('p-limit');
const onSeries = pLimit(1);

await Promise.all(
Expand Down
4 changes: 2 additions & 2 deletions src/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default function registry<T = any>(inputOptions: RegistryOptions<T>) {
return callback('not opened');
};

const register = (
plugin: Omit<Plugin, 'callback'>,
const register = <T = any>(
plugin: Omit<Plugin<T>, 'callback'>,
callback?: (...args: any[]) => void
) => {
plugins.push(Object.assign(plugin, { callback }));
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ export interface Template {
) => void;
}

export interface Plugin {
export interface Plugin<T = any> {
callback?: (error: unknown) => void;
description?: string;
name: string;
options?: any;
options?: T;
register: {
register: (
options: any,
options: T,
dependencies: any,
next: (error?: Error) => void
) => void;
Expand Down

0 comments on commit aa8d5e8

Please sign in to comment.