Skip to content

Commit

Permalink
docs: Multiple documentation fixes + small fixes in packages (#140)
Browse files Browse the repository at this point in the history
* Multiple documentation fixes + small fixes in packages

* Renamed otherOptions for options

* Fixed CI and added changeset files

* Updated define functions jest snapshots
  • Loading branch information
patricklafrance authored Jan 28, 2024
1 parent 2351abb commit 6eaf4ac
Show file tree
Hide file tree
Showing 22 changed files with 1,049 additions and 948 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-cycles-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@squide/firefly": patch
---

Internal changes
5 changes: 5 additions & 0 deletions .changeset/fuzzy-weeks-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@squide/webpack-configs": minor
---

Added i18next libraries as shared singleton dependencies
5 changes: 5 additions & 0 deletions .changeset/smooth-fans-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@squide/i18next": minor
---

Now throwing an Error when an instance is registered with an existing key
12 changes: 6 additions & 6 deletions docs/guides/setup-msw.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { setupWorker } from "msw/browser";
export function startMsw(moduleRequestHandlers: RequestHandler[]) {
const worker = setupWorker(...moduleRequestHandlers);

worker.start();
return worker.start();
}
```

Expand Down Expand Up @@ -104,10 +104,10 @@ if (process.env.USE_MSW) {
const startMsw = (await import("../mocks/browser.ts")).startMsw;

// Will start MSW with the modules request handlers.
startMsw(runtime.requestHandlers);

// Indicate that MSW has been started and the routes can now be safely rendered.
setMswAsStarted();
startMsw(runtime.requestHandlers).then(() => {
// Indicate that MSW has been started and the routes can now be safely rendered.
setMswAsStarted();
});
}

const root = createRoot(document.getElementById("root")!);
Expand All @@ -132,7 +132,7 @@ export function App() {
<AppRouter
fallbackElement={<div>Loading...</div>}
errorElement={<div>An error occured!</div>}
waitForMsw={process.env.USE_MSW}
waitForMsw={Boolean(process.env.USE_MSW)}
>
{(routes, providerProps) => (
<RouterProvider router={createBrowserRouter(routes)} {...providerProps} />
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/runtime/runtime-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ runtime.registerRoute({
If the route is nested under an authentication boundary, don't forget to either mark the route as [hoisted](#register-an-hoisted-route) or to [nest the route](#register-nested-routes-under-an-existing-route) under a public parent.

!!!info
A `$visibility` hint only takes effect if your application is using the [useIsRouteMatchProtected](../routing/useIsRouteMatchProtected.md) hook. When no `$visibility` hint is provided, a route is considered `protected`.
A `$visibility` hint only takes effect if your application is using the [useIsRouteProtected](../routing/useIsRouteProtected.md) hook. When no `$visibility` hint is provided, a route is considered `protected`.
!!!

### Register a named route
Expand Down
24 changes: 12 additions & 12 deletions packages/firefly/src/defineConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export interface FireflyDefineDevHostConfigOptions extends DefineDevHostConfigOp
features?: FireflyFeatures;
}

// The function return type is mandatory, otherwise we got an error TS4058.
export function defineDevHostConfig(swcConfig: SwcConfig, applicationName: string, port: number, { features, ...otherOptions }: FireflyDefineDevHostConfigOptions = {}): webpack.Configuration {
// The function return type is mandatory, otherwise we get an error TS4058.
export function defineDevHostConfig(swcConfig: SwcConfig, applicationName: string, port: number, { features, ...options }: FireflyDefineDevHostConfigOptions = {}): webpack.Configuration {
return baseDefineDevHostConfig(swcConfig, applicationName, port, {
...otherOptions,
...options,
features: {
router: "react-router",
msw: true,
Expand All @@ -43,10 +43,10 @@ export interface FireflyDefineBuildHostConfigOptions extends DefineBuildHostConf
features?: FireflyFeatures;
}

// The function return type is mandatory, otherwise we got an error TS4058.
export function defineBuildHostConfig(swcConfig: SwcConfig, applicationName: string, { features, ...otherOptions }: FireflyDefineBuildHostConfigOptions = {}): webpack.Configuration {
// The function return type is mandatory, otherwise we get an error TS4058.
export function defineBuildHostConfig(swcConfig: SwcConfig, applicationName: string, { features, ...options }: FireflyDefineBuildHostConfigOptions = {}): webpack.Configuration {
return baseDefineBuildHostConfig(swcConfig, applicationName, {
...otherOptions,
...options,
features: {
router: "react-router",
msw: true,
Expand All @@ -59,10 +59,10 @@ export interface FireflyDefineDevRemoteModuleConfigOptions extends DefineDevRemo
features?: FireflyFeatures;
}

// The function return type is mandatory, otherwise we got an error TS4058.
export function defineDevRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, port: number, { features, ...otherOptions }: FireflyDefineDevRemoteModuleConfigOptions = {}): webpack.Configuration {
// The function return type is mandatory, otherwise we get an error TS4058.
export function defineDevRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, port: number, { features, ...options }: FireflyDefineDevRemoteModuleConfigOptions = {}): webpack.Configuration {
return baseDefineDevRemoteModuleConfig(swcConfig, applicationName, port, {
...otherOptions,
...options,
features: {
router: "react-router",
msw: true,
Expand All @@ -75,10 +75,10 @@ export interface FireflyDefineBuildRemoteModuleConfigOptions extends DefineBuild
features?: FireflyFeatures;
}

// The function return type is mandatory, otherwise we got an error TS4058.
export function defineBuildRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, { features, ...otherOptions }: FireflyDefineBuildRemoteModuleConfigOptions = {}): webpack.Configuration {
// The function return type is mandatory, otherwise we get an error TS4058.
export function defineBuildRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, { features, ...options }: FireflyDefineBuildRemoteModuleConfigOptions = {}): webpack.Configuration {
return baseDefineBuildRemoteModuleConfig(swcConfig, applicationName, {
...otherOptions,
...options,
features: {
router: "react-router",
msw: true,
Expand Down
4 changes: 4 additions & 0 deletions packages/i18next/src/i18nextInstanceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export class i18nextInstanceRegistry {
readonly #instances: Map<string, i18n> = new Map();

add(key: string, instance: i18n) {
if (this.#instances.has("key")) {
throw new Error(`An i18next instance has already been registered with the "${key}" key.`);
}

this.#instances.set(key, instance);
}

Expand Down
21 changes: 17 additions & 4 deletions packages/webpack-configs/src/defineConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import webpack from "webpack";

// Webpack doesn't export ModuleFederationPlugin typings.
export type ModuleFederationPluginOptions = ConstructorParameters<typeof webpack.container.ModuleFederationPlugin>[0];
export type ModuleFederationSharedOption = ModuleFederationPluginOptions["shared"];

// Generally, only the host application should have eager dependencies.
// For more informations about shared dependencies refer to: https://github.com/patricklafrance/wmf-versioning
function getDefaultSharedDependencies(features: Features, isHost: boolean) {
function getDefaultSharedDependencies(features: Features, isHost: boolean): ModuleFederationSharedOption {
return {
"react": {
singleton: true,
Expand Down Expand Up @@ -45,7 +46,7 @@ export interface Features {

// Generally, only the host application should have eager dependencies.
// For more informations about shared dependencies refer to: https://github.com/patricklafrance/wmf-versioning
function getReactRouterSharedDependencies(isHost: boolean) {
function getReactRouterSharedDependencies(isHost: boolean): ModuleFederationSharedOption {
return {
"react-router-dom": {
singleton: true,
Expand All @@ -58,7 +59,7 @@ function getReactRouterSharedDependencies(isHost: boolean) {
};
}

function getMswSharedDependency(isHost: boolean) {
function getMswSharedDependency(isHost: boolean): ModuleFederationSharedOption {
return {
"@squide/msw": {
singleton: true,
Expand All @@ -67,8 +68,20 @@ function getMswSharedDependency(isHost: boolean) {
};
}

function getI18nextSharedDependency(isHost: boolean) {
function getI18nextSharedDependency(isHost: boolean): ModuleFederationSharedOption {
return {
"i18next": {
singleton: true,
eager: isHost ? true : undefined
},
"react-i18next": {
singleton: true,
eager: isHost ? true : undefined
},
"i18next-browser-languagedetector": {
singleton: true,
eager: isHost ? true : undefined
},
"@squide/i18next": {
singleton: true,
eager: isHost ? true : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ exports[`defineBuildHostConfig when i18next is activated, add i18next shared dep
"eager": true,
"singleton": true,
},
"i18next": {
"eager": true,
"singleton": true,
},
"i18next-browser-languagedetector": {
"eager": true,
"singleton": true,
},
"react": {
"eager": true,
"requiredVersion": false,
Expand All @@ -167,6 +175,10 @@ exports[`defineBuildHostConfig when i18next is activated, add i18next shared dep
"eager": true,
"singleton": true,
},
"react-i18next": {
"eager": true,
"singleton": true,
},
},
},
},
Expand Down Expand Up @@ -466,6 +478,14 @@ exports[`defineBuildRemoteModuleConfig when i18next is activated, add i18next sh
"eager": undefined,
"singleton": true,
},
"i18next": {
"eager": undefined,
"singleton": true,
},
"i18next-browser-languagedetector": {
"eager": undefined,
"singleton": true,
},
"react": {
"eager": undefined,
"requiredVersion": false,
Expand All @@ -475,6 +495,10 @@ exports[`defineBuildRemoteModuleConfig when i18next is activated, add i18next sh
"eager": undefined,
"singleton": true,
},
"react-i18next": {
"eager": undefined,
"singleton": true,
},
},
},
},
Expand Down Expand Up @@ -753,6 +777,14 @@ exports[`defineDevHostConfig when i18next is activated, add i18next shared depen
"eager": true,
"singleton": true,
},
"i18next": {
"eager": true,
"singleton": true,
},
"i18next-browser-languagedetector": {
"eager": true,
"singleton": true,
},
"react": {
"eager": true,
"requiredVersion": false,
Expand All @@ -762,6 +794,10 @@ exports[`defineDevHostConfig when i18next is activated, add i18next shared depen
"eager": true,
"singleton": true,
},
"react-i18next": {
"eager": true,
"singleton": true,
},
},
},
},
Expand Down Expand Up @@ -1061,6 +1097,14 @@ exports[`defineDevRemoteModuleConfig when i18next is activated, add i18next shar
"eager": undefined,
"singleton": true,
},
"i18next": {
"eager": undefined,
"singleton": true,
},
"i18next-browser-languagedetector": {
"eager": undefined,
"singleton": true,
},
"react": {
"eager": undefined,
"requiredVersion": false,
Expand All @@ -1070,6 +1114,10 @@ exports[`defineDevRemoteModuleConfig when i18next is activated, add i18next shar
"eager": undefined,
"singleton": true,
},
"react-i18next": {
"eager": undefined,
"singleton": true,
},
},
},
},
Expand Down
Loading

0 comments on commit 6eaf4ac

Please sign in to comment.