Skip to content

Commit

Permalink
feat(js): generate JS monorepos with workspaces enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored and leosvelperez committed Sep 19, 2024
1 parent aaa0202 commit e0e15eb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
12 changes: 6 additions & 6 deletions docs/generated/packages/js/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"title": "Init nx/js",
"description": "Init generator placeholder for nx/js.",
"properties": {
"formatter": {
"description": "The tool to use for code formatting.",
"type": "string",
"enum": ["none", "prettier"],
"default": "none"
},
"js": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -40,12 +46,6 @@
"type": "string",
"description": "Customize the generated base tsconfig file name.",
"x-priority": "internal"
},
"setUpPrettier": {
"type": "boolean",
"description": "Add Prettier and corresponding configuration files.",
"x-priority": "internal",
"default": false
}
},
"presets": []
Expand Down
4 changes: 0 additions & 4 deletions docs/generated/packages/js/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@
"useProjectJson": {
"type": "boolean",
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
},
"setUpPrettier": {
"description": "Set up prettier configuration in the workspace if not already set up.",
"type": "boolean"
}
},
"required": ["name"],
Expand Down
6 changes: 0 additions & 6 deletions docs/generated/packages/vite/generators/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@
"type": "string",
"enum": ["node", "jsdom", "happy-dom", "edge-runtime"],
"default": "jsdom"
},
"setUpPrettier": {
"type": "boolean",
"description": "Add Prettier and corresponding configuration files.",
"x-priority": "internal",
"default": false
}
},
"examplesFile": "---\ntitle: Examples for the Vite configuration generator\ndescription: This page contains examples for the Vite @nx/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/).\n\nIt 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 @nx/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 configure your project for testing with [Vitest](https://vitest.dev/), by adding the `test` configuration in your `vite.config.ts` file.\n\n## How to use\n\nIf you have an existing project that does not use Vite, you may want to convert it to use Vite. This can be a `webpack` project, a buildable JS library that uses the `@nx/js:babel`, the `@nx/js:swc` or the `@nx/rollup:rollup` executor, or even a non-buildable library.\nBy default, the `@nx/vite:configuration` generator will search your project to find the relevant configuration (either a `webpack.config.ts` file for example, or the `@nx/js` executors). If it determines that your project can be converted, then Nx will generate the configuration for you. If it cannot determine that your project can be converted, it will ask you if you want to convert it anyway or throw an error if it determines that it cannot be converted.\n\nYou can then test on your own if the result works or not, and modify the configuration as needed. It's suggested that 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 `@nx/vite` executors\n\nUsually, React and Web projects generated with the `@nx/react` and the `@nx/web` generators can be converted to use the `@nx/vite` executors without any issues.\n\nThe list of executors for building, testing and serving that can be converted to use the `@nx/vite` executors is:\n\n### Supported `build` executors\n\n- `@nxext/vite:build`\n- `@nx/js:babel`\n- `@nx/js:swc`\n- `@nx/rollup:rollup`\n- `@nx/webpack:webpack`\n- `@nx/web:rollup`\n\n### Unsupported executors\n\n- `@nx/angular:ng-packagr-lite`\n- `@nx/angular:package`\n- `@nx/angular:webpack-browser`\n- `@angular-devkit/build-angular:browser`\n- `@angular-devkit/build-angular:dev-server`\n- `@nx/esbuild:esbuild`\n- `@nx/react-native:start`\n- `@nx/next:build`\n- `@nx/next:server`\n- `@nx/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 Vite.\n\nYou can read more in the [Vite package overview page](/nx-api/vite).\n\n## Examples\n\n### Convert a React app to use Vite\n\n```bash\nnx g @nx/vite:configuration --project=my-react-app --uiFramework=react --includeVitest\n```\n\nThis will configure the `my-react-app` project to use Vite.\n\n### Convert a Web app to use Vite\n\n```bash\nnx g @nx/vite:configuration --project=my-web-app --uiFramework=none --includeVitest\n```\n\nThis will configure the `my-web-app` project to use Vite.\n",
Expand Down
6 changes: 0 additions & 6 deletions docs/generated/packages/vite/generators/vitest.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
"description": "The vitest environment to use. See https://vitest.dev/config/#environment.",
"type": "string",
"enum": ["node", "jsdom", "happy-dom", "edge-runtime"]
},
"setUpPrettier": {
"type": "boolean",
"description": "Add Prettier and corresponding configuration files.",
"x-priority": "internal",
"default": false
}
},
"required": ["project"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ function createFiles(tree: Tree, options: NormalizedSchema) {
options.preset === Preset.RemixStandalone ||
options.preset === Preset.TsStandalone
? './files-root-app'
: options.preset === Preset.NPM
: (options.preset === Preset.TS &&
process.env.NX_ADD_TS_PLUGIN === 'true') ||
options.preset === Preset.NPM
? './files-package-based-repo'
: './files-integrated-repo';
generateFiles(tree, join(__dirname, filesDirName), options.directory, {
Expand Down Expand Up @@ -409,7 +411,10 @@ function normalizeOptions(options: NormalizedSchema) {
}

function setUpWorkspacesInPackageJson(tree: Tree, options: NormalizedSchema) {
if (options.preset === Preset.NPM) {
if (
options.preset === Preset.NPM ||
(options.preset === Preset.TS && process.env.NX_ADD_TS_PLUGIN === 'true')
) {
if (options.packageManager === 'pnpm') {
tree.write(
join(options.directory, 'pnpm-workspace.yaml'),
Expand Down

0 comments on commit e0e15eb

Please sign in to comment.