@ecopages/core 0.10.1 → 0.10.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/core",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "Core package for Ecopages",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@clack/prompts": "^1.7.0",
27
- "@ecopages/file-system": "0.10.1",
27
+ "@ecopages/file-system": "0.10.3",
28
28
  "@ecopages/logger": "^0.2.3",
29
29
  "@ecopages/scripts-injector": "^0.1.5",
30
30
  "@jridgewell/remapping": "^2.3.5",
@@ -37,7 +37,7 @@
37
37
  "ws": "^8.20.1"
38
38
  },
39
39
  "peerDependencies": {
40
- "@ecopages/dev-toolbar": "0.10.1"
40
+ "@ecopages/dev-toolbar": "0.10.3"
41
41
  },
42
42
  "peerDependenciesMeta": {
43
43
  "@ecopages/dev-toolbar": {
@@ -20,7 +20,6 @@ import { CLIENT_OUTPUT_DIR, resolveEntryFile, SERVER_BUNDLE_FILENAME } from '../
20
20
  import { createServerBundleLoaderSource, SERVER_BUNDLE_IMPLEMENTATION_FILENAME, } from '../../../utils/server-bundle-context.js';
21
21
  import { copyRuntimePublicDirIfChanged } from './copy-runtime-public-dir.js';
22
22
  import { readEndpointHandlers } from '../http/endpoint-route-handler.js';
23
- import { warnAboutUnattachedScripts } from './unattached-scripts.js';
24
23
  import { emitProductionServerModules, shouldBuildPagesUnifiedGraph, } from '../../../build/cache/pages-unified-graph-build.js';
25
24
  /**
26
25
  * Handles static site generation.
@@ -196,7 +195,6 @@ export class ServerStaticBuilder {
196
195
  router: dependencies.router,
197
196
  staticRoutes: dependencies.staticRoutes,
198
197
  errorPageLoaders: dependencies.errorPageLoaders,
199
- onServerSources: (sources) => warnAboutUnattachedScripts(this.appConfig, sources),
200
198
  });
201
199
  }
202
200
  writeProductionRouteList(this.appConfig, dependencies.router.templateRoutes);
@@ -37,8 +37,6 @@ export declare function emitProductionServerModules(options: {
37
37
  staticRoutes?: readonly StaticRoute[];
38
38
  errorPageLoaders?: ErrorPageLoaders;
39
39
  outdir?: string;
40
- /** Receives the project and package source files the server build bundled, after it succeeds. */
41
- onServerSources?: (sources: readonly string[]) => void | Promise<void>;
42
40
  }): Promise<ProductionServerModulesManifest>;
