Skip to content

Commit c033642

Browse files
committed
feat(config): set new defaults for transformAliasedImportPaths
this commit updates the default values for the `transformAliasedImportPaths` and `transformAliasedImportPathsInCollection` configuration fields. both are being updated to be set to `true` if neither a `true` nor `false` value is provided (previously `false` if `false` or nothing was provided). the latter of the two is used to set the former for, hence its new default. by setting both of these new defaults to `true`, the hope is that stencil configuration will be simplified for projects using `paths` in their `tsconfig.json` STENCIL-829 BREAKING CHANGE: `transformAliasedImportPaths` and `transformAliasedPathsInCollection` both default to `true`. To opt-out of these new defaults, both may be set to `false` in `stencil.config.ts`. See https://stenciljs.com/docs/introduction/upgrading-to-stencil-four#transformaliasedimportpaths and https://stenciljs.com/docs/introduction/upgrading-to-stencil-four#transformaliasedimportpathsincollection (respectively) for more information
1 parent 4878adc commit c033642

12 files changed

+100
-13
lines changed

BREAKING_CHANGES.md

+79
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,92 @@ This is a comprehensive list of the breaking changes introduced in the major ver
1212
## Stencil v4.0.0
1313

1414
- [General](#general)
15+
- [New Configuration Defaults](#new-configuration-defaults)
16+
- [transformAliasedImportPaths](#transformaliasedimportpaths)
17+
- [transformAliasedImportPathsInCollection](#transformaliasedimportpathsincollection)
1518
- [In Browser Compilation Support Removed](#in-browser-compilation-support-removed)
1619
- [Legacy Context and Connect APIs Removed](#legacy-context-and-connect-APIs-removed)
1720
- [Legacy Browser Support Removed](#legacy-browser-support-removed)
1821
- [Drop Node 14 Support](#drop-node-14-support)
1922

2023
### General
2124

25+
#### New Configuration Defaults
26+
Starting with Stencil v4.0.0, the default configuration values have changed for a few configuration options.
27+
The following sections lay out the configuration options that have changed, their new default values, and ways to opt-out of the new behavior (if applicable).
28+
29+
##### `transformAliasedImportPaths`
30+
31+
TypeScript projects have the ability to specify a path aliases via the [`paths` configuration in their `tsconfig.json`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) like so:
32+
```json title="tsconfig.json"
33+
{
34+
"compilerOptions": {
35+
"baseUrl": ".",
36+
"paths": {
37+
"@utils": ["src/utils/index.ts"]
38+
}
39+
}
40+
}
41+
```
42+
In the example above, `"@utils"` would be mapped to the string `"src/utils/index.ts"` when TypeScript performs type resolution.
43+
The TypeScript compiler does not however, transform these paths from their keys to their values as a part of its output.
44+
Instead, it relies on a bundler/loader to do the transformation.
45+
46+
The ability to transform path aliases was introduced in [Stencil v3.1.0](https://github.com/ionic-team/stencil/releases/tag/v3.1.0) as an opt-in feature.
47+
Previously, users had to explicitly enable this functionality in their `stencil.config.ts` file with `transformAliasedImportPaths`:
48+
```ts title="stencil.config.ts - enabling 'transformAliasedImportPaths' in Stencil v3.1.0"
49+
import { Config } from '@stencil/core';
50+
51+
export const config: Config = {
52+
transformAliasedImportPaths: true,
53+
// ...
54+
};
55+
```
56+
57+
Starting with Stencil v4.0.0, this feature is enabled by default.
58+
Projects that had previously enabled this functionality that are migrating from Stencil v3.1.0+ may safely remove the flag from their Stencil configuration file(s).
59+
60+
For users that run into issues with this new default, we encourage you to file a [new issue on the Stencil GitHub repo](https://github.com/ionic-team/stencil/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=bug%3A+).
61+
As a workaround, this flag can be set to `false` to disable the default functionality.
62+
```ts title="stencil.config.ts - disabling 'transformAliasedImportPaths' in Stencil v4.0.0"
63+
import { Config } from '@stencil/core';
64+
65+
export const config: Config = {
66+
transformAliasedImportPaths: false,
67+
// ...
68+
};
69+
```
70+
71+
For more information on this flag, please see the [configuration documentation](https://stenciljs.com/docs/config#transformaliasedimportpaths)
72+
73+
##### `transformAliasedImportPathsInCollection`
74+
75+
Introduced in [Stencil v2.18.0](https://github.com/ionic-team/stencil/releases/tag/v2.18.0), `transformAliasedImportPathsInCollection` is a configuration flag on the [`dist` output target](https://stenciljs.com/docs/distribution#transformaliasedimportpathsincollection).
76+
`transformAliasedImportPathsInCollection` transforms import paths, similar to [`transformAliasedImportPaths`](#transformaliasedimportpathsincollection).
77+
This flag however, only enables the functionality of `transformAliasedImportPaths` for collection output targets.
78+
79+
Starting with Stencil v4.0.0, this flag is enabled by default.
80+
Projects that had previously enabled this functionality that are migrating from Stencil v2.18.0+ may safely remove the flag from their Stencil configuration file(s).
81+
82+
For users that run into issues with this new default, we encourage you to file a [new issue on the Stencil GitHub repo](https://github.com/ionic-team/stencil/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=bug%3A+).
83+
As a workaround, this flag can be set to `false` to disable the default functionality.
84+
```ts title="stencil.config.ts - disabling 'transformAliasedImportPathsInCollection' in Stencil v4.0.0"
85+
import { Config } from '@stencil/core';
86+
87+
export const config: Config = {
88+
outputTargets: [
89+
{
90+
type: 'dist',
91+
transformAliasedImportPathsInCollection: false,
92+
},
93+
// ...
94+
]
95+
// ...
96+
};
97+
```
98+
99+
For more information on this flag, please see the [`dist` output target's documentation](https://stenciljs.com/docs/distribution#transformaliasedimportpathsincollection).
100+
22101
#### In Browser Compilation Support Removed
23102

24103
Prior to Stencil v4.0.0, components could be compiled from TSX to JS in the browser.

src/compiler/config/outputs/validate-collection.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isOutputTargetDistCollection } from '@utils';
1+
import { isBoolean, isOutputTargetDistCollection } from '@utils';
22

33
import type * as d from '../../../declarations';
44
import { getAbsolutePath } from '../config-utils';
@@ -18,7 +18,9 @@ export const validateCollection = (
1818
return userOutputs.filter(isOutputTargetDistCollection).map((outputTarget) => {
1919
return {
2020
...outputTarget,
21-
transformAliasedImportPaths: outputTarget.transformAliasedImportPaths ?? false,
21+
transformAliasedImportPaths: isBoolean(outputTarget.transformAliasedImportPaths)
22+
? outputTarget.transformAliasedImportPaths
23+
: true,
2224
dir: getAbsolutePath(config, outputTarget.dir ?? 'dist/collection'),
2325
};
2426
});

src/compiler/config/outputs/validate-dist.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ const validateOutputTargetDist = (config: d.ValidatedConfig, o: d.OutputTargetDi
137137
copy: validateCopy(o.copy ?? [], []),
138138
polyfills: isBoolean(o.polyfills) ? o.polyfills : undefined,
139139
empty: isBoolean(o.empty) ? o.empty : true,
140-
transformAliasedImportPathsInCollection: o.transformAliasedImportPathsInCollection ?? false,
140+
transformAliasedImportPathsInCollection: isBoolean(o.transformAliasedImportPathsInCollection)
141+
? o.transformAliasedImportPathsInCollection
142+
: false,
141143
isPrimaryPackageOutputTarget: o.isPrimaryPackageOutputTarget ?? false,
142144
};
143145

src/compiler/config/test/validate-config.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ describe('validation', () => {
110110
expect(config.transformAliasedImportPaths).toBe(bool);
111111
});
112112

113-
it('default transformAliasedImportPaths false', () => {
113+
it('defaults `transformAliasedImportPaths` to true', () => {
114114
const { config } = validateConfig(userConfig, bootstrapConfig);
115-
expect(config.transformAliasedImportPaths).toBe(false);
115+
expect(config.transformAliasedImportPaths).toBe(true);
116116
});
117117
});
118118

src/compiler/config/test/validate-output-dist-collection.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('validateDistCollectionOutputTarget', () => {
3131
empty: false,
3232
dir: defaultDir,
3333
collectionDir: null,
34-
transformAliasedImportPaths: false,
34+
transformAliasedImportPaths: true,
3535
},
3636
]);
3737
});
@@ -53,7 +53,7 @@ describe('validateDistCollectionOutputTarget', () => {
5353
empty: false,
5454
dir: '/my-dist',
5555
collectionDir: null,
56-
transformAliasedImportPaths: false,
56+
transformAliasedImportPaths: true,
5757
},
5858
]);
5959
});

src/compiler/config/test/validate-service-worker.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('validateServiceWorker', () => {
2222
rootDir: '/',
2323
sys: mockCompilerSystem(),
2424
testing: {},
25-
transformAliasedImportPaths: false,
25+
transformAliasedImportPaths: true,
2626
});
2727
});
2828

src/compiler/config/validate-config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export const validateConfig = (
8787
rollupConfig: validateRollupConfig(config),
8888
sys: config.sys ?? bootstrapConfig.sys ?? createNodeSys({ logger }),
8989
testing: config.testing ?? {},
90-
transformAliasedImportPaths: userConfig.transformAliasedImportPaths ?? false,
90+
transformAliasedImportPaths: isBoolean(userConfig.transformAliasedImportPaths)
91+
? userConfig.transformAliasedImportPaths
92+
: true,
9193
validatePrimaryPackageOutputTarget: userConfig.validatePrimaryPackageOutputTarget ?? false,
9294
...validatePaths(config),
9395
};

src/compiler/output-targets/test/output-targets-collection.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('Dist Collection output target', () => {
4747

4848
describe('transform aliased import paths', () => {
4949
// These tests ensure that the transformer for import paths is called regardless
50-
// of the config value (the function will decided whether or not to actually do anything) to avoid
50+
// of the config value (the function will decide whether or not to actually do anything) to avoid
5151
// a race condition with duplicate file writes
5252
it.each([true, false])(
5353
'calls function to transform aliased import paths when the output target config flag is `%s`',

src/declarations/stencil-public-compiler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface StencilConfig {
109109
* Sets whether or not Stencil should transform path aliases set in a project's
110110
* `tsconfig.json` from the assigned module aliases to resolved relative paths.
111111
*
112-
* This behavior is opt-in and hence this flag defaults to `false`.
112+
* This behavior defaults to `true`, but may be opted-out of by setting this flag to `false`.
113113
*/
114114
transformAliasedImportPaths?: boolean;
115115
/**
@@ -1912,7 +1912,7 @@ export interface OutputTargetDist extends OutputTargetValidationConfig {
19121912
* a project's `tsconfig.json` to relative import paths in the compiled output's
19131913
* `dist-collection` bundle if it is generated (i.e. `collectionDir` is set).
19141914
*
1915-
* Paths will be left in aliased format if `false` or `undefined`.
1915+
* Paths will be left in aliased format if `false`.
19161916
*
19171917
* @example
19181918
* // tsconfig.json

src/testing/mocks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function mockValidatedConfig(overrides: Partial<ValidatedConfig> = {}): V
4646
srcDir: '/src',
4747
sys: createTestingSystem(),
4848
testing: {},
49-
transformAliasedImportPaths: false,
49+
transformAliasedImportPaths: true,
5050
rollupConfig: {
5151
inputOptions: {},
5252
outputOptions: {},

test/browser-compile/stencil.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export const config: Config = {
2626
},
2727
],
2828
enableCache: false,
29+
transformAliasedImportPaths: false,
2930
};

test/end-to-end/stencil.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ export const config: Config = {
6060
hashFileNames: false,
6161
buildEs5: 'prod',
6262
sourceMap: true,
63+
transformAliasedImportPaths: false,
6364
};

0 commit comments

Comments
 (0)