Skip to content

fix(cdk/overlay): ensure re-exported transitive Dir directive can be imported #30679

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

Merged
merged 1 commit into from
Mar 21, 2025
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
1 change: 1 addition & 0 deletions integration/module-tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module_test(
"//src/cdk:npm_package": "src/cdk/npm_package",
"//src/material:npm_package": "src/material/npm_package",
},
shard_count = 4,
skipped_entry_points = [
# This entry-point is JIT and would fail the AOT test.
"@angular/material/dialog/testing",
Expand Down
3 changes: 2 additions & 1 deletion integration/module-tests/index.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//js:defs.bzl", "js_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

def module_test(name, npm_packages, skipped_entry_points = [], additional_deps = []):
def module_test(name, npm_packages, skipped_entry_points = [], additional_deps = [], **kwargs):
write_file(
name = "%s_config" % name,
out = "%s_config.json" % name,
Expand All @@ -21,4 +21,5 @@ def module_test(name, npm_packages, skipped_entry_points = [], additional_deps =
] + additional_deps + [pkg[0] for pkg in npm_packages.items()],
entry_point = ":index.mjs",
fixed_args = ["$(rootpath :%s_config)" % name],
**kwargs
)
87 changes: 53 additions & 34 deletions integration/module-tests/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,38 @@ async function main() {
config.packages.map(pkgPath => findAllEntryPointsAndExportedModules(pkgPath)),
);

const exports = packages
const allExports = packages
.map(p => p.moduleExports)
.flat()
.filter(e => !config.skipEntryPoints.includes(e.importPath));
.filter(e => !config.skipEntryPoints.includes(e.importPath))
.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));

const testFile = `
import {NgModule, Component} from '@angular/core';
${exports.map(e => `import {${e.symbolName}} from '${e.importPath}';`).join('\n')}
// Distribute the exports based on the current test shard.
// Controlled via Bazel's `shard_count` attribute. See:
// https://bazel.build/reference/test-encyclopedia#initial-conditions.
const testShardIndex =
process.env['TEST_SHARD_INDEX'] !== undefined ? Number(process.env['TEST_SHARD_INDEX']) : 0;
const testMaxShards =
process.env['TEST_TOTAL_SHARDS'] !== undefined ? Number(process.env['TEST_TOTAL_SHARDS']) : 1;
const testChunkSize = Math.ceil(allExports.length / testMaxShards);
const testChunkStart = testChunkSize * testShardIndex;
const shardExports = allExports.slice(testChunkStart, testChunkStart + testChunkSize);

@NgModule({
exports: [
${exports.map(e => e.symbolName).join(', ')}
]
})
export class TestModule {}
const testFiles = shardExports.map(e => ({
content: `
import {NgModule, Component} from '@angular/core';
import {${e.symbolName}} from '${e.importPath}';

@Component({imports: [TestModule], template: ''})
export class TestComponent {}
`;
@NgModule({
exports: [${e.symbolName}]
})
export class TestModule {}

await fs.writeFile(path.join(tmpDir, 'test.ts'), testFile);
@Component({imports: [TestModule], template: ''})
export class TestComponent {}
`,
path: path.join(tmpDir, `${e.symbolName.toLowerCase()}.ts`),
}));

// Prepare node modules to resolve e.g. `@angular/core`
await fs.symlink(path.resolve('./node_modules'), path.join(tmpDir, 'node_modules'));
Expand All @@ -47,26 +58,34 @@ async function main() {
await fs.symlink(path.resolve(packagePath), `./node_modules/${name}`);
}

const result = performCompilation({
options: {
rootDir: tmpDir,
skipLibCheck: true,
noEmit: true,
module: ts.ModuleKind.ESNext,
moduleResolution: ts.ModuleResolutionKind.Bundler,
strictTemplates: true,
preserveSymlinks: true,
strict: true,
// Note: HMR is needed as it will disable the Angular compiler's tree-shaking of used
// directives/components. This is critical for this test as it allows us to simply all
// modules and automatically validate that all symbols are reachable/importable.
_enableHmr: true,
},
rootNames: [path.join(tmpDir, 'test.ts')],
});
const diagnostics: ts.Diagnostic[] = [];

for (const testFile of testFiles) {
await fs.writeFile(testFile.path, testFile.content);

const result = performCompilation({
options: {
rootDir: tmpDir,
skipLibCheck: true,
noEmit: true,
module: ts.ModuleKind.ESNext,
moduleResolution: ts.ModuleResolutionKind.Bundler,
strictTemplates: true,
preserveSymlinks: true,
strict: true,
// Note: HMR is needed as it will disable the Angular compiler's tree-shaking of used
// directives/components. This is critical for this test as it allows us to simply all
// modules and automatically validate that all symbols are reachable/importable.
_enableHmr: true,
},
rootNames: [testFile.path],
});

diagnostics.push(...result.diagnostics);
}

console.error(
ts.formatDiagnosticsWithColorAndContext(result.diagnostics, {
ts.formatDiagnosticsWithColorAndContext(diagnostics, {
getCanonicalFileName: f => f,
getCurrentDirectory: () => '/',
getNewLine: () => '\n',
Expand All @@ -75,7 +94,7 @@ async function main() {

await fs.rm(tmpDir, {recursive: true, force: true, maxRetries: 2});

if (result.diagnostics.length > 0) {
if (diagnostics.length > 0) {
process.exitCode = 1;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cdk/overlay/overlay-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ export {
CdkVirtualScrollableWindow as ɵɵCdkVirtualScrollableWindow,
CdkVirtualScrollableElement as ɵɵCdkVirtualScrollableElement,
} from '../scrolling';
export {Dir as ɵɵDir} from '../bidi';
Loading