@netlify/build-info 6.0.8 → 6.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.
@@ -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,129 @@
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', 'BUILD.bazel'];
104
+ const bazelConfigPath = lookFor(bazel, baseDir, rootDir);
105
+ if (bazelConfigPath) {
106
+ return Promise.resolve({
107
+ name: 'bazel',
108
+ });
109
+ }
110
+ },
111
+ moon: async (baseDir, rootDir) => {
112
+ const moon = ['.moon'];
113
+ const moonConfigPath = lookFor(moon, baseDir, rootDir, 'directory');
114
+ if (moonConfigPath) {
115
+ const pkgJson = getPkgJson(moonConfigPath);
116
+ const { devDependencies } = pkgJson;
117
+ return Promise.resolve({
118
+ name: 'moon',
119
+ version: devDependencies?.moon,
120
+ });
121
+ }
122
+ },
123
+ };
124
+ const lookFor = (configFile, baseDir, rootDir, type) => {
125
+ return findUpSync(configFile, { cwd: baseDir, stopAt: rootDir, type: type });
126
+ };
127
+ const getPkgJson = (configPath) => {
128
+ return JSON.parse(readFileSync(path.join(path.dirname(configPath), 'package.json'), 'utf-8'));
129
+ };
@@ -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,20 +1,23 @@
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
8
  let frameworks = [];
9
+ let buildSystems = [];
8
10
  try {
9
- // if the framework detection is crashing we should not crash the build info and package-manager
11
+ // if the framework or buildSystem detection is crashing we should not crash the build info and package-manager
10
12
  // detection
11
13
  frameworks = await listFrameworks({ projectDir: context.projectDir });
14
+ buildSystems = await detectBuildSystems(context.projectDir, context.rootDir);
12
15
  }
13
16
  catch {
14
17
  // TODO: build reporting to buildbot see: https://github.com/netlify/pillar-workflow/issues/1001
15
18
  // noop
16
19
  }
17
- const info = { frameworks };
20
+ const info = { frameworks, buildSystems };
18
21
  // only if we find a root package.json we know this is a javascript workspace
19
22
  if (Object.keys(context.rootPackageJson).length > 0) {
20
23
  info.packageManager = await detectPackageManager(context.projectDir, context.rootDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build-info",
3
- "version": "6.0.8",
3
+ "version": "6.1.0",
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": "b33663b6af4bd9acb552af1d17673679acb2ef75"
55
+ "gitHead": "e22d6106d734d2b4b7b49d2a2350be21913c0cbf"
56
56
  }