Skip to content

Commit

Permalink
share json between TypeScript and Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitropoulos committed Sep 5, 2024
1 parent a50e603 commit 7cdc458
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"type": "shell",
"label": "prepare turbo",
"command": "cargo build -p turbo"
"command": "cargo build --package turbo"
}
]
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Dependencies

Building

- Building `turbo` CLI: `cargo build -p turbo`
- Building `turbo` CLI: `cargo build --package turbo`
- Using `turbo` to build `turbo` CLI: `./turbow.js`

### TLS Implementation
Expand Down
6 changes: 3 additions & 3 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"private": true,
"version": "0.0.0",
"scripts": {
"clean": "cargo clean -p turbo",
"build": "cargo build -p turbo",
"build:release": "cargo build -p turbo --profile release-turborepo"
"clean": "cargo clean --package turbo",
"build": "cargo build --package turbo",
"build:release": "cargo build --package turbo --profile release-turborepo"
}
}
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ impl Framework {

static FRAMEWORKS: OnceLock<Vec<Framework>> = OnceLock::new();

const FRAMEWORKS_JSON: &str = include_str!("frameworks.json");
const FRAMEWORKS_JSON: &str =
include_str!("../../../packages/turbo-types/src/json/frameworks.json");

fn get_frameworks() -> &'static Vec<Framework> {
FRAMEWORKS.get_or_init(|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Learn how to handle environments for your applications.
import { Callout } from '#/components/callout';
import { Tabs, Tab } from '#/components/tabs';
import { Accordion, Accordions } from '#/components/accordion';
import frameworks from '../../../crates/turborepo-lib/src/frameworks.json';
import { metadata } from 'eslint-plugin-turbo';

Environment variable inputs are a vital part of your applications that you'll need to account for in your Turborepo configuration.

Expand Down Expand Up @@ -67,7 +67,7 @@ Turborepo automatically adds prefix wildcards to your [`env`](/repo/docs/referen
</tr>
</thead>
<tbody>
{frameworks.map(({ name, envWildcards }) => (
{metadata.frameworks.map(({ name, envWildcards }) => (
<tr key={name}>
<td>{name}</td>
<td>{envWildcards.map((w) => <code>{w}</code>).join(', ')}</td>
Expand Down
2 changes: 0 additions & 2 deletions packages/eslint-plugin-turbo/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { RULES } from "./constants";
// rules
import noUndeclaredEnvVars from "./rules/no-undeclared-env-vars";
// configs
import recommended from "./configs/recommended";

const rules = {
Expand Down
16 changes: 1 addition & 15 deletions packages/eslint-plugin-turbo/lib/rules/no-undeclared-env-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync, readFileSync } from "node:fs";
import type { Rule } from "eslint";
import type { Node, MemberExpression } from "estree";
import { logger } from "@turbo/utils";
import { frameworks } from "@turbo/types";
import { RULES } from "../constants";
import { Project, getWorkspaceFromFilePath } from "../utils/calculate-inputs";

Expand All @@ -14,15 +15,6 @@ const debug = debugging
/* noop */
};

interface Framework {
slug: string;
envWildcards: Array<string>;
dependencyMatch: {
strategy: "all" | "some";
dependencies: Array<string>;
};
}

export interface RuleContextWithOptions extends Rule.RuleContext {
options: Array<{
cwd?: string;
Expand Down Expand Up @@ -126,12 +118,6 @@ const packageJsonDependencies = (filePath: string): Set<string> => {
.reduce((acc, dependency) => acc.add(dependency), new Set<string>());
};

const frameworksJsonString = readFileSync(
"../../../../crates/turborepo-lib/src/frameworks.json",
"utf-8"
);
const frameworks = JSON.parse(frameworksJsonString) as Array<Framework>;

/**
* Turborepo does some nice framework detection based on the dependencies in the package.json. This function ports that logic to this ESLint rule.
*
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-turbo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"author": "Vercel",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/**"
],
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-turbo/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defineConfig, Options } from "tsup";
import { defineConfig, type Options } from "tsup";

export default defineConfig((options: Options) => ({
entry: ["lib/index.ts"],
clean: true,
minify: true,
dts: true,
...options,
}));
2 changes: 1 addition & 1 deletion packages/turbo-benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
To run benchmarks for turborepo

1. Follow the [Building Turborepo](../CONTRIBUTING.md#building-turborepo) instructions to install dependencies
2. `cargo build -p turbo --profile release-turborepo` to build turbo
2. `cargo build --package turbo --profile release-turborepo` to build turbo
3. From this directory `pnpm run benchmark`
7 changes: 7 additions & 0 deletions packages/turbo-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import type { Framework as FW } from "./types/frameworks";
import frameworksJson from "./json/frameworks.json";

export const frameworks = frameworksJson as Array<Framework>;
export type Framework = FW;
export type { FrameworkStrategy } from "./types/frameworks";

export {
type BaseSchema,
type BaseSchema as BaseSchemaV2,
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions packages/turbo-types/src/types/frameworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type FrameworkStrategy = "all" | "some";

export interface Framework {
slug: string;
name: string;
envWildcards: Array<string>;
dependencyMatch: {
strategy: FrameworkStrategy;
dependencies: Array<string>;
};
}

0 comments on commit 7cdc458

Please sign in to comment.