Skip to content

Commit

Permalink
Update to ES modules
Browse files Browse the repository at this point in the history
  • Loading branch information
zeekay committed Apr 1, 2017
1 parent 30b0ea0 commit 9672122
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 62 deletions.
18 changes: 9 additions & 9 deletions Cakefile
Expand Up @@ -12,10 +12,17 @@ task 'clean', 'clean project', (options) ->
exec 'rm -rf lib'

task 'build', 'build project', (options) ->
exec 'coffee -bcm -o lib/ src/'
Promise.all [
bundle.write
entry: 'src/index.coffee'
bundle.write
entry: 'src/register.coffee'
format: 'cjs'
dest: 'register.js'
sourceMap: false
]

task 'watch', 'watch for changes and recompile project', ->
exec 'coffee -bc -m -w -o lib/ src/'

task 'test', 'run tests', (options) ->
test = options.test ? 'test'
Expand All @@ -37,10 +44,3 @@ task 'test', 'run tests', (options) ->
task 'gh-pages', 'Publish docs to gh-pages', ->
brief = require 'brief'
brief.update()

task 'publish', 'publish project', ->
exec.parallel '''
git push
git push --tags
npm publish
'''
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2013-2015 Zach Kelling
Copyright (c) 2013-2017 Zach Kelling

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
18 changes: 8 additions & 10 deletions package.json
Expand Up @@ -3,26 +3,24 @@
"version": "0.2.4",
"description": "When code dies, it deserves a proper autopsy. Stacktrace library with sourcemap support.",
"keywords": [
"stacktrace",
"debugging"
"debugging",
"sourcemaps",
"stacktrace"
],
"homepage": "http://github.com/zeekay/postmortem",
"bugs": {
"url": "http://github.com/zeekay/postmortem/issues"
},
"main": "lib/",
"main": "lib/postmortem.js",
"module": "lib/postmortem.mjs",
"jsnext:main": "lib/postmortem.mjs",
"scripts": {
"prepublish": "cake build",
"prepublishOnly": "cake build",
"test": "cake test"
},
"repository": "https://github.com/zeekay/postmortem",
"author": {
"name": "Zach Kelling",
"email": "zk@monoid.io",
"url": "http://zeekay.io"
},
"author": "Zach Kelling <z@zeekay.io>",
"license": "MIT",
"readmeFilename": "README.md",
"dependencies": {
"source-map-support": "^0.4.14"
},
Expand Down
56 changes: 55 additions & 1 deletion register.js
@@ -1 +1,55 @@
require('./lib/register')
'use strict';

// src/coffee.coffee
var _prepareStackTrace;

_prepareStackTrace = Error.prepareStackTrace;