43
41
  /**
44
42
  * Imports the emitted module for `filePath` from the production server-modules map.
@@ -93,7 +93,7 @@ export async function importEmittedServerModule(appConfig, filePath, outputPath)
93
93
  }
94
94
  async function emitRolldownServerModules(appConfig, entryPaths, outdir) {
95
95
  if (entryPaths.length === 0) {
96
- return { modules: {}, sources: [] };
96
+ return {};
97
97
  }
98
98
  const entryRecord = {};
99
99
  for (const entryPath of entryPaths) {
@@ -123,8 +123,7 @@ async function emitRolldownServerModules(appConfig, entryPaths, outdir) {
123
123
  modules[toRootRelativePath(appConfig.rootDir, chunk.facadeModuleId)] ??= toRootRelativePath(outdir, outputPath);
124
124
  }
125
125
  }
126
- const sources = [...new Set(Object.values(buildResult.dependencyGraph.entrypoints).flat())];
127
- return { modules, sources };
126
+ return modules;
128
127
  }
129
128
  function assignProductionServerModules(appConfig, manifest) {
130
129
  const runtime = requireAppRuntime(appConfig);
@@ -151,8 +150,7 @@ export async function emitProductionServerModules(options) {
151
150
  });
152
151
  const rolldownEntries = collected.filter((entryPath) => isRolldownServerModuleEntry(entryPath, appConfig));
153
152
  const htmlEntries = collected.filter((entryPath) => !isRolldownServerModuleEntry(entryPath, appConfig));
154
- const { modules, sources } = await emitRolldownServerModules(appConfig, uniqueEntryPaths(rolldownEntries), outdir);
155
- await options.onServerSources?.(sources);
153
+ const modules = await emitRolldownServerModules(appConfig, uniqueEntryPaths(rolldownEntries), outdir);
156
154
  for (const htmlEntry of uniqueEntryPaths(htmlEntries)) {
157
155
  const emitted = await emitCompiledPageModule(appConfig, htmlEntry, outdir);
158
156
  modules[emitted.sourceKey] = emitted.relativePath;
@@ -499,13 +499,10 @@ async function buildRolldownInputOptions(options, contextRoot, outdir, external,
499
499
  transform: buildRolldownTransformOptions(options),
500
500
  resolve: options.conditions ? { conditionNames: options.conditions } : undefined,
501
501
  treeshake: typeof options.treeshaking === 'boolean' ? options.treeshaking : true,
502
- ...(isEcopagesEnvEnabled('ECOPAGES_PROFILE_BUILD')
503
- ? {}
504
- : {
505
- checks: {
506
- pluginTimings: false,
507
- },
508
- }),
502
+ checks: {
503
+ moduleLevelDirective: false,
504
+ ...(isEcopagesEnvEnabled('ECOPAGES_PROFILE_BUILD') ? {} : { pluginTimings: false }),
505
+ },
509
506
  experimental: {
510
507
  nativeMagicString: true,
511
508
  },
@@ -1,22 +1,9 @@
1
1
  import type { RolldownPlugin } from 'rolldown';
2
- declare const PARSER_LANGUAGES: readonly ["js", "jsx", "ts", "tsx"];
3
2
  /** A script a declaration lists with a literal `src`. */
4
3
  export type DeclaredScript = {
5
4
  src: string;
6
5
  ssr: boolean;
7
6
  };
8
- /**
9
- * Lists the scripts a module's declarations name with a literal `src`, relative to that module.
10
- *
11
- * @remarks
12
- * Finds each string or `{ src }` entry of a literal `scripts: [...]` array, and any `{ src, ssr: true }` object.
13
- * A `src` that is computed at runtime is not found.
14
- */
15
- export declare function findDeclaredScripts(file: string, code: string, lang: (typeof PARSER_LANGUAGES)[number]): DeclaredScript[];
16
- /**
17
- * The parser language for a file name, or `undefined` when it is not a script module.
18
- */
19
- export declare function scriptModuleLanguage(file: string): (typeof PARSER_LANGUAGES)[number] | undefined;
20
7
  /**
21
8
  * Emits each `ssr: true` script a declaration lists as an entry of the server build that bundles the declaration.
22
9
  *
@@ -28,4 +15,3 @@ export declare function scriptModuleLanguage(file: string): (typeof PARSER_LANGU
28
15
  * script path computed at runtime is not.
29
16
  */
30
17
  export declare function createSsrScriptEntriesPlugin(): RolldownPlugin;
