fix(misc): skip formatting files in nested generator calls (#15961)

This commit is contained in:
Leosvel Pérez Espinosa 2023-03-31 16:22:18 +01:00 committed by GitHub
parent ba93808a2e
commit 4eb7cc7bf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
80 changed files with 393 additions and 73 deletions

View File

@ -14,7 +14,14 @@
"description": "Create the Workspace Lint Rules Project"
}
],
"properties": {},
"properties": {
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": [],
"presets": []
},

View File

@ -101,6 +101,12 @@
"description": "Use pascal case directory name (e.g. `App/App.tsx`).",
"alias": "R",
"default": false
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name", "project"],

View File

@ -89,6 +89,12 @@
"type": "boolean",
"description": "Create component at the source root rather than its own directory.",
"default": false
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name", "project"],

View File

@ -45,6 +45,12 @@
"type": "boolean",
"description": "Generate the e2e project with a minimal setup. This would involve not generating tests for a default executor and generator.",
"default": false
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["pluginName", "npmPackageName"],

View File

@ -22,6 +22,12 @@
"description": "Relative path to the component file from the library root.",
"examples": ["lib/components"],
"x-prompt": "What's path of the component relative to the project's lib root?"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project", "componentPath"],

View File

@ -27,6 +27,12 @@
"**/**/src/**/*.other.*",
"libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts"
]
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project"],

View File

@ -32,6 +32,12 @@
"cypressProject": {
"type": "string",
"description": "The Cypress project to generate the stories under. By default, inferred from `project`."
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project", "componentPath"],

View File

@ -24,6 +24,12 @@
"examples": ["lib/components"],
"x-prompt": "What's path of the component relative to the project's lib root?",
"x-priority": "important"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project", "componentPath"],

View File

@ -136,6 +136,12 @@
"type": "boolean",
"default": false,
"description": "When using Vitest, separate spec files will not be generated and instead will be included within the source files. Read more on the Vitest docs site: https://vitest.dev/guide/in-source.html"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name", "project"],

View File

@ -43,6 +43,12 @@
"**/**/src/**/*.other.*",
"libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts"
]
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project"],

View File

@ -111,6 +111,12 @@
"@storybook/web-components-vite"
],
"hidden": true
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name"],

View File

@ -43,6 +43,12 @@
"type": "string",
"description": "The name of the devServerTarget to use for the Cypress CI configuration. Used to control if using <storybook-project>:static-storybook:ci or <storybook-project>:storybook:ci",
"x-priority": "internal"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name"],

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,12 @@
"type": "string",
"description": "The test target of the project to be transformed to use the @nrwl/vite:test executor.",
"hidden": true
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project"],

View File

@ -18,7 +18,10 @@ export async function esbuildProjectGenerator(
tree: Tree,
options: EsBuildProjectSchema
) {
const task = await esbuildInitGenerator(tree, options);
const task = await esbuildInitGenerator(tree, {
...options,
skipFormat: true,
});
checkForTargetConflicts(tree, options);
addBuildTarget(tree, options);
await formatFiles(tree);

View File

@ -18,5 +18,6 @@ export async function addDetox(host: Tree, options: NormalizedSchema) {
appName: options.name,
framework: 'expo',
setParserOptionsProject: options.setParserOptionsProject,
skipFormat: true,
});
}

View File

@ -18,6 +18,7 @@ export async function addJest(
skipSerializers: true,
setupFile: 'none',
babelJest: true,
skipFormat: true,
});
// overwrite the jest.config.ts file because react native needs to have special transform property

View File

@ -31,7 +31,10 @@ function updateDependencies(tree: Tree) {
}
export async function initGenerator(tree: Tree, schema: Schema) {
const initTask = await nodeInitGenerator(tree, schema);
const initTask = await nodeInitGenerator(tree, {
...schema,
skipFormat: true,
});
const installTask = updateDependencies(tree);
if (!schema.skipFormat) {
await formatFiles(tree);

View File

@ -80,6 +80,7 @@ export async function projectGenerator(
uiFramework: 'none',
includeVitest: options.unitTestRunner === 'vitest',
includeLib: true,
skipFormat: true,
});
tasks.push(viteTask);
}
@ -107,6 +108,7 @@ export async function projectGenerator(
project: options.name,
uiFramework: 'none',
coverageProvider: 'c8',
skipFormat: true,
});
tasks.push(vitestTask);
}

