Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/1902.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@asyncapi/cli': patch
---

fix: resolve Next.js version mismatch for studio/preview

- e836cf8: fix: resolve Next.js version mismatch for studio/preview
- 617e4b5: fix: remove unnecessary type assertions in Studio and Preview


14 changes: 11 additions & 3 deletions src/domains/models/Preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { createServer } from 'http';
import { WebSocketServer } from 'ws';
import chokidar from 'chokidar';
import open from 'open';
import next from 'next';
import path from 'path';
import yaml from 'js-yaml';
import { blueBright, redBright } from 'picocolors';
Expand All @@ -24,6 +23,15 @@ function isValidFilePath(filePath: string): boolean {
return existsSync(filePath);
}

type NextFactory = typeof import('next')['default'];

function resolveStudioNextInstance(studioPath: string): NextFactory {
const resolvedNextPath = require.resolve('next', { paths: [studioPath] });
// eslint-disable-next-line @typescript-eslint/no-var-requires,security/detect-non-literal-require
const nextModule = require(resolvedNextPath);
return nextModule.default ?? nextModule;
}

// eslint-disable-next-line sonarjs/cognitive-complexity
export function startPreview(filePath:string,base:string | undefined,baseDirectory:string | undefined ,xOrigin:boolean | undefined,suppressLogs:boolean|undefined,port: number = DEFAULT_PORT, noBrowser?: boolean):void {
if (filePath && !isValidFilePath(filePath)) {
Expand All @@ -44,7 +52,8 @@ export function startPreview(filePath:string,base:string | undefined,baseDirecto
});

const studioPath = path.dirname(require.resolve('@asyncapi/studio/package.json'));
const app = next({
const nextInstance = resolveStudioNextInstance(studioPath);
const app = nextInstance({
dev: false,
dir: studioPath,
conf: {
Expand Down Expand Up @@ -232,4 +241,3 @@ function findPathsToWatchFromSchemaRef(filePath: string,baseDir:string) {
}
}
}

13 changes: 11 additions & 2 deletions src/domains/models/Studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createServer } from 'http';
import { WebSocketServer } from 'ws';
import chokidar from 'chokidar';
import open from 'open';
import next from 'next';
import path from 'path';
import { version as studioVersion } from '@asyncapi/studio/package.json';
import { blueBright, redBright } from 'picocolors';
Expand All @@ -20,6 +19,15 @@ function isValidFilePath(filePath: string): boolean {
return existsSync(filePath);
}

type NextFactory = typeof import('next')['default'];

function resolveStudioNextInstance(studioPath: string): NextFactory {
const resolvedNextPath = require.resolve('next', { paths: [studioPath] });
// eslint-disable-next-line @typescript-eslint/no-var-requires,security/detect-non-literal-require
const nextModule = require(resolvedNextPath);
return nextModule.default ?? nextModule;
}

// eslint-disable-next-line sonarjs/cognitive-complexity
export function start(filePath: string, port: number = DEFAULT_PORT, noBrowser?:boolean): void {
if (filePath && !isValidFilePath(filePath)) {
Expand All @@ -30,7 +38,8 @@ export function start(filePath: string, port: number = DEFAULT_PORT, noBrowser?:
const studioPath = path.dirname(
require.resolve('@asyncapi/studio/package.json'),
);
const app = next({
const nextInstance = resolveStudioNextInstance(studioPath);
const app = nextInstance({
dev: false,
dir: studioPath,
conf: {
Expand Down
Loading