Combine FilePath append and appendList methods
MODIFY
packages/cli-flags/Parser.ts
packages/cli-flags/Parser.ts
@@ -408,7 +408,7 @@ export default class Parser<T> {
}
case "fish": {
- path = HOME_PATH.appendList(
+ path = HOME_PATH.append(
".config",
"fish",
"completions",

MODIFY
packages/core/common/constants.ts
packages/core/common/constants.ts
@@ -20,7 +20,7 @@ export const MAP = BIN.addExtension(".map");
const MEGABYTE = 10_000;
// Where we store user configuration, recoverable files etc
-export const USER_CONFIG_DIRECTORY = HOME_PATH.appendList(".rome");
+export const USER_CONFIG_DIRECTORY = HOME_PATH.append(".rome");
export const USER_CONFIG_FILENAMES: Array<string> = [
"config.json",
"config.rjson",

MODIFY
packages/core/server/fs/Resolver.ts
packages/core/server/fs/Resolver.ts
@@ -740,7 +740,7 @@ export default class Resolver {
return this.resolvePath(
{
...query,
- source: manifestDef.directory.appendList(...moduleNameParts),
+ source: manifestDef.directory.append(...moduleNameParts),
},
true,
["package"],
@@ -821,7 +821,7 @@ export default class Resolver {
return this.resolvePath(
{
...query,
- source: virtualResolved.appendList(...moduleNameParts),
+ source: virtualResolved.append(...moduleNameParts),
},
true,
["virtual"],

MODIFY
packages/core/server/fs/resolverSuggest.ts
packages/core/server/fs/resolverSuggest.ts
@@ -252,7 +252,7 @@ function getPathSuggestions(
// Try parent directories of the origin
for (const path of originDirectory.getChain()) {
- tryPathSuggestions(resolver, suggestions, path.appendList(...sourceParts));
+ tryPathSuggestions(resolver, suggestions, path.append(...sourceParts));
}
return suggestions;
@@ -311,7 +311,7 @@ function tryPathSuggestions(
tryPathSuggestions(
resolver,
suggestions,
- createUnknownFilePath(rating.target).appendList(...segments.slice(1)).assertAbsolute(),
+ createUnknownFilePath(rating.target).append(...segments.slice(1)).assertAbsolute(),
);
}
}

MODIFY
packages/path/index.ts
packages/path/index.ts
@@ -458,7 +458,24 @@ class BaseFilePath<Super extends UnknownFilePath> {
}
}
- append(item: FilePathOrString): Super {
+ append(...items: Array<FilePathOrString>): Super {
+ if (items.length === 0) {
+ return this._assert();
+ }
+
+ if (items.length === 1) {
+ return this._append(items[0]);
+ }
+
+ let target: Super = this._assert();
+ for (const item of items) {
+ // @ts-ignore
+ target = target._append(item);
+ }
+ return target;
+ }
+
+ _append(item: FilePathOrString): Super {
if (typeof item === "string") {
const cached = this.memoizedChildren.get(item);
if (cached !== undefined) {
@@ -478,19 +495,6 @@ class BaseFilePath<Super extends UnknownFilePath> {
return child;
}
-
- appendList(...items: Array<FilePathOrString>): Super {
- if (items.length === 0) {
- return this._assert();
- }
-
- let target: Super = this._assert();
- for (const item of items) {
- // @ts-ignore
- target = target.append(item);
- }
- return target;
- }
}
export class RelativeFilePath extends BaseFilePath<RelativeFilePath> {

MODIFY
scripts/ast-create-node.ts
scripts/ast-create-node.ts
@@ -27,7 +27,7 @@ export async function main(
const builderName = toCamelCase(nodeType);
// Write AST def
- const astDefPath = PACKAGES.appendList("ast", `${joined}.ts`);
+ const astDefPath = PACKAGES.append("ast", `${joined}.ts`);
if (await exists(astDefPath)) {
reporter.error(markup`AST node ${joined} already exists`);
return 1;
@@ -51,7 +51,7 @@ export async function main(
// Write builder
await writeFile(
- PACKAGES.appendList("formatter", "builders", `${joined}.ts`),
+ PACKAGES.append("formatter", "builders", `${joined}.ts`),
dedent`
import {${nodeType}} from "@romefrontend/ast";
import {Builder, Token} from "@romefrontend/formatter";
@@ -65,12 +65,7 @@ export async function main(
// Write analysis
if (language === "js") {
await writeFile(
- PACKAGES.appendList(
- "js-analysis",
- "evaluators",
- category,
- `${nodeType}.ts`,
- ),
+ PACKAGES.append("js-analysis", "evaluators", category, `${nodeType}.ts`),
dedent`
import {AnyNode, ${nodeType}, ${builderName}} from "@romefrontend/ast";

MODIFY
scripts/ast-delete-node.ts
scripts/ast-delete-node.ts
@@ -21,17 +21,11 @@ export async function main([filename]: Array<string>) {
const [, category, nodeName] = segments;
// Remove files
+ await removeFile(PACKAGES.append("formatter", "builders", `${filename}.ts`));
await removeFile(
- PACKAGES.appendList("formatter", "builders", `${filename}.ts`),
+ PACKAGES.append("js-analysis", "evaluators", `${category}/${nodeName}.ts`),
);
- await removeFile(
- PACKAGES.appendList(
- "js-analysis",
- "evaluators",
- `${category}/${nodeName}.ts`,
- ),
- );
- await removeFile(PACKAGES.appendList("ast", `${filename}.ts`));
+ await removeFile(PACKAGES.append("ast", `${filename}.ts`));
// Regenerate indexes
await generateAST();

MODIFY
scripts/build-release.ts
scripts/build-release.ts
import {ROOT, execDev} from "./_utils";
export async function main(args: Array<string>) {
- await execDev(["bundle", ROOT.appendList("packages", "rome").join(), ...args]);
+ await execDev(["bundle", ROOT.append("packages", "rome").join(), ...args]);
}

MODIFY
scripts/generated-files/ast.ts
scripts/generated-files/ast.ts
@@ -100,7 +100,7 @@ export async function main() {
// Add to builders
await readIndexFile(
- PACKAGES.appendList("formatter", "builders", "index.ts"),
+ PACKAGES.append("formatter", "builders", "index.ts"),
[
{
iterator({language, category, nodeType}) {
@@ -112,7 +112,7 @@ export async function main() {
// Add to analysis
await readIndexFile(
- PACKAGES.appendList("js-analysis", "evaluators", "index.ts"),
+ PACKAGES.append("js-analysis", "evaluators", "index.ts"),
[
{
iterator({language, category, nodeType}) {

MODIFY
scripts/generated-files/lint-rules.ts
scripts/generated-files/lint-rules.ts
@@ -2,9 +2,9 @@ import {PACKAGES, ROOT, modifyGeneratedFile} from "../_utils";
import {lstat, readDirectory, readFileText} from "@romefrontend/fs";
import {AbsoluteFilePath} from "@romefrontend/path";
-const lintRulesFolder = PACKAGES.appendList("compiler", "lint", "rules");
+const lintRulesFolder = PACKAGES.append("compiler", "lint", "rules");
-const lintRulesDocFolder = ROOT.appendList(
+const lintRulesDocFolder = ROOT.append(
"website",
"src",
"docs",
@@ -72,7 +72,7 @@ export async function main() {
// Generate diagnostic categories
await modifyGeneratedFile(
- PACKAGES.appendList("diagnostics", "categories.ts"),
+ PACKAGES.append("diagnostics", "categories.ts"),
async () => {
const lines = ["type LintDiagnosticCategory ="];
for (const {ruleName} of defs) {

MODIFY
scripts/generated-files/virtual-modules.ts
scripts/generated-files/virtual-modules.ts
import {PACKAGES, ROOT, modifyGeneratedFile} from "../_utils";
import {lstat, readDirectory, readFileText} from "@romefrontend/fs";
-const runtimeModules = ROOT.appendList("packages", "@romefrontend-runtime");
-const runtimeIndex = PACKAGES.appendList("core", "common", "virtual-modules.ts");
+const runtimeModules = ROOT.append("packages", "@romefrontend-runtime");
+const runtimeIndex = PACKAGES.append("core", "common", "virtual-modules.ts");
export async function main() {
await modifyGeneratedFile(

MODIFY
scripts/lint-create-rule.ts
scripts/lint-create-rule.ts
@@ -4,7 +4,7 @@ import {readFileText} from "@romefrontend/fs";
import {main as generateLintRules} from "./generated-files/lint-rules";
import {markup} from "@romefrontend/cli-layout";
-const rulesPath = PACKAGES.appendList("compiler", "lint", "rules");
+const rulesPath = PACKAGES.append("compiler", "lint", "rules");
export async function main([ruleName]: Array<string>): Promise<number> {
if (ruleName === undefined) {
@@ -22,7 +22,7 @@ export async function main([ruleName]: Array<string>): Promise<number> {
// Write rule
await writeFile(
- rulesPath.appendList(`${ruleName}.ts`),
+ rulesPath.append(`${ruleName}.ts`),
dedent`
import {createVisitor, signals} from "@romefrontend/compiler";
import {descriptions} from "@romefrontend/diagnostics";
@@ -47,7 +47,7 @@ export async function main([ruleName]: Array<string>): Promise<number> {
// Write test fixture
await writeFile(
- rulesPath.appendList(`${ruleName}.test.rjson`),
+ rulesPath.append(`${ruleName}.test.rjson`),
dedent`
filename: "filename.ts"
invalid: [
@@ -65,7 +65,7 @@ export async function main([ruleName]: Array<string>): Promise<number> {
// Write docs
await writeFile(
- ROOT.appendList("website", "src", "docs", "lint", "rules", `${ruleName}.md`),
+ ROOT.append("website", "src", "docs", "lint", "rules", `${ruleName}.md`),
`
---
title: Lint Rule ${ruleName}
@@ -85,7 +85,7 @@ export async function main([ruleName]: Array<string>): Promise<number> {
);
// Add description
- const diagDescriptionsPath = PACKAGES.appendList(
+ const diagDescriptionsPath = PACKAGES.append(
"diagnostics",
"descriptions",
"lint.ts",

Combine FilePath append and appendList methods (#900)