View File

@ -25,7 +25,8 @@ export async function lintWorkspaceRuleGenerator(
) {
// Ensure that the workspace rules project has been created
const projectGeneratorCallback = await lintWorkspaceRulesProjectGenerator(
tree
tree,
{ skipFormat: true }
);
const ruleDir = joinPathFragments(

View File

@ -11,6 +11,13 @@
"description": "Create the Workspace Lint Rules Project"
}
],
"properties": {},
"properties": {
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": []
}

View File

@ -23,7 +23,14 @@ export const WORKSPACE_RULES_PROJECT_NAME = 'eslint-rules';
export const WORKSPACE_PLUGIN_DIR = 'tools/eslint-rules';
export async function lintWorkspaceRulesProjectGenerator(tree: Tree) {
export interface LintWorkspaceRulesProjectGeneratorOptions {
skipFormat?: boolean;
}
export async function lintWorkspaceRulesProjectGenerator(
tree: Tree,
options: LintWorkspaceRulesProjectGeneratorOptions = {}
) {
const { addPropertyToJestConfig, jestProjectGenerator } = ensurePackage(
'@nrwl/jest',
nxVersion
@ -114,7 +121,9 @@ export async function lintWorkspaceRulesProjectGenerator(tree: Tree) {
}
);
if (!options.skipFormat) {
await formatFiles(tree);
}
return installTask;
}

View File

@ -68,7 +68,7 @@ export async function conversionGenerator(
projectDirectory: '',
fileName: '',
parsedTags: [],
skipFormat: options.skipFormat,
skipFormat: true,
} as AddLintForLibrarySchema);
}
},

View File

@ -16,7 +16,10 @@ export async function initGenerator(
const options = normalizeOptions(rawOptions);
const tasks: GeneratorCallback[] = [];
const nodeInitTask = await nodeInitGenerator(tree, options);
const nodeInitTask = await nodeInitGenerator(tree, {
...options,
skipFormat: true,
});
tasks.push(nodeInitTask);
if (!options.skipPackageJson) {

View File

@ -18,5 +18,6 @@ export async function addCypress(host: Tree, options: NormalizedSchema) {
name: `${options.name}-e2e`,
directory: options.directory,
project: options.projectName,
skipFormat: true,
});
}

View File

@ -1,5 +1,6 @@
import {
convertNxGenerator,
formatFiles,
getProjects,
runTasksInSerial,
Tree,
@ -17,6 +18,7 @@ interface Schema {
flat?: boolean;
pascalCaseFiles?: boolean;
pascalCaseDirectory?: boolean;
skipFormat?: boolean;
}
function getDirectory(host: Tree, options: Schema) {
@ -40,10 +42,15 @@ export async function componentGenerator(host: Tree, options: Schema) {
directory: getDirectory(host, options),
classComponent: false,
routing: false,
skipFormat: true,
});
const styledInstall = addStyleDependencies(host, options.style);
if (!options.skipFormat) {
await formatFiles(host);
}
return runTasksInSerial(styledInstall, componentInstall);
}

View File

@ -106,6 +106,12 @@
"description": "Use pascal case directory name (e.g. `App/App.tsx`).",
"alias": "R",
"default": false
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name", "project"],

View File

@ -62,7 +62,10 @@ export async function nextInitGenerator(host: Tree, schema: InitSchema) {
tasks.push(cypressTask);
}
const reactTask = await reactInitGenerator(host, schema);
const reactTask = await reactInitGenerator(host, {
...schema,
skipFormat: true,
});
tasks.push(reactTask);
if (!schema.skipPackageJson) {

View File

@ -1,5 +1,6 @@
import {
convertNxGenerator,
formatFiles,
GeneratorCallback,
getWorkspaceLayout,
joinPathFragments,
@ -31,6 +32,7 @@ export async function libraryGenerator(host: Tree, options: Schema) {
const libTask = await reactLibraryGenerator(host, {
...options,
compiler: 'swc',
skipFormat: true,
});
tasks.push(libTask);
@ -87,6 +89,10 @@ export async function libraryGenerator(host: Tree, options: Schema) {
}
);
if (!options.skipFormat) {
await formatFiles(host);
}
return runTasksInSerial(...tasks);
}

View File

@ -1,5 +1,10 @@
import { componentGenerator as reactComponentGenerator } from '@nrwl/react';
import { convertNxGenerator, runTasksInSerial, Tree } from '@nrwl/devkit';
import {
convertNxGenerator,
formatFiles,
runTasksInSerial,
Tree,
} from '@nrwl/devkit';
import { addStyleDependencies } from '../../utils/styles';
import { Schema } from './schema';
@ -21,10 +26,15 @@ export async function pageGenerator(host: Tree, options: Schema) {
skipTests: !options.withTests,
flat: !!options.flat,
fileName: !options.flat ? 'index' : undefined,
skipFormat: true,
});
const styledTask = addStyleDependencies(host, options.style);
if (!options.skipFormat) {
await formatFiles(host);
}
return runTasksInSerial(componentTask, styledTask);
}

