From fc0ccac2bcedd372bb7a59dbd2996f857d2b7680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20=C3=80lvarez=20i=20Capilla?= Date: Thu, 1 Jun 2017 03:53:16 +0200 Subject: [PATCH 1/2] Support exporting async functions --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 791265b..d1ce567 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ hook.hook('.js', (src, name) => { src = src.replace(/import ([^{]*?) from '(.*?)'/g, 'const $1 = require("$2")'); src = src.replace(/export default ([^ ]*)/g, 'module.exports = $1'); src = src.replace(/export (var|let|const) ([a-zA-Z0-9_$]*)/g, '$1 $2 = module.exports.$2'); + src = src.replace(/export async function ([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = async function'); src = src.replace(/export function ([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = function'); src = src.replace(/export class ([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = class'); src = src.replace(/import {(.*?)} from '(.*?)'/g, (all, $1, $2) => { @@ -12,4 +13,4 @@ hook.hook('.js', (src, name) => { .join(''); }); return src; -}); \ No newline at end of file +}); From de6924c40531806ffeadb96d21cd19b6a33b1fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20=C3=80lvarez=20i=20Capilla?= Date: Sun, 4 Jun 2017 21:58:42 +0200 Subject: [PATCH 2/2] Support "import ;" expressions --- index.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d1ce567..59466c8 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var hook = require('node-hook'); hook.hook('.js', (src, name) => { src = src.replace(/import ([^{]*?) from '(.*?)'/g, 'const $1 = require("$2")'); + src = src.replace(/import ([^{]*?);/g, 'const $1 = require("$1")'); src = src.replace(/export default ([^ ]*)/g, 'module.exports = $1'); src = src.replace(/export (var|let|const) ([a-zA-Z0-9_$]*)/g, '$1 $2 = module.exports.$2'); src = src.replace(/export async function ([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = async function'); diff --git a/package.json b/package.json index 4cb2529..8aa88db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "import-export", - "version": "1.0.1", + "version": "1.0.2", "description": "Use ECMA6 import/export syntax from within NodeJS (simply require this module)", "main": "index.js", "dependencies": {