@netlify/build-info 6.2.2 → 6.2.3-rc.1
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/src/browser/file-system.d.ts +25 -0
- package/lib/src/browser/file-system.js +70 -0
- package/lib/src/build-systems/bazel.d.ts +7 -0
- package/lib/src/build-systems/bazel.js +15 -0
- package/lib/src/build-systems/buck.d.ts +7 -0
- package/lib/src/build-systems/buck.js +15 -0
- package/lib/src/build-systems/build-system.d.ts +29 -0
- package/lib/src/build-systems/build-system.js +25 -0
- package/lib/src/build-systems/gradle.d.ts +7 -0
- package/lib/src/build-systems/gradle.js +15 -0
- package/lib/src/build-systems/index.d.ts +2 -0
- package/lib/src/build-systems/index.js +11 -0
- package/lib/src/build-systems/lage.d.ts +6 -0
- package/lib/src/build-systems/lage.js +6 -0
- package/lib/src/build-systems/moon.d.ts +7 -0
- package/lib/src/build-systems/moon.js +18 -0
- package/lib/src/build-systems/nix.d.ts +7 -0
- package/lib/src/build-systems/nix.js +15 -0
- package/lib/src/build-systems/nrwl.d.ts +16 -0
- package/lib/src/build-systems/nrwl.js +55 -0
- package/lib/src/build-systems/pants.d.ts +7 -0
- package/lib/src/build-systems/pants.js +15 -0
- package/lib/src/build-systems/rush.d.ts +6 -0
- package/lib/src/build-systems/rush.js +6 -0
- package/lib/src/build-systems/turbo.d.ts +6 -0
- package/lib/src/build-systems/turbo.js +6 -0
- package/lib/src/file-system.d.ts +54 -0
- package/lib/src/file-system.js +160 -0
- package/lib/src/frameworks/angular.d.ts +24 -0
- package/lib/src/frameworks/angular.js +22 -0
- package/lib/src/frameworks/assemble.d.ts +16 -0
- package/lib/src/frameworks/assemble.js +16 -0
- package/lib/src/frameworks/astro.d.ts +25 -0
- package/lib/src/frameworks/astro.js +23 -0
- package/lib/src/frameworks/blitz.d.ts +23 -0
- package/lib/src/frameworks/blitz.js +21 -0
- package/lib/src/frameworks/brunch.d.ts +24 -0
- package/lib/src/frameworks/brunch.js +22 -0
- package/lib/src/frameworks/cecil.d.ts +23 -0
- package/lib/src/frameworks/cecil.js +21 -0
- package/lib/src/frameworks/docpad.d.ts +18 -0
- package/lib/src/frameworks/docpad.js +16 -0
- package/lib/src/frameworks/docusaurus.d.ts +30 -0
- package/lib/src/frameworks/docusaurus.js +44 -0
- package/lib/src/frameworks/eleventy.d.ts +24 -0
- package/lib/src/frameworks/eleventy.js +22 -0
- package/lib/src/frameworks/ember.d.ts +24 -0
- package/lib/src/frameworks/ember.js +22 -0
- package/lib/src/frameworks/expo.d.ts +24 -0
- package/lib/src/frameworks/expo.js +22 -0
- package/lib/src/frameworks/framework.d.ts +84 -0
- package/lib/src/frameworks/framework.js +89 -0
- package/lib/src/frameworks/gatsby.d.ts +32 -0
- package/lib/src/frameworks/gatsby.js +44 -0
- package/lib/src/frameworks/gridsome.d.ts +24 -0
- package/lib/src/frameworks/gridsome.js +22 -0
- package/lib/src/frameworks/grunt.d.ts +16 -0
- package/lib/src/frameworks/grunt.js +16 -0
- package/lib/src/frameworks/gulp.d.ts +16 -0
- package/lib/src/frameworks/gulp.js +16 -0
- package/lib/src/frameworks/harp.d.ts +23 -0
- package/lib/src/frameworks/harp.js +21 -0
- package/lib/src/frameworks/hexo.d.ts +24 -0
- package/lib/src/frameworks/hexo.js +22 -0
- package/lib/src/frameworks/hugo.d.ts +23 -0
- package/lib/src/frameworks/hugo.js +21 -0
- package/lib/src/frameworks/hydrogen.d.ts +23 -0
- package/lib/src/frameworks/hydrogen.js +21 -0
- package/lib/src/frameworks/index.d.ts +5 -0
- package/lib/src/frameworks/index.js +95 -0
- package/lib/src/frameworks/jekyll.d.ts +23 -0
- package/lib/src/frameworks/jekyll.js +21 -0
- package/lib/src/frameworks/metalsmith.d.ts +16 -0
- package/lib/src/frameworks/metalsmith.js +16 -0
- package/lib/src/frameworks/middleman.d.ts +23 -0
- package/lib/src/frameworks/middleman.js +21 -0
- package/lib/src/frameworks/next.d.ts +24 -0
- package/lib/src/frameworks/next.js +32 -0
- package/lib/src/frameworks/nuxt.d.ts +25 -0
- package/lib/src/frameworks/nuxt.js +40 -0
- package/lib/src/frameworks/parcel.d.ts +23 -0
- package/lib/src/frameworks/parcel.js +21 -0
- package/lib/src/frameworks/phenomic.d.ts +23 -0
- package/lib/src/frameworks/phenomic.js +21 -0
- package/lib/src/frameworks/quasar.d.ts +25 -0
- package/lib/src/frameworks/quasar.js +36 -0
- package/lib/src/frameworks/qwik.d.ts +23 -0
- package/lib/src/frameworks/qwik.js +24 -0
- package/lib/src/frameworks/react-static.d.ts +24 -0
- package/lib/src/frameworks/react-static.js +22 -0
- package/lib/src/frameworks/react.d.ts +30 -0
- package/lib/src/frameworks/react.js +16 -0
- package/lib/src/frameworks/redwoodjs.d.ts +25 -0
- package/lib/src/frameworks/redwoodjs.js +26 -0
- package/lib/src/frameworks/remix.d.ts +20 -0
- package/lib/src/frameworks/remix.js +20 -0
- package/lib/src/frameworks/roots.d.ts +23 -0
- package/lib/src/frameworks/roots.js +21 -0
- package/lib/src/frameworks/sapper.d.ts +24 -0
- package/lib/src/frameworks/sapper.js +22 -0
- package/lib/src/frameworks/solid-start.d.ts +23 -0
- package/lib/src/frameworks/solid-start.js +21 -0
- package/lib/src/frameworks/solid.d.ts +24 -0
- package/lib/src/frameworks/solid.js +22 -0
- package/lib/src/frameworks/stencil.d.ts +28 -0
- package/lib/src/frameworks/stencil.js +26 -0
- package/lib/src/frameworks/svelte-kit.d.ts +24 -0
- package/lib/src/frameworks/svelte-kit.js +22 -0
- package/lib/src/frameworks/svelte.d.ts +25 -0
- package/lib/src/frameworks/svelte.js +23 -0
- package/lib/src/frameworks/vite.d.ts +24 -0
- package/lib/src/frameworks/vite.js +22 -0
- package/lib/src/frameworks/vue.d.ts +23 -0
- package/lib/src/frameworks/vue.js +21 -0
- package/lib/src/frameworks/vuepress.d.ts +23 -0
- package/lib/src/frameworks/vuepress.js +21 -0
- package/lib/src/frameworks/wintersmith.d.ts +24 -0
- package/lib/src/frameworks/wintersmith.js +22 -0
- package/lib/src/frameworks/wmr.d.ts +23 -0
- package/lib/src/frameworks/wmr.js +21 -0
- package/lib/src/frameworks/zola.d.ts +18 -0
- package/lib/src/frameworks/zola.js +16 -0
- package/lib/src/index.d.ts +2 -0
- package/lib/src/index.js +2 -0
- package/lib/{bin.js → src/node/bin.js} +4 -3
- package/lib/src/node/file-system.d.ts +19 -0
- package/lib/src/node/file-system.js +60 -0
- package/lib/src/node/get-build-info.d.ts +20 -0
- package/lib/src/node/get-build-info.js +47 -0
- package/lib/{detect-package-manager.d.ts → src/package-managers/detect-package-manager.d.ts} +4 -4
- package/lib/src/package-managers/detect-package-manager.js +82 -0
- package/lib/src/project.d.ts +53 -0
- package/lib/src/project.js +207 -0
- package/lib/src/workspaces/detect-workspace.d.ts +22 -0
- package/lib/src/workspaces/detect-workspace.js +61 -0
- package/lib/src/workspaces/get-workspace-packages.d.ts +20 -0
- package/lib/src/workspaces/get-workspace-packages.js +80 -0
- package/lib/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +14 -10
- 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/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/workspaces.d.ts +0 -22
- package/lib/workspaces.js +0 -56
- /package/lib/{bin.d.ts → src/node/bin.d.ts} +0 -0
package/bin.js
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DirType, FileSystem } from '../file-system.js';
|
|
2
|
+
/** A sample implementation of a github provider */
|
|
3
|
+
export declare class GithubProvider {
|
|
4
|
+
repo: string;
|
|
5
|
+
branch?: string | undefined;
|
|
6
|
+
constructor(repo: string, branch?: string | undefined);
|
|
7
|
+
dir(filePath?: string): Promise<{
|
|
8
|
+
path: string;
|
|
9
|
+
type: 'file' | 'dir';
|
|
10
|
+
}[]>;
|
|
11
|
+
read(filePath: string): Promise<string>;
|
|
12
|
+
private request;
|
|
13
|
+
}
|
|
14
|
+
/** A sample implementation of a web based file system that fetches from Github */
|
|
15
|
+
export declare class WebFS extends FileSystem {
|
|
16
|
+
git: GithubProvider;
|
|
17
|
+
constructor(git: GithubProvider);
|
|
18
|
+
isAbsolute(path: string): boolean;
|
|
19
|
+
resolve(...paths: string[]): string;
|
|
20
|
+
fileExists(path: string): Promise<boolean>;
|
|
21
|
+
/** Get a list of directory entries */
|
|
22
|
+
readDir(path: string): Promise<string[]>;
|
|
23
|
+
readDir(path: string, withFileTypes: true): Promise<Record<string, DirType>>;
|
|
24
|
+
readFile(path: string): Promise<string>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { FileSystem } from '../file-system.js';
|
|
2
|
+
/** A sample implementation of a github provider */
|
|
3
|
+
export class GithubProvider {
|
|
4
|
+
repo;
|
|
5
|
+
branch;
|
|
6
|
+
constructor(repo, branch) {
|
|
7
|
+
this.repo = repo;
|
|
8
|
+
this.branch = branch;
|
|
9
|
+
}
|
|
10
|
+
async dir(filePath = '') {
|
|
11
|
+
let path = `/repos/${this.repo}/contents${filePath}`;
|
|
12
|
+
if (this.branch) {
|
|
13
|
+
path += `?ref=${this.branch}`;
|
|
14
|
+
}
|
|
15
|
+
return this.request(path);
|
|
16
|
+
}
|
|
17
|
+
async read(filePath) {
|
|
18
|
+
const headers = { Accept: 'application/vnd.github.VERSION.raw' };
|
|
19
|
+
let path = `/repos/${this.repo}/contents${filePath}`;
|
|
20
|
+
if (this.branch) {
|
|
21
|
+
path += `?ref=${this.branch}`;
|
|
22
|
+
}
|
|
23
|
+
return this.request(path, headers);
|
|
24
|
+
}
|
|
25
|
+
async request(path, headers = {}) {
|
|
26
|
+
const response = await fetch(new URL(path, `https://api.github.com`).href, { headers });
|
|
27
|
+
if (response.headers?.get('Content-Type')?.match(/json/)) {
|
|
28
|
+
const json = await response.json();
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
Promise.reject(json);
|
|
31
|
+
}
|
|
32
|
+
return json;
|
|
33
|
+
}
|
|
34
|
+
return response.text();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** A sample implementation of a web based file system that fetches from Github */
|
|
38
|
+
export class WebFS extends FileSystem {
|
|
39
|
+
git;
|
|
40
|
+
constructor(git) {
|
|
41
|
+
super();
|
|
42
|
+
this.git = git;
|
|
43
|
+
}
|
|
44
|
+
isAbsolute(path) {
|
|
45
|
+
return path.startsWith('/');
|
|
46
|
+
}
|
|
47
|
+
resolve(...paths) {
|
|
48
|
+
const path = this.join(...paths);
|
|
49
|
+
return this.isAbsolute(path) ? path : this.join(this.cwd, path);
|
|
50
|
+
}
|
|
51
|
+
async fileExists(path) {
|
|
52
|
+
try {
|
|
53
|
+
this.readFile(path);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async readDir(path, withFileTypes) {
|
|
61
|
+
const result = await this.git.dir(this.resolve(path));
|
|
62
|
+
if (!withFileTypes) {
|
|
63
|
+
return result.map(({ path }) => path);
|
|
64
|
+
}
|
|
65
|
+
return result.reduce((prev, cur) => ({ ...prev, [cur.path]: cur.type === 'dir' ? 'directory' : 'file' }), {});
|
|
66
|
+
}
|
|
67
|
+
async readFile(path) {
|
|
68
|
+
return this.git.read(this.resolve(path));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseBuildTool } from './build-system.js';
|
|
2
|
+
export class Bazel extends BaseBuildTool {
|
|
3
|
+
id = 'bazel';
|
|
4
|
+
name = 'Bazel';
|
|
5
|
+
configFiles = ['.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'BUILD.bazel'];
|
|
6
|
+
async detect() {
|
|
7
|
+
const config = await this.project.fs.findUp(this.configFiles, {
|
|
8
|
+
cwd: this.project.baseDirectory,
|
|
9
|
+
stopAt: this.project.root,
|
|
10
|
+
});
|
|
11
|
+
if (config) {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseBuildTool } from './build-system.js';
|
|
2
|
+
export class Buck extends BaseBuildTool {
|
|
3
|
+
id = 'buck';
|
|
4
|
+
name = 'Buck';
|
|
5
|
+
configFiles = ['.buckconfig', 'BUCK'];
|
|
6
|
+
async detect() {
|
|
7
|
+
const config = await this.project.fs.findUp(this.configFiles, {
|
|
8
|
+
cwd: this.project.baseDirectory,
|
|
9
|
+
stopAt: this.project.root,
|
|
10
|
+
});
|
|
11
|
+
if (config) {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PollingStrategy } from '../frameworks/framework.js';
|
|
2
|
+
import { Project } from '../project.js';
|
|
3
|
+
export interface BuildSystem {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
project: Project;
|
|
7
|
+
version?: string;
|
|
8
|
+
dev?: {
|
|
9
|
+
command: string;
|
|
10
|
+
port?: number;
|
|
11
|
+
pollingStrategies?: PollingStrategy[];
|
|
12
|
+
};
|
|
13
|
+
detect(): Promise<BuildSystem | undefined>;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class BaseBuildTool implements BuildSystem {
|
|
16
|
+
project: Project;
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
version?: string;
|
|
20
|
+
configFiles: string[];
|
|
21
|
+
constructor(project: Project);
|
|
22
|
+
detect(): Promise<this | undefined>;
|
|
23
|
+
/** Get's a JSON from the class information */
|
|
24
|
+
toJSON(): {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
version: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class BaseBuildTool {
|
|
2
|
+
project;
|
|
3
|
+
id;
|
|
4
|
+
name;
|
|
5
|
+
version;
|
|
6
|
+
configFiles = [];
|
|
7
|
+
constructor(project) {
|
|
8
|
+
this.project = project;
|
|
9
|
+
}
|
|
10
|
+
async detect() {
|
|
11
|
+
const config = await this.project.fs.findUp(this.configFiles, {
|
|
12
|
+
cwd: this.project.baseDirectory,
|
|
13
|
+
stopAt: this.project.root,
|
|
14
|
+
});
|
|
15
|
+
if (config) {
|
|
16
|
+
const pkgJson = await this.project.getPackageJSON(this.project.fs.dirname(config));
|
|
17
|
+
this.version = pkgJson.devDependencies?.[this.id];
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Get's a JSON from the class information */
|
|
22
|
+
toJSON() {
|
|
23
|
+
return { id: this.id, name: this.name, version: this.version };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseBuildTool } from './build-system.js';
|
|
2
|
+
export class Gradle extends BaseBuildTool {
|
|
3
|
+
id = 'gradle';
|
|
4
|
+
name = 'Gradle';
|
|
5
|
+
configFiles = ['build.gradle'];
|
|
6
|
+
async detect() {
|
|
7
|
+
const config = await this.project.fs.findUp(this.configFiles, {
|
|
8
|
+
cwd: this.project.baseDirectory,
|
|
9
|
+
stopAt: this.project.root,
|
|
10
|
+
});
|
|
11
|
+
if (config) {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Bazel } from './bazel.js';
|
|
2
|
+
import { Buck } from './buck.js';
|
|
3
|
+
import { Gradle } from './gradle.js';
|
|
4
|
+
import { Lage } from './lage.js';
|
|
5
|
+
import { Moon } from './moon.js';
|
|
6
|
+
import { Nix } from './nix.js';
|
|
7
|
+
import { Lerna, Nx } from './nrwl.js';
|
|
8
|
+
import { Pants } from './pants.js';
|
|
9
|
+
import { Rush } from './rush.js';
|
|
10
|
+
import { Turbo } from './turbo.js';
|
|
11
|
+
export const buildSystems = [Bazel, Buck, Gradle, Lage, Lerna, Moon, Nix, Nx, Pants, Rush, Turbo];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseBuildTool } from './build-system.js';
|
|
2
|
+
export class Moon extends BaseBuildTool {
|
|
3
|
+
id = 'moon';
|
|
4
|
+
name = 'MoonRepo';
|
|
5
|
+
configFiles = ['.moon'];
|
|
6
|
+
async detect() {
|
|
7
|
+
const config = await this.project.fs.findUp(this.configFiles, {
|
|
8
|
+
cwd: this.project.baseDirectory,
|
|
9
|
+
type: 'directory',
|
|
10
|
+
stopAt: this.project.root,
|
|
11
|
+
});
|
|
12
|
+
if (config) {
|
|
13
|
+
const pkgJson = await this.project.getPackageJSON(config);
|
|
14
|
+
this.version = pkgJson.devDependencies?.[this.id];
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseBuildTool } from './build-system.js';
|
|
2
|
+
export class Nix extends BaseBuildTool {
|
|
3
|
+
id = 'nix';
|
|
4
|
+
name = 'Nix';
|
|
5
|
+
configFiles = ['default.nix', 'shell.nix', 'release.nix'];
|
|
6
|
+
async detect() {
|
|
7
|
+
const config = await this.project.fs.findUp(this.configFiles, {
|
|
8
|
+
cwd: this.project.baseDirectory,
|
|
9
|
+
stopAt: this.project.root,
|
|
10
|
+
});
|
|
11
|
+
if (config) {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseBuildTool } from './build-system.js';
|
|
2
|
+
export declare class Nx extends BaseBuildTool {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
configFiles: string[];
|
|
6
|
+
dev: {
|
|
7
|
+
commands: string[];
|
|
8
|
+
port: number;
|
|
9
|
+
};
|
|
10
|
+
detect(): Promise<this | undefined>;
|
|
11
|
+
}
|
|
12
|
+
export declare class Lerna extends BaseBuildTool {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
configFiles: string[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { findPackages } from '../workspaces/get-workspace-packages.js';
|
|
2
|
+
import { BaseBuildTool } from './build-system.js';
|
|
3
|
+
export class Nx extends BaseBuildTool {
|
|
4
|
+
id = 'nx';
|
|
5
|
+
name = 'Nx';
|
|
6
|
+
configFiles = ['nx.json'];
|
|
7
|
+
dev = {
|
|
8
|
+
commands: ['nx serve'],
|
|
9
|
+
port: 4200,
|
|
10
|
+
};
|
|
11
|
+
async detect() {
|
|
12
|
+
const detected = await super.detect();
|
|
13
|
+
const fs = this.project.fs;
|
|
14
|
+
if (detected) {
|
|
15
|
+
try {
|
|
16
|
+
// in nx integrated setup the workspace is not managed through the package manager
|
|
17
|
+
// in this case we have to check the `nx.json` for the project references
|
|
18
|
+
if (this.project.workspace === null) {
|
|
19
|
+
const { workspaceLayout } = await fs.readJSON(fs.join(this.project.jsWorkspaceRoot, 'nx.json'));
|
|
20
|
+
// if an apps dir is specified get it.
|
|
21
|
+
if (workspaceLayout?.appsDir?.length) {
|
|
22
|
+
const identifyPkg = async ({ entry, directory }) => {
|
|
23
|
+
if (entry === 'project.json') {
|
|
24
|
+
try {
|
|
25
|
+
// we need to check the project json for application types (we don't care about libraries)
|
|
26
|
+
const { projectType } = await fs.readJSON(fs.join(directory, entry));
|
|
27
|
+
return projectType === 'application';
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
const packages = await findPackages(this.project, workspaceLayout.appsDir, identifyPkg, '*');
|
|
36
|
+
this.project.workspace = {
|
|
37
|
+
isRoot: this.project.jsWorkspaceRoot === this.project.baseDirectory,
|
|
38
|
+
packages,
|
|
39
|
+
rootDir: this.project.jsWorkspaceRoot,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// noop
|
|
46
|
+
}
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class Lerna extends BaseBuildTool {
|
|
52
|
+
id = 'lerna';
|
|
53
|
+
name = 'Lerna';
|
|
54
|
+
configFiles = ['lerna.json'];
|
|
55
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseBuildTool } from './build-system.js';
|
|
2
|
+
export class Pants extends BaseBuildTool {
|
|
3
|
+
id = 'pants';
|
|
4
|
+
name = 'Pants';
|
|
5
|
+
configFiles = ['pants.toml'];
|
|
6
|
+
async detect() {
|
|
7
|
+
const config = await this.project.fs.findUp(this.configFiles, {
|
|
8
|
+
cwd: this.project.baseDirectory,
|
|
9
|
+
stopAt: this.project.root,
|
|
10
|
+
});
|
|
11
|
+
if (config) {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
debug(...any: any[]): void;
|
|
3
|
+
log(...any: any[]): void;
|
|
4
|
+
error(...any: any[]): void;
|
|
5
|
+
}
|
|
6
|
+
export type DirType = 'directory' | 'file';
|
|
7
|
+
export type TextFile = {
|
|
8
|
+
content: string;
|
|
9
|
+
type: 'text';
|
|
10
|
+
};
|
|
11
|
+
export type JSONFile<T = Record<string, any>> = {
|
|
12
|
+
content: T;
|
|
13
|
+
type: 'json';
|
|
14
|
+
};
|
|
15
|
+
export type TOMLFile = {
|
|
16
|
+
content: string;
|
|
17
|
+
type: 'toml';
|
|
18
|
+
};
|
|
19
|
+
export type File = TextFile | JSONFile | TOMLFile;
|
|
20
|
+
export type findUpOptions = {
|
|
21
|
+
cwd?: string;
|
|
22
|
+
type?: DirType;
|
|
23
|
+
stopAt?: string;
|
|
24
|
+
};
|
|
25
|
+
/** A platform independent version of path.join() */
|
|
26
|
+
export declare function join(...segments: string[]): string;
|
|
27
|
+
export declare abstract class FileSystem {
|
|
28
|
+
logger: Logger;
|
|
29
|
+
/** The current working directory will be set by the project */
|
|
30
|
+
cwd: string;
|
|
31
|
+
abstract fileExists(path: string): Promise<boolean>;
|
|
32
|
+
abstract readDir(path: string): Promise<string[]>;
|
|
33
|
+
abstract readDir(path: string, withFileTypes: true): Promise<Record<string, DirType>>;
|
|
34
|
+
abstract readDir(path: string, withFileTypes?: true): Promise<Record<string, DirType> | string[]>;
|
|
35
|
+
abstract readFile(path: string): Promise<string>;
|
|
36
|
+
/** resolves a path to an absolute path */
|
|
37
|
+
abstract resolve(...paths: string[]): string;
|
|
38
|
+
/** check if a path is an absolute path */
|
|
39
|
+
abstract isAbsolute(path: string): boolean;
|
|
40
|
+
/** returns the last portion of a path */
|
|
41
|
+
basename(path: string): string;
|
|
42
|
+
/** returns the relative path from to based on the current working directory */
|
|
43
|
+
relative(from: string, to: string): string;
|
|
44
|
+
/** returns the directory name of a path */
|
|
45
|
+
dirname(path: string): string;
|
|
46
|
+
/** A platform independent version of path.join() */
|
|
47
|
+
join(...segments: string[]): string;
|
|
48
|
+
/** Gracefully reads a file as JSON and parses it */
|
|
49
|
+
readJSON<V = Record<string, unknown>>(path: string): Promise<Partial<V>>;
|
|
50
|
+
/** Find a file or directory by walking up parent directories. */
|
|
51
|
+
findUp(name: string | readonly string[], options?: findUpOptions): Promise<string | undefined>;
|
|
52
|
+
/** Find files or directories by walking up parent directories. */
|
|
53
|
+
findUpMultiple(name: string | readonly string[], options?: findUpOptions): Promise<string[]>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
class DefaultLogger {
|
|
2
|
+
debug(...data) {
|
|
3
|
+
// TODO: add reporting
|
|
4
|
+
console.debug(...data);
|
|
5
|
+
}
|
|
6
|
+
log(...data) {
|
|
7
|
+
console.log(...data);
|
|
8
|
+
}
|
|
9
|
+
error(...data) {
|
|
10
|
+
// TODO: on error add reporting
|
|
11
|
+
console.error(...data);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** A platform independent version of path.join() */
|
|
15
|
+
export function join(...segments) {
|
|
16
|
+
let parts = [];
|
|
17
|
+
for (let i = 0, max = segments.length; i < max; i++) {
|
|
18
|
+
// split the segments to parts by all kind of separator (forward and backward)
|
|
19
|
+
parts = parts.concat(segments[i].split(/[\\/]/g));
|
|
20
|
+
}
|
|
21
|
+
// resolve .. inside path segments
|
|
22
|
+
const resolvedParts = [];
|
|
23
|
+
for (let i = 0, max = parts.length; i < max; i++) {
|
|
24
|
+
const part = parts[i];
|
|
25
|
+
// Remove leading and trailing slashes
|
|
26
|
+
// Also remove "." segments
|
|
27
|
+
if (!part || part === '.')
|
|
28
|
+
continue;
|
|
29
|
+
// Interpret ".." to pop the last segment
|
|
30
|
+
if (part === '..') {
|
|
31
|
+
resolvedParts.pop();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
resolvedParts.push(part);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Preserve the initial slash if there was one.
|
|
38
|
+
if (parts[0] === '') {
|
|
39
|
+
resolvedParts.unshift('');
|
|
40
|
+
}
|
|
41
|
+
return resolvedParts.join('/') || (resolvedParts.length ? '/' : '.');
|
|
42
|
+
}
|
|
43
|
+
export class FileSystem {
|
|
44
|
+
logger = new DefaultLogger();
|
|
45
|
+
/** The current working directory will be set by the project */
|
|
46
|
+
cwd = '/';
|
|
47
|
+
/** returns the last portion of a path */
|
|
48
|
+
basename(path) {
|
|
49
|
+
return this.join(path).split('/').pop() || '';
|
|
50
|
+
}
|
|
51
|
+
/** returns the relative path from to based on the current working directory */
|
|
52
|
+
relative(from, to) {
|
|
53
|
+
const absoluteFrom = this.isAbsolute(from) ? from : this.join(this.cwd, from);
|
|
54
|
+
const absoluteTo = this.isAbsolute(to) ? to : this.join(this.cwd, to);
|
|
55
|
+
// if the paths are equal return an empty string
|
|
56
|
+
if (absoluteFrom === absoluteTo) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
const matching = [];
|
|
60
|
+
// split by / excluding the starting slash
|
|
61
|
+
const fromParts = this.join(absoluteFrom).split(/(?<!^)\//gm);
|
|
62
|
+
const toParts = this.join(absoluteTo).split(/(?<!^)\//gm);
|
|
63
|
+
for (let i = 0, max = toParts.length; i < max; i++) {
|
|
64
|
+
if (toParts[i] === fromParts?.[i]) {
|
|
65
|
+
matching.push(toParts[i]);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// calculate how many dirs we need to go up from the to path
|
|
72
|
+
const toUp = toParts.length - matching.length;
|
|
73
|
+
const fromUp = fromParts.length - matching.length;
|
|
74
|
+
// the max we have to go up
|
|
75
|
+
const up = Math.max(toUp, fromUp);
|
|
76
|
+
// if we have something from the 'from' to go up go up the max difference
|
|
77
|
+
const result = fromUp > 0 ? [...new Array(up).fill('..')] : [];
|
|
78
|
+
// if we have some parts left add them to the going up
|
|
79
|
+
if (toUp > 0) {
|
|
80
|
+
result.push(...toParts.slice(-toUp));
|
|
81
|
+
}
|
|
82
|
+
return result.join('/');
|
|
83
|
+
}
|
|
84
|
+
/** returns the directory name of a path */
|
|
85
|
+
dirname(path) {
|
|
86
|
+
const parts = this.join(path).split('/');
|
|
87
|
+
parts.pop();
|
|
88
|
+
// Preserve the initial slash if there was one.
|
|
89
|
+
if (parts.length === 1 && parts[0] === '') {
|
|
90
|
+
return '/';
|
|
91
|
+
}
|
|
92
|
+
return parts.join('/');
|
|
93
|
+
}
|
|
94
|
+
/** A platform independent version of path.join() */
|
|
95
|
+
join(...segments) {
|
|
96
|
+
return join(...segments);
|
|
97
|
+
}
|
|
98
|
+
/** Gracefully reads a file as JSON and parses it */
|
|
99
|
+
async readJSON(path) {
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(await this.readFile(path));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.logger.error(`Could not parse JSON file ${path}\n${error}`);
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Find a file or directory by walking up parent directories. */
|
|
109
|
+
async findUp(name, options = {}) {
|
|
110
|
+
let startDir = this.resolve(options.cwd || this.cwd);
|
|
111
|
+
// function for a recursive call
|
|
112
|
+
const readUp = async () => {
|
|
113
|
+
const entries = await this.readDir(startDir, true);
|
|
114
|
+
const found = Object.entries(entries).find(([entry, dirType]) => {
|
|
115
|
+
if ((typeof name === 'string' && entry === name) || (Array.isArray(name) && name.includes(entry))) {
|
|
116
|
+
if (options.type) {
|
|
117
|
+
if (options.type === dirType) {
|
|
118
|
+
return entry;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return entry;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
// either found something or reached the root and nothing found
|
|
125
|
+
if (found?.[0]) {
|
|
126
|
+
return this.join(startDir, found[0]);
|
|
127
|
+
}
|
|
128
|
+
if (startDir === '/' || (options.stopAt && this.resolve(options.stopAt) === startDir)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
startDir = this.join(startDir, '..');
|
|
132
|
+
// recursive call to walk up
|
|
133
|
+
return readUp();
|
|
134
|
+
};
|
|
135
|
+
return readUp();
|
|
136
|
+
}
|
|
137
|
+
/** Find files or directories by walking up parent directories. */
|
|
138
|
+
async findUpMultiple(name, options = {}) {
|
|
139
|
+
let startDir = this.resolve(options.cwd || this.cwd);
|
|
140
|
+
const found = [];
|
|
141
|
+
// function for a recursive call
|
|
142
|
+
const readUp = async () => {
|
|
143
|
+
const entries = await this.readDir(startDir, true);
|
|
144
|
+
for (const [entry, dirType] of Object.entries(entries)) {
|
|
145
|
+
if ((typeof name === 'string' && entry === name) || (Array.isArray(name) && name.includes(entry))) {
|
|
146
|
+
if ((options.type && options.type === dirType) || !options.type) {
|
|
147
|
+
found.push(this.resolve(startDir, entry));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (startDir === '/' || (options.stopAt && this.resolve(options.stopAt) === startDir)) {
|
|
152
|
+
return found;
|
|
153
|
+
}
|
|
154
|
+
startDir = this.join(startDir, '..');
|
|
155
|
+
// recursive call to walk up
|
|
156
|
+
return readUp();
|
|
157
|
+
};
|
|
158
|
+
return readUp();
|
|
159
|
+
}
|
|
160
|
+
}
|