31
- export {};
@@ -61,7 +61,7 @@ function collectDeclaredScripts(value, scripts) {
61
61
  * Finds each string or `{ src }` entry of a literal `scripts: [...]` array, and any `{ src, ssr: true }` object.
62
62
  * A `src` that is computed at runtime is not found.
63
63
  */
64
- export function findDeclaredScripts(file, code, lang) {
64
+ function findDeclaredScripts(file, code, lang) {
65
65
  const scripts = [];
66
66
  collectDeclaredScripts(parseModuleSource(file, code, { sourceType: 'module', lang }).program, scripts);
67
67
  return scripts;
@@ -69,7 +69,7 @@ export function findDeclaredScripts(file, code, lang) {
69
69
  /**
70
70
  * The parser language for a file name, or `undefined` when it is not a script module.
71
71
  */
72
- export function scriptModuleLanguage(file) {
72
+ function scriptModuleLanguage(file) {
73
73
  return PARSER_LANGUAGES.find((language) => file.endsWith(`.${language}`));
74
74
  }
75
75
  /**
@@ -1,17 +0,0 @@
1
- import type { EcoPagesAppConfig } from '../../../config/internal-types.js';
2
- /**
3
- * Lists the `.script` files under `srcDir` that nothing attaches to a page.
4
- *
5
- * @remarks
6
- * A script is attached when a literal `dependencies.scripts` entry in a module of the server build names it, an
7
- * HTML Page or the Html shell loads it with `<script src>`, or an attached script imports it. A module of the
8
- * server build that imports a script also counts, since that script is then part of the build. A `src` computed at
9
- * runtime is not found, and neither is a declaration in an MDX file, so such a script is listed here.
10
- *
11
- * @param serverModules Source files of the server build, whose declarations are read.
12
- */
13
- export declare function findUnattachedScripts(appConfig: EcoPagesAppConfig, serverModules: readonly string[]): Promise<string[]>;
14
- /**
15
- * Warns once per `.script` file that {@link findUnattachedScripts} lists.
16
- */
17
- export declare function warnAboutUnattachedScripts(appConfig: EcoPagesAppConfig, serverModules: readonly string[]): Promise<void>;
@@ -1,57 +0,0 @@
1
- import { appLogger } from '../../../global/app-logger.js';
2
- import { fileSystem } from '@ecopages/file-system';
3
- import { path } from '@ecopages/file-system/path';
4
- import { collectHtmlPageModuleScriptBuildInputs, scanModuleScript, } from '../../../html-pages/html-page-module-scripts.js';
5
- import { FILE_ROLE_SUFFIXES } from '../../../utils/file-roles.js';
6
- import { findDeclaredScripts, scriptModuleLanguage } from '../../../build/rolldown/ssr-script-entries-plugin.js';
7
- const SCRIPT_SUFFIXES = FILE_ROLE_SUFFIXES.filter((suffix) => suffix.startsWith('.script.'));
8
- /**
9
- * Lists the `.script` files under `srcDir` that nothing attaches to a page.
10
- *
11
- * @remarks
12
- * A script is attached when a literal `dependencies.scripts` entry in a module of the server build names it, an
13
- * HTML Page or the Html shell loads it with `<script src>`, or an attached script imports it. A module of the
14
- * server build that imports a script also counts, since that script is then part of the build. A `src` computed at
15
- * runtime is not found, and neither is a declaration in an MDX file, so such a script is listed here.
16
- *
17
- * @param serverModules Source files of the server build, whose declarations are read.
18
- */
19
- export async function findUnattachedScripts(appConfig, serverModules) {
20
- const { srcDir } = appConfig.absolutePaths;
21
- const patterns = SCRIPT_SUFFIXES.map((suffix) => `**/*${suffix}`);
22
- const scripts = (await fileSystem.glob(patterns, { cwd: srcDir })).map((file) => path.resolve(srcDir, file));
23
- if (scripts.length === 0)
24
- return [];
25
- const attached = new Set();
26
- const roots = new Set();
27
- for (const file of serverModules) {
28
- attached.add(path.resolve(file));
29
- const lang = scriptModuleLanguage(file);
30
- if (!lang || !fileSystem.exists(file))
31
- continue;
32
- const code = fileSystem.readFileSync(file).toString();
33
- if (!code.includes('scripts'))
34
- continue;
35
- for (const { src } of findDeclaredScripts(file, code, lang))
36
- roots.add(path.resolve(path.dirname(file), src));
37
- }
38
- const html = collectHtmlPageModuleScriptBuildInputs(appConfig);
39
- for (const script of html.scripts)
40
- roots.add(path.resolve(script));
41
- for (const file of html.files)
42
- attached.add(path.resolve(file));
43
- for (const root of roots) {
44
- attached.add(root);
45
- for (const file of scanModuleScript(appConfig, root).files)
46
- attached.add(file);
47
- }
48
- return scripts.filter((script) => !attached.has(script)).sort();
49
- }
50
- /**
51
- * Warns once per `.script` file that {@link findUnattachedScripts} lists.
52
- */
53
- export async function warnAboutUnattachedScripts(appConfig, serverModules) {
54
- for (const script of await findUnattachedScripts(appConfig, serverModules)) {
55
- appLogger.warn(`${path.relative(appConfig.rootDir, script)} is a browser script, but no dependencies.scripts entry or HTML <script src> attaches it, so it ships nowhere. Check the declaration's path, or delete the file.`);
56
- }
57
- }