Skip to content

Commit

Permalink
Fix webpack config for deployment to marketplace, add path logging
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrch committed Nov 10, 2019
1 parent 506def1 commit 72907d8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
9 changes: 8 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
"clear": false
},
"problemMatcher": [
"$ts-webpack"
{
"base": "$ts-webpack",
"background": {
"activeOnStart": true,
"beginsPattern": "webpack is watching the files",
"endsPattern": "Built at"
},
}
],
"isBackground": true
},
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "duk-debug",
"displayName": "Duktape Debugger",
"version": "0.5.1",
"version": "0.5.2",
"description": "Debug Adapter for Duktape runtimes.",
"author": "Harold Brenes",
"publisher": "HaroldBrenes",
"license": "MIT (See LICENSE.txt)",
"icon": "img/icon.png",
"maintainers": [
"Harold Brenes <brenes.games@gmail.com> (http://hbrenes.com/cv)"
"Harold Brenes <brenes.games@gmail.com> (http://hbrenes.com/cv)",
"Andrew Chambers <andrewrchambers@gmail.com>"
],
"categories": [
"Debuggers"
Expand Down Expand Up @@ -65,8 +66,8 @@
"tslint": "tslint ./src/**/*.ts",
"postinstall": "node ./node_modules/vscode/bin/install",
"vscode:prepublish": "webpack --mode production",
"compile": "webpack --mode none",
"watch": "webpack --mode none --watch",
"compile": "webpack --mode development",
"watch": "webpack --mode development --watch",
"format": "prettier --write \"**/*.{ts,tsx,js}\"",
"check-format": "prettier --list-different \"**/*.{ts,tsx,js}\""
},
Expand Down
30 changes: 23 additions & 7 deletions src/DukDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,8 @@ export class DukDebugSession extends DebugSession {

//-----------------------------------------------------------
private mapSourceFile(name: string): SourceFile {
this.dbgLog(`[mapSourceFile] Mapping source file ${name}`);

if (!name) {
return null;
}
Expand All @@ -1956,6 +1958,7 @@ export class DukDebugSession extends DebugSession {
for (let k in sources) {
let val: SourceFile = sources[k];
if (val.name === name) {
this.dbgLog(`[mapSourceFile] Mapped source file ${val.path}`);
return val;
}
}
Expand All @@ -1973,7 +1976,13 @@ export class DukDebugSession extends DebugSession {
}
}

if (!fpath || !FS.existsSync(fpath)) {
if (!fpath) {
this.dbgLog(`[mapSourceFile] failed to map source file`);
return null;
}

if (!FS.existsSync(fpath)) {
this.dbgLog(`[mapSourceFile] mapped source path doesn't exist ${fpath}`);
return null;
}

Expand All @@ -1989,7 +1998,7 @@ export class DukDebugSession extends DebugSession {
try {
this.checkForSourceMap(src);
if (src.srcMap) {
// Create a generated-to-oiriginal lookup
// Create a generated-to-original lookup
// entry for each file in the source map.
let srcMap = src.srcMap;
for (let i = 0; i < srcMap._sources.length; i++) {
Expand All @@ -2004,7 +2013,9 @@ export class DukDebugSession extends DebugSession {
this._sourceToGen[srcPath] = src;
}
}
} catch (err) {}
} catch (err) {
this.dbgLog(`[mapSourceFile] Failed to process source map for source: ${src}`);
}

return src;
}
Expand All @@ -2017,13 +2028,15 @@ export class DukDebugSession extends DebugSession {
// and attempts to find the file in them
//-----------------------------------------------------------
private unmapSourceFile(path: string): SourceFile {
this.dbgLog(`[unmapSourceFile] Unmapping file: ${path}`);
path = Path.normalize(path);
let name = Path.basename(path);

// Grab the relative path under the source root if this is located there,
// or just keep the full path if it's not
let pathUnderRoot = Path.dirname(this.getSourceNameByPath(path) || "");

this.dbgLog(`[unmapSourceFile] Path under root: ${pathUnderRoot}`);
if (!this._sourceMaps) {
return this.mapSourceFile(Path.join(pathUnderRoot, name));
}
Expand All @@ -2035,17 +2048,16 @@ export class DukDebugSession extends DebugSession {
return src2gen[path];
}

let src: SourceFile = null;

// If we still haven't found anything,
// we try to mapa the source files in the outDir until
// we try to map the source files in the outDir until
// we find the matching one.
const scanDir = (dirPath: string, rootPath: string) => {
// In case the directory doesn't exsist
let files: string[];
try {
files = FS.readdirSync(dirPath);
} catch (err) {
this.dbgLog(`[scanDir] Error reading directory: ${dirPath}`);
return;
}

Expand All @@ -2063,13 +2075,15 @@ export class DukDebugSession extends DebugSession {

const candidate = this.mapSourceFile(Path.join(rootPath, f));
if (candidate.name === Path.join(pathUnderRoot, name)) {
this.dbgLog(`[scanDir] Found matching file: ${candidate.name}`);
return candidate;
}
if (!candidate.srcMap) {
continue;
}
for (const candidateFile of candidate.srcMap._sources) {
if (candidateFile && this.normPath(Path.resolve(this._outDir, candidateFile)) === path) {
this.dbgLog(`[scanDir] Found matching file: ${candidateFile}`);
return candidate;
}
}
Expand Down Expand Up @@ -2106,7 +2120,9 @@ export class DukDebugSession extends DebugSession {

for (let rpath of this._sourceRoots) {
if (fpath.indexOf(rpath) === 0) {
return fpath.substr(rpath.length + 1);
const sourceName = fpath.substr(rpath.length + 1);
this.dbgLog(`[getSourceNameByPath] Path found in source root '${rpath}' source name: ${sourceName}`);
return sourceName;
}
}

Expand Down
17 changes: 13 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ const path = require("path");

const config = {
target: "node",

entry: "./src/extension.ts",
output: {
path: path.resolve(__dirname, "dist"),
filename: "extension.js",
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "../[resource-path]"
},
devtool: "source-map",
externals: {
vscode: "commonjs vscode"
},
Expand All @@ -35,4 +32,16 @@ const config = {
]
}
};
module.exports = config;

module.exports = (env, argv) => {
if (argv.mode === "development") {
config.devtool = "source-map";
config.entry = "./src/extension.ts";
}

if (argv.mode === "production") {
config.entry = "./src/debugAdapter.ts";
}

return config;
};

0 comments on commit 72907d8

Please sign in to comment.