@react-native-windows/cli 0.73.2 → 0.74.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.d.ts +87 -87
  2. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js +654 -654
  3. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.d.ts +14 -14
  4. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js +32 -32
  5. package/lib-commonjs/commands/codegenWindows/codegenWindows.d.ts +27 -27
  6. package/lib-commonjs/commands/codegenWindows/codegenWindows.js +205 -205
  7. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.d.ts +12 -12
  8. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js +22 -22
  9. package/lib-commonjs/commands/config/configUtils.d.ts +123 -123
  10. package/lib-commonjs/commands/config/configUtils.js +380 -380
  11. package/lib-commonjs/commands/config/dependencyConfig.d.ts +37 -37
  12. package/lib-commonjs/commands/config/dependencyConfig.js +227 -227
  13. package/lib-commonjs/commands/config/projectConfig.d.ts +27 -27
  14. package/lib-commonjs/commands/config/projectConfig.js +180 -180
  15. package/lib-commonjs/commands/healthCheck/healthCheckList.d.ts +6 -6
  16. package/lib-commonjs/commands/healthCheck/healthCheckList.js +20 -20
  17. package/lib-commonjs/commands/healthCheck/healthCheckList.js.map +1 -1
  18. package/lib-commonjs/commands/healthCheck/healthChecks.d.ts +7 -7
  19. package/lib-commonjs/commands/healthCheck/healthChecks.js +123 -123
  20. package/lib-commonjs/commands/initWindows/initWindows.d.ts +46 -46
  21. package/lib-commonjs/commands/initWindows/initWindows.js +243 -243
  22. package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +15 -15
  23. package/lib-commonjs/commands/initWindows/initWindowsOptions.js +37 -37
  24. package/lib-commonjs/commands/runWindows/runWindows.d.ts +10 -10
  25. package/lib-commonjs/commands/runWindows/runWindows.js +321 -321
  26. package/lib-commonjs/commands/runWindows/runWindowsOptions.d.ts +56 -56
  27. package/lib-commonjs/commands/runWindows/runWindowsOptions.js +132 -132
  28. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -6
  29. package/lib-commonjs/e2etest/autolink.test.js +366 -366
  30. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -6
  31. package/lib-commonjs/e2etest/dependencyConfig.test.js +129 -129
  32. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -6
  33. package/lib-commonjs/e2etest/healthChecks.test.js +30 -30
  34. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -6
  35. package/lib-commonjs/e2etest/initWindows.test.js +42 -42
  36. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -6
  37. package/lib-commonjs/e2etest/projectConfig.test.js +110 -110
  38. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -8
  39. package/lib-commonjs/e2etest/projectConfig.utils.js +76 -76
  40. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -6
  41. package/lib-commonjs/e2etest/runWindows.test.js +60 -60
  42. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  43. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  44. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  45. package/lib-commonjs/generator-common/index.d.ts +39 -39
  46. package/lib-commonjs/generator-common/index.js +242 -242
  47. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  48. package/lib-commonjs/generator-windows/index.js +316 -316
  49. package/lib-commonjs/index.d.ts +50 -50
  50. package/lib-commonjs/index.js +77 -77
  51. package/lib-commonjs/utils/build.d.ts +12 -12
  52. package/lib-commonjs/utils/build.js +84 -84
  53. package/lib-commonjs/utils/checkRequirements.d.ts +6 -6
  54. package/lib-commonjs/utils/checkRequirements.js +69 -69
  55. package/lib-commonjs/utils/commandWithProgress.d.ts +21 -21
  56. package/lib-commonjs/utils/commandWithProgress.js +149 -149
  57. package/lib-commonjs/utils/deploy.d.ts +12 -12
  58. package/lib-commonjs/utils/deploy.js +353 -353
  59. package/lib-commonjs/utils/info.d.ts +6 -6
  60. package/lib-commonjs/utils/info.js +28 -28
  61. package/lib-commonjs/utils/msbuildtools.d.ts +28 -28
  62. package/lib-commonjs/utils/msbuildtools.js +273 -273
  63. package/lib-commonjs/utils/msbuildtools.js.map +1 -1
  64. package/lib-commonjs/utils/pathHelpers.d.ts +9 -9
  65. package/lib-commonjs/utils/pathHelpers.js +36 -36
  66. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -29
  67. package/lib-commonjs/utils/telemetryHelpers.js +120 -120
  68. package/lib-commonjs/utils/version.d.ts +19 -19
  69. package/lib-commonjs/utils/version.js +109 -109
  70. package/lib-commonjs/utils/vsInstalls.d.ts +34 -34
  71. package/lib-commonjs/utils/vsInstalls.js +99 -99
  72. package/lib-commonjs/utils/vstools.d.ts +16 -16
  73. package/lib-commonjs/utils/vstools.js +189 -189
  74. package/lib-commonjs/utils/winappdeploytool.d.ts +24 -24
  75. package/lib-commonjs/utils/winappdeploytool.js +108 -108
  76. package/package.json +16 -16
