VScode sourceMaps detected but not used - javascript

Hi everyone !
I'm using VSCode to work on an OpenSource project in monorepo with lerna, and I want to provide a package which contains the tools needed to contribute easily.
In order to do this in a way that seems pretty clean to me, I added my monorepo as a submodule in my workbench package.
Here is a link to my current setup:
https://github.com/Aetherall/accounts-workbench
The main goal of this package is to give to the developper a working debugger configuration, which allows breakpoints and follows the Error stack within the sources of the monorepo packages.
I succeded to make VSCode read my sourcemaps.
Indeed, I switched on the trace options, and I saw in the logs that the .map files were resolved.
But, - and there is my issue - when I trigger an error, instead of leading me to the sources, the debugger just show me the transpiled files...
Here is a sample of my log for one file ( I can provide my whole log if needed to help me )
SourceMaps: sourcemap url parsed from end of generated content:
AuthenticationServicePassword.js.map
SourceMaps.getMapForGeneratedPath: Finding SourceMap for
/home/aetherall/Workspace/github/accounts/accounts-workbench/accounts/packages/Server/Authentication/Password/PasswordService/lib/AuthenticationServicePassword.js by URI:
AuthenticationServicePassword.js.map
SourceMaps.loadSourceMapContents: Reading local sourcemap file from
/home/aetherall/Workspace/github/accounts/accounts-workbench/accounts/packages/Server/Authentication/Password/PasswordService/lib/AuthenticationServicePassword.js.map
here is my debugger config:
{
"type": "node",
"request": "launch",
"name": "Start dev server",
"program": "${workspaceRoot}/config/start.js",
"protocol": "inspector",
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"outFiles": [
"${workspaceRoot}/dist/**/*.js",
"${workspaceRoot}/**/lib/**/*.js",
"!**/node_modules/**/*",
],
"skipFiles": ["${workspaceRoot}/node_modules/**/*", "<node_internals>/**/*.js"],
"smartStep": true,
"trace": "sm"
},
I am using webpack to bundle the workbench package (not the monorepo) and tsc to transpile the typescript packages in javascript with sourceMaps in my monorepo submodule
I can of course add more informations if needed
Thanks for helping me on this one !
I really can't get why sourceMaps arn't used by the debugger ...
If you do have a solution, please give me some explanations on the problem

I found a solution to my issue :
Source Map loader for webpack
this way, the sourcemaps of the files imported and transpiled will be resolved within webpack.
https://github.com/webpack-contrib/source-map-loader

Related

How to stop VSCode from auto-skipping Node Internals while debugging

I'm trying to understand how certain node internal modules work, and wish to deliberately step into the node core while debugging my js files. I've tried setting the skipFiles property in Launch.json to an empty array [""] but VSCode somehow auto-attaches "<node_internals>/**" to it
This works for me:
"skipFiles": [
"!<node_internals>/**"
],

How do I update my config file in vs code?

When I see example config files on VS Code they are often lengthy and offer two panels for updating (one for default settings and the other for customization). For some reason my config file is only a few lines and whenever I try to update it, nothing happens:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
For example I'm trying add a line of code to get rid of the error displayed for using .jsx in a .js file as found here and here but it doesn't work. This is just an example, I've tried other modifications as well. How do I add the below code my launch.json (and is there more than one launch.json?). As you can see, I'm super new to this so thanks for any help.
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
}
You can open:
default settings: Ctrl+Shift+P/Cmd+Shift+P -> Open Default Settings (JSON).
VS Code setting (applied to whole VS code instance): Ctrl+Shift+P / Cmd+Shift+P` -> Open Settings (JSON).
workspace settings (applied only to current "project"/folder): create in root directory '.vscode' folder -> 'settings.json' file.
All these you can find in UI instead of JSON.
In your example, you provided Launch configuration (it is not vs code settings), it is used to configure how to launch/debug your application.
And if you want to get rid of errors, you don't need to use VS Code settings. These rules:
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
}
are configuration for eslint plugin (based on links you provided). So, you need to place these lines to .eslintrc file and eslint and appropriate plugins should be installed and properly configured.
The launch.json file is used for launching commands like building, running or debugging, you need to change some settings, not launching any thing.
vsCode offers you couple of ways to declare your settings:
Workspace - will save a settings.json file on your root workspace dir.
User - will save a settings.json file on one of those pathes (according your os):
Windows %APPDATA%\Code\User\settings. json.
Mac $HOME/Library/Application Support/Code/User/settings. json.
Linux $HOME/. config/Code/User/settings. json.
On vsCode docs you can read all about it.
You can edit your settings by ctrl+shift+p to open the command palette and search settings, or File > Preferences > Settings (Code > Preferences > Settings on Mac).

How to create an express api executable

I have created a fully functioning fairly basic javaScript Node.js Express API application that I want to run as an executable in a windows environment. I am wanting to do this so I can give clients the ability to run my API on premise without exposing my source code to them.
Currently I have been using the pkg npm package which allows me to package my node.js application into an executable that will contain everything needed to run the app including node and my bundled source code.
My executable runs but my POST route is breaking with the following error:
"name": "RequestError",
"message": "Error: form-data: File or directory 'C:\\**\\myapp-api\\uploads\\1553103249524_test.wav' was not included into executable at compilation stage. Please recompile adding it as asset or script.",
"cause": {
"errno": -4058,
"code": "ENOENT",
"path": "C:\\snapshot\\myapp-api\\uploads\\test.wav",
"pkg": true
},
"error": {
"errno": -4058,
"code": "ENOENT",
"path": "C:\\snapshot\\myapp-api\\uploads\\1553103249524_test.wav",
"pkg": true
},
My POST allows clients to upload a file in a multipart form using multer.js to another external API that will return some metadata. pkg.js doesn't appear to have the means to discover files that are included after the bundling of the executable.
Is there anything I can do in my configuration for my uploaded files to be included? Is there some other utility or process that others use for creating an executable of their node.js express APIs that would better handle the issue I am having?
Any guidance would really be great.
Try adding your files under "assets" in the package.json file.
The config paragraph on the pkg website https://www.npmjs.com/package/pkg#config states:
So you must specify the files - scripts and assets - manually in pkg property of your package.json file.
"pkg": {
"scripts": "build/**/*.js",
"assets": "views/**/*"
}
You may also specify arrays of globs:
"assets": [ "assets/**/*", "images/**/*" ]
Just be sure to call pkg package.json or pkg . to make use of scripts and assets entries.
You are probably using something like this in your script (I am guessing since you didnt provide this part of the code)
app.use(express.static(__dirname+'/uploads'));
res.sendFile(path.join(__dirname+'/uploads'));
__dirname will be wrong when you pack your .exe get rid of it everywhere and replace it with ./
app.use(express.static('./uploads'));
res.sendFile(path.join('./uploads'));
Something like that. It worked for me.
Good luck!

JSLint - ignoring folder when building in Visual Studio 2015

I want to implement javascript code and style checking with JSLint.
I installed JSLint.NET for Visual Studio.
Now i want to exclude all the javascript files that are included from external libraries like datatables, jquery, .. also my own minified files need to be excluded.
My project configurations are added in the JSLintNet.json file:
{
"version": "2.2.0",
"output": "Error",
"ignore": [
"\\Scripts\\angular-datatables\\plugins\\tabletools\\",
"\\Scripts\\angular-datatables\\plugins\\fixedcolumns\\angular-datatables.fixedcolumns.js",
"\\Scripts\\angular-datatables\\plugins\\fixedcolumns\\angular-datatables.fixedcolumns.min.js"
],
"options": {},
"globalVariables": [],
"runOnBuild": true
}
Whatever path i provide here, is it a folder or a file. The code analysis still keeps running. It is important that i can ignore certain files/ folder for JSLint to be practical.
How can i solve the ignoring of folders and files, perhaps even certain extensions.
I have had this problem and am not certain whether this is the right answer: however, it usually works for me. It seems that JSLint.Net only parses the configuration file on startup; so if you edit JSLintNet.json, quit VisualStudio and restart it.
I'm using Visual Studio 2013, version 12.0.40629.00 with JSLint.Net 2.2.0
Hope this helps.

Instruct Sencha SDK tools to bundle other js files specified in app.json

My app.json file of a Sencha touch 2 application contain.
"js": [
{
"path": "sdk/sencha-touch.js"
},
{"path": "js/mootools-1.2.5-core.js"}, // I want these files to be bundled too
{"path": "js/mootools-1.2.5.1-more.js"}, // <----------+
{"path": "js/soundmanager2-nodebug-jsmin.js"}, // <----+
... // <----+ and there are more.
...
{
"path": "app.js",
"bundle": true, /* Indicates that all class dependencies are concatenated into this file when build */
"update": "delta"
},
Now I see when I invoke sencha app build production It compiles all the sencha classes into a giant app.js file. But all my other classes are just compressed to build directory. They are not concatenated. how can I include them in app.js?
F.A.Q.
Your json file is properly written, right?
A. Yes, app.json is written without any syntax error. The project builds successfully on invoking sencha app build production
After looking at the source code and talking with the devs behind Cmd, it appears that it is currently not possible.
However, because the build file is written in JavaScript, in theory, it wouldn't take much to modify it and add this functionality into Cmd.
You can find the Sencha Touch build file in:
CMD-ROOT/plugins/touch/current/app-build.js
Where CMD-ROOT is the location of the sencha command - which you can find out by using which sencha.
On my system (OSX), the path is:
/Users/Robert/bin/Sencha/Cmd/3.0.0.250/plugins/touch/current/app-build.js
Hopefully this is of some help to you.
Update
It appears that, after talking to another Cmd developer, this actually is possible. There are 2 steps you need to take to make it happen:
1) Add the skipFrameworkFile property into each JS resource you want to bundle. This tells the compiler to not copy the resource when your build your app.
{
"path": "resources/js/jquery.js",
"skipFrameworkFile": true
},
"path": "resources/js/jquery2.js",
"skipFrameworkFile": true
}
2) Require each of the files in your app.js file using the #require tag. This tells the compiler to include each of your files into your app.js file.
//#require resources/js/jquery.js
//#require resources/js/jquery2.js
For SenchaCmd 3.2, rdougan's solution didn't work for me. However, instead of using:
'skipFrameworkFile: true
I used
'x-bootstrap': true
(by looking at SenchaCmd source code) and it worked!
The other steps are the same as rdougan's
Hope this helps. Cheers

Categories

Resources