@nerest/nerest 1.7.2 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
1
  import type { InlineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import path from 'path';
2
4
 
3
5
  import type { BuildArgs } from './shared.js';
4
6
  import { viteConfigShared } from './shared.js';
@@ -15,7 +17,10 @@ export async function viteConfigDevelopmentClient(
15
17
  modulePreload: false,
16
18
  watch: {},
17
19
  rollupOptions: {
18
- input: '/node_modules/@nerest/nerest/client/index.ts',
20
+ input: [
21
+ '/node_modules/@nerest/nerest/client/index.ts',
22
+ ...args.appDirectories.map((dir) => path.join(dir, 'index.tsx')),
23
+ ],
19
24
  output: {
20
25
  dir: 'build/client/assets',
21
26
  entryFileNames: `[name].js`,
@@ -24,6 +29,7 @@ export async function viteConfigDevelopmentClient(
24
29
  },
25
30
  },
26
31
  },
32
+ plugins: [react()],
27
33
  customLogger: logger,
28
34
  };
29
35
  }
@@ -51,6 +57,7 @@ export async function viteConfigDevelopmentServer(
51
57
  noDiscovery: true,
52
58
  include: [],
53
59
  },
60
+ plugins: [react()],
54
61
  customLogger: logger,
55
62
  };
56
63
  }
@@ -1,5 +1,7 @@
1
1
  import type { InlineConfig } from 'vite';
2
2
  import { viteExternalsPlugin } from 'vite-plugin-externals';
3
+ import react from '@vitejs/plugin-react';
4
+ import path from 'path';
3
5
 
4
6
  import type { BuildArgs } from './shared.js';
5
7
  import { viteConfigShared } from './shared.js';
@@ -15,7 +17,10 @@ export async function viteConfigProductionClient(
15
17
  manifest: true,
16
18
  modulePreload: false,
17
19
  rollupOptions: {
18
- input: '/node_modules/@nerest/nerest/client/index.ts',
20
+ input: [
21
+ '/node_modules/@nerest/nerest/client/index.ts',
22
+ ...args.appDirectories.map((dir) => path.join(dir, 'index.tsx')),
23
+ ],
19
24
  output: {
20
25
  dir: 'build/client/assets',
21
26
  entryFileNames: `[name].js`,
@@ -31,6 +36,7 @@ export async function viteConfigProductionClient(
31
36
  plugins: [
32
37
  // externals - map buildConfig.externals packages to a global variable on window
33
38
  viteExternalsPlugin(args.buildConfig?.externals, { useWindow: false }),
39
+ react(),
34
40
  ],
35
41
  };
36
42
  }
@@ -55,5 +61,6 @@ export async function viteConfigProductionServer(
55
61
  },
56
62
  },
57
63
  },
64
+ plugins: [react()],
58
65
  };
59
66
  }
@@ -8,6 +8,7 @@ export type BuildArgs = {
8
8
  base: string;
9
9
  buildConfig: BuildConfiguration | undefined;
10
10
  project: Project;
11
+ appDirectories: string[];
11
12
  };
12
13
 
13
14
  export async function viteConfigShared({
package/build/index.ts CHANGED
@@ -5,6 +5,7 @@ import { build } from 'vite';
5
5
 
6
6
  import { loadBuildConfig } from '../server/loaders/build.js';
7
7
  import { loadApps } from '../server/loaders/apps.js';
8
+ import { loadAppDirectories } from '../server/loaders/directories.js';
8
9
  import type { Project } from '../server/loaders/project.js';
9
10
  import { loadProject } from '../server/loaders/project.js';
10
11
  import {
@@ -22,19 +23,23 @@ export async function buildMicroFrontend() {
22
23
  // Read project meta info from package.json
23
24
  const project = await loadProject(root);
24
25
 
26
+ // Load app directories following the `apps/{name}` convention
27
+ const appDirectories = await loadAppDirectories(root);
28
+
25
29
  // Build client
26
30
  const clientViteConfig = await viteConfigProductionClient({
27
31
  root,
28
32
  base: staticPath,
29
33
  buildConfig,
30
34
  project,
35
+ appDirectories,
31
36
  });
32
37
  console.log('Producing production client build...');
33
38
  await build(clientViteConfig);
34
39
 
35
40
  // Create nerest-manifest.json that production server reads on startup
36
41
  console.log('Producing Nerest manifest file...');
37
- await createNerestManifest(root, staticPath, project);
42
+ await createNerestManifest(root, appDirectories, staticPath, project);
38
43
 
39
44
  // Build server
40
45
  const serverViteConfig = await viteConfigProductionServer({
@@ -42,6 +47,7 @@ export async function buildMicroFrontend() {
42
47
  base: staticPath,
43
48
  buildConfig,
44
49
  project,
50
+ appDirectories,
45
51
  });
46
52
  console.log('Producing production server build...');
47
53
  await build(serverViteConfig);
@@ -49,10 +55,11 @@ export async function buildMicroFrontend() {
49
55
 
50
56
  async function createNerestManifest(
51
57
  root: string,
58
+ appDirectories: string[],
52
59
  staticPath: string,
53
60
  project: Project
54
61
  ) {
55
- const apps = await loadApps(root, staticPath);
62
+ const apps = await loadApps(root, appDirectories, staticPath);
56
63
  await fs.writeFile(
57
64
  path.join(root, 'build/nerest-manifest.json'),
58
65
  JSON.stringify({ project, apps }),
@@ -1,3 +1,5 @@
1
+ import react from '@vitejs/plugin-react';
2
+ import path from 'path';
1
3
  import { viteConfigShared } from './shared.js';
2
4
  import logger from './vite-logger.development.js';
3
5
  export async function viteConfigDevelopmentClient(args) {
@@ -9,7 +11,10 @@ export async function viteConfigDevelopmentClient(args) {
9
11
  modulePreload: false,
10
12
  watch: {},
11
13
  rollupOptions: {
12
- input: '/node_modules/@nerest/nerest/client/index.ts',
14
+ input: [
15
+ '/node_modules/@nerest/nerest/client/index.ts',
16
+ ...args.appDirectories.map((dir) => path.join(dir, 'index.tsx')),
17
+ ],
13
18
  output: {
14
19
  dir: 'build/client/assets',
15
20
  entryFileNames: `[name].js`,
@@ -18,6 +23,7 @@ export async function viteConfigDevelopmentClient(args) {
18
23
  },
19
24
  },
20
25
  },
26
+ plugins: [react()],
21
27
  customLogger: logger,
22
28
  };
23
29
  }
@@ -42,6 +48,7 @@ export async function viteConfigDevelopmentServer(args) {
42
48
  noDiscovery: true,
43
49
  include: [],
44
50
  },
51
+ plugins: [react()],
45
52
  customLogger: logger,
46
53
  };
47
54
  }
@@ -1,4 +1,6 @@
1
1
  import { viteExternalsPlugin } from 'vite-plugin-externals';
2
+ import react from '@vitejs/plugin-react';
3
+ import path from 'path';
2
4
  import { viteConfigShared } from './shared.js';
3
5
  import { excludes } from '../excludes/index.js';
4
6
  export async function viteConfigProductionClient(args) {
@@ -9,7 +11,10 @@ export async function viteConfigProductionClient(args) {
9
11
  manifest: true,
10
12
  modulePreload: false,
11
13
  rollupOptions: {
12
- input: '/node_modules/@nerest/nerest/client/index.ts',
14
+ input: [
15
+ '/node_modules/@nerest/nerest/client/index.ts',
16
+ ...args.appDirectories.map((dir) => path.join(dir, 'index.tsx')),
17
+ ],
13
18
  output: {
14
19
  dir: 'build/client/assets',
15
20
  entryFileNames: `[name].js`,
@@ -25,6 +30,7 @@ export async function viteConfigProductionClient(args) {
25
30
  plugins: [
26
31
  // externals - map buildConfig.externals packages to a global variable on window
27
32
  viteExternalsPlugin(args.buildConfig?.externals, { useWindow: false }),
33
+ react(),
28
34
  ],
29
35
  };
30
36
  }
@@ -46,5 +52,6 @@ export async function viteConfigProductionServer(args) {
46
52
  },
47
53
  },
48
54
  },
55
+ plugins: [react()],
49
56
  };
50
57
  }
@@ -6,5 +6,6 @@ export type BuildArgs = {
6
6
  base: string;
7
7
  buildConfig: BuildConfiguration | undefined;
8
8
  project: Project;
9
+ appDirectories: string[];
9
10
  };
10
11
  export declare function viteConfigShared({ root, base, buildConfig, project, }: BuildArgs): Promise<InlineConfig>;
@@ -3,6 +3,7 @@ import fs from 'fs/promises';
3
3
  import { build } from 'vite';
4
4
  import { loadBuildConfig } from '../server/loaders/build.js';
5
5
  import { loadApps } from '../server/loaders/apps.js';
6
+ import { loadAppDirectories } from '../server/loaders/directories.js';
6
7
  import { loadProject } from '../server/loaders/project.js';
7
8
  import { viteConfigProductionClient, viteConfigProductionServer, } from './configs/production.js';
8
9
  export async function buildMicroFrontend() {
@@ -12,30 +13,34 @@ export async function buildMicroFrontend() {
12
13
  const buildConfig = await loadBuildConfig(root);
13
14
  // Read project meta info from package.json
14
15
  const project = await loadProject(root);
16
+ // Load app directories following the `apps/{name}` convention
17
+ const appDirectories = await loadAppDirectories(root);
15
18
  // Build client
16
19
  const clientViteConfig = await viteConfigProductionClient({
17
20
  root,
18
21
  base: staticPath,
19
22
  buildConfig,
20
23
  project,
24
+ appDirectories,
21
25
  });
22
26
  console.log('Producing production client build...');
23
27
  await build(clientViteConfig);
24
28
  // Create nerest-manifest.json that production server reads on startup
25
29
  console.log('Producing Nerest manifest file...');
26
- await createNerestManifest(root, staticPath, project);
30
+ await createNerestManifest(root, appDirectories, staticPath, project);
27
31
  // Build server
28
32
  const serverViteConfig = await viteConfigProductionServer({
29
33
  root,
30
34
  base: staticPath,
31
35
  buildConfig,
32
36
  project,
37
+ appDirectories,
33
38
  });
34
39
  console.log('Producing production server build...');
35
40
  await build(serverViteConfig);
36
41
  }
37
- async function createNerestManifest(root, staticPath, project) {
38
- const apps = await loadApps(root, staticPath);
42
+ async function createNerestManifest(root, appDirectories, staticPath, project) {
43
+ const apps = await loadApps(root, appDirectories, staticPath);
39
44
  await fs.writeFile(path.join(root, 'build/nerest-manifest.json'), JSON.stringify({ project, apps }), 'utf-8');
40
45
  }
41
46
  function prepareStaticPath() {
@@ -7,6 +7,7 @@ import { createServer } from './shared.js';
7
7
  import { viteConfigDevelopmentClient, viteConfigDevelopmentServer, } from '../build/configs/development.js';
8
8
  import { loadBuildConfig } from './loaders/build.js';
9
9
  import { loadApps } from './loaders/apps.js';
10
+ import { loadAppDirectories } from './loaders/directories.js';
10
11
  import { loadProject } from './loaders/project.js';
11
12
  export async function runDevelopmentServer(port) {
12
13
  const root = process.cwd();
@@ -20,12 +21,15 @@ export async function runDevelopmentServer(port) {
20
21
  const buildConfig = await loadBuildConfig(root);
21
22
  // Load project meta details
22
23
  const project = await loadProject(root);
24
+ // Load app directories following the `apps/{name}` convention
25
+ const appDirectories = await loadAppDirectories(root);
23
26
  // Build the clientside assets and watch for changes
24
27
  await startClientBuildWatcher(await viteConfigDevelopmentClient({
25
28
  root,
26
29
  base: staticPath,
27
30
  buildConfig,
28
31
  project,
32
+ appDirectories,
29
33
  }));
30
34
  // Start vite server that will be rendering SSR components
31
35
  const viteSsr = await createViteServer(await viteConfigDevelopmentServer({
@@ -33,9 +37,10 @@ export async function runDevelopmentServer(port) {
33
37
  base: staticPath,
34
38
  buildConfig,
35
39
  project,
40
+ appDirectories,
36
41
  }));
37
42
  // Load app entries following the `apps/{name}/index.tsx` convention
38
- const apps = await loadApps(root, staticPath);
43
+ const apps = await loadApps(root, appDirectories, staticPath);
39
44
  const app = await createServer({
40
45
  root,
41
46
  project,
@@ -8,6 +8,6 @@ export type AppEntry = {
8
8
  examples: Record<string, unknown>;
9
9
  schema: JSONSchema | null;
10
10
  };
11
- export declare function loadApps(root: string, deployedStaticPath: string): Promise<{
11
+ export declare function loadApps(root: string, appDirs: string[], deployedStaticPath: string): Promise<{
12
12
  [k: string]: AppEntry;
13
13
  }>;
@@ -1,5 +1,4 @@
1
1
  import path from 'path';
2
- import fg from 'fast-glob';
3
2
  import { loadAppAssets } from './assets.js';
4
3
  import { loadAppExamples } from './examples.js';
5
4
  import { loadAppSchema } from './schema.js';
@@ -7,11 +6,8 @@ import { loadViteManifest } from './manifest.js';
7
6
  // Build the record of the available apps by convention
8
7
  // apps -> /apps/{name}/index.tsx
9
8
  // examples -> /apps/{name}/examples/{example}.json
10
- export async function loadApps(root, deployedStaticPath) {
9
+ export async function loadApps(root, appDirs, deployedStaticPath) {
11
10
  const manifest = await loadViteManifest(root);
12
- const appBase = path.join(root, 'apps');
13
- const appPattern = `${fg.convertPathToPattern(appBase)}/*`;
14
- const appDirs = await fg.glob(appPattern, { onlyDirectories: true });
15
11
  const apps = [];
16
12
  for (const appDir of appDirs) {
17
13
  apps.push(await loadApp(appDir, manifest, deployedStaticPath));
@@ -0,0 +1 @@
1
+ export declare function loadAppDirectories(root: string): Promise<string[]>;
@@ -0,0 +1,8 @@
1
+ import path from 'path';
2
+ import fg from 'fast-glob';
3
+ // Load app directories following the `apps/{name}` convention
4
+ export async function loadAppDirectories(root) {
5
+ const appBase = path.join(root, 'apps');
6
+ const appPattern = `${fg.convertPathToPattern(appBase)}/*`;
7
+ return fg.glob(appPattern, { onlyDirectories: true });
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nerest/nerest",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "React micro frontend framework",
5
5
  "homepage": "https://github.com/nerestjs/nerest",
6
6
  "repository": {
@@ -49,38 +49,39 @@
49
49
  ]
50
50
  },
51
51
  "dependencies": {
52
- "@apidevtools/json-schema-ref-parser": "^15.2.1",
53
- "@fastify/middie": "^9.1.0",
52
+ "@apidevtools/json-schema-ref-parser": "^15.3.1",
53
+ "@fastify/middie": "^9.2.0",
54
54
  "@fastify/static": "^9.0.0",
55
- "@fastify/swagger": "^9.6.1",
56
- "@fastify/swagger-ui": "^5.2.4",
57
- "ajv": "^8.17.1",
55
+ "@fastify/swagger": "^9.7.0",
56
+ "@fastify/swagger-ui": "^5.2.5",
57
+ "@vitejs/plugin-react": "^5.1.4",
58
+ "ajv": "^8.18.0",
58
59
  "ajv-formats": "^3.0.1",
59
- "dotenv": "^17.2.3",
60
+ "dotenv": "^17.3.1",
60
61
  "fast-glob": "^3.3.3",
61
62
  "fast-uri": "^3.1.0",
62
- "fastify": "^5.7.1",
63
+ "fastify": "^5.7.4",
63
64
  "fastify-graceful-shutdown": "^5.0.0",
64
65
  "json-schema-to-typescript": "^15.0.4",
65
66
  "vite": "^7.3.1",
66
67
  "vite-plugin-externals": "^0.6.2"
67
68
  },
68
69
  "devDependencies": {
69
- "@commitlint/cli": "^20.3.1",
70
- "@commitlint/config-conventional": "^20.3.1",
71
- "@playwright/test": "^1.57.0",
70
+ "@commitlint/cli": "^20.4.2",
71
+ "@commitlint/config-conventional": "^20.4.2",
72
+ "@playwright/test": "^1.58.2",
72
73
  "@tinkoff/eslint-config": "^5.0.1",
73
74
  "@tinkoff/eslint-config-react": "^5.0.1",
74
75
  "@tinkoff/prettier-config": "^5.0.0",
75
- "@types/react": "^19.2.8",
76
+ "@types/react": "^19.2.14",
76
77
  "@types/react-dom": "^19.2.3",
77
- "lint-staged": "^16.2.7",
78
- "react": "^19.2.3",
79
- "react-dom": "^19.2.3",
78
+ "lint-staged": "^16.3.1",
79
+ "react": "^19.2.4",
80
+ "react-dom": "^19.2.4",
80
81
  "simple-git-hooks": "^2.13.1",
81
- "sort-package-json": "^3.6.0",
82
+ "sort-package-json": "^3.6.1",
82
83
  "typescript": "^5.9.3",
83
- "vitest": "^4.0.17"
84
+ "vitest": "^4.0.18"
84
85
  },
85
86
  "peerDependencies": {
86
87
  "react": "^18.0.0 || ^19.0.0",
@@ -12,6 +12,7 @@ import {
12
12
  } from '../build/configs/development.js';
13
13
  import { loadBuildConfig } from './loaders/build.js';
14
14
  import { loadApps } from './loaders/apps.js';
15
+ import { loadAppDirectories } from './loaders/directories.js';
15
16
  import { loadProject } from './loaders/project.js';
16
17
 
17
18
  export async function runDevelopmentServer(port: number) {
@@ -30,6 +31,9 @@ export async function runDevelopmentServer(port: number) {
30
31
  // Load project meta details
31
32
  const project = await loadProject(root);
32
33
 
34
+ // Load app directories following the `apps/{name}` convention
35
+ const appDirectories = await loadAppDirectories(root);
36
+
33
37
  // Build the clientside assets and watch for changes
34
38
  await startClientBuildWatcher(
35
39
  await viteConfigDevelopmentClient({
@@ -37,6 +41,7 @@ export async function runDevelopmentServer(port: number) {
37
41
  base: staticPath,
38
42
  buildConfig,
39
43
  project,
44
+ appDirectories,
40
45
  })
41
46
  );
42
47
 
@@ -47,11 +52,12 @@ export async function runDevelopmentServer(port: number) {
47
52
  base: staticPath,
48
53
  buildConfig,
49
54
  project,
55
+ appDirectories,
50
56
  })
51
57
  );
52
58
 
53
59
  // Load app entries following the `apps/{name}/index.tsx` convention
54
- const apps = await loadApps(root, staticPath);
60
+ const apps = await loadApps(root, appDirectories, staticPath);
55
61
 
56
62
  const app = await createServer({
57
63
  root,
@@ -1,5 +1,4 @@
1
1
  import path from 'path';
2
- import fg from 'fast-glob';
3
2
  import type { Manifest as ViteManifest } from 'vite';
4
3
  import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
5
4
 
@@ -21,13 +20,13 @@ export type AppEntry = {
21
20
  // Build the record of the available apps by convention
22
21
  // apps -> /apps/{name}/index.tsx
23
22
  // examples -> /apps/{name}/examples/{example}.json
24
- export async function loadApps(root: string, deployedStaticPath: string) {
23
+ export async function loadApps(
24
+ root: string,
25
+ appDirs: string[],
26
+ deployedStaticPath: string
27
+ ) {
25
28
  const manifest = await loadViteManifest(root);
26
29
 
27
- const appBase = path.join(root, 'apps');
28
- const appPattern = `${fg.convertPathToPattern(appBase)}/*`;
29
- const appDirs = await fg.glob(appPattern, { onlyDirectories: true });
30
-
31
30
  const apps: Array<[name: string, entry: AppEntry]> = [];
32
31
  for (const appDir of appDirs) {
33
32
  apps.push(await loadApp(appDir, manifest, deployedStaticPath));
@@ -0,0 +1,9 @@
1
+ import path from 'path';
2
+ import fg from 'fast-glob';
3
+
4
+ // Load app directories following the `apps/{name}` convention
5
+ export async function loadAppDirectories(root: string) {
6
+ const appBase = path.join(root, 'apps');
7
+ const appPattern = `${fg.convertPathToPattern(appBase)}/*`;
8
+ return fg.glob(appPattern, { onlyDirectories: true });
9
+ }