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

dts bundling produces broken metadata.json #29315

Closed
alexeagle opened this Issue Mar 14, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@alexeagle
Copy link
Contributor

alexeagle commented Mar 14, 2019

/cc @alan-agius4

in beta.7, the core package was published without dts bundling,
https://unpkg.com/@angular/core@8.0.0-beta.7/core.metadata.json:

"exports":[{"export":[{"name":"Type","as":"Type"}],"from":"./src/interface/type"},
...

this allowed us to run ngc on the node_modules directory to create working ngsummary files.

In beta.8, it changed: https://unpkg.com/@angular/core@8.0.0-beta.8/core.metadata.json

"exports":[{"export":[{"name":"Type","as":"Type"}],"from":"./core"},
...

which expresses a self-referential re-export.
This causes a self-export edge to appear in the ngsummary file as well.

Later, when running ngc, we'll read the bad data from the summary and infinite-loop trying to resolve the re-export

: RangeError: Maximum call stack size exceeded
    at String.replace (<anonymous>)
    at stripGeneratedFileSuffix (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:18711:25)
    at AotSummaryResolver.isLibraryFile (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:26072:44)
    at ToJsonSerializer.visitStaticSymbol (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:24037:38)
    at ToJsonSerializer.visitStaticSymbol (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:24046:34)
... more JSON serializing visitor frames...
    at ToJsonSerializer.visitStringMap (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:24027:52)
    at visitValue (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:2453:28)
    at ToJsonSerializer.processValue (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:24003:20)
    at ToJsonSerializer.addSummary (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:23916:50)
    at /usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:23947:39
    at Array.forEach (<anonymous>)
    at ToJsonSerializer.addSummary (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:23941:94)
    at /usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:23824:30
    at Array.forEach (<anonymous>)
    at serializeSummaries (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:23822:15)
    at AotCompiler._createSummary (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:24685:22)
    at AotCompiler._compileImplFile (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:24630:69)
    at /usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:24622:74
    at Array.map (<anonymous>)
    at AotCompiler.emitAllImpls (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler/bundles/compiler.umd.js:24622:39)
    at AngularCompilerProgram.generateFilesForEmit (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler-cli/src/transformers/program.js:619:46)
    at AngularCompilerProgram._emitRender2 (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler-cli/src/transformers/program.js:265:47)
    at AngularCompilerProgram.emit (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler-cli/src/transformers/program.js:200:25)
    at Object.performCompilation (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/compiler-cli/src/perform_compile.js:214:29)
    at compile (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/bazel/src/ngc-wrapped/index.js:317:57)
    at runOneBuild (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/bazel/src/ngc-wrapped/index.js:113:33)
    at Socket.process.stdin.on (/usr/local/google/home/alexeagle/.cache/bazel/_bazel_alexeagle/5c0aaa094e7be03dbabccfd0d5d7e8a8/execroot/angular_bazel_example/bazel-out/host/bin/external/npm/node_modules/@angular/bazel/ngc-wrapped__bin.runfiles/npm/node_modules/@angular/bazel/node_modules/@bazel/typescript/internal/tsc_wrapped/worker.js:113:38)

@alexeagle

This comment has been minimized.

Copy link
Contributor Author

alexeagle commented Mar 14, 2019

Proposed solution is to strip self-referential re-exports when producing the bundled metadata.

I believe the bug is here:

/**
* Rewires metadata to point to the flattened dts file.
*
* @param metadataPath the metadata file path
* @param typingsPath the typings bundle entrypoint
*/
function rewireMetadata(metadataPath: string, typingsPath: string): string {
const metadata = fs.readFileSync(metadataPath, 'utf-8');
let typingsRelativePath =
normalizeSeparators(path.relative(path.dirname(metadataPath), typingsPath));
if (!typingsRelativePath.startsWith('..')) {
typingsRelativePath = `./${typingsRelativePath}`;
}
typingsRelativePath = typingsRelativePath.replace('.d.ts', '');
// the regexp here catches all relative paths such as:
// ./src/core/foo.d.ts and ../src/core/foo.d.ts
return metadata.replace(/\.?\.\/[\w\.\-_\/]+/g, typingsRelativePath);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.