@webstir-io/webstir-frontend 0.1.40 → 0.1.41

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 (138) hide show
  1. package/README.md +124 -60
  2. package/dist/assets/imageOptimizer.js +10 -15
  3. package/dist/assets/precompression.js +1 -1
  4. package/dist/builders/contentBuilder.js +102 -90
  5. package/dist/builders/cssBuilder.js +25 -19
  6. package/dist/builders/htmlBuilder.js +57 -42
  7. package/dist/builders/index.js +1 -1
  8. package/dist/builders/jsBuilder.js +219 -76
  9. package/dist/builders/staticAssetsBuilder.js +27 -9
  10. package/dist/builders/types.d.ts +1 -0
  11. package/dist/cli.d.ts +1 -1
  12. package/dist/cli.js +6 -30
  13. package/dist/config/manifest.js +7 -6
  14. package/dist/config/paths.js +2 -2
  15. package/dist/config/schema.d.ts +8 -0
  16. package/dist/config/schema.js +7 -6
  17. package/dist/config/setup.js +1 -1
  18. package/dist/config/workspace.js +11 -9
  19. package/dist/core/constants.d.ts +1 -1
  20. package/dist/core/constants.js +5 -5
  21. package/dist/core/diagnostics.js +1 -1
  22. package/dist/core/pages.js +4 -4
  23. package/dist/hooks.js +3 -3
  24. package/dist/html/criticalCss.js +6 -3
  25. package/dist/html/htmlSecurity.d.ts +6 -1
  26. package/dist/html/htmlSecurity.js +28 -14
  27. package/dist/html/lazyLoad.js +1 -1
  28. package/dist/html/pageScaffold.js +1 -1
  29. package/dist/html/resourceHints.js +5 -2
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.js +2 -0
  32. package/dist/inspect.d.ts +2 -0
  33. package/dist/inspect.js +110 -0
  34. package/dist/modes/ssg/metadata.js +4 -4
  35. package/dist/modes/ssg/routing.js +2 -5
  36. package/dist/modes/ssg/seo.js +5 -5
  37. package/dist/modes/ssg/views.js +17 -11
  38. package/dist/operations.js +18 -10
  39. package/dist/pipeline.d.ts +1 -0
  40. package/dist/pipeline.js +6 -1
  41. package/dist/provider.js +28 -24
  42. package/dist/runtime/boundary.d.ts +28 -0
  43. package/dist/runtime/boundary.js +247 -0
  44. package/dist/runtime/index.d.ts +1 -0
  45. package/dist/runtime/index.js +1 -0
  46. package/dist/types.d.ts +52 -0
  47. package/dist/utils/fs.d.ts +11 -10
  48. package/dist/utils/fs.js +48 -20
  49. package/dist/utils/glob.d.ts +8 -0
  50. package/dist/utils/glob.js +21 -0
  51. package/dist/utils/hash.js +1 -2
  52. package/dist/utils/pagePaths.js +2 -2
  53. package/package.json +19 -14
  54. package/scripts/publish.sh +2 -94
  55. package/scripts/update-contract.sh +12 -10
  56. package/src/assets/assetManifest.ts +39 -29
  57. package/src/assets/imageOptimizer.ts +91 -82
  58. package/src/assets/precompression.ts +22 -16
  59. package/src/builders/contentBuilder.ts +1224 -1149
  60. package/src/builders/cssBuilder.ts +466 -417
  61. package/src/builders/htmlBuilder.ts +511 -448
  62. package/src/builders/index.ts +7 -7
  63. package/src/builders/jsBuilder.ts +538 -280
  64. package/src/builders/staticAssetsBuilder.ts +166 -135
  65. package/src/builders/types.ts +7 -6
  66. package/src/cli.ts +66 -90
  67. package/src/config/manifest.ts +16 -14
  68. package/src/config/paths.ts +5 -5
  69. package/src/config/schema.ts +38 -37
  70. package/src/config/setup.ts +7 -7
  71. package/src/config/workspace.ts +118 -116
  72. package/src/config/workspaceManifest.ts +14 -14
  73. package/src/core/constants.ts +62 -62
  74. package/src/core/diagnostics.ts +26 -26
  75. package/src/core/pages.ts +19 -19
  76. package/src/hooks.ts +128 -118
  77. package/src/html/criticalCss.ts +84 -77
  78. package/src/html/htmlSecurity.ts +107 -66
  79. package/src/html/lazyLoad.ts +22 -19
  80. package/src/html/pageScaffold.ts +37 -28
  81. package/src/html/resourceHints.ts +83 -74
  82. package/src/index.ts +2 -0
  83. package/src/inspect.ts +158 -0
  84. package/src/modes/ssg/metadata.ts +53 -51
  85. package/src/modes/ssg/routing.ts +177 -177
  86. package/src/modes/ssg/seo.ts +208 -200
  87. package/src/modes/ssg/validation.ts +31 -25
  88. package/src/modes/ssg/views.ts +257 -238
  89. package/src/operations.ts +105 -95
  90. package/src/pipeline.ts +81 -69
  91. package/src/provider.ts +184 -176
  92. package/src/runtime/boundary.ts +325 -0
  93. package/src/runtime/index.ts +1 -0
  94. package/src/types.ts +107 -48
  95. package/src/utils/changedFile.ts +22 -22
  96. package/src/utils/fs.ts +73 -26
  97. package/src/utils/glob.ts +38 -0
  98. package/src/utils/hash.ts +2 -4
  99. package/src/utils/pagePaths.ts +35 -23
  100. package/src/utils/pathMatch.ts +26 -23
  101. package/tests/add-page-defaults.test.js +44 -39
  102. package/tests/bundlerParity.test.js +252 -0
  103. package/tests/cli.contract.test.js +13 -0
  104. package/tests/content-pages.test.js +108 -13
  105. package/tests/css-app-imports.test.js +22 -11
  106. package/tests/css-page-imports.test.js +26 -13
  107. package/tests/diagnostics.test.js +39 -36
  108. package/tests/features.test.js +48 -43
  109. package/tests/hooks.test.js +58 -42
  110. package/tests/htmlSecurity.test.js +66 -0
  111. package/tests/inspect.test.js +148 -0
  112. package/tests/provider.integration.test.js +71 -20
  113. package/tests/runtime.test.js +493 -0
  114. package/tests/ssg-defaults.test.js +284 -177
  115. package/tests/ssg-guardrails.test.js +51 -51
  116. package/tsconfig.json +3 -10
  117. package/dist/watch/frontendFiles.d.ts +0 -3
  118. package/dist/watch/frontendFiles.js +0 -25
  119. package/dist/watch/hotUpdateTracker.d.ts +0 -51
  120. package/dist/watch/hotUpdateTracker.js +0 -205
  121. package/dist/watch/pipelineHelpers.d.ts +0 -26
  122. package/dist/watch/pipelineHelpers.js +0 -177
  123. package/dist/watch/types.d.ts +0 -27
  124. package/dist/watch/types.js +0 -1
  125. package/dist/watch/watchCoordinator.d.ts +0 -36
  126. package/dist/watch/watchCoordinator.js +0 -551
  127. package/dist/watch/watchDaemon.d.ts +0 -17
  128. package/dist/watch/watchDaemon.js +0 -127
  129. package/dist/watch/watchReporter.d.ts +0 -21
  130. package/dist/watch/watchReporter.js +0 -64
  131. package/scripts/smoke.mjs +0 -35
  132. package/src/watch/frontendFiles.ts +0 -32
  133. package/src/watch/hotUpdateTracker.ts +0 -285
  134. package/src/watch/pipelineHelpers.ts +0 -242
  135. package/src/watch/types.ts +0 -23
  136. package/src/watch/watchCoordinator.ts +0 -666
  137. package/src/watch/watchDaemon.ts +0 -144
  138. package/src/watch/watchReporter.ts +0 -98
