@netlify/build-info 6.0.6 → 6.0.8-rc

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/bin.js CHANGED
File without changes
package/lib/context.js CHANGED
@@ -29,7 +29,14 @@ export const getContext = async (config = {}) => {
29
29
  // If rootDir equals projectDir we'll be getting the projectDir package.json
30
30
  // Later on if we also need the projectDir package.json we can check for it
31
31
  // and only perform one resolution
32
- const rootPackageJson = await getRootPackageJson(absoluteProjectDir, validRootDir || absoluteProjectDir);
32
+ let rootPackageJson = {};
33
+ try {
34
+ rootPackageJson = await getRootPackageJson(absoluteProjectDir, validRootDir || absoluteProjectDir);
35
+ }
36
+ catch {
37
+ // gracefully handle un-parseable package.json files
38
+ //noop
39
+ }
33
40
  return {
34
41
  projectDir: absoluteProjectDir,
35
42
  rootDir: validRootDir,
@@ -0,0 +1,5 @@
1
+ export declare type BuildSystem = {
2
+ name: string;
3
+ version?: string | undefined;
4
+ };
5
+ export declare const detectBuildSystems: (baseDir: string, rootDir?: string) => Promise<BuildSystem[]>;
@@ -0,0 +1,117 @@
1
+ import { readFileSync } from 'fs';
2
+ import path from 'path';
3
+ import { findUpSync } from 'find-up';
4
+ export const detectBuildSystems = async (baseDir, rootDir) => {
5
+ const buildTools = Object.keys(BUILD_SYSTEMS);
6
+ const buildSystems = await Promise.all(buildTools.map(async (tool) => await BUILD_SYSTEMS[tool](baseDir, rootDir)));
7
+ return buildSystems.reduce((res, tool) => {
8
+ if (tool) {
9
+ res.push(tool);
10
+ }
11
+ return res;
12
+ }, []);
13
+ };
14
+ const BUILD_SYSTEMS = {
15
+ nx: async (baseDir, rootDir) => {
16
+ const nx = ['nx.json'];
17
+ const nxConfigPath = lookFor(nx, baseDir, rootDir);
18
+ if (nxConfigPath) {
19
+ const pkgJson = getPkgJson(nxConfigPath);
20
+ const { devDependencies } = pkgJson;
21
+ return Promise.resolve({
22
+ name: 'nx',
23
+ version: devDependencies?.nx,
24
+ });
25
+ }
26
+ },
27
+ lerna: async (baseDir, rootDir) => {
28
+ const lerna = ['lerna.json'];
29
+ const lernaConfigPath = lookFor(lerna, baseDir, rootDir);
30
+ if (lernaConfigPath) {
31
+ const pkgJson = getPkgJson(lernaConfigPath);
32
+ const { devDependencies } = pkgJson;
33
+ return Promise.resolve({
34
+ name: 'lerna',
35
+ version: devDependencies?.lerna,
36
+ });
37
+ }
38
+ },
39
+ turbo: async (baseDir, rootDir) => {
40
+ const turbo = ['turbo.json'];
41
+ const turboConfigPath = lookFor(turbo, baseDir, rootDir);
42
+ if (turboConfigPath) {
43
+ const pkgJson = getPkgJson(turboConfigPath);
44
+ const { devDependencies } = pkgJson;
45
+ return Promise.resolve({
46
+ name: 'turbo',
47
+ version: devDependencies?.turbo,
48
+ });
49
+ }
50
+ },
51
+ rush: async (baseDir, rootDir) => {
52
+ const rush = ['rush.json'];
53
+ const rushConfigPath = lookFor(rush, baseDir, rootDir);
54
+ if (rushConfigPath) {
55
+ const pkgJson = getPkgJson(rushConfigPath);
56
+ const { devDependencies } = pkgJson;
57
+ return Promise.resolve({
58
+ name: 'rush',
59
+ version: devDependencies?.rush,
60
+ });
61
+ }
62
+ },
63
+ lage: async (baseDir, rootDir) => {
64
+ const lage = ['lage.config.js'];
65
+ const lageConfigPath = lookFor(lage, baseDir, rootDir);
66
+ if (lageConfigPath) {
67
+ const pkgJson = getPkgJson(lageConfigPath);
68
+ const { devDependencies } = pkgJson;
69
+ return Promise.resolve({
70
+ name: 'lage',
71
+ version: devDependencies?.lage,
72
+ });
73
+ }
74
+ },
75
+ pants: async (baseDir, rootDir) => {
76
+ const pants = ['pants.toml'];
77
+ const pantsConfigPath = lookFor(pants, baseDir, rootDir);
78
+ if (pantsConfigPath) {
79
+ return Promise.resolve({
80
+ name: 'pants',
81
+ });
82
+ }
83
+ },
84
+ buck: async (baseDir, rootDir) => {
85
+ const buck = ['.buckconfig', 'BUCK'];
86
+ const buckConfigPath = lookFor(buck, baseDir, rootDir);
87
+ if (buckConfigPath) {
88
+ return Promise.resolve({
89
+ name: 'buck',
90
+ });
91
+ }
92
+ },
93
+ gradle: async (baseDir, rootDir) => {
94
+ const gradle = ['build.gradle'];
95
+ const gradleConfigPath = lookFor(gradle, baseDir, rootDir);
96
+ if (gradleConfigPath) {
97
+ return Promise.resolve({
98
+ name: 'gradle',
99
+ });
100
+ }
101
+ },
102
+ bazel: async (baseDir, rootDir) => {
103
+ const bazel = ['.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel'];
104
+ const bazelConfigPath = lookFor(bazel, baseDir, rootDir);
105
+ if (bazelConfigPath) {
106
+ return Promise.resolve({
107
+ name: 'bazel',
108
+ });
109
+ }
110
+ },
111
+ };
112
+ const lookFor = (configFile, baseDir, rootDir) => {
113
+ return findUpSync(configFile, { cwd: baseDir, stopAt: rootDir });
114
+ };
115
+ const getPkgJson = (configPath) => {
116
+ return JSON.parse(readFileSync(path.join(path.dirname(configPath), 'package.json'), 'utf-8'));
117
+ };
@@ -1,9 +1,11 @@
1
1
  import { ContextOptions } from './context.js';
2
+ import { BuildSystem } from './detect-build-system.js';
2
3
  import { PkgManagerFields } from './detect-package-manager.js';
3
4
  import { WorkspaceInfo } from './workspaces.js';
4
5
  export declare type Info = {
5
6
  jsWorkspaces?: WorkspaceInfo;
6
7
  packageManager?: PkgManagerFields;
7
8
  frameworks: unknown[];
9
+ buildSystems?: BuildSystem[];
8
10
  };
9
11
  export declare const getBuildInfo: (opts: ContextOptions) => Promise<Info>;
@@ -1,12 +1,21 @@
1
1
  import { listFrameworks } from '@netlify/framework-info';
2
2
  import { getContext } from './context.js';
3
+ import { detectBuildSystems } from './detect-build-system.js';
3
4
  import { detectPackageManager } from './detect-package-manager.js';
4
5
  import { getWorkspaceInfo } from './workspaces.js';
5
6
  export const getBuildInfo = async (opts) => {
6
7
  const context = await getContext(opts);
7
- const info = {
8
- frameworks: await listFrameworks({ projectDir: context.projectDir }),
9
- };
8
+ let frameworks = [];
9
+ try {
10
+ // if the framework detection is crashing we should not crash the build info and package-manager
11
+ // detection
12
+ frameworks = await listFrameworks({ projectDir: context.projectDir });
13
+ }
14
+ catch {
15
+ // TODO: build reporting to buildbot see: https://github.com/netlify/pillar-workflow/issues/1001
16
+ // noop
17
+ }
18
+ const info = { frameworks };
10
19
  // only if we find a root package.json we know this is a javascript workspace
11
20
  if (Object.keys(context.rootPackageJson).length > 0) {
12
21
  info.packageManager = await detectPackageManager(context.projectDir, context.rootDir);
@@ -15,5 +24,9 @@ export const getBuildInfo = async (opts) => {
15
24
  info.jsWorkspaces = workspaceInfo;
16
25
  }
17
26
  }
27
+ const buildSystems = await detectBuildSystems(context.projectDir, context.rootDir);
28
+ if (buildSystems.length > 0) {
29
+ info.buildSystems = buildSystems;
30
+ }
18
31
  return info;
19
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build-info",
3
- "version": "6.0.6",
3
+ "version": "6.0.8-rc",
4
4
  "description": "Build info utility",
5
5
  "type": "module",
6
6
  "exports": {
@@ -51,6 +51,5 @@
51
51
  },
52
52
  "engines": {
53
53
  "node": "^14.16.0 || >=16.0.0"
54
- },
55
- "gitHead": "c7e107e79b77f3037ca6d10aceadfa208af5ace8"
54
+ }
56
55
  }