fix(core): add outputs to nx.json for nx init in monorepo (#22061)

This commit is contained in:
Emily Xiong 2024-03-05 00:56:32 -05:00 committed by GitHub
parent 587fe6a63b
commit 22de9b5b84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 30 deletions

View File

@ -113,7 +113,7 @@ export async function addNxToNest(options: Options, packageJson: PackageJson) {
repoRoot,
[],
[...cacheableOperations, ...nestCacheableScripts],
{}
scriptOutputs
);
const pmc = getPackageManagerCommand();
@ -121,12 +121,7 @@ export async function addNxToNest(options: Options, packageJson: PackageJson) {
updateGitIgnore(repoRoot);
addDepsToPackageJson(repoRoot);
addNestPluginToPackageJson(repoRoot);
markRootPackageJsonAsNxProject(
repoRoot,
cacheableOperations,
scriptOutputs,
pmc
);
markRootPackageJsonAsNxProject(repoRoot, cacheableOperations, pmc);
createProjectJson(repoRoot, packageJson, nestCLIConfiguration);
removeFile(repoRoot, 'nest-cli.json');

View File

@ -72,18 +72,13 @@ export async function addNxToNpmRepo(options: Options) {
: false);
}
createNxJsonFile(repoRoot, [], cacheableOperations, {});
createNxJsonFile(repoRoot, [], cacheableOperations, scriptOutputs);
const pmc = getPackageManagerCommand();
updateGitIgnore(repoRoot);
addDepsToPackageJson(repoRoot);
markRootPackageJsonAsNxProject(
repoRoot,
cacheableOperations,
scriptOutputs,
pmc
);
markRootPackageJsonAsNxProject(repoRoot, cacheableOperations, pmc);
output.log({ title: '📦 Installing dependencies' });

View File

@ -39,6 +39,7 @@ export function createNxJsonFile(
nxJson.targetDefaults[scriptName] ??= {};
nxJson.targetDefaults[scriptName] = { dependsOn: [`^${scriptName}`] };
}
}
for (const [scriptName, output] of Object.entries(scriptOutputs)) {
if (!output) {
// eslint-disable-next-line no-continue
@ -47,7 +48,6 @@ export function createNxJsonFile(
nxJson.targetDefaults[scriptName] ??= {};
nxJson.targetDefaults[scriptName].outputs = [`{projectRoot}/${output}`];
}
}
for (const target of cacheableOperations) {
nxJson.targetDefaults[target] ??= {};
@ -171,20 +171,12 @@ export function addVsCodeRecommendedExtensions(
export function markRootPackageJsonAsNxProject(
repoRoot: string,
cacheableScripts: string[],
scriptOutputs: { [script: string]: string },
pmc: PackageManagerCommands
) {
const json = readJsonFile<PackageJson>(
joinPathFragments(repoRoot, `package.json`)
);
json.nx = { targets: {} };
for (let script of Object.keys(scriptOutputs)) {
if (scriptOutputs[script]) {
json.nx.targets[script] = {
outputs: [`{projectRoot}/${scriptOutputs[script]}`],
};
}
}
json.nx = {};
for (let script of cacheableScripts) {
const scriptDefinition = json.scripts[script];
if (!scriptDefinition) {