Skip to content

Commit

Permalink
Remove cruft from configure script
Browse files Browse the repository at this point in the history
Continue the effort to remove things from the configure script that
should be handled by default in the plugins.  In this case it is,

  1. `phony` supports extracting `orderOnlyDeps` from the input so we
     can depend on formatted files
  2. all plugins now support passing `orderOnlyDeps` when creating
     rules, which we use to replace our `inject` function
  3. the `biome` plugin takes a `configPath` so we no longer need to
     wrap the function and inject it ourselves

Upgrade to the latest biome as part of this, which also requires fixing
a few small linting errors.
  • Loading branch information
elliotgoodrich committed Jul 7, 2024
1 parent d0af42d commit 1fdd7ed
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 203 deletions.
2 changes: 1 addition & 1 deletion configure/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"lineEnding": "crlf",
"lineEnding": "lf",
"ignore": []
},
"linter": {
Expand Down
76 changes: 18 additions & 58 deletions configure/configure.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { basename, dirname, extname, join, relative } from "node:path/posix";
import {
resolve as resolveNative,
relative as relativeNative,
sep,
} from "node:path";
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
Expand All @@ -26,19 +25,6 @@ if (isCi) {
console.log("Running in CI mode");
}

// Copy from `@ninjutsu-build/core` for the moment until we widen the
// contract of `phony`
function getOrderOnlyDeps(input) {
if (typeof input !== "object") {
return input;
}

if (Array.isArray(input)) {
return input.map(getOrderOnlyDeps);
}
return input[orderOnlyDeps] ?? input.file;
}

const extLookup = {
".ts": ".js",
".mts": ".mjs",
Expand Down Expand Up @@ -136,28 +122,7 @@ function formatAndLint(file) {
return lint({ in: formatted });
}

// Return a function that will append `args[orderOnlyDeps]` with the build arguments
// before passing to `rule`.
function inject(rule, args) {
return (a) => {
const { [orderOnlyDeps]: _orderOnlyDeps = [], ...rest } = a;
const deps =
typeof _orderOnlyDeps === "string" ? [_orderOnlyDeps] : _orderOnlyDeps;
return rule({
...rest,
[orderOnlyDeps]: deps.concat(args[orderOnlyDeps]),
});
};
}

function addBiomeConfig(rule) {
return (a) => {
return rule({
...a,
configPath: join("configure", "biome.json"),
});
};
}
const biomeConfig = join("configure", "biome.json");

async function loadSourcesFromTSConfig(tsConfig) {
tsConfig = getInput(tsConfig);
Expand Down Expand Up @@ -209,37 +174,34 @@ let checkFormatted;
const toolsInstalled = ci({
in: "configure/package.json",
[validations]: (out) => {
checkFormatted = addBiomeConfig(
inject(makeCheckFormattedRule(ninja), {
[orderOnlyDeps]: out,
}),
);
checkFormatted = makeCheckFormattedRule(ninja, {
configPath: biomeConfig,
[orderOnlyDeps]: out,
});
// Add a validation that `package.json` is formatted correctly.
// If we formatted after running `npmci` it would cause us to run it again
return checkFormatted({ in: "configure/package.json" })[validations];
},
});

const tsc = inject(makeTSCRule(ninja), { [orderOnlyDeps]: toolsInstalled });
const typecheck = inject(makeTypeCheckRule(ninja), {
const tsc = makeTSCRule(ninja, { [orderOnlyDeps]: toolsInstalled });
const typecheck = makeTypeCheckRule(ninja, {
[orderOnlyDeps]: toolsInstalled,
});
const test = makeNodeTestRule(ninja);
const tar = makeTarRule(ninja);
const format = isCi
? checkFormatted
: addBiomeConfig(
inject(makeFormatRule(ninja), {
[orderOnlyDeps]: toolsInstalled,
}),
);
: makeFormatRule(ninja, {
configPath: biomeConfig,
[orderOnlyDeps]: toolsInstalled,
});
const copy = makeCopyRule(ninja);
const lint = addBiomeConfig(
inject(makeLintRule(ninja), {
[orderOnlyDeps]: toolsInstalled,
}),
);
const transpile = inject(makeSWCRule(ninja), {
const lint = makeLintRule(ninja, {
configPath: biomeConfig,
[orderOnlyDeps]: toolsInstalled,
});
const transpile = makeSWCRule(ninja, {
[orderOnlyDeps]: toolsInstalled,
});

Expand Down Expand Up @@ -298,9 +260,7 @@ for (const cwd of workspaceJSON.workspaces) {
// and it is ready to be executed.
const packageRunnable = phony({
out: `${localPKGJSON.name}/runnable`,
in: [packageJSON, ...javascript, ...dependenciesRunnable].map(
getOrderOnlyDeps,
),
in: [packageJSON, ...javascript, ...dependenciesRunnable],
});

// Create the TypeScript type declaration files and do typechecking
Expand All @@ -319,7 +279,7 @@ for (const cwd of workspaceJSON.workspaces) {
// check their own code.
const packageHasTypes = phony({
out: `${localPKGJSON.name}/typed`,
in: [packageJSON, ...typeDeclarations].map(getOrderOnlyDeps),
in: [packageJSON, ...typeDeclarations],
});

docsDependencies.push(packageHasTypes);
Expand Down
Loading

0 comments on commit 1fdd7ed

Please sign in to comment.