Allow omitting .test from `rome test` args
MODIFY
packages/@romejs/core/master/MasterRequest.ts
packages/@romejs/core/master/MasterRequest.ts
@@ -71,7 +71,9 @@ import {
AbsoluteFilePathSet,
createAbsoluteFilePath,
createUnknownFilePath,
+ UnknownFilePath,
} from '@romejs/path';
+import {ResolverQueryResponseFound} from './fs/Resolver';
import crypto = require('crypto');
import {createErrorFromStructure, getErrorStructure} from '@romejs/v8';
import {Dict, RequiredProps} from '@romejs/typescript-helpers';
@@ -110,10 +112,15 @@ export const EMPTY_SUCCESS_RESPONSE: MasterQueryResponseSuccess = {
markers: [],
};
+type GetFilesTryAlternateArg = (
+ path: UnknownFilePath,
+) => undefined | UnknownFilePath;
+
export type MasterRequestGetFilesOptions = Omit<
MemoryFSGlobOptions,
'getProjectIgnore'
> & {
+ tryAlternateArg?: GetFilesTryAlternateArg;
ignoreArgumentMisses?: boolean;
ignoreProjectIgnore?: boolean;
disabledDiagnosticCategory?: DiagnosticCategory;
@@ -231,7 +238,9 @@ export default class MasterRequest {
if (this.query.requestFlags.timing) {
const end = Date.now();
this.reporter.info(
- `Request took <duration emphasis>${String(end - this.start)}</duration>`,
+ `Request took <duration emphasis>${String(
+ end - this.start,
+ )}</duration>`,
);
}
@@ -371,8 +380,7 @@ export default class MasterRequest {
}
}
- throwDiagnosticFlagError(
- {
+ throwDiagnosticFlagError({
description,
target = {type: 'none'},
showHelp = true,
@@ -380,8 +388,7 @@ export default class MasterRequest {
description: RequiredProps<Partial<DiagnosticDescription>, 'message'>;
target?: SerializeCLITarget;
showHelp?: boolean;
- },
- ) {
+ }) {
const location = this.getDiagnosticPointerFromFlags(target);
let {category} = description;
@@ -421,7 +428,9 @@ export default class MasterRequest {
};
}
- getDiagnosticPointerFromFlags(target: SerializeCLITarget): DiagnosticLocation {
+ getDiagnosticPointerFromFlags(
+ target: SerializeCLITarget,
+ ): DiagnosticLocation {
const {query} = this;
const rawFlags = {
@@ -484,6 +493,7 @@ export default class MasterRequest {
async resolveFilesFromArgs(
overrideArgs?: Array<string>,
+ tryAlternateArg?: GetFilesTryAlternateArg,
): Promise<{
projects: Set<ProjectDefinition>;
resolvedArgs: ResolvedArgs;
@@ -493,6 +503,7 @@ export default class MasterRequest {
const projects: Set<ProjectDefinition> = new Set();
const rawArgs = overrideArgs === undefined ? this.query.args : overrideArgs;
const resolvedArgs: ResolvedArgs = [];
+ const {cwd} = this.client.flags;
// If args was explicitly provided then don't assume empty args is the project root
if (rawArgs.length === 0 && overrideArgs === undefined) {
@@ -513,16 +524,40 @@ export default class MasterRequest {
key: i,
});
- const resolved = await this.master.resolver.resolveEntryAssert(
+ let source = createUnknownFilePath(arg);
+ let resolved: undefined | ResolverQueryResponseFound;
+
+ if (tryAlternateArg !== undefined) {
+ const alternateSource = tryAlternateArg(source);
+ if (alternateSource !== undefined) {
+ const resolvedAlternate = await this.master.resolver.resolveEntry(
{
- origin: this.client.flags.cwd,
- source: createUnknownFilePath(arg),
+ origin: cwd,
+ source: alternateSource,
requestedType: 'folder',
},
{
location,
},
);
+ if (resolvedAlternate.type === 'FOUND') {
+ resolved = resolvedAlternate;
+ }
+ }
+ }
+
+ if (resolved === undefined) {
+ resolved = await this.master.resolver.resolveEntryAssert(
+ {
+ origin: cwd,
+ source,
+ requestedType: 'folder',
+ },
+ {
+ location,
+ },
+ );
+ }
const project = this.master.projectManager.assertProjectExisting(
resolved.path,
@@ -553,7 +588,10 @@ export default class MasterRequest {
this.checkCancelled();
// Everything needs to be relative to this
- const {resolvedArgs} = await this.resolveFilesFromArgs();
+ const {resolvedArgs} = await this.resolveFilesFromArgs(
+ opts.args,
+ opts.tryAlternateArg,
+ );
const initial = await this.getFilesFromArgs(opts);
await callback(initial, true);
@@ -636,14 +674,16 @@ export default class MasterRequest {
const {master} = this;
const {configCategory, ignoreProjectIgnore} = opts;
- const {projects, resolvedArgs} = await this.resolveFilesFromArgs(opts.args);
+ const {projects, resolvedArgs} = await this.resolveFilesFromArgs(
+ opts.args,
+ opts.tryAlternateArg,
+ );
const extendedGlobOpts: MemoryFSGlobOptions = {...opts};
if (configCategory !== undefined) {
extendedGlobOpts.getProjectIgnore = (project) =>
- ignoreProjectIgnore ? [] : project.config[configCategory].ignore
- ;
+ ignoreProjectIgnore ? [] : project.config[configCategory].ignore;
}
// Resolved arguments that resulted in no files
@@ -706,8 +746,7 @@ export default class MasterRequest {
project,
(consumer) =>
consumer.has(configCategory) &&
- consumer.get(configCategory).get('ignore')
- ,
+ consumer.get(configCategory).get('ignore'),
);
if (ignoreSource.value !== undefined) {
@@ -758,7 +797,8 @@ export default class MasterRequest {
return {
...res,
cacheDependencies: res.cacheDependencies.map((filename) => {
- return projectManager.getFileReference(createAbsoluteFilePath(filename)).uid;
+ return projectManager.getFileReference(createAbsoluteFilePath(filename))
+ .uid;
}),
};
}
@@ -832,10 +872,8 @@ export default class MasterRequest {
): Promise<void> {
this.checkCancelled();
- await this.wrapRequestDiagnostic(
- 'updateBuffer',
- path,
- (bridge, file) => bridge.updateBuffer.call({file, content}),
+ await this.wrapRequestDiagnostic('updateBuffer', path, (bridge, file) =>
+ bridge.updateBuffer.call({file, content}),
);
this.master.fileChangeEvent.send(path);
}
@@ -846,16 +884,17 @@ export default class MasterRequest {
): Promise<Program> {
this.checkCancelled();
- return this.wrapRequestDiagnostic(
- 'parse',
- path,
- (bridge, file) => bridge.parseJS.call({file, options: opts}),
+ return this.wrapRequestDiagnostic('parse', path, (bridge, file) =>
+ bridge.parseJS.call({file, options: opts}),
);
}
async requestWorkerLint(
path: AbsoluteFilePath,
- optionsWithoutModSigs: Omit<WorkerLintOptions, 'prefetchedModuleSignatures'>,
+ optionsWithoutModSigs: Omit<
+ WorkerLintOptions,
+ 'prefetchedModuleSignatures'
+ >,
): Promise<WorkerLintResult> {
this.checkCancelled();
@@ -877,21 +916,16 @@ export default class MasterRequest {
prefetchedModuleSignatures,
};
- const res = await this.wrapRequestDiagnostic(
- 'lint',
- path,
- (bridge, file) => bridge.lint.call({file, options, parseOptions: {}}),
+ const res = await this.wrapRequestDiagnostic('lint', path, (bridge, file) =>
+ bridge.lint.call({file, options, parseOptions: {}}),
);
- await cache.update(
- path,
- (cacheEntry) => ({
+ await cache.update(path, (cacheEntry) => ({
lint: {
...cacheEntry.lint,
[cacheKey]: res,
},
- }),
- );
+ }));
return res;
}
@@ -902,10 +936,8 @@ export default class MasterRequest {
): Promise<undefined | WorkerFormatResult> {
this.checkCancelled();
- return await this.wrapRequestDiagnostic(
- 'format',
- path,
- (bridge, file) => bridge.format.call({file, parseOptions}),
+ return await this.wrapRequestDiagnostic('format', path, (bridge, file) =>
+ bridge.format.call({file, parseOptions}),
);
}
@@ -949,9 +981,7 @@ export default class MasterRequest {
});
// There's a race condition here between the file being opened and then rewritten
- await cache.update(
- path,
- (cacheEntry) => ({
+ await cache.update(path, (cacheEntry) => ({
compile: {
...cacheEntry.compile,
[cacheKey]: {
@@ -959,8 +989,7 @@ export default class MasterRequest {
cached: true,
},
},
- }),
- );
+ }));
return res;
}
@@ -983,15 +1012,12 @@ export default class MasterRequest {
path,
(bridge, file) => bridge.analyzeDependencies.call({file, parseOptions}),
);
- await cache.update(
- path,
- {
+ await cache.update(path, {
analyzeDependencies: {
...res,
cached: true,
},
- },
- );
+ });
return {
...res,
@@ -1017,12 +1043,9 @@ export default class MasterRequest {
path,
(bridge, file) => bridge.moduleSignatureJS.call({file, parseOptions}),
);
- await cache.update(
- path,
- {
+ await cache.update(path, {
moduleSignature: res,
- },
- );
+ });
return res;
}

MODIFY
packages/@romejs/core/master/commands/test.ts
packages/@romejs/core/master/commands/test.ts
@@ -35,6 +35,14 @@ export default createMasterCommand({
const {reporter} = req;
const {paths} = await req.getFilesFromArgs({
+ tryAlternateArg: (path) =>
+ path.hasExtension('test')
+ ? undefined
+ : path
+ .getParent()
+ .append(
+ `${path.getExtensionlessBasename()}.test${path.getExtensions()}`,
+ ),
test: (path) => path.hasExtension('test'),
noun: 'test',
verb: 'testing',
@@ -43,18 +51,14 @@ export default createMasterCommand({
{
type: 'log',
category: 'info',
- text: 'Searched for files with <emphasis>.test.*</emphasis> file extension',
+ text:
+ 'Searched for files with <emphasis>.test.*</emphasis> file extension',
},
],
extensions: JS_EXTENSIONS,
disabledDiagnosticCategory: 'tests/disabled',
});
- if (paths.size === 0) {
- reporter.warn('No tests ran');
- return;
- }
-
reporter.info(`Bundling test files`);
let addDiagnostics: Diagnostics = [];
@@ -68,20 +72,14 @@ export default createMasterCommand({
}),
);
- for (const [path, res] of await bundler.bundleMultiple(
- Array.from(paths),
- {
+ for (const [path, res] of await bundler.bundleMultiple(Array.from(paths), {
deferredSourceMaps: true,
- },
- )) {
- tests.set(
- path.join(),
- {
+ })) {
+ tests.set(path.join(), {
code: res.entry.js.content,
sourceMap: res.entry.sourceMap.map,
path,
- },
- );
+ });
}
reporter.info(`Running tests`);

MODIFY
packages/@romejs/core/master/fs/Resolver.ts
packages/@romejs/core/master/fs/Resolver.ts
@@ -37,9 +37,7 @@ function request(
}
> {
return new Promise((resolve) => {
- const req = https.get(
- url,
- (res) => {
+ const req = https.get(url, (res) => {
if (res.statusCode !== 200) {
console.log('non-200 return');
resolve({
@@ -58,25 +56,16 @@ function request(
let data = '';
- res.on(
- 'data',
- (chunk) => {
+ res.on('data', (chunk) => {
data += chunk;
- },
- );
+ });
- res.on(
- 'end',
- () => {
+ res.on('end', () => {
resolve({type: 'DOWNLOADED', content: data});
- },
- );
- },
- );
+ });
+ });
- req.on(
- 'error',
- (err) => {
+ req.on('error', (err) => {
resolve({
type: 'FETCH_ERROR',
source: undefined,
@@ -88,8 +77,7 @@ function request(
},
],
});
- },
- );
+ });
});
}
@@ -217,7 +205,8 @@ function attachExportAliasIfUnresolved(
return {
...res,
- source: location === undefined
+ source:
+ location === undefined
? undefined
: {
location,
@@ -226,8 +215,7 @@ function attachExportAliasIfUnresolved(
};
}
-function getExportsAlias(
- {
+function getExportsAlias({
manifest,
relative,
platform,
@@ -235,8 +223,7 @@ function getExportsAlias(
manifest: Manifest;
relative: UnknownFilePath;
platform?: Platform;
- },
-): undefined | ExportAlias {
+}): undefined | ExportAlias {
if (typeof manifest.exports === 'boolean') {
return undefined;
}
@@ -339,9 +326,12 @@ export default class Resolver {
return res.path;
}
- async resolveEntry(query: ResolverRemoteQuery): Promise<ResolverQueryResponse> {
+ async resolveEntry(
+ query: ResolverRemoteQuery,
+ querySource?: ResolverQuerySource,
+ ): Promise<ResolverQueryResponse> {
await this.findProjectFromQuery(query);
- return this.resolveRemote({...query, entry: true});
+ return this.resolveRemote({...query, entry: true}, querySource);
}
async resolveAssert(
@@ -512,11 +502,10 @@ export default class Resolver {
// Check with appended extensions
if (usesUnknownExtension && !callees.includes('implicitExtension')) {
for (const ext of IMPLICIT_JS_EXTENSIONS) {
- yield* this._getFilenameVariants(
- query,
- path.addExtension(`.${ext}`),
- [...callees, 'implicitExtension'],
- );
+ yield* this._getFilenameVariants(query, path.addExtension(`.${ext}`), [
+ ...callees,
+ 'implicitExtension',
+ ]);
}
}
@@ -531,7 +520,9 @@ export default class Resolver {
yield* this._getFilenameVariants(
query,
path.changeBasename(
- `${path.getExtensionlessBasename()}@${String(i)}x${path.memoizedExtension}`,
+ `${path.getExtensionlessBasename()}@${String(i)}x${
+ path.memoizedExtension
+ }`,
),
[...callees, 'implicitScale'],
);
@@ -663,13 +654,17 @@ export default class Resolver {
moduleName: string,
): undefined | ManifestDefinition {
// Find the project
- const project = this.master.projectManager.findProjectExisting(query.origin);
+ const project = this.master.projectManager.findProjectExisting(
+ query.origin,
+ );
if (project === undefined) {
return undefined;
}
// Find the package
- const projects = this.master.projectManager.getHierarchyFromProject(project);
+ const projects = this.master.projectManager.getHierarchyFromProject(
+ project,
+ );
for (const project of projects) {
const pkg = project.packages.get(moduleName);
@@ -887,7 +882,9 @@ export default class Resolver {
// Check all parent directories for node_modules
for (const dir of parentDirectories) {
const modulePath = dir.append(NODE_MODULES).append(moduleName);
- const manifestDef = this.master.memoryFs.getManifestDefinition(modulePath);
+ const manifestDef = this.master.memoryFs.getManifestDefinition(
+ modulePath,
+ );
if (manifestDef !== undefined) {
return this.resolveManifest(query, manifestDef, moduleNameParts);
}

Allow omitting .test from `rome test` args