var coffeeDetected = /formatSourcePosition\(frame, getSourceMapping/.test(_prepareStackTrace);

// src/install.coffee
var install = function(options = {}) {
if (options.handleUncaughtExceptions == null) {
options.handleUncaughtExceptions = true;
}
if (options.structuredStackTrace == null) {
options.structuredStackTrace = false;
}
if (options.handleUncaughtExceptions) {
process.on('uncaughtException', function(err) {
(require('./utils')).prettyPrint(err, {
colorize: process.stdout.isTTY
});
return process.exit(1);
});
}
return Error.prepareStackTrace = function(err, stack) {
var _stack, frame;
_stack = (function() {
var i, len, results;
results = [];
for (i = 0, len = stack.length; i < len; i++) {
frame = stack[i];
results.push((require('./callsite/wrap'))(err, frame));
}
return results;
})();
if (options.structuredStackTrace) {
err.structuredStackTrace = require('./structured-stack-trace')(err, stack);
}
return err + ((function() {
var i, len, results;
results = [];
for (i = 0, len = _stack.length; i < len; i++) {
frame = _stack[i];
results.push('\n at ' + frame);
}
return results;
})()).join('');
};
};

// src/register.coffee
install({
handleUncaughtExceptions: false
});
2 changes: 1 addition & 1 deletion src/callsite/clone.coffee
Expand Up @@ -55,7 +55,7 @@ CallSiteToString = ->
line += ' (' + fileLocation + ')'
line

module.exports = (frame) ->
export default (frame) ->
_frame = {}
proto = Object.getPrototypeOf frame

Expand Down
10 changes: 7 additions & 3 deletions src/callsite/index.coffee
@@ -1,3 +1,7 @@
module.exports =
clone: require './clone'
wrap: require './wrap'
import clone from './clone'
import wrap from './wrap'

export {
clone
wrap
}
10 changes: 5 additions & 5 deletions src/callsite/wrap.coffee
@@ -1,10 +1,10 @@
clone = require './clone'
import clone from './clone'

{coffeePrepare} = require '../coffee'
{coffeeStackRegex} = require '../utils'
{mapSourcePosition, mapEvalOrigin} = require '../source-map-support'
import {coffeePrepare} from '../coffee'
import {coffeeStackRegex} from '../utils'
import {mapSourcePosition, mapEvalOrigin} from '../source-map-support'

module.exports = (err, frame) ->
export default (err, frame) ->
# If using coffee 1.6.2+ executable we can derive source, line, and column
# from it's prepareStackTrace function
if coffeePrepare and match = coffeeStackRegex.exec coffeePrepare err, [frame]
Expand Down
8 changes: 2 additions & 6 deletions src/coffee.coffee
@@ -1,8 +1,4 @@
_prepareStackTrace = Error.prepareStackTrace

coffeeDetected = /formatSourcePosition\(frame, getSourceMapping/.test _prepareStackTrace
coffeePrepare = if coffeeDetected then _prepareStackTrace else null

module.exports =
coffeeDetected: coffeeDetected
coffeePrepare: coffeePrepare
export coffeeDetected = /formatSourcePosition\(frame, getSourceMapping/.test _prepareStackTrace
export coffeePrepare = if coffeeDetected then _prepareStackTrace else null
23 changes: 16 additions & 7 deletions src/index.coffee
@@ -1,7 +1,16 @@
Object.defineProperties module.exports,
callsite: enumerable: true, get: -> require './callsite'
coffee: enumerable: true, get: -> require './coffee'
install: enumerable: true, get: -> require './install'
sourceMapSupport: enumerable: true, get: -> require './source-map-support'
structuredStackTrace: enumerable: true, get: -> require './structured-stack-trace'
utils: enumerable: true, get: -> require './utils'
import * as callsite from './callsite'
import * as coffee from './coffee'
import * as utils from './utils'
import install from './install'
import structuredStackTrace from './structured-stack-trace'
import {mapEvalOrigin, mapSourcePosition} from './source-map-support'

export {
callsite
coffee
install
mapEvalOrigin
mapSourcePosition
structuredStackTrace
utils
}
4 changes: 2 additions & 2 deletions src/install.coffee
@@ -1,6 +1,6 @@
require './coffee'
import './coffee'

module.exports = (options = {}) ->
export default (options = {}) ->
options.handleUncaughtExceptions ?= true
options.structuredStackTrace ?= false

Expand Down
4 changes: 2 additions & 2 deletions src/register.coffee
@@ -1,2 +1,2 @@
(require './install')
handleUncaughtExceptions: false
import install from './install'
install handleUncaughtExceptions: false
6 changes: 2 additions & 4 deletions src/source-map-support.coffee
@@ -1,4 +1,4 @@
{mapSourcePosition} = require 'source-map-support'
import {mapSourcePosition} from 'source-map-support'

mapEvalOrigin = (origin) ->
# Most eval() calls are in this format
Expand All @@ -18,6 +18,4 @@ mapEvalOrigin = (origin) ->
# Make sure we still return useful information if we didn't find anything
origin

module.exports =
mapEvalOrigin: mapEvalOrigin
mapSourcePosition: mapSourcePosition
export {mapEvalOrigin, mapSourcePosition}
2 changes: 1 addition & 1 deletion src/structured-stack-trace.coffee
Expand Up @@ -39,4 +39,4 @@ structuredStackTrace = (err, stack) ->
_frame.toJSON = toJSON
_frame

module.exports = structuredStackTrace
export default structuredStackTrace
15 changes: 5 additions & 10 deletions src/utils.coffee
@@ -1,11 +1,11 @@
fs = require 'fs'
import fs from 'fs'

{mapSourcePosition} = require './source-map-support'
import {mapSourcePosition} from './source-map-support'

nodeStackRegex = /\n at [^(]+ \((.*):(\d+):(\d+)\)/
coffeeStackRegex = /\((.*)\.coffee:(\d+):(\d+)\)/
export nodeStackRegex = /\n at [^(]+ \((.*):(\d+):(\d+)\)/
export coffeeStackRegex = /\((.*)\.coffee:(\d+):(\d+)\)/

prettyPrint = (err, options = {}) ->
export prettyPrint = (err, options = {}) ->
options.colorize ?= false

match = nodeStackRegex.exec err.stack
Expand All @@ -30,8 +30,3 @@ prettyPrint = (err, options = {}) ->
console.error ((new Array(+position.column)).join ' ') + caret

console.error err.stack

module.exports =
coffeeStackRegex: coffeeStackRegex
nodeStackRegex: nodeStackRegex
prettyPrint: prettyPrint

0 comments on commit 9672122

Please sign in to comment.