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" "description": "Create the Workspace Lint Rules Project"
} }
], ],
"properties": {}, "properties": {
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": [], "required": [],
"presets": [] "presets": []
}, },

View File

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

View File

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

View File

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

View File

@ -22,6 +22,12 @@
"description": "Relative path to the component file from the library root.", "description": "Relative path to the component file from the library root.",
"examples": ["lib/components"], "examples": ["lib/components"],
"x-prompt": "What's path of the component relative to the project's lib root?" "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"], "required": ["project", "componentPath"],

View File

@ -27,6 +27,12 @@
"**/**/src/**/*.other.*", "**/**/src/**/*.other.*",
"libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts" "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"], "required": ["project"],

View File

@ -32,6 +32,12 @@
"cypressProject": { "cypressProject": {
"type": "string", "type": "string",
"description": "The Cypress project to generate the stories under. By default, inferred from `project`." "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"], "required": ["project", "componentPath"],

View File

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

View File

@ -136,6 +136,12 @@
"type": "boolean", "type": "boolean",
"default": false, "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" "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"], "required": ["name", "project"],

View File

@ -43,6 +43,12 @@
"**/**/src/**/*.other.*", "**/**/src/**/*.other.*",
"libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts" "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"], "required": ["project"],

View File

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

View File

@ -43,6 +43,12 @@
"type": "string", "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", "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" "x-priority": "internal"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
} }
}, },
"required": ["name"], "required": ["name"],

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

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

View File

@ -18,6 +18,7 @@ export async function addJest(
skipSerializers: true, skipSerializers: true,
setupFile: 'none', setupFile: 'none',
babelJest: true, babelJest: true,
skipFormat: true,
}); });
// overwrite the jest.config.ts file because react native needs to have special transform property // 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) { 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); const installTask = updateDependencies(tree);
if (!schema.skipFormat) { if (!schema.skipFormat) {
await formatFiles(tree); await formatFiles(tree);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -56,14 +56,13 @@ describe('e2eProjectGenerator', () => {
describe('CLI tests', () => { describe('CLI tests', () => {
it('should print a message', () => { 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(); const output = execSync(\`node \${cliPath}\`).toString();
expect(output).toMatch(/Hello World/); 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); await formatFiles(host);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -174,7 +174,10 @@ export async function componentStoryGenerator(
schema: CreateComponentStoriesFileSchema schema: CreateComponentStoriesFileSchema
) { ) {
createComponentStoriesFile(host, schema); createComponentStoriesFile(host, schema);
await formatFiles(host);
if (!schema.skipFormat) {
await formatFiles(host);
}
} }
export default componentStoryGenerator; export default componentStoryGenerator;

View File

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

View File

@ -22,6 +22,12 @@
"description": "Relative path to the component file from the library root.", "description": "Relative path to the component file from the library root.",
"examples": ["lib/components"], "examples": ["lib/components"],
"x-prompt": "What's path of the component relative to the project's lib root?" "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"] "required": ["project", "componentPath"]

View File

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

View File

@ -30,6 +30,12 @@
"**/**/src/**/*.other.*", "**/**/src/**/*.other.*",
"libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts" "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"] "required": ["project"]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,6 +32,12 @@
"cypressProject": { "cypressProject": {
"type": "string", "type": "string",
"description": "The Cypress project to generate the stories under. By default, inferred from `project`." "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"] "required": ["project", "componentPath"]

View File

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

View File

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

View File

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

View File

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

View File

@ -141,6 +141,12 @@
"type": "boolean", "type": "boolean",
"default": false, "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" "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"] "required": ["name", "project"]

View File

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

View File

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

View File

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

View File

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

View File

@ -46,6 +46,12 @@
"**/**/src/**/*.other.*", "**/**/src/**/*.other.*",
"libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts" "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"], "required": ["project"],

View File

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

View File

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

View File

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

View File

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

View File

@ -15,4 +15,5 @@ export interface StorybookConfigureSchema {
configureStaticServe?: boolean; configureStaticServe?: boolean;
storybook7Configuration?: boolean; // TODO(katerina): Change when Storybook 7 storybook7Configuration?: boolean; // TODO(katerina): Change when Storybook 7
storybook7UiFramework?: UiFramework7; // 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" "@storybook/web-components-vite"
], ],
"hidden": true "hidden": true
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
} }
}, },
"required": ["name"], "required": ["name"],

View File

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

View File

@ -43,6 +43,12 @@
"type": "string", "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", "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" "x-priority": "internal"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
} }
}, },
"required": ["name"] "required": ["name"]

View File

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

View File

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

View File

@ -49,6 +49,12 @@
"testTarget": { "testTarget": {
"type": "string", "type": "string",
"description": "The test target of the project to be transformed to use the @nrwl/vite:test executor." "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" "examplesFile": "../../../docs/configuration-examples.md"

View File

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

View File

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

View File

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

View File

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

View File

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