question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I use this with Ember? Given a new Ember project (ember new ember-new), I have this file in app/models/test.js:

import { alias } from "@ember/object/computed";
import { computed } from "@ember/object";
import { inject as service } from "@ember/service";
import DS from "ember-data";

const { attr, Model } = DS;

export default Model.extend({
  store: service(),

  name: attr(),

  alternateName: computed.alias("name"),
  anotherAlias: alias("name")
});

(contrived, but you get the idea)

All of the dependencies seem to be in devDependencies, so I added importDevDependencies: true to the config file.

Removing the imports at the top of this example, none of them are added back in by importjs fix app/models/test.js. Should this be working? I dug around node_modules and noticed most of @ember/... is defined in an ember-source package.

If I add namedExports to the config file, such as below, these specific imports work perfectly, but I noticed it’s deprecated since 2.1.0, and this also doesn’t seem to solve non-named imports:

{
  namedExports: {
    "@ember/object/computed": ["alias"], // etc
    "@ember/object": ["computed", "observer"],
  }
}

I don’t mind manually creating a config file which would make this work for Ember (there’s only ~10-20 things I need to import day-to-day), but I can’t figure out how to write the config file to achieve that. Do I need something special in aliases for this to work?

Thanks in advance!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:12

github_iconTop GitHub Comments

4reactions
monovertexcommented, Aug 10, 2018

Until we get support for plugins and eventually an Ember plugin, I wrote an .importjs.js config file for our ember-cli project which includes all the @ember modules. You can find in this gist.

To extract the modules, I used the data from https://github.com/ember-cli/ember-rfc176-data and the scripts used can be found here: https://github.com/monovertex/ember-rfc176-data/tree/master/scripts (generate-import-js-aliases.js, generate-import-js-core-modules.js, generate-import-js-named-exports.js).

Thank you @justincampbell for the ember-concurrency and ember-qunit named exports 👍.

0reactions
trotzigcommented, Feb 28, 2018

Okay, it’s getting late here and I’m not having much success with my attempt at finding ember exports automatically. The idea I had was to use the findExports function from import-js to automatically create the lists you had in your gist. As long as we know the paths to the files exporting those variables, we can theoretically auto-find them inside .importjs.js. Something like

const fs = require('fs');
const findExports = require('import-js/build/findExports');

const path = require.resolve('@ember/object');
const exports = findExports(fs.readFileSync(path), path);

// do something with exports
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ember Help Bar
Ember Mug · Travel Mug · Ember App ... Register your product and we'll help you get the very best from your product...
Read more >
Ember®: The World's First Temperature Control Mug®
With the Ember® temperature control mug, you can enjoy your coffee or tea at the perfect temperature all the time. Click to buy...
Read more >
Customer Support – Embertec USA LLC
Our Embertec experts are here to answer your questions, help you troubleshoot issues, improve your experience and increase satisfaction with our products.
Read more >
Browser Support - Ember.js
Ember runs tests against the latest desktop versions of the following browsers: Google Chrome; Mozilla Firefox; Microsoft Edge; Internet Explorer 11; Safari ...
Read more >
Help Desk - Ember IT
We've been doing help desk for a long, long time, responding to client support tickets since 1999. Our line has been open for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found