Skip to content

Commit dc8ebde

Browse files
committed
Merge branch 'feat/angular-v19'
2 parents ee8657f + e378d69 commit dc8ebde

File tree

178 files changed

+1873
-4326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+1873
-4326
lines changed

.bitmap

Lines changed: 194 additions & 68 deletions
Large diffs are not rendered by default.

angular/app-types/angular-app-type/angular.application.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { VERSION } from '@angular/cli';
2-
import {
3-
ApplicationOptions,
4-
getWorkspace,
5-
NG_APP_NAME,
6-
normalizePath
7-
} from '@bitdev/angular.dev-services.common';
2+
import { getWorkspace, NG_APP_NAME, normalizePath } from '@bitdev/angular.dev-services.common';
3+
import { ApplicationBuilderOptions, SsrClass } from '@bitdev/angular.dev-services.ng-compat';
84
import { AngularPreview } from '@bitdev/angular.dev-services.preview.preview';
95
import {
106
AppBuildContext,
@@ -44,7 +40,7 @@ export class AngularApp implements Application {
4440
readonly options: AngularAppOptions
4541
) {
4642
this.name = options.name || NG_APP_NAME;
47-
this.idName = `bitdev.angular/${ this.name }`;
43+
this.idName = `bitdev.angular/${this.name}`;
4844
this.deploy = options.deploy;
4945
}
5046

@@ -59,19 +55,19 @@ export class AngularApp implements Application {
5955
}
6056

6157
private getTsconfigPath(tempFolder: string): string {
62-
return normalizePath(join(tempFolder, `tsconfig/tsconfig-${ Date.now() }.json`));
58+
return normalizePath(join(tempFolder, `tsconfig/tsconfig-${Date.now()}.json`));
6359
}
6460

6561
private getPublicDir(artifactsDir: string) {
6662
return join(artifactsDir, this.name);
6763
}
6864

69-
private getDevServerContext(context: AppContext, _appRootPath: string): DevServerContext {
65+
private getDevServerContext(context: AppContext): DevServerContext {
7066
// const ngEnvOptions = this.angularEnv.getNgEnvOptions();
7167
return Object.assign(cloneDeep(context), {
7268
entry: [],
7369
rootPath: /*ngEnvOptions.devServer === 'vite' ? _appRootPath : */'',
74-
publicPath: `${ this.publicDir }/${ this.options.name }`,
70+
publicPath: `${this.publicDir}/${this.options.name}`,
7571
title: this.options.name
7672
});
7773
}
@@ -122,9 +118,9 @@ export class AngularApp implements Application {
122118
const pkgName = depsResolver.getPackageName(dep);
123119
// TODO we should find a way to use the real entry file based on the component config because people can change it
124120
if (fs.existsSync(join(componentDir, 'public-api.ts'))) {
125-
tsconfigJSON.compilerOptions.paths[pkgName] = [`${ componentDir }/public-api.ts`, `${ componentDir }`];
121+
tsconfigJSON.compilerOptions.paths[pkgName] = [`${componentDir}/public-api.ts`, `${componentDir}`];
126122
}
127-
tsconfigJSON.compilerOptions.paths[`${ pkgName }/*`] = [`${ componentDir }/*`];
123+
tsconfigJSON.compilerOptions.paths[`${pkgName}/*`] = [`${componentDir}/*`];
128124
}
129125
});
130126

