Skip to content

Commit

Permalink
Merge branch 'main' into mischnic/pack-3107-self-reference-unpublished
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored Jul 29, 2024
2 parents 016c674 + aeecec6 commit a591902
Show file tree
Hide file tree
Showing 90 changed files with 8,791 additions and 33 deletions.
9 changes: 8 additions & 1 deletion crates/turbopack-ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,14 @@ async fn gen_content_with_visitors(
for visitor in root_visitors {
program.visit_mut_with(&mut visitor.create());
}
program.visit_mut_with(&mut swc_core::ecma::transforms::base::hygiene::hygiene());
program.visit_mut_with(
&mut swc_core::ecma::transforms::base::hygiene::hygiene_with_config(
swc_core::ecma::transforms::base::hygiene::Config {
top_level_mark: eval_context.top_level_mark,
..Default::default()
},
),
);
program.visit_mut_with(&mut swc_core::ecma::transforms::base::fixer::fixer(None));

// we need to remove any shebang before bundling as it's only valid as the first
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module; // <- This is important!

it("should not rename variables when eval is used", () => {
const modules = {
x: (module) => {
"use strict";
return eval("module");
},
};
const moduleArrowFunction = (module) => {
"use strict";
return eval("module");
};
function moduleFunciton(module) {
"use strict";
return eval("module");
}
expect(modules.x(42)).toBe(42);
expect(moduleArrowFunction(42)).toBe(42);
expect(moduleFunciton(42)).toBe(42);
});
4 changes: 3 additions & 1 deletion crates/turborepo-auth/src/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
pub use error::Error;
use reqwest::Url;
use tokio::sync::OnceCell;
use tracing::warn;
use tracing::{debug, warn};
use turborepo_api_client::{CacheClient, Client, TokenClient};
use turborepo_ui::{start_spinner, BOLD, UI};

Expand Down Expand Up @@ -49,6 +49,7 @@ pub async fn login<T: Client + TokenClient + CacheClient>(
// Check if passed in token exists first.
if !force {
if let Some(token) = existing_token {
debug!("found existing turbo token");
let token = Token::existing(token.into());
if token
.is_valid(
Expand All @@ -64,6 +65,7 @@ pub async fn login<T: Client + TokenClient + CacheClient>(
// The extraction can return an error, but we don't want to fail the login if
// the token is not found.
if let Ok(Some(token)) = extract_vercel_token() {
debug!("found existing Vercel token");
let token = Token::existing(token);
if token
.is_valid(
Expand Down
6 changes: 6 additions & 0 deletions crates/turborepo-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ impl Token {
turborepo_api_client::Error::UnknownStatus { code, .. } if code == "forbidden" => {
Ok(false)
}
// If the entire request fails with 403 also return false
turborepo_api_client::Error::ReqwestError(e)
if e.status() == Some(reqwest::StatusCode::FORBIDDEN) =>
{
Ok(false)
}
_ => Err(e.into()),
},
}
Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,6 @@ pub async fn run(
}

run_args.track(&event);
event.track_run_code_path(CodePath::Rust);
let exit_code = run::run(base, event).await.inspect(|code| {
if *code != 0 {
error!("run failed: command exited ({code})");
Expand Down
13 changes: 0 additions & 13 deletions crates/turborepo-telemetry/src/events/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,6 @@ impl CommandEventBuilder {
self
}

// run
pub fn track_run_code_path(&self, path: CodePath) -> &Self {
self.track(Event {
key: "binary".to_string(),
value: match path {
CodePath::Go => "go".to_string(),
CodePath::Rust => "rust".to_string(),
},
is_sensitive: EventType::NonSensitive,
});
self
}

// login
pub fn track_login_method(&self, method: LoginMethod) -> &Self {
self.track(Event {
Expand Down
38 changes: 38 additions & 0 deletions examples/with-typeorm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Dependencies
node_modules
.pnp
.pnp.js

# Local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Testing
coverage

# Turbo
.turbo

# Vercel
.vercel

# Build Outputs
.next/
out/
build
dist


# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Misc
.DS_Store
*.pem
Empty file added examples/with-typeorm/.npmrc
Empty file.
106 changes: 106 additions & 0 deletions examples/with-typeorm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Turborepo with TypeORM

This is an official starter Turborepo configured with TypeORM to manage the service layer in a monorepo setup.

## What's inside?

This Turborepo includes the following packages/apps:

### Apps and Packages

- `docs`: a [Next.js](https://nextjs.org/) app
- `web`: another [Next.js](https://nextjs.org/) app
- `ui`: a stub React component library shared by both `web` and `docs` applications
- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo
- `@repo/typeorm-service`: contains the service layer with TypeORM integration to manage database entities and transactions. It utilizes **dependency injection** to provide services across different applications.

## Dependency Injection

The @repo/typeorm-service package demonstrates a sophisticated setup where services are defined using TypeORM repositories and injected into Next.js apps using a custom dependency injection mechanism. This approach emphasizes a clear separation of concerns and a modular architecture.

```typescript
// root/packages/typeorm-service/domain/todo/todo.repository.ts
@Repository
export class TodoRepository {...}

// root/packages/typeorm-service/domain/todo/todo.service.ts
@InjectAble
export class TodoService {
constructor(private todoRepo: TodoRepository) {}
...
}
```

## Example Usage of the Service Layer

This example demonstrates how to use the typeorm-service package to inject and use services within a Next.js app. The TodoService is injected into both page.tsx and API routes.

```typescript
// root/apps/docs/app/page.tsx
import { inject, TodoService } from "@repo/typeorm-service";

export default async function Page(): Promise<JSX.Element> {
const todoService = inject(TodoService);

const todoList = await todoService.findAll();

return ...
}
```

In the API route file, TodoService is injected to handle GET and POST requests. The GET request returns the list of todos, while the POST request adds a new todo.

```typescript
// root/apps/web/app/api/todo/route.ts

import { inject, type Todo, TodoService } from "@repo/typeorm-service";

const todoService = inject(TodoService);

export async function GET() {
const list = await todoService.findAll();

return Response.json(list);
}

export async function POST(req: Request) {
const res: Pick<Todo, "content"> = await req.json();

const entity = await todoService.add(res.content);

return Response.json(entity);
}
```

## Configuring the Database

For managing the database settings such as the database type, username, password, and other configurations, refer to the orm-config.ts file located in the packages/typeorm-service/src directory. This file centralizes all database connection settings to ensure secure and efficient database management. Make sure to review and adjust these settings according to your environment to ensure optimal performance and security.

```typescript
// packages/typeorm-service/src/orm-config.ts
import { DataSource } from "typeorm";

export const AppDataSource = new DataSource({
type: "mysql", // or your database type
host: "localhost",
port: 3306,
username: "your_username",
password: "your_password",
database: "your_database_name",
synchronize: true,
logging: false,
entities: [...],
migrations: [...],
});

```

### Utilities

This Turborepo has some additional tools already setup for you:

- [TypeORM](https://typeorm.io/) for service layer
- [TypeScript](https://www.typescriptlang.org/) for static type checking
- [ESLint](https://eslint.org/) for code linting
- [Prettier](https://prettier.io) for code formatting
9 changes: 9 additions & 0 deletions examples/with-typeorm/apps/docs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["@repo/eslint-config/next.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
};
28 changes: 28 additions & 0 deletions examples/with-typeorm/apps/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Getting Started

First, run the development server:

```bash
yarn dev
```

Open [http://localhost:3001](http://localhost:3001) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

To create [API routes](https://nextjs.org/docs/app/building-your-application/routing/router-handlers) add an `api/` directory to the `app/` directory with a `route.ts` file. For individual endpoints, create a subfolder in the `api` directory, like `api/hello/route.ts` would map to [http://localhost:3001/api/hello](http://localhost:3001/api/hello).

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn/foundations/about-nextjs) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_source=github.com&utm_medium=referral&utm_campaign=turborepo-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Binary file added examples/with-typeorm/apps/docs/app/favicon.ico
Binary file not shown.
50 changes: 50 additions & 0 deletions examples/with-typeorm/apps/docs/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
:root {
--max-width: 1100px;
--border-radius: 12px;
--font-mono: ui-monospace, Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono",
"Roboto Mono", "Oxygen Mono", "Ubuntu Monospace", "Source Code Pro",
"Fira Mono", "Droid Sans Mono", "Courier New", monospace;

--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;

--callout-rgb: 20, 20, 20;
--callout-border-rgb: 108, 108, 108;
--card-rgb: 100, 100, 100;
--card-border-rgb: 200, 200, 200;

--glow-conic: conic-gradient(
from 180deg at 50% 50%,
#2a8af6 0deg,
#a853ba 180deg,
#e92a67 360deg
);
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

a {
color: inherit;
text-decoration: none;
}
22 changes: 22 additions & 0 deletions examples/with-typeorm/apps/docs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import "./globals.css";
import type { Metadata } from "next";
import { Inter } from "next/font/google";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Create Turborepo",
description: "Generated by create turbo",
};

export default function RootLayout({
children,
}: {
children: React.ReactNode;
}): JSX.Element {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
Loading

0 comments on commit a591902

Please sign in to comment.