Skip to content

webpacker:clean is deleting files when they are outputted more than 2 seconds apart #2441

Closed
@sbeam

Description

@sbeam

In 4.2.2, the webpacker:clean task is grouping all files that are not mentioned in manifest.json by their last modified time, down to a one-second resolution. This is meant to find very old versions of assets files that can be safely deleted.

After upgrading and deploying to Heroku yesterday, noticed many lines in the build log where assets were being removed just after being compiled (including on brand new app deploys where /public/packs started out empty).

On heroku, and sometimes locally, these groups of files can easily span more than the default of 2. This task now removes all files except from the last 2 seconds.

Here is a example console session from a brand new heroku app where the assets:clean task was skipped, but mimicking the code that would have run if it were left alone:

irb(main):010:0> all_files       = Dir.glob("public/packs/**/*")
irb(main):011:0> manifest_config = Dir.glob("public/packs/manifest.json*")
irb(main):012:0> packs = all_files - manifest_config
irb(main):013:0> pp packs.group_by { |file| File.mtime(file).utc.to_i }.sort.reverse.map(&:first); nil
[1579728071, 1579728056, 1579728055, 1579728054]

webpack outputted files over a period of 17 seconds here, and this clean task would have deleted all the files from the first two groups, including the main .js entrypoints and a lot of other useful stuff.

I think this is due to changes in #2389. Possibly could decrease the resolution of that grouping to something more pessimistic, like 1 minute, or add a min_age param so that it ignores basically new files.

In the meantime have added Rake::Task['assets:clean'].clear to the app to avoid this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions