@arcgis/node-toolkit 5.2.0-next.57 → 5.2.0-next.59
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/packageJson.d.ts +3 -2
- package/dist/packageJson.js +7 -22
- package/dist/workspace.d.ts +42 -0
- package/dist/workspace.js +74 -0
- package/package.json +2 -1
package/dist/packageJson.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export declare function asyncRetrievePackageJson(location?: string): Promise<Pac
|
|
|
59
59
|
*/
|
|
60
60
|
export declare function fetchPackageLocation(packageName: string, cwd?: string): Promise<string>;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Find the package.json for a given package name in node_modules, and return the parsed JSON.
|
|
63
|
+
* Returns undefined if the package.json cannot be found.
|
|
63
64
|
*/
|
|
64
|
-
export declare function
|
|
65
|
+
export declare function findPackageJson(packageName: string): PackageJson | undefined;
|
package/dist/packageJson.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { path } from "./path.js";
|
|
3
3
|
import { asyncFindPath, findPath } from "./file.js";
|
|
4
|
-
import {
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
5
|
const cachedPackageJson = {};
|
|
6
6
|
const cachedPackageJsonPromises = {};
|
|
7
7
|
let rootPackageJsonLocation;
|
|
@@ -43,31 +43,16 @@ async function fetchPackageLocation(packageName, cwd) {
|
|
|
43
43
|
cachedPackageLocation[packageName] ??= result;
|
|
44
44
|
return cachedPackageLocation[packageName];
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
while (pathParts.length > 1) {
|
|
51
|
-
const packageJson = path.join(pathParts.join(path.sep), "package.json");
|
|
52
|
-
pathParts.pop();
|
|
53
|
-
if (!existsSync(packageJson)) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const contents = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
57
|
-
if (typeof contents !== "object" || Array.isArray(contents)) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (typeof contents.packageManager === "string") {
|
|
61
|
-
packageManager ??= contents.packageManager.match(/\w+/u)?.[0] ?? packageManager;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
46
|
+
function findPackageJson(packageName) {
|
|
47
|
+
const path2 = findPath(`node_modules/${packageName}/`);
|
|
48
|
+
if (!path2) {
|
|
49
|
+
return void 0;
|
|
64
50
|
}
|
|
65
|
-
|
|
66
|
-
return packageManager;
|
|
51
|
+
return retrievePackageJson(path2);
|
|
67
52
|
}
|
|
68
53
|
export {
|
|
69
54
|
asyncRetrievePackageJson,
|
|
70
|
-
detectPackageManager,
|
|
71
55
|
fetchPackageLocation,
|
|
56
|
+
findPackageJson,
|
|
72
57
|
retrievePackageJson
|
|
73
58
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
export declare function setRootTargetFile(target: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Locate the root directory by finding a target file.
|
|
8
|
+
* By default, it looks for the pnpm-lock.yaml file, but you can call setRootTargetFile to specify a different target file if needed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function findRepositoryRoot(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Parse a version string into its components.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const parsed = parseVersion("4.34.0-next.123");
|
|
17
|
+
* // { major: 4, minor: 34, patch: 0, prerelease: ["next", 123], majorMinorVersion: "4.34", cdnVersion: "4.34.0-next" }
|
|
18
|
+
* const parsed = parseVersion("5.2.20");
|
|
19
|
+
* // { major: 5, minor: 2, patch: 20, prerelease: [], majorMinorVersion: "5.2", cdnVersion: "5.2.20" }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const parseVersion: (version: string) => {
|
|
23
|
+
major: string;
|
|
24
|
+
minor: string;
|
|
25
|
+
patch: string;
|
|
26
|
+
prerelease: string[];
|
|
27
|
+
majorMinorVersion: string;
|
|
28
|
+
cdnVersion: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 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.
|
|
32
|
+
* The majorMinorVersion is major.minor version of the system version, and is used for deployment and publishing.
|
|
33
|
+
* The cdnVersion is the system version without any pre-release or build metadata, and is used for deployment and publishing
|
|
34
|
+
* (e.g. 1.2.3-next.4 becomes 1.2.3-next and 5.2.1 stays 5.2.1).
|
|
35
|
+
*/
|
|
36
|
+
export declare function getSystemVersion(): ReturnType<typeof parseVersion> & {
|
|
37
|
+
version: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Detect if current repository/monorepo uses npm, pnpm, or yarn
|
|
41
|
+
*/
|
|
42
|
+
export declare function detectPackageManager(cwd?: string): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
const parseVersion = (version) => {
|
|
19
|
+
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(
|
|
20
|
+
version
|
|
21
|
+
);
|
|
22
|
+
if (!versionParts?.groups) {
|
|
23
|
+
throw new Error(`Unable to parse version "${version}"`);
|
|
24
|
+
}
|
|
25
|
+
const { major, minor, patch, prereleaseParts } = versionParts.groups;
|
|
26
|
+
const prerelease = prereleaseParts ? prereleaseParts.split(".") : [];
|
|
27
|
+
const majorMinorVersion = `${major}.${minor}`;
|
|
28
|
+
const cdnVersion = prerelease[0] ? `${majorMinorVersion}.${patch}-${prerelease[0]}` : `${majorMinorVersion}.${patch}`;
|
|
29
|
+
return {
|
|
30
|
+
major,
|
|
31
|
+
minor,
|
|
32
|
+
patch,
|
|
33
|
+
prerelease,
|
|
34
|
+
majorMinorVersion,
|
|
35
|
+
cdnVersion
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
function getSystemVersion() {
|
|
39
|
+
const repositoryRoot = findRepositoryRoot();
|
|
40
|
+
const version = retrievePackageJson(repositoryRoot).version;
|
|
41
|
+
if (!version) {
|
|
42
|
+
throw new Error("Root package.json does not have a version defined");
|
|
43
|
+
}
|
|
44
|
+
return { version, ...parseVersion(version) };
|
|
45
|
+
}
|
|
46
|
+
function detectPackageManager(cwd = process.cwd()) {
|
|
47
|
+
let packageManager = void 0;
|
|
48
|
+
{
|
|
49
|
+
const pathParts = path.resolve(cwd).split(path.sep);
|
|
50
|
+
while (pathParts.length > 1) {
|
|
51
|
+
const packageJson = path.join(pathParts.join(path.sep), "package.json");
|
|
52
|
+
pathParts.pop();
|
|
53
|
+
if (!existsSync(packageJson)) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const contents = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
57
|
+
if (typeof contents !== "object" || Array.isArray(contents)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (typeof contents.packageManager === "string") {
|
|
61
|
+
packageManager ??= contents.packageManager.match(/\w+/u)?.[0] ?? packageManager;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
packageManager ??= "npm";
|
|
66
|
+
return packageManager;
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
detectPackageManager,
|
|
70
|
+
findRepositoryRoot,
|
|
71
|
+
getSystemVersion,
|
|
72
|
+
parseVersion,
|
|
73
|
+
setRootTargetFile
|
|
74
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcgis/node-toolkit",
|
|
3
|
-
"version": "5.2.0-next.
|
|
3
|
+
"version": "5.2.0-next.59",
|
|
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",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"./packageJson": "./dist/packageJson.js",
|
|
13
13
|
"./vite/presetPlugin": "./dist/vite/presetPlugin.js",
|
|
14
14
|
"./vite/externalizeDependenciesPlugin": "./dist/vite/externalizeDependenciesPlugin.js",
|
|
15
|
+
"./workspace": "./dist/workspace.js",
|
|
15
16
|
"./package.json": "./package.json"
|
|
16
17
|
},
|
|
17
18
|
"files": [
|