From 49be811bee356130eaa2772c87513e60b4f6fa1b Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Mon, 23 Feb 2015 22:34:30 -0800 Subject: [PATCH] Report a deprecation warning when 'use 6to5' is used instead of 'use babel'. --- src/babel.coffee | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/babel.coffee b/src/babel.coffee index 766324ce0..d4b53c204 100644 --- a/src/babel.coffee +++ b/src/babel.coffee @@ -8,6 +8,7 @@ crypto = require 'crypto' fs = require 'fs-plus' path = require 'path' babel = null # Defer until used +Grim = null # Defer until used stats = hits: 0 @@ -127,15 +128,33 @@ transpile = (sourceCode, filePath, cachePath) -> js +isRoot = (filePath) -> + parts = path.parse(filePath) + parts.root == filePath + # Function that obeys the contract of an entry in the require.extensions map. # Returns the transpiled version of the JavaScript code at filePath, which is # either generated on the fly or pulled from cache. loadFile = (module, filePath) -> sourceCode = fs.readFileSync(filePath, 'utf8') - return module._compile(sourceCode, filePath) unless sourceCode.startsWith('"use 6to5"') or - sourceCode.startsWith("'use 6to5'") or - sourceCode.startsWith('"use babel"') or - sourceCode.startsWith("'use babel'") + 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 + + Grim ?= require 'grim' + Grim.deprecate("Use the 'use babel' pragma instead of 'use 6to5' in #{filePath}", {packageName}) + else + return module._compile(sourceCode, filePath) cachePath = getCachePath(sourceCode) js = getCachedJavaScript(cachePath) ? transpile(sourceCode, filePath, cachePath)