Remove haste
MODIFY
packages/@romejs/core/common/fileHandlers.ts
packages/@romejs/core/common/fileHandlers.ts
@@ -97,7 +97,6 @@ export type ExtensionHandlerMethodInfo = {
export type ExtensionHandler = {
sourceType?: ConstSourceType;
syntax?: Array<ConstProgramSyntax>;
- hasteMode?: 'ext' | 'noext';
isAsset?: boolean;
canHaveScale?: boolean;
lint?: (info: ExtensionLintInfo) => Promise<ExtensionLintResult>;
@@ -164,7 +163,6 @@ const assetHandler: ExtensionHandler = {
const jsonHandler: ExtensionHandler = {
// analyzeDependencies shim
...textHandler,
- hasteMode: 'noext',
async format(info: ExtensionHandlerMethodInfo): Promise<ExtensionLintResult> {
const {file, worker} = info;
const {uid} = file;
@@ -260,7 +258,6 @@ function buildJSHandler(
JS_EXTENSIONS.push(ext);
return {
- hasteMode: 'ext',
syntax,
sourceType,
async analyzeDependencies({file, worker, parseOptions}) {

MODIFY
packages/@romejs/core/master/fs/MemoryFileSystem.ts
packages/@romejs/core/master/fs/MemoryFileSystem.ts
@@ -9,7 +9,6 @@ import Master from '../Master';
import {
Manifest,
ManifestDefinition,
- manifestNameToString,
normalizeManifest,
} from '@romejs/codec-js-manifest';
import {
@@ -50,8 +49,6 @@ import {markup} from '@romejs/string-markup';
const DEFAULT_DENYLIST = ['.hg', '.git'];
-const PACKAGE_JSON = 'package.json';
-
const GLOB_IGNORE: PathPatterns = [
parsePathPattern({input: 'node_modules'}),
parsePathPattern({input: '.git'}),
@@ -115,8 +112,6 @@ type DeclareManifestOpts = {
diagnostics: DiagnosticsProcessor;
dirname: AbsoluteFilePath;
path: AbsoluteFilePath;
- hasteName: undefined | string;
- hastePath: AbsoluteFilePath;
};
type CrawlOptions = {
@@ -143,12 +138,6 @@ export type MemoryFSGlobOptions = {
test?: (path: AbsoluteFilePath) => boolean;
};
-export type HasteCollisionCallback = (
- hasteName: string,
- existing: string,
- filename: string,
-) => void;
-
async function createRegularWatcher(
memoryFs: MemoryFileSystem,
diagnostics: DiagnosticsProcessor,
@@ -608,9 +597,6 @@ export default class MemoryFileSystem {
// Remove from 'all possible caches
this.files.delete(path);
- // Remove from 'haste maps
- this.handleDeletedHaste(path);
-
// If this is a manifest filename then clear it from 'any possible package and our internal module map
const basename = path.getBasename();
if (basename === 'package.json') {
@@ -627,21 +613,6 @@ export default class MemoryFileSystem {
this.deletedFileEvent.send(path);
}
- handleDeletedHaste(path: AbsoluteFilePath): void {
- const hasteName = this.getHasteName(path);
- if (hasteName === undefined) {
- return;
- }
-
- const projects = this.master.projectManager.getHierarchyFromFilename(path);
- for (const {hasteMap} of projects) {
- const existing = hasteMap.get(hasteName);
- if (existing !== undefined && existing.equal(path)) {
- hasteMap.delete(hasteName);
- }
- }
- }
-
handleDeletedManifest(path: AbsoluteFilePath): void {
const folder = path.getParent();
const def = this.manifests.get(folder);
@@ -832,77 +803,23 @@ export default class MemoryFileSystem {
return path.getSegments().includes('node_modules') === false;
}
- isInsideHaste(path: AbsoluteFilePath): boolean {
- if (!this.isInsideProject(path)) {
- return false;
- }
-
- // Check if we're inside a haste package, child files of a haste package shouldn't be added to the haste map
- for (const dir of path.getChain()) {
- const packagePath = dir.append(PACKAGE_JSON);
- if (path.equal(packagePath)) {
- // isInsideHaste will be called after we declare a haste package, all it's subfiles wont be inside the haste map but we should still be
- continue;
- }
-
- const manifest = this.getManifest(packagePath);
-
- // rome-ignore lint/camelCase
- if ((manifest?.raw)?.haste_commonjs === true) {
- return false;
- }
- }
-
- return true;
- }
-
- getHasteName(path: AbsoluteFilePath): undefined | string {
- const filename = path.join();
-
- let {handler, ext} = this.master.projectManager.getHandlerWithProject(path);
- if (handler === undefined || handler.hasteMode === undefined) {
- return undefined;
- }
-
- const basename = path.getBasename();
-
- if (handler.hasteMode === 'ext') {
- ext = `.${ext}`; // we also want to remove the dot suffix from the haste name
- if (!filename.endsWith(ext)) {
- throw new Error(
- `Expected ${filename} to end with ${ext} as it was returned as the extension name`,
- );
- }
-
- return basename.slice(0, -ext.length);
- } else if (handler.hasteMode === 'noext') {
- return basename;
- }
-
- return undefined;
- }
-
// This is a wrapper around _declareManifest as it can produce diagnostics
- async declareManifest(opts: DeclareManifestOpts): Promise<undefined | string> {
- const {value, diagnostics} = await catchDiagnostics(() => {
+ async declareManifest(opts: DeclareManifestOpts): Promise<void> {
+ const {diagnostics} = await catchDiagnostics(() => {
return this._declareManifest(opts);
});
- if (diagnostics === undefined) {
- return value;
- } else {
+ if (diagnostics !== undefined) {
opts.diagnostics.addDiagnostics(diagnostics);
- return undefined;
}
}
async _declareManifest(
{
path,
- hasteName,
diagnostics,
}: DeclareManifestOpts,
- ): Promise<undefined | string> {
+ ): Promise<void> {
// Fetch the manifest
const manifestRaw = await readFileText(path);
const hash = crypto.createHash('sha256').update(manifestRaw).digest('hex');
@@ -937,11 +854,6 @@ export default class MemoryFileSystem {
this.manifests.set(folder, def);
- // Set haste name and haste location to the directory itself
- if (manifest.name !== undefined) {
- hasteName = manifestNameToString(manifest.name);
- }
-
// If we aren't in node_modules then this is a project package
const isProjectPackage = this.isInsideProject(path);
const {projectManager} = this.master;
@@ -961,8 +873,6 @@ export default class MemoryFileSystem {
manifests: [{id: def.id, manifest: this.getPartialManifest(def)}],
});
}
-
- return hasteName;
}
glob(
@@ -1116,7 +1026,7 @@ export default class MemoryFileSystem {
}
};
- // Give priority to package.json as we base some haste heuristics on it's entry
+ // Give priority to package.json in case we want to derive something from the project config
for (const file of files) {
if (PRIORITY_FILES.has(file.getBasename())) {
files.delete(file);
@@ -1183,9 +1093,6 @@ export default class MemoryFileSystem {
this.files.set(path, stats);
this.addFileToDirectoryListing(path);
- let hastePath = path;
- let hasteName = this.getHasteName(path);
-
const basename = path.getBasename();
const dirname = path.getParent();
@@ -1198,21 +1105,12 @@ export default class MemoryFileSystem {
await projectManager.queueAddProject(dirname, path);
}
- // If this is a package.json then declare this module and setup the correct haste variables
if (isValidManifest(path)) {
- hasteName = await this.declareManifest({
+ await this.declareManifest({
diagnostics: opts.diagnostics,
dirname,
path,
- hasteName,
- hastePath,
});
- hastePath = dirname;
- }
-
- // Add to haste map
- if (hasteName !== undefined && this.isInsideHaste(path)) {
- projectManager.declareHaste(path, hasteName, hastePath, opts.diagnostics);
}
return true;

MODIFY
packages/@romejs/core/master/fs/Resolver.ts
packages/@romejs/core/master/fs/Resolver.ts
@@ -121,7 +121,6 @@ type ResolverQueryResponseFoundType =
| 'package'
| 'mock'
| 'virtual'
- | 'haste'
| 'implicitPlatform'
| 'implicitScale'
| 'implicitExtension'
@@ -774,46 +773,6 @@ export default class Resolver {
return QUERY_RESPONSE_MISSING;
}
- resolveHaste(
- query: ResolverLocalQuery,
- mainProject: ProjectDefinition,
- moduleName: string,
- moduleNameParts: Array<string>,
- ): ResolverQueryResponse {
- const projects = this.master.projectManager.getHierarchyFromProject(
- mainProject,
- );
-
- for (const project of projects) {
- // Check for an entry for the direct name, in the case we're given something like react-relay/modern/ReactRelayQueryFetcher we'll resolve react-relay then resolve from it with the rest of the path
- const resolved = project.hasteMap.get(moduleName);
- if (resolved !== undefined) {
- if (moduleNameParts.length === 0) {
- return this.finishResolverQueryResponse(resolved, ['haste']);
- } else {
- return this.resolvePath(
- {
- ...query,
- source: resolved.append(moduleNameParts),
- },
- true,
- ['haste'],
- );
- }
- }
-
- // Check all filename variants, we use the full module path here so using the parts separately isn't necessary
- for (const {path} of this.getFilenameVariants(query, query.source)) {
- const resolved = project.hasteMap.get(path.join());
- if (resolved !== undefined) {
- return this.finishResolverQueryResponse(resolved, ['haste']);
- }
- }
- }
-
- return QUERY_RESPONSE_MISSING;
- }
-
// Given a reference to a module, extract the module name and any trailing relative paths
splitModuleName(path: UnknownFilePath): [string, Array<string>] {
// fetch the first part of the path as that's the module name
@@ -861,19 +820,6 @@ export default class Resolver {
);
}
- // Check the haste map
- if (project !== undefined && project.hasteMap.size > 0) {
- const hasteResolved = this.resolveHaste(
- query,
- project,
- moduleName,
- moduleNameParts,
- );
- if (shouldReturnQueryResponse(hasteResolved)) {
- return hasteResolved;
- }
- }
-
// Check if it matches any of our project packages
const packageResolved = this.resolvePackage(
query,

MODIFY
packages/@romejs/core/master/fs/resolverSuggest.ts
packages/@romejs/core/master/fs/resolverSuggest.ts
@@ -334,10 +334,6 @@ function getPackageSuggestions(
);
for (const project of projects) {
- for (const [name, value] of project.hasteMap) {
- possibleGlobalPackages.set(name, value.join());
- }
-
for (const [name, value] of project.packages) {
possibleGlobalPackages.set(name, value.folder.join());
}

MODIFY
packages/@romejs/core/master/project/ProjectManager.ts
packages/@romejs/core/master/project/ProjectManager.ts
@@ -31,7 +31,6 @@ import {
createSingleDiagnosticError,
descriptions,
} from '@romejs/diagnostics';
-import {matchPathPatterns} from '@romejs/path-match';
import {
ManifestDefinition,
manifestNameToString,
@@ -281,22 +280,6 @@ export default class ProjectManager {
const project = this.assertProjectExisting(path);
- // For haste projects, use the haste name as the uid. If the user has multiple projects
-
- // with colliding uids then that's fine, it will just cause more cache misses as we compare
-
- // mtime, project config hash etc stored in the cache.
- if (this.isHasteDeclared(path, project)) {
- const hasteName = this.master.memoryFs.getHasteName(path);
- if (hasteName === undefined) {
- throw new Error(
- 'isHasteDeclared returned true so this should always return a valid name',
- );
- }
- this.setUid(path, hasteName);
- return hasteName;
- }
-
// Format of uids will be <PROJECT_NAME>/<PACKAGE_NAME>/<RELATIVE>
const parts: Array<string> = [];
@@ -631,7 +614,6 @@ export default class ProjectManager {
id: this.projectIdCounter++,
packages: new Map(),
manifests: new Map(),
- hasteMap: new Map(),
parent: parentProject,
children: new Set(),
};
@@ -711,77 +693,6 @@ export default class ProjectManager {
}
}
- isHasteIgnored(path: AbsoluteFilePath, config: ProjectConfig): boolean {
- return matchPathPatterns(path, config.haste.ignore) !== 'NO_MATCH';
- }
-
- isHasteDeclared(path: AbsoluteFilePath, project: ProjectDefinition): boolean {
- if (project.config.haste.enabled === false) {
- return false;
- }
-
- const hasteName = this.master.memoryFs.getHasteName(path);
- if (hasteName === undefined) {
- return false;
- }
-
- const existing = project.hasteMap.get(hasteName);
- if (existing === undefined) {
- return false;
- }
-
- return existing.equal(path);
- }
-
- declareHaste(
- path: AbsoluteFilePath,
- hasteName: string,
- hastePath: AbsoluteFilePath,
- diagnostics: DiagnosticsProcessor,
- ) {
- for (const project of this.getHierarchyFromFilename(path)) {
- const {hasteMap, config} = project;
-
- if (config.haste.enabled === false) {
- break;
- }
-
- if (this.isHasteIgnored(path, config)) {
- continue;
- }
-
- let existing = hasteMap.get(hasteName);
- if (existing !== undefined && !existing.equal(hastePath)) {
- const existingResolved = this.master.resolver.resolvePath({
- // `existing` will be absolute so the origin doesn't really matter
- origin: existing,
- source: existing,
- });
-
- // If both resolve to the same location then this isn't a collision and we should just ignore it
- if (
- existingResolved.type === 'FOUND' &&
- hastePath.equal(existingResolved.ref.real)
- ) {
- continue;
- }
-
- diagnostics.addDiagnostic({
- description: descriptions.PROJECT_MANAGER.HASTE_COLLISION(
- hasteName,
- existing.join(),
- ),
- location: {
- filename: hastePath.join(),
- },
- });
- continue;
- }
-
- hasteMap.set(hasteName, hastePath);
- }
- }
-
async notifyWorkersOfProjects(
workers: Array<WorkerContainer>,
projects?: Array<ProjectDefinition>,

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -663,17 +663,6 @@ export const descriptions = createMessages({
},
],
}),
- HASTE_COLLISION: (hasteName: string, existing: string) => ({
- category: 'projectManager/nameCollision',
- message: `Found a haste collision for <emphasis>${hasteName}</emphasis>`,
- advice: [
- {
- type: 'log',
- category: 'info',
- text: markup`Defined already by <filelink emphasis target="${existing}" />`,
- },
- ],
- }),
NOT_FOUND: {
category: 'projectManager/missing',
message: `Couldn't find a project`,

MODIFY
packages/@romejs/project/load.ts
packages/@romejs/project/load.ts
@@ -184,7 +184,6 @@ export function normalizeProjectConfig(
bundler: {},
cache: {},
lint: {},
- haste: {},
resolver: {},
develop: {},
typeCheck: {},
@@ -250,17 +249,6 @@ export function normalizeProjectConfig(
}
}
- const haste = consumer.get('haste');
- if (categoryExists(haste)) {
- if (haste.has('enabled')) {
- config.haste.enabled = haste.get('enabled').asBoolean();
- }
-
- if (haste.has('ignore')) {
- config.haste.ignore = arrayOfPatterns(haste.get('ignore'));
- }
- }
-
const typeChecking = consumer.get('typeChecking');
if (categoryExists(typeChecking)) {
if (typeChecking.has('enabled')) {
@@ -449,11 +437,6 @@ function extendProjectConfig(
merged.lint.globals = lintGlobals;
}
- const hasteIgnore = mergeArrays(extendsObj.haste.ignore, config.haste.ignore);
- if (hasteIgnore !== undefined) {
- merged.haste.ignore = hasteIgnore;
- }
-
const testingIgnore = mergeArrays(
extendsObj.tests.ignore,
config.tests.ignore,
@@ -523,10 +506,6 @@ function mergePartialConfig<
...a.resolver,
...b.resolver,
},
- haste: {
- ...a.haste,
- ...b.haste,
- },
typeCheck: {
...a.typeCheck,
...b.typeCheck,

MODIFY
packages/@romejs/project/types.ts
packages/@romejs/project/types.ts
@@ -26,7 +26,6 @@ export type ProjectDefinition = {
config: ProjectConfig;
packages: Map<string, ManifestDefinition>;
manifests: Map<number, ManifestDefinition>;
- hasteMap: Map<string, AbsoluteFilePath>;
children: Set<ProjectDefinition>;
parent: undefined | ProjectDefinition;
};
@@ -39,10 +38,6 @@ export type ProjectConfigObjects = {
bundler: {
mode: BundlerMode;
};
- haste: {
- enabled: boolean;
- ignore: PathPatterns;
- };
lint: {
globals: Array<string>;
ignore: PathPatterns;
@@ -180,10 +175,6 @@ export const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
dependencies: {
enabled: false,
},
- haste: {
- enabled: false,
- ignore: [],
- },
lint: {
ignore: [],
globals: [],

Remove haste