@ecopages/core 0.3.1 → 0.3.2

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 (39) hide show
  1. package/package.json +3 -3
  2. package/src/adapters/node/create-app.d.ts +12 -1
  3. package/src/adapters/node/create-app.js +18 -3
  4. package/src/adapters/node/runtime-host.d.ts +5 -0
  5. package/src/adapters/node/runtime-host.js +8 -1
  6. package/src/adapters/shared/hmr/hmr-manager.d.ts +12 -2
  7. package/src/adapters/shared/hmr/hmr-manager.js +20 -16
  8. package/src/adapters/shared/runtime/bind-runtime-server.js +3 -1
  9. package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
  10. package/src/adapters/shared/runtime/port-manager.d.ts +6 -0
  11. package/src/adapters/shared/runtime/port-manager.js +16 -2
  12. package/src/assets/app-browser-client-build.js +1 -2
  13. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
  14. package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
  15. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
  16. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
  17. package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
  18. package/src/assets/browser-asset-output.d.ts +19 -0
  19. package/src/assets/browser-asset-output.js +30 -0
  20. package/src/assets/hashed-browser-asset.d.ts +8 -6
  21. package/src/assets/hashed-browser-asset.js +8 -6
  22. package/src/build/build-graph.js +2 -2
  23. package/src/build/preserve-import-meta-transform.js +2 -2
  24. package/src/build/rolldown/app-package-declarations.js +3 -3
  25. package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
  26. package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
  27. package/src/build/server-bundle-publication.js +4 -5
  28. package/src/config/config-module-files.js +2 -3
  29. package/src/diagnostics/startup-trace.js +2 -5
  30. package/src/html-pages/html-page-module-scripts.js +4 -3
  31. package/src/html-pages/html-page-renderer.js +2 -3
  32. package/src/plugins/component-import-discovery.js +4 -4
  33. package/src/plugins/foreign-jsx-override-plugin.js +2 -2
  34. package/src/plugins/tsconfig-import-resolver.js +12 -12
  35. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +0 -17
  36. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -23
  37. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
  38. package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
  39. package/src/router/server/route-registry.js +1 -2
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
+ import { assertBrowserOutputInsideDist, sourceRelativeBrowserAssetPath } from '../../../browser-asset-output.js';
3
4
  import { writeHashedBrowserAsset } from '../../../hashed-browser-asset.js';
4
5
  import { BaseProcessor } from '../base/base-processor.js';
5
6
  import { applyStylesheetProcessors } from './stylesheet-processor-pipeline.js';
