stonyx 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/modules.js +10 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stonyx",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Base stonyx framework module",
5
5
  "main": "main.js",
6
6
  "type": "module",
package/src/modules.js CHANGED
@@ -6,8 +6,10 @@ import { readFile } from '@stonyx/utils/file';
6
6
 
7
7
  export default async (config, rootPath) => {
8
8
  const modules = [];
9
+ const initPromises = [];
9
10
  const rootPackage = await readFile(`${rootPath}/package.json`, { json: true });
10
11
  const { devDependencies:dependencies } = rootPackage;
12
+ config.rootPath = rootPath;
11
13
 
12
14
  for (const moduleName of Object.keys(dependencies)) {
13
15
  if (!moduleName.startsWith('@stonyx/')) continue; // All official stonyx modules should be start with "@stonyx/"
@@ -37,11 +39,17 @@ export default async (config, rootPath) => {
37
39
 
38
40
  const { main: entryPoint } = modulePackage;
39
41
  const { default: moduleClass } = await import(`${rootPath}/node_modules/${moduleName}/${entryPoint}`);
40
-
41
- modules.push(new moduleClass());
42
+ const moduleInstance = new moduleClass();
43
+
44
+ modules.push(moduleInstance);
45
+ if (moduleInstance.init) initPromises.push(moduleInstance.init());
46
+
42
47
  } catch (error) {
43
48
  console.error(error);
44
49
  throw new Error(`Stonyx modules with async loading must have a config/environment.js file with default configurations.`);
45
50
  }
46
51
  }
52
+
53
+ // Wait until all modules are initialized
54
+ await Promise.all(initPromises);
47
55
  }