Skip to content

Commit 6002f8a

Browse files
authored
fix: support object outputPath for Angular application builder (#96)
1 parent 0989712 commit 6002f8a

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

projects/angular-server-side-configuration/builders/ngsscbuild/index.spec.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Ngssc Builder', () => {
7777

7878
expect(output.success).toBe(true);
7979

80-
const ngssc = readNgsscJson(applicationHost);
80+
const ngssc = readNgsscJson(applicationHost, 'dist/browser/ngssc.json');
8181
expect(ngssc.variant).toEqual('process');
8282
expect(ngssc.filePattern).toEqual('**/index{.,.server.}html');
8383
});
@@ -93,7 +93,7 @@ describe('Ngssc Builder', () => {
9393

9494
expect(output.success).toBe(true);
9595

96-
const ngssc = readNgsscJson(applicationHost);
96+
const ngssc = readNgsscJson(applicationHost, 'dist/browser/ngssc.json');
9797
expect(ngssc.environmentVariables).toContain(expected);
9898
});
9999

@@ -111,5 +111,19 @@ describe('Ngssc Builder', () => {
111111
expect(ngssc.variant).toEqual('process');
112112
expect(ngssc.filePattern).toEqual('index.html');
113113
});
114+
115+
it('should handle object outputPath', async () => {
116+
applicationHost.replaceInFile(
117+
'angular.json',
118+
'"outputPath": "dist",',
119+
`"outputPath": { "base": "dist", "browser": "html" },`,
120+
);
121+
const output = await runNgsscbuild(applicationHost);
122+
123+
expect(output.success).toBe(true);
124+
125+
const ngssc = readNgsscJson(applicationHost, 'dist/html/ngssc.json');
126+
expect(ngssc.variant).toEqual('process');
127+
});
114128
});
115129
});

projects/angular-server-side-configuration/builders/ngsscbuild/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export async function ngsscBuild(options: NgsscBuildSchema, context: BuilderCont
3939
builderName !== '@angular-devkit/build-angular:application'
4040
? undefined
4141
: 'server' in builderOptions && builderOptions.server
42-
? 'server'
43-
: 'browser-only',
42+
? 'server'
43+
: 'browser-only',
4444
);
4545

4646
return result;
@@ -54,8 +54,11 @@ export async function detectVariablesAndBuildNgsscJson(
5454
applicationBuilderVariant: ApplicationBuilderVariant = undefined,
5555
) {
5656
const ngsscContext = await detectVariables(context, options.searchPattern);
57-
// TODO: Fix possible outputPath options.
58-
let outputPath = join(context.workspaceRoot, builderOptions.outputPath as string);
57+
const builderOutputPath =
58+
typeof builderOptions.outputPath === 'string'
59+
? builderOptions.outputPath
60+
: builderOptions.outputPath.base;
61+
let outputPath = join(context.workspaceRoot, builderOutputPath);
5962
const ngssc = buildNgssc(
6063
ngsscContext,
6164
options,
@@ -64,10 +67,11 @@ export async function detectVariablesAndBuildNgsscJson(
6467
applicationBuilderVariant,
6568
);
6669

67-
const browserOutputPath = join(outputPath, 'browser');
68-
if (applicationBuilderVariant === 'browser-only' && existsSync(browserOutputPath)) {
69-
outputPath = browserOutputPath;
70+
const browserOutputPaths = [join(outputPath, 'browser')];
71+
if (typeof builderOptions.outputPath !== 'string' && builderOptions.outputPath.browser) {
72+
browserOutputPaths.unshift(join(outputPath, builderOptions.outputPath.browser));
7073
}
74+
outputPath = browserOutputPaths.find(existsSync) ?? outputPath;
7175
writeFileSync(join(outputPath, 'ngssc.json'), JSON.stringify(ngssc, null, 2), 'utf8');
7276
}
7377

0 commit comments

Comments
 (0)