@aws-sdk/util-user-agent-node 3.973.0 → 3.973.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.
package/dist-cjs/index.js CHANGED
@@ -16,18 +16,31 @@ const getRuntimeUserAgentPair = () => {
16
16
  return ["md/nodejs", node_process.versions.node];
17
17
  };
18
18
 
19
- const getTypeScriptPackageJsonPath = (dirname = "") => {
20
- let nodeModulesPath;
19
+ const SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/;
20
+ const getSanitizedTypeScriptVersion = (version = "") => {
21
+ const match = version.match(SEMVER_REGEX);
22
+ if (!match) {
23
+ return undefined;
24
+ }
25
+ const [major, minor, patch, prerelease] = [match[1], match[2], match[3], match[4]];
26
+ return prerelease ? `${major}.${minor}.${patch}-${prerelease}` : `${major}.${minor}.${patch}`;
27
+ };
28
+
29
+ const typescriptPackageJsonPath = node_path.join("node_modules", "typescript", "package.json");
30
+ const getTypeScriptPackageJsonPaths = (dirname) => {
31
+ const cwdPath = node_path.join(process.cwd(), typescriptPackageJsonPath);
32
+ if (!dirname) {
33
+ return [cwdPath];
34
+ }
21
35
  const normalizedPath = node_path.normalize(dirname);
22
36
  const parts = normalizedPath.split(node_path.sep);
23
37
  const nodeModulesIndex = parts.indexOf("node_modules");
24
- if (nodeModulesIndex !== -1) {
25
- nodeModulesPath = parts.slice(0, nodeModulesIndex).join(node_path.sep);
38
+ const parentDir = nodeModulesIndex !== -1 ? parts.slice(0, nodeModulesIndex).join(node_path.sep) : dirname;
39
+ const parentDirPath = node_path.join(parentDir, typescriptPackageJsonPath);
40
+ if (cwdPath === parentDirPath) {
41
+ return [cwdPath];
26
42
  }
27
- else {
28
- nodeModulesPath = dirname;
29
- }
30
- return node_path.join(nodeModulesPath, "node_modules", "typescript", "package.json");
43
+ return [parentDirPath, cwdPath];
31
44
  };
32
45
 
33
46
  let tscVersion;
@@ -38,19 +51,23 @@ const getTypeScriptUserAgentPair = async () => {
38
51
  else if (typeof tscVersion === "string") {
39
52
  return ["md/tsc", tscVersion];
40
53
  }
41
- try {
42
- const packageJson = await promises.readFile(getTypeScriptPackageJsonPath(__dirname), "utf-8");
43
- const { version } = JSON.parse(packageJson);
44
- if (typeof version !== "string") {
45
- tscVersion = null;
46
- return undefined;
54
+ const dirname = typeof __dirname !== "undefined" ? __dirname : undefined;
55
+ for (const typescriptPackageJsonPath of getTypeScriptPackageJsonPaths(dirname)) {
56
+ try {
57
+ const packageJson = await promises.readFile(typescriptPackageJsonPath, "utf-8");
58
+ const { version } = JSON.parse(packageJson);
59
+ const sanitizedVersion = getSanitizedTypeScriptVersion(version);
60
+ if (typeof sanitizedVersion !== "string") {
61
+ continue;
62
+ }
63
+ tscVersion = sanitizedVersion;
64
+ return ["md/tsc", tscVersion];
65
+ }
66
+ catch {
47
67
  }
48
- tscVersion = version;
49
- return ["md/tsc", tscVersion];
50
- }
51
- catch {
52
- tscVersion = null;
53
68
  }
69
+ tscVersion = null;
70
+ return undefined;
54
71
  };
55
72
 
56
73
  const crtAvailability = {
@@ -0,0 +1,9 @@
1
+ const SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/;
2
+ export const getSanitizedTypeScriptVersion = (version = "") => {
3
+ const match = version.match(SEMVER_REGEX);
4
+ if (!match) {
5
+ return undefined;
6
+ }
7
+ const [major, minor, patch, prerelease] = [match[1], match[2], match[3], match[4]];
8
+ return prerelease ? `${major}.${minor}.${patch}-${prerelease}` : `${major}.${minor}.${patch}`;
9
+ };
@@ -0,0 +1,17 @@
1
+ import { join, normalize, sep } from "node:path";
2
+ const typescriptPackageJsonPath = join("node_modules", "typescript", "package.json");
3
+ export const getTypeScriptPackageJsonPaths = (dirname) => {
4
+ const cwdPath = join(process.cwd(), typescriptPackageJsonPath);
5
+ if (!dirname) {
6
+ return [cwdPath];
7
+ }
8
+ const normalizedPath = normalize(dirname);
9
+ const parts = normalizedPath.split(sep);
10
+ const nodeModulesIndex = parts.indexOf("node_modules");
11
+ const parentDir = nodeModulesIndex !== -1 ? parts.slice(0, nodeModulesIndex).join(sep) : dirname;
12
+ const parentDirPath = join(parentDir, typescriptPackageJsonPath);
13
+ if (cwdPath === parentDirPath) {
14
+ return [cwdPath];
15
+ }
16
+ return [parentDirPath, cwdPath];
17
+ };
@@ -1,5 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
- import { getTypeScriptPackageJsonPath } from "./getTypeScriptPackageJsonPath";
2
+ import { getSanitizedTypeScriptVersion } from "./getSanitizedTypeScriptVersion";
3
+ import { getTypeScriptPackageJsonPaths } from "./getTypeScriptPackageJsonPaths";
3
4
  let tscVersion;
4
5
  export const getTypeScriptUserAgentPair = async () => {
5
6
  if (tscVersion === null) {
@@ -8,17 +9,21 @@ export const getTypeScriptUserAgentPair = async () => {
8
9
  else if (typeof tscVersion === "string") {
9
10
  return ["md/tsc", tscVersion];
10
11
  }
11
- try {
12
- const packageJson = await readFile(getTypeScriptPackageJsonPath(__dirname), "utf-8");
13
- const { version } = JSON.parse(packageJson);
14
- if (typeof version !== "string") {
15
- tscVersion = null;
16
- return undefined;
12
+ const dirname = typeof __dirname !== "undefined" ? __dirname : undefined;
13
+ for (const typescriptPackageJsonPath of getTypeScriptPackageJsonPaths(dirname)) {
14
+ try {
15
+ const packageJson = await readFile(typescriptPackageJsonPath, "utf-8");
16
+ const { version } = JSON.parse(packageJson);
17
+ const sanitizedVersion = getSanitizedTypeScriptVersion(version);
18
+ if (typeof sanitizedVersion !== "string") {
19
+ continue;
20
+ }
21
+ tscVersion = sanitizedVersion;
22
+ return ["md/tsc", tscVersion];
23
+ }
24
+ catch {
17
25
  }
18
- tscVersion = version;
19
- return ["md/tsc", tscVersion];
20
- }
21
- catch {
22
- tscVersion = null;
23
26
  }
27
+ tscVersion = null;
28
+ return undefined;
24
29
  };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Validates a semver string (with optional pre-release and/or build metadata).
3
+ * If valid, returns the version string with build metadata stripped.
4
+ * Returns undefined if the string is not a valid semver.
5
+ *
6
+ * @internal
7
+ */
8
+ export declare const getSanitizedTypeScriptVersion: (version?: string) => string | undefined;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns candidate paths to the TypeScript package.json file derived from the current
3
+ * working directory and, if provided, from the given directory.
4
+ *
5
+ * @param dirname - Optional directory path to derive an additional candidate path from.
6
+ * @returns An array of unique candidate paths to the TypeScript package.json file.
7
+ *
8
+ * @internal
9
+ */
10
+ export declare const getTypeScriptPackageJsonPaths: (dirname?: string) => string[];
@@ -0,0 +1,3 @@
1
+ export declare const getSanitizedTypeScriptVersion: (
2
+ version?: string
3
+ ) => string | undefined;
@@ -0,0 +1,3 @@
1
+ export declare const getTypeScriptPackageJsonPaths: (
2
+ dirname?: string
3
+ ) => string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/util-user-agent-node",
3
- "version": "3.973.0",
3
+ "version": "3.973.1",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
6
6
  "build:cjs": "node ../../scripts/compilation/inline util-user-agent-node",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
- "@aws-sdk/middleware-user-agent": "^3.972.15",
27
+ "@aws-sdk/middleware-user-agent": "^3.972.16",
28
28
  "@aws-sdk/types": "^3.973.4",
29
29
  "@smithy/node-config-provider": "^4.3.10",
30
30
  "@smithy/types": "^4.13.0",
@@ -1,14 +0,0 @@
1
- import { join, normalize, sep } from "node:path";
2
- export const getTypeScriptPackageJsonPath = (dirname = "") => {
3
- let nodeModulesPath;
4
- const normalizedPath = normalize(dirname);
5
- const parts = normalizedPath.split(sep);
6
- const nodeModulesIndex = parts.indexOf("node_modules");
7
- if (nodeModulesIndex !== -1) {
8
- nodeModulesPath = parts.slice(0, nodeModulesIndex).join(sep);
9
- }
10
- else {
11
- nodeModulesPath = dirname;
12
- }
13
- return join(nodeModulesPath, "node_modules", "typescript", "package.json");
14
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * Returns the path to the TypeScript package.json file relative to the given directory.
3
- *
4
- * @param dirname - The directory path to resolve from.
5
- * @returns The path to the TypeScript package.json file.
6
- *
7
- * @internal
8
- */
9
- export declare const getTypeScriptPackageJsonPath: (dirname?: string) => string;
@@ -1 +0,0 @@
1
- export declare const getTypeScriptPackageJsonPath: (dirname?: string) => string;