@netlify/build-info 6.2.2 → 6.3.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/bin.js +1 -1
- package/lib/browser/file-system.d.ts +25 -0
- package/lib/browser/file-system.js +70 -0
- package/lib/build-systems/bazel.d.ts +8 -0
- package/lib/build-systems/bazel.js +12 -0
- package/lib/build-systems/buck.d.ts +8 -0
- package/lib/build-systems/buck.js +12 -0
- package/lib/build-systems/build-system.d.ts +20 -0
- package/lib/build-systems/build-system.js +18 -0
- package/lib/build-systems/gradle.d.ts +8 -0
- package/lib/build-systems/gradle.js +12 -0
- package/lib/build-systems/index.d.ts +2 -0
- package/lib/build-systems/index.js +11 -0
- package/lib/build-systems/lage.d.ts +6 -0
- package/lib/build-systems/lage.js +6 -0
- package/lib/build-systems/moon.d.ts +8 -0
- package/lib/build-systems/moon.js +18 -0
- package/lib/build-systems/nix.d.ts +8 -0
- package/lib/build-systems/nix.js +12 -0
- package/lib/build-systems/nrwl.d.ts +11 -0
- package/lib/build-systems/nrwl.js +11 -0
- package/lib/build-systems/pants.d.ts +8 -0
- package/lib/build-systems/pants.js +12 -0
- package/lib/build-systems/rush.d.ts +6 -0
- package/lib/build-systems/rush.js +6 -0
- package/lib/build-systems/turbo.d.ts +6 -0
- package/lib/build-systems/turbo.js +6 -0
- package/lib/file-system.d.ts +69 -0
- package/lib/file-system.js +195 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/{bin.d.ts → node/bin.d.ts} +0 -0
- package/lib/{bin.js → node/bin.js} +2 -3
- package/lib/node/file-system.d.ts +19 -0
- package/lib/node/file-system.js +65 -0
- package/lib/node/get-build-info.d.ts +20 -0
- package/lib/node/get-build-info.js +46 -0
- package/lib/{detect-package-manager.d.ts → package-managers/detect-package-manager.d.ts} +2 -4
- package/lib/package-managers/detect-package-manager.js +75 -0
- package/lib/project.d.ts +33 -0
- package/lib/project.js +82 -0
- package/lib/workspaces/detect-workspace.d.ts +22 -0
- package/lib/workspaces/detect-workspace.js +56 -0
- package/lib/workspaces/get-workspace-packages.d.ts +3 -0
- package/lib/workspaces/get-workspace-packages.js +66 -0
- package/package.json +9 -4
- package/lib/context.d.ts +0 -11
- package/lib/context.js +0 -45
- package/lib/detect-build-system.d.ts +0 -5
- package/lib/detect-build-system.js +0 -145
- package/lib/detect-package-manager.js +0 -71
- package/lib/get-build-info.d.ts +0 -11
- package/lib/get-build-info.js +0 -34
- package/lib/workspaces.d.ts +0 -22
- package/lib/workspaces.js +0 -56
|
@@ -1,145 +0,0 @@
|
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
107
|
-
name: 'bazel',
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
nix: async (baseDir, rootDir) => {
|
|
112
|
-
const nix = ['default.nix', 'shell.nix', 'release.nix'];
|
|
113
|
-
const nixConfigPath = lookFor(nix, baseDir, rootDir);
|
|
114
|
-
if (nixConfigPath) {
|
|
115
|
-
return {
|
|
116
|
-
name: 'nix',
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
moon: async (baseDir, rootDir) => {
|
|
121
|
-
const moon = ['.moon'];
|
|
122
|
-
const moonConfigPath = lookFor(moon, baseDir, rootDir, 'directory');
|
|
123
|
-
if (moonConfigPath) {
|
|
124
|
-
const pkgJson = getPkgJson(moonConfigPath);
|
|
125
|
-
const { devDependencies } = pkgJson;
|
|
126
|
-
return {
|
|
127
|
-
name: 'moon',
|
|
128
|
-
version: devDependencies?.moon,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
const lookFor = (configFile, baseDir, rootDir, type) => {
|
|
134
|
-
return findUpSync(configFile, { cwd: baseDir, stopAt: rootDir, type: type });
|
|
135
|
-
};
|
|
136
|
-
const getPkgJson = (configPath) => {
|
|
137
|
-
let pkgJson = {};
|
|
138
|
-
try {
|
|
139
|
-
pkgJson = JSON.parse(readFileSync(path.join(path.dirname(configPath), 'package.json'), 'utf-8'));
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
// noop
|
|
143
|
-
}
|
|
144
|
-
return pkgJson;
|
|
145
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { basename } from 'path';
|
|
3
|
-
import { findUp, findUpMultiple } from 'find-up';
|
|
4
|
-
/** The definition of all available package managers */
|
|
5
|
-
const AVAILABLE_PACKAGE_MANAGERS = {
|
|
6
|
-
["yarn" /* PkgManager.YARN */]: {
|
|
7
|
-
name: "yarn" /* PkgManager.YARN */,
|
|
8
|
-
installCommand: 'yarn install',
|
|
9
|
-
lockFile: 'yarn.lock',
|
|
10
|
-
forceEnvironment: 'NETLIFY_USE_YARN',
|
|
11
|
-
},
|
|
12
|
-
["pnpm" /* PkgManager.PNPM */]: {
|
|
13
|
-
name: "pnpm" /* PkgManager.PNPM */,
|
|
14
|
-
installCommand: 'pnpm install',
|
|
15
|
-
lockFile: 'pnpm-lock.yaml',
|
|
16
|
-
forceEnvironment: 'NETLIFY_USE_PNPM',
|
|
17
|
-
},
|
|
18
|
-
["npm" /* PkgManager.NPM */]: {
|
|
19
|
-
name: "npm" /* PkgManager.NPM */,
|
|
20
|
-
installCommand: 'npm install',
|
|
21
|
-
lockFile: 'package-lock.json',
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* generate a map out of key is lock file and value the package manager
|
|
26
|
-
* this is to reduce the complexity in loops
|
|
27
|
-
*/
|
|
28
|
-
const lockFileMap = Object.values(AVAILABLE_PACKAGE_MANAGERS).reduce((cur, pkgManager) => ({ ...cur, [pkgManager.lockFile]: pkgManager }), {});
|
|
29
|
-
/**
|
|
30
|
-
* Detects the used package manager based on
|
|
31
|
-
* 1. packageManager field
|
|
32
|
-
* 2. environment variable that forces the usage
|
|
33
|
-
* 3. a lock file that is present in this directory or up in the tree for workspaces
|
|
34
|
-
* @param cwd The current process working directory of the build
|
|
35
|
-
* @param stopAt The repository root where it should stop looking up for package.json or lock files. (defaults to `path.parse(cwd).root`)
|
|
36
|
-
* @returns The package manager that was detected
|
|
37
|
-
*/
|
|
38
|
-
export const detectPackageManager = async (cwd, stopAt) => {
|
|
39
|
-
const pkgPaths = await findUpMultiple('package.json', { cwd, stopAt });
|
|
40
|
-
for (const pkgPath of pkgPaths) {
|
|
41
|
-
const { packageManager } = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
42
|
-
if (packageManager) {
|
|
43
|
-
//
|
|
44
|
-
const [parsed] = packageManager.split('@');
|
|
45
|
-
if (AVAILABLE_PACKAGE_MANAGERS[parsed]) {
|
|
46
|
-
return AVAILABLE_PACKAGE_MANAGERS[parsed];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// the package manager can be enforced via an environment variable as well
|
|
51
|
-
for (const pkgManager of Object.values(AVAILABLE_PACKAGE_MANAGERS)) {
|
|
52
|
-
if (pkgManager.forceEnvironment && process.env[pkgManager.forceEnvironment] === 'true') {
|
|
53
|
-
return pkgManager;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// find the correct lock file the tree up
|
|
57
|
-
const lockFilePath = await findUp(Object.keys(lockFileMap), { cwd, stopAt });
|
|
58
|
-
// if we found a lock file and the usage is not prohibited through an environment variable
|
|
59
|
-
// return the found package manager
|
|
60
|
-
if (lockFilePath) {
|
|
61
|
-
const lockFile = basename(lockFilePath);
|
|
62
|
-
const pkgManager = lockFileMap[lockFile];
|
|
63
|
-
// check if it not got disabled
|
|
64
|
-
if (!(pkgManager.forceEnvironment && process.env[pkgManager.forceEnvironment] === 'false')) {
|
|
65
|
-
return pkgManager;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// always default to npm
|
|
69
|
-
// TODO: add some reporting here to log that we fall backed
|
|
70
|
-
return AVAILABLE_PACKAGE_MANAGERS["npm" /* PkgManager.NPM */];
|
|
71
|
-
};
|
package/lib/get-build-info.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ContextOptions } from './context.js';
|
|
2
|
-
import { BuildSystem } from './detect-build-system.js';
|
|
3
|
-
import { PkgManagerFields } from './detect-package-manager.js';
|
|
4
|
-
import { WorkspaceInfo } from './workspaces.js';
|
|
5
|
-
export type Info = {
|
|
6
|
-
jsWorkspaces?: WorkspaceInfo;
|
|
7
|
-
packageManager?: PkgManagerFields;
|
|
8
|
-
frameworks: unknown[];
|
|
9
|
-
buildSystems?: BuildSystem[];
|
|
10
|
-
};
|
|
11
|
-
export declare const getBuildInfo: (opts: ContextOptions) => Promise<Info>;
|
package/lib/get-build-info.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { listFrameworks } from '@netlify/framework-info';
|
|
2
|
-
import { getContext } from './context.js';
|
|
3
|
-
import { detectBuildSystems } from './detect-build-system.js';
|
|
4
|
-
import { detectPackageManager } from './detect-package-manager.js';
|
|
5
|
-
import { getWorkspaceInfo } from './workspaces.js';
|
|
6
|
-
export const getBuildInfo = async (opts) => {
|
|
7
|
-
const context = await getContext(opts);
|
|
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 };
|
|
19
|
-
try {
|
|
20
|
-
info.buildSystems = await detectBuildSystems(context.projectDir, context.rootDir);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
// noop
|
|
24
|
-
}
|
|
25
|
-
// only if we find a root package.json we know this is a javascript workspace
|
|
26
|
-
if (Object.keys(context.rootPackageJson).length > 0) {
|
|
27
|
-
info.packageManager = await detectPackageManager(context.projectDir, context.rootDir);
|
|
28
|
-
const workspaceInfo = await getWorkspaceInfo(info.packageManager, context);
|
|
29
|
-
if (workspaceInfo) {
|
|
30
|
-
info.jsWorkspaces = workspaceInfo;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return info;
|
|
34
|
-
};
|
package/lib/workspaces.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { PackageJson } from 'read-pkg';
|
|
2
|
-
import type { Context } from './context.js';
|
|
3
|
-
import { PkgManagerFields } from './detect-package-manager.js';
|
|
4
|
-
export type WorkspaceInfo = {
|
|
5
|
-
/** if we are in the current workspace root or not */
|
|
6
|
-
isRoot: boolean;
|
|
7
|
-
/** the workspace root directory */
|
|
8
|
-
rootDir: string;
|
|
9
|
-
/** list of relative package paths inside the workspace */
|
|
10
|
-
packages: string[];
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Get a list of globs about all the packages inside a pnpm workspace
|
|
14
|
-
* https://pnpm.io/pnpm-workspace_yaml
|
|
15
|
-
*/
|
|
16
|
-
export declare const detectPnpmWorkspaceGlobs: (rootDir: string) => string[];
|
|
17
|
-
export declare const detectNpmOrYarnWorkspaceGlobs: (pkgJson: PackageJson) => string[];
|
|
18
|
-
/**
|
|
19
|
-
* If it's a javascript workspace (npm, pnpm, yarn) it will retrieve a list of all
|
|
20
|
-
* relative package paths and will indicate if it's the root of the workspace
|
|
21
|
-
*/
|
|
22
|
-
export declare const getWorkspaceInfo: (packageManager: PkgManagerFields, context: Context) => Promise<undefined | WorkspaceInfo>;
|
package/lib/workspaces.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'fs';
|
|
2
|
-
import { join, relative } from 'path';
|
|
3
|
-
import mapWorkspaces from '@npmcli/map-workspaces';
|
|
4
|
-
import { parse } from 'yaml';
|
|
5
|
-
/**
|
|
6
|
-
* Get a list of globs about all the packages inside a pnpm workspace
|
|
7
|
-
* https://pnpm.io/pnpm-workspace_yaml
|
|
8
|
-
*/
|
|
9
|
-
export const detectPnpmWorkspaceGlobs = (rootDir) => {
|
|
10
|
-
const workspaceFile = join(rootDir, 'pnpm-workspace.yaml');
|
|
11
|
-
if (!existsSync(workspaceFile)) {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
const { packages } = parse(readFileSync(workspaceFile, 'utf-8'));
|
|
15
|
-
return packages;
|
|
16
|
-
};
|
|
17
|
-
export const detectNpmOrYarnWorkspaceGlobs = (pkgJson) => {
|
|
18
|
-
if (Array.isArray(pkgJson.workspaces)) {
|
|
19
|
-
return pkgJson.workspaces;
|
|
20
|
-
}
|
|
21
|
-
if (typeof pkgJson.workspaces === 'object') {
|
|
22
|
-
return pkgJson.workspaces.packages || [];
|
|
23
|
-
}
|
|
24
|
-
return [];
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* If it's a javascript workspace (npm, pnpm, yarn) it will retrieve a list of all
|
|
28
|
-
* relative package paths and will indicate if it's the root of the workspace
|
|
29
|
-
*/
|
|
30
|
-
export const getWorkspaceInfo = async (packageManager, context) => {
|
|
31
|
-
const rootDir = context.rootDir || context.projectDir;
|
|
32
|
-
const workspaceGlobs = packageManager.name === "pnpm" /* PkgManager.PNPM */
|
|
33
|
-
? detectPnpmWorkspaceGlobs(rootDir)
|
|
34
|
-
: detectNpmOrYarnWorkspaceGlobs(context.rootPackageJson);
|
|
35
|
-
if (workspaceGlobs.length === 0) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const workspacesMap = await mapWorkspaces({
|
|
39
|
-
cwd: rootDir,
|
|
40
|
-
pkg: { workspaces: workspaceGlobs },
|
|
41
|
-
});
|
|
42
|
-
// make paths relative
|
|
43
|
-
const packages = [...workspacesMap.values()].map((p) => relative(rootDir, p));
|
|
44
|
-
// The provided project dir is a workspace package and not a different directory
|
|
45
|
-
// in a mono repository that is not part inside the npm workspaces
|
|
46
|
-
const isWorkspace = packages.find((path) => context.projectDir === join(rootDir, path));
|
|
47
|
-
// The project dir is a collection of workspaces itself
|
|
48
|
-
const isRoot = !context.rootDir;
|
|
49
|
-
if (isWorkspace || isRoot) {
|
|
50
|
-
return {
|
|
51
|
-
isRoot,
|
|
52
|
-
packages,
|
|
53
|
-
rootDir,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
};
|