@@ -181,7 +177,7 @@ export class AngularApp implements Application {
181177
const envVars = await this.getEnvFile('development', appRootPath, context.envVariables as any);
182178
await serveApplication({
183179
angularOptions: {
184-
...this.options.angularBuildOptions as ApplicationOptions,
180+
...this.options.angularBuildOptions as ApplicationBuilderOptions,
185181
tsConfig: tsconfigPath
186182
},
187183
sourceRoot: this.options.sourceRoot || 'src',
@@ -194,7 +190,7 @@ export class AngularApp implements Application {
194190
}
195191
});
196192
} else {
197-
const devServerContext = this.getDevServerContext(context, appRootPath);
193+
const devServerContext = this.getDevServerContext(context);
198194
const envContext = this.getEnvContext(context);
199195
const preview = this.getPreview(tsconfigPath)(envContext);
200196

@@ -216,8 +212,13 @@ export class AngularApp implements Application {
216212
const outputPath = this.getPublicDir(context.artifactsDir);
217213
const appRootPath = capsule.path;
218214
const appTsconfigPath = join(appRootPath, this.options.angularBuildOptions.tsConfig);
219-
const appOptions = this.options.angularBuildOptions as ApplicationOptions;
220-
const entryServer = appOptions.ssr && Number(VERSION.major) >= 17 ? './entry.server.ts' : undefined;
215+
const appOptions = this.options.angularBuildOptions as ApplicationBuilderOptions;
216+
let entryServer: string | undefined;
217+
if ((appOptions.ssr as SsrClass)?.entry) {
218+
entryServer = (appOptions.ssr as SsrClass).entry;
219+
} else if (appOptions.ssr && Number(VERSION.major) >= 17 && Number(VERSION.major) < 19) {
220+
entryServer = './entry.server.ts';
221+
}
221222
const tempFolder = this.getTempFolder();
222223
const tsconfigPath = this.getTsconfigPath(tempFolder);
223224
this.generateTsConfig([capsule.component], appRootPath, appTsconfigPath, tsconfigPath, depsResolver, undefined, entryServer);
@@ -239,6 +240,7 @@ export class AngularApp implements Application {
239240
'process.env': envVars
240241
}
241242
});
243+
console.log('build done');
242244
} else {
243245
let bundler: Bundler;
244246
if (this.options.bundler) {
@@ -260,7 +262,7 @@ export class AngularApp implements Application {
260262
metadata: {
261263
outputPath,
262264
publicDir: join(outputPath, 'browser'),
263-
ssrPublicDir: appOptions.ssr ? join(outputPath, 'ssr') : undefined
265+
ssrPublicDir: appOptions.ssr ? join(outputPath, Number(VERSION.major) >= 19 ? 'server' : 'ssr') : undefined
264266
}
265267
};
266268
}

angular/app-types/angular-app-type/application.bundler.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
/* eslint-disable no-param-reassign */
22
import { OutputHashing } from '@angular-devkit/build-angular';
33
import { VERSION } from '@angular/cli';
4-
import {
5-
ApplicationOptions,
6-
dedupPaths,
7-
getLoggerApi,
8-
normalizePath
9-
} from '@bitdev/angular.dev-services.common';
10-
import {
11-
type ApplicationBuilderOptions,
12-
buildApplicationInternal
13-
} from '@bitdev/angular.dev-services.ng-compat';
4+
import { dedupPaths, getLoggerApi, normalizePath } from '@bitdev/angular.dev-services.common';
5+
import { type ApplicationBuilderOptions, buildApplicationInternal } from '@bitdev/angular.dev-services.ng-compat';
146
import { Logger } from '@teambit/logger';
157
import assert from 'assert';
168
import fs from 'fs-extra';
@@ -22,7 +14,7 @@ import definePlugin from './plugins/define.plugin.js';
2214
import { getIndexInputFile } from './utils.js';
2315

2416
export type BuildApplicationOptions = {
25-
angularOptions: Partial<ApplicationOptions>;
17+
angularOptions: Partial<ApplicationBuilderOptions>;
2618
outputPath: string;
2719
sourceRoot: string;
2820
workspaceRoot: string;
@@ -36,10 +28,10 @@ export type BuildApplicationOptions = {
3628
const BUILDER_NAME = '@angular-devkit/build-angular:application';
3729

3830
export async function buildApplication(options: BuildApplicationOptions): Promise<void> {
39-
const { angularOptions: { tsConfig, ssr, define }, envVars } = options;
31+
const { angularOptions: { tsConfig, server, define }, envVars } = options;
4032
assert(tsConfig, 'tsConfig option is required');
41-
const isSsr = !!ssr && Number(VERSION.major) >= 17;
42-
if (isSsr) {
33+
const isSsr = !!server && Number(VERSION.major) >= 17;
34+
if (isSsr && Number(VERSION.major) < 19) {
4335
addEntryServer(options);
4436
}
4537
const appOptions = getAppOptions(options, isSsr);
@@ -58,7 +50,8 @@ export async function buildApplication(options: BuildApplicationOptions): Promis
5850
}
5951
}
6052

61-
if (isSsr) {
53+
// Versions of Angular <19 require a nitro middleware to support SSR API endpoints
54+
if (isSsr && Number(VERSION.major) < 19) {
6255
await buildNitro(options);
6356
}
6457
}
@@ -68,7 +61,7 @@ function addEntryServer(options: BuildApplicationOptions): void {
6861
if (ssr && entryServer) {
6962
const fileContent = `import type { ApplicationRef } from '@angular/core';
7063
import { renderApplication, renderModule } from '@angular/platform-server';
71-
import bootstrap from '${ server?.replace(extname(server), '') }';
64+
import bootstrap from '${server?.replace(extname(server), '')}';
7265
7366
function isBootstrapFn(value: unknown): value is () => Promise<ApplicationRef> {
7467
// We can differentiate between a module and a bootstrap function by reading compiler-generated "ɵmod" static property:
@@ -95,19 +88,20 @@ export default async function render(url: string, document: string) {
9588
}
9689
}
9790

98-
function getAppOptions(options: BuildApplicationOptions, isSsr: boolean): any {
91+
function getAppOptions(options: BuildApplicationOptions, isSsr: boolean): ApplicationBuilderOptions {
9992
const { entryServer, angularOptions, outputPath, sourceRoot, workspaceRoot } = options;
10093

10194
// declare constants for all reusable values here
102-
const normalizedIndex = `./${ join(sourceRoot, 'index.html') }`;
103-
const normalizedBrowser = `./${ join(sourceRoot, 'main.ts') }`;
95+
const normalizedIndex = `./${join(sourceRoot, 'index.html')}`;
96+
const normalizedBrowser = `./${join(sourceRoot, 'main.ts')}`;
97+
const serverPath = `./${join(sourceRoot, 'main.server.ts')}`;
10498

10599
const dedupedAssets = dedupPaths([posix.join(sourceRoot, `assets/**/*`), ...(angularOptions.assets ?? [])]);
106-
const dedupedStyles = dedupPaths([posix.join(sourceRoot, `styles.${ angularOptions.inlineStyleLanguage }`), ...(angularOptions.styles ?? [])]);
100+
const dedupedStyles = dedupPaths([posix.join(sourceRoot, `styles.${angularOptions.inlineStyleLanguage}`), ...(angularOptions.styles ?? [])]);
107101

108102
return {
109103
...angularOptions,
110-
baseHref: angularOptions.baseHref ?? './',
104+
baseHref: angularOptions.baseHref ?? '/',
111105
preserveSymlinks: false,
112106
outputPath,
113107
index: angularOptions.index ?? normalizedIndex,
@@ -117,13 +111,14 @@ function getAppOptions(options: BuildApplicationOptions, isSsr: boolean): any {
117111
styles: dedupedStyles,
118112
scripts: angularOptions.scripts,
119113
namedChunks: angularOptions.namedChunks ?? true,
120-
optimization: angularOptions.optimization ?? true,
114+
optimization: false,//angularOptions.optimization ?? true,
121115
aot: true,
122116
deleteOutputPath: true,
123117
sourceMap: angularOptions.sourceMap ?? true,
124-
outputHashing: angularOptions.outputHashing ?? OutputHashing.All,
118+
outputHashing: OutputHashing.None,//angularOptions.outputHashing ?? OutputHashing.All,
125119
watch: false,
126-
server: isSsr ? angularOptions.server : undefined,
120+
outputMode: angularOptions.outputMode ?? (isSsr ? 'server' : 'static'),
121+
server: isSsr ? angularOptions.server ?? serverPath : undefined,
127122
prerender: isSsr ? (angularOptions.prerender ?? !!angularOptions.server) : undefined,
128123
ssr: isSsr ? {
129124
entry: entryServer
@@ -149,14 +144,15 @@ function getBuilderContext(options: BuildApplicationOptions, appOptions: Applica
149144
project: 'bit-ng-app-builder',
150145
target: 'build'
151146
},
152-
getProjectMetadata: function(projectName: string): Promise<any> {
147+
getProjectMetadata: function (): Promise<any> {
153148
return Promise.resolve({
154149
root: '',
155150
sourceRoot,
156151
cli: { cache: { enabled: true, path: resolve(tempFolder, 'angular/cache') } }
157152
});
158153
},
159-
addTeardown: () => {},
154+
addTeardown: () => {
155+
},
160156
getBuilderNameForTarget: () => Promise.resolve(BUILDER_NAME),
161157
getTargetOptions: () => Promise.resolve(appOptions as any),
162158
validateOptions: () => Promise.resolve(appOptions as any)
@@ -177,18 +173,18 @@ async function getNitroConfig(options: BuildApplicationOptions): Promise<NitroCo
177173
const nitroDir = normalizePath(resolve(outputDir, 'ssr'));
178174
const indexPath = getIndexInputFile(index!);
179175

180-
const prerenderedRoutes = prerender ? (await import(`${ outputDir }/prerendered-routes.json`, { assert: { type: 'json' }})).default : undefined;
176+
const prerenderedRoutes = prerender ? (await import(`${outputDir}/prerendered-routes.json`, { assert: { type: 'json' } })).default : undefined;
181177

182178
return {
183179
rootDir: workspaceRoot,
184180
logLevel: 1, // TODO reset this to 3 or 2 https://github.com/unjs/consola/#log-level
185-
srcDir: normalizePath(`${ workspaceRoot }/src/server`),
186-
scanDirs: [normalizePath(`${ workspaceRoot }/src/server`)],
181+
srcDir: normalizePath(`${workspaceRoot}/src/server`),
182+
scanDirs: [normalizePath(`${workspaceRoot}/src/server`)],
187183
buildDir: resolve(tempFolder, 'nitro'),
188184

189185
alias: ssr ? {
190186
'#alias/entry.server': normalizePath(join(serverDir, 'server.mjs')),
191-
'#alias/index': normalizePath(join(serverDir, `${ basename(indexPath, extname(indexPath)) }.server.html`))
187+
'#alias/index': normalizePath(join(serverDir, `${basename(indexPath, extname(indexPath))}.server.html`))
192188
} : {},
193189
serverAssets: ssr ? [{
194190
baseName: 'public',

angular/app-types/angular-app-type/application.dev-server.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
/* eslint-disable no-param-reassign */
22
import { executeDevServerBuilder, OutputHashing } from '@angular-devkit/build-angular';
33
import { VERSION } from '@angular/cli';
4-
import {
5-
dedupPaths,
6-
getLoggerApi,
7-
normalizePath
8-
} from '@bitdev/angular.dev-services.common';
9-
import {
10-
type ApplicationBuilderOptions,
11-
type DevServerBuilderOptions
12-
} from '@bitdev/angular.dev-services.ng-compat';
4+
import { dedupPaths, getLoggerApi, normalizePath } from '@bitdev/angular.dev-services.common';
5+
import { type ApplicationBuilderOptions, type DevServerBuilderOptions, } from '@bitdev/angular.dev-services.ng-compat';
136
import { Logger } from '@teambit/logger';
147
import assert from 'assert';
158
import { createEvent } from 'h3';
@@ -45,10 +38,18 @@ export async function serveApplication(options: ServeApplicationOptions): Promis
4538
const isSsr = !!server && Number(VERSION.major) >= 17;
4639
const appOptions = getAppOptions(options, isSsr);
4740
const builderContext = getBuilderContext(options, appOptions);
48-
const devServerOptions = isSsr ? {
49-
buildPlugins: [definePlugin({ ...envVars, ...define })],
50-
middleware: [await createNitroApiMiddleware(options)]
51-
} : undefined;
41+
const devServerOptions: any = {
42+
buildPlugins: [],
43+
middleware: []
44+
};
45+
if (isSsr) {
46+
devServerOptions.buildPlugins = [definePlugin({ ...envVars, ...define })];
47+
48+
// Versions of Angular <19 require a nitro middleware to support SSR API endpoints
49+
if (Number(VERSION.major) < 19) {
50+
devServerOptions.middleware = [await createNitroApiMiddleware(options)];
51+
}
52+
}
5253

5354
// @ts-ignore only v17+ has 4 arguments, previous versions only have 3
5455
await executeDevServerBuilder(appOptions, builderContext as any, undefined, devServerOptions).toPromise();
@@ -57,16 +58,16 @@ export async function serveApplication(options: ServeApplicationOptions): Promis
5758
function getAppOptions(options: ServeApplicationOptions, isSsr: boolean): ApplicationBuilderOptions & DevServerBuilderOptions {
5859
const { angularOptions, port, sourceRoot, workspaceRoot } = options;
5960
// declare constants for all reusable values here
60-
const normalizedIndex = `./${ join(sourceRoot, 'index.html') }`;
61-
const normalizedBrowser = `./${ join(sourceRoot, 'main.ts') }`;
62-
const serverPath = `./${ join(sourceRoot, 'main.server.ts') }`;
61+
const normalizedIndex = `./${join(sourceRoot, 'index.html')}`;
62+
const normalizedBrowser = `./${join(sourceRoot, 'main.ts')}`;
63+
const serverPath = `./${join(sourceRoot, 'main.server.ts')}`;
6364

6465
const dedupedAssets = dedupPaths([posix.join(sourceRoot, `assets/**/*`), ...(angularOptions.assets ?? [])]);
65-
const dedupedStyles = dedupPaths([posix.join(sourceRoot, `styles.${ angularOptions.inlineStyleLanguage }`), ...(angularOptions.styles ?? [])]);
66+
const dedupedStyles = dedupPaths([posix.join(sourceRoot, `styles.${angularOptions.inlineStyleLanguage}`), ...(angularOptions.styles ?? [])]);
6667

6768
return {
6869
...angularOptions,
69-
baseHref: angularOptions.baseHref,
70+
baseHref: angularOptions.baseHref ?? '/',
7071
preserveSymlinks: false,
7172
outputPath: OUTPUT_PATH,
7273
index: angularOptions.index ?? normalizedIndex,
@@ -82,7 +83,9 @@ function getAppOptions(options: ServeApplicationOptions, isSsr: boolean): Applic
8283
sourceMap: angularOptions.sourceMap ?? true,
8384
outputHashing: angularOptions.outputHashing ?? OutputHashing.All,
8485
watch: true,
85-
liveReload: true,
86+
liveReload: angularOptions.liveReload ?? true,
87+
hmr: angularOptions.hmr ?? false,
88+
outputMode: angularOptions.outputMode ?? (isSsr ? 'server' : 'static'),
8689
server: isSsr ? angularOptions.server ?? serverPath : undefined,
8790
prerender: isSsr ? angularOptions.prerender ?? !!angularOptions.server : false,
8891
ssr: isSsr ? (angularOptions.ssr ?? !!angularOptions.server) : false,
@@ -115,7 +118,8 @@ function getBuilderContext(options: ServeApplicationOptions, appOptions: Applica
115118
target: 'development'
116119
},
117120
getProjectMetadata: getProjectMetadata(options),
118-
addTeardown: () => {},
121+
addTeardown: () => {
122+
},
119123
getBuilderNameForTarget: () => Promise.resolve(BUILDER_NAME),
120124
getTargetOptions: () => Promise.resolve(appOptions as any),
121125
validateOptions: () => Promise.resolve(appOptions as any)
@@ -124,7 +128,7 @@ function getBuilderContext(options: ServeApplicationOptions, appOptions: Applica
124128

125129
function getProjectMetadata(options: ServeApplicationOptions) {
126130
const { sourceRoot, tempFolder } = options;
127-
return function(projectName: string): Promise<any> {
131+
return function (): Promise<any> {
128132
return Promise.resolve({
129133
root: '',
130134
sourceRoot,
@@ -144,8 +148,8 @@ function getNitroConfig(options: ServeApplicationOptions): NitroConfig {
144148
return {
145149
rootDir,
146150
logLevel: 2,
147-
srcDir: normalizePath(`${ rootDir }/src/server`),
148-
scanDirs: [normalizePath(`${ rootDir }/src/server`)],
151+
srcDir: normalizePath(`${rootDir}/src/server`),
152+
scanDirs: [normalizePath(`${rootDir}/src/server`)],
149153
buildDir: resolve(tempFolder, 'nitro')
150154
};
151155
}
@@ -164,7 +168,7 @@ async function createNitroApiMiddleware(options: ServeApplicationOptions): Promi
164168
const server = createDevServer(nitro);
165169
await build(nitro);
166170

167-
return async(
171+
return async (
168172
req: any,
169173
res: any,
170174
next: any

angular/app-types/angular-app-type/component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"componentId": {
33
"scope": "bitdev.angular",
44
"name": "app-types/angular-app-type",
5-
"version": "6.0.11"
5+
"version": "7.0.0"
66
},
77
"propagate": false,
88
"extensions": {

angular/devkit/common/component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"componentId": {
33
"scope": "bitdev.angular",
44
"name": "dev-services/common",
5-
"version": "6.0.8"
5+
"version": "7.0.0"
66
},
77
"propagate": false,
88
"extensions": {

0 commit comments

Comments
 (0)