Skip to content

Commit

Permalink
fix(framework): Hardcode json-schema-faker
Browse files Browse the repository at this point in the history
Json-schema-faker is causing big HMR and Webpack headaches when @novu/framework is used in Next.js.
To address the issue, we decided to go old-school and hardcode the IIFE version of the source code in our package.
The code was copied for https://unpkg.com/browse/json-schema-faker@0.5.6/dist/main.iife.js.

PLEASE NOTE THE CODE WAS SLIGHTLY MODIFIED TO MAKE IT WORK IN @novu/framework. See the end of this file.

See json-schema-faker/json-schema-faker#796 (comment).
  • Loading branch information
SokratisVidros committed Oct 25, 2024
1 parent aba2de9 commit 990adf1
Show file tree
Hide file tree
Showing 5 changed files with 6,448 additions and 247 deletions.
1 change: 0 additions & 1 deletion packages/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
"better-ajv-errors": "^1.2.0",
"chalk": "^4.1.2",
"cross-fetch": "^4.0.0",
"json-schema-faker": "^0.5.6",
"json-schema-to-ts": "^3.0.0",
"liquidjs": "^10.13.1",
"ora": "^5.4.1",
Expand Down
18 changes: 3 additions & 15 deletions packages/framework/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { JSONSchemaFaker } from 'json-schema-faker';
import { Liquid } from 'liquidjs';
import ora from 'ora';

Expand Down Expand Up @@ -38,19 +37,9 @@ import type {
} from './types';
import { WithPassthrough } from './types/provider.types';
import { EMOJI, log, sanitizeHtmlInObject, stringifyDataStructureWithSingleQuotes } from './utils';
import { transformSchema, validateData } from './validators';
import { validateData } from './validators';

/**
* We want to respond with a consistent string value for preview
*/
JSONSchemaFaker.random.shuffle = function shuffle() {
return ['[placeholder]'];
};

JSONSchemaFaker.option({
useDefaultValue: true,
alwaysFakeOptionals: true,
});
import { mockSchema } from './jsonSchemaFaker';

function isRuntimeInDevelopment() {
return ['development', undefined].includes(process.env.NODE_ENV);
Expand Down Expand Up @@ -164,8 +153,7 @@ export class Client {
* @returns mocked data
*/
private mock(schema: Schema): Record<string, unknown> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return JSONSchemaFaker.generate(transformSchema(schema) as any) as Record<string, unknown>;
return mockSchema(schema) as Record<string, unknown>;
}

private async validate<T extends Record<string, unknown>>(
Expand Down
Loading

0 comments on commit 990adf1

Please sign in to comment.