Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 5d6e73e

Browse files
committed
refactor: use workspace relative paths everywhere in architect
1 parent f2473e6 commit 5d6e73e

File tree

30 files changed

+187
-165
lines changed

30 files changed

+187
-165
lines changed

packages/angular_devkit/architect/src/architect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
logging,
1919
normalize,
2020
parseJson,
21-
resolve,
2221
virtualFs,
2322
} from '@angular-devkit/core';
2423
import { resolve as nodeResolve } from '@angular-devkit/core/node';
@@ -163,7 +162,7 @@ export class Architect {
163162
}
164163

165164
const builderConfiguration: BuilderConfiguration<OptionsT> = {
166-
root: resolve(this._workspace.root, normalize(project.root)),
165+
root: project.root,
167166
projectType: project.projectType,
168167
builder: target.builder,
169168
options: {
@@ -186,6 +185,7 @@ export class Architect {
186185
logger: new logging.NullLogger(),
187186
architect: this,
188187
host: this._workspace.host,
188+
workspace: this._workspace,
189189
...partialContext,
190190
};
191191

packages/angular_devkit/architect/src/architect_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { experimental, join, normalize } from '@angular-devkit/core';
9+
import { experimental, normalize } from '@angular-devkit/core';
1010
import { NodeJsSyncHost } from '@angular-devkit/core/node';
1111
import { concatMap, tap, toArray } from 'rxjs/operators';
1212
import { BrowserTargetOptions } from '../test/browser';
@@ -66,7 +66,7 @@ describe('Architect', () => {
6666
const targetSpec = { project: 'app', target: 'browser', configuration: 'prod' };
6767
architect.getBuilderConfiguration<BrowserTargetOptions>(targetSpec).pipe(
6868
tap(builderConfig => {
69-
expect(builderConfig.root).toBe(join(root, 'app'));
69+
expect(builderConfig.root).toBe('app');
7070
expect(builderConfig.projectType).toBe('application');
7171
expect(builderConfig.builder).toBe('../test:browser');
7272
expect(builderConfig.options.browserOption).toBe(1);

packages/angular_devkit/architect/src/builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { JsonObject, Path, logging, virtualFs } from '@angular-devkit/core';
9+
import { JsonObject, Path, experimental, logging, virtualFs } from '@angular-devkit/core';
1010
import { Observable } from 'rxjs/Observable';
1111
import { Architect, BuilderConfiguration } from './architect';
1212

1313

1414
export interface BuilderContext {
1515
logger: logging.Logger;
1616
host: virtualFs.Host<{}>;
17+
workspace: experimental.workspace.Workspace;
1718
architect: Architect;
1819
}
1920

packages/angular_devkit/build_webpack/src/angular-cli-files/models/build-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface BuildOptions {
4040
}
4141

4242
export interface WebpackConfigOptions<T extends BuildOptions = BuildOptions> {
43+
root: string;
4344
projectRoot: string;
4445
buildOptions: T;
4546
appConfig: any;

packages/angular_devkit/build_webpack/src/angular-cli-files/models/webpack-configs/browser.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,22 @@ import { WebpackConfigOptions } from '../build-options';
2020
+ */
2121

2222
export function getBrowserConfig(wco: WebpackConfigOptions) {
23-
const { projectRoot, buildOptions, appConfig } = wco;
23+
const { root, projectRoot, buildOptions, appConfig } = wco;
2424

25-
const appRoot = path.resolve(projectRoot, appConfig.root);
2625

2726
let extraPlugins: any[] = [];
2827

2928
// figure out which are the lazy loaded entry points
3029
const lazyChunks = lazyChunksFilter([
31-
...extraEntryParser(appConfig.scripts, appRoot, 'scripts'),
32-
...extraEntryParser(appConfig.styles, appRoot, 'styles')
30+
...extraEntryParser(appConfig.scripts, root, 'scripts'),
31+
...extraEntryParser(appConfig.styles, root, 'styles')
3332
]);
3433

3534
// TODO: Enable this once HtmlWebpackPlugin supports Webpack 4
3635
const generateIndexHtml = false;
3736
if (generateIndexHtml) {
3837
extraPlugins.push(new HtmlWebpackPlugin({
39-
template: path.resolve(appRoot, appConfig.index),
38+
template: path.resolve(root, appConfig.index),
4039
filename: path.resolve(buildOptions.outputPath, appConfig.index),
4140
chunksSortMode: packageChunkSort(appConfig),
4241
excludeChunks: lazyChunks,
@@ -87,7 +86,7 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
8786
}));
8887
}
8988

90-
const globalStylesEntries = extraEntryParser(appConfig.styles, appRoot, 'styles')
89+
const globalStylesEntries = extraEntryParser(appConfig.styles, root, 'styles')
9190
.map(style => style.entry);
9291

9392
return {
@@ -121,8 +120,8 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
121120
},
122121
plugins: extraPlugins.concat([
123122
new IndexHtmlWebpackPlugin({
124-
input: path.resolve(appRoot, appConfig.index),
125-
output: appConfig.index,
123+
input: path.resolve(root, appConfig.index),
124+
output: path.relative(projectRoot, path.resolve(root, appConfig.index)),
126125
baseHref: buildOptions.baseHref,
127126
entrypoints: generateEntryPoints(appConfig),
128127
deployUrl: buildOptions.deployUrl,

packages/angular_devkit/build_webpack/src/angular-cli-files/models/webpack-configs/common.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ const resolve = require('resolve');
3333
*/
3434

3535
export function getCommonConfig(wco: WebpackConfigOptions) {
36-
const { projectRoot, buildOptions, appConfig } = wco;
36+
const { root, projectRoot, buildOptions, appConfig } = wco;
3737

38-
const appRoot = path.resolve(projectRoot, appConfig.root);
3938
const nodeModules = findUp('node_modules', projectRoot);
4039
if (!nodeModules) {
4140
throw new Error('Cannot locate node_modules directory.')
@@ -45,19 +44,19 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
4544
let entryPoints: { [key: string]: string[] } = {};
4645

4746
if (appConfig.main) {
48-
entryPoints['main'] = [path.resolve(appRoot, appConfig.main)];
47+
entryPoints['main'] = [path.resolve(root, appConfig.main)];
4948
}
5049

5150
if (appConfig.polyfills) {
52-
entryPoints['polyfills'] = [path.resolve(appRoot, appConfig.polyfills)];
51+
entryPoints['polyfills'] = [path.resolve(root, appConfig.polyfills)];
5352
}
5453

5554
// determine hashing format
5655
const hashFormat = getOutputHashFormat(buildOptions.outputHashing as any);
5756

5857
// process global scripts
5958
if (appConfig.scripts.length > 0) {
60-
const globalScripts = extraEntryParser(appConfig.scripts, appRoot, 'scripts');
59+
const globalScripts = extraEntryParser(appConfig.scripts, root, 'scripts');
6160
const globalScriptsByEntry = globalScripts
6261
.reduce((prev: { entry: string, paths: string[], lazy: boolean }[], curr) => {
6362

@@ -83,7 +82,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
8382
extraPlugins.push(new ScriptsWebpackPlugin({
8483
name: script.entry,
8584
sourceMap: buildOptions.sourceMap,
86-
filename: `${script.entry}${hash}.js`,
85+
filename: `${path.basename(script.entry)}${hash}.js`,
8786
scripts: script.paths,
8887
basePath: projectRoot,
8988
}));
@@ -96,8 +95,9 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
9695
// Convert all string assets to object notation.
9796
asset = typeof asset === 'string' ? { glob: asset } : asset;
9897
// Add defaults.
99-
// Input is always resolved relative to the appRoot.
100-
asset.input = path.resolve(appRoot, asset.input || '').replace(/\\/g, '/');
98+
// Input is always resolved relative to the projectRoot.
99+
// TODO: add smart defaults to schema to use project root as default.
100+
asset.input = path.resolve(root, asset.input || projectRoot).replace(/\\/g, '/');
101101
asset.output = asset.output || '';
102102
asset.glob = asset.glob || '';
103103

@@ -152,6 +152,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
152152
}
153153
};
154154
});
155+
155156
const copyWebpackPluginOptions = { ignore: ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'] };
156157

157158
const copyWebpackPluginInstance = new CopyWebpackPlugin(copyWebpackPluginPatterns,
@@ -223,7 +224,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
223224
resolve: {
224225
extensions: ['.ts', '.js'],
225226
symlinks: !buildOptions.preserveSymlinks,
226-
modules: [appRoot, 'node_modules'],
227+
modules: [projectRoot, 'node_modules'],
227228
alias
228229
},
229230
resolveLoader: {
@@ -232,7 +233,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
232233
context: projectRoot,
233234
entry: entryPoints,
234235
output: {
235-
path: path.resolve(projectRoot, buildOptions.outputPath as string),
236+
path: path.resolve(root, buildOptions.outputPath as string),
236237
publicPath: buildOptions.deployUrl,
237238
filename: `[name]${hashFormat.chunk}.js`,
238239
},

packages/angular_devkit/build_webpack/src/angular-cli-files/models/webpack-configs/styles.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ interface PostcssUrlAsset {
3838
}
3939

4040
export function getStylesConfig(wco: WebpackConfigOptions) {
41-
const { projectRoot, buildOptions, appConfig } = wco;
41+
const { root, projectRoot, buildOptions, appConfig } = wco;
4242

43-
const appRoot = path.resolve(projectRoot, appConfig.root);
43+
// const appRoot = path.resolve(projectRoot, appConfig.root);
4444
const entryPoints: { [key: string]: string[] } = {};
4545
const globalStylePaths: string[] = [];
4646
const extraPlugins: any[] = [];
@@ -158,15 +158,15 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
158158
&& appConfig.stylePreprocessorOptions.includePaths.length > 0
159159
) {
160160
appConfig.stylePreprocessorOptions.includePaths.forEach((includePath: string) =>
161-
includePaths.push(path.resolve(appRoot, includePath)));
161+
includePaths.push(path.resolve(root, includePath)));
162162
lessPathOptions = {
163163
paths: includePaths,
164164
};
165165
}
166166

167167
// process global styles
168168
if (appConfig.styles.length > 0) {
169-
const globalStyles = extraEntryParser(appConfig.styles, appRoot, 'styles');
169+
const globalStyles = extraEntryParser(appConfig.styles, root, 'styles');
170170
// add style entry points
171171
globalStyles.forEach(style =>
172172
entryPoints[style.entry as any]

packages/angular_devkit/build_webpack/src/angular-cli-files/models/webpack-configs/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { WebpackConfigOptions, WebpackTestOptions } from '../build-options';
1818

1919

2020
export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
21-
const { projectRoot, buildOptions, appConfig } = wco;
21+
const { root, buildOptions, appConfig } = wco;
2222

2323
const extraRules: any[] = [];
2424
const extraPlugins: any[] = [];
@@ -34,7 +34,7 @@ export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
3434
if (codeCoverageExclude) {
3535
codeCoverageExclude.forEach((excludeGlob: string) => {
3636
const excludeFiles = glob
37-
.sync(path.join(projectRoot, excludeGlob), { nodir: true })
37+
.sync(path.join(root, excludeGlob), { nodir: true })
3838
.map(file => path.normalize(file));
3939
exclude.push(...excludeFiles);
4040
});
@@ -57,7 +57,7 @@ export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
5757
},
5858
devtool: buildOptions.sourceMap ? 'inline-source-map' : 'eval',
5959
entry: {
60-
main: path.resolve(projectRoot, appConfig.root, appConfig.main)
60+
main: path.resolve(root, appConfig.main)
6161
},
6262
module: {
6363
rules: [].concat(extraRules as any)

packages/angular_devkit/build_webpack/src/angular-cli-files/models/webpack-configs/typescript.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ const webpackLoader: string = g['angularCliIsLocal']
2020

2121

2222
function _createAotPlugin(wco: WebpackConfigOptions, options: any, useMain = true) {
23-
const { appConfig, projectRoot, buildOptions } = wco;
24-
const appRoot = path.resolve(projectRoot, appConfig.root);
23+
const { appConfig, root, buildOptions } = wco;
2524
options.compilerOptions = options.compilerOptions || {};
2625

2726
if (wco.buildOptions.preserveSymlinks) {
@@ -71,27 +70,26 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any, useMain = tru
7170
const envFile = appConfig.environments[buildOptions.environment as any];
7271

7372
hostReplacementPaths = {
74-
[path.resolve(appRoot, sourcePath)]: path.resolve(appRoot, envFile)
73+
[path.resolve(root, sourcePath)]: path.resolve(root, envFile)
7574
};
7675
}
7776

7877
let i18nInFile = buildOptions.i18nFile
79-
? path.resolve(appRoot, buildOptions.i18nFile)
78+
? path.resolve(root, buildOptions.i18nFile)
8079
: undefined;
8180

8281
const additionalLazyModules: { [module: string]: string } = {};
8382
if (appConfig.lazyModules) {
8483
for (const lazyModule of appConfig.lazyModules) {
8584
additionalLazyModules[lazyModule] = path.resolve(
86-
projectRoot,
87-
appConfig.root,
85+
root,
8886
lazyModule,
8987
);
9088
}
9189
}
9290

9391
const pluginOptions: AngularCompilerPluginOptions = {
94-
mainPath: useMain ? path.join(projectRoot, appConfig.root, appConfig.main) : undefined,
92+
mainPath: useMain ? path.join(root, appConfig.main) : undefined,
9593
i18nInFile: i18nInFile,
9694
i18nInFormat: buildOptions.i18nFormat,
9795
i18nOutFile: buildOptions.i18nOutFile,
@@ -110,8 +108,8 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any, useMain = tru
110108
}
111109

112110
export function getNonAotConfig(wco: WebpackConfigOptions) {
113-
const { appConfig, projectRoot } = wco;
114-
const tsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.tsConfig);
111+
const { appConfig, root } = wco;
112+
const tsConfigPath = path.resolve(root, appConfig.tsConfig);
115113

116114
return {
117115
module: { rules: [{ test: /\.ts$/, loader: webpackLoader }] },
@@ -120,8 +118,8 @@ export function getNonAotConfig(wco: WebpackConfigOptions) {
120118
}
121119

122120
export function getAotConfig(wco: WebpackConfigOptions) {
123-
const { projectRoot, buildOptions, appConfig } = wco;
124-
const tsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.tsConfig);
121+
const { root, buildOptions, appConfig } = wco;
122+
const tsConfigPath = path.resolve(root, appConfig.tsConfig);
125123

126124
const loaders: any[] = [webpackLoader];
127125
if (buildOptions.buildOptimizer) {
@@ -140,15 +138,15 @@ export function getAotConfig(wco: WebpackConfigOptions) {
140138
}
141139

142140
export function getNonAotTestConfig(wco: WebpackConfigOptions) {
143-
const { projectRoot, appConfig } = wco;
144-
const tsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.tsConfig);
141+
const { root, appConfig } = wco;
142+
const tsConfigPath = path.resolve(root, appConfig.tsConfig);
145143

146144
let pluginOptions: any = { tsConfigPath, skipCodeGeneration: true };
147145

148146
if (appConfig.polyfills) {
149147
// TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
150148
// include 'polyfills.ts' in `tsconfig.spec.json'.
151-
const polyfillsPath = path.resolve(projectRoot, appConfig.root, appConfig.polyfills);
149+
const polyfillsPath = path.resolve(root, appConfig.polyfills);
152150
pluginOptions.singleFileIncludes = [polyfillsPath];
153151
}
154152

packages/angular_devkit/build_webpack/src/angular-cli-files/models/webpack-configs/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function extraEntryParser(
6969
if (extraEntry.output) {
7070
extraEntry.entry = extraEntry.output.replace(/\.(js|css)$/i, '');
7171
} else if (extraEntry.lazy) {
72-
extraEntry.entry = extraEntry.input.replace(/\.(js|css|scss|sass|less|styl)$/i, '');
72+
extraEntry.entry = path.basename(extraEntry.input.replace(/\.(js|css|scss|sass|less|styl)$/i, ''));
7373
} else {
7474
extraEntry.entry = defaultEntry;
7575
}

packages/angular_devkit/build_webpack/src/angular-cli-files/plugins/karma.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ function addKarmaFiles(files: any[], newFiles: any[], prepend = false) {
4949
}
5050

5151
const init: any = (config: any, emitter: any, customFileHandlers: any) => {
52-
const options: any = config.webpackBuildFacade.options;
53-
const appRoot = path.join(config.basePath, options.root);
54-
successCb = config.webpackBuildFacade.successCb;
55-
failureCb = config.webpackBuildFacade.failureCb;
52+
const options = config.buildWebpack.options;
53+
const projectRoot = config.buildWebpack.projectRoot;
54+
successCb = config.buildWebpack.successCb;
55+
failureCb = config.buildWebpack.failureCb;
5656

5757
config.reporters.unshift('@angular-devkit/build-webpack--event-reporter');
5858
// Add a reporter that fixes sourcemap urls.
@@ -78,8 +78,8 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
7878
// Convert all string patterns to Pattern type.
7979
pattern = typeof pattern === 'string' ? { glob: pattern } : pattern;
8080
// Add defaults.
81-
// Input is always resolved relative to the appRoot.
82-
pattern.input = path.resolve(appRoot, pattern.input || '');
81+
// Input is always resolved relative to the projectRoot.
82+
pattern.input = path.resolve(projectRoot, pattern.input || '');
8383
pattern.output = pattern.output || '';
8484
pattern.glob = pattern.glob || '';
8585

@@ -107,7 +107,7 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
107107
}
108108

109109
// Add webpack config.
110-
const webpackConfig = config.webpackBuildFacade.webpackConfig;
110+
const webpackConfig = config.buildWebpack.webpackConfig;
111111
const webpackMiddlewareConfig = {
112112
noInfo: true, // Hide webpack output because its noisy.
113113
watchOptions: { poll: options.poll },

0 commit comments

Comments
 (0)