Craft manual deprecation to get around stack depth limit

This allows the deprecation to be properly associated with the
package it originates from.
This commit is contained in:
Kevin Sawicki
2015-02-25 09:24:18 -08:00
parent 49be811bee
commit 1c9dbbf3b3

View File

@@ -140,19 +140,25 @@ loadFile = (module, filePath) ->
if sourceCode.startsWith('"use babel"') or sourceCode.startsWith("'use babel'")
# Continue.
else if sourceCode.startsWith('"use 6to5"') or sourceCode.startsWith("'use 6to5'")
packageName
directory = filePath
until packageName
directory = path.dirname(directory)
manifest = path.join(directory, 'package.json')
if fs.existsSync(manifest)
json = JSON.parse(fs.readFileSync(manifest))
packageName = json.name
else if isRoot(directory)
break
# Create a manual deprecation since the stack is too deep to use Grim
# which limits the depth to 3
Grim ?= require 'grim'
Grim.deprecate("Use the 'use babel' pragma instead of 'use 6to5' in #{filePath}", {packageName})
stack = [
{
fileName: __filename
functionName: 'loadFile'
location: "#{__filename}:161:5"
}
{
fileName: filePath
functionName: '<unknown>'
location: "#{filePath}:1:1"
}
]
deprecation =
message: "Use the 'use babel' pragma instead of 'use 6to5'"
stacks: [stack]
Grim.addSerializedDeprecation(deprecation)
else
return module._compile(sourceCode, filePath)