More relative path fixes

This commit is contained in:
Stéphan Kochen
2023-01-23 14:55:05 +01:00
parent 3938c85ffe
commit 10a8f5a83b
2 changed files with 39 additions and 26 deletions
+32 -17
View File
@@ -45,14 +45,16 @@ export default async (
return;
}
// Sanity checks.
const yarnPathAbs = configuration.get(`yarnPath`);
// Determine relative paths for Nix path literals.
const nixExprPath = configuration.get(`nixExprPath`);
let yarnPath: PortablePath;
const yarnPathAbs = configuration.get(`yarnPath`);
let yarnPathExpr: string;
if (yarnPathAbs.startsWith(cwd)) {
yarnPath = ppath.relative(ppath.dirname(nixExprPath), yarnPathAbs);
yarnPathExpr =
"./" + ppath.relative(ppath.dirname(nixExprPath), yarnPathAbs);
} else {
yarnPath = yarnPathAbs;
yarnPathExpr = json(yarnPathAbs);
report.reportWarning(
0,
`The Yarn path ${yarnPathAbs} is outside the project - it may not be reachable by the Nix build`
@@ -60,29 +62,42 @@ export default async (
}
const cacheFolderAbs = configuration.get(`cacheFolder`);
let cacheFolder = ppath.relative(cwd, cacheFolderAbs);
if (cacheFolder.startsWith(`../`)) {
cacheFolder = cacheFolderAbs;
let cacheFolderExpr: string;
if (cacheFolderAbs.startsWith(cwd)) {
cacheFolderExpr =
"./" + ppath.relative(ppath.dirname(nixExprPath), cacheFolderAbs);
} else {
cacheFolderExpr = json(cacheFolderAbs);
report.reportWarning(
0,
`The cache folder ${cacheFolderAbs} is outside the project - it may not be reachable by the Nix build`
);
}
for (const source of configuration.sources.values()) {
const configSources = new Set();
for (const sourceList of configuration.sources.values()) {
for (const source of sourceList.split(", ")) {
if (!source.startsWith(`<`)) {
const relativeSource = ppath.relative(cwd, source as PortablePath);
if (relativeSource.startsWith(`../`)) {
configSources.add(source);
}
}
}
for (const source of configSources) {
const relativeSource = ppath.resolve(cwd, source as PortablePath);
if (!relativeSource.startsWith(cwd)) {
report.reportWarning(
0,
`The config file ${source} is outside the project - it may not be reachable by the Nix build`
);
}
}
}
// Determine relative paths for Nix path literals.
const lockfileFilename = configuration.get(`lockfileFilename`);
const lockfileExpr =
"./" +
ppath.relative(
ppath.dirname(nixExprPath),
ppath.resolve(cwd, configuration.get(`lockfileFilename`))
);
// Build a list of cache entries so Nix can fetch them.
// TODO: See if we can use Nix fetchurl for npm: dependencies.
@@ -278,9 +293,9 @@ export default async (
const projectName = ident ? structUtils.stringifyIdent(ident) : `workspace`;
const projectExpr = renderTmpl(projectExprTmpl, {
PROJECT_NAME: json(projectName),
YARN_PATH: yarnPath,
LOCKFILE: lockfileFilename,
CACHE_FOLDER: json(cacheFolder),
YARN_PATH: yarnPathExpr,
LOCKFILE: lockfileExpr,
CACHE_FOLDER: cacheFolderExpr,
CACHE_ENTRIES: cacheEntriesCode,
ISOLATED: isolatedCode.join("\n"),
ISOLATED_INTEGRATION: indent(" ", isolatedIntegration.join("\n")),
+3 -5
View File
@@ -7,9 +7,7 @@
let
cacheFolder = @@CACHE_FOLDER@@;
#@@ IF NEED_ISOLATED_BUILD_SUPPRORT
lockfile = ./@@LOCKFILE@@;
#@@ ENDIF NEED_ISOLATED_BUILD_SUPPRORT
lockfile = @@LOCKFILE@@;
# Call overrideAttrs on a derivation if a function is provided.
optionalOverride = fn: drv:
@@ -17,7 +15,7 @@ let
# Simple stub that provides the global yarn command.
yarn = writeShellScriptBin "yarn" ''
exec '${nodejs}/bin/node' '${./@@YARN_PATH@@}' "$@"
exec '${nodejs}/bin/node' '${@@YARN_PATH@@}' "$@"
'';
# Common attributes between Yarn derivations.
@@ -164,7 +162,7 @@ let
mkdir -p "$out/libexec/$name"
tar xzvf package.tgz --directory "$out/libexec/$name" --strip-components=1
cp .yarnrc* '@@LOCKFILE@@' "$out/libexec/$name"
cp .yarnrc* ${lockfile} "$out/libexec/$name"
cp --recursive .yarn "$out/libexec/$name"
# If the project uses the node-modules linker, then