Skip to content

Commit

Permalink
chore: Single import from @squide/firefly (#112)
Browse files Browse the repository at this point in the history
* Updated the code to export everything from firefly

* Updated the guides and reference section

* Added FireflyRuntime and new define functions

* Renamed Runtime to FireflyRuntime in docs

* Updated docs

* New MSW guide

* Minor docs improvements

* Minor docs changes

* Docs enhancement

* Docs enhancements

* Docs enhancements

* Docs enhancements

* Docs enhancements

* Renamed AbstractRuntime to Runtime

* Added changeset files
  • Loading branch information
patricklafrance authored Nov 14, 2023
1 parent ae3a3f7 commit a9dda1c
Show file tree
Hide file tree
Showing 189 changed files with 1,476 additions and 1,481 deletions.
12 changes: 12 additions & 0 deletions .changeset/fluffy-deers-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@squide/webpack-configs": major
---

This is a new package that includes the webpack configs. Moving the webpack configs to a standalone projects allow `@squide/firefly` to take an optionnal dependency on `webpack`. Thisis useful for local module projects that use the firefly stack but don't want to setup webpack because they do not need to support an isolated development environment.

This new packages includes:

- `defineDevHostConfig`
- `defineBuildHostConfig`
- `defineDevRemoteModuleConfig`
- `defineBuildRemoteModuleConfig`
5 changes: 5 additions & 0 deletions .changeset/four-ears-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@squide/webpack-module-federation": major
---

- The define functions has been moved to the new `@squide/webpack-configs` package.
8 changes: 8 additions & 0 deletions .changeset/gorgeous-camels-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@squide/firefly": minor
---

- Added a new `FireflyRuntime` class. This class should be used by all consumer applications rather than the previous `Runtime` class from `@squide/react-router`.
- The `FireflyRuntime` class has a `registerRequestHandlers` function and a `requestHandlers` getter. Consumer applications should use these instead of the `MSwPlugin`.
- Added a new layer of define functions (`defineDevHostConfig`, `defineBuildHostConfig`, `defineDevRemoteModuleConfig`, `defineBuildRemoteModuleConfig`). These functions should be used by all consumer applications rather than the previous define functions from `@squide/wbepack-module-federation`.
- Forward every exports from `@squide/core`, `@squide/react-router`, `@squide/webpack-module-federation`, `@squide/webpack-configs` and `@squide/msw`. Consumer applications should now import everything from `@squide/firefly` except the fakes implementations that should still be imported from `@squide/fakes`.
5 changes: 5 additions & 0 deletions .changeset/moody-suits-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@squide/core": major
---

- Renamed the `AbstractRuntime` class to `Runtime`.
6 changes: 6 additions & 0 deletions .changeset/smooth-carrots-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@squide/react-router": major
---

- The `Runtime` class has been renamed to `ReactRouterRuntime`.
- This package doesn't forward the `@squide/core` package exports anymore.
52 changes: 25 additions & 27 deletions docs/getting-started/create-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ Create a new application (we'll refer to ours as `host`), then open a terminal a

+++ pnpm
```bash
pnpm add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript
pnpm add @squide/core @squide/react-router @squide/webpack-module-federation @squide/msw @squide/firefly react react-dom react-router-dom
pnpm add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript
pnpm add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ yarn
```bash
yarn add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript
yarn add @squide/core @squide/react-router @squide/webpack-module-federation @squide/msw @squide/firefly react react-dom react-router-dom
yarn add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript
yarn add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ npm
```bash
npm install -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript
npm install @squide/core @squide/react-router @squide/webpack-module-federation @squide/msw @squide/firefly react react-dom react-router-dom
npm install -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript
npm install @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++

Expand Down Expand Up @@ -79,12 +79,11 @@ export {};
### Module registration

Next, to register the modules, instanciate the shell [Runtime](/reference/runtime/runtime-class.md) and register the remote module with the [registerRemoteModules](/reference/registration/registerRemoteModules.md) function (the configuration of the remote module will be covered in the [next section](create-remote-module.md)):
Next, to register the modules, instanciate the shell [FireflyRuntime](/reference/runtime/runtime-class.md) and register the remote module with the [registerRemoteModules](/reference/registration/registerRemoteModules.md) function (the configuration of the remote module will be covered in the [next section](create-remote-module.md)):

```tsx !#13-15,18-20,23 host/src/bootstrap.tsx
```tsx !#12-14,17-19,22 host/src/bootstrap.tsx
import { createRoot } from "react-dom/client";
import { ConsoleLogger, RuntimeContext, Runtime } from "@squide/react-router";
import { registerRemoteModules, type RemoteDefinition } from "@squide/webpack-module-federation";
import { ConsoleLogger, RuntimeContext, FireflyRuntime, registerRemoteModules, type RemoteDefinition } from "@squide/firefly";
import type { AppContext} from "@sample/shared";
import { App } from "./App.tsx";

Expand All @@ -94,7 +93,7 @@ const Remotes: RemoteDefinition[] = [
];

// Create the shell runtime.
const runtime = new Runtime({
const runtime = new FireflyRuntime({
loggers: [new ConsoleLogger()]
});

Expand Down Expand Up @@ -204,10 +203,10 @@ export function HomePage() {
Then, add a local module at the root of the host application to register the homepage:

```tsx host/src/register.tsx
import type { ModuleRegisterFunction, Runtime } from "@squide/react-router";
import type { ModuleRegisterFunction, FireflyRuntime } from "@squide/firefly";
import { HomePage } from "./HomePage.tsx";

export const registerHost: ModuleRegisterFunction<Runtime> = runtime => {
export const registerHost: ModuleRegisterFunction<FireflyRuntime> = runtime => {
runtime.registerRoute({
index: true,
element: <HomePage />
Expand All @@ -218,11 +217,11 @@ export const registerHost: ModuleRegisterFunction<Runtime> = runtime => {
And an [hoisted route](../reference/runtime/runtime-class.md#register-an-hoisted-route) to render the `RootLayout` and the [ManagedRoutes](../reference/routing/ManagedRoutes.md) placeholder:

```tsx !#8,12,15 host/src/register.tsx
import { ManagedRoutes, type ModuleRegisterFunction, type Runtime } from "@squide/react-router";
import { ManagedRoutes, type ModuleRegisterFunction, type FireflyRuntime } from "@squide/firefly";
import { HomePage } from "./HomePage.tsx";
import { RootLayout } from "./RootLayout.tsx";

export const registerHost: ModuleRegisterFunction<Runtime> = runtime => {
export const registerHost: ModuleRegisterFunction<FireflyRuntime> = runtime => {
runtime.registerRoute({
// Pathless route to declare a root layout.
element: <RootLayout />,
Expand All @@ -248,10 +247,9 @@ The [ManagedRoutes](../reference/routing/ManagedRoutes.md) placeholder indicates

Finally, update the bootstrapping code to [register](../reference/registration/registerLocalModules.md) the newly created local module:

```tsx !#24 host/src/bootstrap.tsx
```tsx !#23 host/src/bootstrap.tsx
import { createRoot } from "react-dom/client";
import { ConsoleLogger, RuntimeContext, Runtime } from "@squide/react-router";
import { registerRemoteModules, type RemoteDefinition } from "@squide/webpack-module-federation";
import { ConsoleLogger, RuntimeContext, FireflyRuntime, registerRemoteModules, type RemoteDefinition } from "@squide/firefly";
import type { AppContext} from "@sample/shared";
import { App } from "./App.tsx";
import { registerHost } from "./register.tsx";
Expand All @@ -262,7 +260,7 @@ const Remotes: RemoteDefinition[] = [
];

// Create the shell runtime.
const runtime = new Runtime({
const runtime = new FireflyRuntime({
loggers: [new ConsoleLogger()]
});

Expand Down Expand Up @@ -330,7 +328,7 @@ Then, open the `webpack.dev.js` file and use the [defineDevHostConfig](/referenc
```js !#6-13 host/webpack.dev.js
// @ts-check

import { defineDevHostConfig } from "@squide/webpack-module-federation/defineConfig.js";
import { defineDevHostConfig } from "@squide/firefly/defineConfig.js";
import { swcConfig } from "./swc.dev.js";

export default defineDevHostConfig(swcConfig, "host", 8080, {
Expand Down Expand Up @@ -364,7 +362,7 @@ Then, open the `webpack.build.js` file and use the [defineBuildHostConfig](/refe
```js !#6-13 host/webpack.build.js
// @ts-check

import { defineBuildHostConfig } from "@squide/webpack-module-federation/defineConfig.js";
import { defineBuildHostConfig } from "@squide/firefly/defineConfig.js";
import { swcConfig } from "./swc.build.js";

export default defineBuildHostConfig(swcConfig, "host", "http://localhost:8080/", {
Expand Down Expand Up @@ -401,11 +399,11 @@ To build the application, add the following script to the application `package.j

Start the application in a development environment using the `dev` script. You should see the home page. Even if the remote module application is not yet available, the host application will gracefully load.

!!!info
To troubleshoot module registration issues, open the DevTools console. You'll find a log entry for each registration that occurs and error messages if something goes wrong.
!!!
### Troubleshoot issues

!!!info
If you are having issues with this guide, have a look at a working example on [GitHub](https://github.com/gsoft-inc/wl-squide/tree/main/samples/basic/host).
!!!
If you are experiencing issues with this guide:

- Open the [DevTools](https://developer.chrome.com/docs/devtools/) console. You'll find a log entry for each registration that occurs and error messages if something went wrong.
- Refer to a working example on [GitHub](https://github.com/gsoft-inc/wl-squide/tree/main/samples/basic/host).
- Refer to the [troubleshooting](../troubleshooting.md) page.

29 changes: 14 additions & 15 deletions docs/getting-started/create-local-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ Create a new application (we'll refer to ours as `local-module`), then open a te
+++ pnpm
```bash
pnpm add -D @workleap/tsup-configs tsup typescript
pnpm add @squide/core @squide/react-router react react-dom react-router-dom
pnpm add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ yarn
```bash
pnpm add -D @workleap/tsup-configs tsup typescript
yarn add @squide/core @squide/react-router react react-dom react-router-dom
yarn add @squide/firefly react @squide/firefly react-dom react-router-dom react-error-boundary
```
+++ npm
```bash
pnpm add -D @workleap/tsup-configs tsup typescript
npm install @squide/core @squide/react-router react react-dom react-router-dom
npm install @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++

Expand Down Expand Up @@ -86,11 +86,11 @@ Finally, configure the package to be shareable by adding the `name`, `version`,
Next, register the local module routes and navigation items with [registerRoute](/reference/runtime/runtime-class.md#register-routes) and [registerNavigationItem](/reference/runtime/runtime-class.md#register-navigation-items) functions:

```tsx !#6-9,11-14 local-module/src/register.tsx
import type { ModuleRegisterFunction, Runtime } from "@squide/react-router";
import type { ModuleRegisterFunction, FireflyRuntime } from "@squide/firefly";
import type { AppContext } from "@sample/shared";
import { Page } from "./Page.tsx";

export const register: ModuleRegisterFunction<Runtime, AppContext> = (runtime, context) => {
export const register: ModuleRegisterFunction<FireflyRuntime, AppContext> = (runtime, context) => {
runtime.registerRoute({
path: "/local/page",
element: <Page />
Expand Down Expand Up @@ -127,10 +127,9 @@ Go back to the `host` application add a dependency to the `@sample/local-module`

Then, register the local module with the [registerLocalModule](/reference/registration/registerLocalModules.md) function:

```tsx !#5,27 host/src/bootstrap.tsx
```tsx !#4,26 host/src/bootstrap.tsx
import { createRoot } from "react-dom/client";
import { ConsoleLogger, RuntimeContext, Runtime } from "@squide/react-router";
import { registerRemoteModules, type RemoteDefinition } from "@squide/webpack-module-federation";
import { ConsoleLogger, RuntimeContext, FireflyRuntime, registerRemoteModules, type RemoteDefinition } from "@squide/firefly";
import type { AppContext } from "@sample/shared";
import { register as registerLocalModule } from "@sample/local-module";
import { App } from "./App.tsx";
Expand All @@ -141,7 +140,7 @@ const Remotes: RemoteDefinition[] = [
];

// Create the shell runtime.
const runtime = new Runtime({
const runtime = new FireflyRuntime({
loggers: [new ConsoleLogger()]
});

Expand Down Expand Up @@ -213,10 +212,10 @@ To build the module, add the following script to the application `package.json`

Start the `host`, `remote-module` and `local-module` applications in development mode using the `dev` script. You should now notice an additional link in the navigation menu. Click on the link to navigate to the page of your new **local** module!

!!!info
To troubleshoot module registration issues, open the DevTools console. You'll find a log entry for each registration that occurs and error messages if something goes wrong.
!!!
### Troubleshoot issues

!!!info
If you are having issues with this guide, have a look at a working example on [GitHub](https://github.com/gsoft-inc/wl-squide/tree/main/samples/basic/local-module).
!!!
If you are experiencing issues with this guide:

- Open the [DevTools](https://developer.chrome.com/docs/devtools/) console. You'll find a log entry for each registration that occurs and error messages if something went wrong.
- Refer to a working example on [GitHub](https://github.com/gsoft-inc/wl-squide/tree/main/samples/basic/local-module).
- Refer to the [troubleshooting](../troubleshooting.md) page.
32 changes: 16 additions & 16 deletions docs/getting-started/create-remote-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ Create a new application (we'll refer to ours as `remote-module`), then open a t

+++ pnpm
```bash
pnpm add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss
pnpm add @squide/core @squide/react-router @squide/webpack-module-federation react react-dom react-router-dom
pnpm add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss
pnpm add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ yarn
```bash
yarn add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss
yarn add @squide/core @squide/react-router @squide/webpack-module-federation react react-dom react-router-dom
yarn add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss
yarn add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ npm
```bash
npm install -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss
npm install @squide/core @squide/react-router @squide/webpack-module-federation react react-dom react-router-dom
npm install -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss
npm install @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++

Expand Down Expand Up @@ -63,11 +63,11 @@ Then, ensure that you are developing your module using [ESM syntax](https://deve
Next, register the remote module routes and navigation items with the [registerRoute](/reference/runtime/runtime-class.md#register-routes) and [registerNavigationItem](/reference/runtime/runtime-class.md#register-navigation-items) functions:

```tsx !#6-9,11-14 remote-module/src/register.tsx
import type { ModuleRegisterFunction, Runtime } from "@squide/react-router";
import type { ModuleRegisterFunction, FireflyRuntime } from "@squide/firefly";
import type { AppContext } from "@sample/shared";
import { Page } from "./Page.tsx";

export const register: ModuleRegisterFunction<Runtime, AppContext> = (runtime, context) => {
export const register: ModuleRegisterFunction<FireflyRuntime, AppContext> = (runtime, context) => {
runtime.registerRoute({
path: "/remote/page",
element: <Page />
Expand Down Expand Up @@ -115,7 +115,7 @@ Then, open the `webpack.dev.js` file and use the the [defineDevRemoteModuleConfi
```js !#6-12 remote-module/webpack.dev.js
// @ts-check

import { defineDevRemoteModuleConfig } from "@squide/webpack-module-federation/defineConfig.js";
import { defineDevRemoteModuleConfig } from "@squide/firefly/defineConfig.js";
import { swcConfig } from "./swc.dev.js";

export default defineDevRemoteModuleConfig(swcConfig, "remote1", 8081, {
Expand Down Expand Up @@ -148,7 +148,7 @@ Then, open the `webpack.build.js` file and use the the [defineBuildRemoteModuleC
```js !#6-12 remote-module/webpack.build.js
// @ts-check

import { defineBuildRemoteModuleConfig } from "@squide/webpack-module-federation/defineConfig.js";
import { defineBuildRemoteModuleConfig } from "@squide/firefly/defineConfig.js";
import { swcConfig } from "./swc.build.js";

export default defineBuildRemoteModuleConfig(swcConfig, "remote1", "http://localhost:8081/", {
Expand Down Expand Up @@ -184,11 +184,11 @@ To build the module, add the following script to the application `package.json`

Start the `host` and the `remote-module` applications in development mode using the `dev` script. You should notice an additional link in the navigation menu. Click on the link to navigate to the page of your new **remote** module!

!!!info
To troubleshoot module registration issues, open the DevTools console. You'll find a log entry for each registration that occurs and error messages if something goes wrong.
!!!
### Troubleshoot issues

!!!info
If you are having issues with this guide, have a look at a working example on [GitHub](https://github.com/gsoft-inc/wl-squide/tree/main/samples/basic/remote-module).
!!!
If you are experiencing issues with this guide:

- Open the [DevTools](https://developer.chrome.com/docs/devtools/) console. You'll find a log entry for each registration that occurs and error messages if something went wrong.
- Refer to a working example on [GitHub](https://github.com/gsoft-inc/wl-squide/tree/main/samples/basic/remote-module).
- Refer to the [troubleshooting](../troubleshooting.md) page.

12 changes: 6 additions & 6 deletions docs/getting-started/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To enable support for direct page hits, add the following redirect rule to your
Configure the remote modules production URL:

```ts
import { RemoteDefinition } from "@squide/webpack-module-federation";
import { RemoteDefinition } from "@squide/firefly";

const Remotes: RemoteDefinition[] = [
{
Expand All @@ -33,12 +33,12 @@ const Remotes: RemoteDefinition[] = [

## Update the runtime mode

Don't forget to change the [Runtime mode](../reference/runtime/runtime-class.md#change-the-runtime-mode) to `production`:
Don't forget to change the [FireflyRuntime mode](../reference/runtime/runtime-class.md#change-the-runtime-mode) to `production`:

```ts
import { Runtime } from "@squide/react-router";
import { FireflyRuntime } from "@squide/firefly";

const runtime = new Runtime({
const runtime = new FireflyRuntime({
mode: process.env.isNetlify ? "production" : "development"
});
```
Expand All @@ -48,9 +48,9 @@ const runtime = new Runtime({
Remove the [ConsoleLogger](../reference/logging/ConsoleLogger.md) from the production build:

```ts
import { ConsoleLogger, Runtime } from "@squide/react-router";
import { ConsoleLogger, FireflyRuntime } from "@squide/firefly";

const runtime = new Runtime({
const runtime = new FireflyRuntime({
loggers: process.env.isNetlify ? [] : [new ConsoleLogger()]
});
```
Loading

0 comments on commit a9dda1c

Please sign in to comment.