@react-native-windows/cli 0.0.0-canary.11 → 0.0.0-canary.113
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/README.md +49 -0
- package/lib-commonjs/config/configUtils.d.ts +25 -2
- package/lib-commonjs/config/configUtils.js +119 -30
- package/lib-commonjs/config/configUtils.js.map +1 -1
- package/lib-commonjs/config/dependencyConfig.js +101 -44
- package/lib-commonjs/config/dependencyConfig.js.map +1 -1
- package/lib-commonjs/config/projectConfig.d.ts +4 -1
- package/lib-commonjs/config/projectConfig.js +68 -12
- package/lib-commonjs/config/projectConfig.js.map +1 -1
- package/lib-commonjs/e2etest/autolink.test.d.ts +6 -0
- package/lib-commonjs/e2etest/autolink.test.js +435 -0
- package/lib-commonjs/e2etest/autolink.test.js.map +1 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.js +162 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -0
- package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -0
- package/lib-commonjs/e2etest/projectConfig.test.js +123 -0
- package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -0
- package/lib-commonjs/e2etest/projectConfig.utils.d.ts +4 -0
- package/lib-commonjs/e2etest/projectConfig.utils.js +56 -0
- package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
- package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
- package/lib-commonjs/e2etest/runWindows.test.js +61 -0
- package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
- package/lib-commonjs/generator-common/index.d.ts +16 -0
- package/lib-commonjs/generator-common/index.js +65 -44
- package/lib-commonjs/generator-common/index.js.map +1 -1
- package/lib-commonjs/generator-windows/index.d.ts +2 -2
- package/lib-commonjs/generator-windows/index.js +248 -155
- package/lib-commonjs/generator-windows/index.js.map +1 -1
- package/lib-commonjs/healthChecks.d.ts +2 -0
- package/lib-commonjs/healthChecks.js +88 -0
- package/lib-commonjs/healthChecks.js.map +1 -0
- package/lib-commonjs/index.d.ts +5 -0
- package/lib-commonjs/index.js +24 -8
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/runWindows/runWindows.js +211 -53
- package/lib-commonjs/runWindows/runWindows.js.map +1 -1
- package/lib-commonjs/runWindows/runWindowsOptions.d.ts +14 -10
- package/lib-commonjs/runWindows/runWindowsOptions.js +16 -12
- package/lib-commonjs/runWindows/runWindowsOptions.js.map +1 -1
- package/lib-commonjs/runWindows/utils/autolink.d.ts +88 -1
- package/lib-commonjs/runWindows/utils/autolink.js +596 -265
- package/lib-commonjs/runWindows/utils/autolink.js.map +1 -1
- package/lib-commonjs/runWindows/utils/build.d.ts +1 -2
- package/lib-commonjs/runWindows/utils/build.js +25 -32
- package/lib-commonjs/runWindows/utils/build.js.map +1 -1
- package/lib-commonjs/runWindows/utils/checkRequirements.js +12 -8
- package/lib-commonjs/runWindows/utils/checkRequirements.js.map +1 -1
- package/lib-commonjs/runWindows/utils/commandWithProgress.d.ts +11 -3
- package/lib-commonjs/runWindows/utils/commandWithProgress.js +60 -25
- package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +1 -1
- package/lib-commonjs/runWindows/utils/deploy.d.ts +1 -1
- package/lib-commonjs/runWindows/utils/deploy.js +167 -85
- package/lib-commonjs/runWindows/utils/deploy.js.map +1 -1
- package/lib-commonjs/runWindows/utils/info.js +5 -2
- package/lib-commonjs/runWindows/utils/info.js.map +1 -1
- package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +10 -5
- package/lib-commonjs/runWindows/utils/msbuildtools.js +98 -61
- package/lib-commonjs/runWindows/utils/msbuildtools.js.map +1 -1
- package/lib-commonjs/runWindows/utils/telemetryHelpers.d.ts +29 -0
- package/lib-commonjs/runWindows/utils/telemetryHelpers.js +109 -0
- package/lib-commonjs/runWindows/utils/telemetryHelpers.js.map +1 -0
- package/lib-commonjs/runWindows/utils/version.d.ts +4 -4
- package/lib-commonjs/runWindows/utils/version.js +1 -1
- package/lib-commonjs/runWindows/utils/version.js.map +1 -1
- package/lib-commonjs/runWindows/utils/vsInstalls.d.ts +4 -1
- package/lib-commonjs/runWindows/utils/vsInstalls.js +22 -7
- package/lib-commonjs/runWindows/utils/vsInstalls.js.map +1 -1
- package/lib-commonjs/runWindows/utils/vstools.d.ts +1 -0
- package/lib-commonjs/runWindows/utils/vstools.js +42 -29
- package/lib-commonjs/runWindows/utils/vstools.js.map +1 -1
- package/lib-commonjs/runWindows/utils/winappdeploytool.d.ts +3 -3
- package/lib-commonjs/runWindows/utils/winappdeploytool.js +19 -16
- package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +1 -1
- package/package.json +42 -25
- package/powershell/Add-AppDevPackage.ps1 +2 -2
- package/powershell/WindowsStoreAppUtils.ps1 +10 -0
- package/CHANGELOG.json +0 -170
- package/CHANGELOG.md +0 -85
|
@@ -4,292 +4,387 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
* @format
|
|
6
6
|
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
7
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.autoLinkCommand = void 0;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
30
|
+
exports.autoLinkCommand = exports.autolinkOptions = exports.autolinkWindowsInternal = exports.AutolinkWindows = void 0;
|
|
31
|
+
// Types in this file are inaccurate compared to usage in terms of falsiness.
|
|
32
|
+
// We should try to rewrite some of this to do automated schema validation to
|
|
33
|
+
// guarantee correct types
|
|
34
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
35
|
+
const fs_1 = __importDefault(require("@react-native-windows/fs"));
|
|
36
|
+
const path_1 = __importDefault(require("path"));
|
|
37
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
38
|
const perf_hooks_1 = require("perf_hooks");
|
|
13
39
|
const commandWithProgress_1 = require("./commandWithProgress");
|
|
14
|
-
const vstools = require("./vstools");
|
|
15
|
-
const generatorCommon = require("../../generator-common");
|
|
16
|
-
const configUtils = require("../../config/configUtils");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function verboseMessage(message, verbose) {
|
|
33
|
-
if (verbose) {
|
|
34
|
-
console.log(message);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Loads a source template file and performs the given replacements, normalizing CRLF.
|
|
39
|
-
* @param srcFile Path to the source file.
|
|
40
|
-
* @param replacements e.g. {'TextToBeReplaced': 'Replacement'}
|
|
41
|
-
* @return The contents of the file with the replacements applied.
|
|
42
|
-
*/
|
|
43
|
-
function getNormalizedContents(srcFile, replacements) {
|
|
44
|
-
// Template files are CRLF, JS-generated replacements are LF, normalize replacements to CRLF
|
|
45
|
-
for (var key in replacements) {
|
|
46
|
-
replacements[key] = replacements[key].replace(/\n/g, '\r\n');
|
|
47
|
-
}
|
|
48
|
-
replacements.useMustache = true;
|
|
49
|
-
return generatorCommon.resolveContents(srcFile, replacements);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Updates the target file with the expected contents if it's different.
|
|
53
|
-
* @param filePath Path to the target file to update.
|
|
54
|
-
* @param expectedContents The expected contents of the file.
|
|
55
|
-
* @param verbose If true, enable verbose logging.
|
|
56
|
-
* @param checkMode It true, don't make any changes.
|
|
57
|
-
* @return Whether any changes were necessary.
|
|
58
|
-
*/
|
|
59
|
-
function updateFile(filePath, expectedContents, verbose, checkMode) {
|
|
60
|
-
const fileName = chalk.bold(path.basename(filePath));
|
|
61
|
-
verboseMessage(`Reading ${fileName}...`, verbose);
|
|
62
|
-
const actualContents = fs.existsSync(filePath)
|
|
63
|
-
? fs.readFileSync(filePath).toString()
|
|
64
|
-
: '';
|
|
65
|
-
const contentsChanged = expectedContents !== actualContents;
|
|
66
|
-
if (contentsChanged) {
|
|
67
|
-
verboseMessage(chalk.yellow(`${fileName} needs to be updated.`), verbose);
|
|
68
|
-
if (!checkMode) {
|
|
69
|
-
verboseMessage(`Writing ${fileName}...`, verbose);
|
|
70
|
-
fs.writeFileSync(filePath, expectedContents, {
|
|
71
|
-
encoding: 'utf8',
|
|
72
|
-
flag: 'w',
|
|
73
|
-
});
|
|
40
|
+
const vstools = __importStar(require("./vstools"));
|
|
41
|
+
const generatorCommon = __importStar(require("../../generator-common"));
|
|
42
|
+
const configUtils = __importStar(require("../../config/configUtils"));
|
|
43
|
+
const telemetry_1 = require("@react-native-windows/telemetry");
|
|
44
|
+
const telemetryHelpers_1 = require("./telemetryHelpers");
|
|
45
|
+
const xmldom_1 = require("@xmldom/xmldom");
|
|
46
|
+
const formatter = require('xml-formatter');
|
|
47
|
+
class AutolinkWindows {
|
|
48
|
+
constructor(projectConfig, dependenciesConfig, options) {
|
|
49
|
+
this.projectConfig = projectConfig;
|
|
50
|
+
this.dependenciesConfig = dependenciesConfig;
|
|
51
|
+
this.options = options;
|
|
52
|
+
/** Cache of dependencies */
|
|
53
|
+
this.windowsDependencies = {};
|
|
54
|
+
this.changesNecessary = false;
|
|
55
|
+
if (!('windows' in this.projectConfig) ||
|
|
56
|
+
this.projectConfig.windows === null) {
|
|
57
|
+
throw new telemetry_1.CodedError('NoWindowsConfig', 'Windows auto-link only supported on Windows app projects');
|
|
74
58
|
}
|
|
59
|
+
this.windowsAppConfig = projectConfig.windows;
|
|
75
60
|
}
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
areChangesNeeded() {
|
|
62
|
+
return this.changesNecessary;
|
|
78
63
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Exits the script with the given status code.
|
|
83
|
-
* @param statusCode The status code.
|
|
84
|
-
* @param loggingWasEnabled Whether or not verbose lossing was enabled.
|
|
85
|
-
*/
|
|
86
|
-
function exitProcessWithStatusCode(statusCode, loggingWasEnabled) {
|
|
87
|
-
if (!loggingWasEnabled && statusCode !== 0) {
|
|
88
|
-
console.log(`Error: Re-run the command with ${chalk.bold('--logging')} for more information.`);
|
|
64
|
+
getWindowsConfig() {
|
|
65
|
+
return this.windowsAppConfig;
|
|
89
66
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* @param options Options passed from react-native CLI.
|
|
97
|
-
*/
|
|
98
|
-
async function updateAutoLink(args, config, options) {
|
|
99
|
-
const startTime = perf_hooks_1.performance.now();
|
|
100
|
-
const verbose = options.logging;
|
|
101
|
-
const checkMode = options.check;
|
|
102
|
-
var changesNecessary = false;
|
|
103
|
-
const spinner = commandWithProgress_1.newSpinner(checkMode ? 'Checking auto-linked files...' : 'Auto-linking...');
|
|
104
|
-
verboseMessage('', verbose);
|
|
105
|
-
try {
|
|
67
|
+
getSolutionFile() {
|
|
68
|
+
return path_1.default.join(this.getWindowsConfig().folder, this.getWindowsConfig().sourceDir, this.getWindowsConfig().solutionFile);
|
|
69
|
+
}
|
|
70
|
+
async run(spinner) {
|
|
71
|
+
const verbose = this.options.logging;
|
|
72
|
+
verboseMessage('', verbose);
|
|
106
73
|
verboseMessage('Parsing project...', verbose);
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
74
|
+
const rnwRoot = resolveRnwRoot(this.windowsAppConfig);
|
|
75
|
+
const templateRoot = resolveTemplateRoot(this.windowsAppConfig);
|
|
76
|
+
this.fixUpForSlnOption();
|
|
77
|
+
this.fixUpForProjOption();
|
|
78
|
+
verboseMessage('Found Windows app project, config:', verbose);
|
|
79
|
+
verboseMessage(this.windowsAppConfig, verbose);
|
|
80
|
+
this.validateRequiredAppProperties();
|
|
81
|
+
const solutionFile = this.getSolutionFile();
|
|
82
|
+
const windowsAppProjectConfig = this.windowsAppConfig.project;
|
|
83
|
+
this.validateRequiredProjectProperties();
|
|
84
|
+
const projectFile = this.getProjectFile();
|
|
85
|
+
const projectDir = path_1.default.dirname(projectFile);
|
|
86
|
+
const projectLang = windowsAppProjectConfig.projectLang;
|
|
87
|
+
verboseMessage('Parsing dependencies...', verbose);
|
|
88
|
+
this.changesNecessary =
|
|
89
|
+
(await this.ensureXAMLDialect()) || this.changesNecessary;
|
|
90
|
+
// Generating cs/cpp files for app code consumption
|
|
91
|
+
if (projectLang === 'cs') {
|
|
92
|
+
this.changesNecessary =
|
|
93
|
+
(await this.generateCSAutolinking(templateRoot, projectLang, projectDir)) || this.changesNecessary;
|
|
94
|
+
}
|
|
95
|
+
else if (projectLang === 'cpp') {
|
|
96
|
+
this.changesNecessary =
|
|
97
|
+
(await this.generateCppAutolinking(templateRoot, projectLang, projectDir)) || this.changesNecessary;
|
|
110
98
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
99
|
+
// Generating props for app project consumption
|
|
100
|
+
let propertiesForProps = '';
|
|
101
|
+
let csModuleNames = [];
|
|
102
|
+
if (projectLang === 'cpp') {
|
|
103
|
+
csModuleNames = this.getCSModules();
|
|
104
|
+
if (csModuleNames.length > 0) {
|
|
105
|
+
propertiesForProps += `
|
|
106
|
+
<!-- Set due to dependency on C# module(s): ${csModuleNames.join()} -->
|
|
107
|
+
<ConsumeCSharpModules Condition="'$(ConsumeCSharpModules)'==''">true</ConsumeCSharpModules>`;
|
|
108
|
+
}
|
|
116
109
|
}
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
this.changesNecessary =
|
|
111
|
+
(await this.generateAutolinkProps(templateRoot, projectDir, propertiesForProps)) || this.changesNecessary;
|
|
112
|
+
// Generating targets for app project consumption
|
|
113
|
+
this.changesNecessary =
|
|
114
|
+
(await this.generateAutolinkTargets(projectDir, templateRoot)) ||
|
|
115
|
+
this.changesNecessary;
|
|
116
|
+
// Generating project entries for solution
|
|
117
|
+
this.changesNecessary =
|
|
118
|
+
this.updateSolution(rnwRoot, solutionFile) || this.changesNecessary;
|
|
119
|
+
spinner.succeed();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Handles the --proj command-line option by consuming its value into the windowsAppConfig
|
|
123
|
+
*/
|
|
124
|
+
fixUpForProjOption() {
|
|
125
|
+
if (this.options.proj) {
|
|
126
|
+
const projFile = path_1.default.join(this.windowsAppConfig.folder, this.options.proj);
|
|
119
127
|
const projectContents = configUtils.readProjectFile(projFile);
|
|
120
|
-
windowsAppConfig.project = {
|
|
121
|
-
projectFile:
|
|
122
|
-
projectName: configUtils.getProjectName(projectContents),
|
|
128
|
+
this.windowsAppConfig.project = {
|
|
129
|
+
projectFile: path_1.default.relative(path_1.default.join(this.windowsAppConfig.folder, this.windowsAppConfig.sourceDir), projFile),
|
|
130
|
+
projectName: configUtils.getProjectName(projFile, projectContents),
|
|
123
131
|
projectLang: configUtils.getProjectLanguage(projFile),
|
|
124
132
|
projectGuid: configUtils.getProjectGuid(projectContents),
|
|
125
133
|
};
|
|
126
134
|
}
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Handles the --sln command-line option by consuming its value into the windowsAppConfig
|
|
138
|
+
*/
|
|
139
|
+
fixUpForSlnOption() {
|
|
140
|
+
if (this.options.sln) {
|
|
141
|
+
const slnFile = path_1.default.join(this.windowsAppConfig.folder, this.options.sln);
|
|
142
|
+
this.windowsAppConfig.solutionFile = path_1.default.relative(path_1.default.join(this.windowsAppConfig.folder, this.windowsAppConfig.sourceDir), slnFile);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Validates the all of the required app (solution) properties are present and valid */
|
|
146
|
+
validateRequiredAppProperties() {
|
|
129
147
|
const alwaysRequired = [
|
|
130
148
|
'folder',
|
|
131
149
|
'sourceDir',
|
|
132
150
|
'solutionFile',
|
|
133
151
|
'project',
|
|
134
152
|
];
|
|
135
|
-
alwaysRequired.forEach(item => {
|
|
136
|
-
if (!(item in windowsAppConfig) ||
|
|
137
|
-
|
|
153
|
+
alwaysRequired.forEach((item) => {
|
|
154
|
+
if (!(item in this.windowsAppConfig) ||
|
|
155
|
+
this.windowsAppConfig[item] === null) {
|
|
156
|
+
throw new telemetry_1.CodedError('IncompleteConfig', `${item} is required but not specified by react-native config`, { item: item });
|
|
138
157
|
}
|
|
139
|
-
else if (typeof windowsAppConfig[item] === 'string' &&
|
|
140
|
-
windowsAppConfig[item].startsWith('Error: ')) {
|
|
141
|
-
throw new
|
|
158
|
+
else if (typeof this.windowsAppConfig[item] === 'string' &&
|
|
159
|
+
this.windowsAppConfig[item].startsWith('Error: ')) {
|
|
160
|
+
throw new telemetry_1.CodedError('InvalidConfig', `${item} invalid. ${this.windowsAppConfig[item]}`, { item: item });
|
|
142
161
|
}
|
|
143
162
|
});
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
}
|
|
164
|
+
/** @return the full path to the project file (.vcxproj or .csproj) */
|
|
165
|
+
getProjectFile() {
|
|
166
|
+
const windowsAppConfig = this.getWindowsConfig();
|
|
167
|
+
return path_1.default.join(windowsAppConfig.folder, windowsAppConfig.sourceDir, windowsAppConfig.project.projectFile);
|
|
168
|
+
}
|
|
169
|
+
/** Validates that all of the required app _project_ properties are present and valid */
|
|
170
|
+
validateRequiredProjectProperties() {
|
|
171
|
+
const windowsAppProjectConfig = this.windowsAppConfig.project;
|
|
146
172
|
const projectRequired = [
|
|
147
173
|
'projectFile',
|
|
148
174
|
'projectName',
|
|
149
175
|
'projectLang',
|
|
150
176
|
'projectGuid',
|
|
151
177
|
];
|
|
152
|
-
projectRequired.forEach(item => {
|
|
178
|
+
projectRequired.forEach((item) => {
|
|
153
179
|
if (!(item in windowsAppProjectConfig) ||
|
|
154
180
|
windowsAppProjectConfig[item] === null) {
|
|
155
|
-
throw new
|
|
181
|
+
throw new telemetry_1.CodedError('IncompleteConfig', `project.${item} is required but not specified by react-native config`, { item: item });
|
|
156
182
|
}
|
|
157
183
|
else if (typeof windowsAppProjectConfig[item] === 'string' &&
|
|
158
184
|
windowsAppProjectConfig[item].startsWith('Error: ')) {
|
|
159
|
-
throw new
|
|
185
|
+
throw new telemetry_1.CodedError('InvalidConfig', `project.${item} invalid. ${windowsAppProjectConfig[item]}`, { item: item });
|
|
160
186
|
}
|
|
161
187
|
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
188
|
+
}
|
|
189
|
+
async generateCppAutolinking(templateRoot, projectLang, projectDir) {
|
|
190
|
+
const { cppPackageProviders, cppIncludes } = this.getCppReplacements();
|
|
191
|
+
const cppFileName = 'AutolinkedNativeModules.g.cpp';
|
|
192
|
+
const srcCppFile = path_1.default.join(templateRoot, `${projectLang}-app`, 'src', cppFileName);
|
|
193
|
+
const destCppFile = path_1.default.join(projectDir, cppFileName);
|
|
194
|
+
verboseMessage(`Calculating ${chalk_1.default.bold(path_1.default.basename(destCppFile))}...`, this.options.logging);
|
|
195
|
+
const cppContents = generatorCommon.resolveContents(srcCppFile, {
|
|
196
|
+
useMustache: true,
|
|
197
|
+
autolinkCppIncludes: cppIncludes,
|
|
198
|
+
autolinkCppPackageProviders: cppPackageProviders,
|
|
199
|
+
});
|
|
200
|
+
return await this.updateFile(destCppFile, cppContents);
|
|
201
|
+
}
|
|
202
|
+
getCppReplacements() {
|
|
203
|
+
let cppIncludes = '';
|
|
204
|
+
let cppPackageProviders = '';
|
|
205
|
+
const windowsDependencies = this.getWindowsDependencies();
|
|
206
|
+
for (const dependencyName of Object.keys(windowsDependencies)) {
|
|
207
|
+
windowsDependencies[dependencyName].projects.forEach((project) => {
|
|
208
|
+
if (project.directDependency) {
|
|
209
|
+
cppIncludes += `\n\n// Includes from ${dependencyName}`;
|
|
210
|
+
project.cppHeaders.forEach((header) => {
|
|
211
|
+
cppIncludes += `\n#include <${header}>`;
|
|
212
|
+
});
|
|
213
|
+
cppPackageProviders += `\n // IReactPackageProviders from ${dependencyName}`;
|
|
214
|
+
project.cppPackageProviders.forEach((packageProvider) => {
|
|
215
|
+
cppPackageProviders += `\n packageProviders.Append(winrt::${packageProvider}());`;
|
|
191
216
|
});
|
|
192
217
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (cppPackageProviders === '') {
|
|
221
|
+
// There are no windows dependencies, this would result in warning. C4100: 'packageProviders': unreferenced formal parameter.
|
|
222
|
+
// therefore add a usage.
|
|
223
|
+
cppPackageProviders = '\n UNREFERENCED_PARAMETER(packageProviders);'; // CODESYNC: vnext\local-cli\generator-windows\index.js
|
|
224
|
+
}
|
|
225
|
+
return { cppPackageProviders, cppIncludes };
|
|
226
|
+
}
|
|
227
|
+
generateCSAutolinking(templateRoot, projectLang, projectDir) {
|
|
228
|
+
const { csUsingNamespaces, csReactPackageProviders } = this.getCsReplacements();
|
|
229
|
+
const csFileName = 'AutolinkedNativeModules.g.cs';
|
|
230
|
+
const srcCsFile = path_1.default.join(templateRoot, `${projectLang}-app`, 'src', csFileName);
|
|
231
|
+
const destCsFile = path_1.default.join(projectDir, csFileName);
|
|
232
|
+
verboseMessage(`Calculating ${chalk_1.default.bold(path_1.default.basename(destCsFile))}...`, this.options.logging);
|
|
233
|
+
const csContents = generatorCommon.resolveContents(srcCsFile, {
|
|
234
|
+
useMustache: true,
|
|
235
|
+
autolinkCsUsingNamespaces: csUsingNamespaces,
|
|
236
|
+
autolinkCsReactPackageProviders: csReactPackageProviders,
|
|
237
|
+
});
|
|
238
|
+
return this.updateFile(destCsFile, csContents);
|
|
239
|
+
}
|
|
240
|
+
getCsReplacements() {
|
|
241
|
+
let csUsingNamespaces = '';
|
|
242
|
+
let csReactPackageProviders = '';
|
|
243
|
+
const windowsDependencies = this.getWindowsDependencies();
|
|
244
|
+
for (const dependencyName of Object.keys(windowsDependencies)) {
|
|
245
|
+
windowsDependencies[dependencyName].projects.forEach((project) => {
|
|
246
|
+
if (project.directDependency) {
|
|
247
|
+
csUsingNamespaces += `\n\n// Namespaces from ${dependencyName}`;
|
|
248
|
+
project.csNamespaces.forEach((namespace) => {
|
|
249
|
+
csUsingNamespaces += `\nusing ${namespace};`;
|
|
250
|
+
});
|
|
251
|
+
csReactPackageProviders += `\n // IReactPackageProviders from ${dependencyName}`;
|
|
252
|
+
project.csPackageProviders.forEach((packageProvider) => {
|
|
253
|
+
csReactPackageProviders += `\n packageProviders.Add(new ${packageProvider}());`;
|
|
254
|
+
});
|
|
196
255
|
}
|
|
197
|
-
}
|
|
256
|
+
});
|
|
198
257
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
for (const dependencyName
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
258
|
+
return { csUsingNamespaces, csReactPackageProviders };
|
|
259
|
+
}
|
|
260
|
+
getWindowsDependencies() {
|
|
261
|
+
if (Object.keys(this.windowsDependencies).length === 0) {
|
|
262
|
+
for (const dependencyName of Object.keys(this.dependenciesConfig)) {
|
|
263
|
+
const windowsDependency = this.dependenciesConfig[dependencyName].platforms.windows;
|
|
264
|
+
if (windowsDependency) {
|
|
265
|
+
verboseMessage(`${chalk_1.default.bold(dependencyName)} has Windows implementation, config:`, this.options.logging);
|
|
266
|
+
verboseMessage(windowsDependency, this.options.logging);
|
|
267
|
+
let dependencyIsValid = true;
|
|
268
|
+
dependencyIsValid = !!(dependencyIsValid &&
|
|
269
|
+
'sourceDir' in windowsDependency &&
|
|
270
|
+
windowsDependency.sourceDir &&
|
|
271
|
+
!windowsDependency.sourceDir.startsWith('Error: '));
|
|
272
|
+
if ('projects' in windowsDependency &&
|
|
273
|
+
Array.isArray(windowsDependency.projects)) {
|
|
274
|
+
if (windowsDependency.projects.length === 0 &&
|
|
275
|
+
dependencyName.includes('react-native')) {
|
|
276
|
+
// the dependency is probably a react native module, but we didn't find a module project
|
|
277
|
+
throw new telemetry_1.CodedError('Autolinking', `Found a Windows solution for ${dependencyName} but no React Native for Windows native module projects`);
|
|
278
|
+
}
|
|
279
|
+
windowsDependency.projects.forEach((project) => {
|
|
280
|
+
const itemsToCheck = [
|
|
281
|
+
'projectFile',
|
|
282
|
+
'directDependency',
|
|
283
|
+
];
|
|
284
|
+
itemsToCheck.forEach((item) => {
|
|
285
|
+
dependencyIsValid = !!(dependencyIsValid &&
|
|
286
|
+
item in project &&
|
|
287
|
+
project[item] !== '' &&
|
|
288
|
+
!project[item].toString().startsWith('Error: '));
|
|
289
|
+
});
|
|
213
290
|
});
|
|
214
291
|
}
|
|
215
|
-
|
|
292
|
+
if (dependencyIsValid) {
|
|
293
|
+
verboseMessage(`Adding ${chalk_1.default.bold(dependencyName)}.`, this.options.logging);
|
|
294
|
+
this.windowsDependencies[dependencyName] = windowsDependency;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
verboseMessage(`Invalid dependency configuration for dependency ${dependencyName}`, this.options.logging);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
216
300
|
}
|
|
217
|
-
const csFileName = 'AutolinkedNativeModules.g.cs';
|
|
218
|
-
const srcCsFile = path.join(templateRoot, projectLang, 'src', csFileName);
|
|
219
|
-
const destCsFile = path.join(projectDir, csFileName);
|
|
220
|
-
verboseMessage(`Calculating ${chalk.bold(path.basename(destCsFile))}...`, verbose);
|
|
221
|
-
const csContents = getNormalizedContents(srcCsFile, {
|
|
222
|
-
autolinkCsUsingNamespaces: csUsingNamespaces,
|
|
223
|
-
autolinkCsReactPacakgeProviders: csReactPacakgeProviders,
|
|
224
|
-
});
|
|
225
|
-
changesNecessary =
|
|
226
|
-
updateFile(destCsFile, csContents, verbose, checkMode) ||
|
|
227
|
-
changesNecessary;
|
|
228
301
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
302
|
+
return this.windowsDependencies;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Updates the target file with the expected contents if it's different.
|
|
306
|
+
* @param filePath Path to the target file to update.
|
|
307
|
+
* @param expectedContents The expected contents of the file.
|
|
308
|
+
* @return Whether any changes were necessary.
|
|
309
|
+
*/
|
|
310
|
+
async updateFile(filePath, expectedContents) {
|
|
311
|
+
const fileName = chalk_1.default.bold(path_1.default.basename(filePath));
|
|
312
|
+
verboseMessage(`Reading ${fileName}...`, this.options.logging);
|
|
313
|
+
const actualContents = fs_1.default.existsSync(filePath)
|
|
314
|
+
? (await fs_1.default.readFile(filePath)).toString()
|
|
315
|
+
: '';
|
|
316
|
+
const contentsChanged = expectedContents !== actualContents;
|
|
317
|
+
if (contentsChanged) {
|
|
318
|
+
verboseMessage(chalk_1.default.yellow(`${fileName} needs to be updated.`), this.options.logging);
|
|
319
|
+
if (!this.options.check) {
|
|
320
|
+
verboseMessage(`Writing ${fileName}...`, this.options.logging);
|
|
321
|
+
await fs_1.default.writeFile(filePath, expectedContents, {
|
|
322
|
+
encoding: 'utf8',
|
|
323
|
+
flag: 'w',
|
|
244
324
|
});
|
|
245
325
|
}
|
|
246
|
-
if (cppPackageProviders === '') {
|
|
247
|
-
// There are no windows dependencies, this would result in warning. C4100: 'packageProviders': unreferenced formal parameter.
|
|
248
|
-
// therefore add a usage.
|
|
249
|
-
cppPackageProviders = '\n UNREFERENCED_PARAMETER(packageProviders);'; // CODESYNC: vnext\local-cli\generator-windows\index.js
|
|
250
|
-
}
|
|
251
|
-
const cppFileName = 'AutolinkedNativeModules.g.cpp';
|
|
252
|
-
const srcCppFile = path.join(templateRoot, projectLang, 'src', cppFileName);
|
|
253
|
-
const destCppFile = path.join(projectDir, cppFileName);
|
|
254
|
-
verboseMessage(`Calculating ${chalk.bold(path.basename(destCppFile))}...`, verbose);
|
|
255
|
-
const cppContents = getNormalizedContents(srcCppFile, {
|
|
256
|
-
autolinkCppIncludes: cppIncludes,
|
|
257
|
-
autolinkCppPackageProviders: cppPackageProviders,
|
|
258
|
-
});
|
|
259
|
-
changesNecessary =
|
|
260
|
-
updateFile(destCppFile, cppContents, verbose, checkMode) ||
|
|
261
|
-
changesNecessary;
|
|
262
326
|
}
|
|
263
|
-
|
|
327
|
+
else {
|
|
328
|
+
verboseMessage(`No changes to ${fileName}.`, this.options.logging);
|
|
329
|
+
}
|
|
330
|
+
return contentsChanged;
|
|
331
|
+
}
|
|
332
|
+
generateAutolinkTargets(projectDir, templateRoot) {
|
|
264
333
|
let projectReferencesForTargets = '';
|
|
265
|
-
|
|
266
|
-
|
|
334
|
+
const windowsDependencies = this.getWindowsDependencies();
|
|
335
|
+
for (const dependencyName of Object.keys(windowsDependencies)) {
|
|
336
|
+
windowsDependencies[dependencyName].projects.forEach((project) => {
|
|
267
337
|
if (project.directDependency) {
|
|
268
|
-
const dependencyProjectFile =
|
|
269
|
-
const relDependencyProjectFile =
|
|
270
|
-
projectReferencesForTargets +=
|
|
271
|
-
|
|
338
|
+
const dependencyProjectFile = path_1.default.join(windowsDependencies[dependencyName].folder, windowsDependencies[dependencyName].sourceDir, project.projectFile);
|
|
339
|
+
const relDependencyProjectFile = path_1.default.relative(projectDir, dependencyProjectFile);
|
|
340
|
+
projectReferencesForTargets += `
|
|
341
|
+
<!-- Projects from ${dependencyName} -->
|
|
342
|
+
<ProjectReference Include="$(ProjectDir)${relDependencyProjectFile}">
|
|
272
343
|
<Project>${project.projectGuid}</Project>
|
|
273
344
|
</ProjectReference>`;
|
|
274
345
|
}
|
|
275
346
|
});
|
|
276
347
|
}
|
|
277
348
|
const targetFileName = 'AutolinkedNativeModules.g.targets';
|
|
278
|
-
const srcTargetFile =
|
|
279
|
-
const destTargetFile =
|
|
280
|
-
verboseMessage(`Calculating ${
|
|
281
|
-
const targetContents =
|
|
349
|
+
const srcTargetFile = path_1.default.join(templateRoot, `shared-app`, 'src', targetFileName);
|
|
350
|
+
const destTargetFile = path_1.default.join(projectDir, targetFileName);
|
|
351
|
+
verboseMessage(`Calculating ${chalk_1.default.bold(path_1.default.basename(destTargetFile))}...`, this.options.logging);
|
|
352
|
+
const targetContents = generatorCommon.resolveContents(srcTargetFile, {
|
|
353
|
+
useMustache: true,
|
|
282
354
|
autolinkProjectReferencesForTargets: projectReferencesForTargets,
|
|
283
355
|
});
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
356
|
+
return this.updateFile(destTargetFile, targetContents);
|
|
357
|
+
}
|
|
358
|
+
generateAutolinkProps(templateRoot, projectDir, propertiesForProps) {
|
|
359
|
+
const propsFileName = 'AutolinkedNativeModules.g.props';
|
|
360
|
+
const srcPropsFile = path_1.default.join(templateRoot, `shared-app`, 'src', propsFileName);
|
|
361
|
+
const destPropsFile = path_1.default.join(projectDir, propsFileName);
|
|
362
|
+
verboseMessage(`Calculating ${chalk_1.default.bold(path_1.default.basename(destPropsFile))}...`, this.options.logging);
|
|
363
|
+
const propsContents = generatorCommon.resolveContents(srcPropsFile, {
|
|
364
|
+
useMustache: true,
|
|
365
|
+
autolinkPropertiesForProps: propertiesForProps,
|
|
366
|
+
});
|
|
367
|
+
return this.updateFile(destPropsFile, propsContents);
|
|
368
|
+
}
|
|
369
|
+
getCSModules() {
|
|
370
|
+
const csModuleNames = [];
|
|
371
|
+
const windowsDependencies = this.getWindowsDependencies();
|
|
372
|
+
for (const dependencyName of Object.keys(windowsDependencies)) {
|
|
373
|
+
windowsDependencies[dependencyName].projects.forEach((project) => {
|
|
374
|
+
if (project.directDependency && project.projectLang === 'cs') {
|
|
375
|
+
csModuleNames.push(project.projectName);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
return csModuleNames;
|
|
380
|
+
}
|
|
381
|
+
updateSolution(rnwRoot, solutionFile) {
|
|
382
|
+
const projectsForSolution = [];
|
|
383
|
+
const windowsDependencies = this.getWindowsDependencies();
|
|
384
|
+
for (const dependencyName of Object.keys(windowsDependencies)) {
|
|
385
|
+
// Process dependency projects
|
|
386
|
+
windowsDependencies[dependencyName].projects.forEach((project) => {
|
|
387
|
+
const dependencyProjectFile = path_1.default.join(windowsDependencies[dependencyName].folder, windowsDependencies[dependencyName].sourceDir, project.projectFile);
|
|
293
388
|
projectsForSolution.push({
|
|
294
389
|
projectFile: dependencyProjectFile,
|
|
295
390
|
projectName: project.projectName,
|
|
@@ -298,56 +393,292 @@ async function updateAutoLink(args, config, options) {
|
|
|
298
393
|
});
|
|
299
394
|
});
|
|
300
395
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
396
|
+
const csModuleNames = this.getCSModules();
|
|
397
|
+
if (csModuleNames.length > 0) {
|
|
398
|
+
// Add managed projects
|
|
399
|
+
projectsForSolution.push({
|
|
400
|
+
projectFile: path_1.default.join(rnwRoot, 'Microsoft.ReactNative.Managed/Microsoft.ReactNative.Managed.csproj'),
|
|
401
|
+
projectName: 'Microsoft.ReactNative.Managed',
|
|
402
|
+
projectLang: 'cs',
|
|
403
|
+
projectGuid: '{F2824844-CE15-4242-9420-308923CD76C3}',
|
|
404
|
+
});
|
|
405
|
+
projectsForSolution.push({
|
|
406
|
+
projectFile: path_1.default.join(rnwRoot, 'Microsoft.ReactNative.Managed.CodeGen//Microsoft.ReactNative.Managed.CodeGen.csproj'),
|
|
407
|
+
projectName: 'Microsoft.ReactNative.Managed.CodeGen',
|
|
408
|
+
projectLang: 'cs',
|
|
409
|
+
projectGuid: '{ADED4FBE-887D-4271-AF24-F0823BCE7961}',
|
|
410
|
+
projectTypeGuid: vstools.dotNetCoreProjectTypeGuid,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
verboseMessage(`Calculating ${chalk_1.default.bold(path_1.default.basename(solutionFile))} changes...`, this.options.logging);
|
|
414
|
+
let changesNecessary = false;
|
|
415
|
+
projectsForSolution.forEach((project) => {
|
|
416
|
+
const contentsChanged = vstools.addProjectToSolution(solutionFile, project, this.options.logging, this.options.check);
|
|
304
417
|
changesNecessary = changesNecessary || contentsChanged;
|
|
305
418
|
});
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
419
|
+
return changesNecessary;
|
|
420
|
+
}
|
|
421
|
+
getExperimentalFeaturesPropsXml() {
|
|
422
|
+
const experimentalFeaturesProps = path_1.default.join(path_1.default.dirname(this.getSolutionFile()), 'ExperimentalFeatures.props');
|
|
423
|
+
if (fs_1.default.existsSync(experimentalFeaturesProps)) {
|
|
424
|
+
const experimentalFeaturesContents = configUtils.readProjectFile(experimentalFeaturesProps);
|
|
425
|
+
return {
|
|
426
|
+
path: experimentalFeaturesProps,
|
|
427
|
+
content: experimentalFeaturesContents,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
async ensureXAMLDialect() {
|
|
433
|
+
var _a, _b;
|
|
434
|
+
let changesNeeded = false;
|
|
435
|
+
const useWinUI3FromConfig = this.getWindowsConfig().useWinUI3;
|
|
436
|
+
const experimentalFeatures = this.getExperimentalFeaturesPropsXml();
|
|
437
|
+
if (experimentalFeatures) {
|
|
438
|
+
const useWinUI3FromExperimentalFeatures = ((_a = configUtils
|
|
439
|
+
.tryFindPropertyValue(experimentalFeatures.content, 'UseWinUI3')) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'true';
|
|
440
|
+
// Check if WinUI2xVersion is specified in experimental features
|
|
441
|
+
const targetWinUI2xVersion = configUtils.tryFindPropertyValue(experimentalFeatures.content, 'WinUI2xVersion');
|
|
442
|
+
// Check if WinUI3Version is specified in experimental features
|
|
443
|
+
const targetWinUI3xVersion = configUtils.tryFindPropertyValue(experimentalFeatures.content, 'WinUI3Version');
|
|
444
|
+
// Use the UseWinUI3 value in react-native.config.js, or if not present, the value from ExperimentalFeatures.props
|
|
445
|
+
changesNeeded = await this.updatePackagesConfigXAMLDialect(useWinUI3FromConfig !== undefined
|
|
446
|
+
? useWinUI3FromConfig
|
|
447
|
+
: useWinUI3FromExperimentalFeatures, targetWinUI2xVersion, targetWinUI3xVersion);
|
|
448
|
+
if (useWinUI3FromConfig !== undefined) {
|
|
449
|
+
// Make sure ExperimentalFeatures.props matches the value that comes from react-native.config.js
|
|
450
|
+
const node = experimentalFeatures.content.getElementsByTagName('UseWinUI3');
|
|
451
|
+
const newValue = useWinUI3FromConfig ? 'true' : 'false';
|
|
452
|
+
changesNeeded = ((_b = node.item(0)) === null || _b === void 0 ? void 0 : _b.textContent) !== newValue || changesNeeded;
|
|
453
|
+
if (!this.options.check && changesNeeded) {
|
|
454
|
+
node.item(0).textContent = newValue;
|
|
455
|
+
const experimentalFeaturesOutput = new xmldom_1.XMLSerializer().serializeToString(experimentalFeatures.content);
|
|
456
|
+
await this.updateFile(experimentalFeatures.path, experimentalFeaturesOutput);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return changesNeeded;
|
|
461
|
+
}
|
|
462
|
+
getPackagesConfigXml() {
|
|
463
|
+
const projectFile = this.getProjectFile();
|
|
464
|
+
const packagesConfig = path_1.default.join(path_1.default.dirname(projectFile), 'packages.config');
|
|
465
|
+
if (fs_1.default.existsSync(packagesConfig)) {
|
|
466
|
+
return {
|
|
467
|
+
path: packagesConfig,
|
|
468
|
+
content: configUtils.readProjectFile(packagesConfig),
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
return undefined;
|
|
472
|
+
}
|
|
473
|
+
async updatePackagesConfigXAMLDialect(useWinUI3, targetWinUI2xVersion, targetWinUI3xVersion) {
|
|
474
|
+
let changed = false;
|
|
475
|
+
const packagesConfig = this.getPackagesConfigXml();
|
|
476
|
+
if (packagesConfig) {
|
|
477
|
+
// if we don't have a packages.config, then this is a C# project, in which case we use <PackageReference> and dynamically pick the right XAML package.
|
|
478
|
+
const project = this.getWindowsConfig();
|
|
479
|
+
const winUIPropsPath = path_1.default.join(resolveRnwRoot(project), 'PropertySheets/WinUI.props');
|
|
480
|
+
const winuiPropsContents = configUtils.readProjectFile(winUIPropsPath);
|
|
481
|
+
// Use the given WinUI2xVersion, otherwise fallback to WinUI.props
|
|
482
|
+
const winui2xVersion = targetWinUI2xVersion !== null && targetWinUI2xVersion !== void 0 ? targetWinUI2xVersion : configUtils.tryFindPropertyValue(winuiPropsContents, 'WinUI2xVersion');
|
|
483
|
+
// Use the given WinUI3Version, otherwise fallback to WinUI.props
|
|
484
|
+
const winui3Version = targetWinUI3xVersion !== null && targetWinUI3xVersion !== void 0 ? targetWinUI3xVersion : configUtils.tryFindPropertyValue(winuiPropsContents, 'WinUI3Version');
|
|
485
|
+
const dialects = [
|
|
486
|
+
{ id: 'Microsoft.WinUI', version: winui3Version },
|
|
487
|
+
{ id: 'Microsoft.UI.Xaml', version: winui2xVersion },
|
|
488
|
+
];
|
|
489
|
+
const keepPkg = useWinUI3 ? dialects[0] : dialects[1];
|
|
490
|
+
const removePkg = useWinUI3 ? dialects[1] : dialects[0];
|
|
491
|
+
changed = this.updatePackagesConfig(packagesConfig, [removePkg], [keepPkg]);
|
|
492
|
+
if (!this.options.check && changed) {
|
|
493
|
+
const serializer = new xmldom_1.XMLSerializer();
|
|
494
|
+
const output = serializer.serializeToString(packagesConfig.content);
|
|
495
|
+
const formattedXml = formatter(output, { indentation: ' ' });
|
|
496
|
+
await this.updateFile(packagesConfig.path, formattedXml);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return changed;
|
|
500
|
+
}
|
|
501
|
+
updatePackagesConfig(packagesConfig, removePkgs, keepPkgs) {
|
|
502
|
+
let changed = false;
|
|
503
|
+
const packageElements = packagesConfig.content.documentElement.getElementsByTagName('package');
|
|
504
|
+
const nodesToRemove = [];
|
|
505
|
+
for (let i = 0; i < packageElements.length; i++) {
|
|
506
|
+
const packageElement = packageElements.item(i);
|
|
507
|
+
const idAttr = packageElement.getAttributeNode('id');
|
|
508
|
+
const id = idAttr.value;
|
|
509
|
+
const keepPkg = keepPkgs.find((pkg) => pkg.id === id);
|
|
510
|
+
if (removePkgs.find((pkg) => pkg.id === id)) {
|
|
511
|
+
nodesToRemove.push(packageElement);
|
|
512
|
+
changed = true;
|
|
513
|
+
}
|
|
514
|
+
else if (keepPkg) {
|
|
515
|
+
changed =
|
|
516
|
+
changed || keepPkg.version !== packageElement.getAttribute('version');
|
|
517
|
+
packageElement.setAttribute('version', keepPkg.version);
|
|
518
|
+
keepPkgs = keepPkgs.filter((pkg) => pkg.id !== keepPkg.id);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
nodesToRemove.forEach((pkg) => packagesConfig.content.documentElement.removeChild(pkg));
|
|
522
|
+
keepPkgs.forEach((keepPkg) => {
|
|
523
|
+
const newPkg = packagesConfig.content.createElement('package');
|
|
524
|
+
Object.entries(keepPkg).forEach(([attr, value]) => {
|
|
525
|
+
newPkg.setAttribute(attr, value);
|
|
526
|
+
});
|
|
527
|
+
newPkg.setAttribute('targetFramework', 'native');
|
|
528
|
+
packagesConfig.content.documentElement.appendChild(newPkg);
|
|
529
|
+
changed = true;
|
|
530
|
+
});
|
|
531
|
+
return changed;
|
|
532
|
+
}
|
|
533
|
+
/** @return The CLI command to invoke autolink-windows independently */
|
|
534
|
+
getAutolinkWindowsCommand() {
|
|
535
|
+
const folder = this.windowsAppConfig.folder;
|
|
536
|
+
const autolinkCommand = 'npx react-native autolink-windows';
|
|
537
|
+
const autolinkArgs = `--sln "${path_1.default.relative(folder, this.getSolutionFile())}" --proj "${path_1.default.relative(folder, this.getProjectFile())}"`;
|
|
538
|
+
return `${autolinkCommand} ${autolinkArgs}`;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
exports.AutolinkWindows = AutolinkWindows;
|
|
542
|
+
/**
|
|
543
|
+
* Locates the react-native-windows directory
|
|
544
|
+
* @param config project configuration
|
|
545
|
+
*/
|
|
546
|
+
function resolveRnwRoot(projectConfig) {
|
|
547
|
+
const rnwPackage = path_1.default.dirname(require.resolve('react-native-windows/package.json', {
|
|
548
|
+
paths: [projectConfig.folder],
|
|
549
|
+
}));
|
|
550
|
+
return rnwPackage;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Locates the react-native-windows directory containing template files
|
|
554
|
+
* @param config project configuration
|
|
555
|
+
*/
|
|
556
|
+
function resolveTemplateRoot(projectConfig) {
|
|
557
|
+
const rnwPackage = resolveRnwRoot(projectConfig);
|
|
558
|
+
return path_1.default.join(rnwPackage, 'template');
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Logs the given message if verbose is True.
|
|
562
|
+
* @param message The message to log.
|
|
563
|
+
* @param verbose Whether or not verbose logging is enabled.
|
|
564
|
+
*/
|
|
565
|
+
function verboseMessage(message, verbose) {
|
|
566
|
+
if (verbose) {
|
|
567
|
+
console.log(message);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Sanitizes the given option for telemetery.
|
|
572
|
+
* @param key The key of the option.
|
|
573
|
+
* @param value The unsanitized value of the option.
|
|
574
|
+
* @returns The sanitized value of the option.
|
|
575
|
+
*/
|
|
576
|
+
function optionSanitizer(key, value) {
|
|
577
|
+
// Do not add a default case here.
|
|
578
|
+
// Strings risking PII should just return true if present, false otherwise.
|
|
579
|
+
// All others should return the value (or false if undefined).
|
|
580
|
+
switch (key) {
|
|
581
|
+
case 'sln':
|
|
582
|
+
case 'proj':
|
|
583
|
+
return value === undefined ? false : true; // Strip PII
|
|
584
|
+
case 'logging':
|
|
585
|
+
case 'check':
|
|
586
|
+
case 'telemetry':
|
|
587
|
+
return value === undefined ? false : value; // Return value
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Get the extra props to add to the `autolink-windows` telemetry event.
|
|
592
|
+
* @returns The extra props.
|
|
593
|
+
*/
|
|
594
|
+
async function getExtraProps() {
|
|
595
|
+
const extraProps = {};
|
|
596
|
+
return extraProps;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* The function run when calling `react-native autolink-windows`.
|
|
600
|
+
* @param args Unprocessed args passed from react-native CLI.
|
|
601
|
+
* @param config Config passed from react-native CLI.
|
|
602
|
+
* @param options Options passed from react-native CLI.
|
|
603
|
+
*/
|
|
604
|
+
async function autolinkWindows(args, config, options) {
|
|
605
|
+
await (0, telemetryHelpers_1.startTelemetrySession)('autolink-windows', config, options, (0, telemetryHelpers_1.getDefaultOptions)(config, exports.autolinkOptions), optionSanitizer);
|
|
606
|
+
let autolinkWindowsError;
|
|
607
|
+
try {
|
|
608
|
+
await autolinkWindowsInternal(args, config, options);
|
|
609
|
+
}
|
|
610
|
+
catch (ex) {
|
|
611
|
+
autolinkWindowsError =
|
|
612
|
+
ex instanceof Error ? ex : new Error(String(ex));
|
|
613
|
+
telemetry_1.Telemetry.trackException(autolinkWindowsError);
|
|
614
|
+
}
|
|
615
|
+
await (0, telemetryHelpers_1.endTelemetrySession)(autolinkWindowsError, getExtraProps);
|
|
616
|
+
(0, commandWithProgress_1.setExitProcessWithError)(options.logging, autolinkWindowsError);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Performs auto-linking for RNW native modules and apps.
|
|
620
|
+
* @param args Unprocessed args passed from react-native CLI.
|
|
621
|
+
* @param config Config passed from react-native CLI.
|
|
622
|
+
* @param options Options passed from react-native CLI.
|
|
623
|
+
*/
|
|
624
|
+
async function autolinkWindowsInternal(args, config, options) {
|
|
625
|
+
const startTime = perf_hooks_1.performance.now();
|
|
626
|
+
const spinner = (0, commandWithProgress_1.newSpinner)(options.check ? 'Checking auto-linked files...' : 'Auto-linking...');
|
|
627
|
+
try {
|
|
628
|
+
const autolink = new AutolinkWindows(config.project, config.dependencies, options);
|
|
629
|
+
await autolink.run(spinner);
|
|
630
|
+
const endTime = perf_hooks_1.performance.now();
|
|
631
|
+
if (!autolink.areChangesNeeded()) {
|
|
632
|
+
console.log(`${chalk_1.default.green('Success:')} No auto-linking changes necessary. (${Math.round(endTime - startTime)}ms)`);
|
|
310
633
|
}
|
|
311
|
-
else if (
|
|
312
|
-
|
|
313
|
-
|
|
634
|
+
else if (options.check) {
|
|
635
|
+
const autolinkCommand = autolink.getAutolinkWindowsCommand();
|
|
636
|
+
console.log(`${chalk_1.default.yellow('Warning:')} Auto-linking changes were necessary but ${chalk_1.default.bold('--check')} specified. Run '${chalk_1.default.bold(`${autolinkCommand}`)}' to apply the changes. (${Math.round(endTime - startTime)}ms)`);
|
|
637
|
+
throw new telemetry_1.CodedError('NeedAutolinking', `Auto-linking changes were necessary but --check was specified. Run '${autolinkCommand}' to apply the changes`);
|
|
314
638
|
}
|
|
315
639
|
else {
|
|
316
|
-
console.log(`${
|
|
640
|
+
console.log(`${chalk_1.default.green('Success:')} Auto-linking changes completed. (${Math.round(endTime - startTime)}ms)`);
|
|
317
641
|
}
|
|
318
642
|
}
|
|
319
643
|
catch (e) {
|
|
320
644
|
spinner.fail();
|
|
321
|
-
|
|
322
|
-
console.log(`${
|
|
323
|
-
|
|
645
|
+
const endTime = perf_hooks_1.performance.now();
|
|
646
|
+
console.log(`${chalk_1.default.red('Error:')} ${e.toString()}. (${Math.round(endTime - startTime)}ms)`);
|
|
647
|
+
throw e;
|
|
324
648
|
}
|
|
325
649
|
}
|
|
650
|
+
exports.autolinkWindowsInternal = autolinkWindowsInternal;
|
|
651
|
+
exports.autolinkOptions = [
|
|
652
|
+
{
|
|
653
|
+
name: '--logging',
|
|
654
|
+
description: 'Verbose output logging',
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
name: '--check',
|
|
658
|
+
description: 'Only check whether any autolinked files need to change',
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
name: '--sln [string]',
|
|
662
|
+
description: "Override the app solution file determined by 'react-native config', e.g. windows\\myApp.sln",
|
|
663
|
+
default: undefined,
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
name: '--proj [string]',
|
|
667
|
+
description: "Override the app project file determined by 'react-native config', e.g. windows\\myApp\\myApp.vcxproj",
|
|
668
|
+
default: undefined,
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
name: '--no-telemetry',
|
|
672
|
+
description: 'Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',
|
|
673
|
+
},
|
|
674
|
+
];
|
|
675
|
+
/**
|
|
676
|
+
* Performs auto-linking for RNW native modules and apps.
|
|
677
|
+
*/
|
|
326
678
|
exports.autoLinkCommand = {
|
|
327
679
|
name: 'autolink-windows',
|
|
328
680
|
description: 'performs autolinking',
|
|
329
|
-
func:
|
|
330
|
-
options:
|
|
331
|
-
{
|
|
332
|
-
name: '--logging',
|
|
333
|
-
description: 'Verbose output logging',
|
|
334
|
-
default: false,
|
|
335
|
-
},
|
|
336
|
-
{
|
|
337
|
-
name: '--check',
|
|
338
|
-
description: 'Only check whether any autolinked files need to change',
|
|
339
|
-
default: false,
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
name: '--sln [string]',
|
|
343
|
-
description: "Override the app solution file determined by 'react-native config', e.g. windows\\myApp.sln",
|
|
344
|
-
default: undefined,
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
name: '--proj [string]',
|
|
348
|
-
description: "Override the app project file determined by 'react-native config', e.g. windows\\myApp\\myApp.vcxproj",
|
|
349
|
-
default: undefined,
|
|
350
|
-
},
|
|
351
|
-
],
|
|
681
|
+
func: autolinkWindows,
|
|
682
|
+
options: exports.autolinkOptions,
|
|
352
683
|
};
|
|
353
684
|
//# sourceMappingURL=autolink.js.map
|