Defer default project creation
MODIFY
packages/@romejs/compiler/api/analyzeDependencies.test.ts
packages/@romejs/compiler/api/analyzeDependencies.test.ts
*/
import analyzeDependencies from "./analyzeDependencies";
-import {DEFAULT_PROJECT_CONFIG} from "@romejs/project";
+import {createDefaultProjectConfig} from "@romejs/project";
import {test} from "rome";
import {parseJS} from "@romejs/js-parser";
import {ConstSourceType} from "@romejs/ast";
@@ -20,7 +20,7 @@ async function testAnalyzeDeps(input: string, sourceType: ConstSourceType) {
sourceText: input,
project: {
folder: undefined,
- config: DEFAULT_PROJECT_CONFIG,
+ config: createDefaultProjectConfig(),
},
});
}

MODIFY
packages/@romejs/compiler/lib/CompilerContext.ts
packages/@romejs/compiler/lib/CompilerContext.ts
@@ -52,7 +52,7 @@ import stringDiff from "@romejs/string-diff";
import {formatAST} from "@romejs/formatter";
import {REDUCE_REMOVE} from "../constants";
import {FileReference} from "@romejs/core";
-import {DEFAULT_PROJECT_CONFIG} from "@romejs/project";
+import {createDefaultProjectConfig} from "@romejs/project";
import {
buildLintDecisionAdviceAction,
buildLintDecisionGlobalString,
@@ -114,7 +114,7 @@ export default class CompilerContext {
sourceText = "",
project = {
folder: undefined,
- config: DEFAULT_PROJECT_CONFIG,
+ config: createDefaultProjectConfig(),
},
suppressions,
} = arg;

MODIFY
packages/@romejs/compiler/lint/rules/testHelpers.ts
packages/@romejs/compiler/lint/rules/testHelpers.ts
@@ -9,7 +9,7 @@ import {TestHelper} from "rome";
import lint from "../index";
import {parseJS} from "@romejs/js-parser";
import {createUnknownFilePath} from "@romejs/path";
-import {DEFAULT_PROJECT_CONFIG} from "@romejs/project";
+import {createDefaultProjectConfig} from "@romejs/project";
import {ConstProgramSyntax, ConstSourceType} from "@romejs/ast";
import {DiagnosticCategory, DiagnosticsProcessor} from "@romejs/diagnostics";
import {printDiagnosticsToString} from "@romejs/cli-diagnostics";
@@ -84,7 +84,7 @@ async function testLintExpect(
sourceText: input,
project: {
folder: undefined,
- config: DEFAULT_PROJECT_CONFIG,
+ config: createDefaultProjectConfig(),
},
});

