@nx/react 20.6.0-beta.0 → 20.6.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/router-plugin.d.ts +1 -0
- package/router-plugin.js +5 -0
- package/src/generators/application/application.js +42 -4
- package/src/generators/application/files/react-router-ssr/common/app/app-nav.tsx__tmpl__ +15 -0
- package/src/generators/application/files/react-router-ssr/common/app/entry.client.tsx__tmpl__ +18 -0
- package/src/generators/application/files/react-router-ssr/common/app/entry.server.tsx__tmpl__ +74 -0
- package/src/generators/application/files/react-router-ssr/common/app/root.tsx__tmpl__ +51 -0
- package/src/generators/application/files/react-router-ssr/common/app/routes/about.tsx__tmpl__ +7 -0
- package/src/generators/application/files/react-router-ssr/common/app/routes.tsx__tmpl__ +6 -0
- package/src/generators/application/files/react-router-ssr/common/public/favicon.ico +0 -0
- package/src/generators/application/files/react-router-ssr/common/react-router.config.ts__tmpl__ +5 -0
- package/src/generators/application/files/react-router-ssr/common/tests/routes/_index.spec.tsx__tmpl__ +16 -0
- package/src/generators/application/files/react-router-ssr/common/tsconfig.app.json__tmpl__ +23 -0
- package/src/generators/application/files/react-router-ssr/common/tsconfig.json__tmpl__ +27 -0
- package/src/generators/application/files/react-router-ssr/non-root/.gitignore__tmpl__ +5 -0
- package/src/generators/application/files/react-router-ssr/non-root/package.json__tmpl__ +24 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/claimed/app/nx-welcome.tsx__tmpl__ +866 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/not-configured/app/nx-welcome.tsx__tmpl__ +866 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/unclaimed/app/nx-welcome.tsx__tmpl__ +864 -0
- package/src/generators/application/files/react-router-ssr/ts-solution/package.json__tmpl__ +24 -0
- package/src/generators/application/files/react-router-ssr/ts-solution/tsconfig.app.json__tmpl__ +39 -0
- package/src/generators/application/lib/add-e2e.js +4 -2
- package/src/generators/application/lib/add-linting.d.ts +1 -0
- package/src/generators/application/lib/add-linting.js +38 -0
- package/src/generators/application/lib/add-project.js +12 -1
- package/src/generators/application/lib/add-routing.js +1 -1
- package/src/generators/application/lib/bundlers/add-vite.js +15 -6
- package/src/generators/application/lib/create-application-files.js +40 -3
- package/src/generators/application/lib/install-common-dependencies.js +13 -2
- package/src/generators/application/lib/normalize-options.js +3 -0
- package/src/generators/application/schema.d.ts +1 -0
- package/src/generators/application/schema.json +6 -1
- package/src/generators/init/init.js +23 -0
- package/src/generators/init/schema.d.ts +2 -0
- package/src/generators/library/library.js +3 -3
- package/src/plugins/router-plugin.d.ts +10 -0
- package/src/plugins/router-plugin.js +219 -0
- package/src/utils/ast-utils.d.ts +1 -1
- package/src/utils/ast-utils.js +2 -2
- package/src/utils/versions.d.ts +3 -1
- package/src/utils/versions.js +6 -3
@@ -0,0 +1,219 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createNodesV2 = void 0;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const path_1 = require("path");
|
6
|
+
const fs_1 = require("fs");
|
7
|
+
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
8
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
9
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
10
|
+
const js_1 = require("@nx/js");
|
11
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
12
|
+
const util_1 = require("@nx/js/src/plugins/typescript/util");
|
13
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
14
|
+
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
15
|
+
const pmCommand = (0, devkit_1.getPackageManagerCommand)();
|
16
|
+
const reactRouterConfigBlob = '**/react-router.config.{ts,js,cjs,cts,mjs,mts}';
|
17
|
+
function readTargetsCache(cachePath) {
|
18
|
+
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, fs_1.existsSync)(cachePath)
|
19
|
+
? (0, devkit_1.readJsonFile)(cachePath)
|
20
|
+
: {};
|
21
|
+
}
|
22
|
+
function writeTargetsToCache(cachePath, results) {
|
23
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
24
|
+
}
|
25
|
+
exports.createNodesV2 = [
|
26
|
+
reactRouterConfigBlob,
|
27
|
+
async (configFiles, options, context) => {
|
28
|
+
const optionsHash = (0, devkit_internals_1.hashObject)(options);
|
29
|
+
const normalizedOptions = normalizeOptions(options);
|
30
|
+
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `react-router-${optionsHash}.hash`);
|
31
|
+
const targetsCache = readTargetsCache(cachePath);
|
32
|
+
const isUsingTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
|
33
|
+
const { roots: projectRoots, configFiles: validConfigFiles } = configFiles.reduce((acc, configFile) => {
|
34
|
+
const potentialRoot = (0, path_1.dirname)(configFile);
|
35
|
+
if (checkIfConfigFileShouldBeProject(potentialRoot, context)) {
|
36
|
+
acc.roots.push(potentialRoot);
|
37
|
+
acc.configFiles.push(configFile);
|
38
|
+
}
|
39
|
+
return acc;
|
40
|
+
}, {
|
41
|
+
roots: [],
|
42
|
+
configFiles: [],
|
43
|
+
});
|
44
|
+
const lockfile = (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot));
|
45
|
+
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots, { ...normalizedOptions, isUsingTsSolutionSetup }, context, projectRoots.map((_) => [lockfile]));
|
46
|
+
try {
|
47
|
+
return await (0, devkit_1.createNodesFromFiles)(async (configFile, _, context, idx) => {
|
48
|
+
const projectRoot = (0, path_1.dirname)(configFile);
|
49
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, devkit_1.joinPathFragments)(context.workspaceRoot, projectRoot));
|
50
|
+
const hash = hashes[idx] + configFile;
|
51
|
+
const { projectType, metadata, targets } = (targetsCache[hash] ??=
|
52
|
+
await buildReactRouterTargets(configFile, projectRoot, normalizedOptions, context, siblingFiles, isUsingTsSolutionSetup));
|
53
|
+
const project = {
|
54
|
+
root: projectRoot,
|
55
|
+
targets,
|
56
|
+
metadata,
|
57
|
+
};
|
58
|
+
if (project.targets[normalizedOptions.buildTargetName]) {
|
59
|
+
project.projectType = projectType;
|
60
|
+
}
|
61
|
+
return {
|
62
|
+
projects: {
|
63
|
+
[projectRoot]: project,
|
64
|
+
},
|
65
|
+
};
|
66
|
+
}, validConfigFiles, options, context);
|
67
|
+
}
|
68
|
+
finally {
|
69
|
+
writeTargetsToCache(cachePath, targetsCache);
|
70
|
+
}
|
71
|
+
},
|
72
|
+
];
|
73
|
+
async function buildReactRouterTargets(configFilePath, projectRoot, options, context, siblingFiles, isUsingTsSolutionSetup) {
|
74
|
+
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
75
|
+
const configPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
|
76
|
+
if (require.cache[configPath])
|
77
|
+
(0, config_utils_1.clearRequireCache)();
|
78
|
+
const reactRouterConfig = await (0, config_utils_1.loadConfigFile)(configPath);
|
79
|
+
const isLibMode = reactRouterConfig?.ssr !== undefined && reactRouterConfig.ssr === false;
|
80
|
+
const { buildDirectory, serverBuildPath } = await getBuildPaths(reactRouterConfig, isLibMode);
|
81
|
+
const targets = {};
|
82
|
+
targets[options.buildTargetName] = await getBuildTargetConfig(options.buildTargetName, projectRoot, buildDirectory, serverBuildPath, namedInputs, isUsingTsSolutionSetup);
|
83
|
+
targets[options.devTargetName] = await devTarget(projectRoot, isUsingTsSolutionSetup);
|
84
|
+
if (serverBuildPath) {
|
85
|
+
targets[options.startTargetName] = await startTarget(projectRoot, serverBuildPath, options.buildTargetName, isUsingTsSolutionSetup);
|
86
|
+
}
|
87
|
+
targets[options.typecheckTargetName] = await typecheckTarget(projectRoot, options.typecheckTargetName, namedInputs, siblingFiles, isUsingTsSolutionSetup);
|
88
|
+
(0, util_1.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmCommand);
|
89
|
+
const metadata = {};
|
90
|
+
return {
|
91
|
+
targets,
|
92
|
+
metadata,
|
93
|
+
projectType: isLibMode ? 'library' : 'application',
|
94
|
+
};
|
95
|
+
}
|
96
|
+
async function getBuildTargetConfig(buildTargetName, projectRoot, buildDirectory, serverBuildDirectory, namedInputs, isUsingTsSolutionSetup) {
|
97
|
+
const basePath = projectRoot === '.'
|
98
|
+
? `{workspaceRoot}`
|
99
|
+
: (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, projectRoot);
|
100
|
+
const outputs = [
|
101
|
+
(0, devkit_1.joinPathFragments)(basePath, buildDirectory),
|
102
|
+
...(serverBuildDirectory
|
103
|
+
? [(0, devkit_1.joinPathFragments)(basePath, serverBuildDirectory)]
|
104
|
+
: []),
|
105
|
+
];
|
106
|
+
const buildTarget = {
|
107
|
+
cache: true,
|
108
|
+
dependsOn: [`^${buildTargetName}`],
|
109
|
+
inputs: [
|
110
|
+
...('production' in namedInputs
|
111
|
+
? ['production', '^production']
|
112
|
+
: ['default', '^default']),
|
113
|
+
{ externalDependencies: ['@react-router/dev'] },
|
114
|
+
],
|
115
|
+
outputs,
|
116
|
+
command: 'react-router build',
|
117
|
+
options: { cwd: projectRoot },
|
118
|
+
};
|
119
|
+
if (isUsingTsSolutionSetup) {
|
120
|
+
buildTarget.syncGenerators = ['@nx/js:typescript-sync'];
|
121
|
+
}
|
122
|
+
return buildTarget;
|
123
|
+
}
|
124
|
+
async function getBuildPaths(reactRouterConfig, isLibMode) {
|
125
|
+
return {
|
126
|
+
buildDirectory: reactRouterConfig?.buildDirectory ?? 'build/client',
|
127
|
+
...(isLibMode
|
128
|
+
? undefined
|
129
|
+
: {
|
130
|
+
serverBuildPath: reactRouterConfig?.buildDirectory
|
131
|
+
? (0, path_1.join)((0, path_1.dirname)(reactRouterConfig.buildDirectory), `server`)
|
132
|
+
: 'build/server',
|
133
|
+
}),
|
134
|
+
};
|
135
|
+
}
|
136
|
+
async function devTarget(projectRoot, isUsingTsSolutionSetup) {
|
137
|
+
const devTarget = {
|
138
|
+
command: 'react-router dev',
|
139
|
+
options: { cwd: projectRoot },
|
140
|
+
};
|
141
|
+
if (isUsingTsSolutionSetup) {
|
142
|
+
devTarget.syncGenerators = ['@nx/js:typescript-sync'];
|
143
|
+
}
|
144
|
+
return devTarget;
|
145
|
+
}
|
146
|
+
async function startTarget(projectRoot, serverBuildPath, buildTargetName, isUsingTsSolutionSetup) {
|
147
|
+
const serverPath = serverBuildPath === 'build/server'
|
148
|
+
? `${serverBuildPath}/index.js`
|
149
|
+
: serverBuildPath;
|
150
|
+
const startTarget = {
|
151
|
+
dependsOn: [buildTargetName],
|
152
|
+
command: `react-router-serve ${serverPath}`,
|
153
|
+
options: { cwd: projectRoot },
|
154
|
+
};
|
155
|
+
if (isUsingTsSolutionSetup) {
|
156
|
+
startTarget.syncGenerators = ['@nx/js:typescript-sync'];
|
157
|
+
}
|
158
|
+
return startTarget;
|
159
|
+
}
|
160
|
+
async function typecheckTarget(projectRoot, typecheckTargetName, namedInputs, siblingFiles, isUsingTsSolutionSetup) {
|
161
|
+
const hasTsConfigAppJson = siblingFiles.includes('tsconfig.app.json');
|
162
|
+
const typecheckTarget = {
|
163
|
+
cache: true,
|
164
|
+
inputs: [
|
165
|
+
...('production' in namedInputs
|
166
|
+
? ['production', '^production']
|
167
|
+
: ['default', '^default']),
|
168
|
+
{ externalDependencies: ['typescript'] },
|
169
|
+
],
|
170
|
+
command: isUsingTsSolutionSetup
|
171
|
+
? `tsc --build --emitDeclarationOnly`
|
172
|
+
: `tsc${hasTsConfigAppJson ? ` -p tsconfig.app.json` : ``} --noEmit`,
|
173
|
+
options: {
|
174
|
+
cwd: projectRoot,
|
175
|
+
},
|
176
|
+
metadata: {
|
177
|
+
description: `Runs type-checking for the project.`,
|
178
|
+
technologies: ['typescript'],
|
179
|
+
help: {
|
180
|
+
command: isUsingTsSolutionSetup
|
181
|
+
? `${pmCommand.exec} tsc --build --help`
|
182
|
+
: `${pmCommand.exec} tsc${hasTsConfigAppJson ? ` -p tsconfig.app.json` : ``} --help`,
|
183
|
+
example: isUsingTsSolutionSetup
|
184
|
+
? { args: ['--force'] }
|
185
|
+
: { options: { noEmit: true } },
|
186
|
+
},
|
187
|
+
},
|
188
|
+
};
|
189
|
+
if (isUsingTsSolutionSetup) {
|
190
|
+
typecheckTarget.dependsOn = [`^${typecheckTargetName}`];
|
191
|
+
typecheckTarget.syncGenerators = ['@nx/js:typescript-sync'];
|
192
|
+
}
|
193
|
+
return typecheckTarget;
|
194
|
+
}
|
195
|
+
function normalizeOptions(options) {
|
196
|
+
options ??= {};
|
197
|
+
options.buildTargetName ??= 'build';
|
198
|
+
options.devTargetName ??= 'dev';
|
199
|
+
options.startTargetName ??= 'start';
|
200
|
+
options.typecheckTargetName ??= 'typecheck';
|
201
|
+
return options;
|
202
|
+
}
|
203
|
+
function checkIfConfigFileShouldBeProject(projectRoot, context) {
|
204
|
+
// Do not create a project if package.json and project.json isn't there.
|
205
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
206
|
+
return hasRequiredConfigs(siblingFiles);
|
207
|
+
}
|
208
|
+
function hasRequiredConfigs(files) {
|
209
|
+
const lowerFiles = files.map((file) => file.toLowerCase());
|
210
|
+
// Check if vite.config.{ext} is present
|
211
|
+
const hasViteConfig = lowerFiles.some((file) => {
|
212
|
+
const parts = file.split('.');
|
213
|
+
return parts[0] === 'vite' && parts[1] === 'config' && parts.length > 2;
|
214
|
+
});
|
215
|
+
if (!hasViteConfig)
|
216
|
+
return false;
|
217
|
+
const hasProjectOrPackageJson = lowerFiles.includes('project.json') || lowerFiles.includes('package.json');
|
218
|
+
return hasProjectOrPackageJson;
|
219
|
+
}
|
package/src/utils/ast-utils.d.ts
CHANGED
@@ -11,7 +11,7 @@ export declare function findComponentImportPath(componentName: string, source: t
|
|
11
11
|
export declare function findElements(source: ts.SourceFile, tagName: string): ts.Node[];
|
12
12
|
export declare function findClosestOpening(tagName: string, node: ts.Node): ts.Node;
|
13
13
|
export declare function isTag(tagName: string, node: ts.Node): boolean;
|
14
|
-
export declare function addInitialRoutes(sourcePath: string, source: ts.SourceFile): StringChange[];
|
14
|
+
export declare function addInitialRoutes(sourcePath: string, source: ts.SourceFile, addBrowserRouter?: boolean): StringChange[];
|
15
15
|
export declare function addRoute(sourcePath: string, source: ts.SourceFile, options: {
|
16
16
|
routePath: string;
|
17
17
|
componentName: string;
|
package/src/utils/ast-utils.js
CHANGED
@@ -234,7 +234,7 @@ function isTag(tagName, node) {
|
|
234
234
|
}
|
235
235
|
return false;
|
236
236
|
}
|
237
|
-
function addInitialRoutes(sourcePath, source) {
|
237
|
+
function addInitialRoutes(sourcePath, source, addBrowserRouter) {
|
238
238
|
if (!tsModule) {
|
239
239
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
240
240
|
}
|
@@ -281,7 +281,7 @@ function addInitialRoutes(sourcePath, source) {
|
|
281
281
|
`,
|
282
282
|
};
|
283
283
|
return [
|
284
|
-
...addImport(source, `import { Route, Routes, Link } from 'react-router-dom';`),
|
284
|
+
...addImport(source, `import { Route, Routes, Link ${addBrowserRouter ? ', BrowserRouter ' : ''}} from 'react-router-dom';`),
|
285
285
|
insertRoutes,
|
286
286
|
];
|
287
287
|
}
|
package/src/utils/versions.d.ts
CHANGED
@@ -14,7 +14,7 @@ export declare const typesReactDomVersion = "19.0.0";
|
|
14
14
|
export declare const typesReactIsV18Version = "18.3.0";
|
15
15
|
export declare const typesReactIsVersion = "19.0.0";
|
16
16
|
export declare const reactViteVersion = "^4.2.0";
|
17
|
-
export declare const typesNodeVersion = "
|
17
|
+
export declare const typesNodeVersion = "^20.0.0";
|
18
18
|
export declare const babelPresetReactVersion = "^7.14.5";
|
19
19
|
export declare const babelCoreVersion = "^7.14.5";
|
20
20
|
export declare const styledComponentsVersion = "5.3.6";
|
@@ -24,6 +24,8 @@ export declare const emotionReactVersion = "11.11.1";
|
|
24
24
|
export declare const emotionBabelPlugin = "11.11.0";
|
25
25
|
export declare const styledJsxVersion = "5.1.2";
|
26
26
|
export declare const reactRouterDomVersion = "6.29.0";
|
27
|
+
export declare const reactRouterVersion = "^7.2.0";
|
28
|
+
export declare const reactRouterIsBotVersion = "^4.4.0";
|
27
29
|
export declare const testingLibraryReactVersion = "16.1.0";
|
28
30
|
export declare const testingLibraryDomVersion = "10.4.0";
|
29
31
|
export declare const reduxjsToolkitVersion = "1.9.3";
|
package/src/utils/versions.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
exports.swcPluginStyledComponentsVersion = exports.swcPluginEmotionVersion = exports.swcPluginStyledJsxVersion = void 0;
|
3
|
+
exports.sassVersion = exports.lessVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.tailwindcssVersion = exports.postcssVersion = exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryDomVersion = exports.testingLibraryReactVersion = exports.reactRouterIsBotVersion = exports.reactRouterVersion = exports.reactRouterDomVersion = exports.styledJsxVersion = exports.emotionBabelPlugin = exports.emotionReactVersion = exports.emotionStyledVersion = exports.typesStyledComponentsVersion = exports.styledComponentsVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactIsV18Version = exports.typesReactDomVersion = exports.typesReactDomV18Version = exports.typesReactVersion = exports.typesReactV18Version = exports.babelLoaderVersion = exports.swcLoaderVersion = exports.reactIsV18Version = exports.reactIsVersion = exports.reactDomV18Version = exports.reactDomVersion = exports.reactV18Version = exports.reactVersion = exports.nxVersion = void 0;
|
4
|
+
exports.swcPluginStyledComponentsVersion = exports.swcPluginEmotionVersion = exports.swcPluginStyledJsxVersion = exports.svgrRollupVersion = exports.rollupPluginUrlVersion = void 0;
|
5
5
|
exports.nxVersion = require('../../package.json').version;
|
6
6
|
exports.reactVersion = '19.0.0';
|
7
7
|
exports.reactV18Version = '18.3.1';
|
@@ -18,7 +18,8 @@ exports.typesReactDomVersion = '19.0.0';
|
|
18
18
|
exports.typesReactIsV18Version = '18.3.0';
|
19
19
|
exports.typesReactIsVersion = '19.0.0';
|
20
20
|
exports.reactViteVersion = '^4.2.0';
|
21
|
-
|
21
|
+
// Needed for React-Router
|
22
|
+
exports.typesNodeVersion = '^20.0.0';
|
22
23
|
exports.babelPresetReactVersion = '^7.14.5';
|
23
24
|
exports.babelCoreVersion = '^7.14.5';
|
24
25
|
exports.styledComponentsVersion = '5.3.6';
|
@@ -29,6 +30,8 @@ exports.emotionBabelPlugin = '11.11.0';
|
|
29
30
|
// WARNING: This needs to be in sync with Next.js' dependency or else there might be issues.
|
30
31
|
exports.styledJsxVersion = '5.1.2';
|
31
32
|
exports.reactRouterDomVersion = '6.29.0';
|
33
|
+
exports.reactRouterVersion = '^7.2.0';
|
34
|
+
exports.reactRouterIsBotVersion = '^4.4.0';
|
32
35
|
exports.testingLibraryReactVersion = '16.1.0';
|
33
36
|
exports.testingLibraryDomVersion = '10.4.0';
|
34
37
|
exports.reduxjsToolkitVersion = '1.9.3';
|