Skip to content

Commit 1df8a3d

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@angular-devkit/build-angular): correctly resolve symlinked global styles entrypoints
With this change we resolve the global stylesheet entrypoint path to use the realpath instead of the symlink path. Fixes #3500
1 parent d56179a commit 1df8a3d

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/angular_devkit/build_angular/src/webpack/configs/styles.ts

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
5151
resolvedPath = require.resolve(style.input, { paths: [root] });
5252
} catch {}
5353
}
54+
55+
if (!buildOptions.preserveSymlinks) {
56+
resolvedPath = fs.realpathSync(resolvedPath);
57+
}
58+
5459
// Add style entry points.
5560
if (entryPoints[style.bundleName]) {
5661
entryPoints[style.bundleName].push(resolvedPath);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { symlinkSync } from 'fs';
2+
import { resolve } from 'path';
3+
import { expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
4+
import { ng } from '../../../utils/process';
5+
import { updateJsonFile } from '../../../utils/project';
6+
7+
export default async function () {
8+
await writeMultipleFiles({
9+
'src/styles.scss': `p { color: red }`,
10+
'src/styles-for-link.scss': `p { color: blue }`,
11+
});
12+
13+
symlinkSync(
14+
resolve('src/styles-for-link.scss'),
15+
resolve('src/styles-linked.scss'),
16+
'junction',
17+
);
18+
19+
await updateJsonFile('angular.json', workspaceJson => {
20+
const appArchitect = workspaceJson.projects['test-project'].architect;
21+
appArchitect.build.options.styles = [
22+
'src/styles.scss',
23+
'src/styles-linked.scss',
24+
];
25+
});
26+
27+
await ng('build');
28+
await expectFileToMatch('dist/test-project/styles.css', 'red');
29+
await expectFileToMatch('dist/test-project/styles.css', 'blue');
30+
31+
await ng('build', '--preserve-symlinks');
32+
await expectFileToMatch('dist/test-project/styles.css', 'red');
33+
await expectFileToMatch('dist/test-project/styles.css', 'blue');
34+
}

0 commit comments

Comments
 (0)