package/src/operations.ts CHANGED
@@ -4,135 +4,145 @@ import { runPipeline } from './pipeline.js';
4
4
  import { createPageScaffold } from './html/pageScaffold.js';
5
5
  import { prepareWorkspaceConfig } from './config/setup.js';
6
6
  import {
7
- applySsgRouting,
8
- assertNoSsgRoutes,
9
- ensureSsgViewMetadataForPage,
10
- generateSsgViewData
7
+ applySsgRouting,
8
+ assertNoSsgRoutes,
9
+ ensureSsgViewMetadataForPage,
10
+ generateSsgViewData,
11
11
  } from './modes/ssg/index.js';
12
12
  import path from 'node:path';
13
13
  import { FOLDERS } from './core/constants.js';
14
14
  import { pathExists, readJson, remove } from './utils/fs.js';
15
15
 
16
16
  export async function runBuild(options: FrontendCommandOptions): Promise<void> {
17
- const config = await prepareWorkspaceConfig(options.workspaceRoot);
18
- const enable = await readWorkspaceEnableFlags(options.workspaceRoot);
19
-
20
- console.info('[webstir-frontend] Running build pipeline...');
21
- await runPipeline(config, 'build', { changedFile: options.changedFile, enable });
22
- console.info('[webstir-frontend] Build pipeline completed.');
17
+ const config = await prepareWorkspaceConfig(options.workspaceRoot);
18
+ const enable = await readWorkspaceEnableFlags(options.workspaceRoot);
19
+
20
+ console.info('[webstir-frontend] Running build pipeline...');
21
+ await runPipeline(config, 'build', {
22
+ changedFile: options.changedFile,
23
+ enable,
24
+ env: process.env,
25
+ });
26
+ console.info('[webstir-frontend] Build pipeline completed.');
23
27
  }
24
28
 
25
29
  export async function runPublish(options: FrontendCommandOptions): Promise<void> {
26
- const config = await prepareWorkspaceConfig(options.workspaceRoot);
27
- const enable = await readWorkspaceEnableFlags(options.workspaceRoot);
28
- const publishConfig = options.publishMode === 'ssg' ? applySsgPublishLayout(config) : config;
29
-
30
- const modeLabel = options.publishMode === 'ssg' ? 'SSG publish' : 'publish';
31
- console.info(`[webstir-frontend] Running ${modeLabel} pipeline...`);
32
-
33
- if (options.publishMode === 'ssg') {
34
- await assertNoSsgRoutes(config.paths.workspace);
35
- }
36
-
37
- await runPipeline(publishConfig, 'publish', { enable });
38
- if (options.publishMode === 'ssg') {
39
- await generateSsgViewData(publishConfig);
40
- await applySsgRouting(publishConfig);
41
- await removeLegacyPagesFolder(publishConfig);
42
- }
43
- console.info(`[webstir-frontend] ${modeLabel} pipeline completed.`);
30
+ const config = await prepareWorkspaceConfig(options.workspaceRoot);
31
+ const enable = await readWorkspaceEnableFlags(options.workspaceRoot);
32
+ const publishConfig = options.publishMode === 'ssg' ? applySsgPublishLayout(config) : config;
33
+
34
+ const modeLabel = options.publishMode === 'ssg' ? 'SSG publish' : 'publish';
35
+ console.info(`[webstir-frontend] Running ${modeLabel} pipeline...`);
36
+
37
+ if (options.publishMode === 'ssg') {
38
+ await assertNoSsgRoutes(config.paths.workspace);
39
+ }
40
+
41
+ await runPipeline(publishConfig, 'publish', { enable, env: process.env });
42
+ if (options.publishMode === 'ssg') {
43
+ await generateSsgViewData(publishConfig);
44
+ await applySsgRouting(publishConfig);
45
+ await removeLegacyPagesFolder(publishConfig);
46
+ }
47
+ console.info(`[webstir-frontend] ${modeLabel} pipeline completed.`);
44
48
  }
45
49
 
46
50
  export async function runRebuild(options: FrontendCommandOptions): Promise<void> {
47
- const config = await prepareWorkspaceConfig(options.workspaceRoot);
48
- const enable = await readWorkspaceEnableFlags(options.workspaceRoot);
49
-
50
- console.info('[webstir-frontend] Running rebuild pipeline...');
51
- await runPipeline(config, 'build', { changedFile: options.changedFile, enable });
52
- console.info('[webstir-frontend] Rebuild pipeline completed.');
51
+ const config = await prepareWorkspaceConfig(options.workspaceRoot);
52
+ const enable = await readWorkspaceEnableFlags(options.workspaceRoot);
53
+
54
+ console.info('[webstir-frontend] Running rebuild pipeline...');
55
+ await runPipeline(config, 'build', {
56
+ changedFile: options.changedFile,
57
+ enable,
58
+ env: process.env,
59
+ });
60
+ console.info('[webstir-frontend] Rebuild pipeline completed.');
53
61
  }
