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

View File

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

View File

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