repluggable-core 1.302.73 → 1.302.74
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.
- package/dist/debug/src/API.d.ts +7 -0
- package/dist/es/src/API.d.ts +7 -0
- package/dist/es/src/API.d.ts.map +1 -1
- package/dist/es/src/appHost.d.ts.map +1 -1
- package/dist/es/src/appHost.js +23 -0
- package/dist/es/src/appHost.js.map +1 -1
- package/dist/es/test/appHost.spec.js +24 -0
- package/dist/es/test/appHost.spec.js.map +1 -1
- package/dist/src/API.d.ts +7 -0
- package/dist/src/API.d.ts.map +1 -1
- package/dist/src/appHost.d.ts.map +1 -1
- package/dist/src/appHost.js +23 -0
- package/dist/src/appHost.js.map +1 -1
- package/dist/test/appHost.spec.js +24 -0
- package/dist/test/appHost.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/API.ts +7 -0
- package/src/appHost.ts +30 -2
- package/test/appHost.spec.ts +30 -0
package/src/appHost.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import _ from 'lodash'
|
|
3
2
|
import { AnyAction, Store } from 'redux'
|
|
4
3
|
import {
|
|
@@ -56,7 +55,6 @@ import {
|
|
|
56
55
|
} from './throttledStore'
|
|
57
56
|
import { INTERNAL_DONT_USE_SHELL_GET_APP_HOST } from './__internal'
|
|
58
57
|
|
|
59
|
-
|
|
60
58
|
function isMultiArray<T>(v: T[] | T[][]): v is T[][] {
|
|
61
59
|
return _.every(v, _.isArray)
|
|
62
60
|
}
|
|
@@ -212,6 +210,7 @@ export function createAppHost(initialEntryPointsOrPackages: EntryPointOrPackage[
|
|
|
212
210
|
onShellsChanged,
|
|
213
211
|
onDeclarationsChanged,
|
|
214
212
|
removeShellsChangedCallback,
|
|
213
|
+
verifyPendingEntryPointsAPIsMismatch,
|
|
215
214
|
getAppHostServicesShell: appHostServicesEntryPoint.getAppHostServicesShell,
|
|
216
215
|
log: options.logger ? options.logger : ConsoleHostLogger,
|
|
217
216
|
options,
|
|
@@ -996,6 +995,7 @@ miss: ${memoizedWithMissHit.miss}
|
|
|
996
995
|
onShellsChanged: host.onShellsChanged,
|
|
997
996
|
onDeclarationsChanged: host.onDeclarationsChanged,
|
|
998
997
|
removeShellsChangedCallback: host.removeShellsChangedCallback,
|
|
998
|
+
verifyPendingEntryPointsAPIsMismatch: host.verifyPendingEntryPointsAPIsMismatch,
|
|
999
999
|
|
|
1000
1000
|
declareSlot<TItem>(key: SlotKey<TItem>): ExtensionSlot<TItem> {
|
|
1001
1001
|
return declareSlot<TItem>(key, shell)
|
|
@@ -1219,4 +1219,32 @@ miss: ${memoizedWithMissHit.miss}
|
|
|
1219
1219
|
function normalizeApiName(name: string) {
|
|
1220
1220
|
return name.charAt(0).toLowerCase() + name.substring(1).replace(new RegExp(' ', 'g'), '')
|
|
1221
1221
|
}
|
|
1222
|
+
|
|
1223
|
+
function verifyPendingEntryPointsAPIsMismatch(): void {
|
|
1224
|
+
const pendingEntryPoints = unReadyEntryPointsStore.get()
|
|
1225
|
+
|
|
1226
|
+
for (const entryPoint of pendingEntryPoints) {
|
|
1227
|
+
verifyEntryPointAPIsMismatch(entryPoint)
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
function verifyEntryPointAPIsMismatch(entryPoint: EntryPoint): void {
|
|
1232
|
+
const dependencies = entryPoint.getDependencyAPIs?.() || []
|
|
1233
|
+
|
|
1234
|
+
const mismatchedAPI = dependencies.find(dependencyAPI => {
|
|
1235
|
+
const isPrivateAPI = !dependencyAPI.public
|
|
1236
|
+
const foundDeclaredAPIKeyWithSameName = slotKeysByName.get(slotKeyToName(dependencyAPI))
|
|
1237
|
+
const isDeclaredAPIReady = foundDeclaredAPIKeyWithSameName ? readyAPIs.has(foundDeclaredAPIKeyWithSameName) : false
|
|
1238
|
+
|
|
1239
|
+
return isPrivateAPI && isDeclaredAPIReady && dependencyAPI !== foundDeclaredAPIKeyWithSameName
|
|
1240
|
+
})
|
|
1241
|
+
|
|
1242
|
+
if (mismatchedAPI) {
|
|
1243
|
+
throw new Error(
|
|
1244
|
+
`Entry point '${entryPoint.name}' is waiting for API '${mismatchedAPI.name}' that will never be available for it to use.\n` +
|
|
1245
|
+
`This usually happens when trying to consume a private API as a public API.\n` +
|
|
1246
|
+
`If the API is intended to be public, it should be declared as "public: true" in the API key, and built in both bundles.`
|
|
1247
|
+
)
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1222
1250
|
}
|
package/test/appHost.spec.ts
CHANGED
|
@@ -1762,4 +1762,34 @@ describe('App Host', () => {
|
|
|
1762
1762
|
expect(spy).toBeCalledTimes(2)
|
|
1763
1763
|
})
|
|
1764
1764
|
})
|
|
1765
|
+
|
|
1766
|
+
describe('Host.verifyPendingEntryPointsAPIsMismatch', () => {
|
|
1767
|
+
it("should throw an error on verification if there's a pending entry points that waits for an API that is contributed but is not available", () => {
|
|
1768
|
+
const PrivateAPI = { name: 'PrivateAPI' }
|
|
1769
|
+
const entryPointA: EntryPoint = {
|
|
1770
|
+
name: 'EntryPointA',
|
|
1771
|
+
declareAPIs: () => [PrivateAPI],
|
|
1772
|
+
attach(shell) {
|
|
1773
|
+
shell.contributeAPI(PrivateAPI, () => ({}))
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
const PrivateAPIUsedAsPublicAPI = _.cloneDeep(PrivateAPI)
|
|
1777
|
+
const entryPointB: EntryPoint = {
|
|
1778
|
+
name: 'EntryPointB',
|
|
1779
|
+
getDependencyAPIs: () => [PrivateAPIUsedAsPublicAPI],
|
|
1780
|
+
extend(shell) {
|
|
1781
|
+
shell.getAPI(PrivateAPIUsedAsPublicAPI)
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
const host = createAppHost([entryPointA, entryPointB], testHostOptions)
|
|
1785
|
+
|
|
1786
|
+
expect(() => host.verifyPendingEntryPointsAPIsMismatch()).toThrowError(
|
|
1787
|
+
new RegExp(
|
|
1788
|
+
`Entry point 'EntryPointB' is waiting for API '${PrivateAPI.name}' that will never be available for it to use.
|
|
1789
|
+
This usually happens when trying to consume a private API as a public API.
|
|
1790
|
+
If the API is intended to be public, it should be declared as "public: true" in the API key, and built in both bundles.`
|
|
1791
|
+
)
|
|
1792
|
+
)
|
|
1793
|
+
})
|
|
1794
|
+
})
|
|
1765
1795
|
})
|