MODIFY
packages/@romejs/core/master/Cache.ts
packages/@romejs/core/master/Cache.ts
@@ -12,7 +12,7 @@ import {
} from "../common/bridges/WorkerBridge";
import {ModuleSignature} from "@romejs/js-analysis";
import Master from "./Master";
-import {DEFAULT_PROJECT_CONFIG, ProjectDefinition} from "@romejs/project";
+import {ProjectDefinition, createDefaultProjectConfig} from "@romejs/project";
import {VERSION} from "../common/constants";
import {AbsoluteFilePath, AbsoluteFilePathMap} from "@romejs/path";
import {createDirectory, readFileText, removeFile, writeFile} from "@romejs/fs";
@@ -85,7 +85,7 @@ export default class Cache {
const {memoryFs} = this.master;
await createDirectory(this.cachePath);
- await memoryFs.watch(this.cachePath, DEFAULT_PROJECT_CONFIG);
+ await memoryFs.watch(this.cachePath, createDefaultProjectConfig());
this.master.endEvent.subscribe(async () => {
// Wait on possible running writePending

MODIFY
packages/@romejs/core/master/fs/Resolver.ts
packages/@romejs/core/master/fs/Resolver.ts
import {Manifest, ManifestDefinition} from "@romejs/codec-js-manifest";
import Master from "../Master";
import {PLATFORM_ALIASES, Platform} from "../../common/types/platform";
-import {DEFAULT_PROJECT_CONFIG, ProjectDefinition} from "@romejs/project";
+import {ProjectDefinition, createDefaultProjectConfig} from "@romejs/project";
import {FileReference} from "../../common/types/files";
import resolverSuggest from "./resolverSuggest";
import {
@@ -367,7 +367,7 @@ export default class Resolver {
switch (protocol) {
case "http":
case "https": {
- let projectConfig = DEFAULT_PROJECT_CONFIG;
+ let projectConfig = createDefaultProjectConfig();
if (origin.isAbsolute()) {
const project = this.master.projectManager.findProjectExisting(

MODIFY
packages/@romejs/core/master/fs/VirtualModules.ts
packages/@romejs/core/master/fs/VirtualModules.ts
@@ -10,9 +10,9 @@ import {modules} from "./runtime-modules";
import {AbsoluteFilePath} from "@romejs/path";
import {createDirectory, writeFile} from "@romejs/fs";
import {
- DEFAULT_PROJECT_CONFIG,
- DEFAULT_PROJECT_CONFIG_META,
ProjectConfig,
+ createDefaultProjectConfig,
+ createDefaultProjectConfigMeta,
} from "@romejs/project";
export default class VirtualModules {
@@ -41,12 +41,12 @@ export default class VirtualModules {
// Initialize as project
const projectConfig: ProjectConfig = {
- ...DEFAULT_PROJECT_CONFIG,
+ ...createDefaultProjectConfig(),
name: "rome-runtime",
};
await this.master.projectManager.addProjectWithConfig({
projectFolder: runtimeModulesPath,
- meta: DEFAULT_PROJECT_CONFIG_META,
+ meta: createDefaultProjectConfigMeta(),
config: projectConfig,
});
await this.master.memoryFs.watch(runtimeModulesPath, projectConfig);

MODIFY
packages/@romejs/core/master/project/ProjectManager.ts
packages/@romejs/core/master/project/ProjectManager.ts
import Master from "../Master";
import {
- DEFAULT_PROJECT_CONFIG,
- DEFAULT_PROJECT_CONFIG_META,
ProjectConfig,
ProjectConfigMeta,
ProjectDefinition,
@@ -16,6 +14,8 @@ import {
ROME_CONFIG_PACKAGE_JSON_FIELD,
ROME_CONFIG_WARN_FILENAMES,
assertHardMeta,
+ createDefaultProjectConfig,
+ createDefaultProjectConfigMeta,
loadCompleteProjectConfig,
serializeJSONProjectConfig,
} from "@romejs/project";
@@ -167,14 +167,14 @@ export default class ProjectManager {
});
const vendorProjectConfig: ProjectConfig = {
- ...DEFAULT_PROJECT_CONFIG,
+ ...createDefaultProjectConfig(),
name: "rome-internal-remote",
};
const defaultVendorPath = vendorProjectConfig.files.vendorPath;
await createDirectory(defaultVendorPath);
await this.addProjectWithConfig({
projectFolder: defaultVendorPath,
- meta: DEFAULT_PROJECT_CONFIG_META,
+ meta: createDefaultProjectConfigMeta(),
config: vendorProjectConfig,
});
await this.master.memoryFs.watch(defaultVendorPath, vendorProjectConfig);

MODIFY
packages/@romejs/js-analysis/tests/basic.test.ts
packages/@romejs/js-analysis/tests/basic.test.ts
*/
import {Diagnostics} from "@romejs/diagnostics";
-import {DEFAULT_PROJECT_CONFIG} from "@romejs/project";
+import {createDefaultProjectConfig} from "@romejs/project";
import {test} from "rome";
import {check} from "@romejs/js-analysis";
import {parseJS} from "@romejs/js-parser";
@@ -23,7 +23,7 @@ async function testCheck(code: string): Promise<Diagnostics> {
ast,
project: {
folder: undefined,
- config: DEFAULT_PROJECT_CONFIG,
+ config: createDefaultProjectConfig(),
},
provider: {
getExportTypes() {

MODIFY
packages/@romejs/js-ast-utils/removeLoc.ts
packages/@romejs/js-ast-utils/removeLoc.ts
*/
import {AnyNode, JSNodeBase, MOCK_PROGRAM} from "@romejs/ast";
-import {DEFAULT_PROJECT_CONFIG} from "@romejs/project";
+import {createDefaultProjectConfig} from "@romejs/project";
import {CompilerContext, Path, TransformVisitors} from "@romejs/compiler";
import {SourceLocation} from "@romejs/parser-core";
@@ -50,7 +50,7 @@ export default function removeLoc(ast: AnyNode) {
ast: MOCK_PROGRAM,
project: {
folder: undefined,
- config: DEFAULT_PROJECT_CONFIG,
+ config: createDefaultProjectConfig(),
},
});
return context.reduce(ast, removeLocTransform);

MODIFY
packages/@romejs/path/index.ts
packages/@romejs/path/index.ts
*/
import os = require("os");
+import {escapeMarkup} from "@romejs/string-markup";
type FilePathOptions<Super> = {
filename?: string;
@@ -76,7 +77,7 @@ class BaseFilePath<Super extends UnknownFilePath> {
if (emphasis) {
markup += `emphasis `;
}
- markup += `target="${this.join()}" />`;
+ markup += `target="${escapeMarkup(this.join())}" />`;
return markup;
}

MODIFY
packages/@romejs/project/load.ts
packages/@romejs/project/load.ts
// Project configs are initialized very infrequently anyway so we can live with the extremely minor perf hit.
import {Consumer} from "@romejs/consume";
import {
- DEFAULT_PROJECT_CONFIG,
PartialProjectConfig,
ProjectConfig,
ProjectConfigMeta,
ProjectConfigMetaHard,
ProjectConfigObjects,
ProjectConfigTarget,
+ createDefaultProjectConfig,
} from "./types";
import {parsePathPatternsFile} from "@romejs/path-match";
import {
@@ -67,10 +67,11 @@ export function loadCompleteProjectConfig(
const {consumer} = meta;
// Produce a defaultConfig with some folder specific values
+ const _defaultConfig: ProjectConfig = createDefaultProjectConfig();
const defaultConfig: ProjectConfig = {
- ...DEFAULT_PROJECT_CONFIG,
+ ..._defaultConfig,
vcs: {
- ...DEFAULT_PROJECT_CONFIG.vcs,
+ ..._defaultConfig.vcs,
root: projectFolder,
},
};
@@ -80,11 +81,9 @@ export function loadCompleteProjectConfig(
);
const config: ProjectConfig = {
- ...DEFAULT_PROJECT_CONFIG,
+ ...defaultConfig,
name,
- root: partial.root === undefined
- ? DEFAULT_PROJECT_CONFIG.root
- : partial.root,
+ root: partial.root === undefined ? defaultConfig.root : partial.root,
...mergePartialConfig(defaultConfig, partial),
};

MODIFY
packages/@romejs/project/types.ts
packages/@romejs/project/types.ts
@@ -143,7 +143,8 @@ export type ProjectConfigMetaHard = RequiredProps<
// Final project config
export type ProjectConfig = ProjectConfigBase & ProjectConfigObjects;
-export const DEFAULT_PROJECT_CONFIG_META: ProjectConfigMeta = {
+export function createDefaultProjectConfigMeta(): ProjectConfigMeta {
+ return {
projectFolder: undefined,
configPath: undefined,
configHashes: [],
@@ -152,8 +153,10 @@ export const DEFAULT_PROJECT_CONFIG_META: ProjectConfigMeta = {
configSourceSubKey: undefined,
consumersChain: [],
};
+}
-export const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
+export function createDefaultProjectConfig(): ProjectConfig {
+ return {
name: "unknown",
root: false,
version: undefined,
@@ -191,3 +194,4 @@ export const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
},
targets: new Map(),
};
+}

Defer default project creation