Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): correctly resolve symlinked globa…
Browse files Browse the repository at this point in the history
…l styles entrypoints

With this change we resolve the global stylesheet entrypoint path to use the realpath instead of the symlink path.

Fixes #3500

(cherry picked from commit 1df8a3d)
  • Loading branch information
alan-agius4 authored and filipesilva committed Jan 6, 2021
1 parent a7535db commit 0b96aa4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Expand Up @@ -51,6 +51,11 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
resolvedPath = require.resolve(style.input, { paths: [root] });
} catch {}
}

if (!buildOptions.preserveSymlinks) {
resolvedPath = fs.realpathSync(resolvedPath);
}

// Add style entry points.
if (entryPoints[style.bundleName]) {
entryPoints[style.bundleName].push(resolvedPath);
Expand Down
34 changes: 34 additions & 0 deletions tests/legacy-cli/e2e/tests/build/styles/symlinked-global.ts
@@ -0,0 +1,34 @@
import { symlinkSync } from 'fs';
import { resolve } from 'path';
import { expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
import { ng } from '../../../utils/process';
import { updateJsonFile } from '../../../utils/project';

export default async function () {
await writeMultipleFiles({
'src/styles.scss': `p { color: red }`,
'src/styles-for-link.scss': `p { color: blue }`,
});

symlinkSync(
resolve('src/styles-for-link.scss'),
resolve('src/styles-linked.scss'),
'junction',
);

await updateJsonFile('angular.json', workspaceJson => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect.build.options.styles = [
'src/styles.scss',
'src/styles-linked.scss',
];
});

await ng('build');
await expectFileToMatch('dist/test-project/styles.css', 'red');
await expectFileToMatch('dist/test-project/styles.css', 'blue');

await ng('build', '--preserve-symlinks');
await expectFileToMatch('dist/test-project/styles.css', 'red');
await expectFileToMatch('dist/test-project/styles.css', 'blue');
}

0 comments on commit 0b96aa4

Please sign in to comment.