@@ -1,367 +1,367 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- * @format
6
- */
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- const path_1 = __importDefault(require("path"));
12
- const telemetry_1 = require("@react-native-windows/telemetry");
13
- const projectConfig_1 = require("../commands/config/projectConfig");
14
- const autolinkWindows_1 = require("../commands/autolinkWindows/autolinkWindows");
15
- const autolinkWindowsOptions_1 = require("../commands/autolinkWindows/autolinkWindowsOptions");
16
- const xmldom_1 = require("@xmldom/xmldom");
17
- const projectConfig_utils_1 = require("./projectConfig.utils");
18
- test('autolink with no windows project', () => {
19
- expect(() => {
20
- // eslint-disable-next-line no-new
21
- new AutoLinkTest({}, {}, { check: true, logging: false });
22
- }).toThrowError();
23
- });
24
- test('autolink with incomplete windows project', () => {
25
- expect(() => {
26
- const autolink = new AutoLinkTest({ windows: {} }, {}, { check: true, logging: false });
27
- autolink.validateRequiredAppProperties();
28
- }).toThrowError();
29
- });
30
- class AutoLinkTest extends autolinkWindows_1.AutoLinkWindows {
31
- constructor() {
32
- super(...arguments);
33
- this.packagesConfig = '';
34
- this.experimentalFeaturesProps = '';
35
- }
36
- getWindowsProjectConfig() {
37
- return this.windowsAppConfig;
38
- }
39
- getPackagesConfigXml() {
40
- return {
41
- path: 'packages.config',
42
- content: new xmldom_1.DOMParser().parseFromString(this.packagesConfig, 'application/xml'),
43
- };
44
- }
45
- getExperimentalFeaturesPropsXml() {
46
- return {
47
- path: 'ExperimentalFeatures.props',
48
- content: new xmldom_1.DOMParser().parseFromString(this.experimentalFeaturesProps, 'application/xml'),
49
- };
50
- }
51
- async updateFile(filepath, content) {
52
- if (filepath === 'packages.config') {
53
- this.packagesConfig = content;
54
- }
55
- else if (filepath === 'ExperimentalFeatures.props') {
56
- this.experimentalFeaturesProps = content;
57
- }
58
- else {
59
- throw new Error(`Unknown path: ${filepath}`);
60
- }
61
- return true;
62
- }
63
- }
64
- test('autolink fixup sln', () => {
65
- const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.' } }, {}, { check: true, logging: false, sln: 'foo' });
66
- expect(autolink.getWindowsProjectConfig().solutionFile).toBeUndefined();
67
- expect(() => {
68
- autolink.validateRequiredAppProperties();
69
- }).toThrow();
70
- autolink.fixUpForSlnOption();
71
- expect(autolink.getWindowsProjectConfig().solutionFile).toEqual('foo');
72
- expect(() => {
73
- autolink.validateRequiredAppProperties();
74
- }).toThrow();
75
- });
76
- test('autolink fixup proj', async () => {
77
- const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {}, {
78
- check: true,
79
- logging: false,
80
- proj: 'projects/WithWinUI3/windows/WithWinUI3/WithWinUI3.vcxproj',
81
- });
82
- expect(autolink.getWindowsProjectConfig().solutionFile).toEqual('foo.sln');
83
- expect(autolink.getWindowsProjectConfig().project).toBeUndefined();
84
- const folder = path_1.default.resolve('src/e2etest/projects/', 'WithWinUI3');
85
- await (0, projectConfig_utils_1.ensureWinUI3Project)(folder);
86
- expect(() => {
87
- autolink.validateRequiredProjectProperties();
88
- }).toThrow();
89
- autolink.fixUpForProjOption();
90
- const projectConfig = autolink.getWindowsProjectConfig().project;
91
- expect(projectConfig).not.toBeUndefined();
92
- expect(projectConfig.projectName).toEqual('WithWinUI3');
93
- autolink.validateRequiredProjectProperties();
94
- });
95
- test('empty cpp autolink dependencies', () => {
96
- const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {}, {
97
- check: true,
98
- logging: false,
99
- proj: 'projects/WithWinUI3/windows/WithWinUI3/WithWinUI3.vcxproj',
100
- });
101
- const replacements = autolink.getCppReplacements();
102
- expect(replacements.cppIncludes).toEqual('');
103
- expect(replacements.cppPackageProviders).toEqual('\n UNREFERENCED_PARAMETER(packageProviders);');
104
- });
105
- test('one invalid cpp autolink dependency', () => {
106
- const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
107
- superModule: {
108
- name: 'superModule',
109
- root: 'theRoot',
110
- platforms: {
111
- windows: {},
112
- },
113
- },
114
- }, {
115
- check: true,
116
- logging: false,
117
- proj: 'projects/WithWinUI3/windows/WithWinUI3/WithWinUI3.vcxproj',
118
- });
119
- const replacements = autolink.getCppReplacements();
120
- expect(replacements.cppIncludes).toEqual('');
121
- expect(replacements.cppPackageProviders).toEqual('\n UNREFERENCED_PARAMETER(packageProviders);');
122
- });
123
- test('one invalid cs autolink dependency', () => {
124
- const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
125
- superModule: {
126
- name: 'superModule',
127
- root: 'theRoot',
128
- platforms: {
129
- windows: {},
130
- },
131
- },
132
- }, {
133
- check: true,
134
- logging: false,
135
- proj: 'projects/SimpleCSharpApp/windows/SimpleCSharpApp/SimpleCSharpApp.csproj',
136
- });
137
- const replacements = autolink.getCsReplacements();
138
- expect(replacements.csUsingNamespaces).toEqual('');
139
- expect(replacements.csReactPackageProviders).toEqual('');
140
- });
141
- test('one valid cpp autolink dependency', () => {
142
- const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
143
- superModule: {
144
- name: 'superModule',
145
- root: 'theRoot',
146
- platforms: {
147
- windows: {
148
- sourceDir: __dirname,
149
- projects: [
150
- {
151
- directDependency: true,
152
- projectFile: 'superModule.vcxproj',
153
- cppHeaders: ['Garfield.h', 'Snoopy.h'],
154
- cppPackageProviders: ['FamousAnimalCartoons'],
155
- },
156
- ],
157
- },
158
- },
159
- },
160
- }, {
161
- check: true,
162
- logging: false,
163
- proj: 'projects/WithWinUI3/windows/WithWinUI3/WithWinUI3.vcxproj',
164
- });
165
- const replacements = autolink.getCppReplacements();
166
- expect(replacements.cppIncludes).toMatch(/#include <Garfield.h>/);
167
- expect(replacements.cppIncludes).toMatch(/#include <Snoopy.h>/);
168
- expect(replacements.cppPackageProviders).toContain('packageProviders.Append(winrt::FamousAnimalCartoons())');
169
- });
170
- test('one valid cs autolink dependency', () => {
171
- const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
172
- superModule: {
173
- name: 'superModule',
174
- root: 'theRoot',
175
- platforms: {
176
- windows: {
177
- sourceDir: __dirname,
178
- projects: [
179
- {
180
- directDependency: true,
181
- csNamespaces: ['Garfield'],
182
- projectFile: 'superModule.vcxproj',
183
- cppHeaders: ['Garfield.h', 'Snoopy.h'],
184
- csPackageProviders: ['FamousAnimalCartoons'],
185
- },
186
- ],
187
- },
188
- },
189
- },
190
- }, {
191
- check: true,
192
- logging: false,
193
- proj: 'projects/SimpleCSharpApp/windows/SimpleCSharpApp/SimpleCSharpApp.csproj',
194
- });
195
- const replacements = autolink.getCsReplacements();
196
- expect(replacements.csUsingNamespaces).toContain('using Garfield;');
197
- expect(replacements.csReactPackageProviders).toContain('packageProviders.Add(new FamousAnimalCartoons())');
198
- });
199
- test('ensureXAMLDialect - useWinUI3=true in react-native.config.js, useWinUI3=false in ExperimentalFeatures.props', async () => {
200
- const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
201
- // Create project with UseWinUI3 == false in ExperimentalFeatures.props
202
- await (0, projectConfig_utils_1.ensureCppAppProject)(folder, 'WithWinUI3', false, false, false);
203
- const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
204
- const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
205
- // Set useWinUI3=true in react-native.config.js
206
- config.useWinUI3 = true;
207
- const al = new AutoLinkTest({ windows: config }, {}, {
208
- check: false,
209
- logging: false,
210
- });
211
- al.experimentalFeaturesProps = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>false</UseWinUI3></PropertyGroup></Project>`;
212
- al.packagesConfig = `<packages><package id="SuperPkg" version="42"/></packages>`;
213
- const exd = await al.ensureXAMLDialect();
214
- expect(exd).toBeTruthy();
215
- const expectedExperimentalFeatures = '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>true</UseWinUI3></PropertyGroup></Project>';
216
- expect(al.experimentalFeaturesProps).toEqual(expectedExperimentalFeatures);
217
- // example packages.config:
218
- // <packages>
219
- // <package id="SuperPkg" version="42"/>
220
- // <package id="Microsoft.WindowsAppSDK" version="1.0.0" targetFramework="native"/>
221
- // </packages>
222
- //
223
- expect(al.packagesConfig).toContain('Microsoft.WindowsAppSDK');
224
- expect(al.packagesConfig).toContain('<package id="SuperPkg" version="42"/>');
225
- expect(al.packagesConfig).not.toContain('Microsoft.UI.Xaml');
226
- });
227
- test('ensureXAMLDialect - useWinUI3=false in react-native.config.js, useWinUI3=true in ExperimentalFeatures.props', async () => {
228
- const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
229
- const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
230
- const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
231
- config.useWinUI3 = false;
232
- const al = new AutoLinkTest({ windows: config }, {}, {
233
- check: false,
234
- logging: false,
235
- });
236
- al.experimentalFeaturesProps = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>true</UseWinUI3></PropertyGroup></Project>`;
237
- al.packagesConfig = `<packages><package id="SuperPkg" version="42"/></packages>`;
238
- const exd = await al.ensureXAMLDialect();
239
- expect(exd).toBeTruthy();
240
- const expectedExperimentalFeatures = '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>false</UseWinUI3></PropertyGroup></Project>';
241
- expect(al.experimentalFeaturesProps).toEqual(expectedExperimentalFeatures);
242
- // example packages.config:
243
- // <packages>
244
- // <package id="SuperPkg" version="42"/>
245
- // <package id="Microsoft.WindowsAppSDK" version="1.0.0" targetFramework="native"/>
246
- // </packages>
247
- //
248
- expect(al.packagesConfig).not.toContain('Microsoft.WindowsAppSDK');
249
- expect(al.packagesConfig).toContain('<package id="SuperPkg" version="42"/>');
250
- expect(al.packagesConfig).toContain('Microsoft.UI.Xaml');
251
- });
252
- test('ensureXAMLDialect - useWinUI3 not in react-native.config.js, useWinUI3=true in ExperimentalFeatures.props', async () => {
253
- const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
254
- const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
255
- const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
256
- delete config.useWinUI3;
257
- const al = new AutoLinkTest({ windows: config }, {}, {
258
- check: false,
259
- logging: false,
260
- });
261
- al.experimentalFeaturesProps = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>true</UseWinUI3></PropertyGroup></Project>`;
262
- al.packagesConfig = `<packages><package id="SuperPkg" version="42"/></packages>`;
263
- const exd = await al.ensureXAMLDialect();
264
- expect(exd).toBeTruthy();
265
- const expectedExperimentalFeatures = '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>true</UseWinUI3></PropertyGroup></Project>';
266
- expect(al.experimentalFeaturesProps).toEqual(expectedExperimentalFeatures);
267
- // example packages.config:
268
- // <packages>
269
- // <package id="SuperPkg" version="42"/>
270
- // <package id="Microsoft.WindowsAppSDK" version="1.0.0" targetFramework="native"/>
271
- // </packages>
272
- //
273
- expect(al.packagesConfig).toContain('Microsoft.WindowsAppSDK');
274
- expect(al.packagesConfig).toContain('<package id="SuperPkg" version="42"/>');
275
- expect(al.packagesConfig).not.toContain('Microsoft.UI.Xaml');
276
- });
277
- test('ensureXAMLDialect - useWinUI3 not in react-native.config.js, useWinUI3=false in ExperimentalFeatures.props', async () => {
278
- const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
279
- const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
280
- const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
281
- delete config.useWinUI3;
282
- const al = new AutoLinkTest({ windows: config }, {}, {
283
- check: false,
284
- logging: false,
285
- });
286
- al.experimentalFeaturesProps = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>false</UseWinUI3></PropertyGroup></Project>`;
287
- al.packagesConfig = `<packages><package id="SuperPkg" version="42"/><package id="Microsoft.WindowsAppSDK"/></packages>`;
288
- const exd = await al.ensureXAMLDialect();
289
- expect(exd).toBeTruthy();
290
- const expectedExperimentalFeatures = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>false</UseWinUI3></PropertyGroup></Project>`;
291
- expect(al.experimentalFeaturesProps).toEqual(expectedExperimentalFeatures);
292
- // example packages.config:
293
- // <packages>
294
- // <package id="SuperPkg" version="42"/>
295
- // <package id="Microsoft.WindowsAppSDK" version="1.0.0" targetFramework="native"/>
296
- // </packages>
297
- //
298
- expect(al.packagesConfig).not.toContain('Microsoft.WindowsAppSDK');
299
- expect(al.packagesConfig).toContain('<package id="SuperPkg" version="42"/>');
300
- expect(al.packagesConfig).toContain('Microsoft.UI.Xaml');
301
- });
302
- test('Indirect autolink dependency', () => {
303
- const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
304
- superModule: {
305
- name: 'superModule',
306
- root: 'theRoot',
307
- platforms: {
308
- windows: {
309
- sourceDir: __dirname,
310
- projects: [
311
- {
312
- directDependency: true,
313
- projectFile: 'superModule.vcxproj',
314
- cppHeaders: ['Garfield.h', 'Snoopy.h'],
315
- cppPackageProviders: ['FamousAnimalCartoons'],
316
- },
317
- {
318
- directDependency: false,
319
- projectFile: 'indirect.vcxproj',
320
- },
321
- ],
322
- },
323
- },
324
- },
325
- }, {
326
- check: true,
327
- logging: false,
328
- proj: 'projects/WithIndirectDependency/windows/WithIndirectDependency/WithIndirectDependency.vcxproj',
329
- });
330
- const replacements = autolink.getCppReplacements();
331
- expect(replacements.cppIncludes).toMatch(/#include <Garfield.h>/);
332
- expect(replacements.cppIncludes).toMatch(/#include <Snoopy.h>/);
333
- expect(replacements.cppPackageProviders).toContain('packageProviders.Append(winrt::FamousAnimalCartoons())');
334
- });
335
- function validateOptionName(name, optionName) {
336
- // Do not add a default case here. Every item must explicitly return true
337
- switch (optionName) {
338
- case 'check':
339
- case 'logging':
340
- case 'sln':
341
- case 'proj':
342
- case 'telemetry':
343
- return true;
344
- }
345
- throw new Error(`Unable to find ${optionName} to match '${name}' in AutoLinkOptions.`);
346
- }
347
- test('autolinkOptions - validate options', () => {
348
- for (const commandOption of autolinkWindowsOptions_1.autolinkOptions) {
349
- // Validate names
350
- expect(commandOption.name).not.toBeNull();
351
- expect(commandOption.name.startsWith('--')).toBe(true);
352
- expect(commandOption.name).toBe(commandOption.name.trim());
353
- // Validate defaults
354
- if (!commandOption.name.endsWith(' [string]') &&
355
- !commandOption.name.endsWith(' [number]')) {
356
- // Commander ignores defaults for flags, so leave undefined to prevent confusion
357
- expect(commandOption.default).toBeUndefined();
358
- }
359
- // Validate description
360
- expect(commandOption.description).not.toBeNull();
361
- expect(commandOption.description).toBe(commandOption.description.trim());
362
- // Validate all command options are present in AutoLinkOptions
363
- const optionName = (0, telemetry_1.commanderNameToOptionName)(commandOption.name);
364
- expect(validateOptionName(commandOption.name, optionName)).toBe(true);
365
- }
366
- });
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const path_1 = __importDefault(require("path"));
12
+ const telemetry_1 = require("@react-native-windows/telemetry");
13
+ const projectConfig_1 = require("../commands/config/projectConfig");
14
+ const autolinkWindows_1 = require("../commands/autolinkWindows/autolinkWindows");
15
+ const autolinkWindowsOptions_1 = require("../commands/autolinkWindows/autolinkWindowsOptions");
16
+ const xmldom_1 = require("@xmldom/xmldom");
17
+ const projectConfig_utils_1 = require("./projectConfig.utils");
18
+ test('autolink with no windows project', () => {
19
+ expect(() => {
20
+ // eslint-disable-next-line no-new
21
+ new AutoLinkTest({}, {}, { check: true, logging: false });
22
+ }).toThrowError();
23
+ });
24
+ test('autolink with incomplete windows project', () => {
25
+ expect(() => {
26
+ const autolink = new AutoLinkTest({ windows: {} }, {}, { check: true, logging: false });
27
+ autolink.validateRequiredAppProperties();
28
+ }).toThrowError();
29
+ });
30
+ class AutoLinkTest extends autolinkWindows_1.AutoLinkWindows {
31
+ constructor() {
32
+ super(...arguments);
33
+ this.packagesConfig = '';
34
+ this.experimentalFeaturesProps = '';
35
+ }
36
+ getWindowsProjectConfig() {
37
+ return this.windowsAppConfig;
38
+ }
39
+ getPackagesConfigXml() {
40
+ return {
41
+ path: 'packages.config',
42
+ content: new xmldom_1.DOMParser().parseFromString(this.packagesConfig, 'application/xml'),
43
+ };
44
+ }
45
+ getExperimentalFeaturesPropsXml() {
46
+ return {
47
+ path: 'ExperimentalFeatures.props',
48
+ content: new xmldom_1.DOMParser().parseFromString(this.experimentalFeaturesProps, 'application/xml'),
49
+ };
50
+ }
51
+ async updateFile(filepath, content) {
52
+ if (filepath === 'packages.config') {
53
+ this.packagesConfig = content;
54
+ }
55
+ else if (filepath === 'ExperimentalFeatures.props') {
56
+ this.experimentalFeaturesProps = content;
57
+ }
58
+ else {
59
+ throw new Error(`Unknown path: ${filepath}`);
60
+ }
61
+ return true;
62
+ }
63
+ }
64
+ test('autolink fixup sln', () => {
65
+ const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.' } }, {}, { check: true, logging: false, sln: 'foo' });
66
+ expect(autolink.getWindowsProjectConfig().solutionFile).toBeUndefined();
67
+ expect(() => {
68
+ autolink.validateRequiredAppProperties();
69
+ }).toThrow();
70
+ autolink.fixUpForSlnOption();
71
+ expect(autolink.getWindowsProjectConfig().solutionFile).toEqual('foo');
72
+ expect(() => {
73
+ autolink.validateRequiredAppProperties();
74
+ }).toThrow();
75
+ });
76
+ test('autolink fixup proj', async () => {
77
+ const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {}, {
78
+ check: true,
79
+ logging: false,
80
+ proj: 'projects/WithWinUI3/windows/WithWinUI3/WithWinUI3.vcxproj',
81
+ });
82
+ expect(autolink.getWindowsProjectConfig().solutionFile).toEqual('foo.sln');
83
+ expect(autolink.getWindowsProjectConfig().project).toBeUndefined();
84
+ const folder = path_1.default.resolve('src/e2etest/projects/', 'WithWinUI3');
85
+ await (0, projectConfig_utils_1.ensureWinUI3Project)(folder);
86
+ expect(() => {
87
+ autolink.validateRequiredProjectProperties();
88
+ }).toThrow();
89
+ autolink.fixUpForProjOption();
90
+ const projectConfig = autolink.getWindowsProjectConfig().project;
91
+ expect(projectConfig).not.toBeUndefined();
92
+ expect(projectConfig.projectName).toEqual('WithWinUI3');
93
+ autolink.validateRequiredProjectProperties();
94
+ });
95
+ test('empty cpp autolink dependencies', () => {
96
+ const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {}, {
97
+ check: true,
98
+ logging: false,
99
+ proj: 'projects/WithWinUI3/windows/WithWinUI3/WithWinUI3.vcxproj',
100
+ });
101
+ const replacements = autolink.getCppReplacements();
102
+ expect(replacements.cppIncludes).toEqual('');
103
+ expect(replacements.cppPackageProviders).toEqual('\n UNREFERENCED_PARAMETER(packageProviders);');
104
+ });
105
+ test('one invalid cpp autolink dependency', () => {
106
+ const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
107
+ superModule: {
108
+ name: 'superModule',
109
+ root: 'theRoot',
110
+ platforms: {
111
+ windows: {},
112
+ },
113
+ },
114
+ }, {
115
+ check: true,
116
+ logging: false,
117
+ proj: 'projects/WithWinUI3/windows/WithWinUI3/WithWinUI3.vcxproj',
118
+ });
119
+ const replacements = autolink.getCppReplacements();
120
+ expect(replacements.cppIncludes).toEqual('');
121
+ expect(replacements.cppPackageProviders).toEqual('\n UNREFERENCED_PARAMETER(packageProviders);');
122
+ });
123
+ test('one invalid cs autolink dependency', () => {
124
+ const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
125
+ superModule: {
126
+ name: 'superModule',
127
+ root: 'theRoot',
128
+ platforms: {
129
+ windows: {},
130
+ },
131
+ },
132
+ }, {
133
+ check: true,
134
+ logging: false,
135
+ proj: 'projects/SimpleCSharpApp/windows/SimpleCSharpApp/SimpleCSharpApp.csproj',
136
+ });
137
+ const replacements = autolink.getCsReplacements();
138
+ expect(replacements.csUsingNamespaces).toEqual('');
139
+ expect(replacements.csReactPackageProviders).toEqual('');
140
+ });
141
+ test('one valid cpp autolink dependency', () => {
142
+ const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
143
+ superModule: {
144
+ name: 'superModule',
145
+ root: 'theRoot',
146
+ platforms: {
147
+ windows: {
148
+ sourceDir: __dirname,
149
+ projects: [
150
+ {
151
+ directDependency: true,
152
+ projectFile: 'superModule.vcxproj',
153
+ cppHeaders: ['Garfield.h', 'Snoopy.h'],
154
+ cppPackageProviders: ['FamousAnimalCartoons'],
155
+ },
156
+ ],
157
+ },
158
+ },
159
+ },
160
+ }, {
161
+ check: true,
162
+ logging: false,
163
+ proj: 'projects/WithWinUI3/windows/WithWinUI3/WithWinUI3.vcxproj',
164
+ });
165
+ const replacements = autolink.getCppReplacements();
166
+ expect(replacements.cppIncludes).toMatch(/#include <Garfield.h>/);
167
+ expect(replacements.cppIncludes).toMatch(/#include <Snoopy.h>/);
168
+ expect(replacements.cppPackageProviders).toContain('packageProviders.Append(winrt::FamousAnimalCartoons())');
169
+ });
170
+ test('one valid cs autolink dependency', () => {
171
+ const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
172
+ superModule: {
173
+ name: 'superModule',
174
+ root: 'theRoot',
175
+ platforms: {
176
+ windows: {
177
+ sourceDir: __dirname,
178
+ projects: [
179
+ {
180
+ directDependency: true,
181
+ csNamespaces: ['Garfield'],
182
+ projectFile: 'superModule.vcxproj',
183
+ cppHeaders: ['Garfield.h', 'Snoopy.h'],
184
+ csPackageProviders: ['FamousAnimalCartoons'],
185
+ },
186
+ ],
187
+ },
188
+ },
189
+ },
190
+ }, {
191
+ check: true,
192
+ logging: false,
193
+ proj: 'projects/SimpleCSharpApp/windows/SimpleCSharpApp/SimpleCSharpApp.csproj',
194
+ });
195
+ const replacements = autolink.getCsReplacements();
196
+ expect(replacements.csUsingNamespaces).toContain('using Garfield;');
197
+ expect(replacements.csReactPackageProviders).toContain('packageProviders.Add(new FamousAnimalCartoons())');
198
+ });
199
+ test('ensureXAMLDialect - useWinUI3=true in react-native.config.js, useWinUI3=false in ExperimentalFeatures.props', async () => {
200
+ const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
201
+ // Create project with UseWinUI3 == false in ExperimentalFeatures.props
202
+ await (0, projectConfig_utils_1.ensureCppAppProject)(folder, 'WithWinUI3', false, false, false);
203
+ const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
204
+ const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
205
+ // Set useWinUI3=true in react-native.config.js
206
+ config.useWinUI3 = true;
207
+ const al = new AutoLinkTest({ windows: config }, {}, {
208
+ check: false,
209
+ logging: false,
210
+ });
211
+ al.experimentalFeaturesProps = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>false</UseWinUI3></PropertyGroup></Project>`;
212
+ al.packagesConfig = `<packages><package id="SuperPkg" version="42"/></packages>`;
213
+ const exd = await al.ensureXAMLDialect();
214
+ expect(exd).toBeTruthy();
215
+ const expectedExperimentalFeatures = '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>true</UseWinUI3></PropertyGroup></Project>';
216
+ expect(al.experimentalFeaturesProps).toEqual(expectedExperimentalFeatures);
217
+ // example packages.config:
218
+ // <packages>
219
+ // <package id="SuperPkg" version="42"/>
220
+ // <package id="Microsoft.WindowsAppSDK" version="1.0.0" targetFramework="native"/>
221
+ // </packages>
222
+ //
223
+ expect(al.packagesConfig).toContain('Microsoft.WindowsAppSDK');
224
+ expect(al.packagesConfig).toContain('<package id="SuperPkg" version="42"/>');
225
+ expect(al.packagesConfig).not.toContain('Microsoft.UI.Xaml');
226
+ });
227
+ test('ensureXAMLDialect - useWinUI3=false in react-native.config.js, useWinUI3=true in ExperimentalFeatures.props', async () => {
228
+ const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
229
+ const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
230
+ const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
231
+ config.useWinUI3 = false;
232
+ const al = new AutoLinkTest({ windows: config }, {}, {
233
+ check: false,
234
+ logging: false,
235
+ });
236
+ al.experimentalFeaturesProps = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>true</UseWinUI3></PropertyGroup></Project>`;
237
+ al.packagesConfig = `<packages><package id="SuperPkg" version="42"/></packages>`;
238
+ const exd = await al.ensureXAMLDialect();
239
+ expect(exd).toBeTruthy();
240
+ const expectedExperimentalFeatures = '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>false</UseWinUI3></PropertyGroup></Project>';
241
+ expect(al.experimentalFeaturesProps).toEqual(expectedExperimentalFeatures);
242
+ // example packages.config:
243
+ // <packages>
244
+ // <package id="SuperPkg" version="42"/>
245
+ // <package id="Microsoft.WindowsAppSDK" version="1.0.0" targetFramework="native"/>
246
+ // </packages>
247
+ //
248
+ expect(al.packagesConfig).not.toContain('Microsoft.WindowsAppSDK');
249
+ expect(al.packagesConfig).toContain('<package id="SuperPkg" version="42"/>');
250
+ expect(al.packagesConfig).toContain('Microsoft.UI.Xaml');
251
+ });
252
+ test('ensureXAMLDialect - useWinUI3 not in react-native.config.js, useWinUI3=true in ExperimentalFeatures.props', async () => {
253
+ const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
254
+ const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
255
+ const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
256
+ delete config.useWinUI3;
257
+ const al = new AutoLinkTest({ windows: config }, {}, {
258
+ check: false,
259
+ logging: false,
260
+ });
261
+ al.experimentalFeaturesProps = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>true</UseWinUI3></PropertyGroup></Project>`;
262
+ al.packagesConfig = `<packages><package id="SuperPkg" version="42"/></packages>`;
263
+ const exd = await al.ensureXAMLDialect();
264
+ expect(exd).toBeTruthy();
265
+ const expectedExperimentalFeatures = '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>true</UseWinUI3></PropertyGroup></Project>';
266
+ expect(al.experimentalFeaturesProps).toEqual(expectedExperimentalFeatures);
267
+ // example packages.config:
268
+ // <packages>
269
+ // <package id="SuperPkg" version="42"/>
270
+ // <package id="Microsoft.WindowsAppSDK" version="1.0.0" targetFramework="native"/>
271
+ // </packages>
272
+ //
273
+ expect(al.packagesConfig).toContain('Microsoft.WindowsAppSDK');
274
+ expect(al.packagesConfig).toContain('<package id="SuperPkg" version="42"/>');
275
+ expect(al.packagesConfig).not.toContain('Microsoft.UI.Xaml');
276
+ });
277
+ test('ensureXAMLDialect - useWinUI3 not in react-native.config.js, useWinUI3=false in ExperimentalFeatures.props', async () => {
278
+ const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
279
+ const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
280
+ const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
281
+ delete config.useWinUI3;
282
+ const al = new AutoLinkTest({ windows: config }, {}, {
283
+ check: false,
284
+ logging: false,
285
+ });
286
+ al.experimentalFeaturesProps = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>false</UseWinUI3></PropertyGroup></Project>`;
287
+ al.packagesConfig = `<packages><package id="SuperPkg" version="42"/><package id="Microsoft.WindowsAppSDK"/></packages>`;
288
+ const exd = await al.ensureXAMLDialect();
289
+ expect(exd).toBeTruthy();
290
+ const expectedExperimentalFeatures = `<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><UseWinUI3>false</UseWinUI3></PropertyGroup></Project>`;
291
+ expect(al.experimentalFeaturesProps).toEqual(expectedExperimentalFeatures);
292
+ // example packages.config:
293
+ // <packages>
294
+ // <package id="SuperPkg" version="42"/>
295
+ // <package id="Microsoft.WindowsAppSDK" version="1.0.0" targetFramework="native"/>
296
+ // </packages>
297
+ //
298
+ expect(al.packagesConfig).not.toContain('Microsoft.WindowsAppSDK');
299
+ expect(al.packagesConfig).toContain('<package id="SuperPkg" version="42"/>');
300
+ expect(al.packagesConfig).toContain('Microsoft.UI.Xaml');
301
+ });
302
+ test('Indirect autolink dependency', () => {
303
+ const autolink = new AutoLinkTest({ windows: { folder: __dirname, sourceDir: '.', solutionFile: 'foo.sln' } }, {
304
+ superModule: {
305
+ name: 'superModule',
306
+ root: 'theRoot',
307
+ platforms: {
308
+ windows: {
309
+ sourceDir: __dirname,
310
+ projects: [
311
+ {
312
+ directDependency: true,
313
+ projectFile: 'superModule.vcxproj',
314
+ cppHeaders: ['Garfield.h', 'Snoopy.h'],
315
+ cppPackageProviders: ['FamousAnimalCartoons'],
316
+ },
317
+ {
318
+ directDependency: false,
319
+ projectFile: 'indirect.vcxproj',
320
+ },
321
+ ],
322
+ },
323
+ },
324
+ },
325
+ }, {
326
+ check: true,
327
+ logging: false,
328
+ proj: 'projects/WithIndirectDependency/windows/WithIndirectDependency/WithIndirectDependency.vcxproj',
329
+ });
330
+ const replacements = autolink.getCppReplacements();
331
+ expect(replacements.cppIncludes).toMatch(/#include <Garfield.h>/);
332
+ expect(replacements.cppIncludes).toMatch(/#include <Snoopy.h>/);
333
+ expect(replacements.cppPackageProviders).toContain('packageProviders.Append(winrt::FamousAnimalCartoons())');
334
+ });
335
+ function validateOptionName(name, optionName) {
336
+ // Do not add a default case here. Every item must explicitly return true
337
+ switch (optionName) {
338
+ case 'check':
339
+ case 'logging':
340
+ case 'sln':
341
+ case 'proj':
342
+ case 'telemetry':
343
+ return true;
344
+ }
345
+ throw new Error(`Unable to find ${optionName} to match '${name}' in AutoLinkOptions.`);
346
+ }
347
+ test('autolinkOptions - validate options', () => {
348
+ for (const commandOption of autolinkWindowsOptions_1.autolinkOptions) {
349
+ // Validate names
350
+ expect(commandOption.name).not.toBeNull();
351
+ expect(commandOption.name.startsWith('--')).toBe(true);
352
+ expect(commandOption.name).toBe(commandOption.name.trim());
353
+ // Validate defaults
354
+ if (!commandOption.name.endsWith(' [string]') &&
355
+ !commandOption.name.endsWith(' [number]')) {
356
+ // Commander ignores defaults for flags, so leave undefined to prevent confusion
357
+ expect(commandOption.default).toBeUndefined();
358
+ }
359
+ // Validate description
360
+ expect(commandOption.description).not.toBeNull();
361
+ expect(commandOption.description).toBe(commandOption.description.trim());
362
+ // Validate all command options are present in AutoLinkOptions
363
+ const optionName = (0, telemetry_1.commanderNameToOptionName)(commandOption.name);
364
+ expect(validateOptionName(commandOption.name, optionName)).toBe(true);
365
+ }
366
+ });
367
367
  //# sourceMappingURL=autolink.test.js.map