-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-esbuild): expose current target to index html transform
- Loading branch information
1 parent
21e3b6e
commit a9a5086
Showing
5 changed files
with
52 additions
and
8 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
24 changes: 24 additions & 0 deletions
24
packages/custom-esbuild/src/load-index-html-transformer.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,24 @@ | ||
import { loadIndexHtmlTransformer } from './load-index-html-transformer'; | ||
import { Target } from '@angular-devkit/architect'; | ||
|
||
describe('loadIndexHtmlTransformer', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass the target to the transformer', async () => { | ||
const transformIndexHtml = jest.fn(); | ||
jest.mock('test/test-index-transform.js', () => transformIndexHtml, { virtual: true }); | ||
const mockTarget = { project: 'test', target: 'test' } as Target; | ||
const transform = await loadIndexHtmlTransformer( | ||
'test/test-index-transform.js', | ||
'./tsconfig.json', | ||
null as any, | ||
mockTarget | ||
); | ||
|
||
await transform('Hello world!'); | ||
expect(transformIndexHtml).toHaveBeenCalledWith('Hello world!', mockTarget); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/custom-esbuild/src/load-index-html-transformer.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,18 @@ | ||
import { loadModule } from '@angular-builders/common'; | ||
import { logging } from '@angular-devkit/core'; | ||
import { Target } from '@angular-devkit/architect'; | ||
import type { IndexHtmlTransform } from '@angular/build/src/utils/index-file/index-html-generator'; | ||
|
||
export async function loadIndexHtmlTransformer( | ||
indexHtmlTransformerPath: string, | ||
tsConfig: string, | ||
logger: logging.LoggerApi, | ||
target: Target | ||
): Promise<IndexHtmlTransform> { | ||
const transformer = await loadModule<(indexHtml: string, target: Target) => Promise<string>>( | ||
indexHtmlTransformerPath, | ||
tsConfig, | ||
logger | ||
); | ||
return (indexHtml: string) => transformer(indexHtml, target); | ||
} |