Skip to content

Commit

Permalink
feat(nextjs): Add convert-to-inferred generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham committed Jun 26, 2024
1 parent 6ebf676 commit 103b1ee
Show file tree
Hide file tree
Showing 15 changed files with 1,250 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -8200,6 +8200,14 @@
"children": [],
"isExternal": false,
"disableCollapsible": false
},
{
"id": "convert-to-inferred",
"path": "/nx-api/next/generators/convert-to-inferred",
"name": "convert-to-inferred",
"children": [],
"isExternal": false,
"disableCollapsible": false
}
],
"isExternal": false,
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/manifests/nx-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,15 @@
"originalFilePath": "/packages/next/src/generators/cypress-component-configuration/schema.json",
"path": "/nx-api/next/generators/cypress-component-configuration",
"type": "generator"
},
"/nx-api/next/generators/convert-to-inferred": {
"description": "Convert an existing Next.js project(s) using `@nx/next:build` to use `@nx/next/plugin`. Defaults to migrating all projects. Pass '--project' to migrate a single project.",
"file": "generated/packages/next/generators/convert-to-inferred.json",
"hidden": false,
"name": "convert-to-inferred",
"originalFilePath": "/packages/next/src/generators/convert-to-inferred/schema.json",
"path": "/nx-api/next/generators/convert-to-inferred",
"type": "generator"
}
},
"path": "/nx-api/next"
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,15 @@
"originalFilePath": "/packages/next/src/generators/cypress-component-configuration/schema.json",
"path": "next/generators/cypress-component-configuration",
"type": "generator"
},
{
"description": "Convert an existing Next.js project(s) using `@nx/next:build` to use `@nx/next/plugin`. Defaults to migrating all projects. Pass '--project' to migrate a single project.",
"file": "generated/packages/next/generators/convert-to-inferred.json",
"hidden": false,
"name": "convert-to-inferred",
"originalFilePath": "/packages/next/src/generators/convert-to-inferred/schema.json",
"path": "next/generators/convert-to-inferred",
"type": "generator"
}
],
"githubRoot": "https://github.com/nrwl/nx/blob/master",
Expand Down
30 changes: 30 additions & 0 deletions docs/generated/packages/next/generators/convert-to-inferred.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "convert-to-inferred",
"factory": "./src/generators/convert-to-inferred/convert-to-inferred",
"schema": {
"$schema": "https://json-schema.org/schema",
"$id": "NxNextjsConvertToInferred",
"description": "Convert existing Next.js project(s) using `@nx/next:build` executor to use `@nx/next/plugin`.",
"title": "Convert a Nextjs project from executor to plugin",
"type": "object",
"properties": {
"project": {
"type": "string",
"description": "The project to convert from using the `@nx/next:build` executor to use `@nx/next/plugin`. If not provided, all projects using the `@nx/next:build` executor will be converted.",
"x-priority": "important"
},
"skipFormat": {
"type": "boolean",
"description": "Whether to format files.",
"default": false
}
},
"presets": []
},
"description": "Convert an existing Next.js project(s) using `@nx/next:build` to use `@nx/next/plugin`. Defaults to migrating all projects. Pass '--project' to migrate a single project.",
"implementation": "/packages/next/src/generators/convert-to-inferred/convert-to-inferred.ts",
"aliases": [],
"hidden": false,
"path": "/packages/next/src/generators/convert-to-inferred/schema.json",
"type": "generator"
}
1 change: 1 addition & 0 deletions docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@
- [library](/nx-api/next/generators/library)
- [custom-server](/nx-api/next/generators/custom-server)
- [cypress-component-configuration](/nx-api/next/generators/cypress-component-configuration)
- [convert-to-inferred](/nx-api/next/generators/convert-to-inferred)
- [node](/nx-api/node)
- [documents](/nx-api/node/documents)
- [Overview](/nx-api/node/documents/overview)
Expand Down
5 changes: 5 additions & 0 deletions packages/next/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
"factory": "./src/generators/cypress-component-configuration/cypress-component-configuration#cypressComponentConfigurationInternal",
"schema": "./src/generators/cypress-component-configuration/schema.json",
"description": "cypress-component-configuration generator"
},
"convert-to-inferred": {
"factory": "./src/generators/convert-to-inferred/convert-to-inferred",
"schema": "./src/generators/convert-to-inferred/schema.json",
"description": "Convert an existing Next.js project(s) using `@nx/next:build` to use `@nx/next/plugin`. Defaults to migrating all projects. Pass '--project' to migrate a single project."
}
}
}
3 changes: 2 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"@nx/react": "file:../react",
"@nx/web": "file:../web",
"@nx/webpack": "file:../webpack",
"@nx/workspace": "file:../workspace"
"@nx/workspace": "file:../workspace",
"@phenomnomnominal/tsquery": "~5.0.1"
},
"publishConfig": {
"access": "public"
Expand Down
11 changes: 7 additions & 4 deletions packages/next/plugins/with-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type ProjectGraphProjectNode,
type Target,
} from '@nx/devkit';
import type { AssetGlobPattern } from '@nx/webpack';

export interface SvgrOptions {
svgo?: boolean;
Expand All @@ -22,6 +23,8 @@ export interface WithNxOptions extends NextConfig {
nx?: {
svgr?: boolean | SvgrOptions;
babelUpwardRootMode?: boolean;
fileReplacements?: { replace: string; with: string }[];
assets?: AssetGlobPattern[];
};
}

Expand Down Expand Up @@ -210,12 +213,12 @@ function withNx(
const userWebpackConfig = nextConfig.webpack;

const { createWebpackConfig } = require('@nx/next/src/utils/config');
// If we have file replacements or assets, inside of the next config we pass '.' as the workspaceRoot so that the paths are relative to the project.
nextConfig.webpack = (a, b) =>
createWebpackConfig(
workspaceRoot,
projectDirectory,
options.fileReplacements,
options.assets
_nextConfig.nx?.fileReplacements ? projectDirectory : workspaceRoot,
_nextConfig.nx?.assets || options.assets,
_nextConfig.nx?.fileReplacements || options.fileReplacements
)(userWebpackConfig ? userWebpackConfig(a, b) : a, b);

return nextConfig;
Expand Down
Loading

0 comments on commit 103b1ee

Please sign in to comment.