@netlify/build-info 5.0.0 → 5.1.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/README.md CHANGED
@@ -1,6 +1,3 @@
1
- [![Build](https://github.com/netlify/build-info/workflows/Build/badge.svg)](https://github.com/netlify/build-info/actions)
2
- [![Node](https://img.shields.io/node/v/@netlify/build-info.svg?logo=node.js)](https://www.npmjs.com/package/@netlify/build-info)
3
-
4
1
  # Build Info
5
2
 
6
3
  Build information detection utility.
package/lib/bin.js CHANGED
@@ -1,30 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
  import { exit, argv } from 'process';
3
- import yargs from 'yargs';
4
3
  import { hideBin } from 'yargs/helpers';
4
+ import yargs from 'yargs/yargs';
5
5
  import { getBuildInfo } from './main.js';
6
- // CLI entry point
7
- const runCli = async function () {
8
- const { projectDir, rootDir } = parseArgs();
9
- try {
10
- const buildInfo = await getBuildInfo({ projectDir, rootDir });
11
- console.log(JSON.stringify(buildInfo, null, 2));
12
- }
13
- catch (error) {
14
- console.error(error);
15
- exit(1);
16
- }
17
- };
18
- const parseArgs = function () {
19
- return yargs(hideBin(argv)).command('* [projectDir]').options(OPTIONS).usage(USAGE).strict().parse();
20
- };
21
- const OPTIONS = {
6
+ const { projectDir, rootDir } = yargs(hideBin(argv))
7
+ .command('* [projectDir]')
8
+ .options({
22
9
  rootDir: {
23
10
  string: true,
24
11
  describe: `The root directory of the project if different from projectDir`,
25
12
  },
26
- };
27
- const USAGE = `$0 [OPTIONS...] [PROJECT_DIRECTORY]
13
+ })
14
+ .usage(`$0 [OPTIONS...] [PROJECT_DIRECTORY]
28
15
 
29
- Print relevant build information from a project.`;
30
- runCli();
16
+ Print relevant build information from a project.`)
17
+ .strict()
18
+ .parse();
19
+ try {
20
+ const buildInfo = await getBuildInfo({ projectDir, rootDir });
21
+ console.log(JSON.stringify(buildInfo, null, 2));
22
+ }
23
+ catch (error) {
24
+ console.error(error);
25
+ exit(1);
26
+ }
package/lib/context.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- export function getContext({ projectDir, rootDir }?: {
1
+ import { PackageJson } from 'read-pkg';
2
+ export declare type ContextOptions = {
2
3
  projectDir?: string;
3
4
  rootDir?: string;
4
- }): Promise<{
5
+ };
6
+ export declare type Context = {
5
7
  projectDir: string;
6
8
  rootDir: string;
7
- rootPackageJson: import("type-fest").PackageJson;
8
- }>;
9
+ rootPackageJson: PackageJson;
10
+ };
11
+ export declare const getContext: (config?: ContextOptions) => Promise<Context>;
package/lib/context.js CHANGED
@@ -1,19 +1,21 @@
1
1
  import { resolve } from 'path';
2
2
  import { cwd } from 'process';
3
3
  import { readPackage } from 'read-pkg';
4
- const getPackageJson = async function (dir) {
4
+ /**
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
8
+ */
9
+ const getPackageJson = async (cwd) => {
5
10
  try {
6
- const packageJson = await readPackage({ cwd: dir, normalize: false });
7
- if (packageJson === undefined) {
8
- return {};
9
- }
10
- return packageJson;
11
+ return await readPackage({ cwd, normalize: false });
11
12
  }
12
13
  catch {
13
14
  return {};
14
15
  }
15
16
  };
16
- export const getContext = async function ({ projectDir = cwd(), rootDir = '' } = {}) {
17
+ export const getContext = async (config = {}) => {
18
+ const { projectDir = cwd(), rootDir = '' } = config;
17
19
  // Get the absolute dirs for both project and root
18
20
  // We resolve the projectDir from the rootDir
19
21
  const absoluteProjectDir = resolve(rootDir, projectDir);
package/lib/core.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export function buildInfo(context: any): Promise<{
1
+ import type { Context } from './context.js';
2
+ export declare const buildInfo: (context: Context) => Promise<{
2
3
  frameworks: any;
3
4
  jsWorkspaces: {
4
5
  isRoot: boolean;
package/lib/core.js CHANGED
@@ -1,8 +1,8 @@
1
- import { getFrameworks } from './frameworks.js';
1
+ import { listFrameworks } from '@netlify/framework-info';
2
2
  import { getWorkspaceInfo } from './workspaces.js';
3
3
  export const buildInfo = async function (context) {
4
4
  const workspaceInfo = await getWorkspaceInfo(context);
5
5
  const jsWorkspaces = workspaceInfo ? { jsWorkspaces: workspaceInfo } : {};
6
- const frameworks = await getFrameworks(context);
6
+ const frameworks = await listFrameworks({ projectDir: context.projectDir });
7
7
  return { ...jsWorkspaces, frameworks };
8
8
  };
package/lib/main.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export function getBuildInfo(opts: any): Promise<{
1
+ import { ContextOptions } from './context.js';
2
+ export declare const getBuildInfo: (opts: ContextOptions) => Promise<{
2
3
  frameworks: any;
3
4
  jsWorkspaces: {
4
5
  isRoot: boolean;
package/lib/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { getContext } from './context.js';
2
2
  import { buildInfo } from './core.js';
3
- export const getBuildInfo = async function (opts) {
3
+ export const getBuildInfo = async (opts) => {
4
4
  const context = await getContext(opts);
5
5
  return await buildInfo(context);
6
6
  };
@@ -1,8 +1,5 @@
1
- export function getWorkspaceInfo({ rootPackageJson, projectDir, rootDir }: {
2
- rootPackageJson: any;
3
- projectDir: any;
4
- rootDir: any;
5
- }): Promise<{
1
+ import type { Context } from './context.js';
2
+ export declare const getWorkspaceInfo: (context: Context) => Promise<{
6
3
  isRoot: boolean;
7
4
  packages: any[];
8
5
  }>;
package/lib/workspaces.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import mapWorkspaces from '@npmcli/map-workspaces';
2
- export const getWorkspaceInfo = async function ({ rootPackageJson, projectDir, rootDir }) {
3
- if (!rootPackageJson.workspaces) {
2
+ export const getWorkspaceInfo = async (context) => {
3
+ if (!context.rootPackageJson.workspaces) {
4
4
  return;
5
5
  }
6
6
  const workspacesMap = await mapWorkspaces({
7
- cwd: rootDir || projectDir,
8
- pkg: rootPackageJson,
7
+ cwd: context.rootDir || context.projectDir,
8
+ pkg: context.rootPackageJson,
9
9
  });
10
10
  const packages = [...workspacesMap.values()];
11
11
  // The provided project dir is a workspace package
12
- const isWorkspace = packages.find((path) => projectDir === path);
12
+ const isWorkspace = packages.find((path) => context.projectDir === path);
13
13
  // The project dir is a collection of workspaces itself
14
- const isRoot = !rootDir;
14
+ const isRoot = !context.rootDir;
15
15
  if (isWorkspace || isRoot) {
16
16
  return { isRoot, packages };
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build-info",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Build info utility",
5
5
  "type": "module",
6
6
  "exports": "./lib/main.js",
@@ -16,8 +16,9 @@
16
16
  "scripts": {
17
17
  "prebuild": "rm -rf lib",
18
18
  "build": "tsc",
19
- "test": "ava",
20
- "test:ci": "c8 -r lcovonly -r text -r json ava"
19
+ "test": "vitest run",
20
+ "test:dev": "vitest",
21
+ "test:ci": "vitest run --reporter=default"
21
22
  },
22
23
  "keywords": [],
23
24
  "license": "MIT",
@@ -34,14 +35,13 @@
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/node": "^14.18.31",
37
- "ava": "^4.0.0",
38
- "c8": "^7.11.0",
38
+ "@vitest/coverage-c8": "^0.24.1",
39
39
  "execa": "^6.0.0",
40
- "get-bin-path": "^6.0.0",
41
- "typescript": "^4.8.4"
40
+ "typescript": "^4.8.4",
41
+ "vitest": "^0.24.1"
42
42
  },
43
43
  "engines": {
44
44
  "node": "^14.16.0 || >=16.0.0"
45
45
  },
46
- "gitHead": "c4502f1c112e7f33d5e6fa053bfbe7dabdfe0160"
46
+ "gitHead": "701e883d4e19c048e8de9801e49e21de5c891a18"
47
47
  }
@@ -1,3 +0,0 @@
1
- export function getFrameworks({ projectDir }: {
2
- projectDir: any;
3
- }): Promise<any>;
package/lib/frameworks.js DELETED
@@ -1,4 +0,0 @@
1
- import { listFrameworks } from '@netlify/framework-info';
2
- export const getFrameworks = async function ({ projectDir }) {
3
- return await listFrameworks({ projectDir });
4
- };