aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2019-01-17 13:24:09 -0500
committerGitHub <noreply@github.com>2019-01-17 13:24:09 -0500
commit69c963c2e8ac56f4832e767c3c83091b9c6f24dd (patch)
tree30e20d7a0a6cd1c7074bb4113778888bbf6fb3f9 /actiontext
parent2dee59fed1e78b983aed4db53dc8fc59e49b9200 (diff)
parent866da19fd9fc12d001ab99ac87890ea1cebb2cd9 (diff)
downloadrails-69c963c2e8ac56f4832e767c3c83091b9c6f24dd.tar.gz
rails-69c963c2e8ac56f4832e767c3c83091b9c6f24dd.tar.bz2
rails-69c963c2e8ac56f4832e767c3c83091b9c6f24dd.zip
Merge pull request #34958 from javan/actiontext/trix-as-peer
Declare Trix as peer dependency of Action Text's npm package
Diffstat (limited to 'actiontext')
-rw-r--r--actiontext/app/javascript/actiontext/index.js1
-rw-r--r--actiontext/lib/templates/installer.rb29
-rw-r--r--actiontext/package.json4
3 files changed, 23 insertions, 11 deletions
diff --git a/actiontext/app/javascript/actiontext/index.js b/actiontext/app/javascript/actiontext/index.js
index c149eda952..0e9251018a 100644
--- a/actiontext/app/javascript/actiontext/index.js
+++ b/actiontext/app/javascript/actiontext/index.js
@@ -1,4 +1,3 @@
-import * as Trix from "trix"
import { AttachmentUpload } from "./attachment_upload"
addEventListener("trix-attachment-add", event => {
diff --git a/actiontext/lib/templates/installer.rb b/actiontext/lib/templates/installer.rb
index e7c6c2623e..990e41ca00 100644
--- a/actiontext/lib/templates/installer.rb
+++ b/actiontext/lib/templates/installer.rb
@@ -1,3 +1,13 @@
+require "pathname"
+require "json"
+
+APPLICATION_PACK_PATH = Pathname.new("app/javascript/packs/application.js")
+JS_PACKAGE_PATH = Pathname.new("#{__dir__}/../../package.json")
+
+JS_PACKAGE = JSON.load(JS_PACKAGE_PATH)
+JS_DEPENDENCIES = JS_PACKAGE["peerDependencies"].dup.merge \
+ JS_PACKAGE["name"] => "^#{JS_PACKAGE["version"]}"
+
say "Copying actiontext.scss to app/assets/stylesheets"
copy_file "#{__dir__}/actiontext.scss", "app/assets/stylesheets/actiontext.scss"
@@ -8,14 +18,15 @@ say "Copying blob rendering partial to app/views/active_storage/blobs/_blob.html
copy_file "#{__dir__}/../../app/views/active_storage/blobs/_blob.html.erb",
"app/views/active_storage/blobs/_blob.html.erb"
-say "Installing JavaScript dependency"
-run "yarn add @rails/actiontext"
-
-APPLICATION_PACK_PATH = "app/javascript/packs/application.js"
+say "Installing JavaScript dependencies"
+run "yarn add #{JS_DEPENDENCIES.map { |name, version| "#{name}@#{version}" }.join(" ")}"
-if File.exist?(APPLICATION_PACK_PATH) && File.read(APPLICATION_PACK_PATH) !~ /import "@rails\/actiontext"/
- say "Adding import to default JavaScript pack"
- append_to_file APPLICATION_PACK_PATH, <<-EOS
-import "@rails/actiontext"
-EOS
+if APPLICATION_PACK_PATH.exist?
+ JS_DEPENDENCIES.keys.each do |name|
+ line = %[require("#{name}")]
+ unless APPLICATION_PACK_PATH.read.include? line
+ say "Adding #{name} to #{APPLICATION_PACK_PATH}"
+ append_to_file APPLICATION_PACK_PATH, "#{line}\n"
+ end
+ end
end
diff --git a/actiontext/package.json b/actiontext/package.json
index ec8f35fd3c..ee4666b85c 100644
--- a/actiontext/package.json
+++ b/actiontext/package.json
@@ -21,7 +21,9 @@
],
"license": "MIT",
"dependencies": {
- "trix": "^1.0.0",
"@rails/activestorage": "^6.0.0-alpha"
+ },
+ "peerDependencies": {
+ "trix": "^1.0.0"
}
}