Skip to content

Commit

Permalink
feat(rspack): add crystal plugin for inferring projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Jun 12, 2024
1 parent 87f4ad4 commit 9972b1a
Show file tree
Hide file tree
Showing 11 changed files with 688 additions and 334 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ Thumbs.db

# migration file
./migrations.json
.nx/cache
.nx/workspace-data
.nx/cache
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
},
"packageManager": "[email protected]",
"devDependencies": {
"@nx/cypress": "19.0.4",
"@nx/detox": "19.0.4",
"@nx/devkit": "19.0.4",
"@nx/eslint": "19.0.4",
"@nx/eslint-plugin": "19.0.4",
"@nx/jest": "19.0.4",
"@nx/js": "19.0.4",
"@nx/node": "19.0.4",
"@nx/plugin": "19.0.4",
"@nx/react": "19.0.4",
"@nx/storybook": "19.0.4",
"@nx/vite": "19.0.4",
"@nx/workspace": "19.0.4",
"@nx/cypress": "19.2.3",
"@nx/detox": "19.2.3",
"@nx/devkit": "19.2.3",
"@nx/eslint": "19.2.3",
"@nx/eslint-plugin": "19.2.3",
"@nx/jest": "19.2.3",
"@nx/js": "19.2.3",
"@nx/node": "19.2.3",
"@nx/plugin": "19.2.3",
"@nx/react": "19.2.3",
"@nx/storybook": "19.2.3",
"@nx/vite": "19.2.3",
"@nx/workspace": "19.2.3",
"@phenomnomnominal/tsquery": "^5.0.1",
"@rspack/core": "^0.5.6",
"@rspack/dev-server": "^0.5.6",
Expand All @@ -60,7 +60,7 @@
"kill-port": "^2.0.1",
"license-webpack-plugin": "^4.0.2",
"metro-resolver": "0.71.0",
"nx": "19.0.4",
"nx": "19.2.3",
"prettier": "2.6.2",
"prettier-plugin-organize-imports": "^3.2.1",
"release-it": "15.2.0",
Expand All @@ -73,4 +73,3 @@
"verdaccio": "^5.0.4"
}
}

6 changes: 3 additions & 3 deletions packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"generators": "./generators.json",
"executors": "./executors.json",
"dependencies": {
"@nx/js": "^18.1.3",
"@nx/devkit": "^18.1.3",
"@nx/js": "^19.2.3",
"@nx/devkit": "^19.2.3",
"@phenomnomnominal/tsquery": "~5.0.1",
"less-loader": "11.1.0",
"license-webpack-plugin": "^4.0.2",
"sass-loader": "^12.2.0",
"stylus-loader": "^7.1.0",
"@nx/eslint": "^18.1.3",
"@nx/eslint": "^19.2.3",
"@rspack/core": "^0.6.1",
"@rspack/plugin-react-refresh": "^0.6.1",
"@rspack/plugin-minify": "^0.6.1"
Expand Down
2 changes: 2 additions & 0 deletions packages/rspack/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { createDependencies, createNodesV2 } from './src/plugins/plugin';
export type { RspackPluginOptions } from './src/plugins/plugin';
51 changes: 48 additions & 3 deletions packages/rspack/src/generators/init/init.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import {
addDependenciesToPackageJson,
convertNxGenerator,
createProjectGraphAsync,
GeneratorCallback,
readNxJson,
runTasksInSerial,
Tree,
} from '@nx/devkit';
import { addPlugin } from '@nx/devkit/src/utils/add-plugin';
import { initGenerator } from '@nx/js';
import { createNodesV2 } from '../../../plugin';
import {
lessLoaderVersion, reactRefreshVersion,
lessLoaderVersion,
reactRefreshVersion,
rspackCoreVersion,
rspackDevServerVersion,
rspackPluginMinifyVersion,
rspackPluginReactRefreshVersion
rspackPluginReactRefreshVersion,
} from '../../utils/versions';
import { InitGeneratorSchema } from './schema';

Expand All @@ -20,6 +25,46 @@ export async function rspackInitGenerator(
schema: InitGeneratorSchema
) {
const tasks: GeneratorCallback[] = [];

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/rspack/plugin',
createNodesV2,
{
buildTargetName: [
'build',
'rspack:build',
'build:rspack',
'rspack-build',
'build-rspack',
],
serveTargetName: [
'serve',
'rspack:serve',
'serve:rspack',
'rspack-serve',
'serve-rspack',
],
previewTargetName: [
'preview',
'rspack:preview',
'preview:rspack',
'rspack-preview',
'preview-rspack',
],
},
schema.updatePackageScripts
);
}

const jsInitTask = await initGenerator(tree, {
...schema,
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
Expand All @@ -32,7 +77,7 @@ export async function rspackInitGenerator(
'@rspack/core': rspackCoreVersion,
'@rspack/plugin-minify': rspackPluginMinifyVersion,
'@rspack/plugin-react-refresh': rspackPluginReactRefreshVersion,
'react-refresh': reactRefreshVersion
'react-refresh': reactRefreshVersion,
};

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
8 changes: 5 additions & 3 deletions packages/rspack/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export type Framework = 'none' | 'react' | 'web' | 'nest';

export interface InitGeneratorSchema {
framework?: Framework;
style?: 'none' | 'css' | 'scss' | 'less' | 'styl';
addPlugin?: boolean;
devServer?: boolean;
rootProject?: boolean;
framework?: Framework;
keepExistingVersions?: boolean;
rootProject?: boolean;
style?: 'none' | 'css' | 'scss' | 'less' | 'styl';
updatePackageScripts?: boolean;
}
Loading

0 comments on commit 9972b1a

Please sign in to comment.