Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Yarn workspaces? #568

Open
jackiehluo opened this issue May 1, 2018 · 1 comment
Open

Support for Yarn workspaces? #568

jackiehluo opened this issue May 1, 2018 · 1 comment

Comments

@jackiehluo
Copy link

Which operating system and version is the project developed on?
macOS High Sierra, 10.13.4

Which version of ruby is the project developed on?
2.3.1

Which version of npm is the project developed on?
Yarn 1.6.0

Which version of ember-cli is the project developed on?
3.1.3

What is the rails version?
4.2.7.1

What is the ember-cli-rails version (from Gemfile)?
0.10.0

What is the ember-cli-rails-addon version (from package.json)?
0.10.0

Is your application server multi-threaded
(such as puma and unicorn) or is it multi-process (such as thin and webrick)?

Multi-threaded (puma).

What are the contents of config/initializers/ember.rb?

EmberCli.configure do |c|
  c.app :frontend, path: "frontend/packages/application"
end

I'm using Yarn workspaces, and so I have the Rails project, a frontend directory inside it, and then the Ember app I want to mount lives at frontend/packages/application. However, I've been getting a DependencyError:

No `ember-cli` executable found for `frontend`.

Install it:

    $ cd /Users/jackieluo/Code/merchant-front-end/frontend/packages/application
    $ npm install

Due the nature of Yarn workspaces, the node_modules live in frontend, not the application directory, but I think the application should still have access to the Ember CLI executable:

screen shot 2018-05-01 at 4 28 31 pm

Does the project support Yarn workspaces in general? If not, is that on the roadmap at all?

Thanks!

@Skipants
Copy link

Not sure if anyone cares 4 years later but here's what we did in our fork of ember-cli-rails to get workspaces working:

diff --git a/lib/ember_cli/path_set.rb b/lib/ember_cli/path_set.rb
index 9a30e2c..c246a51 100644
--- a/lib/ember_cli/path_set.rb
+++ b/lib/ember_cli/path_set.rb
@@ -1,3 +1,4 @@
+require "json"
 require "ember_cli/helpers"
 
 module EmberCli
@@ -41,7 +42,7 @@ module EmberCli
 
     def ember
       @ember ||= begin
-        root.join("node_modules", "ember-cli", "bin", "ember").tap do |path|
+        ember_path.tap do |path|
           unless path.executable?
             fail DependencyError.new <<-MSG.strip_heredoc
               No `ember-cli` executable found for `#{app_name}`.
@@ -148,6 +149,31 @@ module EmberCli
       app_options[:yarn] || app_options[:yarn_path]
     end
 
+    def workspace?
+      manifest_path = rails_root.join("package.json")
+      return false unless File.file?(manifest_path)
+
+      workspaces = JSON.parse(File.read(manifest_path)).fetch("workspaces", [])
+
+      workspaces.any? { |workspace| File.fnmatch(workspace, relative_path) }
+    end
+
+    def relative_path
+      @relative_path ||= begin
+        path = app_options.fetch(:path) { default_root }
+        pathname = Pathname.new(path)
+        pathname.relative_path_from(rails_root)
+      end
+    end
+
+    def ember_path
+      if workspace?
+        root.join("node_modules", ".bin", "ember")
+      else
+        root.join("node_modules", "ember-cli", "bin", "ember")
+      end
+    end
+
     def app_name
       app.name
     end

This works because doing a yarn install at the top-level with a package.json that has workspaces drops an ember bin stub in each dir under node_modules/.bin/ember.

I am not confident in making a PR because I'm not totally 100% knowledgeable about this gem and not sure where setup from our app starts and the gem finish. It's also only been tested with yarn (latest), node 14, rails 5, and ruby 2.5. So YMMV.

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

No branches or pull requests

2 participants