proteum 1.0.2 → 2.0.0

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.
Files changed (185) hide show
  1. package/AGENTS.md +101 -0
  2. package/agents/codex/AGENTS.md +95 -0
  3. package/agents/codex/CODING_STYLE.md +71 -0
  4. package/agents/codex/agents.md.zip +0 -0
  5. package/agents/codex/client/AGENTS.md +102 -0
  6. package/agents/codex/client/pages/AGENTS.md +35 -0
  7. package/agents/codex/server/routes/AGENTS.md +12 -0
  8. package/agents/codex/server/services/AGENTS.md +137 -0
  9. package/agents/codex/tests/AGENTS.md +8 -0
  10. package/cli/app/config.ts +13 -11
  11. package/cli/app/index.ts +74 -82
  12. package/cli/bin.js +1 -1
  13. package/cli/commands/build.ts +51 -14
  14. package/cli/commands/check.ts +19 -0
  15. package/cli/commands/deploy/app.ts +4 -8
  16. package/cli/commands/deploy/web.ts +16 -20
  17. package/cli/commands/dev.ts +189 -64
  18. package/cli/commands/devEvents.ts +106 -0
  19. package/cli/commands/init.ts +63 -57
  20. package/cli/commands/lint.ts +21 -0
  21. package/cli/commands/refresh.ts +18 -0
  22. package/cli/commands/typecheck.ts +18 -0
  23. package/cli/compiler/client/identite.ts +80 -53
  24. package/cli/compiler/client/index.ts +139 -213
  25. package/cli/compiler/common/bundleAnalysis.ts +94 -0
  26. package/cli/compiler/common/clientManifest.ts +67 -0
  27. package/cli/compiler/common/controllers.ts +288 -0
  28. package/cli/compiler/common/files/autres.ts +7 -18
  29. package/cli/compiler/common/files/images.ts +40 -37
  30. package/cli/compiler/common/files/style.ts +11 -22
  31. package/cli/compiler/common/generatedRouteModules.ts +368 -0
  32. package/cli/compiler/common/index.ts +31 -65
  33. package/cli/compiler/common/loaders/forbid-ssr-import.js +13 -0
  34. package/cli/compiler/common/rspackAliases.ts +13 -0
  35. package/cli/compiler/common/scripts.ts +37 -0
  36. package/cli/compiler/index.ts +781 -230
  37. package/cli/compiler/server/index.ts +59 -75
  38. package/cli/compiler/writeIfChanged.ts +21 -0
  39. package/cli/index.ts +71 -72
  40. package/cli/paths.ts +51 -57
  41. package/cli/print.ts +17 -11
  42. package/cli/tsconfig.json +5 -4
  43. package/cli/utils/agents.ts +100 -0
  44. package/cli/utils/check.ts +71 -0
  45. package/cli/utils/index.ts +1 -3
  46. package/cli/utils/keyboard.ts +8 -25
  47. package/cli/utils/runProcess.ts +30 -0
  48. package/client/app/component.tsx +29 -29
  49. package/client/app/index.ts +36 -57
  50. package/client/app/service.ts +7 -12
  51. package/client/app.tsconfig.json +2 -2
  52. package/client/components/Dialog/Manager.ssr.tsx +40 -0
  53. package/client/components/Dialog/Manager.tsx +119 -150
  54. package/client/components/Dialog/status.tsx +3 -3
  55. package/client/components/index.ts +1 -1
  56. package/client/components/types.d.ts +1 -3
  57. package/client/dev/hmr.ts +65 -0
  58. package/client/global.d.ts +2 -2
  59. package/client/hooks.ts +6 -9
  60. package/client/index.ts +2 -1
  61. package/client/islands/index.ts +7 -0
  62. package/client/islands/useDeferredModule.ts +199 -0
  63. package/client/pages/_layout/index.tsx +4 -12
  64. package/client/pages/useHeader.tsx +14 -21
  65. package/client/router.ts +27 -0
  66. package/client/services/router/components/Link.tsx +34 -27
  67. package/client/services/router/components/Page.tsx +6 -14
  68. package/client/services/router/components/router.ssr.tsx +36 -0
  69. package/client/services/router/components/router.tsx +63 -83
  70. package/client/services/router/index.tsx +185 -220
  71. package/client/services/router/request/api.ts +97 -119
  72. package/client/services/router/request/history.ts +2 -2
  73. package/client/services/router/request/index.ts +13 -12
  74. package/client/services/router/request/multipart.ts +72 -62
  75. package/client/services/router/response/index.tsx +68 -61
  76. package/client/services/router/response/page.ts +28 -32
  77. package/client/utils/dom.ts +17 -33
  78. package/common/app/index.ts +3 -3
  79. package/common/data/chaines/index.ts +22 -23
  80. package/common/data/dates.ts +35 -70
  81. package/common/data/markdown.ts +42 -39
  82. package/common/dev/serverHotReload.ts +26 -0
  83. package/common/errors/index.tsx +110 -142
  84. package/common/router/contracts.ts +29 -0
  85. package/common/router/index.ts +89 -108
  86. package/common/router/layouts.ts +34 -47
  87. package/common/router/pageSetup.ts +50 -0
  88. package/common/router/register.ts +53 -24
  89. package/common/router/request/api.ts +30 -36
  90. package/common/router/request/index.ts +2 -8
  91. package/common/router/response/index.ts +8 -15
  92. package/common/router/response/page.ts +70 -58
  93. package/common/utils.ts +1 -1
  94. package/doc/TODO.md +1 -1
  95. package/eslint.js +62 -0
  96. package/package.json +12 -47
  97. package/prettier.config.cjs +9 -0
  98. package/scripts/cleanup-generated-controllers.ts +62 -0
  99. package/scripts/fix-reference-app-typing.ts +490 -0
  100. package/scripts/refactor-client-app-imports.ts +244 -0
  101. package/scripts/refactor-client-pages.ts +587 -0
  102. package/scripts/refactor-server-controllers.ts +470 -0
  103. package/scripts/refactor-server-runtime-aliases.ts +360 -0
  104. package/scripts/restore-client-app-import-files.ts +41 -0
  105. package/scripts/restore-files-from-git-head.ts +20 -0
  106. package/scripts/update-codex-agents.ts +35 -0
  107. package/server/app/commands.ts +35 -64
  108. package/server/app/container/config.ts +48 -59
  109. package/server/app/container/console/index.ts +202 -248
  110. package/server/app/container/index.ts +33 -71
  111. package/server/app/controller/index.ts +61 -0
  112. package/server/app/index.ts +39 -105
  113. package/server/app/service/container.ts +41 -42
  114. package/server/app/service/index.ts +120 -147
  115. package/server/context.ts +1 -1
  116. package/server/index.ts +25 -1
  117. package/server/services/auth/index.ts +75 -115
  118. package/server/services/auth/router/index.ts +31 -32
  119. package/server/services/auth/router/request.ts +14 -16
  120. package/server/services/cron/CronTask.ts +13 -26
  121. package/server/services/cron/index.ts +14 -36
  122. package/server/services/disks/driver.ts +40 -58
  123. package/server/services/disks/drivers/local/index.ts +79 -90
  124. package/server/services/disks/drivers/s3/index.ts +116 -163
  125. package/server/services/disks/index.ts +23 -38
  126. package/server/services/email/index.ts +45 -104
  127. package/server/services/email/utils.ts +14 -27
  128. package/server/services/fetch/index.ts +53 -85
  129. package/server/services/prisma/Facet.ts +39 -91
  130. package/server/services/prisma/index.ts +74 -110
  131. package/server/services/router/generatedRuntime.ts +29 -0
  132. package/server/services/router/http/index.ts +78 -73
  133. package/server/services/router/http/multipart.ts +19 -42
  134. package/server/services/router/index.ts +378 -365
  135. package/server/services/router/request/api.ts +26 -25
  136. package/server/services/router/request/index.ts +44 -51
  137. package/server/services/router/request/service.ts +7 -11
  138. package/server/services/router/request/validation/zod.ts +111 -148
  139. package/server/services/router/response/index.ts +110 -125
  140. package/server/services/router/response/mask/Filter.ts +31 -72
  141. package/server/services/router/response/mask/index.ts +8 -15
  142. package/server/services/router/response/mask/selecteurs.ts +11 -25
  143. package/server/services/router/response/page/clientManifest.ts +25 -0
  144. package/server/services/router/response/page/document.tsx +199 -127
  145. package/server/services/router/response/page/index.tsx +89 -94
  146. package/server/services/router/service.ts +13 -15
  147. package/server/services/schema/index.ts +17 -26
  148. package/server/services/schema/request.ts +19 -33
  149. package/server/services/schema/router/index.ts +8 -11
  150. package/server/services/security/encrypt/aes/index.ts +15 -35
  151. package/server/utils/slug.ts +29 -35
  152. package/skills/clean-project-code/SKILL.md +63 -0
  153. package/skills/clean-project-code/agents/openai.yaml +4 -0
  154. package/tsconfig.common.json +4 -3
  155. package/tsconfig.json +4 -1
  156. package/types/aliases.d.ts +17 -21
  157. package/types/controller-input.test.ts +48 -0
  158. package/types/express-extra.d.ts +6 -0
  159. package/types/global/constants.d.ts +13 -0
  160. package/types/global/express-extra.d.ts +6 -0
  161. package/types/global/modules.d.ts +13 -16
  162. package/types/global/utils.d.ts +17 -49
  163. package/types/global/vendors.d.ts +62 -0
  164. package/types/icons.d.ts +65 -1
  165. package/types/uuid.d.ts +3 -0
  166. package/types/vendors.d.ts +62 -0
  167. package/cli/compiler/common/babel/index.ts +0 -170
  168. package/cli/compiler/common/babel/plugins/index.ts +0 -0
  169. package/cli/compiler/common/babel/plugins/services.ts +0 -586
  170. package/cli/compiler/common/babel/routes/imports.ts +0 -127
  171. package/cli/compiler/common/babel/routes/routes.ts +0 -1130
  172. package/client/services/captcha/index.ts +0 -67
  173. package/client/services/socket/index.ts +0 -147
  174. package/common/data/rte/nodes.ts +0 -83
  175. package/common/data/stats.ts +0 -90
  176. package/common/utils/rte.ts +0 -183
  177. package/server/services/auth/old.ts +0 -277
  178. package/server/services/cache/commands.ts +0 -41
  179. package/server/services/cache/index.ts +0 -297
  180. package/server/services/cache/service.json +0 -6
  181. package/server/services/socket/index.ts +0 -162
  182. package/server/services/socket/scope.ts +0 -226
  183. package/server/services/socket/service.json +0 -6
  184. package/server/services_old/SocketClient.ts +0 -92
  185. package/server/services_old/Token.old.ts +0 -97
