-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rsbuild): add inferred targets plugin
- Loading branch information
Showing
16 changed files
with
561 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "init", | ||
"factory": "./src/generators/init/init#initGeneratorInternal", | ||
"schema": { | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "Init", | ||
"title": "Nx Rsbuild Init Generator", | ||
"type": "object", | ||
"description": "Rsbuild init generator.", | ||
"properties": { | ||
"rootProject": { "type": "boolean", "x-priority": "internal" }, | ||
"keepExistingVersions": { | ||
"type": "boolean", | ||
"x-priority": "internal", | ||
"description": "Keep existing dependencies versions", | ||
"default": false | ||
}, | ||
"updatePackageScripts": { | ||
"type": "boolean", | ||
"x-priority": "internal", | ||
"description": "Update package scripts", | ||
"default": false | ||
}, | ||
"skipFormat": { | ||
"description": "Skip formatting files.", | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"skipPackageJson": { | ||
"description": "Do not add dependencies to `package.json`.", | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
"required": [], | ||
"presets": [] | ||
}, | ||
"description": "Initialize the `@nx/rsbuild` plugin.", | ||
"aliases": ["ng-add"], | ||
"hidden": true, | ||
"implementation": "/packages/rsbuild/src/generators/init/init#initGeneratorInternal.ts", | ||
"path": "/packages/rsbuild/src/generators/init/schema.json", | ||
"type": "generator" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "Nx Rsbuild", | ||
"version": "0.1", | ||
"generators": { | ||
"init": { | ||
"factory": "./src/generators/init/init#initGeneratorInternal", | ||
"schema": "./src/generators/init/schema.json", | ||
"description": "Initialize the `@nx/rsbuild` plugin.", | ||
"aliases": ["ng-add"], | ||
"hidden": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { createNodesV2, RsbuildPluginOptions } from './src/plugins/plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
type Tree, | ||
type GeneratorCallback, | ||
readNxJson, | ||
createProjectGraphAsync, | ||
addDependenciesToPackageJson, | ||
formatFiles, | ||
runTasksInSerial, | ||
} from '@nx/devkit'; | ||
import { addPlugin } from '@nx/devkit/src/utils/add-plugin'; | ||
import { InitGeneratorSchema } from './schema'; | ||
import { createNodesV2 } from '../../plugins/plugin'; | ||
import { nxVersion, rsbuildVersion } from '../../utils/versions'; | ||
|
||
export function updateDependencies(tree: Tree, schema: InitGeneratorSchema) { | ||
return addDependenciesToPackageJson( | ||
tree, | ||
{}, | ||
{ | ||
'@nx/rsbuild': nxVersion, | ||
'@rsbuild/core': rsbuildVersion, | ||
}, | ||
undefined, | ||
schema.keepExistingVersions | ||
); | ||
} | ||
|
||
export function initGenerator(tree: Tree, schema: InitGeneratorSchema) { | ||
return initGeneratorInternal(tree, { addPlugin: false, ...schema }); | ||
} | ||
|
||
export async function initGeneratorInternal( | ||
tree: Tree, | ||
schema: InitGeneratorSchema | ||
) { | ||
const nxJson = readNxJson(tree); | ||
const addPluginDefault = | ||
process.env.NX_ADD_PLUGINS !== 'false' && | ||
nxJson.useInferencePlugins !== false; | ||
schema.addPlugin ??= addPluginDefault; | ||
|
||
if (schema.addPlugin) { | ||
await addPlugin( | ||
tree, | ||
await createProjectGraphAsync(), | ||
'@nx/rsbuild/plugin', | ||
createNodesV2, | ||
{ | ||
buildTargetName: ['build', 'rsbuild:build', 'rsbuild-build'], | ||
devTargetName: ['dev', 'rsbuild:dev', 'rsbuild-dev'], | ||
previewTargetName: ['preview', 'rsbuild:preview', 'rsbuild-preview'], | ||
inspectTargetName: ['inspect', 'rsbuild:inspect', 'rsbuild-inspect'], | ||
typecheckTargetName: [ | ||
'typecheck', | ||
'rsbuild:typecheck', | ||
'rsbuild-typecheck', | ||
], | ||
}, | ||
schema.updatePackageScripts | ||
); | ||
} | ||
|
||
const tasks: GeneratorCallback[] = []; | ||
if (!schema.skipPackageJson) { | ||
tasks.push(updateDependencies(tree, schema)); | ||
} | ||
|
||
if (!schema.skipFormat) { | ||
await formatFiles(tree); | ||
} | ||
|
||
return runTasksInSerial(...tasks); | ||
} | ||
|
||
export default initGenerator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface InitGeneratorSchema { | ||
keepExistingVersions?: boolean; | ||
updatePackageScripts?: boolean; | ||
addPlugin?: boolean; | ||
skipFormat?: boolean; | ||
skipPackageJson?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "Init", | ||
"title": "Nx Rsbuild Init Generator", | ||
"type": "object", | ||
"description": "Rsbuild init generator.", | ||
"properties": { | ||
"rootProject": { | ||
"type": "boolean", | ||
"x-priority": "internal" | ||
}, | ||
"keepExistingVersions": { | ||
"type": "boolean", | ||
"x-priority": "internal", | ||
"description": "Keep existing dependencies versions", | ||
"default": false | ||
}, | ||
"updatePackageScripts": { | ||
"type": "boolean", | ||
"x-priority": "internal", | ||
"description": "Update package scripts", | ||
"default": false | ||
}, | ||
"skipFormat": { | ||
"description": "Skip formatting files.", | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"skipPackageJson": { | ||
"description": "Do not add dependencies to `package.json`.", | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
"required": [] | ||
} |
Oops, something went wrong.