Skip to content

Commit

Permalink
feat(core): move createPackageJson to nx (#13315)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Nov 22, 2022
1 parent 1033b61 commit f0c18f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
3 changes: 1 addition & 2 deletions packages/next/src/executors/build/lib/create-package-json.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ExecutorContext } from '@nrwl/devkit';
import { writeJsonFile } from '@nrwl/devkit';
import { createPackageJson as generatePackageJson } from '@nrwl/workspace/src/utilities/create-package-json';
import { createPackageJson as generatePackageJson } from 'nx/src/utils/create-package-json';
import type { NextBuildBuilderOptions } from '../../../utils/types';

export async function createPackageJson(
Expand All @@ -12,7 +12,6 @@ export async function createPackageJson(
context.projectGraph,
{
root: context.root,
projectRoot: context.workspace.projects[context.projectName].sourceRoot,
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ProjectGraph } from '@nrwl/devkit';
import { readJsonFile } from '@nrwl/devkit';
import { readJsonFile } from './fileutils';
import { sortObjectByKeys } from 'nx/src/utils/object-sort';
import { ProjectGraph } from '../config/project-graph';

/**
* Creates a package.json in the output directory for support to install dependencies within containers.
Expand All @@ -11,7 +11,6 @@ export function createPackageJson(
projectName: string,
graph: ProjectGraph,
options: {
projectRoot?: string;
root?: string;
}
): any {
Expand All @@ -24,7 +23,9 @@ export function createPackageJson(
devDependencies: {},
};
try {
packageJson = readJsonFile(`${options.projectRoot}/package.json`);
packageJson = readJsonFile(
`${graph.nodes[projectName].data.root}/package.json`
);
if (!packageJson.dependencies) {
packageJson.dependencies = {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type ProjectGraph,
serializeJson,
} from '@nrwl/devkit';
import { createPackageJson } from '@nrwl/workspace/src/utilities/create-package-json';
import { createPackageJson } from 'nx/src/utils/create-package-json';
import {
getHelperDependenciesFromProjectGraph,
HelperDependency,
Expand All @@ -15,14 +15,12 @@ import { readTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';

export class GeneratePackageJsonWebpackPlugin implements WebpackPluginInstance {
private readonly projectConfig: ProjectConfiguration;
private readonly projectGraph: ProjectGraph;

constructor(
private readonly context: ExecutorContext,
private readonly options: NormalizedWebpackExecutorOptions
) {
this.projectConfig = context.workspace.projects[context.projectName];
this.projectGraph = context.projectGraph;
}

Expand Down Expand Up @@ -68,7 +66,7 @@ export class GeneratePackageJsonWebpackPlugin implements WebpackPluginInstance {
const packageJson = createPackageJson(
this.context.projectName,
this.projectGraph,
{ root: this.context.root, projectRoot: this.projectConfig.root }
{ root: this.context.root }
);
packageJson.main = packageJson.main ?? this.options.outputFileName;

Expand Down

0 comments on commit f0c18f5

Please sign in to comment.