Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/cli/src/commands/info/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { runnerPickerOptions } from "../../runnerPickerOptions.js";
import { parseServerOption } from "../parseServerOption.js";
import { optimizeTargetGraph } from "../../optimizeTargetGraph.js";

interface InfoActionOptions extends ReporterInitOptions {
export interface InfoActionOptions extends ReporterInitOptions {
dependencies: boolean;
dependents: boolean;
since: string;
Expand All @@ -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,10 @@ interface PackageTask {
* "workingDirectory": "packages/foo",
* "dependencies": [
* "bar##build"
* ]
* ],
* "weight": 3,
* "inputs": ["src//**/ /*.ts"],
* "inputs": ["lib//**/ /*.js", "lib//**/ /*.d.ts]"
* },
* {
* "id": "foo##test",
Expand Down Expand Up @@ -103,6 +110,7 @@ export async function infoAction(options: InfoActionOptions, command: Command) {
outputs: config.cacheOptions.outputGlob,
tasks,
packageInfos,
enableTargetConfigMerging: config.enableTargetConfigMerging,
});

const scope = getFilteredPackages({
Expand Down Expand Up @@ -134,7 +142,7 @@ export async function infoAction(options: InfoActionOptions, command: Command) {
});
}

function generatePackageTask(
export function generatePackageTask(
target: Target,
taskArgs: string[],
config: ConfigOptions,
Expand All @@ -153,6 +161,10 @@ function generatePackageTask(
workingDirectory,
package: target.packageName ?? "",
task: target.task,
inputs: target.inputs,
outputs: target.outputs,
options: target.options,
weight: target.weight,
};

return packageTask;
Expand Down
41 changes: 38 additions & 3 deletions packages/cli/src/commands/run/createTargetGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface CreateTargetGraphOptions {
outputs: string[];
tasks: string[];
packageInfos: PackageInfos;
enableTargetConfigMerging: boolean;
}

function getChangedFiles(since: string, cwd: string) {
Expand All @@ -37,9 +38,23 @@ function getChangedFiles(since: string, cwd: string) {
}

export async function createTargetGraph(options: CreateTargetGraphOptions) {
const { logger, root, dependencies, dependents, since, scope, repoWideChanges, ignore, pipeline, outputs, tasks, packageInfos } = options;
const {
logger,
root,
dependencies,
dependents,
enableTargetConfigMerging,
since,
scope,
repoWideChanges,
ignore,
pipeline,
outputs,
tasks,
packageInfos,
} = options;

const builder = new WorkspaceTargetGraphBuilder(root, packageInfos);
const builder = new WorkspaceTargetGraphBuilder(root, packageInfos, enableTargetConfigMerging);

const packages = getFilteredPackages({
root,
Expand All @@ -63,7 +78,27 @@ export async function createTargetGraph(options: CreateTargetGraphOptions) {
}
}

for (const [id, definition] of Object.entries(pipeline)) {
const pipelineEntries = Object.entries(pipeline);

// Add lage pipeline configuration in the package.json files.
// They are configured in the lage field, but without the package id.
// i.e. having this package.json
// { "name": "@lage-run/globby", "lage": { "transpile": { type: "npmScript" } }}
// is equivalent to having the following in lage.config.js
// { pipeline: { "@lage-run/globby#transpile": { type: "npmScript" } }
// We conciously add these 'after' the ones in lage.config.js
// to indicate that the more specific package.json definition takes
// precedence over the global lage.config.js.
for (const [packageId, packageInfo] of Object.entries(packageInfos)) {
const packageLageDefinition = packageInfo.lage as PipelineDefinition;
if (packageLageDefinition) {
for (const [id, definition] of Object.entries(packageLageDefinition)) {
pipelineEntries.push([packageId + "#" + id, definition]);
}
}
}

for (const [id, definition] of pipelineEntries) {
if (Array.isArray(definition)) {
builder.addTargetConfig(
id,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/run/runAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export async function runAction(options: RunOptions, command: Command) {
outputs: config.cacheOptions.outputGlob,
tasks,
packageInfos,
enableTargetConfigMerging: config.enableTargetConfigMerging,
});

validateTargetGraph(targetGraph, allowNoTargetRuns);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/run/watchAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export async function watchAction(options: RunOptions, command: Command) {
outputs: config.cacheOptions.outputGlob,
tasks,
packageInfos,
enableTargetConfigMerging: config.enableTargetConfigMerging,
});

// Make sure we do not attempt writeRemoteCache in watch mode
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/server/lageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async function createInitializedPromise({ cwd, logger, serverControls, nodeArg,
outputs: config.cacheOptions.outputGlob,
tasks,
packageInfos,
enableTargetConfigMerging: config.enableTargetConfigMerging,
});

const dependencyMap = createDependencyMap(packageInfos, { withDevDependencies: true, withPeerDependencies: false });
Expand Down
133 changes: 133 additions & 0 deletions packages/cli/tests/__snapshots__/createTargetGraph.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createTargetGraph Basic graph, seperate nodes 1`] = `
"[
{
"id": "__start",
"dependencies": []
},
{
"id": "foo1#build",
"dependencies": [
"__start",
"foo2#build"
]
},
{
"id": "foo2#build",
"dependencies": [
"__start"
]
}
]"
`;

exports[`createTargetGraph Basic graph, spanning tasks 1`] = `
"[
{
"id": "__start",
"dependencies": []
},
{
"id": "foo1#build",
"dependencies": [
"__start",
"foo2#build"
]
},
{
"id": "foo2#build",
"dependencies": [
"__start"
]
},
{
"id": "foo1#test",
"dependencies": [
"__start",
"foo1#build"
]
},
{
"id": "foo2#test",
"dependencies": [
"__start",
"foo2#build"
]
}
]"
`;

exports[`createTargetGraph Merging Dependencies in pipeline and package.json override 1`] = `
"[
{
"id": "__start",
"dependencies": []
},
{
"id": "foo1#build",
"dependencies": [
"__start",
"foo2#build",
"foo3#build",
"foo4#build"
]
},
{
"id": "foo2#build",
"dependencies": [
"__start"
]
},
{
"id": "foo3#build",
"dependencies": [
"__start"
]
},
{
"id": "foo4#build",
"dependencies": [
"__start"
]
}
]"
`;

exports[`createTargetGraph Merging inputs and outputs in pipeline and package.json override 1`] = `
"[
{
"id": "__start",
"dependencies": []
},
{
"id": "foo1#build",
"dependencies": [
"__start",
"foo2#build"
],
"inputs": [
"src/**",
"src/**",
"myTool.config",
"tsconfig.json"
],
"outputs": [
"lib/**",
"dist/**"
]
},
{
"id": "foo2#build",
"dependencies": [
"__start"
],
"inputs": [
"src/**"
],
"outputs": [
"lib/**"
]
}
]"
`;
Loading
Loading