Remove yarn-closure code
This commit is contained in:
+4
-46
@@ -27,7 +27,6 @@ const generate = async (project: Project, cache: Cache, report: Report) => {
|
||||
const { configuration, cwd } = project;
|
||||
const yarnPathAbs = configuration.get(`yarnPath`);
|
||||
const cacheFolderAbs = configuration.get(`cacheFolder`);
|
||||
const lockfileFilename = configuration.get(`lockfileFilename`);
|
||||
|
||||
let yarnPath = ppath.relative(cwd, yarnPathAbs);
|
||||
if (yarnPath.startsWith(`../`)) {
|
||||
@@ -47,48 +46,15 @@ const generate = async (project: Project, cache: Cache, report: Report) => {
|
||||
);
|
||||
}
|
||||
|
||||
// List files the derivation will depend on.
|
||||
const yarnClosureInput = new Set([
|
||||
`package.json`,
|
||||
lockfileFilename,
|
||||
yarnPath,
|
||||
]);
|
||||
for (const source of configuration.sources.values()) {
|
||||
if (!source.startsWith(`<`)) {
|
||||
yarnClosureInput.add(source);
|
||||
}
|
||||
}
|
||||
// TODO: Better way to find plugins? Re-parse rcfiles maybe?
|
||||
const pluginsDir = ppath.join(cwd, `.yarn/plugins` as Filename);
|
||||
if (xfs.existsSync(pluginsDir)) {
|
||||
for (const filename of xfs.readdirSync(pluginsDir)) {
|
||||
yarnClosureInput.add(ppath.join(pluginsDir, filename));
|
||||
}
|
||||
}
|
||||
|
||||
// Build Nix `filterSource` entries to match on.
|
||||
const yarnClosureEntries = new Set();
|
||||
for (const inputPath of yarnClosureInput) {
|
||||
// Filter paths not reachable during the build and warn. (These are often
|
||||
// just user global configuration files, but the warnings can help highlight
|
||||
// dependencies on private registries.)
|
||||
const relativePath = ppath.relative(cwd, inputPath);
|
||||
if (relativePath.startsWith(`../`)) {
|
||||
if (inputPath !== yarnPath) {
|
||||
const relativeSource = ppath.relative(cwd, source);
|
||||
if (relativeSource.startsWith(`../`)) {
|
||||
report.reportWarning(
|
||||
0,
|
||||
`The path ${inputPath} is outside the project and was ignored - it may not be reachable in the Nix build`
|
||||
`The config file ${source} is outside the project - it may not be reachable by the Nix build`
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Add the file itself.
|
||||
yarnClosureEntries.add(`regular:${relativePath}`);
|
||||
// Add directories leading up to the file.
|
||||
let dir = ppath.dirname(relativePath);
|
||||
while (dir !== `.`) {
|
||||
yarnClosureEntries.add(`directory:${dir}`);
|
||||
dir = ppath.dirname(dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +84,7 @@ const generate = async (project: Project, cache: Cache, report: Report) => {
|
||||
const projectName = ident ? structUtils.stringifyIdent(ident) : `workspace`;
|
||||
const projectExpr = projectExprTmpl
|
||||
.replace(`@@PROJECT_NAME@@`, JSON.stringify(projectName))
|
||||
.replace(`@@YARN_PATH@@`, JSON.stringify(yarnPath))
|
||||
.replace(`@@CACHE_FOLDER@@`, JSON.stringify(cacheFolder))
|
||||
.replace(
|
||||
`@@CACHE_ENTRIES@@`,
|
||||
@@ -126,15 +93,6 @@ const generate = async (project: Project, cache: Cache, report: Report) => {
|
||||
.map((entry) => ` { ${entry.join(` `)} }\n`)
|
||||
.join(``) +
|
||||
` ]`
|
||||
)
|
||||
.replace(`@@YARN_PATH@@`, JSON.stringify(yarnPath))
|
||||
.replace(
|
||||
`@@YARN_CLOSURE_ENTRIES@@`,
|
||||
`[\n` +
|
||||
[...yarnClosureEntries]
|
||||
.map((entry) => ` ${JSON.stringify(entry)}\n`)
|
||||
.join(``) +
|
||||
` ]`
|
||||
);
|
||||
const projectExprPath = ppath.join(cwd, `yarn-project.nix` as Filename);
|
||||
xfs.writeFileSync(projectExprPath, projectExpr);
|
||||
|
||||
+3
-14
@@ -9,10 +9,9 @@ let
|
||||
|
||||
# Variables provided by the generator.
|
||||
project-name = @@PROJECT_NAME@@;
|
||||
yarn-path = @@YARN_PATH@@;
|
||||
cache-folder = @@CACHE_FOLDER@@;
|
||||
cache-entries = @@CACHE_ENTRIES@@;
|
||||
yarn-path = @@YARN_PATH@@;
|
||||
yarn-closure-entries = @@YARN_CLOSURE_ENTRIES@@;
|
||||
|
||||
# Defines the shell alias to run Yarn.
|
||||
yarn-alias = ''
|
||||
@@ -21,16 +20,6 @@ let
|
||||
}
|
||||
'';
|
||||
|
||||
# Directory of just the files needed to run Yarn.
|
||||
yarn-closure = cleanSourceWith {
|
||||
inherit src;
|
||||
filter = let
|
||||
srcStr = toString src;
|
||||
srcRel = removePrefix "${srcStr}/";
|
||||
in path: type:
|
||||
elem "${type}:${srcRel path}" yarn-closure-entries;
|
||||
};
|
||||
|
||||
# Fetch a single dependency.
|
||||
fetch = { filename, sha512, locator-hash }: stdenv.mkDerivation {
|
||||
name = replaceStrings [ "@" ] [ "-" ] filename;
|
||||
@@ -46,7 +35,7 @@ let
|
||||
export yarn_cache_folder="$PWD"
|
||||
|
||||
# Setup to environment so we can run Yarn.
|
||||
pushd '${yarn-closure}' > /dev/null
|
||||
pushd '${src}' > /dev/null
|
||||
|
||||
export NIX_YARN_PATH="$(readlink -f '${yarn-path}')"
|
||||
${yarn-alias}
|
||||
@@ -128,6 +117,6 @@ in stdenv.mkDerivation {
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
inherit yarn-closure offline-cache;
|
||||
inherit offline-cache;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user