nx 20.5.0-beta.4 → 20.5.0-beta.5
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 +11 -11
- package/src/command-line/init/command-object.js +5 -0
- package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.js +6 -4
- package/src/command-line/init/implementation/react/index.d.ts +1 -1
- package/src/command-line/init/implementation/react/index.js +32 -185
- package/src/command-line/init/implementation/react/write-vite-config.js +19 -3
- package/src/command-line/init/implementation/utils.d.ts +1 -0
- package/src/command-line/init/implementation/utils.js +14 -0
- package/src/command-line/init/init-v2.d.ts +1 -0
- package/src/command-line/init/init-v2.js +25 -3
- package/src/command-line/release/config/config.js +1 -0
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/styles.js +1 -1
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/plugins/js/lock-file/yarn-parser.js +10 -10
- package/src/utils/find-matching-projects.js +2 -2
- package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
- package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nx",
|
3
|
-
"version": "20.5.0-beta.
|
3
|
+
"version": "20.5.0-beta.5",
|
4
4
|
"private": false,
|
5
5
|
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
|
6
6
|
"repository": {
|
@@ -82,16 +82,16 @@
|
|
82
82
|
}
|
83
83
|
},
|
84
84
|
"optionalDependencies": {
|
85
|
-
"@nx/nx-darwin-arm64": "20.5.0-beta.
|
86
|
-
"@nx/nx-darwin-x64": "20.5.0-beta.
|
87
|
-
"@nx/nx-freebsd-x64": "20.5.0-beta.
|
88
|
-
"@nx/nx-linux-arm-gnueabihf": "20.5.0-beta.
|
89
|
-
"@nx/nx-linux-arm64-gnu": "20.5.0-beta.
|
90
|
-
"@nx/nx-linux-arm64-musl": "20.5.0-beta.
|
91
|
-
"@nx/nx-linux-x64-gnu": "20.5.0-beta.
|
92
|
-
"@nx/nx-linux-x64-musl": "20.5.0-beta.
|
93
|
-
"@nx/nx-win32-arm64-msvc": "20.5.0-beta.
|
94
|
-
"@nx/nx-win32-x64-msvc": "20.5.0-beta.
|
85
|
+
"@nx/nx-darwin-arm64": "20.5.0-beta.5",
|
86
|
+
"@nx/nx-darwin-x64": "20.5.0-beta.5",
|
87
|
+
"@nx/nx-freebsd-x64": "20.5.0-beta.5",
|
88
|
+
"@nx/nx-linux-arm-gnueabihf": "20.5.0-beta.5",
|
89
|
+
"@nx/nx-linux-arm64-gnu": "20.5.0-beta.5",
|
90
|
+
"@nx/nx-linux-arm64-musl": "20.5.0-beta.5",
|
91
|
+
"@nx/nx-linux-x64-gnu": "20.5.0-beta.5",
|
92
|
+
"@nx/nx-linux-x64-musl": "20.5.0-beta.5",
|
93
|
+
"@nx/nx-win32-arm64-msvc": "20.5.0-beta.5",
|
94
|
+
"@nx/nx-win32-x64-msvc": "20.5.0-beta.5"
|
95
95
|
},
|
96
96
|
"nx-migrations": {
|
97
97
|
"migrations": "./migrations.json",
|
@@ -46,6 +46,11 @@ async function withInitOptions(yargs) {
|
|
46
46
|
type: 'boolean',
|
47
47
|
description: 'Initialize an Nx workspace setup in the .nx directory of the current repository.',
|
48
48
|
default: false,
|
49
|
+
})
|
50
|
+
.option('force', {
|
51
|
+
describe: 'Force the migration to continue and ignore custom webpack setup or uncommitted changes. Only for CRA projects.',
|
52
|
+
type: 'boolean',
|
53
|
+
default: false,
|
49
54
|
});
|
50
55
|
}
|
51
56
|
else {
|
@@ -9,10 +9,12 @@ function addViteCommandsToPackageScripts(appName, isStandalone) {
|
|
9
9
|
const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
|
10
10
|
packageJson.scripts = {
|
11
11
|
...packageJson.scripts,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
// These should be replaced by the vite init generator later.
|
13
|
+
start: 'vite',
|
14
|
+
test: 'vitest',
|
15
|
+
dev: 'vite',
|
16
|
+
build: 'vite build',
|
17
|
+
eject: undefined,
|
16
18
|
};
|
17
19
|
(0, fileutils_1.writeJsonFile)(packageJsonPath, packageJson, { spaces: 2 });
|
18
20
|
}
|
@@ -2,43 +2,52 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.addNxToCraRepo = addNxToCraRepo;
|
4
4
|
const child_process_1 = require("child_process");
|
5
|
-
const node_fs_1 = require("node:fs");
|
6
5
|
const path_1 = require("path");
|
6
|
+
const fs_1 = require("fs");
|
7
7
|
const fileutils_1 = require("../../../../utils/fileutils");
|
8
8
|
const output_1 = require("../../../../utils/output");
|
9
9
|
const package_manager_1 = require("../../../../utils/package-manager");
|
10
10
|
const check_for_custom_webpack_setup_1 = require("./check-for-custom-webpack-setup");
|
11
|
-
const check_for_uncommitted_changes_1 = require("./check-for-uncommitted-changes");
|
12
|
-
const clean_up_files_1 = require("./clean-up-files");
|
13
11
|
const read_name_from_package_json_1 = require("./read-name-from-package-json");
|
14
12
|
const rename_js_to_jsx_1 = require("./rename-js-to-jsx");
|
15
|
-
const tsconfig_setup_1 = require("./tsconfig-setup");
|
16
|
-
const write_craco_config_1 = require("./write-craco-config");
|
17
13
|
const write_vite_config_1 = require("./write-vite-config");
|
18
14
|
const write_vite_index_html_1 = require("./write-vite-index-html");
|
19
|
-
|
20
|
-
|
21
|
-
if (!options.force) {
|
22
|
-
(0, check_for_uncommitted_changes_1.checkForUncommittedChanges)();
|
15
|
+
async function addNxToCraRepo(_options) {
|
16
|
+
if (!_options.force) {
|
23
17
|
(0, check_for_custom_webpack_setup_1.checkForCustomWebpackSetup)();
|
24
18
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
const options = await normalizeOptions(_options);
|
20
|
+
await addBundler(options);
|
21
|
+
(0, fs_1.appendFileSync)(`.gitignore`, '\nnode_modules');
|
22
|
+
(0, fs_1.appendFileSync)(`.gitignore`, '\ndist');
|
23
|
+
installDependencies(options);
|
24
|
+
// Vite expects index.html to be in the root as the main entry point.
|
25
|
+
const indexPath = options.isStandalone
|
26
|
+
? 'index.html'
|
27
|
+
: (0, path_1.join)('apps', options.reactAppName, 'index.html');
|
28
|
+
const oldIndexPath = options.isStandalone
|
29
|
+
? (0, path_1.join)('public', 'index.html')
|
30
|
+
: (0, path_1.join)('apps', options.reactAppName, 'public', 'index.html');
|
31
|
+
output_1.output.note({
|
32
|
+
title: `A new ${indexPath} has been created. Compare it to the previous ${oldIndexPath} file and make any changes needed, then delete the previous file.`,
|
33
|
+
});
|
34
|
+
if (_options.force) {
|
35
|
+
output_1.output.note({
|
36
|
+
title: `Using --force converts projects with custom Webpack setup. You will need to manually update your vite.config.js file to match the plugins used in your old Webpack configuration.`,
|
37
|
+
});
|
38
|
+
}
|
28
39
|
}
|
29
40
|
function installDependencies(options) {
|
30
41
|
const dependencies = [
|
42
|
+
'@rollup/plugin-replace',
|
31
43
|
'@testing-library/jest-dom',
|
44
|
+
'@vitejs/plugin-react',
|
32
45
|
'eslint-config-react-app',
|
33
46
|
'web-vitals',
|
34
47
|
'jest-watch-typeahead',
|
48
|
+
'vite',
|
49
|
+
'vitest',
|
35
50
|
];
|
36
|
-
if (options.isVite) {
|
37
|
-
dependencies.push('vite', 'vitest', '@vitejs/plugin-react');
|
38
|
-
}
|
39
|
-
else {
|
40
|
-
dependencies.push('@craco/craco', 'cross-env', 'react-scripts', 'tsconfig-paths-webpack-plugin');
|
41
|
-
}
|
42
51
|
(0, child_process_1.execSync)(`${options.pmc.addDev} ${dependencies.join(' ')}`, {
|
43
52
|
stdio: [0, 1, 2],
|
44
53
|
windowsHide: false,
|
@@ -49,182 +58,20 @@ async function normalizeOptions(options) {
|
|
49
58
|
const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
|
50
59
|
const appIsJs = !(0, fileutils_1.fileExists)(`tsconfig.json`);
|
51
60
|
const reactAppName = (0, read_name_from_package_json_1.readNameFromPackageJson)();
|
52
|
-
const packageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(process.cwd(), 'package.json'));
|
53
|
-
const deps = {
|
54
|
-
...packageJson.dependencies,
|
55
|
-
...packageJson.devDependencies,
|
56
|
-
};
|
57
|
-
const isCRA5 = /^[^~]?5/.test(deps['react-scripts']);
|
58
|
-
const npmVersion = (0, child_process_1.execSync)('npm -v', {
|
59
|
-
windowsHide: false,
|
60
|
-
}).toString();
|
61
|
-
// Should remove this check 04/2023 once Node 14 & npm 6 reach EOL
|
62
|
-
const npxYesFlagNeeded = !npmVersion.startsWith('6'); // npm 7 added -y flag to npx
|
63
|
-
const isVite = options.vite;
|
64
61
|
const isStandalone = !options.integrated;
|
65
|
-
const nxCloud = options.nxCloud ??
|
66
|
-
(options.interactive ? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)() : false);
|
67
62
|
return {
|
68
63
|
...options,
|
69
|
-
nxCloud,
|
70
64
|
packageManager,
|
71
65
|
pmc,
|
72
66
|
appIsJs,
|
73
67
|
reactAppName,
|
74
|
-
isCRA5,
|
75
|
-
npxYesFlagNeeded,
|
76
|
-
isVite,
|
77
68
|
isStandalone,
|
78
69
|
};
|
79
70
|
}
|
80
|
-
/**
|
81
|
-
* - Create a temp workspace
|
82
|
-
* - Move all files to temp workspace
|
83
|
-
* - Add bundler to temp workspace
|
84
|
-
* - Move files back to root
|
85
|
-
* - Clean up unused files
|
86
|
-
*/
|
87
|
-
async function reorgnizeWorkspaceStructure(options) {
|
88
|
-
createTempWorkspace(options);
|
89
|
-
moveFilesToTempWorkspace(options);
|
90
|
-
await addBundler(options);
|
91
|
-
output_1.output.log({ title: '🧶 Updating .gitignore file' });
|
92
|
-
(0, child_process_1.execSync)(`echo "node_modules" >> .gitignore`, {
|
93
|
-
stdio: [0, 1, 2],
|
94
|
-
windowsHide: false,
|
95
|
-
});
|
96
|
-
(0, child_process_1.execSync)(`echo "dist" >> .gitignore`, {
|
97
|
-
stdio: [0, 1, 2],
|
98
|
-
windowsHide: false,
|
99
|
-
});
|
100
|
-
process.chdir('..');
|
101
|
-
copyFromTempWorkspaceToRoot();
|
102
|
-
cleanUpUnusedFilesAndAddConfigFiles(options);
|
103
|
-
output_1.output.log({ title: '🙂 Please be patient, one final step remaining!' });
|
104
|
-
output_1.output.log({ title: '📦 Installing dependencies' });
|
105
|
-
installDependencies(options);
|
106
|
-
if (options.isVite) {
|
107
|
-
const indexPath = options.isStandalone
|
108
|
-
? 'index.html'
|
109
|
-
: (0, path_1.join)('apps', options.reactAppName, 'index.html');
|
110
|
-
const oldIndexPath = options.isStandalone
|
111
|
-
? (0, path_1.join)('public', 'index.html')
|
112
|
-
: (0, path_1.join)('apps', options.reactAppName, 'public', 'index.html');
|
113
|
-
output_1.output.note({
|
114
|
-
title: `A new ${indexPath} has been created. Compare it to the previous ${oldIndexPath} file and make any changes needed, then delete the previous file.`,
|
115
|
-
});
|
116
|
-
}
|
117
|
-
}
|
118
|
-
function createTempWorkspace(options) {
|
119
|
-
(0, node_fs_1.rmSync)('temp-workspace', { recursive: true, force: true });
|
120
|
-
(0, child_process_1.execSync)(`npx ${options.npxYesFlagNeeded ? '-y' : ''} create-nx-workspace@latest temp-workspace --appName=${options.reactAppName} --preset=react-monorepo --style=css --bundler=${options.isVite ? 'vite' : 'webpack'} --packageManager=${options.packageManager} ${options.nxCloud ? '--nxCloud=yes' : '--nxCloud=skip'} ${options.addE2e ? '--e2eTestRunner=playwright' : '--e2eTestRunner=none'}`, { stdio: [0, 1, 2], windowsHide: false });
|
121
|
-
output_1.output.log({ title: '👋 Welcome to Nx!' });
|
122
|
-
output_1.output.log({ title: '🧹 Clearing unused files' });
|
123
|
-
(0, node_fs_1.cpSync)((0, path_1.join)('temp-workspace', 'apps', options.reactAppName, 'project.json'), 'project.json', { recursive: true });
|
124
|
-
(0, node_fs_1.rmSync)((0, path_1.join)('temp-workspace', 'apps', options.reactAppName), {
|
125
|
-
recursive: true,
|
126
|
-
force: true,
|
127
|
-
});
|
128
|
-
(0, node_fs_1.rmSync)('node_modules', { recursive: true, force: true });
|
129
|
-
}
|
130
|
-
function copyPackageJsonDepsFromTempWorkspace() {
|
131
|
-
const repoRoot = process.cwd();
|
132
|
-
let rootPackageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(repoRoot, 'package.json'));
|
133
|
-
const tempWorkspacePackageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(repoRoot, 'temp-workspace', 'package.json'));
|
134
|
-
rootPackageJson = overridePackageDeps('dependencies', rootPackageJson, tempWorkspacePackageJson);
|
135
|
-
rootPackageJson = overridePackageDeps('devDependencies', rootPackageJson, tempWorkspacePackageJson);
|
136
|
-
rootPackageJson.scripts = {}; // remove existing scripts
|
137
|
-
(0, fileutils_1.writeJsonFile)((0, path_1.join)(repoRoot, 'package.json'), rootPackageJson);
|
138
|
-
(0, fileutils_1.writeJsonFile)((0, path_1.join)(repoRoot, 'temp-workspace', 'package.json'), rootPackageJson);
|
139
|
-
}
|
140
|
-
function overridePackageDeps(depConfigName, base, override) {
|
141
|
-
if (!base[depConfigName]) {
|
142
|
-
base[depConfigName] = override[depConfigName];
|
143
|
-
return base;
|
144
|
-
}
|
145
|
-
const deps = override[depConfigName];
|
146
|
-
Object.keys(deps).forEach((dep) => {
|
147
|
-
if (base.dependencies?.[dep]) {
|
148
|
-
delete base.dependencies[dep];
|
149
|
-
}
|
150
|
-
if (base.devDependencies?.[dep]) {
|
151
|
-
delete base.devDependencies[dep];
|
152
|
-
}
|
153
|
-
base[depConfigName][dep] = deps[dep];
|
154
|
-
});
|
155
|
-
return base;
|
156
|
-
}
|
157
|
-
function moveSync(src, dest) {
|
158
|
-
const destParentDir = (0, path_1.dirname)(dest);
|
159
|
-
(0, node_fs_1.mkdirSync)(destParentDir, { recursive: true });
|
160
|
-
(0, node_fs_1.rmSync)(dest, { recursive: true, force: true });
|
161
|
-
return (0, node_fs_1.renameSync)(src, dest);
|
162
|
-
}
|
163
|
-
function moveFilesToTempWorkspace(options) {
|
164
|
-
output_1.output.log({ title: '🚚 Moving your React app in your new Nx workspace' });
|
165
|
-
copyPackageJsonDepsFromTempWorkspace();
|
166
|
-
const requiredCraFiles = [
|
167
|
-
'project.json',
|
168
|
-
'package.json',
|
169
|
-
'src',
|
170
|
-
'public',
|
171
|
-
options.appIsJs ? null : 'tsconfig.json',
|
172
|
-
options.packageManager === 'yarn' ? 'yarn.lock' : null,
|
173
|
-
options.packageManager === 'pnpm' ? 'pnpm-lock.yaml' : null,
|
174
|
-
options.packageManager === 'npm' ? 'package-lock.json' : null,
|
175
|
-
options.packageManager === 'bun' ? 'bun.lockb' : null,
|
176
|
-
];
|
177
|
-
const optionalCraFiles = ['README.md'];
|
178
|
-
const filesToMove = [...requiredCraFiles, ...optionalCraFiles].filter(Boolean);
|
179
|
-
filesToMove.forEach((f) => {
|
180
|
-
try {
|
181
|
-
moveSync(f, options.isStandalone
|
182
|
-
? (0, path_1.join)('temp-workspace', f)
|
183
|
-
: (0, path_1.join)('temp-workspace', 'apps', options.reactAppName, f));
|
184
|
-
}
|
185
|
-
catch (error) {
|
186
|
-
if (requiredCraFiles.includes(f)) {
|
187
|
-
throw error;
|
188
|
-
}
|
189
|
-
}
|
190
|
-
});
|
191
|
-
process.chdir('temp-workspace');
|
192
|
-
}
|
193
71
|
async function addBundler(options) {
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
(0, write_vite_index_html_1.writeViteIndexHtml)(options.reactAppName, options.isStandalone, options.appIsJs);
|
200
|
-
await (0, rename_js_to_jsx_1.renameJsToJsx)(options.reactAppName, options.isStandalone);
|
201
|
-
}
|
202
|
-
else {
|
203
|
-
output_1.output.log({ title: '🧑🔧 Setting up craco + Webpack' });
|
204
|
-
const { addCracoCommandsToPackageScripts } = await Promise.resolve().then(() => require('./add-craco-commands-to-package-scripts'));
|
205
|
-
addCracoCommandsToPackageScripts(options.reactAppName, options.isStandalone);
|
206
|
-
(0, write_craco_config_1.writeCracoConfig)(options.reactAppName, options.isCRA5, options.isStandalone);
|
207
|
-
output_1.output.log({
|
208
|
-
title: '🛬 Skip CRA preflight check since Nx manages the monorepo',
|
209
|
-
});
|
210
|
-
(0, child_process_1.execSync)(`echo "SKIP_PREFLIGHT_CHECK=true" > .env`, {
|
211
|
-
stdio: [0, 1, 2],
|
212
|
-
windowsHide: false,
|
213
|
-
});
|
214
|
-
}
|
215
|
-
}
|
216
|
-
function copyFromTempWorkspaceToRoot() {
|
217
|
-
output_1.output.log({ title: '🚚 Folder restructuring.' });
|
218
|
-
(0, node_fs_1.readdirSync)('temp-workspace').forEach((f) => {
|
219
|
-
moveSync((0, path_1.join)('temp-workspace', f), f);
|
220
|
-
});
|
221
|
-
}
|
222
|
-
function cleanUpUnusedFilesAndAddConfigFiles(options) {
|
223
|
-
output_1.output.log({ title: '🧹 Cleaning up.' });
|
224
|
-
(0, clean_up_files_1.cleanUpFiles)(options.reactAppName, options.isStandalone);
|
225
|
-
output_1.output.log({ title: "📃 Extend the app's tsconfig.json from the base" });
|
226
|
-
(0, tsconfig_setup_1.setupTsConfig)(options.reactAppName, options.isStandalone);
|
227
|
-
if (options.isStandalone) {
|
228
|
-
(0, node_fs_1.rmSync)('apps', { recursive: true, force: true });
|
229
|
-
}
|
72
|
+
const { addViteCommandsToPackageScripts } = await Promise.resolve().then(() => require('./add-vite-commands-to-package-scripts'));
|
73
|
+
addViteCommandsToPackageScripts(options.reactAppName, options.isStandalone);
|
74
|
+
(0, write_vite_config_1.writeViteConfig)(options.reactAppName, options.isStandalone, options.appIsJs);
|
75
|
+
(0, write_vite_index_html_1.writeViteIndexHtml)(options.reactAppName, options.isStandalone, options.appIsJs);
|
76
|
+
await (0, rename_js_to_jsx_1.renameJsToJsx)(options.reactAppName, options.isStandalone);
|
230
77
|
}
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.writeViteConfig = writeViteConfig;
|
4
4
|
const fs_1 = require("fs");
|
5
5
|
function writeViteConfig(appName, isStandalone, isJs) {
|
6
|
-
let port =
|
6
|
+
let port = 3000;
|
7
7
|
// Use PORT from .env file if it exists in project.
|
8
8
|
if ((0, fs_1.existsSync)(`../.env`)) {
|
9
9
|
const envFile = (0, fs_1.readFileSync)(`../.env`).toString();
|
@@ -13,8 +13,20 @@ function writeViteConfig(appName, isStandalone, isJs) {
|
|
13
13
|
port = portCandidate;
|
14
14
|
}
|
15
15
|
}
|
16
|
-
(0, fs_1.writeFileSync)(isStandalone ? 'vite.config.
|
16
|
+
(0, fs_1.writeFileSync)(isStandalone ? 'vite.config.mjs' : `apps/${appName}/vite.config.mjs`, `import { defineConfig } from 'vite'
|
17
17
|
import react from '@vitejs/plugin-react'
|
18
|
+
import replace from '@rollup/plugin-replace';
|
19
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
20
|
+
|
21
|
+
// Match CRA's environment variables.
|
22
|
+
// TODO: Replace these with VITE_ prefixed environment variables, and using import.meta.env.VITE_* instead of process.env.REACT_APP_*.
|
23
|
+
const craEnvVarRegex = /^REACT_APP/i;
|
24
|
+
const craEnvVars = Object.keys(process.env)
|
25
|
+
.filter((key) => craEnvVarRegex.test(key))
|
26
|
+
.reduce((env, key) => {
|
27
|
+
env[\`process.env.\${key}\`] = JSON.stringify(process.env[key]);
|
28
|
+
return env;
|
29
|
+
}, {});
|
18
30
|
|
19
31
|
// https://vitejs.dev/config/
|
20
32
|
export default defineConfig({
|
@@ -31,7 +43,11 @@ export default defineConfig({
|
|
31
43
|
setupFiles: 'src/setupTests.${isJs ? 'js' : 'ts'}',
|
32
44
|
css: true,
|
33
45
|
},
|
34
|
-
plugins: [
|
46
|
+
plugins: [
|
47
|
+
react(),
|
48
|
+
replace({ values: craEnvVars, preventAssignment: true }),
|
49
|
+
nxViteTsPaths(),
|
50
|
+
],
|
35
51
|
});
|
36
52
|
`);
|
37
53
|
}
|
@@ -11,6 +11,7 @@ exports.markRootPackageJsonAsNxProjectLegacy = markRootPackageJsonAsNxProjectLeg
|
|
11
11
|
exports.markPackageJsonAsNxProject = markPackageJsonAsNxProject;
|
12
12
|
exports.printFinalMessage = printFinalMessage;
|
13
13
|
exports.isMonorepo = isMonorepo;
|
14
|
+
exports.isCRA = isCRA;
|
14
15
|
const child_process_1 = require("child_process");
|
15
16
|
const path_1 = require("path");
|
16
17
|
const fileutils_1 = require("../../../utils/fileutils");
|
@@ -266,3 +267,16 @@ function isMonorepo(packageJson) {
|
|
266
267
|
return true;
|
267
268
|
return false;
|
268
269
|
}
|
270
|
+
function isCRA(packageJson) {
|
271
|
+
const combinedDependencies = {
|
272
|
+
...packageJson.dependencies,
|
273
|
+
...packageJson.devDependencies,
|
274
|
+
};
|
275
|
+
return (
|
276
|
+
// Required dependencies for CRA projects
|
277
|
+
combinedDependencies['react'] &&
|
278
|
+
combinedDependencies['react-dom'] &&
|
279
|
+
combinedDependencies['react-scripts'] &&
|
280
|
+
(0, fileutils_1.directoryExists)('src') &&
|
281
|
+
(0, fileutils_1.directoryExists)('public'));
|
282
|
+
}
|
@@ -5,6 +5,7 @@ export interface InitArgs {
|
|
5
5
|
useDotNxInstallation?: boolean;
|
6
6
|
integrated?: boolean;
|
7
7
|
verbose?: boolean;
|
8
|
+
force?: boolean;
|
8
9
|
}
|
9
10
|
export declare function initHandler(options: InitArgs): Promise<void>;
|
10
11
|
export declare function detectPlugins(nxJson: NxJsonConfiguration, interactive: boolean, includeAngularCli?: boolean): Promise<{
|
@@ -21,6 +21,7 @@ const add_nx_to_turborepo_1 = require("./implementation/add-nx-to-turborepo");
|
|
21
21
|
const angular_1 = require("./implementation/angular");
|
22
22
|
const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
|
23
23
|
const utils_1 = require("./implementation/utils");
|
24
|
+
const react_1 = require("./implementation/react");
|
24
25
|
async function initHandler(options) {
|
25
26
|
process.env.NX_RUNNING_NX_INIT = 'true';
|
26
27
|
const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ? 'next' : 'latest');
|
@@ -60,6 +61,7 @@ async function initHandler(options) {
|
|
60
61
|
const packageJson = (0, fileutils_1.readJsonFile)('package.json');
|
61
62
|
const _isTurborepo = (0, fs_1.existsSync)('turbo.json');
|
62
63
|
const _isMonorepo = (0, utils_1.isMonorepo)(packageJson);
|
64
|
+
const _isCRA = (0, utils_1.isCRA)(packageJson);
|
63
65
|
const learnMoreLink = _isTurborepo
|
64
66
|
? 'https://nx.dev/recipes/adopting-nx/from-turborepo'
|
65
67
|
: _isMonorepo
|
@@ -80,7 +82,18 @@ async function initHandler(options) {
|
|
80
82
|
});
|
81
83
|
return;
|
82
84
|
}
|
83
|
-
|
85
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
86
|
+
if (_isCRA) {
|
87
|
+
await (0, react_1.addNxToCraRepo)({
|
88
|
+
addE2e: false,
|
89
|
+
force: options.force,
|
90
|
+
vite: true,
|
91
|
+
integrated: false,
|
92
|
+
interactive: options.interactive,
|
93
|
+
nxCloud: false,
|
94
|
+
});
|
95
|
+
}
|
96
|
+
else if (_isMonorepo) {
|
84
97
|
await (0, add_nx_to_monorepo_1.addNxToMonorepo)({
|
85
98
|
interactive: options.interactive,
|
86
99
|
nxCloud: false,
|
@@ -95,12 +108,21 @@ async function initHandler(options) {
|
|
95
108
|
const useNxCloud = options.nxCloud ??
|
96
109
|
(options.interactive ? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)() : false);
|
97
110
|
const repoRoot = process.cwd();
|
98
|
-
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
99
111
|
(0, utils_1.createNxJsonFile)(repoRoot, [], [], {});
|
100
112
|
(0, utils_1.updateGitIgnore)(repoRoot);
|
101
113
|
const nxJson = (0, nx_json_1.readNxJson)(repoRoot);
|
102
114
|
output_1.output.log({ title: '🧐 Checking dependencies' });
|
103
|
-
|
115
|
+
let plugins;
|
116
|
+
let updatePackageScripts;
|
117
|
+
if (_isCRA) {
|
118
|
+
plugins = ['@nx/vite'];
|
119
|
+
updatePackageScripts = true;
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
const { plugins: _plugins, updatePackageScripts: _updatePackageScripts } = await detectPlugins(nxJson, options.interactive);
|
123
|
+
plugins = _plugins;
|
124
|
+
updatePackageScripts = _updatePackageScripts;
|
125
|
+
}
|
104
126
|
output_1.output.log({ title: '📦 Installing Nx' });
|
105
127
|
(0, configure_plugins_1.runPackageManagerInstallPlugins)(repoRoot, pmc, plugins);
|
106
128
|
await (0, configure_plugins_1.configurePlugins)(plugins, updatePackageScripts, pmc, repoRoot, options.verbose);
|
@@ -598,6 +598,7 @@ async function handleNxReleaseConfigError(error) {
|
|
598
598
|
title: `There was an error when resolving the configured changelog renderer at path: ${error.data.workspaceRelativePath}`,
|
599
599
|
bodyLines: [nxJsonMessage],
|
600
600
|
});
|
601
|
+
break;
|
601
602
|
}
|
602
603
|
case 'INVALID_CHANGELOG_CREATE_RELEASE_PROVIDER':
|
603
604
|
{
|