Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular: Fix tsConfig paths not resolving for Angular >=12.2 #16882

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"projects": {
"foo-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"build": {
"options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"projects": {
"foo-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"build": {
"options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"projects": {
"foo-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"build": {
"options": {
Expand All @@ -14,6 +15,7 @@
},
"no-confs-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"target-build": {
"options": {
Expand All @@ -25,6 +27,7 @@
},
"no-target-conf-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"target-build": {
"options": {
Expand All @@ -41,6 +44,7 @@
},
"target-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"target-build": {
"options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"projects": {
"foo-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"build": {
"options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"projects": {
"foo-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"build": {
"options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"projects": {
"foo-project": {
"root": "",
"sourceRoot": "src",
"architect": {
"build": {
"options": {
Expand Down
7 changes: 7 additions & 0 deletions app/angular/src/server/angular-cli-webpack-12.2.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
getStylesConfig,
getTypeScriptConfig,
} = require('@angular-devkit/build-angular/src/webpack/configs');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

const { filterOutStylingRules } = require('./utils/filter-out-styling-rules');

Expand Down Expand Up @@ -65,6 +66,12 @@ exports.getWebpackConfig = async (baseConfig, { builderOptions, builderContext }
const resolve = {
...baseConfig.resolve,
modules: Array.from(new Set([...baseConfig.resolve.modules, ...cliConfig.resolve.modules])),
plugins: [
new TsconfigPathsPlugin({
configFile: builderOptions.tsConfig,
mainFields: ['browser', 'module', 'main'],
}),
],
};

return {
Expand Down
7 changes: 7 additions & 0 deletions app/angular/src/server/angular-cli-webpack-13.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
getStylesConfig,
getTypescriptWorkerPlugin,
} = require('@angular-devkit/build-angular/src/webpack/configs');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

const { filterOutStylingRules } = require('./utils/filter-out-styling-rules');

Expand Down Expand Up @@ -65,6 +66,12 @@ exports.getWebpackConfig = async (baseConfig, { builderOptions, builderContext }
const resolve = {
...baseConfig.resolve,
modules: Array.from(new Set([...baseConfig.resolve.modules, ...cliConfig.resolve.modules])),
plugins: [
new TsconfigPathsPlugin({
configFile: builderOptions.tsConfig,
mainFields: ['browser', 'module', 'main'],
}),
],
};

return {
Expand Down
2 changes: 1 addition & 1 deletion app/angular/src/server/angular-devkit-build-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const buildWebpackConfigOptions = async (
// The dependency of `@angular-devkit/build-angular` to `@angular-devkit/core` is not exactly the same version as the one for storybook (node modules of node modules ^^)
logger: (createConsoleLogger() as unknown) as WebpackConfigOptions['logger'],
projectRoot: getSystemPath(projectRootNormalized),
sourceRoot: getSystemPath(sourceRootNormalized),
sourceRoot: sourceRootNormalized ? getSystemPath(sourceRootNormalized) : undefined,
buildOptions,
tsConfig,
tsConfigPath,
Expand Down
13 changes: 11 additions & 2 deletions app/angular/src/server/framework-preset-angular-cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable jest/no-interpolation-in-snapshots */
import { Configuration } from 'webpack';
import { logger } from '@storybook/node-logger';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import { webpackFinal } from './framework-preset-angular-cli';
import { PresetOptions } from './options';

Expand Down Expand Up @@ -189,7 +190,11 @@ describe('framework-preset-angular-cli', () => {
...baseWebpackConfig.resolve,
modules: expect.arrayContaining(baseWebpackConfig.resolve.modules),
// the base resolve.plugins are not kept 🤷‍♂️
plugins: expect.not.arrayContaining(baseWebpackConfig.resolve.plugins),
plugins: expect.arrayContaining([
expect.objectContaining({
absoluteBaseUrl: expect.any(String),
} as TsconfigPathsPlugin),
]),
},
resolveLoader: expect.anything(),
});
Expand Down Expand Up @@ -480,7 +485,11 @@ describe('framework-preset-angular-cli', () => {
...baseWebpackConfig.resolve,
modules: expect.arrayContaining(baseWebpackConfig.resolve.modules),
// the base resolve.plugins are not kept 🤷‍♂️
plugins: expect.not.arrayContaining(baseWebpackConfig.resolve.plugins),
plugins: expect.arrayContaining([
expect.objectContaining({
absoluteBaseUrl: expect.any(String),
} as TsconfigPathsPlugin),
]),
},
resolveLoader: expect.anything(),
});
Expand Down