react-native-windows-init 1.4.4 → 1.4.6
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/lib-commonjs/Cli.d.ts +80 -80
- package/lib-commonjs/Cli.js +459 -459
- package/lib-commonjs/GenerateWindowsType.d.ts +9 -9
- package/lib-commonjs/GenerateWindowsType.js +8 -8
- package/lib-commonjs/e2etest/cli.test.d.ts +7 -7
- package/lib-commonjs/e2etest/cli.test.js +68 -68
- package/lib-commonjs/requireGenerateWindows.d.ts +12 -12
- package/lib-commonjs/requireGenerateWindows.js +28 -28
- package/package.json +11 -11
package/lib-commonjs/Cli.js
CHANGED
|
@@ -1,468 +1,468 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*
|
|
6
|
-
* @format
|
|
7
|
-
*/
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
var _a;
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.reactNativeWindowsInit = exports.windowsInitOptions = void 0;
|
|
14
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
15
|
-
const fs_1 = __importDefault(require("@react-native-windows/fs"));
|
|
16
|
-
const semver_1 = __importDefault(require("semver"));
|
|
17
|
-
const child_process_1 = require("child_process");
|
|
18
|
-
const valid_url_1 = __importDefault(require("valid-url"));
|
|
19
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
20
|
-
const find_up_1 = __importDefault(require("find-up"));
|
|
21
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
22
|
-
const npm_registry_fetch_1 = __importDefault(require("npm-registry-fetch"));
|
|
23
|
-
const telemetry_1 = require("@react-native-windows/telemetry");
|
|
24
|
-
/**
|
|
25
|
-
* Important:
|
|
26
|
-
* Do not use process.exit() in this script as it will prevent telemetry from being sent.
|
|
27
|
-
* See https://github.com/microsoft/ApplicationInsights-node.js/issues/580
|
|
28
|
-
*/
|
|
29
|
-
const requireGenerateWindows_1 = __importDefault(require("./requireGenerateWindows"));
|
|
30
|
-
let NPM_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
31
|
-
try {
|
|
32
|
-
const npmConfReg = (0, child_process_1.execSync)('npm config get registry').toString().trim();
|
|
33
|
-
if (valid_url_1.default.isUri(npmConfReg)) {
|
|
34
|
-
NPM_REGISTRY_URL = npmConfReg;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
// Ignore workspace errors as `npm config` does not support it
|
|
39
|
-
const stderr = ((_a = error === null || error === void 0 ? void 0 : error.stderr) === null || _a === void 0 ? void 0 : _a.toString()) || '';
|
|
40
|
-
if (!stderr.includes('ENOWORKSPACES')) {
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// Causes the type-checker to ensure the options object is a valid yargs options object
|
|
45
|
-
function initOptions(options) {
|
|
46
|
-
return options;
|
|
47
|
-
}
|
|
48
|
-
exports.windowsInitOptions = initOptions({
|
|
49
|
-
version: {
|
|
50
|
-
type: 'string',
|
|
51
|
-
describe: 'The version of react-native-windows to use.',
|
|
52
|
-
},
|
|
53
|
-
namespace: {
|
|
54
|
-
type: 'string',
|
|
55
|
-
describe: "The native project namespace. This should be expressed using dots as separators. i.e. 'Level1.Level2.Level3'. The generator will apply the correct syntax for the target language",
|
|
56
|
-
},
|
|
57
|
-
verbose: {
|
|
58
|
-
type: 'boolean',
|
|
59
|
-
describe: 'Enables logging.',
|
|
60
|
-
default: false,
|
|
61
|
-
},
|
|
62
|
-
telemetry: {
|
|
63
|
-
type: 'boolean',
|
|
64
|
-
describe: 'Controls sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',
|
|
65
|
-
default: true,
|
|
66
|
-
},
|
|
67
|
-
language: {
|
|
68
|
-
type: 'string',
|
|
69
|
-
describe: 'The language the project is written in.',
|
|
70
|
-
choices: ['cs', 'cpp'],
|
|
71
|
-
default: 'cpp',
|
|
72
|
-
},
|
|
73
|
-
overwrite: {
|
|
74
|
-
type: 'boolean',
|
|
75
|
-
describe: 'Overwrite any existing files without prompting',
|
|
76
|
-
default: false,
|
|
77
|
-
},
|
|
78
|
-
projectType: {
|
|
79
|
-
type: 'string',
|
|
80
|
-
describe: 'The type of project to initialize (supported on 0.64+)',
|
|
81
|
-
choices: ['app', 'lib'],
|
|
82
|
-
default: 'app',
|
|
83
|
-
},
|
|
84
|
-
experimentalNuGetDependency: {
|
|
85
|
-
type: 'boolean',
|
|
86
|
-
describe: '[Experimental] change to start consuming a NuGet containing a pre-built dll version of Microsoft.ReactNative',
|
|
87
|
-
hidden: true,
|
|
88
|
-
default: false,
|
|
89
|
-
},
|
|
90
|
-
useHermes: {
|
|
91
|
-
type: 'boolean',
|
|
92
|
-
describe: '[Experimental] Use Hermes instead of Chakra as the JS engine (supported on 0.64+ for C++ projects)',
|
|
93
|
-
default: false,
|
|
94
|
-
},
|
|
95
|
-
useWinUI3: {
|
|
96
|
-
type: 'boolean',
|
|
97
|
-
describe: '[Experimental] Use WinUI 3 (Windows App SDK)',
|
|
98
|
-
hidden: true,
|
|
99
|
-
default: false,
|
|
100
|
-
},
|
|
101
|
-
nuGetTestVersion: {
|
|
102
|
-
type: 'string',
|
|
103
|
-
describe: '[internalTesting] By default the NuGet version matches the rnw package. This flag allows manually specifying the version for internal testing.',
|
|
104
|
-
hidden: true,
|
|
105
|
-
},
|
|
106
|
-
nuGetTestFeed: {
|
|
107
|
-
type: 'string',
|
|
108
|
-
describe: '[internalTesting] Allows a test feed to be added to the generated NuGet configuration',
|
|
109
|
-
hidden: true,
|
|
110
|
-
},
|
|
111
|
-
useDevMode: {
|
|
112
|
-
type: 'boolean',
|
|
113
|
-
describe: '[internalTesting] Link rather than Add/Install the react-native-windows package. This option is for the development workflow of the developers working on react-native-windows.',
|
|
114
|
-
hidden: true,
|
|
115
|
-
default: undefined,
|
|
116
|
-
conflicts: 'version',
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
const yargsParser = yargs_1.default
|
|
120
|
-
.version(false)
|
|
121
|
-
.options(exports.windowsInitOptions)
|
|
122
|
-
.strict(true);
|
|
123
|
-
function getReactNativeProjectName() {
|
|
124
|
-
console.log('Reading project name from package.json...');
|
|
125
|
-
const cwd = process.cwd();
|
|
126
|
-
const pkgJsonPath = find_up_1.default.sync('package.json', { cwd });
|
|
127
|
-
if (!pkgJsonPath) {
|
|
128
|
-
throw new telemetry_1.CodedError('NoPackageJson', 'Unable to find package.json. This should be run from within an existing react-native project.');
|
|
129
|
-
}
|
|
130
|
-
let name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
|
|
131
|
-
if (!name) {
|
|
132
|
-
const appJsonPath = find_up_1.default.sync('app.json', { cwd });
|
|
133
|
-
if (appJsonPath) {
|
|
134
|
-
console.log('Reading project name from app.json...');
|
|
135
|
-
name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (!name) {
|
|
139
|
-
console.error('Please specify name in package.json or app.json');
|
|
140
|
-
}
|
|
141
|
-
return name;
|
|
142
|
-
}
|
|
143
|
-
function getReactNativeVersion() {
|
|
144
|
-
console.log('Reading react-native version from node_modules...');
|
|
145
|
-
const rnPkgJsonPath = require.resolve('react-native/package.json', {
|
|
146
|
-
paths: [process.cwd()],
|
|
147
|
-
});
|
|
148
|
-
if (fs_1.default.existsSync(rnPkgJsonPath)) {
|
|
149
|
-
return require(rnPkgJsonPath).version;
|
|
150
|
-
}
|
|
151
|
-
throw new telemetry_1.CodedError('NoReactNativeFound', 'Must be run from a project that already depends on react-native, and has react-native installed.');
|
|
152
|
-
}
|
|
153
|
-
function getDefaultReactNativeWindowsSemVerForReactNativeVersion(rnVersion) {
|
|
154
|
-
const validVersion = semver_1.default.valid(rnVersion);
|
|
155
|
-
if (validVersion) {
|
|
156
|
-
const major = semver_1.default.major(validVersion);
|
|
157
|
-
const minor = semver_1.default.minor(validVersion);
|
|
158
|
-
if (major === 0 && minor >= 59) {
|
|
159
|
-
return `^${major}.${minor}.0-0`;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
throw new telemetry_1.CodedError('UnsupportedReactNativeVersion', `Error: Unsupported version of react-native: ${chalk_1.default.cyan(rnVersion)} react-native-windows supports react-native versions ${chalk_1.default.cyan('>=0.60')}`);
|
|
163
|
-
}
|
|
164
|
-
function getMatchingReactNativeSemVerForReactNativeWindowsVersion(rnwVersion) {
|
|
165
|
-
const validVersion = semver_1.default.valid(rnwVersion);
|
|
166
|
-
if (validVersion) {
|
|
167
|
-
const major = semver_1.default.major(validVersion);
|
|
168
|
-
const minor = semver_1.default.minor(validVersion);
|
|
169
|
-
if (major === 0 && minor >= 59) {
|
|
170
|
-
return `^${major}.${minor}`;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return 'unknown';
|
|
174
|
-
}
|
|
175
|
-
async function getLatestMatchingVersion(pkg, versionSemVer) {
|
|
176
|
-
const npmResponse = await npm_registry_fetch_1.default.json(pkg, { registry: NPM_REGISTRY_URL });
|
|
177
|
-
// Check if versionSemVer is a tag (i.e. 'canary', 'latest', 'preview', etc.)
|
|
178
|
-
if ('dist-tags' in npmResponse) {
|
|
179
|
-
const distTags = npmResponse['dist-tags'];
|
|
180
|
-
if (versionSemVer in distTags) {
|
|
181
|
-
return distTags[versionSemVer];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Check if versionSemVer is a semver version (i.e. '^0.60.0-0', '0.63.1', etc.)
|
|
185
|
-
if ('versions' in npmResponse) {
|
|
186
|
-
const versions = Object.keys(npmResponse.versions);
|
|
187
|
-
if (versions.length > 0) {
|
|
188
|
-
const candidates = versions
|
|
189
|
-
.filter(v => semver_1.default.satisfies(v, versionSemVer))
|
|
190
|
-
.sort(semver_1.default.rcompare);
|
|
191
|
-
if (candidates.length > 0) {
|
|
192
|
-
return candidates[0];
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
throw new telemetry_1.CodedError('NoMatchingPackageVersion', `No matching version of ${pkg}@${versionSemVer} found`);
|
|
197
|
-
}
|
|
198
|
-
async function getLatestRNWVersion() {
|
|
199
|
-
const rnwLatestVersion = await getLatestMatchingRNWVersion('latest');
|
|
200
|
-
if (!rnwLatestVersion) {
|
|
201
|
-
throw new telemetry_1.CodedError('NoLatestReactNativeWindows', 'Error: No version of react-native-windows@latest found');
|
|
202
|
-
}
|
|
203
|
-
return rnwLatestVersion;
|
|
204
|
-
}
|
|
205
|
-
async function getLatestMatchingRNWVersion(versionSemVer) {
|
|
206
|
-
try {
|
|
207
|
-
const version = await getLatestMatchingVersion('react-native-windows', versionSemVer);
|
|
208
|
-
return version;
|
|
209
|
-
}
|
|
210
|
-
catch (err) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function installReactNativeWindows(version, verbose, useDevMode) {
|
|
215
|
-
const cwd = process.cwd();
|
|
216
|
-
const execOptions = verbose ? { stdio: 'inherit' } : {};
|
|
217
|
-
if (useDevMode) {
|
|
218
|
-
const packageCmd = isProjectUsingYarn(cwd) ? 'yarn' : 'npm';
|
|
219
|
-
(0, child_process_1.execSync)(`${packageCmd} link react-native-windows`, execOptions);
|
|
220
|
-
version = '*';
|
|
221
|
-
}
|
|
222
|
-
else if (!version) {
|
|
223
|
-
throw new telemetry_1.CodedError('Unknown', 'Unexpected error encountered. If you are able, please file an issue on: https://github.com/microsoft/react-native-windows/issues/new/choose');
|
|
224
|
-
}
|
|
225
|
-
console.log(`Installing ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(version)}...`);
|
|
226
|
-
const pkgJsonPath = find_up_1.default.sync('package.json', { cwd });
|
|
227
|
-
if (!pkgJsonPath) {
|
|
228
|
-
throw new telemetry_1.CodedError('NoPackageJson', 'Unable to find package.json');
|
|
229
|
-
}
|
|
230
|
-
const pkgJson = require(pkgJsonPath);
|
|
231
|
-
// check how react-native is installed
|
|
232
|
-
if ('dependencies' in pkgJson && 'react-native' in pkgJson.dependencies) {
|
|
233
|
-
// regular dependency (probably an app), inject into json and run install
|
|
234
|
-
pkgJson.dependencies['react-native-windows'] = version;
|
|
235
|
-
fs_1.default.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
236
|
-
(0, child_process_1.execSync)(isProjectUsingYarn(cwd) ? 'yarn' : 'npm install', execOptions);
|
|
237
|
-
}
|
|
238
|
-
else if ('devDependencies' in pkgJson &&
|
|
239
|
-
'react-native' in pkgJson.devDependencies) {
|
|
240
|
-
// only a dev dependency (probably a native module),
|
|
241
|
-
(0, child_process_1.execSync)(isProjectUsingYarn(cwd)
|
|
242
|
-
? `yarn add react-native-windows@${version} --dev`
|
|
243
|
-
: `npm install react-native-windows@${version} --save-dev`, execOptions);
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
throw new telemetry_1.CodedError('NoReactNativeDependencies', "Unable to find 'react-native' in package.json's dependencies or devDependencies. This should be run from within an existing react-native app or lib.");
|
|
247
|
-
}
|
|
248
|
-
console.log(chalk_1.default.green(`react-native-windows@${chalk_1.default.cyan(require(require.resolve('react-native-windows/package.json', {
|
|
249
|
-
paths: [cwd],
|
|
250
|
-
})).version)} successfully installed.`));
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Sanitizes the given option for telemetry.
|
|
254
|
-
* @param key The key of the option.
|
|
255
|
-
* @param value The unsanitized value of the option.
|
|
256
|
-
* @returns The sanitized value of the option.
|
|
257
|
-
*/
|
|
258
|
-
function optionSanitizer(key, value) {
|
|
259
|
-
// Do not add a default case here.
|
|
260
|
-
// Strings risking PII should just return true if present, false otherwise.
|
|
261
|
-
// All others should return the value (or false if undefined).
|
|
262
|
-
switch (key) {
|
|
263
|
-
case 'namespace':
|
|
264
|
-
case 'nuGetTestFeed':
|
|
265
|
-
case 'nuGetTestVersion':
|
|
266
|
-
return value ? true : false;
|
|
267
|
-
case 'verbose':
|
|
268
|
-
case 'version':
|
|
269
|
-
case 'telemetry':
|
|
270
|
-
case 'language':
|
|
271
|
-
case 'overwrite':
|
|
272
|
-
case 'projectType':
|
|
273
|
-
case 'experimentalNuGetDependency':
|
|
274
|
-
case 'useHermes':
|
|
275
|
-
case 'useWinUI3':
|
|
276
|
-
case 'useDevMode':
|
|
277
|
-
return value === undefined ? false : value;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Sets up and starts the telemetry gathering for the CLI command.
|
|
282
|
-
* @param args The raw CLI args.
|
|
283
|
-
* @param options The CLI args parsed by yargs.
|
|
284
|
-
*/
|
|
285
|
-
async function startTelemetrySession(args, options) {
|
|
286
|
-
const verbose = options.verbose === true;
|
|
287
|
-
if (!options.telemetry) {
|
|
288
|
-
if (verbose) {
|
|
289
|
-
console.log('Telemetry is disabled');
|
|
290
|
-
}
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
if (verbose) {
|
|
294
|
-
console.log(`Running ${(0, telemetry_1.nodeArchitecture)()} node on a ${(0, telemetry_1.deviceArchitecture)()} machine`);
|
|
295
|
-
}
|
|
296
|
-
if ((0, telemetry_1.deviceArchitecture)() !== (0, telemetry_1.nodeArchitecture)()) {
|
|
297
|
-
console.warn('This version of node was built for a different architecture than this machine and may cause unintended behavior');
|
|
298
|
-
}
|
|
299
|
-
// Setup telemetry, but don't get NPM package version info right away as
|
|
300
|
-
// we're going to change things and this may interfere with the resolver
|
|
301
|
-
await telemetry_1.Telemetry.setup({ populateNpmPackageVersions: false });
|
|
302
|
-
const sanitizedOptions = (0, telemetry_1.yargsOptionsToOptions)(options, optionSanitizer);
|
|
303
|
-
const sanitizedDefaultOptions = (0, telemetry_1.yargsOptionsToOptions)(yargsParser.parse(''), optionSanitizer);
|
|
304
|
-
const sanitizedArgs = (0, telemetry_1.optionsToArgs)(sanitizedOptions, args);
|
|
305
|
-
const startInfo = {
|
|
306
|
-
commandName: 'react-native-windows-init',
|
|
307
|
-
args: sanitizedArgs,
|
|
308
|
-
options: sanitizedOptions,
|
|
309
|
-
defaultOptions: sanitizedDefaultOptions,
|
|
310
|
-
};
|
|
311
|
-
telemetry_1.Telemetry.startCommand(startInfo);
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Adds the new project's telemetry info by calling and processing `react-native config`.
|
|
315
|
-
*/
|
|
316
|
-
async function addProjectInfoToTelemetry() {
|
|
317
|
-
if (!telemetry_1.Telemetry.isEnabled()) {
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
try {
|
|
321
|
-
const config = JSON.parse((0, child_process_1.execSync)('npx react-native config', {
|
|
322
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
323
|
-
}).toString());
|
|
324
|
-
const projectInfo = await (0, telemetry_1.configToProjectInfo)(config);
|
|
325
|
-
if (projectInfo) {
|
|
326
|
-
telemetry_1.Telemetry.setProjectInfo(projectInfo);
|
|
327
|
-
}
|
|
328
|
-
const projectFile = (0, telemetry_1.getProjectFileFromConfig)(config);
|
|
329
|
-
if (projectFile) {
|
|
330
|
-
await telemetry_1.Telemetry.populateNuGetPackageVersions(projectFile);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
catch (_a) { }
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Ends the gathering of telemetry for the CLI command.
|
|
337
|
-
* @param error The error (if any) thrown during the command.
|
|
338
|
-
*/
|
|
339
|
-
function endTelemetrySession(error) {
|
|
340
|
-
const endInfo = {
|
|
341
|
-
resultCode: 'Success',
|
|
342
|
-
};
|
|
343
|
-
if (error) {
|
|
344
|
-
endInfo.resultCode =
|
|
345
|
-
error instanceof telemetry_1.CodedError ? error.type : 'Unknown';
|
|
346
|
-
}
|
|
347
|
-
telemetry_1.Telemetry.endCommand(endInfo);
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Sets the process exit code and offers some information at the end of a CLI command.
|
|
351
|
-
* @param loggingIsEnabled Is verbose logging enabled.
|
|
352
|
-
* @param error The error caught during the process, if any.
|
|
353
|
-
*/
|
|
354
|
-
function setExitProcessWithError(loggingIsEnabled, error) {
|
|
355
|
-
if (error) {
|
|
356
|
-
const errorType = error instanceof telemetry_1.CodedError ? error.type : 'Unknown';
|
|
357
|
-
process.exitCode = telemetry_1.CodedErrors[errorType];
|
|
358
|
-
if (loggingIsEnabled) {
|
|
359
|
-
console.log(`Command failed with error ${chalk_1.default.bold(errorType)}: ${error.message}`);
|
|
360
|
-
if (telemetry_1.Telemetry.isEnabled()) {
|
|
361
|
-
console.log(`Your telemetry sessionId was ${chalk_1.default.bold(telemetry_1.Telemetry.getSessionId())}`);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
console.log(`Command failed. Re-run the command with ${chalk_1.default.bold('--verbose')} for more information.`);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Check if project is using Yarn (has `yarn.lock` in the tree)
|
|
371
|
-
*/
|
|
372
|
-
function isProjectUsingYarn(cwd) {
|
|
373
|
-
return !!find_up_1.default.sync('yarn.lock', { cwd });
|
|
374
|
-
}
|
|
375
|
-
async function reactNativeWindowsInit(args) {
|
|
376
|
-
args = args !== null && args !== void 0 ? args : process.argv;
|
|
377
|
-
const options = yargsParser.parse(args);
|
|
378
|
-
if (options.verbose) {
|
|
379
|
-
console.log(options);
|
|
380
|
-
}
|
|
381
|
-
await startTelemetrySession(args, options);
|
|
382
|
-
let initWindowsError;
|
|
383
|
-
try {
|
|
384
|
-
const name = getReactNativeProjectName();
|
|
385
|
-
const ns = options.namespace || name;
|
|
386
|
-
const useDevMode = !!options.useDevMode; // TS assumes the type is undefined
|
|
387
|
-
let version = options.version;
|
|
388
|
-
if (options.useWinUI3 && options.experimentalNuGetDependency) {
|
|
389
|
-
throw new telemetry_1.CodedError('IncompatibleOptions', "Error: Incompatible options specified. Options '--useWinUI3' and '--experimentalNuGetDependency' are incompatible", { detail: 'useWinUI3 and experimentalNuGetDependency' });
|
|
390
|
-
}
|
|
391
|
-
if (!useDevMode) {
|
|
392
|
-
if (!version) {
|
|
393
|
-
const rnVersion = getReactNativeVersion();
|
|
394
|
-
version =
|
|
395
|
-
getDefaultReactNativeWindowsSemVerForReactNativeVersion(rnVersion);
|
|
396
|
-
}
|
|
397
|
-
const rnwResolvedVersion = await getLatestMatchingRNWVersion(version);
|
|
398
|
-
if (!rnwResolvedVersion) {
|
|
399
|
-
if (options.version) {
|
|
400
|
-
console.warn(`Warning: Querying npm to find react-native-windows@${options.version} failed. Attempting to continue anyway...`);
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
const rnwLatestVersion = await getLatestRNWVersion();
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
var _a;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.reactNativeWindowsInit = exports.windowsInitOptions = void 0;
|
|
14
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
15
|
+
const fs_1 = __importDefault(require("@react-native-windows/fs"));
|
|
16
|
+
const semver_1 = __importDefault(require("semver"));
|
|
17
|
+
const child_process_1 = require("child_process");
|
|
18
|
+
const valid_url_1 = __importDefault(require("valid-url"));
|
|
19
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
20
|
+
const find_up_1 = __importDefault(require("find-up"));
|
|
21
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
22
|
+
const npm_registry_fetch_1 = __importDefault(require("npm-registry-fetch"));
|
|
23
|
+
const telemetry_1 = require("@react-native-windows/telemetry");
|
|
24
|
+
/**
|
|
25
|
+
* Important:
|
|
26
|
+
* Do not use process.exit() in this script as it will prevent telemetry from being sent.
|
|
27
|
+
* See https://github.com/microsoft/ApplicationInsights-node.js/issues/580
|
|
28
|
+
*/
|
|
29
|
+
const requireGenerateWindows_1 = __importDefault(require("./requireGenerateWindows"));
|
|
30
|
+
let NPM_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
31
|
+
try {
|
|
32
|
+
const npmConfReg = (0, child_process_1.execSync)('npm config get registry').toString().trim();
|
|
33
|
+
if (valid_url_1.default.isUri(npmConfReg)) {
|
|
34
|
+
NPM_REGISTRY_URL = npmConfReg;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
// Ignore workspace errors as `npm config` does not support it
|
|
39
|
+
const stderr = ((_a = error === null || error === void 0 ? void 0 : error.stderr) === null || _a === void 0 ? void 0 : _a.toString()) || '';
|
|
40
|
+
if (!stderr.includes('ENOWORKSPACES')) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Causes the type-checker to ensure the options object is a valid yargs options object
|
|
45
|
+
function initOptions(options) {
|
|
46
|
+
return options;
|
|
47
|
+
}
|
|
48
|
+
exports.windowsInitOptions = initOptions({
|
|
49
|
+
version: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
describe: 'The version of react-native-windows to use.',
|
|
52
|
+
},
|
|
53
|
+
namespace: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
describe: "The native project namespace. This should be expressed using dots as separators. i.e. 'Level1.Level2.Level3'. The generator will apply the correct syntax for the target language",
|
|
56
|
+
},
|
|
57
|
+
verbose: {
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
describe: 'Enables logging.',
|
|
60
|
+
default: false,
|
|
61
|
+
},
|
|
62
|
+
telemetry: {
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
describe: 'Controls sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',
|
|
65
|
+
default: true,
|
|
66
|
+
},
|
|
67
|
+
language: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
describe: 'The language the project is written in.',
|
|
70
|
+
choices: ['cs', 'cpp'],
|
|
71
|
+
default: 'cpp',
|
|
72
|
+
},
|
|
73
|
+
overwrite: {
|
|
74
|
+
type: 'boolean',
|
|
75
|
+
describe: 'Overwrite any existing files without prompting',
|
|
76
|
+
default: false,
|
|
77
|
+
},
|
|
78
|
+
projectType: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
describe: 'The type of project to initialize (supported on 0.64+)',
|
|
81
|
+
choices: ['app', 'lib'],
|
|
82
|
+
default: 'app',
|
|
83
|
+
},
|
|
84
|
+
experimentalNuGetDependency: {
|
|
85
|
+
type: 'boolean',
|
|
86
|
+
describe: '[Experimental] change to start consuming a NuGet containing a pre-built dll version of Microsoft.ReactNative',
|
|
87
|
+
hidden: true,
|
|
88
|
+
default: false,
|
|
89
|
+
},
|
|
90
|
+
useHermes: {
|
|
91
|
+
type: 'boolean',
|
|
92
|
+
describe: '[Experimental] Use Hermes instead of Chakra as the JS engine (supported on 0.64+ for C++ projects)',
|
|
93
|
+
default: false,
|
|
94
|
+
},
|
|
95
|
+
useWinUI3: {
|
|
96
|
+
type: 'boolean',
|
|
97
|
+
describe: '[Experimental] Use WinUI 3 (Windows App SDK)',
|
|
98
|
+
hidden: true,
|
|
99
|
+
default: false,
|
|
100
|
+
},
|
|
101
|
+
nuGetTestVersion: {
|
|
102
|
+
type: 'string',
|
|
103
|
+
describe: '[internalTesting] By default the NuGet version matches the rnw package. This flag allows manually specifying the version for internal testing.',
|
|
104
|
+
hidden: true,
|
|
105
|
+
},
|
|
106
|
+
nuGetTestFeed: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
describe: '[internalTesting] Allows a test feed to be added to the generated NuGet configuration',
|
|
109
|
+
hidden: true,
|
|
110
|
+
},
|
|
111
|
+
useDevMode: {
|
|
112
|
+
type: 'boolean',
|
|
113
|
+
describe: '[internalTesting] Link rather than Add/Install the react-native-windows package. This option is for the development workflow of the developers working on react-native-windows.',
|
|
114
|
+
hidden: true,
|
|
115
|
+
default: undefined,
|
|
116
|
+
conflicts: 'version',
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const yargsParser = yargs_1.default
|
|
120
|
+
.version(false)
|
|
121
|
+
.options(exports.windowsInitOptions)
|
|
122
|
+
.strict(true);
|
|
123
|
+
function getReactNativeProjectName() {
|
|
124
|
+
console.log('Reading project name from package.json...');
|
|
125
|
+
const cwd = process.cwd();
|
|
126
|
+
const pkgJsonPath = find_up_1.default.sync('package.json', { cwd });
|
|
127
|
+
if (!pkgJsonPath) {
|
|
128
|
+
throw new telemetry_1.CodedError('NoPackageJson', 'Unable to find package.json. This should be run from within an existing react-native project.');
|
|
129
|
+
}
|
|
130
|
+
let name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
|
|
131
|
+
if (!name) {
|
|
132
|
+
const appJsonPath = find_up_1.default.sync('app.json', { cwd });
|
|
133
|
+
if (appJsonPath) {
|
|
134
|
+
console.log('Reading project name from app.json...');
|
|
135
|
+
name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!name) {
|
|
139
|
+
console.error('Please specify name in package.json or app.json');
|
|
140
|
+
}
|
|
141
|
+
return name;
|
|
142
|
+
}
|
|
143
|
+
function getReactNativeVersion() {
|
|
144
|
+
console.log('Reading react-native version from node_modules...');
|
|
145
|
+
const rnPkgJsonPath = require.resolve('react-native/package.json', {
|
|
146
|
+
paths: [process.cwd()],
|
|
147
|
+
});
|
|
148
|
+
if (fs_1.default.existsSync(rnPkgJsonPath)) {
|
|
149
|
+
return require(rnPkgJsonPath).version;
|
|
150
|
+
}
|
|
151
|
+
throw new telemetry_1.CodedError('NoReactNativeFound', 'Must be run from a project that already depends on react-native, and has react-native installed.');
|
|
152
|
+
}
|
|
153
|
+
function getDefaultReactNativeWindowsSemVerForReactNativeVersion(rnVersion) {
|
|
154
|
+
const validVersion = semver_1.default.valid(rnVersion);
|
|
155
|
+
if (validVersion) {
|
|
156
|
+
const major = semver_1.default.major(validVersion);
|
|
157
|
+
const minor = semver_1.default.minor(validVersion);
|
|
158
|
+
if (major === 0 && minor >= 59) {
|
|
159
|
+
return `^${major}.${minor}.0-0`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
throw new telemetry_1.CodedError('UnsupportedReactNativeVersion', `Error: Unsupported version of react-native: ${chalk_1.default.cyan(rnVersion)} react-native-windows supports react-native versions ${chalk_1.default.cyan('>=0.60')}`);
|
|
163
|
+
}
|
|
164
|
+
function getMatchingReactNativeSemVerForReactNativeWindowsVersion(rnwVersion) {
|
|
165
|
+
const validVersion = semver_1.default.valid(rnwVersion);
|
|
166
|
+
if (validVersion) {
|
|
167
|
+
const major = semver_1.default.major(validVersion);
|
|
168
|
+
const minor = semver_1.default.minor(validVersion);
|
|
169
|
+
if (major === 0 && minor >= 59) {
|
|
170
|
+
return `^${major}.${minor}`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return 'unknown';
|
|
174
|
+
}
|
|
175
|
+
async function getLatestMatchingVersion(pkg, versionSemVer) {
|
|
176
|
+
const npmResponse = await npm_registry_fetch_1.default.json(pkg, { registry: NPM_REGISTRY_URL });
|
|
177
|
+
// Check if versionSemVer is a tag (i.e. 'canary', 'latest', 'preview', etc.)
|
|
178
|
+
if ('dist-tags' in npmResponse) {
|
|
179
|
+
const distTags = npmResponse['dist-tags'];
|
|
180
|
+
if (versionSemVer in distTags) {
|
|
181
|
+
return distTags[versionSemVer];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Check if versionSemVer is a semver version (i.e. '^0.60.0-0', '0.63.1', etc.)
|
|
185
|
+
if ('versions' in npmResponse) {
|
|
186
|
+
const versions = Object.keys(npmResponse.versions);
|
|
187
|
+
if (versions.length > 0) {
|
|
188
|
+
const candidates = versions
|
|
189
|
+
.filter(v => semver_1.default.satisfies(v, versionSemVer))
|
|
190
|
+
.sort(semver_1.default.rcompare);
|
|
191
|
+
if (candidates.length > 0) {
|
|
192
|
+
return candidates[0];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
throw new telemetry_1.CodedError('NoMatchingPackageVersion', `No matching version of ${pkg}@${versionSemVer} found`);
|
|
197
|
+
}
|
|
198
|
+
async function getLatestRNWVersion() {
|
|
199
|
+
const rnwLatestVersion = await getLatestMatchingRNWVersion('latest');
|
|
200
|
+
if (!rnwLatestVersion) {
|
|
201
|
+
throw new telemetry_1.CodedError('NoLatestReactNativeWindows', 'Error: No version of react-native-windows@latest found');
|
|
202
|
+
}
|
|
203
|
+
return rnwLatestVersion;
|
|
204
|
+
}
|
|
205
|
+
async function getLatestMatchingRNWVersion(versionSemVer) {
|
|
206
|
+
try {
|
|
207
|
+
const version = await getLatestMatchingVersion('react-native-windows', versionSemVer);
|
|
208
|
+
return version;
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function installReactNativeWindows(version, verbose, useDevMode) {
|
|
215
|
+
const cwd = process.cwd();
|
|
216
|
+
const execOptions = verbose ? { stdio: 'inherit' } : {};
|
|
217
|
+
if (useDevMode) {
|
|
218
|
+
const packageCmd = isProjectUsingYarn(cwd) ? 'yarn' : 'npm';
|
|
219
|
+
(0, child_process_1.execSync)(`${packageCmd} link react-native-windows`, execOptions);
|
|
220
|
+
version = '*';
|
|
221
|
+
}
|
|
222
|
+
else if (!version) {
|
|
223
|
+
throw new telemetry_1.CodedError('Unknown', 'Unexpected error encountered. If you are able, please file an issue on: https://github.com/microsoft/react-native-windows/issues/new/choose');
|
|
224
|
+
}
|
|
225
|
+
console.log(`Installing ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(version)}...`);
|
|
226
|
+
const pkgJsonPath = find_up_1.default.sync('package.json', { cwd });
|
|
227
|
+
if (!pkgJsonPath) {
|
|
228
|
+
throw new telemetry_1.CodedError('NoPackageJson', 'Unable to find package.json');
|
|
229
|
+
}
|
|
230
|
+
const pkgJson = require(pkgJsonPath);
|
|
231
|
+
// check how react-native is installed
|
|
232
|
+
if ('dependencies' in pkgJson && 'react-native' in pkgJson.dependencies) {
|
|
233
|
+
// regular dependency (probably an app), inject into json and run install
|
|
234
|
+
pkgJson.dependencies['react-native-windows'] = version;
|
|
235
|
+
fs_1.default.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
236
|
+
(0, child_process_1.execSync)(isProjectUsingYarn(cwd) ? 'yarn' : 'npm install', execOptions);
|
|
237
|
+
}
|
|
238
|
+
else if ('devDependencies' in pkgJson &&
|
|
239
|
+
'react-native' in pkgJson.devDependencies) {
|
|
240
|
+
// only a dev dependency (probably a native module),
|
|
241
|
+
(0, child_process_1.execSync)(isProjectUsingYarn(cwd)
|
|
242
|
+
? `yarn add react-native-windows@${version} --dev`
|
|
243
|
+
: `npm install react-native-windows@${version} --save-dev`, execOptions);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
throw new telemetry_1.CodedError('NoReactNativeDependencies', "Unable to find 'react-native' in package.json's dependencies or devDependencies. This should be run from within an existing react-native app or lib.");
|
|
247
|
+
}
|
|
248
|
+
console.log(chalk_1.default.green(`react-native-windows@${chalk_1.default.cyan(require(require.resolve('react-native-windows/package.json', {
|
|
249
|
+
paths: [cwd],
|
|
250
|
+
})).version)} successfully installed.`));
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Sanitizes the given option for telemetry.
|
|
254
|
+
* @param key The key of the option.
|
|
255
|
+
* @param value The unsanitized value of the option.
|
|
256
|
+
* @returns The sanitized value of the option.
|
|
257
|
+
*/
|
|
258
|
+
function optionSanitizer(key, value) {
|
|
259
|
+
// Do not add a default case here.
|
|
260
|
+
// Strings risking PII should just return true if present, false otherwise.
|
|
261
|
+
// All others should return the value (or false if undefined).
|
|
262
|
+
switch (key) {
|
|
263
|
+
case 'namespace':
|
|
264
|
+
case 'nuGetTestFeed':
|
|
265
|
+
case 'nuGetTestVersion':
|
|
266
|
+
return value ? true : false;
|
|
267
|
+
case 'verbose':
|
|
268
|
+
case 'version':
|
|
269
|
+
case 'telemetry':
|
|
270
|
+
case 'language':
|
|
271
|
+
case 'overwrite':
|
|
272
|
+
case 'projectType':
|
|
273
|
+
case 'experimentalNuGetDependency':
|
|
274
|
+
case 'useHermes':
|
|
275
|
+
case 'useWinUI3':
|
|
276
|
+
case 'useDevMode':
|
|
277
|
+
return value === undefined ? false : value;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Sets up and starts the telemetry gathering for the CLI command.
|
|
282
|
+
* @param args The raw CLI args.
|
|
283
|
+
* @param options The CLI args parsed by yargs.
|
|
284
|
+
*/
|
|
285
|
+
async function startTelemetrySession(args, options) {
|
|
286
|
+
const verbose = options.verbose === true;
|
|
287
|
+
if (!options.telemetry) {
|
|
288
|
+
if (verbose) {
|
|
289
|
+
console.log('Telemetry is disabled');
|
|
290
|
+
}
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (verbose) {
|
|
294
|
+
console.log(`Running ${(0, telemetry_1.nodeArchitecture)()} node on a ${(0, telemetry_1.deviceArchitecture)()} machine`);
|
|
295
|
+
}
|
|
296
|
+
if ((0, telemetry_1.deviceArchitecture)() !== (0, telemetry_1.nodeArchitecture)()) {
|
|
297
|
+
console.warn('This version of node was built for a different architecture than this machine and may cause unintended behavior');
|
|
298
|
+
}
|
|
299
|
+
// Setup telemetry, but don't get NPM package version info right away as
|
|
300
|
+
// we're going to change things and this may interfere with the resolver
|
|
301
|
+
await telemetry_1.Telemetry.setup({ populateNpmPackageVersions: false });
|
|
302
|
+
const sanitizedOptions = (0, telemetry_1.yargsOptionsToOptions)(options, optionSanitizer);
|
|
303
|
+
const sanitizedDefaultOptions = (0, telemetry_1.yargsOptionsToOptions)(yargsParser.parse(''), optionSanitizer);
|
|
304
|
+
const sanitizedArgs = (0, telemetry_1.optionsToArgs)(sanitizedOptions, args);
|
|
305
|
+
const startInfo = {
|
|
306
|
+
commandName: 'react-native-windows-init',
|
|
307
|
+
args: sanitizedArgs,
|
|
308
|
+
options: sanitizedOptions,
|
|
309
|
+
defaultOptions: sanitizedDefaultOptions,
|
|
310
|
+
};
|
|
311
|
+
telemetry_1.Telemetry.startCommand(startInfo);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Adds the new project's telemetry info by calling and processing `react-native config`.
|
|
315
|
+
*/
|
|
316
|
+
async function addProjectInfoToTelemetry() {
|
|
317
|
+
if (!telemetry_1.Telemetry.isEnabled()) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const config = JSON.parse((0, child_process_1.execSync)('npx react-native config', {
|
|
322
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
323
|
+
}).toString());
|
|
324
|
+
const projectInfo = await (0, telemetry_1.configToProjectInfo)(config);
|
|
325
|
+
if (projectInfo) {
|
|
326
|
+
telemetry_1.Telemetry.setProjectInfo(projectInfo);
|
|
327
|
+
}
|
|
328
|
+
const projectFile = (0, telemetry_1.getProjectFileFromConfig)(config);
|
|
329
|
+
if (projectFile) {
|
|
330
|
+
await telemetry_1.Telemetry.populateNuGetPackageVersions(projectFile);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
catch (_a) { }
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Ends the gathering of telemetry for the CLI command.
|
|
337
|
+
* @param error The error (if any) thrown during the command.
|
|
338
|
+
*/
|
|
339
|
+
function endTelemetrySession(error) {
|
|
340
|
+
const endInfo = {
|
|
341
|
+
resultCode: 'Success',
|
|
342
|
+
};
|
|
343
|
+
if (error) {
|
|
344
|
+
endInfo.resultCode =
|
|
345
|
+
error instanceof telemetry_1.CodedError ? error.type : 'Unknown';
|
|
346
|
+
}
|
|
347
|
+
telemetry_1.Telemetry.endCommand(endInfo);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Sets the process exit code and offers some information at the end of a CLI command.
|
|
351
|
+
* @param loggingIsEnabled Is verbose logging enabled.
|
|
352
|
+
* @param error The error caught during the process, if any.
|
|
353
|
+
*/
|
|
354
|
+
function setExitProcessWithError(loggingIsEnabled, error) {
|
|
355
|
+
if (error) {
|
|
356
|
+
const errorType = error instanceof telemetry_1.CodedError ? error.type : 'Unknown';
|
|
357
|
+
process.exitCode = telemetry_1.CodedErrors[errorType];
|
|
358
|
+
if (loggingIsEnabled) {
|
|
359
|
+
console.log(`Command failed with error ${chalk_1.default.bold(errorType)}: ${error.message}`);
|
|
360
|
+
if (telemetry_1.Telemetry.isEnabled()) {
|
|
361
|
+
console.log(`Your telemetry sessionId was ${chalk_1.default.bold(telemetry_1.Telemetry.getSessionId())}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
console.log(`Command failed. Re-run the command with ${chalk_1.default.bold('--verbose')} for more information.`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Check if project is using Yarn (has `yarn.lock` in the tree)
|
|
371
|
+
*/
|
|
372
|
+
function isProjectUsingYarn(cwd) {
|
|
373
|
+
return !!find_up_1.default.sync('yarn.lock', { cwd });
|
|
374
|
+
}
|
|
375
|
+
async function reactNativeWindowsInit(args) {
|
|
376
|
+
args = args !== null && args !== void 0 ? args : process.argv;
|
|
377
|
+
const options = yargsParser.parse(args);
|
|
378
|
+
if (options.verbose) {
|
|
379
|
+
console.log(options);
|
|
380
|
+
}
|
|
381
|
+
await startTelemetrySession(args, options);
|
|
382
|
+
let initWindowsError;
|
|
383
|
+
try {
|
|
384
|
+
const name = getReactNativeProjectName();
|
|
385
|
+
const ns = options.namespace || name;
|
|
386
|
+
const useDevMode = !!options.useDevMode; // TS assumes the type is undefined
|
|
387
|
+
let version = options.version;
|
|
388
|
+
if (options.useWinUI3 && options.experimentalNuGetDependency) {
|
|
389
|
+
throw new telemetry_1.CodedError('IncompatibleOptions', "Error: Incompatible options specified. Options '--useWinUI3' and '--experimentalNuGetDependency' are incompatible", { detail: 'useWinUI3 and experimentalNuGetDependency' });
|
|
390
|
+
}
|
|
391
|
+
if (!useDevMode) {
|
|
392
|
+
if (!version) {
|
|
393
|
+
const rnVersion = getReactNativeVersion();
|
|
394
|
+
version =
|
|
395
|
+
getDefaultReactNativeWindowsSemVerForReactNativeVersion(rnVersion);
|
|
396
|
+
}
|
|
397
|
+
const rnwResolvedVersion = await getLatestMatchingRNWVersion(version);
|
|
398
|
+
if (!rnwResolvedVersion) {
|
|
399
|
+
if (options.version) {
|
|
400
|
+
console.warn(`Warning: Querying npm to find react-native-windows@${options.version} failed. Attempting to continue anyway...`);
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
const rnwLatestVersion = await getLatestRNWVersion();
|
|
404
404
|
throw new telemetry_1.CodedError('NoAutoMatchingReactNativeWindows', `
|
|
405
405
|
No compatible version of ${chalk_1.default.green('react-native-windows')} found.
|
|
406
406
|
The latest supported version is ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwLatestVersion)}.
|
|
407
407
|
Please modify your application to use ${chalk_1.default.green('react-native')}@${chalk_1.default.cyan(getMatchingReactNativeSemVerForReactNativeWindowsVersion(rnwLatestVersion))} or another supported version of ${chalk_1.default.green('react-native')} and try again.
|
|
408
|
-
`, { rnwLatestVersion: rnwLatestVersion });
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
if (!options.version) {
|
|
412
|
-
console.log(`Latest matching version of ${chalk_1.default.bold('react-native-windows')} for ${chalk_1.default.green('react-native')}@${chalk_1.default.cyan(getReactNativeVersion())} is ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwResolvedVersion)}`);
|
|
413
|
-
if (rnwResolvedVersion && semver_1.default.prerelease(rnwResolvedVersion)) {
|
|
414
|
-
const rnwLatestVersion = await getLatestRNWVersion();
|
|
408
|
+
`, { rnwLatestVersion: rnwLatestVersion });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (!options.version) {
|
|
412
|
+
console.log(`Latest matching version of ${chalk_1.default.bold('react-native-windows')} for ${chalk_1.default.green('react-native')}@${chalk_1.default.cyan(getReactNativeVersion())} is ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwResolvedVersion)}`);
|
|
413
|
+
if (rnwResolvedVersion && semver_1.default.prerelease(rnwResolvedVersion)) {
|
|
414
|
+
const rnwLatestVersion = await getLatestRNWVersion();
|
|
415
415
|
console.warn(`
|
|
416
416
|
${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwResolvedVersion)} is a ${chalk_1.default.yellow('pre-release')} version.
|
|
417
417
|
The latest supported version is ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwLatestVersion)}.
|
|
418
418
|
You can either downgrade your version of ${chalk_1.default.green('react-native')} to ${chalk_1.default.cyan(getMatchingReactNativeSemVerForReactNativeWindowsVersion(rnwLatestVersion))}, or continue with a ${chalk_1.default.yellow('pre-release')} version of ${chalk_1.default.bold('react-native-windows')}.
|
|
419
|
-
`);
|
|
420
|
-
const confirm = (await (0, prompts_1.default)({
|
|
421
|
-
type: 'confirm',
|
|
422
|
-
name: 'confirm',
|
|
423
|
-
message: `Do you wish to continue with ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwResolvedVersion)}?`,
|
|
424
|
-
})).confirm;
|
|
425
|
-
if (!confirm) {
|
|
426
|
-
throw new telemetry_1.CodedError('UserCancel', 'User canceled');
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
if (rnwResolvedVersion) {
|
|
431
|
-
version = rnwResolvedVersion;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
installReactNativeWindows(version, options.verbose, useDevMode);
|
|
435
|
-
const generateWindows = (0, requireGenerateWindows_1.default)();
|
|
436
|
-
// Now that new NPM packages have been installed, get their versions
|
|
437
|
-
await telemetry_1.Telemetry.populateNpmPackageVersions();
|
|
438
|
-
await generateWindows(process.cwd(), name, ns, {
|
|
439
|
-
language: options.language,
|
|
440
|
-
overwrite: options.overwrite,
|
|
441
|
-
verbose: options.verbose,
|
|
442
|
-
projectType: options.projectType,
|
|
443
|
-
experimentalNuGetDependency: options.experimentalNuGetDependency,
|
|
444
|
-
useWinUI3: options.useWinUI3,
|
|
445
|
-
useHermes: options.useHermes,
|
|
446
|
-
useDevMode: useDevMode,
|
|
447
|
-
nuGetTestVersion: options.nuGetTestVersion,
|
|
448
|
-
nuGetTestFeed: options.nuGetTestFeed,
|
|
449
|
-
telemetry: options.telemetry,
|
|
450
|
-
});
|
|
451
|
-
// Now that the project has been generated, add project info
|
|
452
|
-
await addProjectInfoToTelemetry();
|
|
453
|
-
}
|
|
454
|
-
catch (ex) {
|
|
455
|
-
// Since we may have failed before generating a project, make
|
|
456
|
-
// sure we get those NPM package versions
|
|
457
|
-
await telemetry_1.Telemetry.populateNpmPackageVersions();
|
|
458
|
-
initWindowsError =
|
|
459
|
-
ex instanceof Error ? ex : new Error(String(ex));
|
|
460
|
-
telemetry_1.Telemetry.trackException(initWindowsError);
|
|
461
|
-
console.error(chalk_1.default.red(initWindowsError.message));
|
|
462
|
-
console.error(initWindowsError);
|
|
463
|
-
}
|
|
464
|
-
endTelemetrySession(initWindowsError);
|
|
465
|
-
setExitProcessWithError(options.verbose, initWindowsError);
|
|
466
|
-
}
|
|
467
|
-
exports.reactNativeWindowsInit = reactNativeWindowsInit;
|
|
419
|
+
`);
|
|
420
|
+
const confirm = (await (0, prompts_1.default)({
|
|
421
|
+
type: 'confirm',
|
|
422
|
+
name: 'confirm',
|
|
423
|
+
message: `Do you wish to continue with ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwResolvedVersion)}?`,
|
|
424
|
+
})).confirm;
|
|
425
|
+
if (!confirm) {
|
|
426
|
+
throw new telemetry_1.CodedError('UserCancel', 'User canceled');
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (rnwResolvedVersion) {
|
|
431
|
+
version = rnwResolvedVersion;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
installReactNativeWindows(version, options.verbose, useDevMode);
|
|
435
|
+
const generateWindows = (0, requireGenerateWindows_1.default)();
|
|
436
|
+
// Now that new NPM packages have been installed, get their versions
|
|
437
|
+
await telemetry_1.Telemetry.populateNpmPackageVersions();
|
|
438
|
+
await generateWindows(process.cwd(), name, ns, {
|
|
439
|
+
language: options.language,
|
|
440
|
+
overwrite: options.overwrite,
|
|
441
|
+
verbose: options.verbose,
|
|
442
|
+
projectType: options.projectType,
|
|
443
|
+
experimentalNuGetDependency: options.experimentalNuGetDependency,
|
|
444
|
+
useWinUI3: options.useWinUI3,
|
|
445
|
+
useHermes: options.useHermes,
|
|
446
|
+
useDevMode: useDevMode,
|
|
447
|
+
nuGetTestVersion: options.nuGetTestVersion,
|
|
448
|
+
nuGetTestFeed: options.nuGetTestFeed,
|
|
449
|
+
telemetry: options.telemetry,
|
|
450
|
+
});
|
|
451
|
+
// Now that the project has been generated, add project info
|
|
452
|
+
await addProjectInfoToTelemetry();
|
|
453
|
+
}
|
|
454
|
+
catch (ex) {
|
|
455
|
+
// Since we may have failed before generating a project, make
|
|
456
|
+
// sure we get those NPM package versions
|
|
457
|
+
await telemetry_1.Telemetry.populateNpmPackageVersions();
|
|
458
|
+
initWindowsError =
|
|
459
|
+
ex instanceof Error ? ex : new Error(String(ex));
|
|
460
|
+
telemetry_1.Telemetry.trackException(initWindowsError);
|
|
461
|
+
console.error(chalk_1.default.red(initWindowsError.message));
|
|
462
|
+
console.error(initWindowsError);
|
|
463
|
+
}
|
|
464
|
+
endTelemetrySession(initWindowsError);
|
|
465
|
+
setExitProcessWithError(options.verbose, initWindowsError);
|
|
466
|
+
}
|
|
467
|
+
exports.reactNativeWindowsInit = reactNativeWindowsInit;
|
|
468
468
|
//# sourceMappingURL=Cli.js.map
|