Skip to content

Commit

Permalink
fix(misc): skip formatting files in nested generator calls (#15961)
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Mar 31, 2023
1 parent ba93808 commit 4eb7cc7
Show file tree
Hide file tree
Showing 80 changed files with 393 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
},
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/next/generators/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/next/generators/page.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/nx-plugin/generators/e2e-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/react-native/generators/stories.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/react/generators/component-story.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/react/generators/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/react/generators/stories.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
"@storybook/web-components-vite"
],
"hidden": true
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"required": ["name"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/vite/generators/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "---\ntitle: Examples for the Vite configuration generator\ndescription: This page contains examples for the Vite @nrwl/vite:configuration generator, which helps you set up Vite on your Nx workspace, or convert an existing project to use Vite.\n---\n\nThis generator is used for converting an existing React or Web project to use [Vite.js](https://vitejs.dev/) and the [@nrwl/vite executors](/packages/vite#executors).\n\nIt will change the `build` and `serve` targets to use the `@nrwl/vite` executors for serving and building the application. If you choose so, it will also change your `test` target to use the `@nrwl/vite:test` executor. It will create a `vite.config.ts` file at the root of your project with the correct settings, or if there's already a `vite.config.ts` file, it will modify it to include the correct settings.\n\n{% callout type=\"caution\" title=\"Your code will be modified!\" %}\nThis generator will modify your code, so make sure to commit your changes before running it.\n{% /callout %}\n\n```bash\nnx g @nrwl/vite:configuration\n```\n\nWhen running this generator, you will be prompted to provide the following:\n\n- The `project`, as the name of the project you want to generate the configuration for.\n- The `uiFramework` you want to use. Supported values are: `react` and `none`.\n\nYou must provide a `project` and a `uiFramework` for the generator to work.\n\nYou may also pass the `includeVitest` flag. This will also change your `test` target to use the `@nrwl/vite:test` executor, and configure your project for testing with [Vitest](https://vitest.dev/), by adding the `test` configuration in your `vite.config.ts` file.\n\n## Converting custom (specific) targets\n\nBy default, the `@nrwl/vite:configuration` generator will search your project's configuration to find the targets for serving, building, and testing your project, and it will attempt to convert these targets to use the `@nrwl/vite` executors.\n\nYour targets for building, serving and testing may not be named `build`, `serve` and `test`. Nx will try to infer the correct targets to convert, and it will attempt to convert the first one it finds for each of these actions if you have more than one. If you have more than one target for serving, building, or testing your project, you can pass the `--serveTarget`, `--buildTarget`, and `--testTarget` flags to the generator, to tell Nx specifically which targets to convert.\n\nNx will determine if the targets you provided (or the ones it inferred) are valid and can be converted to use the `@nrwl/vite` executors. If the targets are not valid, the generator will fail. If no targets are found - or recognized to be either supported or unsupported - Nx will ask you whether you want to convert your project anyway. If you choose to do so, Nx will configure your project to use Vite.js, creating new targets for you, and creating or modifying your `vite.config.ts` file. You can then test on your own if the result works or not, and modify the configuration as needed. It's suggested that if Nx does not recognize your targets automatically, you commit your changes before running the generator, so you can revert the changes if needed.\n\n## Projects that can be converted to use the `@nrwl/vite` executors\n\nUsually, React and Web projects generated with the `@nrwl/react` and the `@nrwl/web` generators can be converted to use the `@nrwl/vite` executors without any issues.\n\nThe list of executors for building, testing and serving that can be converted to use the `@nrwl/vite` executors is:\n\n### Supported `build` executors\n\n- `@nxext/vite:build`\n- `@nrwl/js:babel`\n- `@nrwl/js:swc`\n- `@nrwl/webpack:webpack`\n- `@nrwl/rollup:rollup`\n- `@nrwl/web:rollup`\n\n### Supported `serve` executors\n\n- `@nxext/vite:dev`\n- `@nrwl/webpack:dev-server`\n\n### Supported `test` executors\n\n- `@nrwl/jest:jest`\n- `@nxext/vitest:vitest`\n\n### Unsupported executors\n\n- `@nrwl/angular:ng-packagr-lite`\n- `@nrwl/angular:package`\n- `@nrwl/angular:webpack-browser`\n- `@angular-devkit/build-angular:browser`\n- `@angular-devkit/build-angular:dev-server`\n- `@nrwl/esbuild:esbuild`\n- `@nrwl/react-native:start`\n- `@nrwl/next:build`\n- `@nrwl/next:server`\n- `@nrwl/js:tsc`\n- any executor _not_ listed in the lists of \"supported executors\"\n- any project that does _not_ have a target for building, serving or testing\n\nWe **cannot** guarantee that projects using unsupported executors - _or any executor that is NOT listed in the list of \"supported executors\"_ - for either building, testing or serving will work correctly when converted to use the `@nrwl/vite` executors.\n\nIf you have a project that does _not_ use one of the supported executors you can try to [configure it to use the `@nrwl/vite` executors manually](/packages/vite/documents/set-up-vite-manually), but it may not work properly.\n\nYou can read more in the [Vite package overview page](/packages/vite).\n\n## Examples\n\n### Change a React app to use Vite\n\n```bash\nnx g @nrwl/vite:configuration --project=my-react-app --uiFramework=react --includeVitest\n```\n\nThis will change the `my-react-app` project to use the `@nrwl/vite` executors for building, serving and testing the application.\n\n### Change a Web app to use Vite\n\n```bash\nnx g @nrwl/vite:configuration --project=my-web-app --uiFramework=none --includeVitest\n```\n\nThis will change the `my-web-app` project to use the `@nrwl/vite` executors for building, serving and testing the application.\n\n### Change only my custom provided targets to use Vite\n\n```bash\nnx g @nrwl/vite:configuration --project=my-react-app --uiFramework=react --includeVitest --buildTarget=my-build --serveTarget=my-serve --testTarget=my-test\n```\n\nThis will change the `my-build`, `my-serve` and `my-test` targets to use the `@nrwl/vite` executors for building, serving and testing the application, even if you have other targets for these actions as well.\n",
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/vite/generators/vitest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/expo/src/generators/application/lib/add-detox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export async function addDetox(host: Tree, options: NormalizedSchema) {
appName: options.name,
framework: 'expo',
setParserOptionsProject: options.setParserOptionsProject,
skipFormat: true,
});
}
1 change: 1 addition & 0 deletions packages/expo/src/utils/add-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion packages/express/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function projectGenerator(
uiFramework: 'none',
includeVitest: options.unitTestRunner === 'vitest',
includeLib: true,
skipFormat: true,
});
tasks.push(viteTask);
}
Expand Down Expand Up @@ -107,6 +108,7 @@ export async function projectGenerator(
project: options.name,
uiFramework: 'none',
coverageProvider: 'c8',
skipFormat: true,
});
tasks.push(vitestTask);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,7 +121,9 @@ export async function lintWorkspaceRulesProjectGenerator(tree: Tree) {
}
);

await formatFiles(tree);
if (!options.skipFormat) {
await formatFiles(tree);
}

return installTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function conversionGenerator(
projectDirectory: '',
fileName: '',
parsedTags: [],
skipFormat: options.skipFormat,
skipFormat: true,
} as AddLintForLibrarySchema);
}
},
Expand Down
5 changes: 4 additions & 1 deletion packages/nest/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export async function addCypress(host: Tree, options: NormalizedSchema) {
name: `${options.name}-e2e`,
directory: options.directory,
project: options.projectName,
skipFormat: true,
});
}
7 changes: 7 additions & 0 deletions packages/next/src/generators/component/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
convertNxGenerator,
formatFiles,
getProjects,
runTasksInSerial,
Tree,
Expand All @@ -17,6 +18,7 @@ interface Schema {
flat?: boolean;
pascalCaseFiles?: boolean;
pascalCaseDirectory?: boolean;
skipFormat?: boolean;
}

function getDirectory(host: Tree, options: Schema) {
Expand All @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/generators/component/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

1 comment on commit 4eb7cc7

@vercel
Copy link

@vercel vercel bot commented on 4eb7cc7 Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.