Skip to content
This repository was archived by the owner on Sep 17, 2023. It is now read-only.

fix: use pack source instead of hardlink #105

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/make_depend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fs;
use std::path::PathBuf;

use askama::Template;
use pathdiff::diff_paths;

use crate::configuration_file::ConfigurationFile;
use crate::lerna_manifest::LernaManifest;
Expand All @@ -18,7 +19,6 @@ struct MakefileTemplate<'a> {
package_directory: &'a str,
scoped_package_name: &'a str,
unscoped_package_name: &'a str,
pack_archive_filename: &'a str,
internal_dependency_package_json_filenames_inclusive: &'a Vec<String>,
create_pack_target: &'a bool,
npm_pack_archive_dependencies: &'a HashMap<String, String>,
Expand Down Expand Up @@ -47,17 +47,19 @@ pub fn make_dependency_makefile(opts: crate::opts::MakeDepend) -> Result<(), Box
let npm_pack_archive_dependencies = &internal_dependencies_exclusive
.iter()
.map(|dependency| {
let target = package_manifest
let target_directory = package_manifest
.directory()
.join(".internal-npm-dependencies")
.join(".internal-npm-dependencies");
let target = target_directory
.join(dependency.npm_pack_file_basename())
.to_str()
.expect("npm pack filename is not UTF-8 encodable")
.to_owned();
let source = dependency
.npm_pack_filename()
let source_package_directory = dependency.directory();
let source = diff_paths(source_package_directory, target_directory)
.expect("no relative path to source package")
.to_str()
.expect("npm pack filename is not UTF-8 encodable")
.expect("source package path is not UTF-8 encodable")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect messages start with an uppercase letter in this project, except for npm because npm is a proper noun 😅

Not blocking, can follow-up

.to_owned();
(target, source)
})
Expand All @@ -79,10 +81,6 @@ pub fn make_dependency_makefile(opts: crate::opts::MakeDepend) -> Result<(), Box
.expect("Package directory is not UTF-8 encodable"),
scoped_package_name: &package_manifest.contents.name,
unscoped_package_name: package_manifest.unscoped_package_name(),
pack_archive_filename: package_manifest
.npm_pack_filename()
.to_str()
.expect("npm pack filename is not UTF-8 encodable"),
internal_dependency_package_json_filenames_inclusive:
&internal_dependency_package_json_filenames_inclusive
.iter()
Expand Down
4 changes: 0 additions & 4 deletions src/package_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ impl PackageManifest {
)
}

pub fn npm_pack_filename(&self) -> PathBuf {
self.directory().join(&self.npm_pack_file_basename())
}

pub fn unscoped_package_name(&self) -> &str {
match &self.contents.name.rsplit_once("/") {
Some((_scope, name)) => name,
Expand Down
7 changes: 2 additions & 5 deletions templates/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ $({{ unscoped_package_name.replace("-", "_").to_uppercase() }}_INTERNAL_DEPENDEN
# a .PHONY target and let the compiler's built-in logic determine whether or not to
# re-compile its input sources. Since we don't have the list of sources available here,
# let's invoke pack only when the file does not exist.
{{ pack_archive_filename }}:
cd {{ package_directory }}; npm pack --force

{{ unscoped_package_name.replace("-", "_").to_uppercase() }}_INTERNAL_NPM_DEPENDENCIES_EXCLUSIVE = {{ internal_npm_dependencies_exclusive.join(" \\\n") }}

{{ package_directory }}/.internal-npm-dependencies:
mkdir $@

{% for (target, source) in npm_pack_archive_dependencies.iter() %}
{{ target }}: {{ source }} | {{ package_directory }}/.internal-npm-dependencies
rm -f $@
ln $< $@
{{ target }}: | {{ package_directory }}/.internal-npm-dependencies
cd {{ package_directory }}/.internal-npm-dependencies; npm pack {{ source }}
{% endfor %}

.PHONY: {{ unscoped_package_name }}-docker-dependencies
Expand Down