Skip to content

Commit 06aeb78

Browse files
authored
fix: debugger when using Angular based projects. (#279)
1 parent f042ba2 commit 06aeb78

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type": "git",
1414
"url": "https://github.com/NativeScript/nativescript-vscode-extension/"
1515
},
16-
"publisher": "Telerik",
16+
"publisher": "NativeScript",
1717
"bugs": "https://github.com/NativeScript/nativescript-vscode-extension/issues",
1818
"engines": {
1919
"vscode": "^1.19.0"

src/debug-adapter/nativeScriptDebugAdapter.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
166166
}
167167
}
168168

169+
/**
170+
* Determines if the NativeScript project being debugged is an Angular based
171+
* project by returning true if an **angular.json** file exists at the base
172+
* of the project or returns false if not found.
173+
* @param webRoot The root of the project.
174+
*/
175+
private isAngularProject(webRoot): boolean {
176+
const isAngularProject = existsSync(join(webRoot, 'angular.json'));
177+
178+
if (isAngularProject) {
179+
logger.log('Angular project detected, found angular.json file.');
180+
}
181+
182+
return isAngularProject;
183+
}
184+
169185
private translateArgs(args): any {
170186
if (args.diagnosticLogging) {
171187
args.trace = args.diagnosticLogging;
@@ -179,7 +195,7 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
179195
args.sourceMapPathOverrides = {};
180196
}
181197

182-
const appDirPath = this.getAppDirPath(args.webRoot) || 'app';
198+
const appDirPath = this.getAppDirPath(args.webRoot) || (this.isAngularProject(args.webRoot) ? 'src' : 'app');
183199
const fullAppDirPath = join(args.webRoot, appDirPath);
184200

185201
if (!args.sourceMapPathOverrides['webpack:///*']) {

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function activate(context: vscode.ExtensionContext) {
2020

2121
services.logger = new ChannelLogger(channel);
2222

23-
const packageJSON = vscode.extensions.getExtension('Telerik.nativescript').packageJSON;
23+
const packageJSON = vscode.extensions.getExtension('nativescript.nativescript').packageJSON;
2424
const cliVersion = services.cli().executeGetVersion();
2525

2626
if (!cliVersion) {

src/tests/nativeScriptDebugAdapter.tests.ts

+8
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ describe('NativeScriptDebugAdapter', () => {
141141
it(`${method} for ${platform} should add sourceMapPathOverrides data`, async () => {
142142
const spy = sinon.spy(ChromeDebugAdapter.prototype, 'attach');
143143
const existsSyncStub = sinon.stub(fs, 'existsSync');
144+
// Need to also stub isAngularProject to return false or it will always return true bc it utilizes
145+
// `fs.existsSync` which is also stubbed and made to return true in this test.
146+
const isAngularProjectStub = sinon.stub(nativeScriptDebugAdapter, 'isAngularProject');
144147

145148
existsSyncStub.returns(true);
149+
isAngularProjectStub.returns(false);
146150
webpackConfigFunctionStub
147151
.withArgs({ [platform]: platform })
148152
.returns({ output: { library: 'myLib' } });
@@ -164,8 +168,12 @@ describe('NativeScriptDebugAdapter', () => {
164168
it(`${method} for ${platform} should not fail when unable to require webpack.config.js`, async () => {
165169
const spy = sinon.spy(ChromeDebugAdapter.prototype, 'attach');
166170
const existsSyncStub = sinon.stub(fs, 'existsSync');
171+
// Need to also stub isAngularProject to return false or it will always return true bc it utilizes
172+
// `fs.existsSync` which is also stubbed and made to return true in this test.
173+
const isAngularProjectStub = sinon.stub(nativeScriptDebugAdapter, 'isAngularProject');
167174

168175
existsSyncStub.returns(true);
176+
isAngularProjectStub.returns(false);
169177
webpackConfigFunctionStub
170178
.withArgs({ [platform]: platform })
171179
.throws(new Error('test'));

0 commit comments

Comments
 (0)