Empty rome package
DELETE
packages/rome/error.ts
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-import {
- DiagnosticSuppressions,
- Diagnostics,
- getDiagnosticsFromError,
-} from '@romejs/diagnostics';
-import {printDiagnosticsToString} from '@romejs/cli-diagnostics';
-
-export class RomeDiagnosticsError extends Error {
- constructor(message: string) {
- super(message);
- this.name = 'RomeDiagnosticsError';
- }
-
- getHTML(): string {
- return '';
- }
-
- getAnsi(): string {
- return '';
- }
-}
-
-export function throwDiagnostics(diagnostics: Diagnostics) {
- if (diagnostics.length === 0) {
- return;
- }
-
- const suppressions: DiagnosticSuppressions = [];
-
- // We do not want to expose the `diagnostics`
- const err = new RomeDiagnosticsError(
- printDiagnosticsToString({
- diagnostics,
- suppressions,
- format: 'none',
- }),
- );
- err.getHTML = () =>
- printDiagnosticsToString({
- diagnostics,
- suppressions,
- format: 'html',
- })
- ;
- err.getAnsi = () =>
- printDiagnosticsToString({
- diagnostics,
- suppressions,
- format: 'ansi',
- })
- ;
- throw err;
-}
-
-export function wrapForErrors<T, Args extends Array<unknown>>(
- callback: (...args: Args) => Promise<T>,
-): (...args: Args) => Promise<T> {
- return async function(...args: Args): Promise<T> {
- try {
- return await callback(...args);
- } catch (err) {
- // Catches DiagnosticsError
- const diags = getDiagnosticsFromError(err);
- if (diags === undefined) {
- throw err;
- } else {
- throw throwDiagnostics(diags);
- }
- }
- };
-}

DELETE
packages/rome/index.ts
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-import {parseJS} from '@romejs/js-parser';
-import {
- AbsoluteFilePath,
- AbsoluteFilePathMap,
- createAbsoluteFilePath,
-} from '@romejs/path';
-import {SourceMap, SourceMapGenerator} from '@romejs/codec-source-map';
-import * as compiler from '@romejs/js-compiler';
-import {exists, lstat, readdir, watch} from '@romejs/fs';
-import {ConstSourceType} from '@romejs/js-ast';
-import {findProject} from './project';
-import {throwDiagnostics, wrapForErrors} from './error';
-import {getFileHandlerAssert} from '@romejs/core/common/fileHandlers';
-
-export {RomeDiagnosticsError} from './error';
-
-//
-const cacheKeyPartsCache: AbsoluteFilePathMap<string> = new AbsoluteFilePathMap();
-
-async function getCacheKeyPart(
- path: AbsoluteFilePath,
- relative: AbsoluteFilePath,
-): Promise<string> {
- const cached = cacheKeyPartsCache.get(path);
- if (cached !== undefined) {
- return `${path.relative(relative).join()}:${cached}`;
- }
-
- let part: string = '??';
-
- if (await exists(path)) {
- const stats = await lstat(path);
- if (stats.isFile()) {
- part = `mtime:${String(stats.mtimeMs)}`;
- } else if (stats.isDirectory()) {
- const filenames = await readdir(path);
- part = `readdir:${filenames}`;
- }
- } else {
- part = `noexist`;
- }
-
- cacheKeyPartsCache.set(path, part);
-
- // Watch for changes to invalidate our cached... cache key
- const watcher = watch(
- path,
- {},
- () => {
- cacheKeyPartsCache.delete(path);
- watcher.close();
- },
- );
-
- return `${path.relative(relative).join()}:${part}`;
-}
-
-export async function getCacheKey(filename: string): Promise<string> {
- const path = createAbsoluteFilePath(filename);
- const project = await findProject(path);
- const parts: Array<string> = [];
-
- parts.push(await getCacheKeyPart(path, path));
-
- for (const configDepPath of project.meta.configDependencies) {
- parts.push(await getCacheKeyPart(configDepPath, path));
- }
-
- return parts.join(';');
-}
-
-//
-export const compile = wrapForErrors(async function(
- opts: {
- filename: string;
- input: string;
- sourceType: ConstSourceType;
- },
-): Promise<{
- cacheKey: string;
- code: string;
- sourceMap: SourceMap;
-}> {
- const path = createAbsoluteFilePath(opts.filename);
-
- const project = await findProject(path);
- const cacheKey = await getCacheKey(opts.filename);
-
- const {handler} = getFileHandlerAssert(path, project.config);
-
- const sourceType =
- opts.sourceType === undefined ? handler.sourceType : opts.sourceType;
-
- const ast = parseJS({
- input: opts.input,
- path,
- syntax: handler.syntax,
- sourceType,
- });
- throwDiagnostics(ast.diagnostics);
-
- const res = await compiler.compile({
- ast,
- sourceText: opts.input,
- project: project.definition,
- options: {},
- });
- throwDiagnostics(res.diagnostics);
-
- // Build source map
- const sourceMapGenerator = new SourceMapGenerator({file: 'unknown'});
- for (const mapping of res.mappings) {
- sourceMapGenerator.addMapping(mapping);
- }
- const sourceMap = sourceMapGenerator.serialize();
-
- return {
- cacheKey,
- code: res.compiledCode,
- sourceMap,
- };
-});
-
-export function lint(filename: string, input: string) {
- filename;
- input;
-}

MODIFY
packages/rome/package.json
packages/rome/package.json
{
"name": "rome",
- "version": "0.0.2",
+ "version": "0.0.9",
"type": "module",
- "main": "index.ts",
"license": "MIT",
"files": [
"LICENSE"

DELETE
packages/rome/project.ts
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-import {TransformProjectDefinition} from '@romejs/js-compiler';
-import {
- AbsoluteFilePath,
- AbsoluteFilePathMap,
- AbsoluteFilePathSet,
-} from '@romejs/path';
-import {
- ProjectConfig,
- ProjectConfigMeta,
- ROME_CONFIG_FILENAMES,
- ROME_CONFIG_PACKAGE_JSON_FIELD,
- getParentConfigDependencies,
- loadCompleteProjectConfig,
-} from '@romejs/project';
-import {exists, readFileText} from '@romejs/fs';
-import {consumeJSON} from '@romejs/codec-json';
-import fs = require('fs');
-
-type FoundProject = {
- watchers: AbsoluteFilePathMap<fs.FSWatcher>;
- meta: ProjectConfigMeta;
- config: ProjectConfig;
- definition: TransformProjectDefinition;
-};
-
-const foundProjects: AbsoluteFilePathMap<FoundProject> = new AbsoluteFilePathMap();
-
-function addProject(
- projectFolder: AbsoluteFilePath,
- configPath: AbsoluteFilePath,
-) {
- const {config, meta} = loadCompleteProjectConfig(projectFolder, configPath);
-
- const project: FoundProject = {
- watchers: new AbsoluteFilePathMap(),
- config,
- meta,
- definition: {
- config,
- folder: projectFolder,
- },
- };
-
- foundProjects.set(projectFolder, project);
-
- watchEvict(project, meta.configDependencies);
-}
-
-function watchEvict(project: FoundProject, deps: AbsoluteFilePathSet) {
- for (const cachePath of deps) {
- if (project.watchers.has(cachePath)) {
- continue;
- }
-
- const watcher = fs.watch(
- cachePath.join(),
- () => {
- evictProject(project);
- },
- );
- project.watchers.set(cachePath, watcher);
- }
-}
-
-function evictProject(evictProject: FoundProject) {
- for (const watcher of evictProject.watchers.values()) {
- watcher.close();
- }
-
- for (const [path, project] of foundProjects) {
- if (project === evictProject) {
- foundProjects.delete(path);
- }
- }
-}
-
-export async function findProject(path: AbsoluteFilePath): Promise<FoundProject> {
- const tried: Array<AbsoluteFilePath> = [];
-
- for (const segment of path.getChain()) {
- // Check if we've already found a project for this
- const cached = foundProjects.get(segment);
- if (cached !== undefined) {
- // Set paths that we've already visited
- for (const segment of tried) {
- foundProjects.set(segment, cached);
- }
-
- // Invalidate cache entries when files that are deeper than the project we found could create a new project target
- watchEvict(cached, getParentConfigDependencies(segment.getParent()));
-
- return cached;
- }
-
- // Check for possible configs
- for (const configFilename of ROME_CONFIG_FILENAMES) {
- const possibleConfigPath = segment.append(configFilename);
- if (await exists(possibleConfigPath)) {
- addProject(segment, possibleConfigPath);
-
- // Get the definition again. This time hitting the cached value and then setting all ancestors.
- return findProject(path);
- }
- }
-
- // Check for package.json
- const packagePath = segment.append('package.json');
- if (await exists(packagePath)) {
- const input = await readFileText(packagePath);
- const json = await consumeJSON({input, path: packagePath});
- if (json.has(ROME_CONFIG_PACKAGE_JSON_FIELD)) {
- addProject(segment, packagePath);
- return findProject(path);
- }
- }
- }
-
- throw new Error(`No project found for ${path.join()}`);
-}

Empty rome package