@@ -13,14 +14,18 @@ export class FileStylesheetProcessor extends BaseProcessor {
13
14
  const processedContent = await applyStylesheetProcessors(this.appConfig, rawContent, dep.filepath);
14
15
  let filepath;
15
16
  if (!dep.inline) {
16
- filepath = this.isProduction
17
- ? writeHashedBrowserAsset({
17
+ const relativePath = sourceRelativeBrowserAssetPath(this.appConfig.absolutePaths.srcDir, dep.filepath);
18
+ const directory = this.getAssetsDir();
19
+ if (this.isProduction || !relativePath) {
20
+ filepath = writeHashedBrowserAsset({
18
21
  bytes: processedContent,
19
- directory: this.getAssetsDir(),
22
+ directory,
20
23
  extension: '.css',
21
- })
22
- : path.join(this.getAssetsDir(), path.relative(this.appConfig.absolutePaths.srcDir, dep.filepath));
23
- if (!this.isProduction) {
24
+ });
25
+ }
26
+ else {
27
+ filepath = path.join(directory, relativePath);
28
+ assertBrowserOutputInsideDist(this.appConfig.absolutePaths.distDir, filepath);
24
29
  fileSystem.ensureDir(path.dirname(filepath));
25
30
  fileSystem.write(filepath, processedContent);
26
31
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Source-relative path of a file inside `srcDir`.
3
+ *
4
+ * @remarks
5
+ * `path.relative` from `srcDir` to a file outside it starts with `..`. Joining
6
+ * that onto `dist` writes the asset outside the build. Callers then emit the file
7
+ * in `dist/assets`: a bundled script under the bundler's `[name]-[hash]` name, and
8
+ * an unbundled script or stylesheet under a content hash.
9
+ */
10
+ export declare function sourceRelativeBrowserAssetPath(srcDir: string, filepath: string): string | undefined;
11
+ /**
12
+ * Throws when a browser output is not inside `distDir`.
13
+ *
14
+ * @remarks
15
+ * The public URL and the gzip pass already skip a file outside `dist`. A write
16
+ * that appends a source-relative path uses the same check, so the file is not
17
+ * created there either.
18
+ */
19
+ export declare function assertBrowserOutputInsideDist(distDir: string, outputPath: string): void;
@@ -0,0 +1,30 @@
1
+ import path from 'node:path';
2
+ import { isPathInside } from '../utils/path-containment.js';
3
+ /**
4
+ * Source-relative path of a file inside `srcDir`.
5
+ *
6
+ * @remarks
7
+ * `path.relative` from `srcDir` to a file outside it starts with `..`. Joining
8
+ * that onto `dist` writes the asset outside the build. Callers then emit the file
9
+ * in `dist/assets`: a bundled script under the bundler's `[name]-[hash]` name, and
10
+ * an unbundled script or stylesheet under a content hash.
11
+ */
12
+ export function sourceRelativeBrowserAssetPath(srcDir, filepath) {
13
+ if (!isPathInside(filepath, srcDir))
14
+ return undefined;
15
+ const relativePath = path.relative(srcDir, filepath);
16
+ return relativePath === '' ? undefined : relativePath;
17
+ }
18
+ /**
19
+ * Throws when a browser output is not inside `distDir`.
20
+ *
21
+ * @remarks
22
+ * The public URL and the gzip pass already skip a file outside `dist`. A write
23
+ * that appends a source-relative path uses the same check, so the file is not
24
+ * created there either.
25
+ */
26
+ export function assertBrowserOutputInsideDist(distDir, outputPath) {
27
+ if (!isPathInside(outputPath, distDir)) {
28
+ throw new Error(`Refusing to write ${outputPath} outside ${distDir}`);
29
+ }
30
+ }
@@ -9,14 +9,16 @@ export declare function recordHashedBrowserAsset(filePath: string): void;
9
9
  export declare function isHashedBrowserAsset(filePath: string): boolean;
10
10
  export declare function forgetHashedBrowserAsset(filePath: string): void;
11
11
  /**
12
- * Writes a production browser asset under a name derived from a hash of its
13
- * final bytes, and returns that path.
12
+ * Writes a browser asset under a name derived from a hash of its final bytes,
13
+ * and returns that path.
14
14
  *
15
15
  * @remarks
16
- * The same bytes always produce the same name, so an unchanged stylesheet keeps
17
- * its URL and a quality or source change gets a new URL. Development keeps
18
- * source-relative names so CSS HMR can refresh the same href. Vendor runtimes
19
- * keep their own stable names and must not go through this helper.
16
+ * The same bytes always produce the same name, so an unchanged file keeps its URL
17
+ * and a content change gets a new URL. Callers use it for production assets, and
18
+ * for a source file outside `srcDir` in development, because a source-relative
19
+ * path would leave `dist`. A file inside `srcDir` keeps its source-relative name
20
+ * in development so CSS HMR can refresh the same href. A vendor runtime inside
21
+ * `src` keeps its stable name and does not use this helper.
20
22
  */
21
23
  export declare function writeHashedBrowserAsset(options: {
22
24
  bytes: string | Buffer;
@@ -77,14 +77,16 @@ function normalizeExtension(extension) {
77
77
  return extension.startsWith('.') ? extension : `.${extension}`;
78
78
  }
79
79
  /**
80
- * Writes a production browser asset under a name derived from a hash of its
81
- * final bytes, and returns that path.
80
+ * Writes a browser asset under a name derived from a hash of its final bytes,
81
+ * and returns that path.
82
82
  *
83
83
  * @remarks
84
- * The same bytes always produce the same name, so an unchanged stylesheet keeps
85
- * its URL and a quality or source change gets a new URL. Development keeps
86
- * source-relative names so CSS HMR can refresh the same href. Vendor runtimes
87
- * keep their own stable names and must not go through this helper.
84
+ * The same bytes always produce the same name, so an unchanged file keeps its URL
85
+ * and a content change gets a new URL. Callers use it for production assets, and
86
+ * for a source file outside `srcDir` in development, because a source-relative
87
+ * path would leave `dist`. A file inside `srcDir` keeps its source-relative name
88
+ * in development so CSS HMR can refresh the same href. A vendor runtime inside
89
+ * `src` keeps its stable name and does not use this helper.
88
90
  */
89
91
  export function writeHashedBrowserAsset(options) {
90
92
  const buffer = typeof options.bytes === 'string' ? Buffer.from(options.bytes) : options.bytes;
@@ -1,9 +1,9 @@
1
- import { existsSync, realpathSync } from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  function tryRealpath(filePath) {
5
5
  try {
6
- return existsSync(filePath) ? realpathSync(filePath) : undefined;
6
+ return fileSystem.exists(filePath) ? fileSystem.realpath(filePath) : undefined;
7
7
  }
8
8
  catch {
9
9
  return undefined;
@@ -1,5 +1,5 @@
1
- import { realpathSync } from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { parseModuleSource } from '../cache/module-parse-cache.js';
4
4
  import { createCoreTransformPlugin, createMappedSourceTransformResult } from './mapped-source-transform.js';
5
5
  /**
@@ -13,7 +13,7 @@ import { createCoreTransformPlugin, createMappedSourceTransformResult } from './
13
13
  */
14
14
  export function realpathOfDirectory(dir) {
15
15
  try {
16
- return realpathSync(dir);
16
+ return fileSystem.realpath(dir);
17
17
  }
18
18
  catch {
19
19
  const parent = path.dirname(dir);
@@ -1,5 +1,5 @@
1
- import { readFileSync } from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { toPackageRootSpecifier } from '../../plugins/package-specifier.js';
4
4
  const appDeclaredPackageCache = new Map();
5
5
  const appWorkspacePackageCache = new Map();
@@ -12,7 +12,7 @@ function getDeclaredAppPackages(rootDir) {
12
12
  const packageJsonPath = path.resolve(rootDir, 'package.json');
13
13
  const declaredPackages = new Set();
14
14
  try {
15
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
15
+ const packageJson = JSON.parse(fileSystem.readFileSync(packageJsonPath));
16
16
  for (const field of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
17
17
  const entries = packageJson[field];
18
18
  if (!entries || typeof entries !== 'object') {
@@ -47,7 +47,7 @@ function getWorkspacePackages(rootDir) {
47
47
  const packageJsonPath = path.resolve(rootDir, 'package.json');
48
48
  const workspacePackages = new Set();
49
49
  try {
50
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
50
+ const packageJson = JSON.parse(fileSystem.readFileSync(packageJsonPath));
51
51
  for (const field of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
52
52
  const entries = packageJson[field];
53
53
  if (!entries || typeof entries !== 'object') {
@@ -10,8 +10,8 @@
10
10
  * @module
11
11
  */
12
12
  import { builtinModules, createRequire } from 'node:module';
13
- import { readFileSync } from 'node:fs';
14
13
  import path from 'node:path';
14
+ import { fileSystem } from '@ecopages/file-system';
15
15
  import { fileURLToPath } from 'node:url';
16
16
  import { stripVTControlCharacters } from 'node:util';
17
17
  import { recordBuildEntryOutput, resolveBuildEntryPath } from '../build-graph.js';
@@ -43,10 +43,10 @@ function getCorePackageNames() {
43
43
  if (corePackageNames) {
44
44
  return corePackageNames;
45
45
  }
46
- const packageJsonPath = new URL('../../../package.json', import.meta.url);
46
+ const packageJsonPath = fileURLToPath(new URL('../../../package.json', import.meta.url));
47
47
  corePackageNames = new Set();
48
48
  try {
49
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
49
+ const packageJson = JSON.parse(fileSystem.readFileSync(packageJsonPath));
50
50
  for (const field of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
51
51
  const entries = packageJson[field];
52
52
  if (!entries || typeof entries !== 'object') {
@@ -20,8 +20,8 @@
20
20
  * and continue to declare stylesheets in `dependencies.stylesheets`
21
21
  * — the shim is intentionally inert for those flows.
22
22
  */
23
- import { existsSync, readFileSync } from 'node:fs';
24
23
  import path from 'node:path';
24
+ import { fileSystem } from '@ecopages/file-system';
25
25
  import { id as idFilter, include } from 'rolldown/filter';
26
26
  const CSS_PATH = /\.css$/u;
27
27
  const CSS_QUERY = '?ecopages-css-shim';
@@ -41,13 +41,13 @@ export function createServerSideCssShimPlugin() {
41
41
  filter: [include(idFilter(CSS_PATH))],
42
42
  handler(source, importer) {
43
43
  const resolved = importer ? path.resolve(path.dirname(importer), source) : path.resolve(source);
44
- return existsSync(resolved) ? `${resolved}${CSS_QUERY}` : null;
44
+ return fileSystem.exists(resolved) ? `${resolved}${CSS_QUERY}` : null;
45
45
  },
46
46
  },
47
47
  load: {
48
48
  filter: [include(idFilter(CSS_SHIM_ID))],
49
49
  handler(id) {
50
- readFileSync(stripShimQuery(id), 'utf-8');
50
+ fileSystem.readFileSync(stripShimQuery(id));
51
51
  return {
52
52
  code: 'export default "";',
53
53
  moduleType: 'js',
@@ -1,12 +1,11 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { mkdtempSync, renameSync } from 'node:fs';
3
2
  import path from 'node:path';
4
3
  import { fileSystem } from '@ecopages/file-system';
5
4
  /** Creates a sibling staging directory so publication stays on one filesystem. */
6
5
  export function createServerBundleStagingDirectory(serverOutdir) {
7
6
  const parentDir = path.dirname(serverOutdir);
8
7
  fileSystem.ensureDir(parentDir);
9
- return mkdtempSync(path.join(parentDir, `.${path.basename(serverOutdir)}.staging-`));
8
+ return fileSystem.mkdtemp(path.join(parentDir, `.${path.basename(serverOutdir)}.staging-`));
10
9
  }
11
10
  /**
12
11
  * Publishes a complete server bundle generation without exposing mixed artifacts.
@@ -20,12 +19,12 @@ export function publishServerBundleDirectory(stagingDir, serverOutdir) {
20
19
  const hadPublishedBundle = fileSystem.exists(serverOutdir);
21
20
  try {
22
21
  if (hadPublishedBundle)
23
- renameSync(serverOutdir, backupDir);
24
- renameSync(stagingDir, serverOutdir);
22
+ fileSystem.rename(serverOutdir, backupDir);
23
+ fileSystem.rename(stagingDir, serverOutdir);
25
24
  }
26
25
  catch (error) {
27
26
  if (hadPublishedBundle && !fileSystem.exists(serverOutdir) && fileSystem.exists(backupDir)) {
28
- renameSync(backupDir, serverOutdir);
27
+ fileSystem.rename(backupDir, serverOutdir);
29
28
  }
30
29
  throw error;
31
30
  }
@@ -1,4 +1,3 @@
1
- import { realpathSync } from 'node:fs';
2
1
  import path from 'node:path';
3
2
  import { fileSystem } from '@ecopages/file-system';
4
3
  import { rolldown } from 'rolldown';
@@ -27,9 +26,9 @@ function toProjectPath(id, realRoot, root) {
27
26
  */
28
27
  export async function collectConfigModuleFiles(configFilePath, rootDir) {
29
28
  const root = path.resolve(rootDir);
30
- const realRoot = fileSystem.exists(root) ? realpathSync(root) : root;
29
+ const realRoot = fileSystem.exists(root) ? fileSystem.realpath(root) : root;
31
30
  const configFile = path.resolve(configFilePath);
32
- const realConfigFile = fileSystem.exists(configFile) ? realpathSync(configFile) : configFile;
31
+ const realConfigFile = fileSystem.exists(configFile) ? fileSystem.realpath(configFile) : configFile;
33
32
  const moduleFiles = new Set([configFile]);
34
33
  try {
35
34
  const bundle = await rolldown({
@@ -1,5 +1,3 @@
1
- import { mkdirSync, statSync, writeFileSync } from 'node:fs';
2
- import path from 'node:path';
3
1
  import { fileSystem } from '@ecopages/file-system';
4
2
  import { resolveBuildParallelism } from '../build/build-parallelism.js';
5
3
  import { getProcessRuntime } from '../utils/runtime.js';
@@ -133,7 +131,7 @@ class StartupTrace {
133
131
  for (const output of outputs) {
134
132
  try {
135
133
  if (fileSystem.exists(output.path)) {
136
- this.firstRequestClientBytes += statSync(output.path).size;
134
+ this.firstRequestClientBytes += fileSystem.stat(output.path).size;
137
135
  }
138
136
  }
139
137
  catch {
@@ -210,8 +208,7 @@ class StartupTrace {
210
208
  return;
211
209
  }
212
210
  const report = this.createReport();
213
- mkdirSync(path.dirname(outputPath), { recursive: true });
214
- writeFileSync(outputPath, JSON.stringify(report, null, 2), 'utf-8');
211
+ fileSystem.write(outputPath, JSON.stringify(report, null, 2));
215
212
  }
216
213
  createReport() {
217
214
  const phases = {};
@@ -1,5 +1,4 @@
1
1
  import { contentHash } from '../utils/content-hash.js';
2
- import { readdirSync, realpathSync } from 'node:fs';
3
2
  import { getBuildEntryOutput } from '../build/build-graph.js';
4
3
  import { assertBuildSucceeded } from '../build/build-log.js';
5
4
  import { createRequire } from 'node:module';
@@ -200,7 +199,9 @@ export function scanModuleScript(appConfig, script) {
200
199
  function listHtmlFiles(appConfig) {
201
200
  const { pagesDir, htmlTemplatePath } = appConfig.absolutePaths;
202
201
  const pages = fileSystem.exists(pagesDir)
203
- ? readdirSync(pagesDir, { recursive: true, encoding: 'utf8' })
202
+ ? fileSystem
203
+ .readdir(pagesDir, { recursive: true })
204
+ .map((entry) => entry.name)
204
205
  .filter((name) => name.endsWith('.html'))
205
206
  .map((name) => path.join(pagesDir, name))
206
207
  .sort()
@@ -287,7 +288,7 @@ async function buildModuleScripts(appConfig, referencedScripts) {
287
288
  for (const script of scripts) {
288
289
  const output = getBuildEntryOutput(result, script, appConfig.rootDir);
289
290
  if (output)
290
- urls.set(realpathSync(script), `/${path.relative(distDir, output).split(path.sep).join('/')}`);
291
+ urls.set(fileSystem.realpath(script), `/${path.relative(distDir, output).split(path.sep).join('/')}`);
291
292
  }
292
293
  return urls;
293
294
  }
@@ -1,4 +1,3 @@
1
- import { realpathSync } from 'node:fs';
2
1
  import path from 'node:path';
3
2
  import { fileSystem } from '@ecopages/file-system';
4
3
  import { AssetFactory } from '../assets/asset-processing-service/asset.factory.js';
@@ -237,7 +236,7 @@ export class HtmlPageRenderer extends StringMarkupRenderer {
237
236
  if (asset.kind === 'module-script') {
238
237
  const hmr = this.assetProcessingService.getHmrManager()?.isEnabled() === true;
239
238
  if (!hmr) {
240
- const url = (await getHtmlPageModuleScriptUrls(this.appConfig)).get(realpathSync(asset.filepath));
239
+ const url = (await getHtmlPageModuleScriptUrls(this.appConfig)).get(fileSystem.realpath(asset.filepath));
241
240
  if (url !== undefined)
242
241
  return url;
243
242
  }
@@ -265,7 +264,7 @@ export class HtmlPageRenderer extends StringMarkupRenderer {
265
264
  const found = scanModuleScript(this.appConfig, script).stylesheetImport;
266
265
  if (!found)
267
266
  return;
268
- const real = (target) => (fileSystem.exists(target) ? realpathSync(target) : target);
267
+ const real = (target) => (fileSystem.exists(target) ? fileSystem.realpath(target) : target);
269
268
  const rootDir = real(this.appConfig.rootDir);
270
269
  const show = (target) => path.isAbsolute(target) ? path.relative(rootDir, real(target)).split(path.sep).join('/') : target;
271
270
  const stylesheet = real(found.stylesheet);
@@ -1,5 +1,5 @@
1
1
  import path from 'node:path';
2
- import { existsSync, readFileSync, realpathSync } from 'node:fs';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { parseModuleSource } from '../cache/module-parse-cache.js';
4
4
  import { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix, resolveProjectModulePath, } from './tsconfig-import-resolver.js';
5
5
  function node(value) {
@@ -89,7 +89,7 @@ function indexModuleExports(file, cache) {
89
89
  const cached = cache.get(file);
90
90
  if (cached)
91
91
  return cached;
92
- const source = readFileSync(file, 'utf8');
92
+ const source = fileSystem.readFileSync(file);
93
93
  const parsed = parseModuleSource(file, source, { sourceType: 'module' });
94
94
  const body = nodes(parsed.program.body);
95
95
  const { declared, factories } = collectDeclaredFactoryBindings(body);
@@ -155,7 +155,7 @@ function resolveStylesheetImportPath(source, ownerFile, projectRoot, pathPrefixe
155
155
  }
156
156
  if (isRelative) {
157
157
  const candidate = path.resolve(path.dirname(ownerFile), source);
158
- return existsSync(candidate) ? realpathSync(candidate) : undefined;
158
+ return fileSystem.exists(candidate) ? fileSystem.realpath(candidate) : undefined;
159
159
  }
160
160
  return resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
161
161
  }
@@ -171,7 +171,7 @@ function tryRecordSideEffectStylesheetImport(statement, source, ownerFile, proje
171
171
  }
172
172
  return false;
173
173
  }
174
- if (!existsSync(resolved)) {
174
+ if (!fileSystem.exists(resolved)) {
175
175
  throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(source)} from ${ownerFile}`);
176
176
  }
177
177
  result.stylesheets.push(resolved);
@@ -1,4 +1,4 @@
1
- import { readFileSync } from 'node:fs';
1
+ import { fileSystem } from '@ecopages/file-system';
2
2
  import { escapeRegExp } from '../utils/regex-escaping.js';
3
3
  import { createJsxImportSourcePragma, filterJsxSourceExtensions } from './jsx-import-source.utils.js';
4
4
  /**
@@ -38,7 +38,7 @@ export function createForeignJsxOverridePlugin(options) {
38
38
  if (excludedExtensions.some((extension) => args.path.endsWith(extension))) {
39
39
  return undefined;
40
40
  }
41
- const source = readFileSync(args.path, 'utf-8');
41
+ const source = fileSystem.readFileSync(args.path);
42
42
  const loader = args.path.endsWith('.jsx') ? 'jsx' : 'tsx';
43
43
  if (source.includes('@jsxImportSource')) {
44
44
  return undefined;
@@ -1,5 +1,5 @@
1
- import { existsSync, readFileSync, realpathSync } from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { ResolverFactory } from 'oxc-resolver';
4
4
  import { toPackageRootSpecifier } from './package-specifier.js';
5
5
  const RESOLVABLE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.mdx'];
@@ -10,10 +10,10 @@ function stripJsonComments(source) {
10
10
  }
11
11
  function findTsconfigPath(projectRoot) {
12
12
  const candidate = path.join(projectRoot, 'tsconfig.json');
13
- return existsSync(candidate) ? candidate : undefined;
13
+ return fileSystem.exists(candidate) ? candidate : undefined;
14
14
  }
15
15
  function readJsonFile(filePath) {
16
- const source = readFileSync(filePath, 'utf8');
16
+ const source = fileSystem.readFileSync(filePath);
17
17
  try {
18
18
  return JSON.parse(source);
19
19
  }
@@ -173,7 +173,7 @@ export function resolveBarePackageBrowserEntry(projectRoot, specifier) {
173
173
  return undefined;
174
174
  }
175
175
  try {
176
- return { path: realpathSync(result.path), packageJsonPath: result.packageJsonPath };
176
+ return { path: fileSystem.realpath(result.path), packageJsonPath: result.packageJsonPath };
177
177
  }
178
178
  catch {
179
179
  return { path: result.path, packageJsonPath: result.packageJsonPath };
@@ -183,7 +183,7 @@ function resolveAliasedBarrelTarget(resolvedPath) {
183
183
  if (!path.basename(resolvedPath).startsWith('index.')) {
184
184
  return resolvedPath;
185
185
  }
186
- const source = readFileSync(resolvedPath, 'utf8').trim();
186
+ const source = fileSystem.readFileSync(resolvedPath).trim();
187
187
  const match = source.match(/^export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?$/);
188
188
  if (!match?.[1]?.startsWith('.')) {
189
189
  return resolvedPath;
@@ -192,13 +192,13 @@ function resolveAliasedBarrelTarget(resolvedPath) {
192
192
  const targetBase = path.resolve(targetDir, match[1]);
193
193
  for (const extension of RESOLVABLE_EXTENSIONS) {
194
194
  const candidate = `${targetBase}${extension}`;
195
- if (existsSync(candidate)) {
195
+ if (fileSystem.exists(candidate)) {
196
196
  return candidate;
197
197
  }
198
198
  }
199
199
  for (const extension of RESOLVABLE_EXTENSIONS) {
200
200
  const candidate = path.join(targetBase, `index${extension}`);
201
- if (existsSync(candidate)) {
201
+ if (fileSystem.exists(candidate)) {
202
202
  return candidate;
203
203
  }
204
204
  }
@@ -216,18 +216,18 @@ export function resolveRelativeModulePath(fromFile, specifier) {
216
216
  return undefined;
217
217
  }
218
218
  const targetBase = path.resolve(path.dirname(fromFile), specifier);
219
- if (existsSync(targetBase)) {
219
+ if (fileSystem.exists(targetBase)) {
220
220
  return path.resolve(targetBase);
221
221
  }
222
222
  for (const candidateExtension of RESOLVABLE_EXTENSIONS) {
223
223
  const candidate = `${targetBase}${candidateExtension}`;
224
- if (existsSync(candidate)) {
224
+ if (fileSystem.exists(candidate)) {
225
225
  return path.resolve(candidate);
226
226
  }
227
227
  }
228
228
  for (const candidateExtension of RESOLVABLE_EXTENSIONS) {
229
229
  const candidate = path.join(targetBase, `index${candidateExtension}`);
230
- if (existsSync(candidate)) {
230
+ if (fileSystem.exists(candidate)) {
231
231
  return path.resolve(candidate);
232
232
  }
233
233
  }
@@ -248,8 +248,8 @@ export function resolveProjectModulePath(projectRoot, fromFile, specifier, optio
248
248
  const result = resolver.sync(path.dirname(fromFile), specifier);
249
249
  if (result.path) {
250
250
  return options?.preserveBarrel
251
- ? realpathSync(result.path)
252
- : resolveAliasedBarrelTarget(realpathSync(result.path));
251
+ ? fileSystem.realpath(result.path)
252
+ : resolveAliasedBarrelTarget(fileSystem.realpath(result.path));
253
253
  }
254
254
  }
255
255
  if (isRelative) {
@@ -1,5 +1,4 @@
1
1
  import type { GroupedGraphScope } from './route-instance-key.js';
2
- import type { EcoPagesAppConfig } from '../../../config/internal-types.js';
3
2
  import type { PageBrowserGraphContribution, PageBrowserGraphResult } from '../../../types/contracts.js';
4
3
  import type { ProcessedAsset } from '../../../assets/asset-processing-service/assets.types.js';
5
4
  import { BuildInputDependencyIndex } from '../../../build/cache/build-input-dependency-index.js';
@@ -32,13 +31,6 @@ type GroupedGraphRecord = {
32
31
  dependencyPaths: ReadonlySet<string>;
33
32
  generation: number;
34
33
  };
35
- export type AffectedGraphIdentity = {
36
- integrationName: string;
37
- routeFile: string;
38
- dependencyInstanceKey: string;
39
- policy: GraphPolicy;
40
- entryFingerprint: string;
41
- };
42
34
  /**
43
35
  * Session-local Page Browser Graph cache with precise dependency invalidation.
44
36
  */
@@ -63,7 +55,6 @@ export declare class SessionPageBrowserGraphCache {
63
55
  getBuildCount(): number;
64
56
  getGraphByRoute(integrationName: string, routeFile: string, policy: GraphPolicy, dependencyInstanceKey?: string): PageBrowserGraphResult | undefined;
65
57
  getDependencyPathsByRoute(integrationName: string, routeFile: string, policy: GraphPolicy, dependencyInstanceKey?: string): ReadonlySet<string> | undefined;
66
- getAffectedGraphIdentities(filePath: string): AffectedGraphIdentity[];
67
58
  resolveGraph(key: GraphKey, provisionalDependencyPaths: ReadonlySet<string>, build: () => Promise<GraphBuildResult | undefined>, options?: {
68
59
  reuseCachedResult?: boolean;
69
60
  }): Promise<PageBrowserGraphResult | undefined>;
@@ -89,14 +80,6 @@ export declare class SessionPageBrowserGraphCache {
89
80
  private clearInFlightBuild;
90
81
  private releaseInFlightDependencyPaths;
91
82
  }
92
- /**
93
- * Invalidates graph records that depend on the changed file path.
94
- */
95
- export declare function invalidatePageBrowserGraphSession(appConfig: EcoPagesAppConfig, filePath: string): void;
96
- /**
97
- * Returns graph identities affected by a source file change.
98
- */
99
- export declare function getAffectedPageBrowserGraphIdentities(appConfig: EcoPagesAppConfig, filePath: string): AffectedGraphIdentity[];
100
83
  /**
101
84
  * Builds a stable fingerprint from declared browser-entry dependencies and assets.
102
85
  */
@@ -3,7 +3,6 @@ import { serializeGroupedGraphCacheKey } from './route-instance-key.js';
3
3
  import { contentHash } from '../../../utils/content-hash.js';
4
4
  import { appLogger } from '../../../global/app-logger.js';
5
5
  import { BuildInputDependencyIndex, } from '../../../build/cache/build-input-dependency-index.js';
6
- import { requireAppRuntime } from '../../../utils/app-runtime.js';
7
6
  function graphBinding(key) {
8
7
  return { consumer: 'page-browser-graph', key };
9
8
  }
@@ -106,16 +105,6 @@ export class SessionPageBrowserGraphCache {
106
105
  }
107
106
  return undefined;
108
107
  }
109
- getAffectedGraphIdentities(filePath) {
110
- const identities = [];
111
- for (const serializedKey of this.graphKeysFor(filePath)) {
112
- const identity = parseSerializedGraphKey(serializedKey);
113
- if (identity) {
114
- identities.push(identity);
115
- }
116
- }
117
- return identities;
118
- }
119
108
  resolveGraph(key, provisionalDependencyPaths, build, options = {}) {
120
109
  if (options.reuseCachedResult === false) {
121
110
  return this.buildGraphWithoutCaching(build);
@@ -396,18 +385,6 @@ export class SessionPageBrowserGraphCache {
396
385
  this.inFlightDependencyPaths.delete(serializedKey);
397
386
  }
398
387
  }
399
- /**
400
- * Invalidates graph records that depend on the changed file path.
401
- */
402
- export function invalidatePageBrowserGraphSession(appConfig, filePath) {
403
- requireAppRuntime(appConfig).pageBrowserGraphSession.invalidateByFilePath(filePath);
404
- }
405
- /**
406
- * Returns graph identities affected by a source file change.
407
- */
408
- export function getAffectedPageBrowserGraphIdentities(appConfig, filePath) {
409
- return requireAppRuntime(appConfig).pageBrowserGraphSession.getAffectedGraphIdentities(filePath);
410
- }
411
388
  /**
412
389
  * Builds a stable fingerprint from declared browser-entry dependencies and assets.
413
390
  */
@@ -1,4 +1,4 @@
1
- import { readFileSync } from 'node:fs';
1
+ import { fileSystem } from '@ecopages/file-system';
2
2
  import { isContentServerVirtualModule } from '../../build/contracts/content-virtual-modules.js';
3
3
  import { parseModuleSource } from '../../cache/module-parse-cache.js';
4
4
  import { isProductionRuntime } from '../../utils/runtime.js';
@@ -70,7 +70,7 @@ const productionVirtualImportsByFile = new Map();
70
70
  function readEcopagesVirtualImports(file) {
71
71
  let source;
72
72
  try {
73
- source = readFileSync(file, 'utf-8');
73
+ source = fileSystem.readFileSync(file);
74
74
  }
75
75
  catch {
76
76
  return [];
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync } from 'node:fs';
1
+ import { fileSystem } from '@ecopages/file-system';
2
2
  import { AssetFactory } from '../../assets/asset-processing-service/index.js';
3
3
  import { contentHash } from '../../utils/content-hash.js';
4
4
  import { isProductionRuntime } from '../../utils/runtime.js';
@@ -74,10 +74,10 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
74
74
  if (dependency.source === 'content') {
75
75
  return isSafeBundledStylesheetContent(dependency.content);
76
76
  }
77
- if (!existsSync(dependency.filepath)) {
77
+ if (!fileSystem.exists(dependency.filepath)) {
78
78
  return false;
79
79
  }
80
- return isSafeBundledStylesheetContent(readFileSync(dependency.filepath, 'utf8'));
80
+ return isSafeBundledStylesheetContent(fileSystem.readFileSync(dependency.filepath));
81
81
  })
82
82
  .filter(isBundleableFileStylesheetAsset);
83
83
  const bundleableScripts = dependencies
@@ -93,7 +93,7 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
93
93
  !dependency.packageRole &&
94
94
  dependency.bundle !== false &&
95
95
  hasOnlyExpectedAttributes(dependency.attributes, { type: 'module', defer: '' }) &&
96
- existsSync(dependency.filepath));
96
+ fileSystem.exists(dependency.filepath));
97
97
  })
98
98
  .filter(isBundleableFileScriptAsset);
99
99
  const eligibleStyles = new Set(bundleableStyles);
@@ -106,7 +106,7 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
106
106
  const bundledScriptMembers = new Set();
107
107
  for (const run of collectContiguousEligibleRuns(dependencies, isEligibleStyle)) {
108
108
  const bundledStylesheet = AssetFactory.createContentStylesheet({
109
- content: run.assets.map((dependency) => readFileSync(dependency.filepath, 'utf8')).join('\n'),
109
+ content: run.assets.map((dependency) => fileSystem.readFileSync(dependency.filepath)).join('\n'),
110
110
  position: 'head',
111
111
  attributes: { rel: 'stylesheet' },
112
112
  packageRole: 'page-style',