@netlify/build-info 5.1.1-rc.0 → 5.1.1-rc.2
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 +5 -2
- package/lib/context.d.ts +1 -1
- package/lib/core.d.ts +1 -10
- package/lib/core.js +4 -0
- package/lib/detect-package-manager.d.ts +23 -0
- package/lib/detect-package-manager.js +67 -0
- package/lib/main.d.ts +1 -10
- package/package.json +6 -2
package/lib/bin.js
CHANGED
|
@@ -11,8 +11,11 @@ yargs(hideBin(argv))
|
|
|
11
11
|
// no build options
|
|
12
12
|
}, async ({ projectDir }) => {
|
|
13
13
|
const context = await getContext({ projectDir });
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const workspaces = await getWorkspaceInfo(context);
|
|
15
|
+
if (!workspaces) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
console.log(workspaces.packages.map((p) => relative(context.projectDir, p)).join(' '));
|
|
16
19
|
})
|
|
17
20
|
.command('* [projectDir]', '', (builder) => builder.options({
|
|
18
21
|
rootDir: {
|
package/lib/context.d.ts
CHANGED
package/lib/core.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
import type { Context } from './context.js';
|
|
2
|
-
export declare const buildInfo: (context: Context) => Promise<
|
|
3
|
-
frameworks: any;
|
|
4
|
-
jsWorkspaces: {
|
|
5
|
-
isRoot: boolean;
|
|
6
|
-
packages: any[];
|
|
7
|
-
};
|
|
8
|
-
} | {
|
|
9
|
-
frameworks: any;
|
|
10
|
-
jsWorkspaces?: undefined;
|
|
11
|
-
}>;
|
|
2
|
+
export declare const buildInfo: (context: Context) => Promise<any>;
|
package/lib/core.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { listFrameworks } from '@netlify/framework-info';
|
|
2
|
+
import { detectPackageManager } from './detect-package-manager.js';
|
|
2
3
|
import { getWorkspaceInfo } from './workspaces.js';
|
|
3
4
|
export const buildInfo = async function (context) {
|
|
4
5
|
const workspaceInfo = await getWorkspaceInfo(context);
|
|
5
6
|
const jsWorkspaces = workspaceInfo ? { jsWorkspaces: workspaceInfo } : {};
|
|
6
7
|
const frameworks = await listFrameworks({ projectDir: context.projectDir });
|
|
8
|
+
if (Object.keys(context.rootPackageJson).length > 0) {
|
|
9
|
+
jsWorkspaces.packageManager = detectPackageManager(context.projectDir);
|
|
10
|
+
}
|
|
7
11
|
return { ...jsWorkspaces, frameworks };
|
|
8
12
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare type PkgManagerFields = {
|
|
2
|
+
/** The package managers name that is used for logging */
|
|
3
|
+
name: string;
|
|
4
|
+
/** The package managers install command */
|
|
5
|
+
installCommand: string;
|
|
6
|
+
/** The lock file a package manager is using */
|
|
7
|
+
lockFile: string;
|
|
8
|
+
/** Environment variable that can be used to force the usage of a package manager even though there is no lock file or a different lock file */
|
|
9
|
+
forceEnvironment?: string;
|
|
10
|
+
/** Flags that should be used for running the install command */
|
|
11
|
+
installFlags?: string[];
|
|
12
|
+
/** A list of all cache locations for the package manager */
|
|
13
|
+
cacheLocations?: string[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Detects the used package manager based on
|
|
17
|
+
* - a set environment variable that forces the usage
|
|
18
|
+
* - a lock file that is present in this directory or up in the tree for workspaces
|
|
19
|
+
* @param cwd The current process working directory of the build
|
|
20
|
+
* @returns The package manager that was detected
|
|
21
|
+
*/
|
|
22
|
+
export declare const detectPackageManager: (cwd?: string) => Promise<PkgManagerFields>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
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',
|
|
8
|
+
installCommand: 'yarn install',
|
|
9
|
+
lockFile: 'yarn.lock',
|
|
10
|
+
forceEnvironment: 'NETLIFY_USE_YARN',
|
|
11
|
+
},
|
|
12
|
+
["pnpm" /* PkgManager.PNPM */]: {
|
|
13
|
+
name: 'pnpm',
|
|
14
|
+
installCommand: 'pnpm install',
|
|
15
|
+
lockFile: 'pnpm-lock.yaml',
|
|
16
|
+
forceEnvironment: 'NETLIFY_USE_PNPM',
|
|
17
|
+
},
|
|
18
|
+
["npm" /* PkgManager.NPM */]: {
|
|
19
|
+
name: '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
|
+
* - a set environment variable that forces the usage
|
|
32
|
+
* - a lock file that is present in this directory or up in the tree for workspaces
|
|
33
|
+
* @param cwd The current process working directory of the build
|
|
34
|
+
* @returns The package manager that was detected
|
|
35
|
+
*/
|
|
36
|
+
export const detectPackageManager = async (cwd) => {
|
|
37
|
+
// the package manager can be enforced via an environment variable as well
|
|
38
|
+
for (const pkgManager of Object.values(AVAILABLE_PACKAGE_MANAGERS)) {
|
|
39
|
+
if (pkgManager.forceEnvironment && process.env[pkgManager.forceEnvironment] === 'true') {
|
|
40
|
+
return pkgManager;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// find the correct lock file the tree up
|
|
44
|
+
const lockFilePath = await findUp(Object.keys(lockFileMap), { cwd });
|
|
45
|
+
// if we found a lock file and the usage is not prohibited through an environment variable
|
|
46
|
+
// return the found package manager
|
|
47
|
+
if (lockFilePath) {
|
|
48
|
+
const lockFile = basename(lockFilePath);
|
|
49
|
+
if (lockFileMap[lockFile].forceEnvironment !== 'false') {
|
|
50
|
+
return lockFileMap[lockFile];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const pkgPaths = await findUpMultiple('package.json', { cwd });
|
|
54
|
+
for (const pkgPath of pkgPaths) {
|
|
55
|
+
const { packageManager } = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
56
|
+
if (packageManager) {
|
|
57
|
+
//
|
|
58
|
+
const [parsed] = packageManager.split('@');
|
|
59
|
+
if (AVAILABLE_PACKAGE_MANAGERS[parsed]) {
|
|
60
|
+
return AVAILABLE_PACKAGE_MANAGERS[parsed];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// always default to npm
|
|
65
|
+
// TODO: add some reporting here to log that we fall backed
|
|
66
|
+
return AVAILABLE_PACKAGE_MANAGERS["npm" /* PkgManager.NPM */];
|
|
67
|
+
};
|
package/lib/main.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
import { ContextOptions } from './context.js';
|
|
2
|
-
export declare const getBuildInfo: (opts: ContextOptions) => Promise<
|
|
3
|
-
frameworks: any;
|
|
4
|
-
jsWorkspaces: {
|
|
5
|
-
isRoot: boolean;
|
|
6
|
-
packages: any[];
|
|
7
|
-
};
|
|
8
|
-
} | {
|
|
9
|
-
frameworks: any;
|
|
10
|
-
jsWorkspaces?: undefined;
|
|
11
|
-
}>;
|
|
2
|
+
export declare const getBuildInfo: (opts: ContextOptions) => Promise<any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/build-info",
|
|
3
|
-
"version": "5.1.1-rc.
|
|
3
|
+
"version": "5.1.1-rc.2",
|
|
4
4
|
"description": "Build info utility",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/main.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"prebuild": "rm -rf lib",
|
|
18
18
|
"build": "tsc",
|
|
19
19
|
"test": "vitest run",
|
|
20
|
-
"test:dev": "vitest",
|
|
20
|
+
"test:dev": "vitest --ui",
|
|
21
21
|
"test:ci": "vitest run --reporter=default"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [],
|
|
@@ -30,14 +30,18 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@netlify/framework-info": "^9.3.0",
|
|
32
32
|
"@npmcli/map-workspaces": "^2.0.0",
|
|
33
|
+
"find-up": "^6.3.0",
|
|
33
34
|
"read-pkg": "^7.1.0",
|
|
34
35
|
"yargs": "^17.6.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/node": "^14.18.31",
|
|
38
39
|
"@vitest/coverage-c8": "^0.24.1",
|
|
40
|
+
"@vitest/ui": "^0.24.3",
|
|
39
41
|
"execa": "^6.0.0",
|
|
42
|
+
"memfs": "^3.4.7",
|
|
40
43
|
"typescript": "^4.8.4",
|
|
44
|
+
"unionfs": "^4.4.0",
|
|
41
45
|
"vitest": "^0.24.1"
|
|
42
46
|
},
|
|
43
47
|
"engines": {
|