-
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.
refactor: add
outExtension
to browser-esbuild
as an internal option
The `outExtension` option allows users to generate `*.mjs` files, which is useful for forcing ESM execution in Node under certain use cases. The option is limited to `*.js` and `*.mjs` files to constrain it to expected values. `*.cjs` could theoretically be useful in some specific situations, but `browser-esbuild` does not support that output format anyways, so it is not included in the type. I also updated `index.html` generation, which will correctly insert a `<script />` tag with the `*.mjs` extension. I opted to explicitly ban a "non-module" `*.mjs` file, since that would be very counterintuitive and I can't think of a valid use case for it.
- Loading branch information
Showing
5 changed files
with
89 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
...lar_devkit/build_angular/src/builders/browser-esbuild/tests/options/out-extension_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,52 @@ | ||
/** | ||
* @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 { buildEsbuildBrowserInternal } from '../../index'; | ||
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup'; | ||
|
||
describeBuilder(buildEsbuildBrowserInternal, BROWSER_BUILDER_INFO, (harness) => { | ||
describe('Option: "outExtension"', () => { | ||
it('outputs `.js` files when explicitly set to "js"', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
main: 'src/main.ts', | ||
outExtension: 'js', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
// Should generate the correct file extension. | ||
harness.expectFile('dist/main.js').toExist(); | ||
expect(harness.hasFile('dist/main.mjs')).toBeFalse(); | ||
|
||
// Index page should link to the correct file extension. | ||
const indexContents = harness.readFile('dist/index.html'); | ||
expect(indexContents).toContain('src="main.js"'); | ||
}); | ||
|
||
it('outputs `.mjs` files when set to "mjs"', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
main: 'src/main.ts', | ||
outExtension: 'mjs', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
// Should generate the correct file extension. | ||
harness.expectFile('dist/main.mjs').toExist(); | ||
expect(harness.hasFile('dist/main.js')).toBeFalse(); | ||
|
||
// Index page should link to the correct file extension. | ||
const indexContents = harness.readFile('dist/index.html'); | ||
expect(indexContents).toContain('src="main.mjs"'); | ||
}); | ||
}); | ||
}); |
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