Skip to content

Commit 855e98d

Browse files
authored
Merge pull request #107 from Hyperkid123/get-module
Add getModule method to core.
2 parents 138eb84 + c07cfec commit 855e98d

27 files changed

+15219
-27662
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"rules": {
2929
"@typescript-eslint/ban-types": "off",
30+
"@typescript-eslint/no-explicit-any": "warn",
3031
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "after-used", "argsIgnorePattern": "^_", "ignoreRestSiblings": false }]
3132
}
3233
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe('UseModule loading callback', () => {
2+
it('should display SDK inbox text', () => {
3+
cy.visit('http://localhost:8123/use-module');
4+
cy.contains('SDK Inbox').should('exist');
5+
});
6+
});

jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const transformIgnorePatterns = ['node_modules/(?!(@openshift|lodash-es)/)'];
1+
const transformIgnorePatterns = ['node_modules/(?!(uuid)/)'];
22

33
/** @type {import('jest').Config} */
44
module.exports = {
@@ -15,5 +15,7 @@ module.exports = {
1515
'^.+\\.(js|jsx)$': 'babel-jest',
1616
},
1717
transformIgnorePatterns,
18+
// needs to fix the memory leak errors
19+
coverageProvider: 'v8',
1820
setupFilesAfterEnv: ['<rootDir>/config/jest.setup.js'],
1921
};

lerna.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
22
"npmClient": "npm",
3-
"version": "independent",
4-
"useWorkspaces": true
3+
"version": "independent"
54
}

package-lock.json

Lines changed: 15086 additions & 16192 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,40 @@
88
"packages/**"
99
],
1010
"devDependencies": {
11-
"@babel/preset-env": "^7.15.8",
12-
"@babel/preset-react": "^7.14.5",
13-
"@babel/preset-typescript": "^7.15.0",
14-
"@testing-library/jest-dom": "^5.14.1",
15-
"@testing-library/react": "^12.1.2",
16-
"@types/jest": "^27.0.2",
17-
"@types/lodash": "^4.14.176",
18-
"@types/react": "^17.0.31",
19-
"@types/react-grid-layout": "^1.3.2",
20-
"@types/react-router-dom": "^5.3.1",
21-
"@typescript-eslint/eslint-plugin": "^5.1.0",
22-
"@typescript-eslint/parser": "^5.1.0",
23-
"babel-jest": "^27.5.1",
24-
"chokidar": "^3.5.2",
25-
"css-loader": "^6.7.3",
26-
"cypress": "^10.6.0",
27-
"eslint": "^8.0.1",
28-
"eslint-config-prettier": "^8.3.0",
29-
"eslint-plugin-cypress": "^2.12.1",
30-
"eslint-plugin-prettier": "^4.0.0",
31-
"fs-extra": "^10.0.0",
32-
"glob": "^7.2.0",
11+
"@babel/preset-env": "^7.23.2",
12+
"@babel/preset-react": "^7.22.15",
13+
"@babel/preset-typescript": "^7.23.2",
14+
"@testing-library/jest-dom": "^6.1.4",
15+
"@testing-library/react": "^14.0.0",
16+
"@types/jest": "^29.5.6",
17+
"@types/lodash": "^4.14.200",
18+
"@types/react": "^18.2.31",
19+
"@types/react-grid-layout": "^1.3.4",
20+
"@types/react-router-dom": "^5.3.3",
21+
"@typescript-eslint/eslint-plugin": "^6.8.0",
22+
"@typescript-eslint/parser": "^6.8.0",
23+
"babel-jest": "^29.7.0",
24+
"chokidar": "^3.5.3",
25+
"css-loader": "^6.8.1",
26+
"cypress": "^13.3.2",
27+
"eslint": "^8.52.0",
28+
"eslint-config-prettier": "^9.0.0",
29+
"eslint-plugin-cypress": "^2.15.1",
30+
"eslint-plugin-prettier": "^5.0.1",
31+
"fs-extra": "^11.1.1",
32+
"glob": "^10.3.10",
3333
"identity-obj-proxy": "^3.0.0",
34-
"jest": "~27.3.1",
35-
"lerna": "^6.4.1",
36-
"prettier": "^2.4.1",
34+
"jest": "~29.7.0",
35+
"jest-environment-jsdom": "^29.7.0",
36+
"lerna": "^7.4.1",
37+
"prettier": "^3.0.3",
3738
"process": "^0.11.10",
38-
"regenerator-runtime": "^0.13.11",
39-
"start-server-and-test": "^1.14.0",
40-
"style-loader": "^3.3.1",
41-
"ts-jest": "^27.0.7",
42-
"ts-loader": "^9.2.6",
43-
"typescript": "^4.4.4"
39+
"regenerator-runtime": "^0.14.0",
40+
"start-server-and-test": "^2.0.1",
41+
"style-loader": "^3.3.3",
42+
"ts-jest": "^29.1.1",
43+
"ts-loader": "^9.5.0",
44+
"typescript": "^5.2.2"
4445
},
4546
"scripts": {
4647
"start": "lerna run --parallel start:esm",
@@ -55,8 +56,6 @@
5556
"test:ci": "start-server-and-test start:test http-get://localhost:8123 cypress:run"
5657
},
5758
"dependencies": {
58-
"install": "^0.13.0",
59-
"npm": "^9.4.2",
60-
"react-grid-layout": "^1.3.4"
59+
"react-grid-layout": "^1.4.2"
6160
}
6261
}

