-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular-devkit/build-angular): add initial support for server b…
…undle generation using esbuild This commit adds initial support to generate the server bundle using esbuild as the underlying bundler.
- Loading branch information
1 parent
333da08
commit 095f5ab
Showing
15 changed files
with
538 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/angular_devkit/build_angular/src/builders/application/tests/options/server_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { buildApplication } from '../../index'; | ||
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; | ||
|
||
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { | ||
beforeEach(async () => { | ||
await harness.modifyFile('src/tsconfig.app.json', (content) => { | ||
const tsConfig = JSON.parse(content); | ||
tsConfig.files ??= []; | ||
tsConfig.files.push('main.server.ts'); | ||
|
||
return JSON.stringify(tsConfig); | ||
}); | ||
}); | ||
|
||
describe('Option: "server"', () => { | ||
it('uses a provided TypeScript file', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
server: 'src/main.server.ts', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
harness.expectFile('dist/server.mjs').toExist(); | ||
harness.expectFile('dist/main.js').toExist(); | ||
}); | ||
|
||
it('uses a provided JavaScript file', async () => { | ||
await harness.writeFile('src/server.js', `console.log('server');`); | ||
|
||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
server: 'src/server.js', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
harness.expectFile('dist/server.mjs').content.toContain('console.log("server")'); | ||
}); | ||
|
||
it('fails and shows an error when file does not exist', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
server: 'src/missing.ts', | ||
}); | ||
|
||
const { result, logs } = await harness.executeOnce({ outputLogsOnFailure: false }); | ||
|
||
expect(result?.success).toBeFalse(); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ message: jasmine.stringMatching('Could not resolve "') }), | ||
); | ||
|
||
harness.expectFile('dist/main.js').toNotExist(); | ||
harness.expectFile('dist/server.mjs').toNotExist(); | ||
}); | ||
|
||
it('throws an error when given an empty string', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
server: '', | ||
}); | ||
|
||
const { result, error } = await harness.executeOnce({ outputLogsOnException: false }); | ||
expect(result).toBeUndefined(); | ||
|
||
expect(error?.message).toContain('cannot be an empty string'); | ||
}); | ||
|
||
it('resolves an absolute path as relative inside the workspace root', async () => { | ||
await harness.writeFile('file.mjs', `console.log('Hello!');`); | ||
|
||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
server: '/file.mjs', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
// Always uses the name `server.mjs` for the `server` option. | ||
harness.expectFile('dist/server.mjs').toExist(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...es/angular_devkit/build_angular/src/tools/esbuild/angular/compilation/noop-compilation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import type ng from '@angular/compiler-cli'; | ||
import ts from 'typescript'; | ||
import { AngularHostOptions } from '../angular-host'; | ||
import { AngularCompilation } from './angular-compilation'; | ||
|
||
export class NoopCompilation extends AngularCompilation { | ||
async initialize( | ||
tsconfig: string, | ||
hostOptions: AngularHostOptions, | ||
compilerOptionsTransformer?: (compilerOptions: ng.CompilerOptions) => ng.CompilerOptions, | ||
): Promise<{ | ||
affectedFiles: ReadonlySet<ts.SourceFile>; | ||
compilerOptions: ng.CompilerOptions; | ||
referencedFiles: readonly string[]; | ||
}> { | ||
// Load the compiler configuration and transform as needed | ||
const { options: originalCompilerOptions } = await this.loadConfiguration(tsconfig); | ||
const compilerOptions = | ||
compilerOptionsTransformer?.(originalCompilerOptions) ?? originalCompilerOptions; | ||
|
||
return { affectedFiles: new Set(), compilerOptions, referencedFiles: [] }; | ||
} | ||
|
||
collectDiagnostics(): never { | ||
throw new Error('Not available when using noop compilation.'); | ||
} | ||
|
||
emitAffectedFiles(): never { | ||
throw new Error('Not available when using noop compilation.'); | ||
} | ||
} |
Oops, something went wrong.