Skip to content

Commit 65cff19

Browse files
authored
Merge branch 'main' into main
2 parents 2fbaa30 + 591422b commit 65cff19

File tree

11 files changed

+362
-181
lines changed

11 files changed

+362
-181
lines changed

.changeset/soft-glasses-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli": patch
3+
---
4+
5+
Added whoami command, fixed TypeScript error

apps/webapp/app/entry.server.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function serveTheBots(
7474
{
7575
// Use onAllReady to wait for the entire document to be ready
7676
onAllReady() {
77-
responseHeaders.set("Content-Type", "text/html");
77+
responseHeaders.set("Content-Type", "text/html; charset=utf-8");
7878
let body = new PassThrough();
7979
pipe(body);
8080
resolve(
@@ -114,7 +114,7 @@ function serveBrowsers(
114114
// use onShellReady to wait until a suspense boundary is triggered
115115
onShellReady() {
116116
shellReady = true;
117-
responseHeaders.set("Content-Type", "text/html");
117+
responseHeaders.set("Content-Type", "text/html; charset=utf-8");
118118
let body = new PassThrough();
119119
pipe(body);
120120
resolve(

apps/webapp/app/utils.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@ export function useMatchesData(
4545
const paths = Array.isArray(id) ? id : [id];
4646

4747
// Get the first matching route
48-
const route = paths.reduce(
49-
(acc, path) => {
50-
if (acc) return acc;
51-
return matchingRoutes.find((route) => route.id === path);
52-
},
53-
undefined as RouteMatch | undefined
54-
);
48+
const route = paths.reduce((acc, path) => {
49+
if (acc) return acc;
50+
return matchingRoutes.find((route) => route.id === path);
51+
}, undefined as RouteMatch | undefined);
5552

5653
return route;
5754
}
@@ -76,7 +73,7 @@ export function hydrateDates(object: any): any {
7673
if (
7774
typeof object === "string" &&
7875
object.match(/\d{4}-\d{2}-\d{2}/) &&
79-
!isNaN(Date.parse(object))
76+
!Number.isNaN(Date.parse(object))
8077
) {
8178
return new Date(object);
8279
}

examples/nextjs-12/jsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"compilerOptions": {}
3+
}

examples/nextjs-12/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818
"devDependencies": {
1919
"eslint": "8.44.0",
20-
"eslint-config-next": "12.3.4"
20+
"eslint-config-next": "12.3.4",
21+
"@trigger.dev/cli": "workspace:*"
2122
},
2223
"trigger.dev": {
2324
"endpointId": "nextjs-12"

packages/cli/src/cli/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import inquirer from "inquirer";
33
import pathModule from "node:path";
44
import { createIntegrationCommand } from "../commands/createIntegration";
55
import { devCommand } from "../commands/dev";
6+
import { whoamiCommand } from "../commands/whoami.js";
67
import { initCommand } from "../commands/init";
78
import { CLOUD_TRIGGER_URL, COMMAND_NAME } from "../consts";
89
import { telemetryClient } from "../telemetry/telemetry";
@@ -87,6 +88,21 @@ program
8788
await updateCommand(path);
8889
});
8990

91+
program
92+
.command("whoami")
93+
.description("display the current logged in user and project details")
94+
.argument("[path]", "The path to the project", ".")
95+
.option("-p, --port <port>", "The local port your server is on", "3000")
96+
.option("-e, --env-file <name>", "The name of the env file to load", ".env.local")
97+
.version(getVersion(), "-v, --version", "Display the version number")
98+
.action(async (path, options) => {
99+
try {
100+
await whoamiCommand(path, options);
101+
} catch (e) {
102+
throw e;
103+
}
104+
});
105+
90106
export const promptTriggerUrl = async (): Promise<string> => {
91107
const { instanceType } = await inquirer.prompt<{
92108
instanceType: "cloud" | "self-hosted";

packages/cli/src/commands/dev.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export async function devCommand(path: string, anyOptions: any) {
206206
throttle(refresh, throttleTimeMs);
207207
}
208208

209-
async function getEndpointIdFromPackageJson(path: string, options: DevCommandOptions) {
209+
export async function getEndpointIdFromPackageJson(path: string, options: DevCommandOptions) {
210210
if (options.clientId) {
211211
return options.clientId;
212212
}
@@ -221,7 +221,7 @@ async function getEndpointIdFromPackageJson(path: string, options: DevCommandOpt
221221
return value as string;
222222
}
223223

224-
async function readEnvFilesWithBackups(
224+
export async function readEnvFilesWithBackups(
225225
path: string,
226226
envFile: string,
227227
backups: string[]
@@ -249,7 +249,7 @@ async function readEnvFilesWithBackups(
249249
return;
250250
}
251251

252-
async function getTriggerApiDetails(path: string, envFile: string) {
252+
export async function getTriggerApiDetails(path: string, envFile: string) {
253253
const resolvedEnvFile = await readEnvFilesWithBackups(path, envFile, [
254254
".env",
255255
".env.local",

packages/cli/src/commands/whoami.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { z } from "zod";
2+
import { logger } from "../utils/logger";
3+
import { resolvePath } from "../utils/parseNameAndPath";
4+
import { TriggerApi } from "../utils/triggerApi";
5+
import { DevCommandOptions, getEndpointIdFromPackageJson, getTriggerApiDetails } from "./dev";
6+
import ora from "ora";
7+
8+
export const WhoAmICommandOptionsSchema = z.object({
9+
envFile: z.string(),
10+
});
11+
12+
export type WhoAmICommandOptions = z.infer<typeof WhoAmICommandOptionsSchema>;
13+
14+
export async function whoamiCommand(path: string, anyOptions: any) {
15+
const loadingSpinner = ora(`Hold while we fetch your data`);
16+
loadingSpinner.start();
17+
18+
const result = WhoAmICommandOptionsSchema.safeParse(anyOptions);
19+
if (!result.success) {
20+
logger.error(result.error.message);
21+
return;
22+
}
23+
const options = result.data;
24+
25+
const resolvedPath = resolvePath(path);
26+
27+
// Read from package.json to get the endpointId
28+
const endpointId = await getEndpointIdFromPackageJson(resolvedPath, options as DevCommandOptions);
29+
if (!endpointId) {
30+
logger.error(
31+
"You must run the `init` command first to setup the project – you are missing \n'trigger.dev': { 'endpointId': 'your-client-id' } from your package.json file, or pass in the --client-id option to this command"
32+
);
33+
loadingSpinner.stop();
34+
return;
35+
}
36+
// Read from .env.local or .env to get the TRIGGER_API_KEY and TRIGGER_API_URL
37+
const apiDetails = await getTriggerApiDetails(resolvedPath, options.envFile);
38+
39+
if (!apiDetails) {
40+
return;
41+
}
42+
43+
const triggerAPI = new TriggerApi(apiDetails.apiKey, apiDetails.apiUrl);
44+
const userData = await triggerAPI.whoami(apiDetails.apiKey);
45+
46+
loadingSpinner.stop();
47+
48+
logger.info(`
49+
environment: ${userData?.type}
50+
Trigger Client Id: ${endpointId}
51+
User ID: ${userData?.userId}
52+
Project:
53+
id: ${userData?.project.id}
54+
slug: ${userData?.project.slug}
55+
name: ${userData?.project.name}
56+
Organization:
57+
id: ${userData?.organization.id}
58+
slug: ${userData?.organization.slug}
59+
title: ${userData?.organization.title}
60+
`);
61+
process.exit(1);
62+
}

packages/cli/src/utils/fileSystem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export async function removeFile(path: string) {
2525
}
2626

2727
export async function readFile(path: string) {
28-
return await fsModule.readFile(path, "utf-8");
28+
return await fsModule.readFile(path, "utf8");
2929
}
3030

3131
export async function readJSONFile(path: string) {
32-
const fileContents = await fsModule.readFile(path, "utf-8");
32+
const fileContents = await fsModule.readFile(path, "utf8");
3333

3434
return JSON.parse(fileContents);
3535
}
@@ -39,7 +39,7 @@ export async function writeJSONFile(path: string, json: any) {
3939
}
4040

4141
export function readJSONFileSync(path: string) {
42-
const fileContents = fsSync.readFileSync(path, "utf-8");
42+
const fileContents = fsSync.readFileSync(path, "utf8");
4343

4444
return JSON.parse(fileContents);
4545
}

packages/cli/tsconfig.json

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
11
{
2-
"extends": "@trigger.dev/tsconfig/node18.json",
32
"include": ["src/globals.d.ts", "./src/**/*.ts", "tsup.config.ts", "./test/**/*.ts"],
43
"compilerOptions": {
4+
/* LANGUAGE COMPILATION OPTIONS */
5+
"target": "ES2020",
6+
"lib": ["DOM", "DOM.Iterable", "ES2020"],
7+
"module": "ESNext",
8+
"moduleResolution": "node",
9+
"resolveJsonModule": true,
10+
"allowJs": true,
11+
"checkJs": true,
12+
13+
/* EMIT RULES */
14+
"outDir": "./dist",
15+
"noEmit": true, // TSUP takes care of emitting js for us, in a MUCH faster way
16+
"declaration": true,
17+
"declarationMap": true,
18+
"sourceMap": true,
19+
"removeComments": true,
20+
21+
/* TYPE CHECKING RULES */
22+
"strict": true,
23+
// "noImplicitAny": true, // Included in "Strict"
24+
// "noImplicitThis": true, // Included in "Strict"
25+
// "strictBindCallApply": true, // Included in "Strict"
26+
// "strictFunctionTypes": true, // Included in "Strict"
27+
// "strictNullChecks": true, // Included in "Strict"
28+
// "strictPropertyInitialization": true, // Included in "Strict"
29+
"noFallthroughCasesInSwitch": true,
30+
"noImplicitOverride": true,
31+
"noImplicitReturns": true,
32+
"noUnusedLocals": false,
33+
"noUnusedParameters": false,
34+
"useUnknownInCatchVariables": true,
35+
"noUncheckedIndexedAccess": true, // TLDR - Checking an indexed value (array[0]) now forces type <T | undefined> as there is no confirmation that index exists
36+
// THE BELOW ARE EXTRA STRICT OPTIONS THAT SHOULD ONLY BY CONSIDERED IN VERY SAFE PROJECTS
37+
// "exactOptionalPropertyTypes": true, // TLDR - Setting to undefined is not the same as a property not being defined at all
38+
// "noPropertyAccessFromIndexSignature": true, // TLDR - Use dot notation for objects if youre sure it exists, use ['index'] notaion if unsure
39+
40+
/* OTHER OPTIONS */
41+
"allowSyntheticDefaultImports": true,
42+
"esModuleInterop": true,
43+
// "emitDecoratorMetadata": true,
44+
// "experimentalDecorators": true,
45+
"forceConsistentCasingInFileNames": true,
46+
"skipLibCheck": true,
47+
"useDefineForClassFields": true,
548
"experimentalDecorators": true,
649
"emitDecoratorMetadata": true,
7-
"declaration": false,
8-
"declarationMap": false,
950
"types": ["jest"]
1051
},
1152
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)