Skip to content

Commit

Permalink
More stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklafrance committed Nov 6, 2024
1 parent dc35025 commit d0d1813
Show file tree
Hide file tree
Showing 52 changed files with 3,599 additions and 3,394 deletions.
2 changes: 1 addition & 1 deletion docs/guides/add-a-shared-dependency.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This guide only applies to federated applications (applications including [remot

Squide aims to **simplify** the configuration of shared dependencies by abstracting the shared dependencies necessary for building an application with React, React Router, and optionally MSW and i18next. Nevertheless, every federated application will inevitably have to configure additional custom shared dependencies.

For a more comprehensive documentation of the Module Federation APIs, their functionality, and their benefits, please refer to this [article](https://www.infoxicator.com/en/module-federation-shared-api).
For a comprehensive documentation of the Module Federation APIs, their functionality, and their benefits, please refer to this [article](https://www.infoxicator.com/en/module-federation-shared-api).

## Understanding singleton dependencies

Expand Down
20 changes: 10 additions & 10 deletions docs/reference/env-vars/EnvironmentVariablesPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ const runtime = new FireflyRuntime({
### Retrieve the plugin instance

```ts
import { EnvironmentVariablesPlugin } from "@squide/i18next";
import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPlugin.name) as EnvironmentVariablesPlugin;
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;
```

[!ref Prefer using `getEnvironmentVariablesPlugin` when possible](./getEnvironmentVariablesPlugin.md)

### Register an environment variable

```ts !#5
import { EnvironmentVariablesPlugin } from "@squide/i18next";
import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPlugin.name) as EnvironmentVariablesPlugin;
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

plugin.registerVariable("apiBaseUrl", "https://my-api.com");
```
Expand All @@ -60,9 +60,9 @@ plugin.registerVariable("apiBaseUrl", "https://my-api.com");
### Register multiple environment variables at once

```ts !#5-8
import { EnvironmentVariablesPlugin } from "@squide/i18next";
import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPlugin.name) as EnvironmentVariablesPlugin;
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

plugin.registerVariables({
apiBaseUrl: "https://my-api.com",
Expand All @@ -73,19 +73,19 @@ plugin.registerVariables({
### Retrieve a single environment variable

```ts !#5
import { EnvironmentVariablesPlugin } from "@squide/i18next";
import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPlugin.name) as EnvironmentVariablesPlugin;
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

const apiBaseUrl = plugin.getVariable("apiBaseUrl");
```

### Retrieve all the environment variables

```ts !#5
import { EnvironmentVariablesPlugin } from "@squide/i18next";
import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPlugin.name) as EnvironmentVariablesPlugin;
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

const variables = plugin.getVariables();
```
18 changes: 9 additions & 9 deletions docs/reference/i18next/i18nextPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ const runtime = new FireflyRuntime({
### Retrieve the plugin instance

```ts
import { i18nextPlugin } from "@squide/i18next";
import { i18nextPlugin, i18nextPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(i18nextPlugin.name) as i18nextPlugin;
const plugin = runtime.getPlugin(i18nextPluginName) as i18nextPlugin;
```

[!ref Prefer using `getI18nextPlugin` when possible](./getI18nextPlugin.md)

### Register a i18next instance

```ts !#15
import { i18nextPlugin } from "@squide/i18next";
import { i18nextPlugin, i18nextPluginName } from "@squide/i18next";
import i18n from "./i18next";
import resourcesEn from "./locales/en.json";
import resourcesFr from "./locales/fr.json";
Expand All @@ -60,17 +60,17 @@ const instance = i18n.createInstance({
}
});

const plugin = runtime.getPlugin(i18nextPlugin.name) as i18nextPlugin;
const plugin = runtime.getPlugin(i18nextPluginName) as i18nextPlugin;

plugin.registerInstance("an-instance-key", instance);
```

### Retrieve a i18next instance

```ts !#6
import { i18nextPlugin } from "@squide/i18next";
import { i18nextPlugin, i18nextPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(i18nextPlugin.name) as i18nextPlugin;
const plugin = runtime.getPlugin(i18nextPluginName) as i18nextPlugin;

// If no instance match the specified key, an error will be thrown.
const instance = plugin.getInstance("an-instance-key");
Expand All @@ -97,9 +97,9 @@ const runtime = new FireflyRuntime({
### Retrieve the current language

```ts !#6
import { i18nextPlugin } from "@squide/i18next";
import { i18nextPlugin, i18nextPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(i18nextPlugin.name) as i18nextPlugin;
const plugin = runtime.getPlugin(i18nextPluginName) as i18nextPlugin;

// If the language hasn't been changed nor detected before getting the current language, an error will be thrown.
const language = plugin.currentLanguage;
Expand All @@ -110,7 +110,7 @@ const language = plugin.currentLanguage;
```ts !#6
import { i18nextPlugin } from "@squide/i18next";

const plugin = runtime.getPlugin(i18nextPlugin.name) as i18nextPlugin;
const plugin = runtime.getPlugin(i18nextPluginName) as i18nextPlugin;

// If the language isn't included in the "supportedLanguages" array, an error will be thrown.
plugin.changeLanguage("fr-CA");
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
"devDependencies": {
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.9",
"@types/node": "22.7.4",
"@typescript-eslint/parser": "8.8.1",
"@workleap/eslint-plugin": "3.2.2",
"@types/node": "22.9.0",
"@typescript-eslint/parser": "8.13.0",
"@workleap/eslint-plugin": "3.2.3",
"@workleap/typescript-configs": "3.0.2",
"cross-env": "7.0.3",
"eslint": "8.57.0",
"installed-check": "9.3.0",
"jest": "29.7.0",
"knip": "5.33.1",
"knip": "5.36.2",
"retypeapp": "3.6.0",
"ts-node": "10.9.2",
"turbo": "1.13.3",
Expand Down
12 changes: 6 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
"react-dom": "*"
},
"devDependencies": {
"@swc/core": "1.7.26",
"@swc/jest": "0.2.36",
"@types/jest": "29.5.13",
"@types/react": "18.3.11",
"@workleap/eslint-plugin": "3.2.2",
"@swc/core": "1.8.0",
"@swc/jest": "0.2.37",
"@types/jest": "29.5.14",
"@types/react": "18.3.12",
"@workleap/eslint-plugin": "3.2.3",
"@workleap/swc-configs": "2.2.3",
"@workleap/tsup-configs": "3.0.6",
"@workleap/typescript-configs": "3.0.2",
"eslint": "8.57.0",
"jest": "29.7.0",
"react": "18.3.1",
"tsup": "8.3.0",
"tsup": "8.3.5",
"typescript": "5.5.4"
},
"dependencies": {
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/registration/registerLocalModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export class LocalModuleRegistry implements ModuleRegistry {
} satisfies LocalModulesRegistrationCompletedEventPayload);

this.#setRegistrationStatus(this.#deferredRegistrations.length > 0 ? "modules-registered" : "ready");
} else {
// There's no modules to register, it can be considered as ready.
this.#setRegistrationStatus("ready");
}

return errors;
Expand All @@ -116,19 +119,19 @@ export class LocalModuleRegistry implements ModuleRegistry {
async registerDeferredRegistrations<TData = unknown, TRuntime extends Runtime = Runtime>(data: TData, runtime: TRuntime) {
const errors: ModuleRegistrationError[] = [];

if (this.#registrationStatus === "ready" && this.#deferredRegistrations.length === 0) {
// No deferred registrations were returned by the local modules, skip this phase.
return errors;
}

if (this.#registrationStatus === "none" || this.#registrationStatus === "registering-modules") {
throw new Error("[squide] The registerDeferredRegistrations function can only be called once the local modules are registered.");
}

if (this.#registrationStatus !== "modules-registered" && this.#deferredRegistrations.length > 0) {
if (this.#registrationStatus !== "modules-registered") {
throw new Error("[squide] The registerDeferredRegistrations function can only be called once.");
}

if (this.#registrationStatus === "ready") {
// No deferred registrations were returned by the local modules, skip the completion process.
return errors;
}

this.#setRegistrationStatus("registering-deferred-registration");

runtime.eventBus.dispatch(LocalModulesDeferredRegistrationStartedEvent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test("when called twice, throw an error", async () => {
await registry.registerDeferredRegistrations({}, runtime);

await expect(() => registry.registerDeferredRegistrations({}, runtime)).rejects.toThrow(/The registerDeferredRegistrations function can only be called once/);
});
}, 50000);

test("when called for the first time but the registration status is already \"ready\", return a resolving promise", async () => {
const runtime = new DummyRuntime();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/registerLocalModules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ test("when a context is provided, all the register functions receive the provide
expect(register3).toHaveBeenCalledWith(runtime, context);
});

test("when no modules are provided, the status remain \"none\"", async () => {
test("when no modules are provided, the status is \"ready\"", async () => {
const runtime = new DummyRuntime();
const registry = new LocalModuleRegistry();

await registry.registerModules([], runtime);

expect(registry.registrationStatus).toBe("none");
expect(registry.registrationStatus).toBe("ready");
});

test("when no modules are provided, do not dispatch LocalModulesRegistrationStartedEvent", async () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/env-vars/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@
"build": "tsup --config ./tsup.build.ts"
},
"devDependencies": {
"@swc/core": "1.7.26",
"@swc/jest": "0.2.36",
"@types/jest": "29.5.13",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.0",
"@workleap/eslint-plugin": "3.2.2",
"@swc/core": "1.8.0",
"@swc/jest": "0.2.37",
"@types/jest": "29.5.14",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@workleap/eslint-plugin": "3.2.3",
"@workleap/swc-configs": "2.2.3",
"@workleap/tsup-configs": "3.0.6",
"@workleap/typescript-configs": "3.0.2",
"eslint": "8.57.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"ts-jest": "29.2.5",
"tsup": "8.3.0",
"tsup": "8.3.5",
"typescript": "5.5.4"
},
"dependencies": {
Expand Down
6 changes: 4 additions & 2 deletions packages/env-vars/src/EnvironmentVariablesPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { isNil, Plugin, type Runtime } from "@squide/core";
import { type EnvironmentVariables, EnvironmentVariablesRegistry, type EnvironmentVariablesRegistryKey, type EnvironmentVariablesRegistryValue } from "./EnvironmentVariablesRegistry.ts";

export const EnvironmentVariablesPluginName = "env-vars-plugin";

export class EnvironmentVariablesPlugin extends Plugin {
readonly #environmentVariablesRegistry = new EnvironmentVariablesRegistry();

constructor(runtime: Runtime) {
super(EnvironmentVariablesPlugin.name, runtime);
super(EnvironmentVariablesPluginName, runtime);
}

registerVariable(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue) {
Expand All @@ -30,7 +32,7 @@ export class EnvironmentVariablesPlugin extends Plugin {
}

export function getEnvironmentVariablesPlugin(runtime: Runtime) {
const plugin = runtime.getPlugin(EnvironmentVariablesPlugin.name);
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName);

if (isNil(plugin)) {
throw new Error("[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime.");
Expand Down
4 changes: 2 additions & 2 deletions packages/fakes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"build": "tsup --config ./tsup.build.ts"
},
"devDependencies": {
"@workleap/eslint-plugin": "3.2.2",
"@workleap/eslint-plugin": "3.2.3",
"@workleap/tsup-configs": "3.0.6",
"@workleap/typescript-configs": "3.0.2",
"eslint": "8.57.0",
"tsup": "8.3.0",
"tsup": "8.3.5",
"typescript": "5.5.4"
},
"dependencies": {
Expand Down
12 changes: 6 additions & 6 deletions packages/firefly-honeycomb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@
"@opentelemetry/instrumentation-user-interaction": "*",
"@opentelemetry/instrumentation-xml-http-request": "*",
"@opentelemetry/sdk-trace-web": "*",
"@swc/core": "1.7.26",
"@swc/jest": "0.2.36",
"@types/jest": "29.5.13",
"@swc/core": "1.8.0",
"@swc/jest": "0.2.37",
"@types/jest": "29.5.14",
"@types/uuid": "10.0.0",
"@workleap/eslint-plugin": "3.2.2",
"@workleap/eslint-plugin": "3.2.3",
"@workleap/swc-configs": "2.2.3",
"@workleap/tsup-configs": "3.0.6",
"@workleap/typescript-configs": "3.0.2",
"eslint": "8.57.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"ts-jest": "29.2.5",
"tsup": "8.3.0",
"tsup": "8.3.5",
"typescript": "5.5.4"
},
"dependencies": {
"@squide/firefly": "workspace:*",
"uuid": "10.0.0"
"uuid": "11.0.2"
},
"sideEffects": false,
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function getHoneycombSdkOptions(runtime: FireflyRuntime, serviceName: Non
// Watch out, getWebAutoInstrumentations enables by default all the supported instrumentations.
// It's important to disabled those that we don't want.
instrumentations: [
getWebAutoInstrumentations(autoInstrumentations),
...getWebAutoInstrumentations(autoInstrumentations),
...instrumentations
],
spanProcessors: [globalAttributeSpanProcessor, ...spanProcessors]
Expand Down
Loading

0 comments on commit d0d1813

Please sign in to comment.