diff --git a/packages/cli/src/commands/info/action.ts b/packages/cli/src/commands/info/action.ts index be843e0f6..c042ed4c2 100644 --- a/packages/cli/src/commands/info/action.ts +++ b/packages/cli/src/commands/info/action.ts @@ -37,6 +37,10 @@ interface PackageTask { workingDirectory: string; package: string; task: string; + inputs?: string[]; + outputs?: string[]; + options?: Record; + weight?: number; } /** @@ -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", @@ -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; } diff --git a/packages/e2e-tests/src/__snapshots__/info.test.ts.snap b/packages/e2e-tests/src/__snapshots__/info.test.ts.snap index acf949b63..9f0d7f62d 100644 --- a/packages/e2e-tests/src/__snapshots__/info.test.ts.snap +++ b/packages/e2e-tests/src/__snapshots__/info.test.ts.snap @@ -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`] = ` [ { diff --git a/packages/e2e-tests/src/info.test.ts b/packages/e2e-tests/src/info.test.ts index 7638652a3..94da67352 100644 --- a/packages/e2e-tests/src/info.test.ts +++ b/packages/e2e-tests/src/info.test.ts @@ -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(); + }); }); diff --git a/packages/e2e-tests/src/mock/monorepo.ts b/packages/e2e-tests/src/mock/monorepo.ts index 96a49ac38..e4dd33539 100644 --- a/packages/e2e-tests/src/mock/monorepo.ts +++ b/packages/e2e-tests/src/mock/monorepo.ts @@ -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() {