@arcgis/node-toolkit 5.2.0-next.98 → 6.0.0-next.0
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/dist/codeowners.d.ts +35 -0
- package/dist/codeowners.js +50 -0
- package/dist/file.js +1 -1
- package/dist/glob.js +1 -1
- package/dist/packageJson.d.ts +13 -0
- package/dist/packageJson.js +24 -2
- package/dist/vite/presetPlugin.js +11 -2
- package/dist/vite/simpleTypesEmit.d.ts +7 -3
- package/dist/vite/simpleTypesEmit.js +28 -2
- package/package.json +3 -2
- package/dist/workspace.d.ts +0 -62
- package/dist/workspace.js +0 -78
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pattern and its owners from a CODEOWNERS file.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface CodeownersEntry {
|
|
7
|
+
pattern: string;
|
|
8
|
+
owners: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolves ownership using directory patterns, globs, and last-match precedence.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export interface Codeowners {
|
|
16
|
+
getOwners: (fileName: string) => string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads a CODEOWNERS file and returns its entries.
|
|
20
|
+
* Defaults to `.github/CODEOWNERS` in the nearest Git repository found from
|
|
21
|
+
* the current working directory. Throws if the repository or file is missing.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
* @param codeownersPath Optional explicit path to a CODEOWNERS file.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readCodeownersEntries(codeownersPath?: string | undefined): CodeownersEntry[];
|
|
27
|
+
/**
|
|
28
|
+
* Loads `.github/CODEOWNERS` from the nearest Git repository found from the
|
|
29
|
+
* current working directory. Returns undefined if the repository or file is missing.
|
|
30
|
+
* Returned ownership lookups accept file paths relative to the current working
|
|
31
|
+
* directory or absolute file paths.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadCodeowners(): Codeowners | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { path } from "./path.js";
|
|
2
|
+
import { findPath } from "./file.js";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import picomatch from "picomatch";
|
|
5
|
+
function readCodeownersEntries(codeownersPath = findCodeownersPath()) {
|
|
6
|
+
if (!codeownersPath) {
|
|
7
|
+
throw new Error(`Unable to find Git repository from current working directory: ${process.cwd()}`);
|
|
8
|
+
}
|
|
9
|
+
return parseCodeownersEntries(readFileSync(codeownersPath, "utf8"));
|
|
10
|
+
}
|
|
11
|
+
function loadCodeowners() {
|
|
12
|
+
const codeownersPath = findCodeownersPath();
|
|
13
|
+
return codeownersPath && existsSync(codeownersPath) ? createCodeowners(readCodeownersEntries(codeownersPath), path.dirname(path.dirname(codeownersPath))) : void 0;
|
|
14
|
+
}
|
|
15
|
+
function findCodeownersPath() {
|
|
16
|
+
const gitPath = findPath(".git");
|
|
17
|
+
return gitPath ? path.join(path.dirname(gitPath), ".github", "CODEOWNERS") : void 0;
|
|
18
|
+
}
|
|
19
|
+
function parseCodeownersEntries(contents) {
|
|
20
|
+
return contents.split(/\r?\n/u).map((line) => line.trim()).filter((line) => line !== "" && !line.startsWith("#")).map((line) => {
|
|
21
|
+
const [pattern, ...owners] = line.split(/\s+/u);
|
|
22
|
+
return { pattern, owners };
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function createCodeowners(rawEntries, repositoryRoot) {
|
|
26
|
+
const entries = rawEntries.map(({ pattern, owners }) => {
|
|
27
|
+
const normalizedPattern = pattern.startsWith("/") ? pattern.slice(1) : pattern;
|
|
28
|
+
const matcherPattern = normalizedPattern.includes("/") ? normalizedPattern : `**/${normalizedPattern}`;
|
|
29
|
+
return {
|
|
30
|
+
matches: picomatch([matcherPattern, `${matcherPattern.replace(/\/$/u, "")}/**`], { dot: true }),
|
|
31
|
+
owners
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
getOwners(fileName) {
|
|
36
|
+
const relativeFileName = path.relative(repositoryRoot, fileName);
|
|
37
|
+
let owners = [];
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
if (entry.matches(relativeFileName)) {
|
|
40
|
+
owners = entry.owners;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return owners;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
loadCodeowners,
|
|
49
|
+
readCodeownersEntries
|
|
50
|
+
};
|
package/dist/file.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { access, existsSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { mkdir, writeFile, constants } from "node:fs/promises";
|
|
3
3
|
import { dirname, resolve, sep, join } from "path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
const existsAsync = async (file) => (
|
package/dist/glob.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
function gitIgnoreFileToGlobs(filePath) {
|
|
3
3
|
return readFileSync(filePath, "utf8").split("\n").filter((line) => line.trim().length > 0 && !line.trim().startsWith("#")).map(gitIgnoreToGlob);
|
|
4
4
|
}
|
|
5
|
-
const gitIgnoreToGlob = (pattern) => fixAbsoluteSyntax(fixMatchFilesSyntax(pattern));
|
|
5
|
+
const gitIgnoreToGlob = (pattern) => fixAbsoluteSyntax(fixMatchFilesSyntax(pattern.trim()));
|
|
6
6
|
function fixAbsoluteSyntax(pattern) {
|
|
7
7
|
if (pattern.startsWith("/")) {
|
|
8
8
|
return pattern.slice(1);
|
package/dist/packageJson.d.ts
CHANGED
|
@@ -102,3 +102,16 @@ export declare function fetchPackageLocation(packageName: string, cwd?: string):
|
|
|
102
102
|
* @param packageName
|
|
103
103
|
*/
|
|
104
104
|
export declare function findPackageJson(packageName: string): PackageJson | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Detect the package manager from the nearest ancestor package.json with a packageManager field.
|
|
107
|
+
* Defaults to npm when no package manager is declared.
|
|
108
|
+
* Uses retrievePackageJson's cached manifest reads.
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const packageManager = detectPackageManager();
|
|
112
|
+
* console.log(packageManager); // e.g., "npm" or "pnpm"
|
|
113
|
+
* ```
|
|
114
|
+
* @public
|
|
115
|
+
* @param cwd The current working directory to start searching for the package manager from. Defaults to process.cwd().
|
|
116
|
+
*/
|
|
117
|
+
export declare function detectPackageManager(cwd?: string): string;
|
package/dist/packageJson.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { path } from "./path.js";
|
|
3
|
-
import {
|
|
3
|
+
import { findPath, asyncFindPath } from "./file.js";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
const cachedPackageJson = {};
|
|
6
6
|
const cachedPackageJsonPromises = {};
|
|
@@ -34,7 +34,7 @@ async function fetchPackageLocation(packageName, cwd) {
|
|
|
34
34
|
).then((packageJsonLocation) => {
|
|
35
35
|
if (packageJsonLocation === void 0) {
|
|
36
36
|
throw Error(
|
|
37
|
-
|
|
37
|
+
`Unable to resolve package.json location for "${packageName}" package. Current working directory: ${process.cwd()}`
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
40
|
return path.dirname(packageJsonLocation);
|
|
@@ -50,8 +50,30 @@ function findPackageJson(packageName) {
|
|
|
50
50
|
}
|
|
51
51
|
return retrievePackageJson(path2);
|
|
52
52
|
}
|
|
53
|
+
function detectPackageManager(cwd = process.cwd()) {
|
|
54
|
+
let packageManager = void 0;
|
|
55
|
+
let directory = path.resolve(cwd);
|
|
56
|
+
for (; ; ) {
|
|
57
|
+
const packageJsonPath = findPath("package.json", directory);
|
|
58
|
+
if (packageJsonPath === void 0) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const packageDirectory = path.dirname(packageJsonPath);
|
|
62
|
+
const contents = retrievePackageJson(packageDirectory);
|
|
63
|
+
if (typeof contents === "object" && !Array.isArray(contents) && typeof contents.packageManager === "string") {
|
|
64
|
+
packageManager ??= contents.packageManager.match(/\w+/u)?.[0] ?? packageManager;
|
|
65
|
+
}
|
|
66
|
+
directory = path.dirname(packageDirectory);
|
|
67
|
+
if (directory === packageDirectory) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
packageManager ??= "npm";
|
|
72
|
+
return packageManager;
|
|
73
|
+
}
|
|
53
74
|
export {
|
|
54
75
|
asyncRetrievePackageJson,
|
|
76
|
+
detectPackageManager,
|
|
55
77
|
fetchPackageLocation,
|
|
56
78
|
findPackageJson,
|
|
57
79
|
retrievePackageJson
|
|
@@ -3,6 +3,10 @@ import { externalizeDependencies } from "./externalizeDependenciesPlugin.js";
|
|
|
3
3
|
function shouldSkip(id) {
|
|
4
4
|
return id.includes("__test") || id.includes(".e2e.") || id.includes(".spec.") || id.includes(".test.") || id.includes(".stories.");
|
|
5
5
|
}
|
|
6
|
+
const hashlessOutputNames = {
|
|
7
|
+
assetFileNames: "assets/[name][extname]",
|
|
8
|
+
chunkFileNames: "chunks/[name].js"
|
|
9
|
+
};
|
|
6
10
|
function vitePresetPlugin({ dtsOptions = {}, externalize, bundleIn, isApplication } = {
|
|
7
11
|
externalize: [],
|
|
8
12
|
dtsOptions: {}
|
|
@@ -13,13 +17,18 @@ function vitePresetPlugin({ dtsOptions = {}, externalize, bundleIn, isApplicatio
|
|
|
13
17
|
return [
|
|
14
18
|
{
|
|
15
19
|
name: "vite-preset-config",
|
|
16
|
-
config(
|
|
20
|
+
config(config, env) {
|
|
17
21
|
command = env.command;
|
|
22
|
+
const { rollupOptions, ssr, target } = config.build ?? {};
|
|
23
|
+
const isBrowserApplication = isApplication && !ssr && !env.isSsrBuild;
|
|
24
|
+
const output = rollupOptions?.output;
|
|
25
|
+
const hashlessOutput = Array.isArray(output) ? output.map((entry) => ({ ...hashlessOutputNames, ...entry })) : { ...hashlessOutputNames, ...output };
|
|
18
26
|
return {
|
|
19
27
|
build: {
|
|
20
28
|
// REFACTOR: get this from tsconfig
|
|
21
29
|
// It's a best practice to let the final bundler down-level as needed.
|
|
22
|
-
target: target ?? "es2024"
|
|
30
|
+
target: target ?? "es2024",
|
|
31
|
+
rollupOptions: isBrowserApplication ? void 0 : { output: hashlessOutput }
|
|
23
32
|
},
|
|
24
33
|
define: env.mode === "test" ? {
|
|
25
34
|
"process.env.ESRI_INTERNAL": true
|
|
@@ -6,8 +6,8 @@ import type { Plugin } from "vite";
|
|
|
6
6
|
* Do not use this plugin for new code.
|
|
7
7
|
* Use https://webgis.esri.com/references/api-extractor/integrations instead.
|
|
8
8
|
*
|
|
9
|
-
* This exists only for usage by `@arcgis/toolkit
|
|
10
|
-
* `@arcgis/node-toolkit` as they cannot use API Extractor to avoid a
|
|
9
|
+
* This exists only for usage by `@arcgis/toolkit`,
|
|
10
|
+
* `@arcgis/node-toolkit`, and `@webgis/monorepo-toolkit` as they cannot use API Extractor to avoid a
|
|
11
11
|
* cyclical dependency.
|
|
12
12
|
*
|
|
13
13
|
* This serves as a minimal replacement for vite-plugin-dts. For comparison,
|
|
@@ -15,5 +15,9 @@ import type { Plugin } from "vite";
|
|
|
15
15
|
* vite-plugin-dts.
|
|
16
16
|
*
|
|
17
17
|
* @public
|
|
18
|
+
* @param options Declaration emission options.
|
|
19
|
+
* @param options.mapDeclarationImport Optional mapping for module specifiers in emitted declarations.
|
|
18
20
|
*/
|
|
19
|
-
export declare function simpleTypesEmit(
|
|
21
|
+
export declare function simpleTypesEmit({ mapDeclarationImport, }?: {
|
|
22
|
+
mapDeclarationImport?: (specifier: string) => string;
|
|
23
|
+
}): Plugin;
|
|
@@ -2,7 +2,9 @@ import ts from "typescript";
|
|
|
2
2
|
import { loadTypeScriptConfig } from "./typeScript.js";
|
|
3
3
|
import { path } from "../path.js";
|
|
4
4
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
|
-
function simpleTypesEmit(
|
|
5
|
+
function simpleTypesEmit({
|
|
6
|
+
mapDeclarationImport
|
|
7
|
+
} = {}) {
|
|
6
8
|
let oldProgram;
|
|
7
9
|
let isWatchMode = false;
|
|
8
10
|
const sourcePrefix = path.join(process.cwd(), "src/");
|
|
@@ -42,7 +44,8 @@ function simpleTypesEmit() {
|
|
|
42
44
|
);
|
|
43
45
|
},
|
|
44
46
|
void 0,
|
|
45
|
-
true
|
|
47
|
+
true,
|
|
48
|
+
mapDeclarationImport ? { afterDeclarations: [createDeclarationImportTransformer(mapDeclarationImport)] } : void 0
|
|
46
49
|
);
|
|
47
50
|
allDiagnostics.push(...diagnostics.diagnostics);
|
|
48
51
|
}
|
|
@@ -66,6 +69,29 @@ function simpleTypesEmit() {
|
|
|
66
69
|
}
|
|
67
70
|
};
|
|
68
71
|
}
|
|
72
|
+
function createDeclarationImportTransformer(mapDeclarationImport) {
|
|
73
|
+
return (context) => {
|
|
74
|
+
let parent;
|
|
75
|
+
let importTypeArgument;
|
|
76
|
+
const visit = (node) => {
|
|
77
|
+
if (ts.isStringLiteral(node) && parent !== void 0 && (ts.isImportDeclaration(parent) || ts.isExportDeclaration(parent) || ts.isLiteralTypeNode(parent) && parent === importTypeArgument)) {
|
|
78
|
+
const specifier = mapDeclarationImport(node.text);
|
|
79
|
+
return specifier === node.text ? node : context.factory.createStringLiteral(specifier);
|
|
80
|
+
}
|
|
81
|
+
const previousParent = parent;
|
|
82
|
+
const previousImportTypeArgument = importTypeArgument;
|
|
83
|
+
parent = node;
|
|
84
|
+
if (ts.isImportTypeNode(node)) {
|
|
85
|
+
importTypeArgument = node.argument;
|
|
86
|
+
}
|
|
87
|
+
const result = ts.visitEachChild(node, visit, context);
|
|
88
|
+
parent = previousParent;
|
|
89
|
+
importTypeArgument = previousImportTypeArgument;
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
return (root) => ts.visitNode(root, visit);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
69
95
|
const isIncludedFile = (filePath, prefix) => isPermittedFile(filePath) && isInIncludedFolder(filePath, prefix);
|
|
70
96
|
const isPermittedFile = (filePath) => (filePath.endsWith(".ts") || filePath.endsWith(".tsx")) && !isTestFile(filePath) && !isStoryFile(filePath);
|
|
71
97
|
const isTestFile = (filePath) => filePath.includes("__test") || filePath.includes(".e2e.") || filePath.includes(".spec.") || filePath.includes(".test.");
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcgis/node-toolkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-next.0",
|
|
4
4
|
"description": "Collection of common internal build-time patterns and utilities for ArcGIS Maps SDK for JavaScript components.",
|
|
5
5
|
"homepage": "https://developers.arcgis.com/javascript/latest/",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
|
+
"./codeowners": "./dist/codeowners.js",
|
|
8
9
|
"./file": "./dist/file.js",
|
|
9
10
|
"./shell": "./dist/shell.js",
|
|
10
11
|
"./glob": "./dist/glob.js",
|
|
@@ -15,7 +16,6 @@
|
|
|
15
16
|
"./vite/installPlaywright": "./dist/vite/installPlaywright.js",
|
|
16
17
|
"./vite/simpleTypesEmit": "./dist/vite/simpleTypesEmit.js",
|
|
17
18
|
"./vite/typeScript": "./dist/vite/typeScript.js",
|
|
18
|
-
"./workspace": "./dist/workspace.js",
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@types/node": "~24.11.2",
|
|
27
|
+
"picomatch": "^4.0.4",
|
|
27
28
|
"tslib": "^2.8.1",
|
|
28
29
|
"typescript": "~6.0.3",
|
|
29
30
|
"vite": "^7.3.2",
|
package/dist/workspace.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set the target file to use when finding the root of the repository.
|
|
3
|
-
* By default, it looks for the pnpm-lock.yaml file, but you can specify a different target file if needed.
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
* @param target
|
|
7
|
-
*/
|
|
8
|
-
export declare function setRootTargetFile(target: string): void;
|
|
9
|
-
/**
|
|
10
|
-
* Locate the root directory by finding a target file.
|
|
11
|
-
* By default, it looks for the pnpm-lock.yaml file, but you can call setRootTargetFile to specify a different target file if needed.
|
|
12
|
-
*
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export declare function findRepositoryRoot(): string;
|
|
16
|
-
/**
|
|
17
|
-
* Get the path to the Turbo CLI. This allows us to directly invoke it without incurring the overhead of going through
|
|
18
|
-
* the package manager.
|
|
19
|
-
*
|
|
20
|
-
* @public
|
|
21
|
-
* @param repositoryRoot
|
|
22
|
-
*/
|
|
23
|
-
export declare function getTurboPath(repositoryRoot?: string): string;
|
|
24
|
-
/**
|
|
25
|
-
* Parse a version string into its components.
|
|
26
|
-
*
|
|
27
|
-
* @public
|
|
28
|
-
* @param version
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const parsed = parseVersion("4.34.0-next.123");
|
|
32
|
-
* // { major: 4, minor: 34, patch: 0, prerelease: ["next", 123], majorMinorVersion: "4.34", cdnVersion: "4.34.0-next" }
|
|
33
|
-
* const parsed = parseVersion("5.2.20");
|
|
34
|
-
* // { major: 5, minor: 2, patch: 20, prerelease: [], majorMinorVersion: "5.2", cdnVersion: "5.2.20" }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare const parseVersion: (version: string) => {
|
|
38
|
-
major: string;
|
|
39
|
-
minor: string;
|
|
40
|
-
patch: string;
|
|
41
|
-
prerelease: string[];
|
|
42
|
-
majorMinorVersion: string;
|
|
43
|
-
cdnVersion: string;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Get the system version from the root package.json. The system version is the version of the monorepo as a whole, and is used for deployment and publishing.
|
|
47
|
-
* The majorMinorVersion is major.minor version of the system version, and is used for deployment and publishing.
|
|
48
|
-
* The cdnVersion is the system version without any pre-release or build metadata, and is used for deployment and publishing
|
|
49
|
-
* (e.g. 1.2.3-next.4 becomes 1.2.3-next and 5.2.1 stays 5.2.1).
|
|
50
|
-
*
|
|
51
|
-
* @public
|
|
52
|
-
*/
|
|
53
|
-
export declare function getSystemVersion(): ReturnType<typeof parseVersion> & {
|
|
54
|
-
version: string;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Detect if current repository/monorepo uses npm, pnpm, or yarn
|
|
58
|
-
*
|
|
59
|
-
* @public
|
|
60
|
-
* @param cwd
|
|
61
|
-
*/
|
|
62
|
-
export declare function detectPackageManager(cwd?: string): string;
|
package/dist/workspace.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { findPath } from "./file.js";
|
|
2
|
-
import { retrievePackageJson } from "./packageJson.js";
|
|
3
|
-
import { path } from "./path.js";
|
|
4
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
-
let rootTargetFile = "pnpm-lock.yaml";
|
|
6
|
-
function setRootTargetFile(target) {
|
|
7
|
-
rootTargetFile = target;
|
|
8
|
-
}
|
|
9
|
-
function findRepositoryRoot() {
|
|
10
|
-
const lockFilePath = findPath(rootTargetFile);
|
|
11
|
-
if (!lockFilePath) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`Unable to find root with target "${rootTargetFile}" from current working directory: ${process.cwd()}`
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
return path.dirname(lockFilePath);
|
|
17
|
-
}
|
|
18
|
-
function getTurboPath(repositoryRoot = findRepositoryRoot()) {
|
|
19
|
-
return path.join(repositoryRoot, "node_modules/turbo/bin/turbo");
|
|
20
|
-
}
|
|
21
|
-
const parseVersion = (version) => {
|
|
22
|
-
const versionParts = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prereleaseParts>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u.exec(
|
|
23
|
-
version
|
|
24
|
-
);
|
|
25
|
-
if (!versionParts?.groups) {
|
|
26
|
-
throw new Error(`Unable to parse version "${version}"`);
|
|
27
|
-
}
|
|
28
|
-
const { major, minor, patch, prereleaseParts } = versionParts.groups;
|
|
29
|
-
const prerelease = prereleaseParts ? prereleaseParts.split(".") : [];
|
|
30
|
-
const majorMinorVersion = `${major}.${minor}`;
|
|
31
|
-
const cdnVersion = prerelease[0] ? `${majorMinorVersion}.${patch}-${prerelease[0]}` : `${majorMinorVersion}.${patch}`;
|
|
32
|
-
return {
|
|
33
|
-
major,
|
|
34
|
-
minor,
|
|
35
|
-
patch,
|
|
36
|
-
prerelease,
|
|
37
|
-
majorMinorVersion,
|
|
38
|
-
cdnVersion
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
function getSystemVersion() {
|
|
42
|
-
const repositoryRoot = findRepositoryRoot();
|
|
43
|
-
const version = retrievePackageJson(repositoryRoot).version;
|
|
44
|
-
if (!version) {
|
|
45
|
-
throw new Error("Root package.json does not have a version defined");
|
|
46
|
-
}
|
|
47
|
-
return { version, ...parseVersion(version) };
|
|
48
|
-
}
|
|
49
|
-
function detectPackageManager(cwd = process.cwd()) {
|
|
50
|
-
let packageManager = void 0;
|
|
51
|
-
{
|
|
52
|
-
const pathParts = path.resolve(cwd).split(path.sep);
|
|
53
|
-
while (pathParts.length > 1) {
|
|
54
|
-
const packageJson = path.join(pathParts.join(path.sep), "package.json");
|
|
55
|
-
pathParts.pop();
|
|
56
|
-
if (!existsSync(packageJson)) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const contents = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
60
|
-
if (typeof contents !== "object" || Array.isArray(contents)) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if (typeof contents.packageManager === "string") {
|
|
64
|
-
packageManager ??= contents.packageManager.match(/\w+/u)?.[0] ?? packageManager;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
packageManager ??= "npm";
|
|
69
|
-
return packageManager;
|
|
70
|
-
}
|
|
71
|
-
export {
|
|
72
|
-
detectPackageManager,
|
|
73
|
-
findRepositoryRoot,
|
|
74
|
-
getSystemVersion,
|
|
75
|
-
getTurboPath,
|
|
76
|
-
parseVersion,
|
|
77
|
-
setRootTargetFile
|
|
78
|
-
};
|