diff --git a/lexicons/github/docs/src/content/docs/composites.mdx b/lexicons/github/docs/src/content/docs/composites.mdx index c1823d2cc1..77a19d5324 100644 --- a/lexicons/github/docs/src/content/docs/composites.mdx +++ b/lexicons/github/docs/src/content/docs/composites.mdx @@ -50,7 +50,7 @@ const download = DownloadArtifact({ }); // Combine composites in a job -export const build = new Job({ +export const combinedJob = new Job({ "runs-on": "ubuntu-latest", steps: [ checkout.step, diff --git a/lexicons/github/docs/src/content/docs/getting-started.mdx b/lexicons/github/docs/src/content/docs/getting-started.mdx index 53af751355..5a50a67f1f 100644 --- a/lexicons/github/docs/src/content/docs/getting-started.mdx +++ b/lexicons/github/docs/src/content/docs/getting-started.mdx @@ -26,7 +26,7 @@ export const workflow = new Workflow({ permissions: { contents: "read" }, }); -export const build = new Job({ +export const buildJob = new Job({ "runs-on": "ubuntu-latest", timeoutMinutes: 15, steps: [ diff --git a/lexicons/github/docs/src/content/docs/index.mdx b/lexicons/github/docs/src/content/docs/index.mdx index dbc146f8df..9e0e50ad05 100644 --- a/lexicons/github/docs/src/content/docs/index.mdx +++ b/lexicons/github/docs/src/content/docs/index.mdx @@ -27,7 +27,7 @@ export const workflow = new Workflow({ permissions: { contents: "read" }, }); -export const build = new Job({ +export const buildJob = new Job({ "runs-on": "ubuntu-latest", timeoutMinutes: 15, steps: [ diff --git a/lexicons/github/examples/docs-snippets/src/composites-usage.ts b/lexicons/github/examples/docs-snippets/src/composites-usage.ts index 8b469c338a..3c329a1e4c 100644 --- a/lexicons/github/examples/docs-snippets/src/composites-usage.ts +++ b/lexicons/github/examples/docs-snippets/src/composites-usage.ts @@ -43,7 +43,7 @@ const download = DownloadArtifact({ }); // Combine composites in a job -export const build = new Job({ +export const combinedJob = new Job({ "runs-on": "ubuntu-latest", steps: [ checkout.step, diff --git a/lexicons/github/examples/docs-snippets/src/quickstart.ts b/lexicons/github/examples/docs-snippets/src/quickstart.ts index d193111247..7beaa38613 100644 --- a/lexicons/github/examples/docs-snippets/src/quickstart.ts +++ b/lexicons/github/examples/docs-snippets/src/quickstart.ts @@ -9,7 +9,7 @@ export const workflow = new Workflow({ permissions: { contents: "read" }, }); -export const build = new Job({ +export const buildJob = new Job({ "runs-on": "ubuntu-latest", timeoutMinutes: 15, steps: [ diff --git a/lexicons/github/examples/examples.test.ts b/lexicons/github/examples/examples.test.ts index b3d64502fb..2128be5ef5 100644 --- a/lexicons/github/examples/examples.test.ts +++ b/lexicons/github/examples/examples.test.ts @@ -56,7 +56,7 @@ describeAllExamples( expect(output).toContain("GITHUB_OUTPUT"); }, }, - "docs-snippets": { skipLint: true, skipBuild: true }, + "docs-snippets": { skipLint: true }, "reusable-workflow": { skipLint: true, checks: (output) => { diff --git a/lexicons/github/src/composites/cache.ts b/lexicons/github/src/composites/cache.ts index 6123826b7c..34192a0eb1 100644 --- a/lexicons/github/src/composites/cache.ts +++ b/lexicons/github/src/composites/cache.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Step } from "../generated/index"; +import { Step } from "../generated/index"; export interface CacheActionProps { path: string; @@ -18,9 +18,7 @@ export const CacheAction = Composite((props) => { }; if (props.restoreKeys !== undefined) withObj["restore-keys"] = props.restoreKeys.join("\n"); - const { createProperty } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const step = new StepClass(mergeDefaults({ + const step = new Step(mergeDefaults({ name: "Cache", uses: "actions/cache@v4", with: withObj, diff --git a/lexicons/github/src/composites/checkout.ts b/lexicons/github/src/composites/checkout.ts index fbee6c03ca..22a64b697e 100644 --- a/lexicons/github/src/composites/checkout.ts +++ b/lexicons/github/src/composites/checkout.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Step } from "../generated/index"; +import { Step } from "../generated/index"; export interface CheckoutProps { ref?: string; @@ -23,10 +23,7 @@ export const Checkout = Composite((props) => { if (props.submodules !== undefined) withObj.submodules = String(props.submodules); if (props.sshKey !== undefined) withObj["ssh-key"] = props.sshKey; - // Import Step lazily to avoid circular dependency at module load time - const { createProperty } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const step = new StepClass(mergeDefaults({ + const step = new Step(mergeDefaults({ name: "Checkout", uses: "actions/checkout@v4", ...(Object.keys(withObj).length > 0 ? { with: withObj } : {}), diff --git a/lexicons/github/src/composites/deploy-environment.ts b/lexicons/github/src/composites/deploy-environment.ts index 29ba3b48c5..66d73770b7 100644 --- a/lexicons/github/src/composites/deploy-environment.ts +++ b/lexicons/github/src/composites/deploy-environment.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Job } from "../generated/index"; +import { Job, Step } from "../generated/index"; export interface DeployEnvironmentProps { /** Environment name. Required. */ @@ -38,15 +38,11 @@ export const DeployEnvironment = Composite((props) => { const deployScriptArr = Array.isArray(deployScript) ? deployScript : [deployScript]; const cleanupScriptArr = Array.isArray(cleanupScript) ? cleanupScript : [cleanupScript]; - const { createProperty, createResource } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const JobClass = createResource("GitHub::Actions::Job", "github", {}); - // ── Deploy job ───────────────────────────────────────────────────── const deploySteps = [ - new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }), + new Step({ name: "Checkout", uses: "actions/checkout@v4" }), ...deployScriptArr.map( - (cmd: string) => new StepClass({ name: "Deploy", run: cmd }), + (cmd: string) => new Step({ name: "Deploy", run: cmd }), ), ]; @@ -55,7 +51,7 @@ export const DeployEnvironment = Composite((props) => { environment.url = url; } - const deployJob = new JobClass(mergeDefaults({ + const deployJob = new Job(mergeDefaults({ "runs-on": runsOn, environment, concurrency: { @@ -67,13 +63,13 @@ export const DeployEnvironment = Composite((props) => { // ── Cleanup job ──────────────────────────────────────────────────── const cleanupSteps = [ - new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }), + new Step({ name: "Checkout", uses: "actions/checkout@v4" }), ...cleanupScriptArr.map( - (cmd: string) => new StepClass({ name: "Cleanup", run: cmd }), + (cmd: string) => new Step({ name: "Cleanup", run: cmd }), ), ]; - const cleanupJob = new JobClass(mergeDefaults({ + const cleanupJob = new Job(mergeDefaults({ "runs-on": runsOn, environment: { name }, steps: cleanupSteps, diff --git a/lexicons/github/src/composites/docker-build.ts b/lexicons/github/src/composites/docker-build.ts index b403beee08..e074d104af 100644 --- a/lexicons/github/src/composites/docker-build.ts +++ b/lexicons/github/src/composites/docker-build.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Job, Workflow } from "../generated/index"; +import { Job, Step, Workflow } from "../generated/index"; export interface DockerBuildProps { /** Image tag. Default: "${{ github.sha }}" */ @@ -43,15 +43,10 @@ export const DockerBuild = Composite((props) => { defaults, } = props; - const { createProperty, createResource } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const JobClass = createResource("GitHub::Actions::Job", "github", {}); - const WorkflowClass = createResource("GitHub::Actions::Workflow", "github", {}); - // ── Steps ────────────────────────────────────────────────────────── - const checkout = new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }); + const checkout = new Step({ name: "Checkout", uses: "actions/checkout@v4" }); - const login = new StepClass({ + const login = new Step({ name: "Log in to container registry", uses: "docker/login-action@v3", with: { @@ -61,7 +56,7 @@ export const DockerBuild = Composite((props) => { }, }); - const setupBuildx = new StepClass({ + const setupBuildx = new Step({ name: "Set up Docker Buildx", uses: "docker/setup-buildx-action@v3", }); @@ -72,7 +67,7 @@ export const DockerBuild = Composite((props) => { tags.push(`${imageName}:latest`); } - const metadata = new StepClass({ + const metadata = new Step({ name: "Extract metadata", id: "meta", uses: "docker/metadata-action@v5", @@ -100,18 +95,18 @@ export const DockerBuild = Composite((props) => { .join("\n"); } - const buildPush = new StepClass({ + const buildPush = new Step({ name: "Build and push", uses: "docker/build-push-action@v6", with: buildPushWith, }); - const job = new JobClass(mergeDefaults({ + const job = new Job(mergeDefaults({ "runs-on": runsOn, steps: [checkout, login, setupBuildx, metadata, buildPush], }, defaults?.job)); - const workflow = new WorkflowClass(mergeDefaults({ + const workflow = new Workflow(mergeDefaults({ name: "Docker Build", on: { push: { branches: ["main"] }, diff --git a/lexicons/github/src/composites/download-artifact.ts b/lexicons/github/src/composites/download-artifact.ts index 93eee66939..5c1fea95f1 100644 --- a/lexicons/github/src/composites/download-artifact.ts +++ b/lexicons/github/src/composites/download-artifact.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Step } from "../generated/index"; +import { Step } from "../generated/index"; export interface DownloadArtifactProps { name?: string; @@ -17,9 +17,7 @@ export const DownloadArtifact = Composite((props) => { if (props.path !== undefined) withObj.path = props.path; if (props.mergeMultiple !== undefined) withObj["merge-multiple"] = String(props.mergeMultiple); - const { createProperty } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const step = new StepClass(mergeDefaults({ + const step = new Step(mergeDefaults({ name: "Download Artifact", uses: "actions/download-artifact@v4", ...(Object.keys(withObj).length > 0 ? { with: withObj } : {}), diff --git a/lexicons/github/src/composites/go-ci.ts b/lexicons/github/src/composites/go-ci.ts index c431b0c435..29ef362098 100644 --- a/lexicons/github/src/composites/go-ci.ts +++ b/lexicons/github/src/composites/go-ci.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Job, Workflow } from "../generated/index"; +import { Job, Step, Workflow } from "../generated/index"; export interface GoCIProps { /** Go version. Default: "1.22" */ @@ -30,52 +30,47 @@ export const GoCI = Composite((props) => { defaults, } = props; - const { createProperty, createResource } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const JobClass = createResource("GitHub::Actions::Job", "github", {}); - const WorkflowClass = createResource("GitHub::Actions::Workflow", "github", {}); - // ── Build job ────────────────────────────────────────────────────── - const buildJob = new JobClass(mergeDefaults({ + const buildJob = new Job(mergeDefaults({ "runs-on": runsOn, steps: [ - new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }), - new StepClass({ + new Step({ name: "Checkout", uses: "actions/checkout@v4" }), + new Step({ name: "Setup Go", uses: "actions/setup-go@v5", with: { "go-version": goVersion }, }), - new StepClass({ name: "Build", run: buildCommand }), + new Step({ name: "Build", run: buildCommand }), ], }, defaults?.buildJob)); // ── Test job ─────────────────────────────────────────────────────── - const testJob = new JobClass(mergeDefaults({ + const testJob = new Job(mergeDefaults({ "runs-on": runsOn, steps: [ - new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }), - new StepClass({ + new Step({ name: "Checkout", uses: "actions/checkout@v4" }), + new Step({ name: "Setup Go", uses: "actions/setup-go@v5", with: { "go-version": goVersion }, }), - new StepClass({ name: "Test", run: testCommand }), + new Step({ name: "Test", run: testCommand }), ], }, defaults?.testJob)); // ── Lint job (optional) ──────────────────────────────────────────── const lintJob = lintCommand !== null - ? new JobClass(mergeDefaults({ + ? new Job(mergeDefaults({ "runs-on": runsOn, steps: [ - new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }), - new StepClass({ + new Step({ name: "Checkout", uses: "actions/checkout@v4" }), + new Step({ name: "Setup Go", uses: "actions/setup-go@v5", with: { "go-version": goVersion }, }), - new StepClass({ + new Step({ name: "Lint", uses: "golangci/golangci-lint-action@v6", with: { args: lintCommand }, @@ -84,7 +79,7 @@ export const GoCI = Composite((props) => { }, defaults?.lintJob)) : undefined; - const workflow = new WorkflowClass(mergeDefaults({ + const workflow = new Workflow(mergeDefaults({ name: "Go CI", on: { push: { branches: ["main"] }, diff --git a/lexicons/github/src/composites/node-ci.ts b/lexicons/github/src/composites/node-ci.ts index c96c46f612..7c211258b3 100644 --- a/lexicons/github/src/composites/node-ci.ts +++ b/lexicons/github/src/composites/node-ci.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Job, Workflow } from "../generated/index"; +import { Job, Step, Workflow } from "../generated/index"; export interface NodeCIProps { nodeVersion?: string; @@ -26,17 +26,12 @@ export const NodeCI = Composite((props) => { const install = installCommand ?? (packageManager === "npm" ? "npm ci" : `${packageManager} install`); const run = packageManager === "npm" ? "npm run" : packageManager; - const { createProperty, createResource } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const JobClass = createResource("GitHub::Actions::Job", "github", {}); - const WorkflowClass = createResource("GitHub::Actions::Workflow", "github", {}); - - const checkoutStep = new StepClass({ + const checkoutStep = new Step({ name: "Checkout", uses: "actions/checkout@v4", }); - const setupNodeStep = new StepClass({ + const setupNodeStep = new Step({ name: "Setup Node.js", uses: "actions/setup-node@v4", with: { @@ -45,27 +40,27 @@ export const NodeCI = Composite((props) => { }, }); - const installStep = new StepClass({ + const installStep = new Step({ name: "Install dependencies", run: install, }); - const buildStep = new StepClass({ + const buildStep = new Step({ name: "Build", run: `${run} ${buildScript}`, }); - const testStep = new StepClass({ + const testStep = new Step({ name: "Test", run: `${run} ${testScript}`, }); - const job = new JobClass(mergeDefaults({ + const job = new Job(mergeDefaults({ "runs-on": "ubuntu-latest", steps: [checkoutStep, setupNodeStep, installStep, buildStep, testStep], }, defaults?.job)); - const workflow = new WorkflowClass(mergeDefaults({ + const workflow = new Workflow(mergeDefaults({ name: "CI", on: { push: { branches: ["main"] }, diff --git a/lexicons/github/src/composites/node-pipeline.ts b/lexicons/github/src/composites/node-pipeline.ts index b5a996b9c4..9b49620849 100644 --- a/lexicons/github/src/composites/node-pipeline.ts +++ b/lexicons/github/src/composites/node-pipeline.ts @@ -1,5 +1,5 @@ import { Composite, withDefaults, mergeDefaults } from "@intentius/chant"; -import type { Job, Workflow } from "../generated/index"; +import { Job, Step, Workflow } from "../generated/index"; export interface NodePipelineProps { /** Node.js version. Default: "22" */ @@ -72,29 +72,24 @@ export const NodePipeline = Composite((props) => { const install = installCommand ?? pm.installCmd; const run = pm.runPrefix; - const { createProperty, createResource } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const JobClass = createResource("GitHub::Actions::Job", "github", {}); - const WorkflowClass = createResource("GitHub::Actions::Workflow", "github", {}); - const isBun = packageManager === "bun"; // ── Build job steps ──────────────────────────────────────────────── - const buildCheckout = new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }); + const buildCheckout = new Step({ name: "Checkout", uses: "actions/checkout@v4" }); const buildSetup = isBun - ? new StepClass({ name: "Setup Bun", uses: "oven-sh/setup-bun@v2" }) - : new StepClass({ + ? new Step({ name: "Setup Bun", uses: "oven-sh/setup-bun@v2" }) + : new Step({ name: "Setup Node.js", uses: "actions/setup-node@v4", with: { "node-version": nodeVersion, cache: pm.cache }, }); - const buildInstall = new StepClass({ name: "Install dependencies", run: install }); + const buildInstall = new Step({ name: "Install dependencies", run: install }); - const buildRun = new StepClass({ name: "Build", run: `${run} ${buildScript}` }); + const buildRun = new Step({ name: "Build", run: `${run} ${buildScript}` }); - const buildUpload = new StepClass({ + const buildUpload = new Step({ name: "Upload build artifacts", uses: "actions/upload-artifact@v4", with: { @@ -104,40 +99,40 @@ export const NodePipeline = Composite((props) => { }, }); - const buildJob = new JobClass(mergeDefaults({ + const buildJob = new Job(mergeDefaults({ "runs-on": runsOn, steps: [buildCheckout, buildSetup, buildInstall, buildRun, buildUpload], }, defaults?.buildJob)); // ── Test job steps ───────────────────────────────────────────────── - const testCheckout = new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }); + const testCheckout = new Step({ name: "Checkout", uses: "actions/checkout@v4" }); const testSetup = isBun - ? new StepClass({ name: "Setup Bun", uses: "oven-sh/setup-bun@v2" }) - : new StepClass({ + ? new Step({ name: "Setup Bun", uses: "oven-sh/setup-bun@v2" }) + : new Step({ name: "Setup Node.js", uses: "actions/setup-node@v4", with: { "node-version": nodeVersion, cache: pm.cache }, }); - const testInstall = new StepClass({ name: "Install dependencies", run: install }); + const testInstall = new Step({ name: "Install dependencies", run: install }); - const testDownload = new StepClass({ + const testDownload = new Step({ name: "Download build artifacts", uses: "actions/download-artifact@v4", with: { name: artifactName }, }); - const testRun = new StepClass({ name: "Test", run: `${run} ${testScript}` }); + const testRun = new Step({ name: "Test", run: `${run} ${testScript}` }); - const testJob = new JobClass(mergeDefaults({ + const testJob = new Job(mergeDefaults({ "runs-on": runsOn, needs: ["build"], steps: [testCheckout, testSetup, testInstall, testDownload, testRun], }, defaults?.testJob)); // ── Workflow ─────────────────────────────────────────────────────── - const workflow = new WorkflowClass(mergeDefaults({ + const workflow = new Workflow(mergeDefaults({ name: "Node Pipeline", on: { push: { branches: ["main"] }, diff --git a/lexicons/github/src/composites/python-ci.ts b/lexicons/github/src/composites/python-ci.ts index 6a9500d3af..4af2039118 100644 --- a/lexicons/github/src/composites/python-ci.ts +++ b/lexicons/github/src/composites/python-ci.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Job, Workflow } from "../generated/index"; +import { Job, Step, Workflow } from "../generated/index"; export interface PythonCIProps { /** Python version. Default: "3.12" */ @@ -32,59 +32,54 @@ export const PythonCI = Composite((props) => { defaults, } = props; - const { createProperty, createResource } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const JobClass = createResource("GitHub::Actions::Job", "github", {}); - const WorkflowClass = createResource("GitHub::Actions::Workflow", "github", {}); - const cacheType = usePoetry ? "poetry" : "pip"; const installSteps = usePoetry ? [ - new StepClass({ name: "Install Poetry", run: "pip install poetry" }), - new StepClass({ name: "Install dependencies", run: "poetry install" }), + new Step({ name: "Install Poetry", run: "pip install poetry" }), + new Step({ name: "Install dependencies", run: "poetry install" }), ] : [ - new StepClass({ name: "Install dependencies", run: `pip install -r ${requirementsFile}` }), + new Step({ name: "Install dependencies", run: `pip install -r ${requirementsFile}` }), ]; // ── Test job ─────────────────────────────────────────────────────── - const testJob = new JobClass(mergeDefaults({ + const testJob = new Job(mergeDefaults({ "runs-on": runsOn, steps: [ - new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }), - new StepClass({ + new Step({ name: "Checkout", uses: "actions/checkout@v4" }), + new Step({ name: "Setup Python", uses: "actions/setup-python@v5", with: { "python-version": pythonVersion, cache: cacheType }, }), ...installSteps, - new StepClass({ name: "Test", run: testCommand }), + new Step({ name: "Test", run: testCommand }), ], }, defaults?.testJob)); // ── Lint job (optional) ──────────────────────────────────────────── const lintJob = lintCommand !== null - ? new JobClass(mergeDefaults({ + ? new Job(mergeDefaults({ "runs-on": runsOn, steps: [ - new StepClass({ name: "Checkout", uses: "actions/checkout@v4" }), - new StepClass({ + new Step({ name: "Checkout", uses: "actions/checkout@v4" }), + new Step({ name: "Setup Python", uses: "actions/setup-python@v5", with: { "python-version": pythonVersion, cache: cacheType }, }), ...installSteps.map((s: any) => { // Create fresh step instances for the lint job - return new StepClass({ name: s.props.name, run: s.props.run }); + return new Step({ name: s.props.name, run: s.props.run }); }), - new StepClass({ name: "Lint", run: lintCommand }), + new Step({ name: "Lint", run: lintCommand }), ], }, defaults?.lintJob)) : undefined; // ── Workflow ─────────────────────────────────────────────────────── - const workflow = new WorkflowClass(mergeDefaults({ + const workflow = new Workflow(mergeDefaults({ name: "Python CI", on: { push: { branches: ["main"] }, diff --git a/lexicons/github/src/composites/setup-go.ts b/lexicons/github/src/composites/setup-go.ts index 1ec8b4db51..a2d0399d22 100644 --- a/lexicons/github/src/composites/setup-go.ts +++ b/lexicons/github/src/composites/setup-go.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Step } from "../generated/index"; +import { Step } from "../generated/index"; export interface SetupGoProps { goVersion?: string; @@ -17,9 +17,7 @@ export const SetupGo = Composite((props) => { if (props.goVersionFile !== undefined) withObj["go-version-file"] = props.goVersionFile; if (props.cache !== undefined) withObj.cache = String(props.cache); - const { createProperty } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const step = new StepClass(mergeDefaults({ + const step = new Step(mergeDefaults({ name: "Setup Go", uses: "actions/setup-go@v5", ...(Object.keys(withObj).length > 0 ? { with: withObj } : {}), diff --git a/lexicons/github/src/composites/setup-node.ts b/lexicons/github/src/composites/setup-node.ts index 2841c1687b..1bdd8aef61 100644 --- a/lexicons/github/src/composites/setup-node.ts +++ b/lexicons/github/src/composites/setup-node.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Step } from "../generated/index"; +import { Step } from "../generated/index"; export interface SetupNodeProps { nodeVersion?: string; @@ -19,9 +19,7 @@ export const SetupNode = Composite((props) => { if (props.cache !== undefined) withObj.cache = props.cache; if (props.cacheFilePath !== undefined) withObj["cache-dependency-path"] = props.cacheFilePath; - const { createProperty } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const step = new StepClass(mergeDefaults({ + const step = new Step(mergeDefaults({ name: "Setup Node.js", uses: "actions/setup-node@v4", ...(Object.keys(withObj).length > 0 ? { with: withObj } : {}), diff --git a/lexicons/github/src/composites/setup-python.ts b/lexicons/github/src/composites/setup-python.ts index 45ed67da0b..27afdcd5a3 100644 --- a/lexicons/github/src/composites/setup-python.ts +++ b/lexicons/github/src/composites/setup-python.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Step } from "../generated/index"; +import { Step } from "../generated/index"; export interface SetupPythonProps { pythonVersion?: string; @@ -17,9 +17,7 @@ export const SetupPython = Composite((props) => { if (props.cache !== undefined) withObj.cache = props.cache; if (props.architecture !== undefined) withObj.architecture = props.architecture; - const { createProperty } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const step = new StepClass(mergeDefaults({ + const step = new Step(mergeDefaults({ name: "Setup Python", uses: "actions/setup-python@v5", ...(Object.keys(withObj).length > 0 ? { with: withObj } : {}), diff --git a/lexicons/github/src/composites/upload-artifact.ts b/lexicons/github/src/composites/upload-artifact.ts index 49ec12298a..27883ffee7 100644 --- a/lexicons/github/src/composites/upload-artifact.ts +++ b/lexicons/github/src/composites/upload-artifact.ts @@ -1,5 +1,5 @@ import { Composite, mergeDefaults } from "@intentius/chant"; -import type { Step } from "../generated/index"; +import { Step } from "../generated/index"; export interface UploadArtifactProps { name: string; @@ -20,9 +20,7 @@ export const UploadArtifact = Composite((props) => { if (props.retentionDays !== undefined) withObj["retention-days"] = String(props.retentionDays); if (props.compressionLevel !== undefined) withObj["compression-level"] = String(props.compressionLevel); - const { createProperty } = require("@intentius/chant/runtime"); - const StepClass = createProperty("GitHub::Actions::Step", "github"); - const step = new StepClass(mergeDefaults({ + const step = new Step(mergeDefaults({ name: "Upload Artifact", uses: "actions/upload-artifact@v4", with: withObj, diff --git a/packages/core/src/runtime.ts b/packages/core/src/runtime.ts index 058f634fa2..5def22c295 100644 --- a/packages/core/src/runtime.ts +++ b/packages/core/src/runtime.ts @@ -54,18 +54,27 @@ export function createResource( /** * Create a property-kind class for a given property type. + * + * Instances carry DECLARABLE_MARKER/lexicon/entityType/kind at runtime (set + * via defineProperty below), so they already satisfy `Declarable` — the + * return type just needs to say so. Before this, the signature was + * `Record` with no `Declarable`, so any composite that + * returned a property-kind instance as a top-level member only type-checked + * by accident: either the caller went through an untyped `require()` (losing + * the type entirely) or never assigned the instance where its `Declarable`-ness + * was checked statically. See chant #1068. */ export function createProperty( type: string, lexicon: string, -): new (props: Record) => Record { +): new (props: Record) => Declarable & Record { const PropertyClass = function (this: Record, props: Record) { Object.defineProperty(this, DECLARABLE_MARKER, { value: true, enumerable: false }); Object.defineProperty(this, "lexicon", { value: lexicon, enumerable: false }); Object.defineProperty(this, "entityType", { value: type, enumerable: false }); Object.defineProperty(this, "kind", { value: "property", enumerable: false }); Object.defineProperty(this, "props", { value: props ?? {}, enumerable: false, configurable: true }); - } as unknown as new (props: Record) => Record; + } as unknown as new (props: Record) => Declarable & Record; Object.defineProperty(PropertyClass, "name", { value: type.split(".").pop() ?? type }); diff --git a/scripts/check-lexicons.ts b/scripts/check-lexicons.ts index 1f35f9feb4..7e13ae4fcb 100644 --- a/scripts/check-lexicons.ts +++ b/scripts/check-lexicons.ts @@ -76,8 +76,6 @@ const KNOWN_FAILURES: Record> = { "#1072 — forgejo has no docs/ site of its own.", }, github: { - "Every shipped example builds": - "#1068 — every github example fails with \"require is not defined in ES module scope\" — several composites (checkout.ts, cache.ts, node-ci.ts, and others) lazily `require(\"@intentius/chant/runtime\")` to avoid a circular import, which is fundamentally incompatible with running as ESM.", "Registered intrinsics are exported by the package": "#1069 — plugin.ts registers an \"expression\" intrinsic; src/index.ts exports the `Expression` class (capitalized) and helper functions, but nothing literally named `expression`.", "Registered intrinsics' isTag matches how they're authored":