@ecopages/core 0.5.0 → 0.6.1

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 (133) hide show
  1. package/README.md +18 -14
  2. package/package.json +13 -4
  3. package/src/adapters/create-app.js +9 -5
  4. package/src/adapters/node/create-app.d.ts +18 -16
  5. package/src/adapters/node/create-app.js +26 -30
  6. package/src/adapters/node/server-adapter.d.ts +26 -9
  7. package/src/adapters/node/server-adapter.js +38 -8
  8. package/src/adapters/shared/hmr/hmr-manager.js +3 -2
  9. package/src/adapters/shared/http/dist-file-handler.js +25 -7
  10. package/src/adapters/shared/runtime/render-context.d.ts +2 -1
  11. package/src/adapters/shared/runtime/render-context.js +18 -21
  12. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +4 -3
  13. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +6 -4
  14. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +6 -1
  15. package/src/adapters/shared/runtime/server-request-pipeline.js +10 -10
  16. package/src/adapters/shared/runtime/server-static-builder.d.ts +11 -11
  17. package/src/adapters/shared/runtime/server-static-builder.js +37 -18
  18. package/src/assets/app-browser-client-manifest.d.ts +1 -3
  19. package/src/assets/app-browser-client-manifest.js +5 -58
  20. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +2 -2
  21. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +2 -2
  22. package/src/assets/browser-asset-output.d.ts +1 -1
  23. package/src/assets/browser-asset-output.js +1 -1
  24. package/src/build/app-build-manifest-runtime.d.ts +11 -1
  25. package/src/build/app-build-manifest-runtime.js +17 -3
  26. package/src/build/cache/pages-unified-graph-build.d.ts +32 -35
  27. package/src/build/cache/pages-unified-graph-build.js +206 -124
  28. package/src/build/cache/server-module-entries.d.ts +35 -0
  29. package/src/build/cache/server-module-entries.js +109 -0
  30. package/src/build/contracts/build-contracts.d.ts +5 -0
  31. package/src/build/copy-server-files.d.ts +10 -0
  32. package/src/build/copy-server-files.js +37 -0
  33. package/src/build/preserve-import-meta-transform.d.ts +1 -1
  34. package/src/build/preserve-import-meta-transform.js +1 -1
  35. package/src/build/production-build-id.d.ts +9 -0
  36. package/src/build/production-build-id.js +19 -0
  37. package/src/build/production-dist-complete.d.ts +5 -0
  38. package/src/build/production-dist-complete.js +101 -0
  39. package/src/build/production-route-list.d.ts +26 -0
  40. package/src/build/production-route-list.js +78 -0
  41. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +2 -2
  42. package/src/build/rolldown/rolldown-adapter-helpers.js +56 -4
  43. package/src/build/rolldown/rolldown-build-adapter.js +1 -1
  44. package/src/build/runtime/build-request-identity.js +2 -1
  45. package/src/build/runtime/build-request-policy.d.ts +3 -2
  46. package/src/build/runtime/build-request-policy.js +5 -3
  47. package/src/build/server/import-view-module.d.ts +11 -0
  48. package/src/build/server/import-view-module.js +21 -0
  49. package/src/build/server/imported-view-plugin.d.ts +16 -0
  50. package/src/build/server/imported-view-plugin.js +59 -0
  51. package/src/build/server/page-module-import.service.d.ts +19 -20
  52. package/src/build/server/page-module-import.service.js +65 -36
  53. package/src/build/server/resolve-static-view.d.ts +9 -0
  54. package/src/build/server/resolve-static-view.js +28 -0
  55. package/src/build/server/route-module-build-cache-registry.d.ts +5 -3
  56. package/src/build/server/route-module-build-cache-registry.js +5 -3
  57. package/src/build/server/server-modules-manifest.d.ts +51 -0
  58. package/src/build/server/server-modules-manifest.js +129 -0
  59. package/src/build/server/view-reference.d.ts +38 -0
  60. package/src/build/server/view-reference.js +112 -0
  61. package/src/build/server-bundle-deploy-manifest.d.ts +9 -9
  62. package/src/build/server-bundle-deploy-manifest.js +24 -28
  63. package/src/build.d.ts +3 -1
  64. package/src/build.js +3 -1
  65. package/src/config/assembly/app-runtime.d.ts +15 -2
  66. package/src/config/assembly/app-runtime.js +3 -1
  67. package/src/config/assembly/finalize-config.js +64 -13
  68. package/src/config/index.d.ts +1 -0
  69. package/src/config/index.js +1 -0
  70. package/src/config/internal-types.d.ts +6 -0
  71. package/src/config/load-eco-config.d.ts +1 -0
  72. package/src/config/load-eco-config.js +11 -2
  73. package/src/config/resolve-eco-config-path.d.ts +2 -1
  74. package/src/config/resolve-eco-config-path.js +21 -15
  75. package/src/config/user-config-types.d.ts +9 -2
  76. package/src/html-pages/html-page-module.d.ts +19 -0
  77. package/src/html-pages/html-page-module.js +66 -13
  78. package/src/html-pages/html-page-renderer.d.ts +4 -0
  79. package/src/html-pages/html-page-renderer.js +9 -3
  80. package/src/html-pages/html-pages.plugin.d.ts +10 -0
  81. package/src/html-pages/html-pages.plugin.js +7 -1
  82. package/src/index.d.ts +2 -0
  83. package/src/index.js +2 -0
  84. package/src/integration.d.ts +2 -1
  85. package/src/integration.js +1 -0
  86. package/src/page-cache/page-cache-service.d.ts +8 -0
  87. package/src/page-cache/page-cache-service.js +12 -0
  88. package/src/plugins/integration-plugin.d.ts +33 -6
  89. package/src/plugins/integration-plugin.js +14 -2
  90. package/src/plugins/processor.d.ts +17 -0
  91. package/src/plugins/processor.js +20 -1
  92. package/src/plugins/server-dom.d.ts +29 -0
  93. package/src/plugins/server-dom.js +36 -0
  94. package/src/route-renderer/error-pages/error-page-renderer.d.ts +6 -4
  95. package/src/route-renderer/error-pages/error-page-renderer.js +9 -5
  96. package/src/route-renderer/orchestration/integration-renderer.d.ts +1 -0
  97. package/src/route-renderer/orchestration/integration-renderer.js +17 -2
  98. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +21 -0
  99. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +31 -0
  100. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +58 -24
  101. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +12 -0
  102. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +55 -0
  103. package/src/router/client/navigation-commit.js +16 -2
  104. package/src/router/client/navigation-head-order.fixture.css +3 -0
  105. package/src/router/client/navigation-head.d.ts +2 -1
  106. package/src/router/client/navigation-head.fixture.css +3 -0
  107. package/src/router/client/navigation-head.js +222 -39
  108. package/src/router/server/route-registry.d.ts +22 -2
  109. package/src/router/server/route-registry.js +39 -15
  110. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +8 -2
  111. package/src/static-site-generator/production-page-browser-graph-prebuild.js +14 -9
  112. package/src/static-site-generator/static-site-generator.d.ts +19 -3
  113. package/src/static-site-generator/static-site-generator.js +78 -40
  114. package/src/types/contracts.d.ts +20 -31
  115. package/src/types/public-types.d.ts +1 -0
  116. package/src/types/view-reference.d.ts +31 -0
  117. package/src/types/view-reference.js +15 -0
  118. package/src/utils/additional-watch-paths.d.ts +3 -3
  119. package/src/utils/additional-watch-paths.js +3 -1
  120. package/src/utils/resolve-entry-file.d.ts +4 -2
  121. package/src/utils/resolve-entry-file.js +4 -2
  122. package/src/utils/root-relative-path.d.ts +4 -0
  123. package/src/utils/root-relative-path.js +8 -0
  124. package/src/utils/server-bundle-context.d.ts +14 -0
  125. package/src/utils/server-bundle-context.js +45 -0
  126. package/src/watchers/project-watcher-ignore.d.ts +2 -5
  127. package/src/watchers/project-watcher-ignore.js +2 -5
  128. package/src/watchers/project-watcher.d.ts +9 -7
  129. package/src/watchers/project-watcher.js +100 -52
  130. package/src/watchers/workspace-package-watch-roots.d.ts +4 -4
  131. package/src/watchers/workspace-package-watch-roots.js +41 -25
  132. package/src/build/server/view-module-loader.d.ts +0 -10
  133. package/src/build/server/view-module-loader.js +0 -46
