Skip to content

Commit

Permalink
Fix tsConfig paths not resolving for Angular >=12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Marklb committed Dec 3, 2021
1 parent 9b5a803 commit f384c0e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 3 deletions.
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

0 comments on commit f384c0e

Please sign in to comment.