Skip to content

Commit

Permalink
Add extra info to lage info for microsoft#815
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvv committed Feb 6, 2025
1 parent b0ee668 commit fe1e053
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 2 deletions.
24 changes: 23 additions & 1 deletion packages/cli/src/commands/info/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ interface PackageTask {
workingDirectory: string;
package: string;
task: string;
inputs?: string[];
outputs?: string[];
options?: Record<string, any>;
weight?: number;
}

/**
Expand All @@ -61,7 +65,15 @@ interface PackageTask {
* "workingDirectory": "packages/foo",
* "dependencies": [
* "bar##build"
* ]
* ],
* "weight": 3,
* "inputs": ["src//**/ /*.ts"],
* "inputs": ["lib//**/ /*.js", "lib//**/ /*.d.ts]"
* "options": {
* "environment": {
* "custom_env_var": "x",
* }
* }
* },
* {
* "id": "foo##test",
Expand Down Expand Up @@ -154,8 +166,18 @@ function generatePackageTask(
workingDirectory,
package: target.packageName ?? "",
task: target.task,
inputs: target.inputs,
outputs: target.outputs,
};

if (target.weight && target.weight !== 1) {
packageTask.weight = target.weight;
}

if (target.options && Object.keys(target.options).length != 0) {
packageTask.options = target.options;
}

return packageTask;
}

Expand Down
220 changes: 220 additions & 0 deletions packages/e2e-tests/src/__snapshots__/info.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,226 @@ exports[`info command basic info test case 1`] = `
]
`;

exports[`info command custom inputs, outputs and weight value 1`] = `
[
{
"data": {
"command": [
"test",
"build",
],
"packageTasks": [
{
"command": [],
"dependencies": [],
"id": "__start",
"package": "",
"task": "__start",
"workingDirectory": "",
},
{
"command": [
"node",
"./test.js",
],
"dependencies": [
"a#build",
],
"id": "a#test",
"inputs": [
"src/**/*.test.ts",
"*",
"^lib/**",
],
"package": "a",
"task": "test",
"weight": 5,
"workingDirectory": "packages/a",
},
{
"command": [
"node",
"./test.js",
],
"dependencies": [
"b#build",
],
"id": "b#test",
"inputs": [
"src/**/*.test.ts",
"*",
"^lib/**",
],
"package": "b",
"task": "test",
"weight": 5,
"workingDirectory": "packages/b",
},
{
"command": [
"node",
"./build.js",
],
"dependencies": [
"b#build",
],
"id": "a#build",
"inputs": [
"src/**",
"*",
],
"outputs": [
"lib/**",
],
"package": "a",
"task": "build",
"workingDirectory": "packages/a",
},
{
"command": [
"node",
"./build.js",
],
"dependencies": [
"__start",
],
"id": "b#build",
"inputs": [
"src/**",
"*",
],
"outputs": [
"lib/**",
],
"package": "b",
"task": "build",
"workingDirectory": "packages/b",
},
],
"scope": [
"a",
"b",
],
},
"level": 30,
"msg": "info",
},
]
`;

exports[`info command custom options 1`] = `
[
{
"data": {
"command": [
"test",
"build",
],
"packageTasks": [
{
"command": [],
"dependencies": [],
"id": "__start",
"package": "",
"task": "__start",
"workingDirectory": "",
},
{
"command": [
"node",
"./test.js",
],
"dependencies": [
"a#build",
],
"id": "a#test",
"options": {
"environment": {
"custom_env_var_array": [
1,
true,
"string",
{
"x": 1,
},
[],
],
"custom_env_var_bool": true,
"custom_env_var_number": 1,
"custom_env_var_string": "string",
},
},
"package": "a",
"task": "test",
"workingDirectory": "packages/a",
},
{
"command": [
"node",
"./test.js",
],
"dependencies": [
"b#build",
],
"id": "b#test",
"options": {
"environment": {
"custom_env_var_array": [
1,
true,
"string",
{
"x": 1,
},
[],
],
"custom_env_var_bool": true,
"custom_env_var_number": 1,
"custom_env_var_string": "string",
},
},
"package": "b",
"task": "test",
"workingDirectory": "packages/b",
},
{
"command": [
"node",
"./build.js",
],
"dependencies": [
"b#build",
],
"id": "a#build",
"package": "a",
"task": "build",
"workingDirectory": "packages/a",
},
{
"command": [
"node",
"./build.js",
],
"dependencies": [
"__start",
],
"id": "b#build",
"package": "b",
"task": "build",
"workingDirectory": "packages/b",
},
],
"scope": [
"a",
"b",
],
},
"level": 30,
"msg": "info",
},
]
`;

exports[`info command scoped info test case 1`] = `
[
{
Expand Down
71 changes: 71 additions & 0 deletions packages/e2e-tests/src/info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,75 @@ describe("info command", () => {

await repo.cleanup();
});

it("custom inputs, outputs and weight value", async () => {
const repo = new Monorepo("scoped-info");

repo.init();
repo.setLageConfig(
`module.exports = {
pipeline: {
build: {
inputs: ["src/**", "*"],
outputs: ["lib/**"],
dependsOn: ["^build"],
},
outputs: ["log/**"],
test: {
inputs: ["src/**/*.test.ts", "*", "^lib/**"],
dependsOn: ["build"],
weight: 5
}
},
cache: true,
};`
);

repo.addPackage("a", ["b"]);
repo.addPackage("b");
repo.install();
const results = repo.run("writeInfo", ["test", "build"]);
const output = results.stdout + results.stderr;
const jsonOutput = parseNdJson(output);
expect(jsonOutput).toMatchSnapshot();

await repo.cleanup();
});

it("custom options", async () => {
const repo = new Monorepo("scoped-info");

repo.init();
repo.setLageConfig(
`module.exports = {
pipeline: {
build: ["^build"],
test: {
dependsOn: ["build"],
options: {
environment: {
custom_env_var_number: 1,
custom_env_var_string: "string",
custom_env_var_bool: true,
custom_env_var_array: [1, true, "string", {x:1}, []],
}
}
}
},
cache: true,
};`
);

repo.addPackage("a", ["b"]);
repo.addPackage("b");

repo.install();

const results = repo.run("writeInfo", ["test", "build"]);
const output = results.stdout + results.stderr;
const jsonOutput = parseNdJson(output);
expect(jsonOutput).toMatchSnapshot();

await repo.cleanup();
});
});
3 changes: 2 additions & 1 deletion packages/e2e-tests/src/mock/monorepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export class Monorepo {
}

fs.cpSync(path.resolve(__dirname, "..", "..", "yarn"), path.dirname(this.yarnPath), { recursive: true });
execa.sync(`"${process.execPath}"`, [`"${this.yarnPath}"`, "install"], { cwd: this.root, shell: true });
// we use --force to install packages to avoid yarn cache not picking up the latest built files from the share.
execa.sync(`"${process.execPath}"`, [`"${this.yarnPath}"`, "install", "--force"], { cwd: this.root, shell: true });
}

generateRepoFiles() {
Expand Down

0 comments on commit fe1e053

Please sign in to comment.