@egen-civitas/egen 2.0.2 → 2.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @egen-civitas/egen
2
2
 
3
+ ## 2.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - ee309f3: `egen develop` : une app lancée localement n'est plus réécrite comme si elle était servie par le backend. Le premier serveur de dev d'app reçoit le port 8082, qui est aussi le backend par défaut (`--backend http://localhost:8082`) : `proxyImportmapAndRoutes` réécrivait alors son URL en chemin relatif (`.//egen-esm-xxx.js`), le shell la demandait au serveur du shell qui répondait une page 404 HTML, et l'app mourait avec « The global variable … does not refer to a federated module ». `proxyImportmapAndRoutes` accepte désormais `localImportKeys` (les apps lancées par `runProject`) et ne les réécrit jamais.
8
+
9
+ ## 2.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - f2b6ad6: `egen develop` n'alloue plus jamais à un serveur de dev d'app le port du backend : `getAvailablePort` accepte une liste de ports réservés (`reservedPorts`) transmise par `runProject`.
14
+
3
15
  ## 2.0.2
4
16
 
5
17
  ### Patch Changes
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAc,EAAE,KAAK,IAAI,EAAE,MAAM,OAAO,CAAC;AAkCzC,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,YAmW/B"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAc,EAAE,KAAK,IAAI,EAAE,MAAM,OAAO,CAAC;AAiDzC,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,YAoW/B"}
package/dist/cli.js CHANGED
@@ -3,6 +3,21 @@ import yargs from "yargs";
3
3
  import { fork } from "child_process";
4
4
  import { resolve } from "node:path";
5
5
  import { getAvailablePort, getImportmapAndRoutes, isPortAvailable, logFail, mergeImportmapAndRoutes, proxyImportmapAndRoutes, resolvePackages, runProject, trimEnd } from "./utils/index.js";
6
+ /**
7
+ * Port explicite de l'URL du backend (ex. 8082 pour http://localhost:8082), à réserver : les serveurs de
8
+ * dev des apps sont alloués à partir de `port + 1` et ne doivent JAMAIS prendre le port du backend, même
9
+ * s'il n'est pas (encore) démarré. Sinon l'import map d'une app dont l'URL est « backend » est réécrite en
10
+ * chemin relatif par proxyImportmapAndRoutes et l'app est introuvable (404).
11
+ */ function backendPorts(backend) {
12
+ try {
13
+ const port = Number(new URL(backend).port);
14
+ return Number.isInteger(port) && port > 0 ? [
15
+ port
16
+ ] : [];
17
+ } catch {
18
+ return [];
19
+ }
20
+ }
6
21
  const runner = resolve(import.meta.dirname, `runner.js`);
7
22
  const root = resolve(import.meta.dirname, '..');
8
23
  function runCommand(type, args) {
@@ -120,12 +135,16 @@ export function buildCli(y) {
120
135
  const sources = deduplicated.length > 0 ? deduplicated : [
121
136
  '.'
122
137
  ];
138
+ const importmapAndRoutes = await getImportmapAndRoutes(args.importmap, args.routes, port);
139
+ // Les ports du backend sont réservés : un serveur de dev d'app ne doit jamais s'y voir allouer.
140
+ const locallyRun = await runProject(port, sources, args['use-rspack'], backendPorts(args.backend));
123
141
  runCommand('runDevelop', {
124
142
  configUrls: args['config-url'],
125
143
  configFiles: args['config-file'],
126
144
  ...args,
127
145
  port,
128
- ...proxyImportmapAndRoutes(await mergeImportmapAndRoutes(await getImportmapAndRoutes(args.importmap, args.routes, port), await runProject(port, sources, args['use-rspack']), args.backend, args.spaPath), args.backend, args.spaPath)
146
+ ...proxyImportmapAndRoutes(await mergeImportmapAndRoutes(importmapAndRoutes, locallyRun, args.backend, args.spaPath), args.backend, args.spaPath, // Apps started locally must never be rewritten as if they were served by the backend.
147
+ Object.keys(locallyRun.importMap))
129
148
  });
130
149
  });