View File

@ -9,4 +9,5 @@ export interface Schema {
withTests?: boolean;
js?: boolean;
flat?: boolean;
skipFormat?: boolean;
}

View File

@ -94,6 +94,12 @@
"type": "boolean",
"description": "Create component at the source root rather than its own directory.",
"default": false
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name", "project"],

View File

@ -371,7 +371,7 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
if (options.framework === 'nest') {
const { applicationGenerator } = ensurePackage('@nrwl/nest', nxVersion);
return await applicationGenerator(tree, options);
return await applicationGenerator(tree, { ...options, skipFormat: true });
}
const initTask = await initGenerator(tree, {
@ -419,6 +419,7 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
project: options.name,
port: options.port,
isNest: options.isNest,
skipFormat: true,
});
tasks.push(e2eTask);
}
@ -435,6 +436,7 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
const dockerTask = await setupDockerGenerator(tree, {
...options,
project: options.name,
skipFormat: true,
});
tasks.push(dockerTask);

View File

@ -56,14 +56,13 @@ describe('e2eProjectGenerator', () => {
describe('CLI tests', () => {
it('should print a message', () => {
const cliPath = join(process.cwd(), \\"dist/api\\");
const cliPath = join(process.cwd(), 'dist/api');
const output = execSync(\`node \${cliPath}\`).toString();
expect(output).toMatch(/Hello World/);
});
});
"
`);
});

View File

@ -139,7 +139,7 @@ export async function e2eProjectGenerator(host: Tree, _options: Schema) {
});
}
if (options.formatFile) {
if (!options.skipFormat) {
await formatFiles(host);
}

View File

@ -5,7 +5,7 @@ export interface Schema {
name?: string;
port?: number;
linter?: 'eslint' | 'none';
formatFile?: boolean;
rootProject?: boolean;
isNest?: boolean;
skipFormat?: boolean;
}

View File

@ -53,10 +53,10 @@
"hidden": true,
"x-priority": "internal"
},
"formatFiles": {
"description": "Format generated files.",
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": true,
"default": false,
"hidden": true,
"x-priority": "internal"
}

View File

@ -90,6 +90,7 @@ async function addJest(host: Tree, options: NormalizedSchema) {
setupFile: 'none',
supportTsx: false,
skipSerializers: true,
skipFormat: true,
});
const project = readProjectConfiguration(host, options.projectName);
@ -141,7 +142,9 @@ export async function e2eProjectGenerator(host: Tree, schema: Schema) {
tasks.push(lintTask);
}
if (!options.skipFormat) {
await formatFiles(host);
}
return runTasksInSerial(...tasks);
}

View File

@ -8,4 +8,5 @@ export interface Schema {
jestConfig?: string;
minimal?: boolean;
linter?: Linter;
skipFormat?: boolean;
}

View File

@ -45,6 +45,12 @@
"type": "boolean",
"description": "Generate the e2e project with a minimal setup. This would involve not generating tests for a default executor and generator.",
"default": false
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["pluginName", "npmPackageName"]

View File