@@ -1,5 +1,4 @@
1
1
  import path from 'node:path';
2
- import chokidar, {} from 'chokidar';
3
2
  import { fileSystem } from '@ecopages/file-system';
4
3
  import { appLogger } from '../global/app-logger.js';
5
4
  import { getEcopagesEnv } from '../env.js';
@@ -41,6 +40,7 @@ export class ProjectWatcher {
41
40
  restartRequestScheduled = false;
42
41
  workspacePackageRoots = [];
43
42
  watcher = null;
43
+ watchedPaths = new Set();
44
44
  watcherReady;
45
45
  watcherReadyTimeout;
46
46
  rejectWatcherReady;
@@ -108,7 +108,7 @@ export class ProjectWatcher {
108
108
  }
109
109
  }
110
110
  /**
111
- * Serializes file change handling so that concurrent chokidar events are
111
+ * Serializes file change handling so that concurrent filesystem events are
112
112
  * processed one at a time, preventing overlapping builds and race conditions.
113
113
  */
114
114
  enqueueChange(task) {
@@ -351,16 +351,16 @@ export class ProjectWatcher {
351
351
  /**
352
352
  * @remarks
353
353
  * The subscription watches `srcDir` recursively alongside external recorded
354
- * inputs, restart files, workspace roots, and additional watch paths. Processor
355
- * notifications share the same file-change pipeline. `awaitWriteFinish` waits
356
- * for writes to stabilize before a file event is processed.
354
+ * inputs, restart files, workspace roots used by recorded inputs, and additional watch paths. Processor
355
+ * notifications share the same file-change pipeline. The filesystem adapter
356
+ * coalesces native events for one path across a 50 ms window.
357
357
  *
358
358
  * A glob in `additionalWatchPaths` is watched through its static base
359
359
  * directory, which can be the project root for `**` patterns. Files reached
360
360
  * only through such a base are ignored unless they match a pattern, and so
361
361
  * are dot-directories the pattern does not name, so a broad base does not
362
362
  * feed unrelated files into the change pipeline. Readiness rejects and closes
363
- * the subscription if Chokidar does not become ready within 30 seconds.
363
+ * the subscription if the filesystem adapter does not become ready within 30 seconds.
364
364
  */
365
365
  async createWatcherSubscription() {
366
366
  if (this.watcher) {
@@ -368,6 +368,9 @@ export class ProjectWatcher {
368
368
  }
369
369
  const buildInputIndex = requireAppRuntime(this.appConfig).buildInputIndex;
370
370
  seedProcessorWatchPaths(this.appConfig, buildInputIndex);
371
+ const recordedWatchPaths = buildInputIndex.recordedWatchPaths();
372
+ this.workspacePackageRoots = resolveWorkspacePackageWatchRoots(this.appConfig.rootDir);
373
+ const activeWorkspacePackageRoots = new Set(this.workspacePackageRoots.filter((root) => recordedWatchPaths.some((filePath) => isPathInside(filePath, root))));
371
374
  const srcDir = this.appConfig.absolutePaths.srcDir;
372
375
  const literalPaths = new Set([srcDir]);
373
376
  const { pagesDir, componentsDir, includesDir, layoutsDir, publicDir } = this.appConfig.absolutePaths;
@@ -376,8 +379,9 @@ export class ProjectWatcher {
376
379
  literalPaths.add(sourceDir);
377
380
  }
378
381
  }
379
- for (const recordedPath of buildInputIndex.recordedWatchPaths()) {
380
- if (!isPathInside(recordedPath, srcDir)) {
382
+ for (const recordedPath of recordedWatchPaths) {
383
+ if (!isPathInside(recordedPath, srcDir) &&
384
+ !this.workspacePackageRoots.some((root) => isPathInside(recordedPath, root))) {
381
385
  literalPaths.add(recordedPath);
382
386
  }
383
387
  }
@@ -396,28 +400,61 @@ export class ProjectWatcher {
396
400
  for (const restartPath of resolveRuntimeRestartWatchPaths(this.appConfig)) {
397
401
  literalPaths.add(restartPath);
398
402
  }
399
- this.workspacePackageRoots = resolveWorkspacePackageWatchRoots(this.appConfig.rootDir);
400
- const ignoreProjectPath = createProjectWatcherIgnorePredicate(this.appConfig.absolutePaths, this.workspacePackageRoots);
401
- const ignored = (watchedPath, stats) => {
402
- if (ignoreProjectPath(watchedPath))
403
- return true;
404
- if (!stats ||
405
- [...literalPaths].some((literalPath) => isPathInside(watchedPath, literalPath)) ||
406
- this.workspacePackageRoots.some((root) => isPathInside(watchedPath, root)))
407
- return false;
408
- return stats.isDirectory()
409
- ? !globWatchPaths.some((watchPath) => mayContainAdditionalWatchMatches(watchedPath, watchPath))
410
- : !globWatchPaths.some((watchPath) => matchesAdditionalWatchPath(watchedPath, watchPath));
411
- };
412
- this.watcher = chokidar.watch([...literalPaths, ...this.workspacePackageRoots, ...new Set(globWatchPaths.map(({ base }) => base))], {
413
- ignoreInitial: true,
414
- ignorePermissionErrors: true,
415
- ignored,
416
- awaitWriteFinish: {
417
- stabilityThreshold: 50,
418
- pollInterval: 50,
403
+ const ignoreProjectPath = createProjectWatcherIgnorePredicate({
404
+ ...this.appConfig.absolutePaths,
405
+ distDir: path.resolve(this.appConfig.rootDir, this.appConfig.distDir),
406
+ }, this.workspacePackageRoots);
407
+ const watchOptions = {
408
+ ignored: (watchedPath, stats) => {
409
+ if (ignoreProjectPath(watchedPath))
410
+ return true;
411
+ if (!stats ||
412
+ [...literalPaths].some((literalPath) => isPathInside(watchedPath, literalPath) || isPathInside(literalPath, watchedPath)) ||
413
+ [...activeWorkspacePackageRoots].some((root) => isPathInside(watchedPath, root) || isPathInside(root, watchedPath)))
414
+ return false;
415
+ return stats.isDirectory
416
+ ? !globWatchPaths.some((watchPath) => mayContainAdditionalWatchMatches(watchedPath, watchPath))
417
+ : !globWatchPaths.some((watchPath) => matchesAdditionalWatchPath(watchedPath, watchPath));
419
418
  },
420
- });
419
+ onChange: (change) => this.handleWatchChange(change),
420
+ onError: (error) => {
421
+ this.handleError(error);
422
+ const processorError = error instanceof Error ? error : new Error(String(error));
423
+ for (const processor of this.appConfig.processors.values()) {
424
+ processor.getWatchConfig()?.onError?.(processorError);
425
+ }
426
+ },
427
+ };
428
+ const initialWatchPaths = [
429
+ ...literalPaths,
430
+ ...activeWorkspacePackageRoots,
431
+ ...new Set(globWatchPaths.map(({ base }) => base)),
432
+ ];
433
+ for (const watchPath of initialWatchPaths)
434
+ this.watchedPaths.add(path.resolve(watchPath));
435
+ const watcher = fileSystem.watch(initialWatchPaths, watchOptions);
436
+ this.watcher = watcher;
437
+ const workspacePackageRootsAdding = new Set();
438
+ /**
439
+ * @remarks
440
+ * A recorded input may not be published again, so inputs arriving during registration request one retry on failure.
441
+ */
442
+ const workspacePackageRootsToRetry = new Set();
443
+ const addWorkspacePackageRoot = (root) => {
444
+ activeWorkspacePackageRoots.add(root);
445
+ this.watchedPaths.add(root);
446
+ workspacePackageRootsAdding.add(root);
447
+ void watcher.add([root]).then(() => {
448
+ workspacePackageRootsAdding.delete(root);
449
+ workspacePackageRootsToRetry.delete(root);
450
+ }, () => {
451
+ workspacePackageRootsAdding.delete(root);
452
+ activeWorkspacePackageRoots.delete(root);
453
+ this.watchedPaths.delete(root);
454
+ if (!this.closed && workspacePackageRootsToRetry.delete(root))
455
+ addWorkspacePackageRoot(root);
456
+ });
457
+ };
421
458
  this.watcherReady = new Promise((resolve, reject) => {
422
459
  this.rejectWatcherReady = reject;
423
460
  this.watcherReadyTimeout = setTimeout(() => {
@@ -425,47 +462,60 @@ export class ProjectWatcher {
425
462
  this.rejectWatcherReady = undefined;
426
463
  reject(new Error(`Filesystem watcher did not become ready within ${ProjectWatcher.watcherReadyTimeoutMs}ms`));
427
464
  }, ProjectWatcher.watcherReadyTimeoutMs);
428
- this.watcher.once('ready', () => {
465
+ watcher.ready.then(() => {
429
466
  this.clearWatcherReadyTimeout();
430
467
  this.rejectWatcherReady = undefined;
431
468
  resolve();
432
- });
433
- this.watcher.once('error', (error) => {
469
+ }, (error) => {
434
470
  this.clearWatcherReadyTimeout();
435
471
  this.rejectWatcherReady = undefined;
436
472
  reject(error);
437
473
  });
438
474
  });
439
475
  this.unsubscribeFromRecordedWatchPaths = buildInputIndex.subscribeToWatchPaths((filePath) => {
440
- if (this.closed || !this.watcher) {
476
+ const watcher = this.watcher;
477
+ if (this.closed || !watcher) {
441
478
  return;
442
479
  }
443
480
  if (ignoreProjectPath(filePath)) {
444
481
  return;
445
482
  }
446
483
  const resolvedPath = path.resolve(filePath);
484
+ const matchingWorkspaceRoots = this.workspacePackageRoots.filter((root) => isPathInside(resolvedPath, root));
485
+ if (matchingWorkspaceRoots.length > 0) {
486
+ for (const root of matchingWorkspaceRoots) {
487
+ if (activeWorkspacePackageRoots.has(root)) {
488
+ if (workspacePackageRootsAdding.has(root))
489
+ workspacePackageRootsToRetry.add(root);
490
+ continue;
491
+ }
492
+ addWorkspacePackageRoot(root);
493
+ }
494
+ return;
495
+ }
447
496
  if (literalPaths.has(resolvedPath) ||
448
- [...literalPaths].some((literalPath) => isPathInside(resolvedPath, literalPath))) {
497
+ [...literalPaths, ...activeWorkspacePackageRoots].some((watchedPath) => isPathInside(resolvedPath, watchedPath))) {
449
498
  return;
450
499
  }
451
500
  literalPaths.add(resolvedPath);
452
- this.watcher.add(resolvedPath);
501
+ this.watchedPaths.add(resolvedPath);
502
+ void watcher.add([resolvedPath]).catch(() => {
503
+ literalPaths.delete(resolvedPath);
504
+ this.watchedPaths.delete(resolvedPath);
505
+ });
453
506
  });
454
- this.watcher
455
- .on('change', (p) => this.handleFileChange(p, 'change'))
456
- .on('add', (p) => this.handleFileChange(p, 'add'))
457
- .on('addDir', (p) => this.handleDirectoryChange(p))
458
- .on('unlink', (p) => this.handleFileChange(p, 'unlink'))
459
- .on('unlinkDir', (p) => this.handleDirectoryChange(p))
460
- .on('error', (error) => this.handleError(error));
461
- for (const processor of this.appConfig.processors.values()) {
462
- const watchConfig = processor.getWatchConfig();
463
- if (watchConfig?.onError) {
464
- this.watcher.on('error', watchConfig.onError);
465
- }
466
- }
467
507
  return this.waitForWatcherReady();
468
508
  }
509
+ handleWatchChange(change) {
510
+ if (change.type === 'rescan') {
511
+ this.handleRuntimeRestart(change.path);
512
+ return Promise.resolve();
513
+ }
514
+ if (change.type === 'addDir' || change.type === 'unlinkDir') {
515
+ return this.handleDirectoryChange(change.path);
516
+ }
517
+ return this.handleFileChange(change.path, change.type);
518
+ }
469
519
  /**
470
520
  * Closes the active filesystem watcher subscription.
471
521
  *
@@ -493,10 +543,8 @@ export class ProjectWatcher {
493
543
  for (const resolve of this.pendingFlushResolvers.splice(0)) {
494
544
  resolve();
495
545
  }
496
- if (this.watcher) {
497
- await this.watcher.close();
498
- this.watcher = null;
499
- }
546
+ await this.watcher?.close();
547
+ this.watcher = null;
500
548
  await this.changeQueue.catch(() => undefined);
501
549
  }
502
550
  }
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @remarks
3
- * Watch declared direct dependencies, including development and optional ones,
4
- * so server-only imports and packages with subpath-only exports are covered
5
- * before the first browser request. Resolve the installed directory rather than
6
- * package exports: a package need not expose its root entry or package.json.
3
+ * Resolve linked direct and transitive dependencies, including development
4
+ * and optional ones. The Project Watcher activates each root only after a
5
+ * recorded build input lies inside it. Resolve installed directories rather
6
+ * than package exports: a package need not expose its root entry or package.json.
7
7
  */
8
8
  export declare function resolveWorkspacePackageWatchRoots(rootDir: string): string[];
9
9
  export declare function isWorkspacePackageFile(filePath: string, roots: readonly string[]): boolean;
@@ -3,41 +3,57 @@ import { fileSystem } from '@ecopages/file-system';
3
3
  import { isPathStrictlyInside } from '../utils/path-containment.js';
4
4
  /**
5
5
  * @remarks
6
- * Watch declared direct dependencies, including development and optional ones,
7
- * so server-only imports and packages with subpath-only exports are covered
8
- * before the first browser request. Resolve the installed directory rather than
9
- * package exports: a package need not expose its root entry or package.json.
6
+ * Resolve linked direct and transitive dependencies, including development
7
+ * and optional ones. The Project Watcher activates each root only after a
8
+ * recorded build input lies inside it. Resolve installed directories rather
9
+ * than package exports: a package need not expose its root entry or package.json.
10
10
  */
11
11
  export function resolveWorkspacePackageWatchRoots(rootDir) {
12
- const manifestPath = path.join(rootDir, 'package.json');
12
+ const roots = new Set();
13
+ const visitedPackages = new Set();
14
+ const pendingPackages = [path.resolve(rootDir)];
15
+ while (pendingPackages.length > 0) {
16
+ const packageRoot = pendingPackages.pop();
17
+ if (!packageRoot || visitedPackages.has(packageRoot))
18
+ continue;
19
+ visitedPackages.add(packageRoot);
20
+ for (const name of getDeclaredDependencies(packageRoot)) {
21
+ const linkedRoot = resolveInstalledPackageRoot(packageRoot, name);
22
+ if (!linkedRoot)
23
+ continue;
24
+ roots.add(linkedRoot);
25
+ if (!visitedPackages.has(linkedRoot))
26
+ pendingPackages.push(linkedRoot);
27
+ }
28
+ }
29
+ return [...roots];
30
+ }
31
+ function getDeclaredDependencies(packageRoot) {
32
+ const manifestPath = path.join(packageRoot, 'package.json');
13
33
  if (!fileSystem.exists(manifestPath))
14
- return [];
34
+ return new Set();
15
35
  const manifest = JSON.parse(fileSystem.readFileSync(manifestPath));
16
- const names = new Set([
36
+ return new Set([
17
37
  ...Object.keys(manifest.dependencies ?? {}),
18
38
  ...Object.keys(manifest.devDependencies ?? {}),
19
39
  ...Object.keys(manifest.optionalDependencies ?? {}),
20
40
  ]);
21
- const roots = new Set();
22
- for (const name of names) {
23
- if (!/^(?:@[^/]+\/)?[^/]+$/u.test(name) || name.startsWith('.'))
24
- continue;
25
- let directory = path.resolve(rootDir);
26
- while (true) {
27
- const installed = path.join(directory, 'node_modules', name);
28
- if (fileSystem.exists(path.join(installed, 'package.json'))) {
29
- const realRoot = fileSystem.realpath(installed);
30
- if (!realRoot.split(path.sep).includes('node_modules'))
31
- roots.add(realRoot);
32
- break;
33
- }
34
- const parent = path.dirname(directory);
35
- if (parent === directory)
36
- break;
37
- directory = parent;
41
+ }
42
+ function resolveInstalledPackageRoot(packageRoot, name) {
43
+ if (!/^(?:@[^/]+\/)?[^/]+$/u.test(name) || name.startsWith('.'))
44
+ return undefined;
45
+ let directory = path.resolve(packageRoot);
46
+ while (true) {
47
+ const installed = path.join(directory, 'node_modules', name);
48
+ if (fileSystem.exists(path.join(installed, 'package.json'))) {
49
+ const realRoot = fileSystem.realpath(installed);
50
+ return realRoot.split(path.sep).includes('node_modules') ? undefined : realRoot;
38
51
  }
52
+ const parent = path.dirname(directory);
53
+ if (parent === directory)
54
+ return undefined;
55
+ directory = parent;
39
56
  }
40
- return [...roots];
41
57
  }
42
58
  export function isWorkspacePackageFile(filePath, roots) {
43
59
  return roots.some((root) => isPathStrictlyInside(filePath, root));
@@ -1,10 +0,0 @@
1
- import type { EcoPagesAppConfig } from '../../config/internal-types.js';
2
- import type { ViewLoader } from '../../types/contracts.js';
3
- /**
4
- * Creates a view loader that imports through the app server-module transpiler.
5
- *
6
- * @remarks
7
- * Use this for `app.static()` and HTML error-page registrations instead of
8
- * raw dynamic `import()` so Node applies Ecopages build transforms (component identity).
9
- */
10
- export declare function createViewModuleLoader<P = Record<string, unknown>>(appConfig: EcoPagesAppConfig, modulePath: string | URL): ViewLoader<P>;
@@ -1,46 +0,0 @@
1
- import path from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import { fileSystem } from '@ecopages/file-system';
4
- import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
5
- import { requireAppRuntime } from '../../utils/app-runtime.js';
6
- function resolveViewModuleOnDisk(filePath, templatesExt) {
7
- if (fileSystem.exists(filePath)) {
8
- return filePath;
9
- }
10
- for (const extension of templatesExt) {
11
- const withExtension = `${filePath}${extension}`;
12
- if (fileSystem.exists(withExtension)) {
13
- return withExtension;
14
- }
15
- }
16
- const pathWithoutTerminalExtension = filePath.replace(/\.[^./]+$/, '');
17
- for (const extension of templatesExt) {
18
- const candidate = `${pathWithoutTerminalExtension}${extension}`;
19
- if (fileSystem.exists(candidate)) {
20
- return candidate;
21
- }
22
- }
23
- return filePath;
24
- }
25
- function resolveViewModuleFilePath(appConfig, modulePath) {
26
- const filePath = modulePath instanceof URL ? fileURLToPath(modulePath) : modulePath;
27
- const rootedPath = path.isAbsolute(filePath)
28
- ? filePath
29
- : path.join(appConfig.rootDir, filePath.replace(/^\.\//, ''));
30
- return resolveViewModuleOnDisk(rootedPath, appConfig.templatesExt);
31
- }
32
- /**
33
- * Creates a view loader that imports through the app server-module transpiler.
34
- *
35
- * @remarks
36
- * Use this for `app.static()` and HTML error-page registrations instead of
37
- * raw dynamic `import()` so Node applies Ecopages build transforms (component identity).
38
- */
39
- export function createViewModuleLoader(appConfig, modulePath) {
40
- const filePath = resolveViewModuleFilePath(appConfig, modulePath);
41
- return async () => await requireAppRuntime(appConfig).moduleLoader.importModule({
42
- filePath,
43
- outdir: path.join(resolveInternalExecutionDir(appConfig), '.server-modules'),
44
- externalPackages: true,
45
- });
46
- }