Skip to content

dts bundling produces broken metadata.json #29315

Closed
@alexeagle

Description

@alexeagle
Contributor

/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)

Activity

alexeagle

alexeagle commented on Mar 14, 2019

@alexeagle
ContributorAuthor

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);
}

added a commit that references this issue on Mar 14, 2019
d35de76
added a commit that references this issue on Apr 17, 2019
d0351e1
angular-automatic-lock-bot

angular-automatic-lock-bot commented on Sep 14, 2019

@angular-automatic-lock-bot

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexeagle

      Issue actions

        dts bundling produces broken metadata.json · Issue #29315 · angular/angular