@ -95,6 +95,7 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
config: 'project',
bundler: options.bundler,
importPath: options.npmPackageName,
skipFormat: true,
});
addDependenciesToPackageJson(
@ -123,6 +124,7 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`,
npmPackageName: options.npmPackageName,
minimal: options.minimal ?? false,
skipFormat: true,
});
}

View File

@ -174,8 +174,11 @@ export async function componentStoryGenerator(
schema: CreateComponentStoriesFileSchema
) {
createComponentStoriesFile(host, schema);
if (!schema.skipFormat) {
await formatFiles(host);
}
}
export default componentStoryGenerator;
export const componentStorySchematic = convertNxGenerator(

View File

@ -1,4 +1,5 @@
export interface CreateComponentStoriesFileSchema {
project: string;
componentPath: string;
skipFormat?: boolean;
}

View File

@ -22,6 +22,12 @@
"description": "Relative path to the component file from the library root.",
"examples": ["lib/components"],
"x-prompt": "What's path of the component relative to the project's lib root?"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project", "componentPath"]

View File

@ -1,4 +1,5 @@
export interface StorybookStoriesSchema {
project: string;
ignorePaths?: string[];
skipFormat?: boolean;
}

View File

@ -30,6 +30,12 @@
"**/**/src/**/*.other.*",
"libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts"
]
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project"]

View File

@ -1,6 +1,7 @@
import {
convertNxGenerator,
ensurePackage,
formatFiles,
getProjects,
Tree,
visitNotIgnoredFiles,
@ -65,6 +66,7 @@ export async function createAllStories(
await componentStoryGenerator(tree, {
componentPath: relativeCmpDir,
project: projectName,
skipFormat: true,
});
})
);
@ -75,6 +77,10 @@ export async function storiesGenerator(
schema: StorybookStoriesSchema
) {
await createAllStories(host, schema.project, schema.ignorePaths);
if (!schema.skipFormat) {
await formatFiles(host);
}
}
export default storiesGenerator;

View File

@ -20,6 +20,7 @@ async function generateStories(host: Tree, schema: StorybookConfigureSchema) {
await storiesGenerator(host, {
project: schema.name,
ignorePaths: schema.ignorePaths,
skipFormat: true,
});
}
@ -27,10 +28,9 @@ export async function storybookConfigurationGenerator(
host: Tree,
schema: StorybookConfigureSchema
): Promise<GeneratorCallback> {
const { configurationGenerator } = ensurePackage(
'@nrwl/storybook',
nxVersion
);
const { configurationGenerator } = ensurePackage<
typeof import('@nrwl/storybook')
>('@nrwl/storybook', nxVersion);
const installTask = await configurationGenerator(host, {
name: schema.name,
@ -40,6 +40,7 @@ export async function storybookConfigurationGenerator(
linter: schema.linter,
standaloneConfig: schema.standaloneConfig,
tsConfiguration: schema.tsConfiguration,
skipFormat: true,
});
addStorybookTask(host, schema.name);

View File

@ -106,10 +106,9 @@ export async function applicationGenerator(
addProject(host, options);
if (options.bundler === 'vite') {
const { viteConfigurationGenerator } = ensurePackage(
'@nrwl/vite',
nxVersion
);
const { viteConfigurationGenerator } = ensurePackage<
typeof import('@nrwl/vite')
>('@nrwl/vite', nxVersion);
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
// See: https://vitejs.dev/guide/env-and-mode.html
if (
@ -126,24 +125,32 @@ export async function applicationGenerator(
newProject: true,
includeVitest: options.unitTestRunner === 'vitest',
inSourceTests: options.inSourceTests,
skipFormat: true,
});
tasks.push(viteTask);
} else if (options.bundler === 'webpack') {
const { webpackInitGenerator } = ensurePackage('@nrwl/webpack', nxVersion);
const { webpackInitGenerator } = ensurePackage<
typeof import('@nrwl/webpack')
>('@nrwl/webpack', nxVersion);
const webpackInitTask = await webpackInitGenerator(host, {
uiFramework: 'react',
skipFormat: true,
});
tasks.push(webpackInitTask);
}
if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
const { vitestGenerator } = ensurePackage('@nrwl/vite', nxVersion);
const { vitestGenerator } = ensurePackage<typeof import('@nrwl/vite')>(
'@nrwl/vite',
nxVersion
);
const vitestTask = await vitestGenerator(host, {
uiFramework: 'react',
coverageProvider: 'c8',
project: options.projectName,
inSourceTests: options.inSourceTests,
skipFormat: true,
});
tasks.push(vitestTask);
}

View File

@ -13,14 +13,16 @@ export async function addCypress(host: Tree, options: NormalizedSchema) {
targetName: 'serve-static',
});
const { cypressProjectGenerator } = ensurePackage('@nrwl/cypress', nxVersion);
const { cypressProjectGenerator } = ensurePackage<
typeof import('@nrwl/cypress')
>('@nrwl/cypress', nxVersion);
return await cypressProjectGenerator(host, {
...options,
name: options.e2eProjectName,
directory: options.directory,
project: options.projectName,
rootProject: options.rootProject,
bundler: options.bundler,
skipFormat: true,
});
}

View File

@ -6,7 +6,10 @@ export async function addJest(
host: Tree,
options: NormalizedSchema
): Promise<GeneratorCallback> {
const { jestProjectGenerator } = ensurePackage('@nrwl/jest', nxVersion);
const { jestProjectGenerator } = ensurePackage<typeof import('@nrwl/jest')>(
'@nrwl/jest',
nxVersion
);
if (options.unitTestRunner !== 'jest') {
return () => {};
@ -19,6 +22,6 @@ export async function addJest(
skipSerializers: true,
setupFile: 'none',
compiler: options.compiler,
rootProject: options.rootProject,
skipFormat: true,
});
}

View File

@ -1,5 +1,6 @@
import {
convertNxGenerator,
formatFiles,
generateFiles,
getProjects,
joinPathFragments,
@ -21,13 +22,18 @@ export interface CreateComponentSpecFileSchema {
componentPath: string;
js?: boolean;
cypressProject?: string;
skipFormat?: boolean;
}
export function componentCypressGenerator(
export async function componentCypressGenerator(
host: Tree,
schema: CreateComponentSpecFileSchema
) {
createComponentSpecFile(host, schema);
if (!schema.skipFormat) {
await formatFiles(host);
}
}
// TODO: candidate to refactor with the angular component story

View File

@ -32,6 +32,12 @@
"cypressProject": {
"type": "string",
"description": "The Cypress project to generate the stories under. By default, inferred from `project`."
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project", "componentPath"]

View File

@ -20,6 +20,7 @@ let tsModule: typeof import('typescript');
export interface CreateComponentStoriesFileSchema {
project: string;
componentPath: string;
skipFormat?: boolean;
}
export function createComponentStoriesFile(
@ -142,8 +143,11 @@ export async function componentStoryGenerator(
schema: CreateComponentStoriesFileSchema
) {
createComponentStoriesFile(host, schema);
if (!schema.skipFormat) {
await formatFiles(host);
}
}
export default componentStoryGenerator;
export const componentStorySchematic = convertNxGenerator(

View File

@ -24,6 +24,12 @@
"examples": ["lib/components"],
"x-prompt": "What's path of the component relative to the project's lib root?",
"x-priority": "important"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project", "componentPath"]

View File

@ -47,7 +47,9 @@ export async function componentGenerator(host: Tree, schema: Schema) {
tasks.push(routingTask);
}
if (!options.skipFormat) {
await formatFiles(host);
}
return runTasksInSerial(...tasks);
}

View File

@ -16,4 +16,5 @@ export interface Schema {
globalCss?: boolean;
fileName?: string;
inSourceTests?: boolean;
skipFormat?: boolean;
}

View File

@ -141,6 +141,12 @@
"type": "boolean",
"default": false,
"description": "When using Vitest, separate spec files will not be generated and instead will be included within the source files. Read more on the Vitest docs site: https://vitest.dev/guide/in-source.html"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name", "project"]

View File

@ -30,6 +30,7 @@ export async function hostGenerator(host: Tree, schema: Schema) {
routing: true,
// Only webpack works with module federation for now.
bundler: 'webpack',
skipFormat: true,
});
tasks.push(initTask);
@ -43,12 +44,12 @@ export async function hostGenerator(host: Tree, schema: Schema) {
name: remote,
directory: options.directory,
style: options.style,
skipFormat: options.skipFormat,
unitTestRunner: options.unitTestRunner,
e2eTestRunner: options.e2eTestRunner,
linter: options.linter,
devServerPort: remotePort,
ssr: options.ssr,
skipFormat: true,
});
remotePort++;
}
@ -62,6 +63,7 @@ export async function hostGenerator(host: Tree, schema: Schema) {
const setupSsrTask = await setupSsrGenerator(host, {
project: options.projectName,
serverPort: options.devServerPort,
skipFormat: true,
});
tasks.push(setupSsrTask);

View File

@ -20,7 +20,10 @@ export async function addRollupBuildTarget(
host: Tree,
options: NormalizedSchema
) {
const { rollupInitGenerator } = ensurePackage('@nrwl/rollup', nxVersion);
const { rollupInitGenerator } = ensurePackage<typeof import('@nrwl/rollup')>(
'@nrwl/rollup',
nxVersion
);
// These are used in `@nrwl/react/plugins/bundle-rollup`
addDependenciesToPackageJson(
@ -75,5 +78,5 @@ export async function addRollupBuildTarget(
targets,
});
return rollupInitGenerator(host, options);
return rollupInitGenerator(host, { ...options, skipFormat: true });
}

View File

@ -63,10 +63,9 @@ export async function libraryGenerator(host: Tree, schema: Schema) {
// Set up build target
if (options.buildable && options.bundler === 'vite') {
const { viteConfigurationGenerator } = ensurePackage(
'@nrwl/vite',
nxVersion
);
const { viteConfigurationGenerator } = ensurePackage<
typeof import('@nrwl/vite')
>('@nrwl/vite', nxVersion);
const viteTask = await viteConfigurationGenerator(host, {
uiFramework: 'react',
project: options.name,
@ -74,6 +73,7 @@ export async function libraryGenerator(host: Tree, schema: Schema) {
includeLib: true,
inSourceTests: options.inSourceTests,
includeVitest: options.unitTestRunner === 'vitest',
skipFormat: true,
});
tasks.push(viteTask);
} else if (options.buildable && options.bundler === 'rollup') {
@ -83,7 +83,10 @@ export async function libraryGenerator(host: Tree, schema: Schema) {
// Set up test target
if (options.unitTestRunner === 'jest') {
const { jestProjectGenerator } = ensurePackage('@nrwl/jest', nxVersion);
const { jestProjectGenerator } = ensurePackage<typeof import('@nrwl/jest')>(
'@nrwl/jest',
nxVersion
);
const jestTask = await jestProjectGenerator(host, {
...options,
@ -92,6 +95,7 @@ export async function libraryGenerator(host: Tree, schema: Schema) {
supportTsx: true,
skipSerializers: true,
compiler: options.compiler,
skipFormat: true,
});
tasks.push(jestTask);
const jestConfigPath = joinPathFragments(
@ -108,12 +112,16 @@ export async function libraryGenerator(host: Tree, schema: Schema) {
options.unitTestRunner === 'vitest' &&
options.bundler !== 'vite' // tests are already configured if bundler is vite
) {
const { vitestGenerator } = ensurePackage('@nrwl/vite', nxVersion);
const { vitestGenerator } = ensurePackage<typeof import('@nrwl/vite')>(
'@nrwl/vite',
nxVersion
);
const vitestTask = await vitestGenerator(host, {
uiFramework: 'react',
project: options.name,
coverageProvider: 'c8',
inSourceTests: options.inSourceTests,
skipFormat: true,
});
tasks.push(vitestTask);
}
@ -132,6 +140,7 @@ export async function libraryGenerator(host: Tree, schema: Schema) {
js: options.js,
pascalCaseFiles: options.pascalCaseFiles,
inSourceTests: options.inSourceTests,
skipFormat: true,
});
tasks.push(componentTask);
}

View File

@ -45,6 +45,7 @@ export async function remoteGenerator(host: Tree, schema: Schema) {
...options,
// Only webpack works with module federation for now.
bundler: 'webpack',
skipFormat: true,
});
tasks.push(initAppTask);
@ -67,6 +68,7 @@ export async function remoteGenerator(host: Tree, schema: Schema) {
const setupSsrTask = await setupSsrGenerator(host, {
project: options.projectName,
serverPort: options.devServerPort,
skipFormat: true,
});
tasks.push(setupSsrTask);

View File

@ -53,7 +53,7 @@ interface AppComponentInfo {
}
export async function setupSsrGenerator(tree: Tree, options: Schema) {
await initGenerator(tree, {});
await initGenerator(tree, { skipFormat: true });
const projectConfig = readProjectConfiguration(tree, options.project);
const projectRoot = projectConfig.root;
const appImportCandidates: AppComponentInfo[] = [

View File

@ -46,6 +46,12 @@
"**/**/src/**/*.other.*",
"libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts"
]
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project"],

View File

@ -6,6 +6,7 @@ import {
} from '../../utils/ast-utils';
import {
convertNxGenerator,
formatFiles,
getProjects,
joinPathFragments,
logger,
@ -25,6 +26,7 @@ export interface StorybookStoriesSchema {
js?: boolean;
cypressProject?: string;
ignorePaths?: string[];
skipFormat?: boolean;
}
export async function projectRootPath(
@ -141,6 +143,7 @@ export async function createAllStories(
await componentStoryGenerator(tree, {
componentPath: relativeCmpDir,
project: projectName,
skipFormat: true,
});
if (generateCypressSpecs && e2eProject) {
@ -149,6 +152,7 @@ export async function createAllStories(
componentPath: relativeCmpDir,
js,
cypressProject,
skipFormat: true,
});
}
})
@ -167,6 +171,10 @@ export async function storiesGenerator(
schema.cypressProject,
schema.ignorePaths
);
if (!schema.skipFormat) {
await formatFiles(host);
}
}
export default storiesGenerator;

View File

@ -27,6 +27,7 @@ async function generateStories(host: Tree, schema: StorybookConfigureSchema) {
js: schema.js,
cypressProject,
ignorePaths: schema.ignorePaths,
skipFormat: true,
});
}
@ -34,10 +35,9 @@ export async function storybookConfigurationGenerator(
host: Tree,
schema: StorybookConfigureSchema
) {
const { configurationGenerator } = ensurePackage(
'@nrwl/storybook',
nxVersion
);
const { configurationGenerator } = ensurePackage<
typeof import('@nrwl/storybook')
>('@nrwl/storybook', nxVersion);
let bundler = schema.bundler ?? 'webpack';
const projectConfig = readProjectConfiguration(host, schema.name);
@ -72,6 +72,7 @@ export async function storybookConfigurationGenerator(
bundler === 'vite'
? '@storybook/react-vite'
: '@storybook/react-webpack5',
skipFormat: true,
});
if (schema.generateStories) {

View File

@ -18,7 +18,10 @@ export async function rollupProjectGenerator(
tree: Tree,
options: RollupProjectSchema
) {
const task = await rollupInitGenerator(tree, options);
const task = await rollupInitGenerator(tree, {
...options,
skipFormat: true,
});
checkForTargetConflicts(tree, options);
addBuildTarget(tree, options);
await formatFiles(tree);

View File

@ -208,6 +208,7 @@ export async function configurationGenerator(
ciTargetName: schema.configureStaticServe
? 'static-storybook'
: undefined,
skipFormat: true,
});
tasks.push(cypressTask);
} else {
@ -243,7 +244,9 @@ export async function configurationGenerator(
tasks.push(addDependenciesToPackageJson(tree, {}, devDeps));
if (!schema.skipFormat) {
await formatFiles(tree);
}
return runTasksInSerial(...tasks);
}

View File

@ -15,4 +15,5 @@ export interface StorybookConfigureSchema {
configureStaticServe?: boolean;
storybook7Configuration?: boolean; // TODO(katerina): Change when Storybook 7
storybook7UiFramework?: UiFramework7; // TODO(katerina): Change when Storybook 7
skipFormat?: boolean;
}

View File

@ -111,6 +111,12 @@
"@storybook/web-components-vite"
],
"hidden": true
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name"],

View File

@ -31,6 +31,7 @@ export interface CypressConfigureSchema {
linter: Linter;
standaloneConfig?: boolean;
ciTargetName?: string;
skipFormat?: boolean;
}
export async function cypressProjectGenerator(
@ -56,6 +57,7 @@ export async function cypressProjectGenerator(
linter: schema.linter,
directory: schema.directory,
standaloneConfig: schema.standaloneConfig,
skipFormat: true,
});
tasks.push(installTask);
@ -72,7 +74,9 @@ export async function cypressProjectGenerator(
ciTargetName: schema.ciTargetName,
});
if (!schema.skipFormat) {
await formatFiles(tree);
}
return runTasksInSerial(...tasks);
}

View File

@ -43,6 +43,12 @@
"type": "string",
"description": "The name of the devServerTarget to use for the Cypress CI configuration. Used to control if using <storybook-project>:static-storybook:ci or <storybook-project>:storybook:ci",
"x-priority": "internal"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name"]

View File

@ -178,11 +178,14 @@ export async function viteConfigurationGenerator(
coverageProvider: 'c8',
skipViteConfig: true,
testTarget: testTargetName,
skipFormat: true,
});
tasks.push(vitestTask);
}
if (!schema.skipFormat) {
await formatFiles(tree);
}
return runTasksInSerial(...tasks);
}

View File

@ -8,4 +8,5 @@ export interface ViteConfigurationGeneratorSchema {
buildTarget?: string;
serveTarget?: string;
testTarget?: string;
skipFormat?: boolean;
}

View File

@ -49,6 +49,12 @@
"testTarget": {
"type": "string",
"description": "The test target of the project to be transformed to use the @nrwl/vite:test executor."
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"examplesFile": "../../../docs/configuration-examples.md"

View File

@ -5,4 +5,5 @@ export interface VitestGeneratorSchema {
inSourceTests?: boolean;
skipViteConfig?: boolean;
testTarget?: string;
skipFormat?: boolean;
}

View File

@ -37,6 +37,12 @@
"type": "string",
"description": "The test target of the project to be transformed to use the @nrwl/vite:test executor.",
"hidden": true
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["project"]

View File

@ -74,7 +74,9 @@ export async function vitestGenerator(
);
tasks.push(installCoverageProviderTask);
if (!schema.skipFormat) {
await formatFiles(tree);
}
return runTasksInSerial(...tasks);
}

View File

@ -88,6 +88,7 @@ async function setupBundler(tree: Tree, options: NormalizedSchema) {
options.appProjectRoot,
'webpack.config.js'
),
skipFormat: true,
});
const project = readProjectConfiguration(tree, options.projectName);
const prodConfig = project.targets.build.configurations.production;
@ -201,10 +202,9 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
await addProject(host, options);
if (options.bundler === 'vite') {
const { viteConfigurationGenerator } = ensurePackage(
'@nrwl/vite',
nxVersion
);
const { viteConfigurationGenerator } = ensurePackage<
typeof import('@nrwl/vite')
>('@nrwl/vite', nxVersion);
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
// See: https://vitejs.dev/guide/env-and-mode.html
if (
@ -221,17 +221,22 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
newProject: true,
includeVitest: options.unitTestRunner === 'vitest',
inSourceTests: options.inSourceTests,
skipFormat: true,
});
tasks.push(viteTask);
}
if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
const { vitestGenerator } = ensurePackage('@nrwl/vite', nxVersion);
const { vitestGenerator } = ensurePackage<typeof import('@nrwl/vite')>(
'@nrwl/vite',
nxVersion
);
const vitestTask = await vitestGenerator(host, {
uiFramework: 'none',
project: options.projectName,
coverageProvider: 'c8',
inSourceTests: options.inSourceTests,
skipFormat: true,
});
tasks.push(vitestTask);
}
@ -265,34 +270,34 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
}
if (options.e2eTestRunner === 'cypress') {
const { cypressProjectGenerator } = await ensurePackage(
'@nrwl/cypress',
nxVersion
);
const { cypressProjectGenerator } = await ensurePackage<
typeof import('@nrwl/cypress')
>('@nrwl/cypress', nxVersion);
const cypressTask = await cypressProjectGenerator(host, {
...options,
name: `${options.name}-e2e`,
directory: options.directory,
project: options.projectName,
skipFormat: true,
});
tasks.push(cypressTask);
}
if (options.unitTestRunner === 'jest') {
const { jestProjectGenerator } = await ensurePackage(
'@nrwl/jest',
nxVersion
);
const { jestProjectGenerator } = await ensurePackage<
typeof import('@nrwl/jest')
>('@nrwl/jest', nxVersion);
const jestTask = await jestProjectGenerator(host, {
project: options.projectName,
skipSerializers: true,
setupFile: 'web-components',
compiler: options.compiler,
skipFormat: true,
});
tasks.push(jestTask);
}
if (options.compiler === 'swc') {
const installTask = await addDependenciesToPackageJson(
const installTask = addDependenciesToPackageJson(
host,
{},
{ '@swc/core': swcCoreVersion, 'swc-loader': swcLoaderVersion }

View File

@ -15,13 +15,20 @@ export async function webpackProjectGenerator(
tree: Tree,
options: WebpackProjectGeneratorSchema
) {
const task = await webpackInitGenerator(tree, options);
const task = await webpackInitGenerator(tree, {
...options,
skipFormat: true,
});
checkForTargetConflicts(tree, options);
addBuildTarget(tree, options);
if (options.devServer) {
addServeTarget(tree, options);
}
if (!options.skipFormat) {
await formatFiles(tree);
}
return task;
}