@vercel/fs-detectors 7.9.2 → 7.9.4

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/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export { LocalFileSystemDetector } from './detectors/local-file-system-detector'
17
17
  export { workspaceManagers } from './workspaces/workspace-managers';
18
18
  export { getWorkspaces, GetWorkspaceOptions, Workspace, WorkspaceType, } from './workspaces/get-workspaces';
19
19
  export { getWorkspacePackagePaths, GetWorkspacePackagePathsOptions, } from './workspaces/get-workspace-package-paths';
20
+ export { resolveWorkspacePackageTargets, type WorkspacePackageTarget, } from './workspaces/resolve-workspace-package-targets';
20
21
  export { monorepoManagers } from './monorepos/monorepo-managers';
21
22
  export { isOfficialRuntime, isStaticRuntime } from './is-official-runtime';
22
23
  export { packageManagers } from './package-managers/package-managers';
package/dist/index.js CHANGED
@@ -65,6 +65,7 @@ __export(src_exports, {
65
65
  resolveAllConfiguredServices: () => import_resolve.resolveAllConfiguredServices,
66
66
  resolveAllConfiguredServicesV2: () => import_resolve_v2.resolveAllConfiguredServicesV2,
67
67
  resolveConfiguredServiceV2: () => import_resolve_v2.resolveConfiguredServiceV2,
68
+ resolveWorkspacePackageTargets: () => import_resolve_workspace_package_targets.resolveWorkspacePackageTargets,
68
69
  validateProxy: () => import_detect_builders.validateProxy,
69
70
  validateProxyConfig: () => import_detect_builders.validateProxyConfig,
70
71
  validateServiceConfigV2: () => import_resolve_v2.validateServiceConfigV2,
@@ -87,6 +88,7 @@ var import_local_file_system_detector = require("./detectors/local-file-system-d
87
88
  var import_workspace_managers = require("./workspaces/workspace-managers");
88
89
  var import_get_workspaces = require("./workspaces/get-workspaces");
89
90
  var import_get_workspace_package_paths = require("./workspaces/get-workspace-package-paths");
91
+ var import_resolve_workspace_package_targets = require("./workspaces/resolve-workspace-package-targets");
90
92
  var import_monorepo_managers = require("./monorepos/monorepo-managers");
91
93
  var import_is_official_runtime = require("./is-official-runtime");
92
94
  var import_package_managers = require("./package-managers/package-managers");
@@ -141,6 +143,7 @@ var import_detect_instrumentation = require("./detect-instrumentation");
141
143
  resolveAllConfiguredServices,
142
144
  resolveAllConfiguredServicesV2,
143
145
  resolveConfiguredServiceV2,
146
+ resolveWorkspacePackageTargets,
144
147
  validateProxy,
145
148
  validateProxyConfig,
146
149
  validateServiceConfigV2,
@@ -3,9 +3,13 @@ import { Workspace } from './get-workspaces';
3
3
  interface GetPackagePathOptions {
4
4
  fs: DetectorFilesystem;
5
5
  }
6
+ export interface GetWorkspacePatternsOptions extends GetPackagePathOptions {
7
+ type: Workspace['type'];
8
+ }
6
9
  export interface GetWorkspacePackagePathsOptions extends GetPackagePathOptions {
7
10
  fs: DetectorFilesystem;
8
11
  workspace: Workspace;
9
12
  }
10
13
  export declare function getWorkspacePackagePaths({ fs, workspace, }: GetWorkspacePackagePathsOptions): Promise<string[]>;
14
+ export declare function getWorkspacePatterns({ fs, type, }: GetWorkspacePatternsOptions): Promise<string[]>;
11
15
  export {};
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var get_workspace_package_paths_exports = {};
30
30
  __export(get_workspace_package_paths_exports, {
31
- getWorkspacePackagePaths: () => getWorkspacePackagePaths
31
+ getWorkspacePackagePaths: () => getWorkspacePackagePaths,
32
+ getWorkspacePatterns: () => getWorkspacePatterns
32
33
  });
33
34
  module.exports = __toCommonJS(get_workspace_package_paths_exports);
34
35
  var import_path = __toESM(require("path"));
@@ -44,22 +45,13 @@ async function getWorkspacePackagePaths({
44
45
  const { type, rootPath } = workspace;
45
46
  const workspaceFs = fs.chdir(rootPath);
46
47
  let results = [];
47
- switch (type) {
48
- case "yarn":
49
- case "npm":
50
- results = await getPackageJsonWorkspacePackagePaths({ fs: workspaceFs });
51
- break;
52
- case "pnpm":
53
- results = await getPnpmWorkspacePackagePaths({ fs: workspaceFs });
54
- break;
55
- case "nx":
56
- results = await getNxWorkspacePackagePaths({ fs: workspaceFs });
57
- break;
58
- case "rush":
59
- results = await getRushWorkspacePackagePaths({ fs: workspaceFs });
60
- break;
61
- default:
62
- throw new Error(`Unknown workspace implementation: ${type}`);
48
+ if (type === "nx") {
49
+ results = await getNxWorkspacePackagePaths({ fs: workspaceFs });
50
+ } else if (type === "rush") {
51
+ results = await getRushWorkspacePackagePaths({ fs: workspaceFs });
52
+ } else {
53
+ const patterns = await getWorkspacePatterns({ fs: workspaceFs, type });
54
+ results = await getPackagePaths(patterns, workspaceFs);
63
55
  }
64
56
  return results.map((packagePath) => {
65
57
  return posixPath.join(rootPath, posixPath.dirname(packagePath));
@@ -88,20 +80,27 @@ async function getPackagePaths(packages, fs) {
88
80
  )
89
81
  )).flat();
90
82
  }
91
- async function getPackageJsonWorkspacePackagePaths({
92
- fs
83
+ async function getWorkspacePatterns({
84
+ fs,
85
+ type
93
86
  }) {
87
+ const stringPatterns = (value) => Array.isArray(value) ? value.filter(
88
+ (pattern) => typeof pattern === "string"
89
+ ) : [];
90
+ if (type === "pnpm") {
91
+ const pnpmWorkspaceAsBuffer = await fs.readFile("pnpm-workspace.yaml");
92
+ const { packages = [] } = import_js_yaml.default.load(
93
+ pnpmWorkspaceAsBuffer.toString()
94
+ );
95
+ return stringPatterns(packages);
96
+ }
94
97
  const packageJsonAsBuffer = await fs.readFile("package.json");
95
98
  const { workspaces } = JSON.parse(
96
99
  packageJsonAsBuffer.toString()
97
100
  );
98
- let packages = [];
99
- if (Array.isArray(workspaces)) {
100
- packages = workspaces;
101
- } else {
102
- packages = workspaces?.packages ?? [];
103
- }
104
- return getPackagePaths(packages, fs);
101
+ return stringPatterns(
102
+ Array.isArray(workspaces) ? workspaces : workspaces?.packages
103
+ );
105
104
  }
106
105
  async function getNxWorkspacePackagePaths({
107
106
  fs
@@ -111,15 +110,6 @@ async function getNxWorkspacePackagePaths({
111
110
  const packages = Object.values(projects);
112
111
  return getPackagePaths(packages, fs);
113
112
  }
114
- async function getPnpmWorkspacePackagePaths({
115
- fs
116
- }) {
117
- const pnpmWorkspaceAsBuffer = await fs.readFile("pnpm-workspace.yaml");
118
- const { packages = [] } = import_js_yaml.default.load(
119
- pnpmWorkspaceAsBuffer.toString()
120
- );
121
- return getPackagePaths(packages, fs);
122
- }
123
113
  async function getRushWorkspacePackagePaths({
124
114
  fs
125
115
  }) {
@@ -136,5 +126,6 @@ async function getRushWorkspacePackagePaths({
136
126
  }
137
127
  // Annotate the CommonJS export names for ESM import in node:
138
128
  0 && (module.exports = {
139
- getWorkspacePackagePaths
129
+ getWorkspacePackagePaths,
130
+ getWorkspacePatterns
140
131
  });
@@ -4,7 +4,7 @@ export interface GetWorkspaceOptions {
4
4
  depth?: number;
5
5
  cwd?: string;
6
6
  }
7
- export type WorkspaceType = 'yarn' | 'pnpm' | 'npm' | 'nx' | 'rush';
7
+ export type WorkspaceType = 'yarn' | 'pnpm' | 'npm' | 'bun' | 'nx' | 'rush';
8
8
  export type Workspace = {
9
9
  type: WorkspaceType;
10
10
  rootPath: string;
@@ -0,0 +1,13 @@
1
+ import { DetectorFilesystem } from '../detectors/filesystem';
2
+ import type { WorkspaceType } from './get-workspaces';
3
+ export interface WorkspacePackageTarget {
4
+ isRoot?: boolean;
5
+ name?: string;
6
+ packageJsonPath: string;
7
+ relativePath: string;
8
+ }
9
+ export declare function resolveWorkspacePackageTargets({ fs, targetPaths, type, }: {
10
+ fs: DetectorFilesystem;
11
+ targetPaths: string[];
12
+ type: Extract<WorkspaceType, 'npm' | 'pnpm' | 'yarn' | 'bun'>;
13
+ }): Promise<WorkspacePackageTarget[] | null>;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var resolve_workspace_package_targets_exports = {};
30
+ __export(resolve_workspace_package_targets_exports, {
31
+ resolveWorkspacePackageTargets: () => resolveWorkspacePackageTargets
32
+ });
33
+ module.exports = __toCommonJS(resolve_workspace_package_targets_exports);
34
+ var import_path = require("path");
35
+ var import_minimatch = __toESM(require("minimatch"));
36
+ var import_get_workspace_package_paths = require("./get-workspace-package-paths");
37
+ function normalize(value) {
38
+ return value.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\//, "");
39
+ }
40
+ function matchesWorkspace(relativePath, patterns) {
41
+ const positives = patterns.filter((pattern) => !pattern.startsWith("!")).map(normalize);
42
+ const negatives = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => normalize(pattern.slice(1)));
43
+ return positives.some((pattern) => (0, import_minimatch.default)(relativePath, pattern)) && !negatives.some((pattern) => (0, import_minimatch.default)(relativePath, pattern));
44
+ }
45
+ async function readPackage(fs, packageJsonPath) {
46
+ try {
47
+ const packageJson = JSON.parse(
48
+ (await fs.readFile(packageJsonPath)).toString()
49
+ );
50
+ return {
51
+ name: typeof packageJson.name === "string" ? packageJson.name : void 0
52
+ };
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
57
+ async function findPackage(fs, targetPath) {
58
+ if (targetPath.startsWith("/") || /^[A-Za-z]:[\\/]/.test(targetPath) || normalize(targetPath) === ".." || normalize(targetPath).startsWith("../")) {
59
+ return null;
60
+ }
61
+ let relativePath = normalize(targetPath);
62
+ while (relativePath && relativePath !== ".") {
63
+ const packageJsonPath = import_path.posix.join(relativePath, "package.json");
64
+ const packageJson = await readPackage(fs, packageJsonPath);
65
+ if (packageJson) {
66
+ return {
67
+ name: packageJson.name,
68
+ packageJsonPath,
69
+ relativePath
70
+ };
71
+ }
72
+ const parent = import_path.posix.dirname(relativePath);
73
+ if (parent === relativePath || parent === ".")
74
+ return null;
75
+ relativePath = parent;
76
+ }
77
+ return null;
78
+ }
79
+ async function resolveWorkspacePackageTargets({
80
+ fs,
81
+ targetPaths,
82
+ type
83
+ }) {
84
+ let patterns;
85
+ try {
86
+ patterns = await (0, import_get_workspace_package_paths.getWorkspacePatterns)({ fs, type });
87
+ } catch {
88
+ return null;
89
+ }
90
+ if (patterns.length === 0)
91
+ return null;
92
+ const targets = /* @__PURE__ */ new Map();
93
+ for (const targetPath of targetPaths) {
94
+ const target = await findPackage(fs, targetPath);
95
+ if (!target || !matchesWorkspace(target.relativePath, patterns))
96
+ return null;
97
+ targets.set(target.packageJsonPath, target);
98
+ }
99
+ const rootPackageJson = await readPackage(fs, "package.json");
100
+ if (rootPackageJson) {
101
+ targets.set("package.json", {
102
+ isRoot: true,
103
+ name: rootPackageJson.name,
104
+ packageJsonPath: "package.json",
105
+ relativePath: "."
106
+ });
107
+ }
108
+ return Array.from(targets.values()).sort(
109
+ (a, b) => a.relativePath.localeCompare(b.relativePath)
110
+ );
111
+ }
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ resolveWorkspacePackageTargets
115
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/fs-detectors",
3
- "version": "7.9.2",
3
+ "version": "7.9.4",
4
4
  "description": "Vercel filesystem detectors",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,11 +20,11 @@
20
20
  "minimatch": "3.1.2",
21
21
  "semver": "6.3.1",
22
22
  "smol-toml": "1.5.2",
23
- "@vercel/build-utils": "14.17.0",
23
+ "@vercel/build-utils": "14.19.0",
24
24
  "@vercel/error-utils": "2.2.1",
25
25
  "@vercel/frameworks": "3.35.0",
26
- "@vercel/python-analysis": "0.14.0",
27
- "@vercel/routing-utils": "6.6.0"
26
+ "@vercel/routing-utils": "6.6.0",
27
+ "@vercel/python-analysis": "0.14.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/glob": "7.2.0",
@@ -33,7 +33,7 @@
33
33
  "@types/node": "20.11.0",
34
34
  "@types/semver": "7.3.10",
35
35
  "vitest": "4.1.10",
36
- "@vercel-internals/runtimes": "1.1.10"
36
+ "@vercel-internals/runtimes": "1.1.12"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "node build.mjs",