feat(misc): update to Nx 16 and rescoped packages (#235)

This commit is contained in:
Jack Hsu 2023-05-02 10:45:48 -04:00 committed by GitHub
parent a5a7fa2f46
commit ffb91bcabb
24 changed files with 88 additions and 82 deletions

View File

@ -18,7 +18,7 @@
"files": ["./package.json", "./generators.json", "./executors.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nrwl/nx/nx-plugin-checks": "error"
"@nx/nx-plugin-checks": "error"
}
}
]

View File

@ -56,7 +56,7 @@ npx nx g @nrwl/rspack:rspack-project --skipValidation
The `@nrwl/rspack` executor support importing workspace libs into the app.
```bash
npx nx g @nrwl/react:lib mylib
npx nx g @nx/react:lib mylib
```
Import the new library in your app.

View File

@ -1,5 +1,5 @@
{
"name": "@nrwl/rspack",
"name": "@nx/rspack",
"version": "0.0.1",
"type": "commonjs",
"repository": {
@ -19,9 +19,9 @@
"generators": "./generators.json",
"executors": "./executors.json",
"dependencies": {
"@nrwl/js": "^15.8.1",
"@nrwl/linter": "^15.8.1",
"@nrwl/devkit": "^15.8.1",
"@nx/js": "^16.0.0",
"@nx/linter": "^16.0.0",
"@nx/devkit": "^16.0.0",
"@phenomnomnominal/tsquery": "~5.0.1",
"ajv": "^8.12.0",
"ajv-keywords": "5.1.0",

View File

@ -5,7 +5,7 @@
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/rspack",
@ -37,7 +37,7 @@
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
@ -49,7 +49,7 @@
}
},
"test": {
"executor": "@nrwl/jest:jest",
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "packages/rspack/jest.config.ts",

View File

@ -2,8 +2,8 @@ import {
ExecutorContext,
parseTargetString,
readTargetOptions,
} from '@nrwl/devkit';
import { createAsyncIterable } from '@nrwl/devkit/src/utils/async-iterable';
} from '@nx/devkit';
import { createAsyncIterable } from '@nx/devkit/src/utils/async-iterable';
import { DevServer } from '@rspack/core/dist/config';
import { RspackDevServer } from '@rspack/dev-server';
import { createCompiler } from '../../utils/create-compiler';

View File

@ -1,7 +1,6 @@
{
"$schema": "http://json-schema.org/schema",
"version": 2,
"cli": "nx",
"title": "Rspack dev-server executor",
"description": "",
"type": "object",

View File

@ -1,5 +1,5 @@
import { ExecutorContext, logger } from '@nrwl/devkit';
import { createAsyncIterable } from '@nrwl/devkit/src/utils/async-iterable';
import { ExecutorContext, logger } from '@nx/devkit';
import { createAsyncIterable } from '@nx/devkit/src/utils/async-iterable';
import { Stats } from '@rspack/core';
import Watching from '@rspack/core/dist/watching';
import { rmSync } from 'fs';

View File

@ -1,7 +1,6 @@
{
"$schema": "http://json-schema.org/schema",
"version": 2,
"cli": "nx",
"title": "Rspack build executor",
"description": "",
"type": "object",

View File

@ -1,9 +1,4 @@
import {
ensurePackage,
formatFiles,
runTasksInSerial,
Tree,
} from '@nrwl/devkit';
import { ensurePackage, formatFiles, runTasksInSerial, Tree } from '@nx/devkit';
import { version as nxVersion } from 'nx/package.json';
import configurationGenerator from '../configuration/configuration';
import rspackInitGenerator from '../init/init';
@ -24,7 +19,7 @@ export default async function (
if (options.framework === 'nest') {
const { applicationGenerator: nestAppGenerator } = ensurePackage(
'@nrwl/nest',
'@nx/nest',
nxVersion
);
const createAppTask = await nestAppGenerator(tree, {
@ -70,7 +65,7 @@ export default async function (
} else {
// default to react
const { applicationGenerator: reactAppGenerator } = ensurePackage(
'@nrwl/react',
'@nx/react',
nxVersion
);
const createAppTask = await reactAppGenerator(tree, {

View File

@ -1,4 +1,4 @@
import { Tree, workspaceRoot, writeJson } from '@nrwl/devkit';
import { Tree, workspaceRoot, writeJson } from '@nx/devkit';
import { relative } from 'path';
import { Framework } from '../../init/schema';
@ -8,12 +8,12 @@ export function editTsConfig(
framework: Framework,
relativePathToRootTsConfig: string
) {
// Nx 15.8 moved util to @nrwl/js, but it is in @nrwl/workspace in 15.7
// Nx 15.8 moved util to @nx/js, but it is in @nx/workspace in 15.7
let shared: any;
try {
shared = require('@nrwl/js/src/utils/typescript/create-ts-config');
shared = require('@nx/js/src/utils/typescript/create-ts-config');
} catch {
shared = require('@nrwl/workspace/src/utils/create-ts-config');
shared = require('@nx/workspace/src/utils/create-ts-config');
}
if (framework === 'react') {

View File

@ -1,5 +1,5 @@
import { Tree } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { normalizeOptions } from './normalize-options';
describe('normalizeOptions', () => {

View File

@ -4,7 +4,7 @@ import {
names,
normalizePath,
Tree,
} from '@nrwl/devkit';
} from '@nx/devkit';
import { ApplicationGeneratorSchema, NormalizedSchema } from '../schema';
export function normalizeDirectory(options: ApplicationGeneratorSchema) {
@ -23,7 +23,7 @@ export function normalizeOptions(
options: ApplicationGeneratorSchema
): NormalizedSchema {
// --monorepo takes precedence over --rootProject
// This won't be needed once we add --bundler=rspack to the @nrwl/react:app preset
// This won't be needed once we add --bundler=rspack to the @nx/react:app preset
const rootProject = !options.monorepo && options.rootProject;
const appDirectory = normalizeDirectory(options);
const appProjectName = normalizeProjectName(options);

View File

@ -1,6 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "Application",
"title": "Application generator for React + rspack",
"type": "object",

View File

@ -4,7 +4,7 @@ import {
offsetFromRoot,
readProjectConfiguration,
Tree,
} from '@nrwl/devkit';
} from '@nx/devkit';
import {
addOrChangeBuildTarget,
addOrChangeServeTarget,
@ -72,8 +72,8 @@ export async function configurationGenerator(
options.framework === 'nest')
) {
throw new Error(
`The project ${options.project} is already configured to use the @nrwl/rspack executors.
Please try a different project, or remove the existing targets
`The project ${options.project} is already configured to use the @nx/rspack executors.
Please try a different project, or remove the existing targets
and re-run this generator to reset the existing Rspack Configuration.
`
);
@ -81,7 +81,7 @@ export async function configurationGenerator(
if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {
throw new Error(
`The project ${options.project} cannot be converted to use the @nrwl/rspack executors.`
`The project ${options.project} cannot be converted to use the @nx/rspack executors.`
);
}

View File

@ -1,6 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "Rspack",
"title": "",
"type": "object",

View File

@ -1,12 +1,11 @@
import {
addDependenciesToPackageJson,
convertNxGenerator,
ensurePackage,
GeneratorCallback,
runTasksInSerial,
Tree,
} from '@nrwl/devkit';
import { version as nxVersion } from 'nx/package.json';
} from '@nx/devkit';
import { initGenerator } from '@nx/js';
import {
rspackCoreVersion,
rspackDevServerVersion,
@ -20,10 +19,6 @@ export async function rspackInitGenerator(
schema: InitGeneratorSchema
) {
const tasks: GeneratorCallback[] = [];
const { initGenerator } = ensurePackage<typeof import('@nrwl/js')>(
'@nrwl/js',
nxVersion
);
const jsInitTask = await initGenerator(tree, {
...schema,
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
@ -41,7 +36,7 @@ export async function rspackInitGenerator(
const version = require('../../../package.json').version;
if (version !== '0.0.1') {
// Ignored for local dev / e2e tests.
devDependencies['@nrwl/rspack'] = version;
devDependencies['@nx/rspack'] = version;
}
if (schema.style === 'less') {

View File

@ -1,6 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "Init",
"title": "",
"type": "object",

View File

@ -1,4 +1,4 @@
import { Tree, updateJson } from '@nrwl/devkit';
import { Tree, updateJson } from '@nx/devkit';
import applicationGenerator from '../application/application';
import { PresetGeneratorSchema } from './schema';

View File

@ -1,6 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "Preset",
"title": "Standalone React and rspack preset",
"type": "object",

View File

@ -1,4 +1,4 @@
import { ExecutorContext } from '@nrwl/devkit';
import { ExecutorContext } from '@nx/devkit';
import { Compiler, createCompiler as _createCompiler } from '@rspack/core';
import * as path from 'path';
import { RspackExecutorSchema } from '../executors/rspack/schema';

View File

@ -5,8 +5,8 @@ import {
TargetConfiguration,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { ensureTypescript } from '@nrwl/js/src/utils/typescript/ensure-typescript';
} from '@nx/devkit';
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
import { RspackExecutorSchema } from '../executors/rspack/schema';
import { ConfigurationSchema } from '../generators/configuration/schema';
import { Framework } from '../generators/init/schema';
@ -41,24 +41,40 @@ export function findExistingTargetsInProject(
'@nrwl/rollup:rollup',
'@nrwl/web:rollup',
'@nrwl/vite:build',
'@nx/webpack:webpack',
'@nx/rollup:rollup',
'@nx/web:rollup',
'@nx/vite:build',
],
serve: [
'@nxext/vite:dev',
'@nrwl/webpack:dev-server',
'@nrwl/vite:dev-server',
'@nx/webpack:dev-server',
'@nx/vite:dev-server',
],
};
const unsupportedExecutors = [
'@nx/js:babel',
'@nx/js:node',
'@nx/js:swc',
'@nx/react-native:run-ios',
'@nx/react-native:start',
'@nx/react-native:run-android',
'@nx/react-native:bundle',
'@nx/react-native:build-android',
'@nx/react-native:bundle',
'@nx/next:build',
'@nx/next:server',
'@nx/js:tsc',
'@nx/angular:ng-packagr-lite',
'@nx/angular:package',
'@nx/angular:webpack-browser',
'@nx/esbuild:esbuild',
'@nrwl/js:babel',
'@nrwl/js:node',
'@nrwl/js:swc',
'@nrwl/js:tsc',
'@nrwl/angular:ng-packagr-lite',
'@nrwl/angular:package',
'@nrwl/angular:webpack-browser',
'@angular-devkit/build-angular:browser',
'@angular-devkit/build-angular:dev-server',
'@nrwl/react-native:run-ios',
'@nrwl/react-native:start',
'@nrwl/react-native:run-android',
@ -67,7 +83,13 @@ export function findExistingTargetsInProject(
'@nrwl/react-native:bundle',
'@nrwl/next:build',
'@nrwl/next:server',
'@nrwl/js:tsc',
'@nrwl/angular:ng-packagr-lite',
'@nrwl/angular:package',
'@nrwl/angular:webpack-browser',
'@nrwl/esbuild:esbuild',
'@angular-devkit/build-angular:browser',
'@angular-devkit/build-angular:dev-server',
];
// First, we check if the user has provided a target
@ -102,8 +124,8 @@ export function findExistingTargetsInProject(
const executorName = targets[target].executor;
const hasRspackTargets = output.alreadyHasNxRspackTargets;
hasRspackTargets.build ||= executorName === '@nrwl/rspack:rspack';
hasRspackTargets.serve ||= executorName === '@nrwl/rspack:dev-server';
hasRspackTargets.build ||= executorName === '@nx/rspack:rspack';
hasRspackTargets.serve ||= executorName === '@nx/rspack:dev-server';
const foundTargets = output.validFoundTargetName;
if (
@ -159,7 +181,7 @@ export function addOrChangeBuildTarget(
project.targets ??= {};
project.targets[target] = {
executor: '@nrwl/rspack:rspack',
executor: '@nx/rspack:rspack',
outputs: ['{options.outputPath}'],
defaultConfiguration: 'production',
options: buildOptions,
@ -188,7 +210,7 @@ export function addOrChangeServeTarget(
project.targets ??= {};
project.targets[target] = {
executor: '@nrwl/rspack:dev-server',
executor: '@nx/rspack:dev-server',
options: {
buildTarget: `${options.project}:build:development`,
},
@ -222,7 +244,7 @@ function createConfig(
) {
if (options.framework === 'react') {
return `
const { composePlugins, withNx, withReact } = require('@nrwl/rspack');
const { composePlugins, withNx, withReact } = require('@nx/rspack');
module.exports = composePlugins(withNx(), withReact(${
stylePreprocessorOptions
@ -238,7 +260,7 @@ function createConfig(
`;
} else if (options.framework === 'web' || options.target === 'web') {
return `
const { composePlugins, withNx, withWeb } = require('@nrwl/rspack');
const { composePlugins, withNx, withWeb } = require('@nx/rspack');
module.exports = composePlugins(withNx(), withWeb(${
stylePreprocessorOptions
@ -254,7 +276,7 @@ function createConfig(
`;
} else if (options.framework === 'nest') {
return `
const { composePlugins, withNx } = require('@nrwl/rspack');
const { composePlugins, withNx } = require('@nx/rspack');
module.exports = composePlugins(withNx(), (config) => {
return config;
@ -264,7 +286,7 @@ function createConfig(
return `
const { composePlugins, withNx${
stylePreprocessorOptions ? ', withWeb' : ''
} } = require('@nrwl/rspack');
} } = require('@nx/rspack');
module.exports = composePlugins(withNx()${
stylePreprocessorOptions
@ -392,7 +414,7 @@ export function getViteConfigPathForProject(
viteConfigPath = targets?.[target]?.options?.configFile;
} else {
const config = Object.values(targets).find(
(config) => config.executor === '@nrwl/rspack:build'
(config) => config.executor === '@nx/rspack:build'
);
viteConfigPath = config?.options?.configFile;
}
@ -436,7 +458,7 @@ async function handleUnsupportedUserProvidedTargetsErrors(
executor: 'rspack' | 'dev-server'
) {
logger.warn(
`The custom ${target} target you provided (${userProvidedTargetName}) cannot be converted to use the @nrwl/rspack:${executor} executor.
`The custom ${target} target you provided (${userProvidedTargetName}) cannot be converted to use the @nx/rspack:${executor} executor.
However, we found the following ${target} target in your project that can be converted: ${validFoundTargetName}
Please note that converting a potentially non-compatible project to use Vite.js may result in unexpected behavior. Always commit
@ -447,13 +469,13 @@ async function handleUnsupportedUserProvidedTargetsErrors(
const { Confirm } = require('enquirer');
const prompt = new Confirm({
name: 'question',
message: `Should we convert the ${validFoundTargetName} target to use the @nrwl/rspack:${executor} executor?`,
message: `Should we convert the ${validFoundTargetName} target to use the @nx/rspack:${executor} executor?`,
initial: true,
});
const shouldConvert = await prompt.run();
if (!shouldConvert) {
throw new Error(
`The ${target} target ${userProvidedTargetName} cannot be converted to use the @nrwl/rspack:${executor} executor.
`The ${target} target ${userProvidedTargetName} cannot be converted to use the @nx/rspack:${executor} executor.
Please try again, either by providing a different ${target} target or by not providing a target at all (Nx will
convert the first one it finds, most probably this one: ${validFoundTargetName})
@ -467,14 +489,14 @@ async function handleUnsupportedUserProvidedTargetsErrors(
export async function handleUnknownExecutors(projectName: string) {
logger.warn(
`
We could not find any targets in project ${projectName} that use executors which
can be converted to the @nrwl/rspack executors.
We could not find any targets in project ${projectName} that use executors which
can be converted to the @nx/rspack executors.
This either means that your project may not have a target
for building, serving, or testing at all, or that your targets are
This either means that your project may not have a target
for building, serving, or testing at all, or that your targets are
using executors that are not known to Nx.
If you still want to convert your project to use the @nrwl/rspack executors,
If you still want to convert your project to use the @nx/rspack executors,
please make sure to commit your changes before running this generator.
`
);
@ -483,13 +505,13 @@ export async function handleUnknownExecutors(projectName: string) {
const { Confirm } = require('enquirer');
const prompt = new Confirm({
name: 'question',
message: `Should Nx convert your project to use the @nrwl/rspack executors?`,
message: `Should Nx convert your project to use the @nx/rspack executors?`,
initial: true,
});
const shouldConvert = await prompt.run();
if (!shouldConvert) {
throw new Error(`
Nx could not verify that the executors you are using can be converted to the @nrwl/rspack executors.
Nx could not verify that the executors you are using can be converted to the @nx/rspack executors.
Please try again with a different project.
`);
}
@ -512,7 +534,7 @@ export function determineFrameworkAndTarget(
// Try to infer from jest config if the env is node
let jestConfigPath: string;
if (
targets?.test?.executor !== '@nrwl/jest:jest' &&
targets?.test?.executor !== '@nx/jest:jest' &&
targets?.test?.options?.jestConfig
) {
jestConfigPath = targets?.test?.options?.jestConfig;

View File

@ -2,10 +2,10 @@ export function updateJestConfigContent(content: string) {
return content
.replace(
'transform: {',
"transform: {\n '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',"
"transform: {\n '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',"
)
.replace(
`'babel-jest'`,
`['babel-jest', { presets: ['@nrwl/react/babel'] }]`
`['babel-jest', { presets: ['@nx/react/babel'] }]`
);
}

View File

@ -1,4 +1,4 @@
import { ExecutorContext } from '@nrwl/devkit';
import { ExecutorContext } from '@nx/devkit';
import { RspackExecutorSchema } from '../executors/rspack/schema';
export interface SharedConfigContext {

View File

@ -1,4 +1,4 @@
import { normalizePath } from '@nrwl/devkit';
import { normalizePath } from '@nx/devkit';
import { statSync } from 'fs';
import { basename, dirname, relative, resolve } from 'path';