Sha256: f74dd3d285304d6481541a7e2a26e18df838924971d5b3007ec203453518b2dd
Contents?: true
Size: 1.73 KB
Versions: 2
Compression:
Stored size: 1.73 KB
Contents
# frozen_string_literal: true require "rails/generators" require "webpacker/runner" require "webpacker/compiler" module Webpacker module PNPM # remove Yarn's lockfile from and add pnpm's lockfile to the default list of # watched paths Webpacker::Compiler.class_eval do def default_watched_paths [ *config.resolved_paths_globbed, config.source_path_globbed, "pnpm-lock.yaml", "package.json", "config/webpack/**/*" ].freeze end end # intercept command execution via Thor to replace yarn with pnpm. this exists in # order to patch existing Webpacker installation templates that make direct # calls to install Yarn dependencies. as a result, this isn't a robust patch Rails::Generators::Actions.module_eval do def run(command, config = {}) cmd = command.to_s if cmd.include?("yarn") cmd.gsub!("yarn", "pnpm") cmd.gsub!("--dev", "--save-dev") end super(cmd, config) end end # intercept generic task loading to clear and alias Yarn tasks Rails::Engine.class_eval do alias_method :unfiltered_tasks, :load_tasks def load_tasks(_app = self) unfiltered_tasks # rather than clear the tasks, alias them to the new pnpm tasks so # that any external code will still run Rake::Task["webpacker:check_yarn"].clear.enhance(["webpacker:check_pnpm"]) Rake::Task["webpacker:yarn_install"].clear.enhance(["webpacker:pnpm_install"]) Rake::Task["webpacker:info"].clear.enhance(["webpacker:env"]) Rake::Task["yarn:install"].clear.enhance(["webpacker:pnpm_install"]) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
webpacker-pnpm-1.2.1 | lib/webpacker/pnpm/patches.rb |
webpacker-pnpm-1.2.0 | lib/webpacker/pnpm/patches.rb |