@react-native-windows/find-dotnet-tools 0.0.0-canary.2
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
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @react-native-windows/find-dotnet-tools
|
|
2
|
+
|
|
3
|
+
Helpers to locate .NET-based tools (e.g. PowerShell) restored via `dotnet tool restore` or
|
|
4
|
+
available on PATH.
|
|
5
|
+
|
|
6
|
+
Used to resolve tool paths consistently across local development and CI
|
|
7
|
+
environments.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Add the package as a dependency:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@react-native-windows/find-dotnet-tools": "<version>"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### findPowerShell
|
|
22
|
+
|
|
23
|
+
Locates a PowerShell executable by checking, in order:
|
|
24
|
+
|
|
25
|
+
1. A `dotnet-tool`-restored copy of `pwsh.exe` (skipped in CI builds)
|
|
26
|
+
2. `pwsh.exe` on the system PATH
|
|
27
|
+
|
|
28
|
+
Throws an error if `pwsh.exe` cannot be found.
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import {findPowerShell} from '@react-native-windows/find-dotnet-tools';
|
|
32
|
+
|
|
33
|
+
const pwsh = findPowerShell();
|
|
34
|
+
// e.g. "C:\\Users\\user\\.nuget\\packages\\PowerShell\\7.6.1\\tools\\net10.0\\any\\win\\pwsh.exe"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### getNugetGlobalPackagesFolder
|
|
38
|
+
|
|
39
|
+
Returns the path to the global NuGet packages folder by checking, in order:
|
|
40
|
+
|
|
41
|
+
1. The `NUGET_PACKAGES` environment variable
|
|
42
|
+
2. The output of `dotnet nuget locals global-packages --list`
|
|
43
|
+
3. The default `~/.nuget/packages` location
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import {getNugetGlobalPackagesFolder} from '@react-native-windows/find-dotnet-tools';
|
|
47
|
+
|
|
48
|
+
const packagesDir = getNugetGlobalPackagesFolder();
|
|
49
|
+
// e.g. "C:\\Users\\user\\.nuget\\packages"
|
|
50
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Returns the path to the global NuGet packages folder, checking (in order):
|
|
8
|
+
* 1. The NUGET_PACKAGES environment variable
|
|
9
|
+
* 2. The `dotnet nuget locals` command output
|
|
10
|
+
* 3. The default ~/.nuget/packages location
|
|
11
|
+
*/
|
|
12
|
+
export declare function getNugetGlobalPackagesFolder(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Locates a PowerShell executable, checking (in order):
|
|
15
|
+
* 1. A NuGet-restored copy of pwsh (skipped in CI builds)
|
|
16
|
+
* 2. pwsh.exe on the system PATH
|
|
17
|
+
*
|
|
18
|
+
* Throws if no pwsh.exe can be located.
|
|
19
|
+
*/
|
|
20
|
+
export declare function findPowerShell(): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
exports.findPowerShell = exports.getNugetGlobalPackagesFolder = void 0;
|
|
12
|
+
const child_process_1 = require("child_process");
|
|
13
|
+
const fs_1 = __importDefault(require("@react-native-windows/fs"));
|
|
14
|
+
const os_1 = __importDefault(require("os"));
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
/**
|
|
17
|
+
* Returns the path to the global NuGet packages folder, checking (in order):
|
|
18
|
+
* 1. The NUGET_PACKAGES environment variable
|
|
19
|
+
* 2. The `dotnet nuget locals` command output
|
|
20
|
+
* 3. The default ~/.nuget/packages location
|
|
21
|
+
*/
|
|
22
|
+
function getNugetGlobalPackagesFolder() {
|
|
23
|
+
if (process.env.NUGET_PACKAGES) {
|
|
24
|
+
return process.env.NUGET_PACKAGES;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const output = (0, child_process_1.execSync)('dotnet.exe nuget locals global-packages --list', {
|
|
28
|
+
encoding: 'utf8',
|
|
29
|
+
}).trim();
|
|
30
|
+
const match = output.match(/global-packages:\s*(.+)/i);
|
|
31
|
+
if (match) {
|
|
32
|
+
return match[1].trim();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch { }
|
|
36
|
+
return path_1.default.join(os_1.default.homedir(), '.nuget', 'packages');
|
|
37
|
+
}
|
|
38
|
+
exports.getNugetGlobalPackagesFolder = getNugetGlobalPackagesFolder;
|
|
39
|
+
/**
|
|
40
|
+
* Locates a PowerShell executable, checking (in order):
|
|
41
|
+
* 1. A NuGet-restored copy of pwsh (skipped in CI builds)
|
|
42
|
+
* 2. pwsh.exe on the system PATH
|
|
43
|
+
*
|
|
44
|
+
* Throws if no pwsh.exe can be located.
|
|
45
|
+
*/
|
|
46
|
+
function findPowerShell() {
|
|
47
|
+
// Build agents already have PowerShell (pwsh) installed
|
|
48
|
+
if (!process.env.TF_BUILD) {
|
|
49
|
+
const nugetPackages = getNugetGlobalPackagesFolder();
|
|
50
|
+
const nugetPwsh = path_1.default.join(nugetPackages, 'PowerShell', '7.6.1', 'tools', 'net10.0', 'any', 'win', 'pwsh.exe');
|
|
51
|
+
if (fs_1.default.existsSync(nugetPwsh)) {
|
|
52
|
+
return nugetPwsh;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const found = (0, child_process_1.execSync)('where pwsh.exe', { encoding: 'utf8' }).trim();
|
|
57
|
+
if (found) {
|
|
58
|
+
return found.split(/\r?\n/)[0];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch { }
|
|
62
|
+
throw new Error('Unable to find pwsh.exe. It should have been made available by `yarn install`.');
|
|
63
|
+
}
|
|
64
|
+
exports.findPowerShell = findPowerShell;
|
|
65
|
+
//# sourceMappingURL=findDotnetTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findDotnetTools.js","sourceRoot":"","sources":["../src/findDotnetTools.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,iDAAuC;AACvC,kEAA0C;AAC1C,4CAAoB;AACpB,gDAAwB;AAExB;;;;;GAKG;AACH,SAAgB,4BAA4B;IAC1C,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE;QAC9B,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;KACnC;IACD,IAAI;QACF,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,gDAAgD,EAAE;YACxE,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QACvD,IAAI,KAAK,EAAE;YACT,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACxB;KACF;IAAC,MAAM,GAAE;IACV,OAAO,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AACvD,CAAC;AAdD,oEAcC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc;IAC5B,wDAAwD;IACxD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QACzB,MAAM,aAAa,GAAG,4BAA4B,EAAE,CAAC;QACrD,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CACzB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,EACL,KAAK,EACL,UAAU,CACX,CAAC;QACF,IAAI,YAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;YAC5B,OAAO,SAAS,CAAC;SAClB;KACF;IAED,IAAI;QACF,MAAM,KAAK,GAAG,IAAA,wBAAQ,EAAC,gBAAgB,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACpE,IAAI,KAAK,EAAE;YACT,OAAO,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;SAChC;KACF;IAAC,MAAM,GAAE;IAEV,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;AACJ,CAAC;AA7BD,wCA6BC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport {execSync} from 'child_process';\nimport fs from '@react-native-windows/fs';\nimport os from 'os';\nimport path from 'path';\n\n/**\n * Returns the path to the global NuGet packages folder, checking (in order):\n * 1. The NUGET_PACKAGES environment variable\n * 2. The `dotnet nuget locals` command output\n * 3. The default ~/.nuget/packages location\n */\nexport function getNugetGlobalPackagesFolder(): string {\n if (process.env.NUGET_PACKAGES) {\n return process.env.NUGET_PACKAGES;\n }\n try {\n const output = execSync('dotnet.exe nuget locals global-packages --list', {\n encoding: 'utf8',\n }).trim();\n const match = output.match(/global-packages:\\s*(.+)/i);\n if (match) {\n return match[1].trim();\n }\n } catch {}\n return path.join(os.homedir(), '.nuget', 'packages');\n}\n\n/**\n * Locates a PowerShell executable, checking (in order):\n * 1. A NuGet-restored copy of pwsh (skipped in CI builds)\n * 2. pwsh.exe on the system PATH\n *\n * Throws if no pwsh.exe can be located.\n */\nexport function findPowerShell(): string {\n // Build agents already have PowerShell (pwsh) installed\n if (!process.env.TF_BUILD) {\n const nugetPackages = getNugetGlobalPackagesFolder();\n const nugetPwsh = path.join(\n nugetPackages,\n 'PowerShell',\n '7.6.1',\n 'tools',\n 'net10.0',\n 'any',\n 'win',\n 'pwsh.exe',\n );\n if (fs.existsSync(nugetPwsh)) {\n return nugetPwsh;\n }\n }\n\n try {\n const found = execSync('where pwsh.exe', {encoding: 'utf8'}).trim();\n if (found) {\n return found.split(/\\r?\\n/)[0];\n }\n } catch {}\n\n throw new Error(\n 'Unable to find pwsh.exe. It should have been made available by `yarn install`.',\n );\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native-windows/find-dotnet-tools",
|
|
3
|
+
"description": "Helpers to locate .NET-based tools (e.g. pwsh) restored via NuGet or available on PATH.",
|
|
4
|
+
"version": "0.0.0-canary.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rnw-scripts build",
|
|
8
|
+
"clean": "rnw-scripts clean",
|
|
9
|
+
"lint": "rnw-scripts lint",
|
|
10
|
+
"lint:fix": "rnw-scripts lint:fix",
|
|
11
|
+
"watch": "rnw-scripts watch"
|
|
12
|
+
},
|
|
13
|
+
"main": "lib-commonjs/findDotnetTools.js",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/microsoft/react-native-windows",
|
|
17
|
+
"directory": "packages/@react-native-windows/find-dotnet-tools"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@react-native-windows/fs": "^0.0.0-canary.72"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@rnw-scripts/eslint-config": "1.2.38",
|
|
24
|
+
"@rnw-scripts/just-task": "2.3.58",
|
|
25
|
+
"@rnw-scripts/ts-config": "2.0.6",
|
|
26
|
+
"@types/node": "^22.14.0",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^8.36.0",
|
|
28
|
+
"@typescript-eslint/parser": "^8.36.0",
|
|
29
|
+
"eslint": "^8.19.0",
|
|
30
|
+
"prettier": "^3.6.2",
|
|
31
|
+
"typescript": "5.0.4"
|
|
32
|
+
},
|
|
33
|
+
"beachball": {
|
|
34
|
+
"defaultNpmTag": "canary",
|
|
35
|
+
"disallowedChangeTypes": [
|
|
36
|
+
"major",
|
|
37
|
+
"minor",
|
|
38
|
+
"patch",
|
|
39
|
+
"premajor",
|
|
40
|
+
"preminor",
|
|
41
|
+
"prepatch"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
"promoteRelease": true,
|
|
45
|
+
"files": [
|
|
46
|
+
"lib-commonjs",
|
|
47
|
+
"README.md"
|
|
48
|
+
],
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">= 22"
|
|
51
|
+
}
|
|
52
|
+
}
|