@netlify/build-info 6.0.4 → 6.0.5

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/lib/context.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare type ContextOptions = {
5
5
  };
6
6
  export declare type Context = {
7
7
  projectDir: string;
8
- rootDir?: string;
8
+ rootDir: string;
9
9
  rootPackageJson: PackageJson;
10
10
  };
11
11
  export declare const getContext: (config?: ContextOptions) => Promise<Context>;
package/lib/context.js CHANGED
@@ -1,18 +1,20 @@
1
- import { resolve } from 'path';
1
+ import { existsSync } from 'fs';
2
+ import { dirname, join, resolve } from 'path';
2
3
  import { cwd } from 'process';
4
+ import { findUp } from 'find-up';
3
5
  import { readPackage } from 'read-pkg';
4
6
  /**
5
- * Reads a package.json up the tree starting at the provided directory
6
- * @param cwd The current working directory where it tries to find the package.json
7
- * @returns A parsed object of the package.json
7
+ * Collects the root package.json if there is one.
8
8
  */
9
- const getPackageJson = async (cwd) => {
10
- try {
11
- return await readPackage({ cwd, normalize: false });
9
+ const getRootPackageJson = async (projectDir, rootDir) => {
10
+ if (existsSync(join(rootDir, 'package.json'))) {
11
+ return await readPackage({ cwd: rootDir, normalize: false });
12
12
  }
13
- catch {
14
- return {};
13
+ const json = await findUp('package.json', { cwd: projectDir, stopAt: rootDir });
14
+ if (json) {
15
+ return await readPackage({ cwd: dirname(json), normalize: false });
15
16
  }
17
+ return {};
16
18
  };
17
19
  export const getContext = async (config = {}) => {
18
20
  const { projectDir = cwd(), rootDir = '' } = config;
@@ -27,7 +29,7 @@ export const getContext = async (config = {}) => {
27
29
  // If rootDir equals projectDir we'll be getting the projectDir package.json
28
30
  // Later on if we also need the projectDir package.json we can check for it
29
31
  // and only perform one resolution
30
- const rootPackageJson = await getPackageJson(rootDir || projectDir);
32
+ const rootPackageJson = await getRootPackageJson(absoluteProjectDir, validRootDir || absoluteProjectDir);
31
33
  return {
32
34
  projectDir: absoluteProjectDir,
33
35
  rootDir: validRootDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build-info",
3
- "version": "6.0.4",
3
+ "version": "6.0.5",
4
4
  "description": "Build info utility",
5
5
  "type": "module",
6
6
  "exports": {
@@ -52,5 +52,5 @@
52
52
  "engines": {
53
53
  "node": "^14.16.0 || >=16.0.0"
54
54
  },
55
- "gitHead": "be9da6e85afa0223bdcd6d228c929f4372515538"
55
+ "gitHead": "3e80c5e33030d37eec733ecb927c54eceebd2fd5"
56
56
  }