@@ -1,72 +1,99 @@
1
1
  // Npm
2
+ import { createHash } from 'crypto';
3
+ import path from 'path';
2
4
  import favicons from 'favicons';
3
5
  import fs from 'fs-extra';
4
6
 
5
- // Libs
6
- import cli from '../..';
7
-
8
7
  // Type
9
- import type App from '../../app';
8
+ import type { App } from '../../app';
9
+
10
+ export default async (app: App, outputDir: string, enabled: boolean = true) => {
11
+ if (!enabled) return;
10
12
 
11
- export default async ( app: App ) => {
13
+ const logoPath = path.join(app.paths.root, 'client', 'assets', 'identity', 'logo.svg');
14
+ const metadataPath = path.join(outputDir, '.proteum-identity-assets.json');
15
+ const options = createIdentityAssetsOptions(app);
16
+ const cacheKey = createHash('sha1').update(fs.readFileSync(logoPath)).update(JSON.stringify(options)).digest('hex');
12
17
 
13
- const dossierCache = app.paths.root + '/public/app';
18
+ const currentMetadata = readIdentityAssetsMetadata(metadataPath);
19
+ if (
20
+ currentMetadata?.cacheKey === cacheKey &&
21
+ currentMetadata.files.length > 0 &&
22
+ currentMetadata.files.every((file) => fs.existsSync(path.join(outputDir, file)))
23
+ )
24
+ return;
14
25
 
15
- if (!fs.existsSync(dossierCache)) {
26
+ console.info(`Generating identity assets ...`);
27
+ fs.emptyDirSync(outputDir);
16
28
 
17
- console.info(`Generating identity assets ...`);
18
- fs.emptyDirSync(dossierCache);
29
+ const response = await favicons(logoPath, options);
30
+ const generatedFiles = [...response.images.map((image) => image.name), ...response.files.map((file) => file.name)];
19
31
 
20
- const identity = app.identity;
32
+ await Promise.all([
33
+ // Enregistrement images
34
+ ...response.images.map((image) => {
35
+ let destimg = outputDir + '/' + image.name;
36
+ return fs.writeFile(destimg, image.contents);
37
+ }),
21
38
 
22
- const response = await favicons( app.paths.root + '/client/assets/identity/logo.svg', {
39
+ // Enregistrement fichiers
40
+ ...response.files.map((fichier) => {
41
+ let destfichier = outputDir + '/' + fichier.name;
42
+ return fs.writeFile(destfichier, fichier.contents);
43
+ }),
23
44
 
24
- path: '/assets/img/identite/favicons/',
25
- appName: identity.name,
26
- appShortName: identity.name,
27
- appDescription: identity.description,
28
- developerName: identity.author.name,
29
- developerURL: identity.author.url,
30
- dir: "auto",
31
- lang: identity.language,
32
- background: "#fff",
33
- theme_color: identity.maincolor,
34
- appleStatusBarStyle: "default",
35
- display: "standalone",
36
- orientation: "any",
37
- //scope: "/",
38
- start_url: "/",
39
- version: identity.web.version,
40
- logging: false,
41
- pixel_art: false,
42
- icons: {
43
- android: true,
44
- appleIcon: true,
45
- appleStartup: false,
46
- coast: false,
47
- favicons: true,
48
- firefox: true,
49
- windows: true,
50
- yandex: false
51
- }
45
+ fs.writeJSON(metadataPath, { cacheKey, files: generatedFiles }, { spaces: 2 }),
46
+ ]);
47
+ };
52
48
 
53
- });
49
+ function createIdentityAssetsOptions(app: App) {
50
+ const identity = app.identity;
54
51
 
55
- await Promise.all([
52
+ return {
53
+ path: '/assets/img/identite/favicons/',
54
+ appName: identity.name,
55
+ appShortName: identity.name,
56
+ appDescription: identity.description,
57
+ developerName: identity.author.name,
58
+ developerURL: identity.author.url,
59
+ dir: 'auto',
60
+ lang: identity.language,
61
+ background: '#fff',
62
+ theme_color: identity.maincolor,
63
+ appleStatusBarStyle: 'default',
64
+ display: 'standalone',
65
+ orientation: 'any',
66
+ start_url: '/',
67
+ version: identity.web.version,
68
+ logging: false,
69
+ pixel_art: false,
70
+ icons: {
71
+ android: true,
72
+ appleIcon: true,
73
+ appleStartup: false,
74
+ coast: false,
75
+ favicons: true,
76
+ windows: true,
77
+ yandex: false,
78
+ },
79
+ };
80
+ }
56
81
 
57
- // Enregistrement images
58
- ...response.images.map((image) => {
59
- let destimg = dossierCache + '/' + image.name;
60
- return fs.writeFile(destimg, image.contents);
61
- }),
82
+ function readIdentityAssetsMetadata(metadataPath: string): null | { cacheKey: string; files: string[] } {
83
+ if (!fs.existsSync(metadataPath)) return null;
62
84
 
63
- // Enregistrement fichiers
64
- ...response.files.map((fichier) => {
65
- let destfichier = dossierCache + '/' + fichier.name;
66
- return fs.writeFile(destfichier, fichier.contents);
67
- })
85
+ try {
86
+ const metadata = fs.readJSONSync(metadataPath);
87
+ if (
88
+ !metadata ||
89
+ typeof metadata.cacheKey !== 'string' ||
90
+ !Array.isArray(metadata.files) ||
91
+ !metadata.files.every((file: unknown) => typeof file === 'string')
92
+ )
93
+ return null;
68
94
 
69
- ]);
95
+ return metadata;
96
+ } catch {
97
+ return null;
70
98
  }
71
-
72
99
  }
@@ -3,26 +3,15 @@
3
3
  ----------------------------------*/
4
4
 
5
5
  // Npm
6
- import webpack from 'webpack';
7
- import fs from 'fs-extra';
6
+ import path from 'path';
7
+ import { rspack, type Configuration, type Module } from '@rspack/core';
8
8
 
9
9
  // Plugins
10
- const TerserPlugin = require('terser-webpack-plugin');
11
- // Optimisations
12
- const BrotliCompression = require("brotli-webpack-plugin");
13
- import CompressionPlugin from "compression-webpack-plugin";
14
- const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
15
- const imageminWebp = require('imagemin-webp');
16
- const { extendDefaultPlugins } = require("svgo");
17
- // Ressources
18
- const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
19
- import MiniCssExtractPlugin from "mini-css-extract-plugin";
20
- import WebpackAssetsManifest from 'webpack-assets-manifest';
21
- // Dev
22
- import PreactRefreshPlugin from '@prefresh/webpack';
23
10
 
24
11
  // Core
25
- import createCommonConfig, { TCompileMode, regex } from '../common';
12
+ import createCommonConfig, { TCompileMode, TCompileOutputTarget, regex } from '../common';
13
+ import { createClientBundleAnalysisPlugins } from '../common/bundleAnalysis';
14
+ import { toRspackAliases } from '../common/rspackAliases';
26
15
  import identityAssets from './identite';
27
16
  import cli from '../..';
28
17
 
@@ -30,19 +19,48 @@ import cli from '../..';
30
19
  import type { App } from '../../app';
31
20
 
32
21
  const debug = false;
22
+ const ssrScriptPattern = /\.ssr\.(ts|tsx)$/;
23
+ const normalizedCoreRoot = cli.paths.core.root.replace(/\\/g, '/');
24
+ const hmrClientEntry = path.join(cli.paths.core.root, 'client', 'dev', 'hmr.ts');
25
+
26
+ const normalizeModulePath = (value?: string) => (value || '').replace(/\\/g, '/');
27
+ const resolveFromAppOrCore = (app: App, request: string) =>
28
+ require.resolve(request, { paths: [app.paths.root, cli.paths.core.root] });
29
+
30
+ const getModulePath = (module: Module) => {
31
+ const resource = typeof module.nameForCondition === 'function' ? module.nameForCondition() : undefined;
32
+ const fallbackModule = module as Module & { resource?: string; context?: string };
33
+
34
+ return normalizeModulePath(resource || fallbackModule.resource || fallbackModule.context);
35
+ };
36
+
37
+ const isExternalVendorModule = (module: Module) => {
38
+ const modulePath = getModulePath(module);
39
+
40
+ return modulePath.includes('/node_modules/') && !modulePath.includes('/node_modules/proteum/');
41
+ };
42
+
43
+ const isCoreSourceModule = (module: Module) => {
44
+ const modulePath = getModulePath(module);
45
+
46
+ return modulePath.startsWith(normalizedCoreRoot + '/') || modulePath.includes('/node_modules/proteum/');
47
+ };
33
48
 
34
49
  /*----------------------------------
35
50
  - CONFIG
36
51
  ----------------------------------*/
37
- export default function createCompiler( app: App, mode: TCompileMode ): webpack.Configuration {
38
-
52
+ export default function createCompiler(
53
+ app: App,
54
+ mode: TCompileMode,
55
+ outputTarget: TCompileOutputTarget = mode === 'dev' ? 'dev' : 'bin',
56
+ ): Configuration {
39
57
  console.info(`Creating compiler for client (${mode}).`);
40
58
  const dev = mode === 'dev';
59
+ const outputPath = app.outputPath(outputTarget);
41
60
 
42
- const commonConfig = createCommonConfig(app, 'client', mode);
61
+ const commonConfig = createCommonConfig(app, 'client', mode, outputTarget);
43
62
 
44
- // Pas besoin d'attendre que les assets soient générés pour lancer la compilation
45
- identityAssets(app);
63
+ identityAssets(app, path.join(outputPath, 'public', 'app'));
46
64
 
47
65
  // Symlinks to public
48
66
  /*const publicDirs = fs.readdirSync(app.paths.root + '/public');
@@ -52,53 +70,57 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
52
70
  app.paths.public + '/' + publicDir
53
71
  );*/
54
72
 
55
- // Convert tsconfig cli.paths to webpack aliases
56
- const { aliases } = app.aliases.client.forWebpack({
57
- modulesPath: app.paths.root + '/node_modules'
58
- });
73
+ // Convert tsconfig paths into bundler aliases.
74
+ const { aliases } = app.aliases.client.forWebpack({ modulesPath: app.paths.root + '/node_modules' });
59
75
 
60
76
  // We're not supposed in any case to import server libs from client
61
- delete aliases["@server"];
62
- delete aliases["@/server"];
63
-
64
- debug && console.log("client aliases", aliases);
65
- const config: webpack.Configuration = {
66
-
77
+ delete aliases['@server'];
78
+ delete aliases['@/server'];
79
+ const rspackAliases = toRspackAliases(aliases);
80
+ rspackAliases['@/client/router$'] = cli.paths.core.root + '/client/router.ts';
81
+ rspackAliases['preact/jsx-runtime$'] = resolveFromAppOrCore(app, 'preact/jsx-runtime');
82
+ rspackAliases['react/jsx-runtime$'] = resolveFromAppOrCore(app, 'preact/jsx-runtime');
83
+ rspackAliases['react/jsx-dev-runtime$'] = resolveFromAppOrCore(app, 'preact/jsx-dev-runtime');
84
+
85
+ debug && console.log('client aliases', rspackAliases);
86
+ const config: Configuration = {
67
87
  ...commonConfig,
68
88
 
69
89
  name: 'client',
70
90
  target: 'web',
71
91
  entry: {
72
- client: [
73
- /*...(dev ? [
74
- process.env.framework + '/cli/compilation/webpack/libs/webpackHotDevClient.js',
75
- // https://github.com/webpack-contrib/webpack-hot-middleware#config
76
- cli.paths.core.root + '/node_modules' + '/webpack-hot-middleware/client?name=client&reload=true',
77
- ] : []),*/
78
- cli.paths.core.root + '/client/index.ts'
79
- ]
92
+ client: dev
93
+ ? [hmrClientEntry, cli.paths.core.root + '/client/index.ts']
94
+ : [cli.paths.core.root + '/client/index.ts'],
80
95
  },
81
96
 
82
97
  output: {
83
-
84
98
  pathinfo: dev,
85
- path: app.paths.bin + '/public',
99
+ path: outputPath + '/public',
86
100
  filename: '[name].js', // Output client.js
87
101
  assetModuleFilename: '[hash][ext]',
88
-
89
- chunkFilename: dev
90
- ? '[name].js'
91
- : '[id].[hash:8].js'
102
+ environment: {
103
+ arrowFunction: true,
104
+ asyncFunction: true,
105
+ bigIntLiteral: true,
106
+ const: true,
107
+ destructuring: true,
108
+ dynamicImport: true,
109
+ forOf: true,
110
+ optionalChaining: true,
111
+ templateLiteral: true,
112
+ },
113
+ cssFilename: '[name].css',
114
+ cssChunkFilename: '[name].css',
115
+ chunkFilename: dev ? '[name].js' : '[id].[contenthash:8].js',
92
116
  },
93
117
 
94
118
  resolve: {
95
-
96
119
  ...commonConfig.resolve,
97
120
 
98
- alias: aliases,
121
+ alias: rspackAliases,
99
122
 
100
- // RAPPEL: on a besoin de résoudre les node_modules
101
- extensions: [".mjs", '.ts', '.tsx', ".jsx", ".js", ".json", ".sql"],
123
+ extensions: ['.mjs', '.ts', '.tsx', '.jsx', '.js', '.json', '.sql'],
102
124
  },
103
125
 
104
126
  module: {
@@ -107,9 +129,29 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
107
129
 
108
130
  rules: [
109
131
  {
110
- test: regex.scripts,
132
+ test: ssrScriptPattern,
111
133
  include: [
134
+ app.paths.root + '/client',
135
+ cli.paths.core.root + '/client',
136
+
137
+ app.paths.root + '/common',
138
+ cli.paths.core.root + '/common',
112
139
 
140
+ app.paths.root + '/server',
141
+ cli.paths.core.root + '/server',
142
+ ],
143
+ loader: path.join(
144
+ cli.paths.core.root,
145
+ 'cli',
146
+ 'compiler',
147
+ 'common',
148
+ 'loaders',
149
+ 'forbid-ssr-import.js',
150
+ ),
151
+ },
152
+ {
153
+ test: regex.scripts,
154
+ include: [
113
155
  app.paths.root + '/client',
114
156
  cli.paths.core.root + '/client',
115
157
 
@@ -117,9 +159,8 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
117
159
  cli.paths.core.root + '/common',
118
160
 
119
161
  app.paths.root + '/server/.generated/models.ts',
120
-
121
162
  ],
122
- rules: require('../common/babel')(app, 'client', dev)
163
+ rules: require('../common/scripts')({ app, side: 'client', dev }),
123
164
  },
124
165
 
125
166
  // Les pages étan tà la fois compilées dans le bundle client et serveur
@@ -128,10 +169,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
128
169
  test: regex.style,
129
170
  rules: require('../common/files/style')(app, dev, true),
130
171
 
131
- // Don't consider CSS imports dead code even if the
132
- // containing package claims to have no side effects.
133
- // Remove this when webpack adds a warning or an error for this.
134
- // See https://github.com/webpack/webpack/issues/6571
172
+ // CSS imports stay side-effectful even when a package marks itself otherwise.
135
173
  sideEffects: true,
136
174
  },
137
175
 
@@ -150,186 +188,74 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
150
188
  },
151
189
 
152
190
  plugins: [
153
-
154
191
  ...(commonConfig.plugins || []),
155
192
 
156
- ...((dev && false) ? [] : [
157
- new MiniCssExtractPlugin({})
158
- ]),
159
-
160
- // Emit a file with assets cli.paths
161
- // https://github.com/webdeveric/webpack-assets-manifest#options
162
- new WebpackAssetsManifest({
163
- output: app.paths.root + `/bin/asset-manifest.json`,
164
- publicPath: true,
165
- writeToDisk: true, // Force la copie du fichier sur e disque, au lieu d'en mémoire en mode dev
166
- customize: ({ key, value }) => {
167
- // You can prevent adding items to the manifest by returning false.
168
- if (key.toLowerCase().endsWith('.map')) return false;
169
- return { key, value };
170
- },
171
- done: (manifest, stats) => {
172
- // Write chunk-manifest.json.json
173
- const chunkFileName = app.paths.root + `/bin/chunk-manifest.json`;
174
- try {
175
- const fileFilter = file => !file.endsWith('.map');
176
- const addPath = file => manifest.getPublicPath(file);
177
- const chunkFiles = stats.compilation.chunkGroups.reduce((acc, c) => {
178
- acc[c.name] = [
179
- ...(acc[c.name] || []),
180
- ...c.chunks.reduce(
181
- (files, cc) => [
182
- ...files,
183
- ...[...cc.files].filter(fileFilter).map(addPath),
184
- ],
185
- [],
186
- ),
187
- ];
188
- return acc;
189
- }, Object.create(null));
190
- fs.writeFileSync(chunkFileName, JSON.stringify(chunkFiles, null, 4));
191
- } catch (err) {
192
- console.error(`ERROR: Cannot write ${chunkFileName}: `, err);
193
- if (!dev) process.exit(1);
194
- }
195
- },
196
- }),
197
-
198
- ...(dev ? [
199
-
200
- // HMR pour preact
201
- //new PreactRefreshPlugin(),
202
-
203
- ] : [
193
+ ...(dev ? [] : [new rspack.CssExtractRspackPlugin({})]),
204
194
 
205
- /*new MomentLocalesPlugin({
206
- localesToKeep: ['fr'],
207
- }),*/
208
-
209
- /*new CompressionPlugin({
210
- cache: true,
211
- minRatio: 0.99
212
- }),
213
-
214
- new BrotliCompression({
215
- algorithm: 'gzip',
216
- test: /\.js$|\.css$|\.html$/,
217
- threshold: 10240,
218
- minRatio: 0.8,
219
- })*/
220
-
221
- /*new webpack.HashedModuleIdsPlugin({
222
- hashFunction: 'sha256',
223
- hashDigest: 'hex',
224
- hashDigestLength: 20,
225
- }),*/
226
-
227
- /*new PurgecssPlugin({}),*/
228
- ]),
195
+ ...createClientBundleAnalysisPlugins(app, outputTarget),
229
196
  ],
230
197
 
231
- // CSP-safe in development: avoid any `eval`-based source map mode.
232
- // https://webpack.js.org/configuration/devtool/#devtool
233
- devtool: dev ? 'cheap-module-source-map' : 'source-map',
198
+ // Use the cheapest practical client source maps in dev for faster rebuilds.
199
+ devtool: dev ? 'eval-cheap-module-source-map' : 'source-map',
234
200
  /*devServer: {
235
201
  hot: true,
236
202
  },*/
237
203
 
238
204
  optimization: {
239
-
240
205
  // Code splitting serveur = même que client
241
206
  // La décomposition des chunks doit toujours être la même car le rendu des pages dépend de cette organisation
242
207
 
243
- // https://webpack.js.org/plugins/split-chunks-plugin/#configuration
208
+ runtimeChunk: { name: 'runtime' },
244
209
  splitChunks: {
245
-
246
- // This indicates which chunks will be selected for optimization
247
- chunks: 'async',
248
- // Minimum size, in bytes, for a chunk to be generated.
249
- // Pour les imports async (ex: pages), on crée systématiquemen un chunk séparé
250
- // Afin que le css d'une page ne soit appliqué qu'à la page concernée
210
+ // Keep the initial shell lean while still preserving async route isolation.
211
+ chunks: 'all',
212
+ minSize: 20_000,
213
+ minRemainingSize: 0,
214
+ maxInitialRequests: 30,
215
+ maxAsyncRequests: 30,
251
216
  cacheGroups: {
252
- defaultVendors: {
253
- test: (module) => {
254
- // Check if the module is in node_modules but not in node_modules/proteum
255
- return /[\\/]node_modules[\\/]/.test(module.context) && !/[\\/]node_modules[\\/]proteum[\\/]/.test(module.context);
256
- },
257
- priority: -10,
217
+ framework: {
218
+ test: isCoreSourceModule,
219
+ chunks: 'initial',
220
+ name: 'framework',
221
+ priority: 40,
258
222
  reuseExistingChunk: true,
223
+ enforce: true,
259
224
  },
260
- default: {
261
- minChunks: 2,
262
- priority: -20,
225
+ initialVendors: {
226
+ test: isExternalVendorModule,
227
+ chunks: 'initial',
228
+ name: 'vendors',
229
+ priority: 30,
263
230
  reuseExistingChunk: true,
231
+ enforce: true,
264
232
  },
265
- },
233
+ asyncVendors: {
234
+ test: isExternalVendorModule,
235
+ chunks: 'async',
236
+ priority: 20,
237
+ reuseExistingChunk: true,
238
+ },
239
+ default: { minChunks: 2, priority: 10, reuseExistingChunk: true },
240
+ defaultVendors: false,
241
+ },
266
242
  },
267
243
 
268
244
  // Production
269
- ...(dev ? {} : {
270
-
271
- // https://github.com/react-boilerplate/react-boilerplate/blob/master/internals/webpack/webpack.prod.babel.js
272
- minimize: true,
273
- removeAvailableModules: true,
274
- minimizer: [
275
- new TerserPlugin({
276
- terserOptions: {
277
- parse: {
278
- // We want terser to parse ecma 8 code. However, we don't want it
279
- // to apply any minification steps that turns valid ecma 5 code
280
- // into invalid ecma 5 code. This is why the 'compress' and 'output'
281
- // sections only apply transformations that are ecma 5 safe
282
- // https://github.com/facebook/create-react-app/pull/4234
283
- ecma: 8,
284
- },
285
- compress: {
286
- ecma: 5,
287
- warnings: false,
288
- // Disabled because of an issue with Uglify breaking seemingly valid code:
289
- // https://github.com/facebook/create-react-app/issues/2376
290
- // Pending further investigation:
291
- // https://github.com/mishoo/UglifyJS2/issues/2011
292
- comparisons: false,
293
- // Disabled because of an issue with Terser breaking valid code:
294
- // https://github.com/facebook/create-react-app/issues/5250
295
- // Pending further investigation:
296
- // https://github.com/terser-js/terser/issues/120
297
- inline: 2,
298
- },
299
- mangle: {
300
- safari10: true,
301
- },
302
- output: {
303
- ecma: 5,
304
- comments: false,
305
- // Turned on because emoji and regex is not minified properly using default
306
- // https://github.com/facebook/create-react-app/issues/2488
307
- ascii_only: true,
308
- },
309
- }
310
- }),
311
-
312
- ...(dev ? [] : [
313
- new CssMinimizerPlugin()
314
- ]),
315
-
316
- /*new ImageMinimizerPlugin({
317
- // (optional) add generators; you can also just import &format=webp (see below)
318
- generator: [
319
- {
320
- preset: "webp",
321
- implementation: ImageMinimizerPlugin.imageminGenerate,
322
- options: { plugins: ["imagemin-webp"] }
323
- }
324
- ]
325
- })*/
326
- ],
327
- nodeEnv: 'production',
328
- sideEffects: true,
329
- }),
330
-
245
+ ...(dev
246
+ ? {}
247
+ : {
248
+ minimize: true,
249
+ removeAvailableModules: true,
250
+ minimizer: [
251
+ new rspack.SwcJsMinimizerRspackPlugin({}),
252
+ new rspack.LightningCssMinimizerRspackPlugin({}),
253
+ ],
254
+ nodeEnv: 'production',
255
+ sideEffects: true,
256
+ }),
331
257
  },
332
258
  };
333
259
 
334
260
  return config;
335
- };
261
+ }