feat(core): move createPackageJson to nx (#13315)
This commit is contained in:
parent
1033b61686
commit
f0c18f5b7d
@ -1,6 +1,6 @@
|
|||||||
import type { ExecutorContext } from '@nrwl/devkit';
|
import type { ExecutorContext } from '@nrwl/devkit';
|
||||||
import { writeJsonFile } 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';
|
import type { NextBuildBuilderOptions } from '../../../utils/types';
|
||||||
|
|
||||||
export async function createPackageJson(
|
export async function createPackageJson(
|
||||||
@ -12,7 +12,6 @@ export async function createPackageJson(
|
|||||||
context.projectGraph,
|
context.projectGraph,
|
||||||
{
|
{
|
||||||
root: context.root,
|
root: context.root,
|
||||||
projectRoot: context.workspace.projects[context.projectName].sourceRoot,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { ProjectGraph } from '@nrwl/devkit';
|
import { readJsonFile } from './fileutils';
|
||||||
import { readJsonFile } from '@nrwl/devkit';
|
|
||||||
import { sortObjectByKeys } from 'nx/src/utils/object-sort';
|
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.
|
* Creates a package.json in the output directory for support to install dependencies within containers.
|
||||||
@ -11,7 +11,6 @@ export function createPackageJson(
|
|||||||
projectName: string,
|
projectName: string,
|
||||||
graph: ProjectGraph,
|
graph: ProjectGraph,
|
||||||
options: {
|
options: {
|
||||||
projectRoot?: string;
|
|
||||||
root?: string;
|
root?: string;
|
||||||
}
|
}
|
||||||
): any {
|
): any {
|
||||||
@ -24,7 +23,9 @@ export function createPackageJson(
|
|||||||
devDependencies: {},
|
devDependencies: {},
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
packageJson = readJsonFile(`${options.projectRoot}/package.json`);
|
packageJson = readJsonFile(
|
||||||
|
`${graph.nodes[projectName].data.root}/package.json`
|
||||||
|
);
|
||||||
if (!packageJson.dependencies) {
|
if (!packageJson.dependencies) {
|
||||||
packageJson.dependencies = {};
|
packageJson.dependencies = {};
|
||||||
}
|
}
|
||||||
@ -5,7 +5,7 @@ import {
|
|||||||
type ProjectGraph,
|
type ProjectGraph,
|
||||||
serializeJson,
|
serializeJson,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { createPackageJson } from '@nrwl/workspace/src/utilities/create-package-json';
|
import { createPackageJson } from 'nx/src/utils/create-package-json';
|
||||||
import {
|
import {
|
||||||
getHelperDependenciesFromProjectGraph,
|
getHelperDependenciesFromProjectGraph,
|
||||||
HelperDependency,
|
HelperDependency,
|
||||||
@ -15,14 +15,12 @@ import { readTsConfig } from '@nrwl/workspace/src/utilities/typescript';
|
|||||||
import { NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';
|
import { NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';
|
||||||
|
|
||||||
export class GeneratePackageJsonWebpackPlugin implements WebpackPluginInstance {
|
export class GeneratePackageJsonWebpackPlugin implements WebpackPluginInstance {
|
||||||
private readonly projectConfig: ProjectConfiguration;
|
|
||||||
private readonly projectGraph: ProjectGraph;
|
private readonly projectGraph: ProjectGraph;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly context: ExecutorContext,
|
private readonly context: ExecutorContext,
|
||||||
private readonly options: NormalizedWebpackExecutorOptions
|
private readonly options: NormalizedWebpackExecutorOptions
|
||||||
) {
|
) {
|
||||||
this.projectConfig = context.workspace.projects[context.projectName];
|
|
||||||
this.projectGraph = context.projectGraph;
|
this.projectGraph = context.projectGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +66,7 @@ export class GeneratePackageJsonWebpackPlugin implements WebpackPluginInstance {
|
|||||||
const packageJson = createPackageJson(
|
const packageJson = createPackageJson(
|
||||||
this.context.projectName,
|
this.context.projectName,
|
||||||
this.projectGraph,
|
this.projectGraph,
|
||||||
{ root: this.context.root, projectRoot: this.projectConfig.root }
|
{ root: this.context.root }
|
||||||
);
|
);
|
||||||
packageJson.main = packageJson.main ?? this.options.outputFileName;
|
packageJson.main = packageJson.main ?? this.options.outputFileName;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user