Skip to content

Commit

Permalink
Fix failure installing yarn 1.22.22 (#1519)
Browse files Browse the repository at this point in the history
* Fix failure installing yarn 1.22.22

In #1516 there were reported build failures:

```
remote: -----> Installing node-v22.11.0-linux-x64
remote: -----> Installing yarn-v1.22.22
remote:
remote:  !
remote:  !     No such file or directory @ rb_file_s_rename - (/tmp/d20241108-1032-vggdc3/yarn-v1.22.22, yarn-v1.22.22)
remote:  !
remote: /tmp/tmp.l8hWafbPfJ/lib/ruby/3.1.0/fileutils.rb:541:in `rename': No such file or directory @ rb_file_s_rename - (/tmp/d20241108-1032-vggdc3/yarn-v1.22.22, yarn-v1.22.22) (Errno::ENOENT)
remote: 	from /tmp/tmp.l8hWafbPfJ/lib/ruby/3.1.0/fileutils.rb:541:in `block in mv'
remote: 	from /tmp/tmp.l8hWafbPfJ/lib/ruby/3.1.0/fileutils.rb:1577:in `block in fu_each_src_dest'
remote: 	from /tmp/tmp.l8hWafbPfJ/lib/ruby/3.1.0/fileutils.rb:1593:in `fu_each_src_dest0'
remote: 	from /tmp/tmp.l8hWafbPfJ/lib/ruby/3.1.0/fileutils.rb:1575:in `fu_each_src_dest'
remote: 	from /tmp/tmp.l8hWafbPfJ/lib/ruby/3.1.0/fileutils.rb:532:in `mv'
remote: 	from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/helpers/yarn_installer.rb:27:in `block in install'
remote: 	from /tmp/tmp.l8hWafbPfJ/lib/ruby/3.1.0/tmpdir.rb:96:in `mktmpdir'
```

This is because older versions of the yarn package have a top level directory that looks like this:

```
yarn-v1.22.19/
```

But yarn 1.22.22 has a directory named "package" instead:

```
package/
```

To work around this naming issue we can use `--strip 1` tar flag to remove the top level directory. From gnutar manfiles https://www.gnu.org/software/tar/manual/tar.html:

```
‘--strip-components=number’
Strip given number of leading components from file names before extraction.

For example, suppose you have archived whole ‘/usr’ hierarchy to a tar archive named ‘usr.tar’. Among other files, this archive contains ‘usr/include/stdlib.h’, which you wish to extract to the current working directory. To do so, you type:

$ tar -xf usr.tar --strip=2 usr/include/stdlib.h
The option ‘--strip=2’ instructs tar to strip the two leading components (‘usr/’ and ‘include/’) off the file name.

If you add the ‘--verbose’ (‘-v’) option to the invocation above, you will note that the verbose listing still contains the full file name, with the two removed components still in place. This can be inconvenient, so tar provides a special option for altering this behavior:
```

* Default to strip 0 instead of true

From the feedback:

> Minor - maybe the default for strip_components should be 0 instead of false? From this signature, I would expect that if I want it to strip components I would pass true instead of false but that would produce an invalid command.
  • Loading branch information
schneems authored Nov 14, 2024
1 parent a3f4f66 commit 55ee089
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- Default Node.js version now 22.11.0 (https://github.com/heroku/heroku-buildpack-ruby/pull/1503)
- Default Yarn version now 1.22.22 (https://github.com/heroku/heroku-buildpack-ruby/pull/1503)

## [v282] - 2024-11-08

Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions lib/language_pack/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def fetch(path)
run!(curl, error_class: FetchError)
end

def fetch_untar(path, files_to_extract = nil)
def fetch_untar(path, files_to_extract = nil, strip_components: 0)
curl = curl_command("#{@host_url.join(path)} -s -o")
run! "#{curl} - | tar zxf - #{files_to_extract}",
tar_cmd = ["tar zxf - #{files_to_extract}", "--strip #{strip_components}"]
run! "#{curl} - | #{tar_cmd.join(" ")}",
error_class: FetchError,
max_attempts: 3
end
Expand Down
4 changes: 2 additions & 2 deletions lib/language_pack/helpers/yarn_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def binary_path
def install
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
@fetcher.fetch_untar(@url)
@fetcher.fetch_untar(@url, strip_components: 1)
end

FileUtils.mv(File.join(dir, name), name)
FileUtils.cp_r(dir, name)
end
end
end

0 comments on commit 55ee089

Please sign in to comment.