54
62
 
55
63
  export async function runAddPage(options: AddPageCommandOptions): Promise<void> {
56
- const config = await prepareWorkspaceConfig(options.workspaceRoot);
57
- console.info('[webstir-frontend] Creating page scaffold...');
58
-
59
- const isSsgWorkspace = await detectSsgWorkspace(options.workspaceRoot);
60
- const effectiveSsg = options.ssg ?? isSsgWorkspace;
61
- await createPageScaffold({
62
- workspaceRoot: options.workspaceRoot,
63
- pageName: options.pageName,
64
- mode: effectiveSsg ? 'ssg' : 'standard',
65
- paths: {
66
- pages: config.paths.src.pages,
67
- app: config.paths.src.app
68
- }
64
+ const config = await prepareWorkspaceConfig(options.workspaceRoot);
65
+ console.info('[webstir-frontend] Creating page scaffold...');
66
+
67
+ const isSsgWorkspace = await detectSsgWorkspace(options.workspaceRoot);
68
+ const effectiveSsg = options.ssg ?? isSsgWorkspace;
69
+ await createPageScaffold({
70
+ workspaceRoot: options.workspaceRoot,
71
+ pageName: options.pageName,
72
+ mode: effectiveSsg ? 'ssg' : 'standard',
73
+ paths: {
74
+ pages: config.paths.src.pages,
75
+ app: config.paths.src.app,
76
+ },
77
+ });
78
+ if (effectiveSsg) {
79
+ await ensureSsgViewMetadataForPage({
80
+ workspaceRoot: options.workspaceRoot,
81
+ pageName: options.pageName,
69
82
  });
70
- if (effectiveSsg) {
71
- await ensureSsgViewMetadataForPage({
72
- workspaceRoot: options.workspaceRoot,
73
- pageName: options.pageName
74
- });
75
- }
76
- console.info('[webstir-frontend] Page scaffold created.');
83
+ }
84
+ console.info('[webstir-frontend] Page scaffold created.');
77
85
  }
78
86
 
79
87
  interface WorkspacePackageJsonMode {
80
- readonly webstir?: {
81
- readonly mode?: string;
82
- };
88
+ readonly webstir?: {
89
+ readonly mode?: string;
90
+ };
83
91
  }
84
92
 
85
93
  async function detectSsgWorkspace(workspaceRoot: string): Promise<boolean> {
86
- const pkgPath = path.join(workspaceRoot, 'package.json');
87
- const pkg = await readJson<WorkspacePackageJsonMode>(pkgPath);
88
- const mode = pkg?.webstir?.mode;
89
- return typeof mode === 'string' && mode.toLowerCase() === 'ssg';
94
+ const pkgPath = path.join(workspaceRoot, 'package.json');
95
+ const pkg = await readJson<WorkspacePackageJsonMode>(pkgPath);
96
+ const mode = pkg?.webstir?.mode;
97
+ return typeof mode === 'string' && mode.toLowerCase() === 'ssg';
90
98
  }
91
99
 
92
- function applySsgPublishLayout(config: import('./types.js').FrontendConfig): import('./types.js').FrontendConfig {
93
- const distFrontend = config.paths.dist.frontend;
94
- const distPages = distFrontend;
95
- const distContent = path.join(distFrontend, 'docs');
96
-
97
- return {
98
- ...config,
99
- paths: {
100
- ...config.paths,
101
- dist: {
102
- ...config.paths.dist,
103
- pages: distPages,
104
- content: distContent
105
- }
106
- }
107
- };
100
+ function applySsgPublishLayout(
101
+ config: import('./types.js').FrontendConfig,
102
+ ): import('./types.js').FrontendConfig {
103
+ const distFrontend = config.paths.dist.frontend;
104
+ const distPages = distFrontend;
105
+ const distContent = path.join(distFrontend, 'docs');
106
+
107
+ return {
108
+ ...config,
109
+ paths: {
110
+ ...config.paths,
111
+ dist: {
112
+ ...config.paths.dist,
113
+ pages: distPages,
114
+ content: distContent,
115
+ },
116
+ },
117
+ };
108
118
  }
109
119
 
110
120
  interface WorkspacePackageJsonEnable {
111
- readonly webstir?: {
112
- readonly enable?: EnableFlags;
113
- };
121
+ readonly webstir?: {
122
+ readonly enable?: EnableFlags;
123
+ };
114
124
  }
115
125
 
116
126
  async function readWorkspaceEnableFlags(workspaceRoot: string): Promise<EnableFlags | undefined> {
117
- const pkgPath = path.join(workspaceRoot, 'package.json');
118
- const pkg = await readJson<WorkspacePackageJsonEnable>(pkgPath);
119
- return pkg?.webstir?.enable;
127
+ const pkgPath = path.join(workspaceRoot, 'package.json');
128
+ const pkg = await readJson<WorkspacePackageJsonEnable>(pkgPath);
129
+ return pkg?.webstir?.enable;
120
130
  }
121
131
 
122
132
  async function removeLegacyPagesFolder(config: import('./types.js').FrontendConfig): Promise<void> {
123
- const legacyPagesRoot = path.join(config.paths.dist.frontend, FOLDERS.pages);
124
- if (legacyPagesRoot === config.paths.dist.pages) {
125
- return;
126
- }
133
+ const legacyPagesRoot = path.join(config.paths.dist.frontend, FOLDERS.pages);
134
+ if (legacyPagesRoot === config.paths.dist.pages) {
135
+ return;
136
+ }
127
137
 
128
- if (!(await pathExists(legacyPagesRoot))) {
129
- return;
130
- }
138
+ if (!(await pathExists(legacyPagesRoot))) {
139
+ return;
140
+ }
131
141
 
132
- const entries = await readdir(legacyPagesRoot);
133
- if (entries.length > 0) {
134
- return;
135
- }
142
+ const entries = await readdir(legacyPagesRoot);
143
+ if (entries.length > 0) {
144
+ return;
145
+ }
136
146
 
137
- await remove(legacyPagesRoot);
147
+ await remove(legacyPagesRoot);
138
148
  }
package/src/pipeline.ts CHANGED
@@ -5,84 +5,96 @@ import type { Builder, BuilderContext } from './builders/types.js';
5
5
  import { createHookContext, executeHooks, loadHooks } from './hooks.js';
6
6
 
7
7
  export interface PipelineOptions {
8
- readonly changedFile?: string;
9
- readonly enable?: EnableFlags;
8
+ readonly changedFile?: string;
9
+ readonly enable?: EnableFlags;
10
+ readonly env?: Record<string, string | undefined>;
10
11
  }
11
12
 
12
13
  export type PipelineMode = 'build' | 'publish';
13
14
 
14
- export async function runPipeline(config: FrontendConfig, mode: PipelineMode, options: PipelineOptions = {}): Promise<void> {
15
- const context: BuilderContext = { config, changedFile: options.changedFile, enable: options.enable };
16
- const builders: Builder[] = createBuilders(context);
17
- const hooks = await loadHooks(config.paths.workspace, mode === 'build');
18
- const pipelineContext = createHookContext(config, mode, options.changedFile);
19
-
20
- await executeHooks('pipeline.beforeAll', hooks.pipelineBefore, pipelineContext);
21
-
22
- let pipelineError: unknown;
23
-
24
- try {
25
- for (const builder of builders) {
26
- const builderContext = createHookContext(config, mode, options.changedFile, builder.name);
27
- const beforeHooks = hooks.builderBefore.get(builder.name) ?? [];
28
- const afterHooks = hooks.builderAfter.get(builder.name) ?? [];
29
-
30
- await executeHooks(`builder.${builder.name}.before`, beforeHooks, builderContext);
31
-
32
- const start = performance.now();
33
- let builderError: Error | undefined;
34
- let afterHookError: Error | undefined;
35
-
36
- try {
37
- if (mode === 'build') {
38
- await builder.build(context);
39
- } else {
40
- await builder.publish(context);
41
- }
42
- } catch (error) {
43
- builderError = wrapPipelineError(builder.name, mode, error);
44
- }
45
-
46
- try {
47
- await executeHooks(`builder.${builder.name}.after`, afterHooks, builderContext);
48
- } catch (error) {
49
- afterHookError = error as Error;
50
- }
51
-
52
- const end = performance.now();
53
- const duration = end - start;
54
- console.info(`[webstir-frontend] ${mode}:${builder.name} completed in ${duration.toFixed(1)}ms`);
55
-
56
- if (builderError) {
57
- throw builderError;
58
- }
59
-
60
- if (afterHookError) {
61
- throw afterHookError;
62
- }
63
- }
64
- } catch (error) {
65
- pipelineError = error;
66
- } finally {
67
- try {
68
- await executeHooks('pipeline.afterAll', hooks.pipelineAfter, pipelineContext);
69
- } catch (hookError) {
70
- if (!pipelineError) {
71
- pipelineError = hookError;
72
- }
15
+ export async function runPipeline(
16
+ config: FrontendConfig,
17
+ mode: PipelineMode,
18
+ options: PipelineOptions = {},
19
+ ): Promise<void> {
20
+ const context: BuilderContext = {
21
+ config,
22
+ changedFile: options.changedFile,
23
+ enable: options.enable,
24
+ env: options.env,
25
+ };
26
+ const builders: Builder[] = createBuilders(context);
27
+ const hooks = await loadHooks(config.paths.workspace, mode === 'build');
28
+ const pipelineContext = createHookContext(config, mode, options.changedFile);
29
+
30
+ await executeHooks('pipeline.beforeAll', hooks.pipelineBefore, pipelineContext);
31
+
32
+ let pipelineError: unknown;
33
+
34
+ try {
35
+ for (const builder of builders) {
36
+ const builderContext = createHookContext(config, mode, options.changedFile, builder.name);
37
+ const beforeHooks = hooks.builderBefore.get(builder.name) ?? [];
38
+ const afterHooks = hooks.builderAfter.get(builder.name) ?? [];
39
+
40
+ await executeHooks(`builder.${builder.name}.before`, beforeHooks, builderContext);
41
+
42
+ const start = performance.now();
43
+ let builderError: Error | undefined;
44
+ let afterHookError: Error | undefined;
45
+
46
+ try {
47
+ if (mode === 'build') {
48
+ await builder.build(context);
49
+ } else {
50
+ await builder.publish(context);
73
51
  }
52
+ } catch (error) {
53
+ builderError = wrapPipelineError(builder.name, mode, error);
54
+ }
55
+
56
+ try {
57
+ await executeHooks(`builder.${builder.name}.after`, afterHooks, builderContext);
58
+ } catch (error) {
59
+ afterHookError = error as Error;
60
+ }
61
+
62
+ const end = performance.now();
63
+ const duration = end - start;
64
+ console.info(
65
+ `[webstir-frontend] ${mode}:${builder.name} completed in ${duration.toFixed(1)}ms`,
66
+ );
67
+
68
+ if (builderError) {
69
+ throw builderError;
70
+ }
71
+
72
+ if (afterHookError) {
73
+ throw afterHookError;
74
+ }
74
75
  }
75
-
76
- if (pipelineError) {
77
- throw pipelineError;
76
+ } catch (error) {
77
+ pipelineError = error;
78
+ } finally {
79
+ try {
80
+ await executeHooks('pipeline.afterAll', hooks.pipelineAfter, pipelineContext);
81
+ } catch (hookError) {
82
+ if (!pipelineError) {
83
+ pipelineError = hookError;
84
+ }
78
85
  }
86
+ }
87
+
88
+ if (pipelineError) {
89
+ throw pipelineError;
90
+ }
79
91
  }
80
92
 
81
93
  function wrapPipelineError(name: string, mode: PipelineMode, error: unknown): Error {
82
- if (error instanceof Error) {
83
- error.message = `[${mode}:${name}] ${error.message}`;
84
- return error;
85
- }
94
+ if (error instanceof Error) {
95
+ error.message = `[${mode}:${name}] ${error.message}`;
96
+ return error;
97
+ }
86
98
 
87
- return new Error(`[${mode}:${name}] ${String(error)}`);
99
+ return new Error(`[${mode}:${name}] ${String(error)}`);
88
100
  }