packages/core/src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,30 @@ export const preloadModule = async (scope: string, module: string, processor?: (
176176
return setPendingLoading(scope, module, Promise.resolve(modulePromise));
177177
};
178178

179+
export const getModule = async <T = any, P = any>(scope: string, module: string, importName = 'default'): Promise<T> => {
180+
const scalprum = getScalprum();
181+
const { cachedModule } = getCachedModule(scope, module);
182+
let Module: ExposedScalprumModule<T, P>;
183+
const manifestLocation = getAppData(scope)?.manifestLocation;
184+
if (!manifestLocation) {
185+
throw new Error(`Could not get module. Manifest location not found for scope ${scope}.`);
186+
}
187+
if (!cachedModule) {
188+
try {
189+
await processManifest(manifestLocation, scope, module);
190+
Module = await scalprum.pluginStore.getExposedModule(scope, module);
191+
} catch {
192+
throw new Error(
193+
`Module not initialized! Module "${module}" was not found in "${scope}" webpack scope. Make sure the remote container is loaded?`,
194+
);
195+
}
196+
} else {
197+
Module = cachedModule;
198+
}
199+
200+
return Module[importName];
201+
};
202+
179203
export const initialize = <T extends Record<string, any> = Record<string, any>>({
180204
appsConfig,
181205
api,

packages/core/src/warnDuplicatePkg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const warnDuplicatePkg = (packages: Packages) => {
2020
const instances = Object.keys(versions);
2121
if (instances.length > 1) {
2222
console.warn(
23-
`[SCALPRUM]: You have ${pkgName} package that is being loaded into browser multiple times. You might want to align your version with the chrome one.`
23+
`[SCALPRUM]: You have ${pkgName} package that is being loaded into browser multiple times. You might want to align your version with the chrome one.`,
2424
);
2525
console.warn(`[SCALPRUM]: All packages instances:`, versions);
2626
}

packages/react-core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"devDependencies": {
2323
"@types/history": "^4.7.9",
24-
"@types/react": "^17.0.31",
24+
"@types/react": "^18.0.0",
2525
"@types/react-dom": "^17.0.10",
2626
"@types/react-router-dom": "^5.3.1"
2727
},
@@ -31,7 +31,7 @@
3131
"lodash": "^4.17.0"
3232
},
3333
"peerDependencies": {
34-
"react": ">=16.8.0 || >=17.0.0",
35-
"react-dom": ">=16.8.0 || >=17.0.0"
34+
"react": ">=16.8.0 || >=17.0.0 || ^18.0.0",
35+
"react-dom": ">=16.8.0 || >=17.0.0 || ^18.0.0"
3636
}
3737
}

packages/react-core/src/__snapshots__/scalprum-component.test.tsx.snap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ exports[`<ScalprumComponent /> should render fallback component 2`] = `
4343
`;
4444

4545
exports[`<ScalprumComponent /> should render test component 1`] = `
46-
<div>
47-
loading
48-
</div>
49-
`;
50-
51-
exports[`<ScalprumComponent /> should render test component 2`] = `
5246
<div>
5347
<span>
5448
Test

0 commit comments

Comments
 (0)