mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: adopt moduleResolution: "bundler" (#64125)
This commit updates the TypeScript configuration across the project to use `moduleResolution: "bundler"`. This modernizes our module resolution strategy to align with current TypeScript best practices and bundler behaviors. The following changes are included: - Updated `tsconfig.json` files to set `moduleResolution` to `"bundler"`. - Updated the `rules_angular` bazel dependency to a version compatible with these changes. - Adjusted related test files and golden files to reflect the new module resolution strategy. PR Close #64125
This commit is contained in:
@@ -37,7 +37,7 @@ export function makeProgram(
|
||||
const compilerOptions = {
|
||||
noLib: true,
|
||||
experimentalDecorators: true,
|
||||
moduleResolution: ts.ModuleResolutionKind.Node10,
|
||||
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
||||
...options,
|
||||
};
|
||||
const compilerHost = new NgtscTestCompilerHost(fs, compilerOptions);
|
||||
|
||||
@@ -173,7 +173,7 @@ export function angularCoreDtsFiles(): TestFile[] {
|
||||
const directory = resolveFromRunfiles('_main/packages/core/npm_package');
|
||||
const dtsFiles = globSync('**/*.d.ts', {cwd: directory});
|
||||
|
||||
return (_angularCoreDts = dtsFiles.map((fileName) => ({
|
||||
return (_angularCoreDts = ['package.json', ...dtsFiles].map((fileName) => ({
|
||||
name: absoluteFrom(`/node_modules/@angular/core/${fileName}`),
|
||||
contents: readFileSync(path.join(directory, fileName), 'utf8'),
|
||||
})));
|
||||
|
||||
@@ -132,7 +132,7 @@ function getOptions(
|
||||
target: ts.ScriptTarget.ES2015,
|
||||
newLine: ts.NewLineKind.LineFeed,
|
||||
module: ts.ModuleKind.ES2015,
|
||||
moduleResolution: ts.ModuleResolutionKind.Node10,
|
||||
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
||||
typeRoots: ['node_modules/@types'],
|
||||
...convertedCompilerOptions.options,
|
||||
enableI18nLegacyMessageIdFormat: false,
|
||||
|
||||
@@ -97,7 +97,7 @@ export class NgtscTestEnvironment {
|
||||
"target": "es2015",
|
||||
"newLine": "lf",
|
||||
"module": "es2015",
|
||||
"moduleResolution": "node",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": ["es2015", "dom"],
|
||||
"typeRoots": ["node_modules/@types"]
|
||||
},
|
||||
|
||||
@@ -10016,7 +10016,7 @@ runInEachFileSystem((os: string) => {
|
||||
|
||||
it('should not error when an undecorated class from a declaration file is provided', () => {
|
||||
env.write(
|
||||
'node_modules/@angular/core/testing/index.d.ts',
|
||||
'node_modules/@angular/core/types/testing.d.ts',
|
||||
`
|
||||
export declare class Testability {
|
||||
}
|
||||
@@ -10041,7 +10041,7 @@ runInEachFileSystem((os: string) => {
|
||||
|
||||
it('should not error when an undecorated class without a constructor from a declaration file is provided via useClass', () => {
|
||||
env.write(
|
||||
'node_modules/@angular/core/testing/index.d.ts',
|
||||
'node_modules/@angular/core/types/testing.d.ts',
|
||||
`
|
||||
export declare class Testability {
|
||||
}
|
||||
@@ -10097,7 +10097,7 @@ runInEachFileSystem((os: string) => {
|
||||
// can be updated.
|
||||
xit('should error when an undecorated class with a non-trivial constructor in a declaration file is provided via useClass', () => {
|
||||
env.write(
|
||||
'node_modules/@angular/core/testing/index.d.ts',
|
||||
'node_modules/@angular/core/types/testing.d.ts',
|
||||
`
|
||||
export declare class NgZone {}
|
||||
|
||||
@@ -10129,7 +10129,7 @@ runInEachFileSystem((os: string) => {
|
||||
|
||||
it('should not error when an class with a factory definition and a non-trivial constructor in a declaration file is provided via useClass', () => {
|
||||
env.write(
|
||||
'node_modules/@angular/core/testing/index.d.ts',
|
||||
'node_modules/@angular/core/types/testing.d.ts',
|
||||
`
|
||||
import * as i0 from '@angular/core';
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ describe('definitions', () => {
|
||||
);
|
||||
expect(definitions.length).toEqual(3);
|
||||
assertTextSpans(definitions, ['transform']);
|
||||
assertFileNames(definitions, ['index.d.ts']);
|
||||
assertFileNames(definitions, ['fake_common.d.ts']);
|
||||
});
|
||||
|
||||
it('gets definitions for all inputs when attribute matches more than one', () => {
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
"strictTemplates": true,
|
||||
"strictInjectionParameters": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -905,7 +905,7 @@ describe('find references and rename locations', () => {
|
||||
|
||||
it('should find references', () => {
|
||||
const refs = getReferencesAtPosition(file)!;
|
||||
assertFileNames(refs, ['index.d.ts', 'prefix-pipe.ts', 'app.ts']);
|
||||
assertFileNames(refs, ['core.d.ts', 'prefix-pipe.ts', 'app.ts']);
|
||||
assertTextSpans(refs, ['transform', 'prefixPipe']);
|
||||
});
|
||||
|
||||
@@ -1830,7 +1830,7 @@ describe('find references and rename locations', () => {
|
||||
const refs = getReferencesAtPosition(file)!;
|
||||
expect(refs.length).toBe(7);
|
||||
assertTextSpans(refs, ['<div *ngFor="let item of items"></div>', 'NgForOf']);
|
||||
assertFileNames(refs, ['index.d.ts', 'app.ts']);
|
||||
assertFileNames(refs, ['fake_common.d.ts', 'app.ts']);
|
||||
});
|
||||
|
||||
it('should not support rename if directive is in a dts file', () => {
|
||||
|
||||
@@ -47,7 +47,7 @@ describe('type definitions', () => {
|
||||
expect(definitions!.length).toEqual(3);
|
||||
|
||||
assertTextSpans(definitions, ['transform']);
|
||||
assertFileNames(definitions, ['index.d.ts']);
|
||||
assertFileNames(definitions, ['fake_common.d.ts']);
|
||||
});
|
||||
|
||||
describe('inputs', () => {
|
||||
@@ -80,7 +80,7 @@ describe('type definitions', () => {
|
||||
expect(definitions!.length).toEqual(1);
|
||||
|
||||
assertTextSpans(definitions, ['InputSignal']);
|
||||
assertFileNames(definitions, ['index.d.ts']);
|
||||
assertFileNames(definitions, ['core.d.ts']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -189,7 +189,7 @@ describe('type definitions', () => {
|
||||
|
||||
expect(definitions.length).toBe(1);
|
||||
assertTextSpans(definitions, ['ModelSignal']);
|
||||
assertFileNames(definitions, ['index.d.ts']);
|
||||
assertFileNames(definitions, ['core.d.ts']);
|
||||
});
|
||||
|
||||
it('should return the definition for the event side of a two-way binding', () => {
|
||||
@@ -202,7 +202,7 @@ describe('type definitions', () => {
|
||||
|
||||
expect(definitions.length).toBe(1);
|
||||
assertTextSpans(definitions, ['ModelSignal']);
|
||||
assertFileNames(definitions, ['index.d.ts']);
|
||||
assertFileNames(definitions, ['core.d.ts']);
|
||||
});
|
||||
|
||||
it('should return the definition of a two-way binding', () => {
|
||||
@@ -215,7 +215,7 @@ describe('type definitions', () => {
|
||||
|
||||
expect(definitions.length).toBe(1);
|
||||
assertTextSpans(definitions, ['ModelSignal']);
|
||||
assertFileNames(definitions, ['index.d.ts']);
|
||||
assertFileNames(definitions, ['core.d.ts']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ function writeTsconfig(
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
experimentalDecorators: true,
|
||||
moduleResolution: 'node',
|
||||
moduleResolution: 'bundler',
|
||||
target: 'es2015',
|
||||
rootDir: '.',
|
||||
lib: ['dom', 'es2015'],
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"strict": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"moduleResolution": "node",
|
||||
"moduleResolution": "bundler",
|
||||
"module": "esnext",
|
||||
"target": "es2022",
|
||||
"lib": ["es2020", "es2022", "dom", "dom.iterable"],
|
||||
|
||||
Reference in New Issue
Block a user