Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,15 @@ export async function addNxToNest(options: Options, packageJson: PackageJson) {
repoRoot,
[],
[...cacheableOperations, ...nestCacheableScripts],
{}
scriptOutputs
);

const pmc = getPackageManagerCommand();

updateGitIgnore(repoRoot);
addDepsToPackageJson(repoRoot);
addNestPluginToPackageJson(repoRoot);
markRootPackageJsonAsNxProject(
repoRoot,
cacheableOperations,
scriptOutputs,
pmc
);
markRootPackageJsonAsNxProject(repoRoot, cacheableOperations, pmc);

createProjectJson(repoRoot, packageJson, nestCLIConfiguration);
removeFile(repoRoot, 'nest-cli.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down
24 changes: 8 additions & 16 deletions packages/nx/src/command-line/init/implementation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ 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
continue;
}
nxJson.targetDefaults[scriptName] ??= {};
nxJson.targetDefaults[scriptName].outputs = [`{projectRoot}/${output}`];
}
for (const [scriptName, output] of Object.entries(scriptOutputs)) {
if (!output) {
// eslint-disable-next-line no-continue
continue;
}
nxJson.targetDefaults[scriptName] ??= {};
nxJson.targetDefaults[scriptName].outputs = [`{projectRoot}/${output}`];
}

for (const target of cacheableOperations) {
Expand Down Expand Up @@ -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) {
Expand Down