<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> The `serve-static` target is being added in the `add-e2e` file, however, it has uses beyond e2e. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> The `serve-static` target should be added with more intention ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #27854
This commit is contained in:
parent
9c218e7606
commit
d7233268d8
@ -16,6 +16,7 @@ import {
|
|||||||
addE2e,
|
addE2e,
|
||||||
addLinting,
|
addLinting,
|
||||||
addProxyConfig,
|
addProxyConfig,
|
||||||
|
addServeStaticTarget,
|
||||||
addUnitTestRunner,
|
addUnitTestRunner,
|
||||||
createFiles,
|
createFiles,
|
||||||
createProject,
|
createProject,
|
||||||
@ -74,7 +75,12 @@ export async function applicationGeneratorInternal(
|
|||||||
|
|
||||||
await addLinting(tree, options);
|
await addLinting(tree, options);
|
||||||
await addUnitTestRunner(tree, options);
|
await addUnitTestRunner(tree, options);
|
||||||
await addE2e(tree, options);
|
const e2ePort = await addE2e(tree, options);
|
||||||
|
addServeStaticTarget(
|
||||||
|
tree,
|
||||||
|
options,
|
||||||
|
options.e2eTestRunner !== 'none' ? e2ePort : options.port
|
||||||
|
);
|
||||||
updateEditorTsConfig(tree, options);
|
updateEditorTsConfig(tree, options);
|
||||||
setGeneratorDefaults(tree, options);
|
setGeneratorDefaults(tree, options);
|
||||||
|
|
||||||
|
|||||||
@ -27,8 +27,6 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) {
|
|||||||
options.name,
|
options.name,
|
||||||
options.port
|
options.port
|
||||||
);
|
);
|
||||||
// TODO: This can call `@nx/web:static-config` generator when ready
|
|
||||||
addFileServerTarget(tree, options, 'serve-static', e2eWebServerInfo.e2ePort);
|
|
||||||
|
|
||||||
if (options.e2eTestRunner === 'cypress') {
|
if (options.e2eTestRunner === 'cypress') {
|
||||||
const { configurationGenerator } = ensurePackage<
|
const { configurationGenerator } = ensurePackage<
|
||||||
@ -101,35 +99,8 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function addFileServerTarget(
|
return e2eWebServerInfo.e2ePort;
|
||||||
tree: Tree,
|
|
||||||
options: NormalizedSchema,
|
|
||||||
targetName: string,
|
|
||||||
e2ePort: number
|
|
||||||
) {
|
|
||||||
if (!options.skipPackageJson) {
|
|
||||||
addDependenciesToPackageJson(tree, {}, { '@nx/web': nxVersion });
|
|
||||||
}
|
|
||||||
|
|
||||||
const { major: angularMajorVersion } = getInstalledAngularVersionInfo(tree);
|
|
||||||
const isUsingApplicationBuilder =
|
|
||||||
angularMajorVersion >= 17 && options.bundler === 'esbuild';
|
|
||||||
|
|
||||||
const projectConfig = readProjectConfiguration(tree, options.name);
|
|
||||||
projectConfig.targets[targetName] = {
|
|
||||||
executor: '@nx/web:file-server',
|
|
||||||
options: {
|
|
||||||
buildTarget: `${options.name}:build`,
|
|
||||||
port: e2ePort,
|
|
||||||
staticFilePath: isUsingApplicationBuilder
|
|
||||||
? joinPathFragments(options.outputPath, 'browser')
|
|
||||||
: undefined,
|
|
||||||
spa: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
updateProjectConfiguration(tree, options.name, projectConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAngularE2EWebServerInfo(
|
function getAngularE2EWebServerInfo(
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
import { Tree } from '@nx/devkit';
|
||||||
|
import type { NormalizedSchema } from './normalized-schema';
|
||||||
|
import {
|
||||||
|
addDependenciesToPackageJson,
|
||||||
|
joinPathFragments,
|
||||||
|
readProjectConfiguration,
|
||||||
|
updateProjectConfiguration,
|
||||||
|
} from '@nx/devkit';
|
||||||
|
import { nxVersion } from '../../../utils/versions';
|
||||||
|
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
|
||||||
|
|
||||||
|
export function addServeStaticTarget(
|
||||||
|
tree: Tree,
|
||||||
|
options: NormalizedSchema,
|
||||||
|
port: number
|
||||||
|
) {
|
||||||
|
addFileServerTarget(tree, options, 'serve-static', port);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addFileServerTarget(
|
||||||
|
tree: Tree,
|
||||||
|
options: NormalizedSchema,
|
||||||
|
targetName: string,
|
||||||
|
e2ePort: number
|
||||||
|
) {
|
||||||
|
if (!options.skipPackageJson) {
|
||||||
|
addDependenciesToPackageJson(tree, {}, { '@nx/web': nxVersion });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { major: angularMajorVersion } = getInstalledAngularVersionInfo(tree);
|
||||||
|
const isUsingApplicationBuilder =
|
||||||
|
angularMajorVersion >= 17 && options.bundler === 'esbuild';
|
||||||
|
|
||||||
|
const projectConfig = readProjectConfiguration(tree, options.name);
|
||||||
|
projectConfig.targets[targetName] = {
|
||||||
|
executor: '@nx/web:file-server',
|
||||||
|
options: {
|
||||||
|
buildTarget: `${options.name}:build`,
|
||||||
|
port: e2ePort,
|
||||||
|
staticFilePath: isUsingApplicationBuilder
|
||||||
|
? joinPathFragments(options.outputPath, 'browser')
|
||||||
|
: undefined,
|
||||||
|
spa: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
updateProjectConfiguration(tree, options.name, projectConfig);
|
||||||
|
}
|
||||||
@ -10,3 +10,4 @@ export * from './normalized-schema';
|
|||||||
export * from './set-app-strict-default';
|
export * from './set-app-strict-default';
|
||||||
export * from './set-generator-defaults';
|
export * from './set-generator-defaults';
|
||||||
export * from './update-editor-tsconfig';
|
export * from './update-editor-tsconfig';
|
||||||
|
export * from './add-serve-static-target';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user