@netlify/build-info 4.0.10 → 4.0.11

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/bin.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ // This is a workaround for npm issue: https://github.com/npm/cli/issues/2632
4
+
5
+ import './lib/bin.js'
package/lib/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/bin.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import { exit, argv } from 'process';
3
+ import yargs from 'yargs';
4
+ import { hideBin } from 'yargs/helpers';
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 = {
22
+ rootDir: {
23
+ string: true,
24
+ describe: `The root directory of the project if different from projectDir`,
25
+ },
26
+ };
27
+ const USAGE = `$0 [OPTIONS...] [PROJECT_DIRECTORY]
28
+
29
+ Print relevant build information from a project.`;
30
+ runCli();
@@ -0,0 +1,8 @@
1
+ export function getContext({ projectDir, rootDir }?: {
2
+ projectDir?: string;
3
+ rootDir?: string;
4
+ }): Promise<{
5
+ projectDir: string;
6
+ rootDir: string;
7
+ rootPackageJson: import("type-fest").PackageJson;
8
+ }>;
package/lib/context.js ADDED
@@ -0,0 +1,34 @@
1
+ import { resolve } from 'path';
2
+ import { cwd } from 'process';
3
+ import { readPackage } from 'read-pkg';
4
+ const getPackageJson = async function (dir) {
5
+ try {
6
+ const packageJson = await readPackage({ cwd: dir, normalize: false });
7
+ if (packageJson === undefined) {
8
+ return {};
9
+ }
10
+ return packageJson;
11
+ }
12
+ catch {
13
+ return {};
14
+ }
15
+ };
16
+ export const getContext = async function ({ projectDir = cwd(), rootDir = '' } = {}) {
17
+ // Get the absolute dirs for both project and root
18
+ // We resolve the projectDir from the rootDir
19
+ const absoluteProjectDir = resolve(rootDir, projectDir);
20
+ // If a relative absolute path is given we rely on cwd
21
+ const absoluteRootDir = rootDir ? resolve(cwd(), rootDir) : undefined;
22
+ // We only pass through the root dir if it was provided and is actually different
23
+ // from the project dir
24
+ const validRootDir = absoluteRootDir && absoluteRootDir !== absoluteProjectDir ? absoluteRootDir : undefined;
25
+ // If rootDir equals projectDir we'll be getting the projectDir package.json
26
+ // Later on if we also need the projectDir package.json we can check for it
27
+ // and only perform one resolution
28
+ const rootPackageJson = await getPackageJson(rootDir || projectDir);
29
+ return {
30
+ projectDir: absoluteProjectDir,
31
+ rootDir: validRootDir,
32
+ rootPackageJson,
33
+ };
34
+ };
package/lib/core.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export function buildInfo(context: any): Promise<{
2
+ frameworks: any;
3
+ jsWorkspaces: {
4
+ isRoot: boolean;
5
+ packages: any[];
6
+ };
7
+ } | {
8
+ frameworks: any;
9
+ jsWorkspaces?: undefined;
10
+ }>;
package/lib/core.js ADDED
@@ -0,0 +1,8 @@
1
+ import { getFrameworks } from './frameworks.js';
2
+ import { getWorkspaceInfo } from './workspaces.js';
3
+ export const buildInfo = async function (context) {
4
+ const workspaceInfo = await getWorkspaceInfo(context);
5
+ const jsWorkspaces = workspaceInfo ? { jsWorkspaces: workspaceInfo } : {};
6
+ const frameworks = await getFrameworks(context);
7
+ return { ...jsWorkspaces, frameworks };
8
+ };
@@ -0,0 +1,3 @@
1
+ export function getFrameworks({ projectDir }: {
2
+ projectDir: any;
3
+ }): Promise<any>;
@@ -0,0 +1,4 @@
1
+ import { listFrameworks } from '@netlify/framework-info';
2
+ export const getFrameworks = async function ({ projectDir }) {
3
+ return await listFrameworks({ projectDir });
4
+ };
package/lib/main.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export function getBuildInfo(opts: any): Promise<{
2
+ frameworks: any;
3
+ jsWorkspaces: {
4
+ isRoot: boolean;
5
+ packages: any[];
6
+ };
7
+ } | {
8
+ frameworks: any;
9
+ jsWorkspaces?: undefined;
10
+ }>;
package/lib/main.js ADDED
@@ -0,0 +1,6 @@
1
+ import { getContext } from './context.js';
2
+ import { buildInfo } from './core.js';
3
+ export const getBuildInfo = async function (opts) {
4
+ const context = await getContext(opts);
5
+ return await buildInfo(context);
6
+ };
@@ -0,0 +1,8 @@
1
+ export function getWorkspaceInfo({ rootPackageJson, projectDir, rootDir }: {
2
+ rootPackageJson: any;
3
+ projectDir: any;
4
+ rootDir: any;
5
+ }): Promise<{
6
+ isRoot: boolean;
7
+ packages: any[];
8
+ }>;
@@ -0,0 +1,18 @@
1
+ import mapWorkspaces from '@npmcli/map-workspaces';
2
+ export const getWorkspaceInfo = async function ({ rootPackageJson, projectDir, rootDir }) {
3
+ if (!rootPackageJson.workspaces) {
4
+ return;
5
+ }
6
+ const workspacesMap = await mapWorkspaces({
7
+ cwd: rootDir || projectDir,
8
+ pkg: rootPackageJson,
9
+ });
10
+ const packages = [...workspacesMap.values()];
11
+ // The provided project dir is a workspace package
12
+ const isWorkspace = packages.find((path) => projectDir === path);
13
+ // The project dir is a collection of workspaces itself
14
+ const isRoot = !rootDir;
15
+ if (isWorkspace || isRoot) {
16
+ return { isRoot, packages };
17
+ }
18
+ };
package/package.json CHANGED
@@ -1,69 +1,45 @@
1
1
  {
2
2
  "name": "@netlify/build-info",
3
- "version": "4.0.10",
3
+ "version": "4.0.11",
4
4
  "description": "Build info utility",
5
5
  "type": "module",
6
- "exports": "./src/main.js",
7
- "main": "./src/main.js",
6
+ "exports": "./lib/main.js",
7
+ "main": "./lib/main.js",
8
+ "types": "./lib/main.d.ts",
8
9
  "bin": {
9
- "build-info": "./src/bin.js"
10
+ "build-info": "./bin.js"
10
11
  },
11
12
  "files": [
12
- "src/**/*.js",
13
- "!src/**/*.test.js"
13
+ "bin.js",
14
+ "lib/**/*"
14
15
  ],
15
16
  "scripts": {
16
- "prepare": "husky install node_modules/@netlify/eslint-config-node/.husky/",
17
- "prepublishOnly": "npm ci && npm test",
18
- "test": "run-s format test:dev",
19
- "format": "run-s format:check-fix:*",
20
- "format:ci": "run-s format:check:*",
21
- "format:check-fix:lint": "run-e format:check:lint format:fix:lint",
22
- "format:check:lint": "cross-env-shell eslint $npm_package_config_eslint",
23
- "format:fix:lint": "cross-env-shell eslint --fix $npm_package_config_eslint",
24
- "format:check-fix:prettier": "run-e format:check:prettier format:fix:prettier",
25
- "format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier",
26
- "format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier",
27
- "test:dev": "run-s test:dev:*",
28
- "test:ci": "run-s test:ci:*",
29
- "test:dev:ava": "ava",
30
- "test:ci:ava": "c8 -r lcovonly -r text -r json ava"
31
- },
32
- "config": {
33
- "eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,.github}/**/*.{cjs,mjs,js,md,html}\" \"*.{cjs,mjs,js,md,html}\" \".*.{cjs,mjs,js,md,html}\"",
34
- "prettier": "--ignore-path .gitignore --loglevel=warn \"{src,scripts,.github}/**/*.{cjs,mjs,js,md,yml,json,html}\" \"*.{cjs,mjs,js,yml,json,html}\" \".*.{cjs,mjs,js,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\""
35
- },
36
- "ava": {
37
- "verbose": true,
38
- "files": [
39
- "!test/fixtures/**/*"
40
- ]
17
+ "prebuild": "rm -rf lib",
18
+ "build": "tsc",
19
+ "test": "ava",
20
+ "test:ci": "c8 -r lcovonly -r text -r json ava"
41
21
  },
42
22
  "keywords": [],
43
23
  "license": "MIT",
44
24
  "repository": "netlify/build-info",
45
25
  "bugs": {
46
- "url": "https://github.com/netlify/build-info/issues"
26
+ "url": "https://github.com/netlify/build/issues"
47
27
  },
48
28
  "author": "Netlify Inc.",
49
- "directories": {
50
- "test": "test"
51
- },
52
29
  "dependencies": {
53
- "@netlify/framework-info": "^9.0.2",
30
+ "@netlify/framework-info": "^9.3.0",
54
31
  "@npmcli/map-workspaces": "^2.0.0",
55
32
  "read-pkg": "^7.0.0",
56
33
  "yargs": "^17.0.0"
57
34
  },
58
35
  "devDependencies": {
59
- "@netlify/eslint-config-node": "^5.1.5",
60
36
  "ava": "^4.0.0",
61
37
  "c8": "^7.11.0",
62
38
  "execa": "^6.0.0",
63
- "get-bin-path": "^6.0.0",
64
- "husky": "^7.0.4"
39
+ "get-bin-path": "^6.0.0"
65
40
  },
66
41
  "engines": {
67
42
  "node": "^12.20.0 || ^14.14.0 || >=16.0.0"
68
- }
43
+ },
44
+ "gitHead": "4a38bc66bc9897e37beaab9e51a48516b0d02b40"
69
45
  }
