-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: provides source map support for stack traces #19
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
coverage | ||
test/fixtures/ts/app/controller/home.js | ||
test/fixtures/ts-pkg/app/controller/home.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
logs/ | ||
npm-debug.log | ||
/node_modules | ||
node_modules | ||
coverage/ | ||
.idea/ | ||
run/ | ||
.DS_Store | ||
*.swp | ||
test/fixtures/ts/app/controller/home.js | ||
test/fixtures/ts-pkg/app/controller/home.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const BaseCommand = require('common-bin'); | ||
const Logger = require('zlogger'); | ||
const helper = require('./helper'); | ||
|
@@ -16,11 +18,47 @@ class Command extends BaseCommand { | |
execArgv: true, | ||
}; | ||
|
||
// common-bin setter, don't care about override at sub class | ||
// https://github.com/node-modules/common-bin/blob/master/lib/command.js#L158 | ||
this.options = { | ||
sourcemap: { | ||
description: 'whether enable sourcemap support, will load `source-map-support` etc', | ||
type: 'boolean', | ||
alias: [ 'ts', 'typescript' ], | ||
}, | ||
}; | ||
|
||
this.logger = new Logger({ | ||
prefix: '[egg-scripts] ', | ||
time: false, | ||
}); | ||
} | ||
|
||
get context() { | ||
const context = super.context; | ||
const { argv, execArgvObj, cwd } = context; | ||
|
||
// read `egg.typescript` from package.json | ||
let baseDir = argv._[0] || cwd; | ||
if (!path.isAbsolute(baseDir)) baseDir = path.join(cwd, baseDir); | ||
const pkgFile = path.join(baseDir, 'package.json'); | ||
if (fs.existsSync(pkgFile)) { | ||
const pkgInfo = require(pkgFile); | ||
if (pkgInfo && pkgInfo.egg && pkgInfo.egg.typescript) { | ||
argv.sourcemap = true; | ||
} | ||
} | ||
|
||
// execArgv | ||
if (argv.sourcemap) { | ||
execArgvObj.require = execArgvObj.require || []; | ||
execArgvObj.require.push(require.resolve('source-map-support/register')); | ||
} | ||
|
||
argv.sourcemap = argv.typescript = argv.ts = undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 后面改造一下,需要哪些参数直接赋值,不然这种代码太多了。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return context; | ||
} | ||
} | ||
|
||
module.exports = Command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Controller } from 'egg'; | ||
|
||
export default class AppController extends Controller { | ||
public index() { | ||
try { | ||
throw new Error('some err'); | ||
} catch (err) { | ||
this.ctx.logger.error(err); | ||
this.ctx.body = { | ||
msg: err.message, | ||
stack: err.stack, | ||
}; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { router, controller } = app; | ||
router.get('/', controller.home.index); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
exports.keys = '123456'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "ts-pkg", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"egg": "^1.0.0" | ||
}, | ||
"egg": { | ||
"typescript": true | ||
}, | ||
"scripts": { | ||
"build": "node ../../../node_modules/.bin/tsc" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"charset": "utf8", | ||
"allowJs": false, | ||
"pretty": true, | ||
"noEmitOnError": false, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"strictPropertyInitialization": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"skipLibCheck": true, | ||
"skipDefaultLibCheck": true, | ||
"inlineSourceMap": true, | ||
"importHelpers": true | ||
}, | ||
"exclude": [ | ||
"app/public", | ||
"app/views" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Controller } from 'egg'; | ||
|
||
export default class AppController extends Controller { | ||
public index() { | ||
try { | ||
throw new Error('some err'); | ||
} catch (err) { | ||
this.ctx.logger.error(err); | ||
this.ctx.body = { | ||
msg: err.message, | ||
stack: err.stack, | ||
}; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { router, controller } = app; | ||
router.get('/', controller.home.index); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
exports.keys = '123456'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "ts", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"egg": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"build": "node ../../../node_modules/.bin/tsc" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"charset": "utf8", | ||
"allowJs": false, | ||
"pretty": true, | ||
"noEmitOnError": false, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"strictPropertyInitialization": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"skipLibCheck": true, | ||
"skipDefaultLibCheck": true, | ||
"inlineSourceMap": true, | ||
"importHelpers": true | ||
}, | ||
"exclude": [ | ||
"app/public", | ||
"app/views" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ts 不支持 sourcemap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ts 支持生成 sourcemap,这里是用来根据 sourcemap 还原堆栈的。可以看看 https://zhuanlan.zhihu.com/p/26267678
之前这个 require 都是放到 config 或 app.js agent.js ,或者放框架。
现在这个 PR 是直接在工具层引入了。