Skip to content

Commit

Permalink
fix(core): add outputs to nx.json for nx init in monorepo (#22061)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Mar 5, 2024
1 parent 587fe6a commit 22de9b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
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

0 comments on commit 22de9b5

Please sign in to comment.