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

Natural/relative source map source file paths #1622

Closed
alastair-todd opened this issue May 3, 2020 · 3 comments · Fixed by #1652
Closed

Natural/relative source map source file paths #1622

alastair-todd opened this issue May 3, 2020 · 3 comments · Fixed by #1652

Comments

@alastair-todd
Copy link

@alastair-todd alastair-todd commented May 3, 2020

Type of Issue

[X] Bug Report
[] Feature Request

Description

When building a project of type library and generating source maps, the paths in the map file to the original files are prefixed ng:// and don't actually point to anywhere that exists

"sources":["ng://shared-modules/lib/utils/string-utils.ts", (also missing /src folder)

If I manually update the map to natural / relative paths, both chrome and nyc(istanbul) are able to locate the source and generate a relevant report - Istanbul doesn't complain about not being able to locate files

"sources":["../../../projects/shared-modules/src/lib/utils/string-utils.ts",

How To Reproduce

See the dist/my-lib/fesm5/my-lib.js.map file and see the sources array

Expected Behaviour

Other programs should be able to locate the source files - not sure the best way around that...

Version Information

Angular CLI: 9.1.0
Node: 10.15.3
OS: darwin x64

Angular: 9.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

@alan-agius4
Copy link
Contributor

@alan-agius4 alan-agius4 commented May 3, 2020

@alastair-todd are you using the vendorSourceMap option in the Angular CLI?

Since ng-packagr generates a library it’s sourcemap will not be picked up automatically by webpack unless this option is enabled.

Updating the source content to point to the actual src root works in this case because the src folder exists, in most cases this will not exists such as when publishing a library to npm.

@alastair-todd
Copy link
Author

@alastair-todd alastair-todd commented May 3, 2020

@alan-agius4 I had been doing in the project as a means to see the library typescript in dev tools - but recently I noticed these appear now anyway - just gathered this was to do with recent ng9 up / Ivy.

That said, with or without vendorSourceMap appears not to effect the contents of the map files in dist/ in terms of file paths...

Everything works - the coverage is picked up so the library is being instrumented by nyc, its just when you click through to the to the file in the generated report its not found

Unable to lookup source: /***/dist/shared-modules/fesm5/ng:/shared-modules/lib/shared-modules.ts (ENOENT: no such file or directory, open '/***/dist/shared-modules/fesm5/ng:/shared-modules/lib/shared-modules.ts') Error: Unable to lookup source: /***/dist/shared-modules/fesm5/ng:/shared-modules/lib/shared-modules.ts (ENOENT: no such file or directory, open '/***/dist/shared-modules/fesm5/ng:/shared-modules/lib/shared-modules.ts') at Context.defaultSourceLookup [as sourceFinder] (/***/node_modules/istanbul-lib-report/lib/context.js:18:15)

The following simple workaround to remap the output is doing the trick

// Load the library and specify options
const replace = require('replace-in-file');
const options = {
  files: '.nyc_output/out.json',
  from: /ng:\/\/shared-modules\/lib/g,
  to: '../../../projects/shared-modules/src/lib'
};
const results = replace.sync(options);

@github-actions
Copy link

@github-actions github-actions bot commented Jun 28, 2020

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

This action has been performed automatically by a bot.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants