Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): support following symlinked asse…
Browse files Browse the repository at this point in the history
…t directories

By default subdirectories within a symlinked directory are not searched by a glob.  The new `followSymlinks` option for the longhand form of the `assets` browser builder option now allows opting in to search such subdirectories.
  • Loading branch information
clydin authored and alan-agius4 committed Oct 21, 2020
1 parent ff7edce commit cc723d8
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
10 changes: 10 additions & 0 deletions packages/angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,11 @@
{
"type": "object",
"properties": {
"followSymlinks": {
"type": "boolean",
"default": false,
"description": "Allow glob patterns to follow symlink directories. This allows subdirectories of the symlink to be searched."
},
"glob": {
"type": "string",
"description": "The pattern to match."
Expand Down Expand Up @@ -1586,6 +1591,11 @@
{
"type": "object",
"properties": {
"followSymlinks": {
"type": "boolean",
"default": false,
"description": "Allow glob patterns to follow symlink directories. This allows subdirectories of the symlink to be searched."
},
"glob": {
"type": "string",
"description": "The pattern to match."
Expand Down
5 changes: 5 additions & 0 deletions packages/angular_devkit/build_angular/src/browser/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@
{
"type": "object",
"properties": {
"followSymlinks": {
"type": "boolean",
"default": false,
"description": "Allow glob patterns to follow symlink directories. This allows subdirectories of the symlink to be searched."
},
"glob": {
"type": "string",
"description": "The pattern to match."
Expand Down
10 changes: 9 additions & 1 deletion packages/angular_devkit/build_angular/src/utils/copy-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ function globAsync(pattern: string, options: glob.IOptions) {
}

export async function copyAssets(
entries: { glob: string; ignore?: string[]; input: string; output: string; flatten?: boolean }[],
entries: {
glob: string;
ignore?: string[];
input: string;
output: string;
flatten?: boolean;
followSymlinks?: boolean;
}[],
basePaths: Iterable<string>,
root: string,
changed?: Set<string>,
Expand All @@ -31,6 +38,7 @@ export async function copyAssets(
dot: true,
nodir: true,
ignore: entry.ignore ? defaultIgnore.concat(entry.ignore) : defaultIgnore,
follow: entry.followSymlinks,
});

const directoryExists = new Set<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
force: true,
globOptions: {
dot: true,
followSymbolicLinks: !!asset.followSymlinks,
ignore: [
'.gitkeep',
'**/.DS_Store',
Expand Down
37 changes: 37 additions & 0 deletions tests/legacy-cli/e2e/tests/build/assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as fs from 'fs';
import { expectFileToExist, expectFileToMatch, writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';

export default async function () {
await writeFile('src/assets/.file', '');
await writeFile('src/assets/test.abc', 'hello world');

await ng('build');

await expectFileToExist('dist/test-project/favicon.ico');
await expectFileToExist('dist/test-project/assets/.file');
await expectFileToMatch('dist/test-project/assets/test.abc', 'hello world');
await expectToFail(() => expectFileToExist('dist/test-project/assets/.gitkeep'));

// Ensure `followSymlinks` option follows symlinks
await updateJsonFile('angular.json', workspaceJson => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect['build'].options.assets = [{ glob: '**/*', input: 'src/assets', output: 'assets', followSymlinks: true }];
});
fs.mkdirSync('dirToSymlink/subdir1', { recursive: true });
fs.mkdirSync('dirToSymlink/subdir2/subsubdir1', { recursive: true });
fs.writeFileSync('dirToSymlink/a.txt', '');
fs.writeFileSync('dirToSymlink/subdir1/b.txt', '');
fs.writeFileSync('dirToSymlink/subdir2/c.txt', '');
fs.writeFileSync('dirToSymlink/subdir2/subsubdir1/d.txt', '');
fs.symlinkSync(process.cwd() + '/dirToSymlink', 'src/assets/symlinkDir');

await ng('build');

await expectFileToExist('dist/test-project/assets/symlinkDir/a.txt');
await expectFileToExist('dist/test-project/assets/symlinkDir/subdir1/b.txt');
await expectFileToExist('dist/test-project/assets/symlinkDir/subdir2/c.txt');
await expectFileToExist('dist/test-project/assets/symlinkDir/subdir2/subsubdir1/d.txt');
}
16 changes: 0 additions & 16 deletions tests/legacy-cli/e2e/tests/misc/assets.ts

This file was deleted.

0 comments on commit cc723d8

Please sign in to comment.