Skip to content

Support for Typescript/Babel emitted ES2015 modules#250

Merged
bajtos merged 1 commit intostrongloop:2.xfrom
zamb3zi:2.x
Jun 26, 2017
Merged

Support for Typescript/Babel emitted ES2015 modules#250
bajtos merged 1 commit intostrongloop:2.xfrom
zamb3zi:2.x

Conversation

@zamb3zi
Copy link
Copy Markdown

@zamb3zi zamb3zi commented Jun 22, 2017

Description

Both Typescript and Babel (when run with modules: false) emit modules that can be identified as ES2015 by the __esModule flag. This PR updates loopback-boot to handle these modules in the following scenarios.

  • Executing:
    • Mixin source files
    • Model source files
    • Boot scripts
    • Middleware source files
    • Component source files
  • Compiling:
    • Model source files
    • Mixin source files

Related issues

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

@slnode
Copy link
Copy Markdown

slnode commented Jun 22, 2017

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@slnode
Copy link
Copy Markdown

slnode commented Jun 22, 2017

Can one of the admins verify this patch?

2 similar comments
@slnode
Copy link
Copy Markdown

slnode commented Jun 22, 2017

Can one of the admins verify this patch?

@slnode
Copy link
Copy Markdown

slnode commented Jun 22, 2017

Can one of the admins verify this patch?

@bajtos bajtos self-requested a review June 23, 2017 14:31
@bajtos bajtos self-assigned this Jun 23, 2017
Copy link
Copy Markdown
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request. The changes look mostly good, please take a look at my comments below.

Comment thread package.json Outdated
{
"name": "loopback-boot",
"version": "2.24.1",
"version": "2.24.2",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert. We are incrementing package version as part of our release process.

Comment thread lib/compiler.js Outdated
// function
var m = require(sourceFile);
var exports = require(sourceFile);
var m = exports && exports.__esModule ? exports.default : exports;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is duplicated on too many places. Could you please extract a shared helper function? Something along the following lines:

// lib/require.js
module.exports = function requireNodeOrEsModule(sourceFile) {
  var exports = require(sourceFile);
  return exports && exports.__esModule ? exports.default : exports;
}

@@ -0,0 +1,11 @@
// Copyright IBM Corp. 2015. All Rights Reserved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Copyright IBM Corp. 2015,2017. All Rights Reserved.

@@ -0,0 +1,11 @@
// Copyright IBM Corp. 2014. All Rights Reserved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Copyright IBM Corp. 2014,2017. All Rights Reserved.

@@ -0,0 +1,11 @@
// Copyright IBM Corp. 2014. All Rights Reserved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Copyright IBM Corp. 2014,2017. All Rights Reserved.

Comment thread test/fixtures/simple-app/boot/umd.js Outdated
@@ -0,0 +1,11 @@
// Copyright IBM Corp. 2014. All Rights Reserved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Copyright IBM Corp. 2014,2017. All Rights Reserved.

Comment thread test/fixtures/simple-app/boot/umd.js Outdated
// Node module: loopback-boot
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
// GENERATED CODE
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this code generated? I am proposing to remove this comment.

@bajtos
Copy link
Copy Markdown
Member

bajtos commented Jun 23, 2017

@slnode ok to test

zamb3zi added a commit to zamb3zi/loopback-boot that referenced this pull request Jun 23, 2017
@zamb3zi
Copy link
Copy Markdown
Author

zamb3zi commented Jun 23, 2017

Great, I've made all those changes. Thanks.

Detect when a script file is an es2015 module created by
a transpiler like Babel or TypeScript and use the `default`
export instead of `module.exports` in such case.

The following artefacts support the new syntax now:

  - boot scripts
  - components
  - middleware
  - model scripts
Copy link
Copy Markdown
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I fixed the copyright years to 2014,2017 and squashed all changes in to a single commit. Let's wait for CI results before landing the patch.

@bajtos bajtos merged commit 06855c1 into strongloop:2.x Jun 26, 2017
@bajtos
Copy link
Copy Markdown
Member

bajtos commented Jun 26, 2017

Landed 🎉 Thank you for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants