From bfa874de6392aba85657be7efd89f3375c760f63 Mon Sep 17 00:00:00 2001 From: Walker Date: Sun, 17 Jun 2018 13:14:52 -0300 Subject: [PATCH] Add support for es6 modules for boot scripts --- lib/plugins/boot-script.js | 1 + test/bootstrapper.test.js | 1 + test/executor.test.js | 2 ++ test/fixtures/simple-app/boot/umd-script.js | 13 +++++++++++++ 4 files changed, 17 insertions(+) create mode 100644 test/fixtures/simple-app/boot/umd-script.js diff --git a/lib/plugins/boot-script.js b/lib/plugins/boot-script.js index 05bce38..3207e91 100644 --- a/lib/plugins/boot-script.js +++ b/lib/plugins/boot-script.js @@ -66,6 +66,7 @@ function runScripts(app, list, callback) { debug('Requiring script %s', filepath); try { var exports = require(filepath); + if (exports.__esModule) exports = exports.default; if (typeof exports === 'function') { debug('Exported function detected %s', filepath); functions.push({ diff --git a/test/bootstrapper.test.js b/test/bootstrapper.test.js index 921d7ca..8245ea3 100644 --- a/test/bootstrapper.test.js +++ b/test/bootstrapper.test.js @@ -81,6 +81,7 @@ describe('Bootstrapper', function() { 'promiseFinished', 'thenableStarted', 'thenableFinished', + 'umdLoaded', ]); done(); }); diff --git a/test/executor.test.js b/test/executor.test.js index 5bc7b9c..c5da184 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -315,6 +315,7 @@ describe('executor', function() { 'promiseFinished', 'thenableStarted', 'thenableFinished', + 'umdLoaded', ]); }); }); @@ -337,6 +338,7 @@ describe('executor', function() { 'promiseFinished', 'thenableStarted', 'thenableFinished', + 'umdLoaded', ]); done(); }); diff --git a/test/fixtures/simple-app/boot/umd-script.js b/test/fixtures/simple-app/boot/umd-script.js new file mode 100644 index 0000000..469f8ab --- /dev/null +++ b/test/fixtures/simple-app/boot/umd-script.js @@ -0,0 +1,13 @@ +// Copyright IBM Corp. 2017. All Rights Reserved. +// Node module: loopback-boot +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +'use strict'; + +module.exports = { + default: function() { + process.bootFlags.push('umdLoaded'); + }, +}; +Object.defineProperty(module.exports, '__esModule', {value: true});