package/src/bin.js DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
- import { exit, argv } from 'process'
3
-
4
- import yargs from 'yargs'
5
- import { hideBin } from 'yargs/helpers'
6
-
7
- import { getBuildInfo } from './main.js'
8
-
9
- // CLI entry point
10
- const runCli = async function () {
11
- const { projectDir, rootDir } = parseArgs()
12
-
13
- try {
14
- const buildInfo = await getBuildInfo({ projectDir, rootDir })
15
- console.log(JSON.stringify(buildInfo, null, 2))
16
- } catch (error) {
17
- console.error(error)
18
- exit(1)
19
- }
20
- }
21
-
22
- const parseArgs = function () {
23
- return yargs(hideBin(argv)).command('* [projectDir]').options(OPTIONS).usage(USAGE).strict().parse()
24
- }
25
-
26
- const OPTIONS = {
27
- rootDir: {
28
- string: true,
29
- describe: `The root directory of the project if different from projectDir`,
30
- },
31
- }
32
-
33
- const USAGE = `$0 [OPTIONS...] [PROJECT_DIRECTORY]
34
-
35
- Print relevant build information from a project.`
36
-
37
- runCli()
package/src/context.js DELETED
@@ -1,39 +0,0 @@
1
- import { resolve } from 'path'
2
- import { cwd } from 'process'
3
-
4
- import { readPackage } from 'read-pkg'
5
-
6
- const getPackageJson = async function (dir) {
7
- try {
8
- const packageJson = await readPackage({ cwd: dir, normalize: false })
9
- if (packageJson === undefined) {
10
- return {}
11
- }
12
-
13
- return packageJson
14
- } catch {
15
- return {}
16
- }
17
- }
18
-
19
- export const getContext = async function ({ projectDir = cwd(), rootDir = '' } = {}) {
20
- // Get the absolute dirs for both project and root
21
- // We resolve the projectDir from the rootDir
22
- const absoluteProjectDir = resolve(rootDir, projectDir)
23
- // If a relative absolute path is given we rely on cwd
24
- const absoluteRootDir = rootDir ? resolve(cwd(), rootDir) : undefined
25
-
26
- // We only pass through the root dir if it was provided and is actually different
27
- // from the project dir
28
- const validRootDir = absoluteRootDir && absoluteRootDir !== absoluteProjectDir ? absoluteRootDir : undefined
29
-
30
- // If rootDir equals projectDir we'll be getting the projectDir package.json
31
- // Later on if we also need the projectDir package.json we can check for it
32
- // and only perform one resolution
33
- const rootPackageJson = await getPackageJson(rootDir || projectDir)
34
- return {
35
- projectDir: absoluteProjectDir,
36
- rootDir: validRootDir,
37
- rootPackageJson,
38
- }
39
- }
package/src/core.js DELETED
@@ -1,11 +0,0 @@
1
- 'use strict'
2
-
3
- import { getFrameworks } from './frameworks.js'
4
- import { getWorkspaceInfo } from './workspaces.js'
5
-
6
- export const buildInfo = async function (context) {
7
- const workspaceInfo = await getWorkspaceInfo(context)
8
- const jsWorkspaces = workspaceInfo ? { jsWorkspaces: workspaceInfo } : {}
9
- const frameworks = await getFrameworks(context)
10
- return { ...jsWorkspaces, frameworks }
11
- }
package/src/frameworks.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict'
2
-
3
- import { listFrameworks } from '@netlify/framework-info'
4
-
5
- export const getFrameworks = async function ({ projectDir }) {
6
- return await listFrameworks({ projectDir })
7
- }
package/src/main.js DELETED
@@ -1,9 +0,0 @@
1
- 'use strict'
2
-
3
- import { getContext } from './context.js'
4
- import { buildInfo } from './core.js'
5
-
6
- export const getBuildInfo = async function (opts) {
7
- const context = await getContext(opts)
8
- return await buildInfo(context)
9
- }
package/src/workspaces.js DELETED
@@ -1,25 +0,0 @@
1
- 'use strict'
2
-
3
- import mapWorkspaces from '@npmcli/map-workspaces'
4
-
5
- export const getWorkspaceInfo = async function ({ rootPackageJson, projectDir, rootDir }) {
6
- if (!rootPackageJson.workspaces) {
7
- return
8
- }
9
-
10
- const workspacesMap = await mapWorkspaces({
11
- cwd: rootDir || projectDir,
12
- pkg: rootPackageJson,
13
- })
14
-
15
- const packages = [...workspacesMap.values()]
16
- // The provided project dir is a workspace package
17
- const isWorkspace = packages.find((path) => projectDir === path)
18
-
19
- // The project dir is a collection of workspaces itself
20
- const isRoot = !rootDir
21
-
22
- if (isWorkspace || isRoot) {
23
- return { isRoot, packages }
24
- }
25
- }