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

Fix issue with "assets:clean" tasks #2385

Closed
wants to merge 2 commits into from
Closed

Fix issue with "assets:clean" tasks #2385

wants to merge 2 commits into from

Conversation

le0pard
Copy link

@le0pard le0pard commented Dec 4, 2019

Issue

By using task bundle exec rake 'assets:clean[3]' gets error: Errno::ENOENT: No such file or directory @ apply2files

Reason

Generated manifest.json file contain this content:

{
  "app.css": "/packs/css/app-bf1542ff.css",
  "app.js": "/packs/js/app-2f5fcfce1c5201c7ae37.js",
  "app.js.map": "/packs/debugging/js/app-2f5fcfce1c5201c7ae37.js.map",
  "entrypoints": {
    "app": {
      "css": [
        "/packs/css/app-bf1542ff.css"
      ],
      "js": [
        "/packs/js/app-2f5fcfce1c5201c7ae37.js"
      ],
      "js.map": [
        "/packs/debugging/js/app-2f5fcfce1c5201c7ae37.js.map"
      ]
    },
    "landing": {
      "css": [
        "/packs/css/landing-b87760de.css"
      ],
      "js": [
        "/packs/js/landing-9ea1a07c26296dbf83d1.js"
      ],
      "js.map": [
        "/packs/debugging/js/landing-9ea1a07c26296dbf83d1.js.map"
      ]
    },
    "mailer": {
      "css": [
        "/packs/css/mailer-b026c729.css"
      ],
      "js": [
        "/packs/js/mailer-99c4577677ba5b22d7b2.js"
      ],
      "js.map": [
        "/packs/debugging/js/mailer-99c4577677ba5b22d7b2.js.map"
      ]
    },
    "print": {
      "css": [
        "/packs/css/print-0e62cc69.css"
      ],
      "js": [
        "/packs/js/print-5a112cec83cf65e54183.js"
      ],
      "js.map": [
        "/packs/debugging/js/print-5a112cec83cf65e54183.js.map"
      ]
    }
  },
  "landing.css": "/packs/css/landing-b87760de.css",
  "landing.js": "/packs/js/landing-9ea1a07c26296dbf83d1.js",
  "landing.js.map": "/packs/debugging/js/landing-9ea1a07c26296dbf83d1.js.map",
  "mailer.css": "/packs/css/mailer-b026c729.css",
  "mailer.js": "/packs/js/mailer-99c4577677ba5b22d7b2.js",
  "mailer.js.map": "/packs/debugging/js/mailer-99c4577677ba5b22d7b2.js.map",
  "print.css": "/packs/css/print-0e62cc69.css",
  "print.js": "/packs/js/print-5a112cec83cf65e54183.js",
  "print.js.map": "/packs/debugging/js/print-5a112cec83cf65e54183.js.map"
}

This converted by process_manifest_hash(manifest_hash) to:

["/var/www/example/releases/20191204055949/public/packs/css/app-bf1542ff.css",
 "/var/www/example/releases/20191204055949/public/packs/js/app-2f5fcfce1c5201c7ae37.js",
 "/var/www/example/releases/20191204055949/public/packs/debugging/js/app-2f5fcfce1c5201c7ae37.js.map",
 "/var/www/example/releases/20191204055949/public/packs/assets/janbodnar-6a1f51bf6f2b99610c781a771b7db549.jpg",
 "/var/www/example/releases/20191204055949/public/packs/assets/signup_bg_girl-0b2a589a8c60b45ae7859fce11c3d23b.svg",
 "/var/www/example/releases/20191204055949/public/packs/assets/signup_bg_mobile-8c6789d7d6cfeb6f6411cd8bbb761ebb.svg",
 "/var/www/example/releases/20191204055949/public/packs/assets/signup_bg_tablet-146a692125d7f1e9daca3938ba44999b.svg",
 "/var/www/example/releases/20191204055949/public/packs/css/app-bf1542ff.css",
 "/var/www/example/releases/20191204055949/public/packs/js/app-2f5fcfce1c5201c7ae37.js",
 "/var/www/example/releases/20191204055949/public/packs/debugging/js/app-2f5fcfce1c5201c7ae37.js.map",
 "/var/www/example/releases/20191204055949/public/packs/css/landing-b87760de.css",
 "/var/www/example/releases/20191204055949/public/packs/js/landing-9ea1a07c26296dbf83d1.js",
 "/var/www/example/releases/20191204055949/public/packs/debugging/js/landing-9ea1a07c26296dbf83d1.js.map",
 "/var/www/example/releases/20191204055949/public/packs/css/mailer-b026c729.css",
 "/var/www/example/releases/20191204055949/public/packs/js/mailer-99c4577677ba5b22d7b2.js",
 "/var/www/example/releases/20191204055949/public/packs/debugging/js/mailer-99c4577677ba5b22d7b2.js.map",
 "/var/www/example/releases/20191204055949/public/packs/css/print-0e62cc69.css",
 "/var/www/example/releases/20191204055949/public/packs/js/print-5a112cec83cf65e54183.js",
 "/var/www/example/releases/20191204055949/public/packs/debugging/js/print-5a112cec83cf65e54183.js.map",
 "/var/www/example/releases/20191204055949/public/packs/css/landing-b87760de.css",
 "/var/www/example/releases/20191204055949/public/packs/js/landing-9ea1a07c26296dbf83d1.js",
 "/var/www/example/releases/20191204055949/public/packs/debugging/js/landing-9ea1a07c26296dbf83d1.js.map",
 "/var/www/example/releases/20191204055949/public/packs/css/mailer-b026c729.css",
 "/var/www/example/releases/20191204055949/public/packs/js/mailer-99c4577677ba5b22d7b2.js",
 "/var/www/example/releases/20191204055949/public/packs/debugging/js/mailer-99c4577677ba5b22d7b2.js.map",
 "/var/www/example/releases/20191204055949/public/packs/css/print-0e62cc69.css",
 "/var/www/example/releases/20191204055949/public/packs/js/print-5a112cec83cf65e54183.js",
 "/var/www/example/releases/20191204055949/public/packs/debugging/js/print-5a112cec83cf65e54183.js.map"]

This lead to duplication for filenames in this array at files_in_manifest (example: app-2f5fcfce1c5201c7ae37.js). After collecting information in variable files_to_be_removed we get this result:

["/var/www/example/releases/20191204055949/public/packs/js/app-1949e13f6d3c0fe658f0.js", 
"/var/www/example/releases/20191204055949/public/packs/js/app-1949e13f6d3c0fe658f0.js"]

As we can see, we marked for remove twice the same file (because we twice search old assets for app.js).

Solution

By adding uniq we can fix this problem.

Errno::ENOENT: No such file or directory @ apply2files
@le0pard
Copy link
Author

le0pard commented Dec 4, 2019

You can test this solution by adding patch in your rails app in config/initializers:

Webpacker::Commands.class_eval do

  private

  def process_manifest_hash(manifest_hash)
    manifest_hash.values.map do |value|
      next process_manifest_hash(value) if value.is_a?(Hash)

      File.join(config.root_path, 'public', value)
    end.flatten.uniq
  end
end

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.

1 participant