131
150
  y.command('build', 'Builds a new app shell.', (argv)=>argv.option('target', {
@@ -17,7 +17,7 @@ export interface ImportmapAndRoutesWithWatches extends ImportmapAndRoutes {
17
17
  }
18
18
  export declare function checkImportmapJson(value: string): boolean;
19
19
  export declare function checkRoutesJson(value: string): boolean;
20
- export declare function runProject(basePort: number, sourceDirectoryPatterns: Array<string>, useRspack?: boolean): Promise<{
20
+ export declare function runProject(basePort: number, sourceDirectoryPatterns: Array<string>, useRspack?: boolean, reservedPorts?: Array<number>): Promise<{
21
21
  importMap: Record<string, string>;
22
22
  routes: Record<string, unknown>;
23
23
  watchedRoutesPaths: Record<string, string>;
@@ -43,9 +43,13 @@ export declare function getRoutes(routesPath: string): Promise<RoutesDeclaration
43
43
  * @param importmapAndRoutes An ImportmapAndRoutes object that holds the import map and routes registry
44
44
  * @param backend The URL for the backend
45
45
  * @param spaPath The spaPath for this instance
46
+ * @param localImportKeys Names of the imports served by dev servers started locally (see `runProject`). They are
47
+ * never rewritten: their URL already points at the right dev server, even when it listens on the same host and
48
+ * port as the backend (the first dev server gets port 8082, which is also the default backend). Rewriting such an
49
+ * entry would make the shell request the bundle from the app shell server, which answers with an HTML 404.
46
50
  * @returns The same import map declaration but with all imports changed to the appropriate path
47
51
  */
48
- export declare function proxyImportmapAndRoutes(importmapAndRoutes: ImportmapAndRoutesWithWatches, backend: string, spaPath: string): {
52
+ export declare function proxyImportmapAndRoutes(importmapAndRoutes: ImportmapAndRoutesWithWatches, backend: string, spaPath: string, localImportKeys?: Iterable<string>): {
49
53
  importmap: ImportmapDeclaration;
50
54
  routes: RoutesDeclaration;
51
55
  watchedRoutesPaths: Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"importmap.d.ts","sourceRoot":"","sources":["../../src/utils/importmap.ts"],"names":[],"mappings":"AA8FA,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,QAAQ,GAAG,KAAK,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,QAAQ,GAAG,KAAK,CAAC;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S,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5C,CAAC,CAgFD;AAED;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,eAAe,EAAE,kBAAkB,EACnC,0BAA0B,EACtB;IACE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5C,GACD,KAAK,EACT,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,6BAA6B,CAAC,CAuCxC;AAED,wBAAsB,qBAAqB,CACzC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,kBAAkB,CAAC,CAI7B;AAED,wBAAsB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAuC1G;AAED,wBAAsB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA4B9E;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,kBAAkB,EAAE,6BAA6B,EACjD,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,eAAe,GAAE,QAAQ,CAAC,MAAM,CAAM;;;;EAkCvC"}
@@ -102,7 +102,7 @@ function runProjectDevServer(configPath, port, project, sourceDirectory, importM
102
102
  routes[project.name] = getAppRoutes(sourceDirectory, project);
103
103
  return ready;
104
104
  }
105
- export async function runProject(basePort, sourceDirectoryPatterns, useRspack) {
105
+ export async function runProject(basePort, sourceDirectoryPatterns, useRspack, reservedPorts = []) {
106
106
  const baseDir = process.cwd();
107
107
  const sourceDirectories = await matchAny(baseDir, sourceDirectoryPatterns);
108
108
  const importMap = {};
@@ -145,12 +145,12 @@ export async function runProject(basePort, sourceDirectoryPatterns, useRspack) {
145
145
  // try to locate and run via default webpack
146
146
  logWarn(`No "webpack.config.js" found in directory "${sourceDirectory}". Trying to use default config ...`);
147
147
  // Find next available port
148
- const port = await getAvailablePort(nextPortToCheck);
148
+ const port = await getAvailablePort(nextPortToCheck, reservedPorts);
149
149
  nextPortToCheck = port + 1;
150
150
  devServerReadyPromises.push(runProjectDevServer(defaultConfigPath, port, project, sourceDirectory, importMap, routes));
151
151
  } else {
152
152
  // Find next available port
153
- const port = await getAvailablePort(nextPortToCheck);
153
+ const port = await getAvailablePort(nextPortToCheck, reservedPorts);
154
154
  nextPortToCheck = port + 1;
155
155
  if (hasConfig) {
156
156
  // run via specialized webpack.config.js
@@ -285,8 +285,12 @@ export async function getRoutes(routesPath) {
285
285
  * @param importmapAndRoutes An ImportmapAndRoutes object that holds the import map and routes registry
286
286
  * @param backend The URL for the backend
287
287
  * @param spaPath The spaPath for this instance
288
+ * @param localImportKeys Names of the imports served by dev servers started locally (see `runProject`). They are
289
+ * never rewritten: their URL already points at the right dev server, even when it listens on the same host and
290
+ * port as the backend (the first dev server gets port 8082, which is also the default backend). Rewriting such an
291
+ * entry would make the shell request the bundle from the app shell server, which answers with an HTML 404.
288
292
  * @returns The same import map declaration but with all imports changed to the appropriate path
289
- */ export function proxyImportmapAndRoutes(importmapAndRoutes, backend, spaPath) {
293
+ */ export function proxyImportmapAndRoutes(importmapAndRoutes, backend, spaPath, localImportKeys = []) {
290
294
  const { importMap: importMapDecl, routes: routesDecl, watchedRoutesPaths } = importmapAndRoutes;
291
295
  if (importMapDecl.type != 'inline') {
292
296
  throw new Error('proxyImportmapAndRoutes called on non-inline import map. This is a programming error. Value: ' + importMapDecl.value);
@@ -297,7 +301,11 @@ export async function getRoutes(routesPath) {
297
301
  const backendUrl = new URL(backend);
298
302
  const importmap = JSON.parse(importMapDecl.value);
299
303
  const spaPathRegEx = new RegExp('^' + spaPath.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d'));
304
+ const localKeys = new Set(localImportKeys);
300
305
  Object.keys(importmap.imports).forEach((key)=>{
306
+ if (localKeys.has(key)) {
307
+ return;
308
+ }
301
309
  const url = new URL(importmap.imports[key], backendUrl);
302
310
  if (url.protocol === backendUrl.protocol && url.host === backendUrl.host) {
303
311
  importmap.imports[key] = `./${url.pathname.replace(spaPathRegEx, '')}${url.search}${url.hash}`;
@@ -13,8 +13,10 @@ export declare function isPortAvailable(port: number): Promise<boolean>;
13
13
  /**
14
14
  * Finds the next available port starting from the given port.
15
15
  * @param startPort The port number to start searching from
16
+ * @param reservedPorts Ports that must never be returned, even if they are currently free
17
+ * (e.g. the port of the backend the dev server proxies to, which may simply not be running yet)
16
18
  * @returns A promise that resolves to an available port number
17
19
  * @throws Error if no available port is found up to port 65535
18
20
  */
19
- export declare function getAvailablePort(startPort: number): Promise<number>;
21
+ export declare function getAvailablePort(startPort: number, reservedPorts?: Iterable<number>): Promise<number>;
20
22
  //# sourceMappingURL=port.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"port.d.ts","sourceRoot":"","sources":["../../src/utils/port.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA6B9D;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQzE"}
1
+ {"version":3,"file":"port.d.ts","sourceRoot":"","sources":["../../src/utils/port.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA6B9D;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,GAAE,QAAQ,CAAC,MAAM,CAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAY/G"}
@@ -41,10 +41,16 @@ const IPV6_UNSUPPORTED_CODES = new Set([
41
41
  /**
42
42
  * Finds the next available port starting from the given port.
43
43
  * @param startPort The port number to start searching from
44
+ * @param reservedPorts Ports that must never be returned, even if they are currently free
45
+ * (e.g. the port of the backend the dev server proxies to, which may simply not be running yet)
44
46
  * @returns A promise that resolves to an available port number
45
47
  * @throws Error if no available port is found up to port 65535
46
- */ export async function getAvailablePort(startPort) {
48
+ */ export async function getAvailablePort(startPort, reservedPorts = []) {
49
+ const reserved = new Set(reservedPorts);
47
50
  for(let port = startPort; port <= MAX_PORT; port++){
51
+ if (reserved.has(port)) {
52
+ continue;
53
+ }
48
54
  if (await isPortAvailable(port)) {
49
55
  return port;
50
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/egen",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "license": "MPL-2.0",
5
5
  "main": "dist/index.js",
6
6
  "files": [