-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): updated build command to typecheck fewer files (#602)
- Loading branch information
Showing
11 changed files
with
109 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"pluv": patch | ||
--- | ||
|
||
Updated the pluv cli's `build` command so that only the pluv entry file and all necessary dependencies are type-checked, instead of all TypeScript files in the project workspace. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { z } from "zod"; | ||
|
||
export const ZodPluvConfig = z.object({ | ||
env: z | ||
.intersection(z.record(z.string(), z.string()), z.string()) | ||
.optional(), | ||
env: z.record(z.string(), z.string()).optional(), | ||
input: z.string().default("./pluv.ts"), | ||
outDir: z.string().default("./.pluv"), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { buildApp } from "./buildApp.js"; | ||
export type { BuildAppOptions } from "./buildApp.js"; |
68 changes: 68 additions & 0 deletions
68
packages/cli/src/utils/buildApp/resolveDependenciesTransformer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ProgramTransformerFactory } from "@rollup/plugin-typescript"; | ||
import path from "node:path"; | ||
import type { SourceFile, TransformerFactory } from "typescript"; | ||
import ts from "typescript"; | ||
|
||
const resolveDependencies = (entryFilePath: string): string[] => { | ||
const dependencies = new Set<string>(); | ||
const visited = new Set<string>(); | ||
|
||
const visit = (filePath: string) => { | ||
if (visited.has(filePath)) return; | ||
|
||
visited.add(filePath); | ||
|
||
const sourceText = ts.sys.readFile(filePath); | ||
|
||
if (!sourceText) return; | ||
|
||
let sourceFile: SourceFile = ts.createSourceFile( | ||
filePath, | ||
sourceText, | ||
ts.ScriptTarget.ESNext, | ||
true, | ||
); | ||
|
||
if (!sourceFile) return; | ||
|
||
ts.forEachChild(sourceFile, (node) => { | ||
if (!ts.isImportDeclaration(node)) return; | ||
|
||
const importPath = node.moduleSpecifier.getText(); | ||
const absolutePath = path.resolve( | ||
path.dirname(filePath), | ||
importPath, | ||
); | ||
|
||
dependencies.add(importPath); | ||
|
||
visit(absolutePath); | ||
}); | ||
}; | ||
|
||
visit(entryFilePath); | ||
|
||
return Array.from(dependencies.values()); | ||
}; | ||
|
||
export const resolveDependenciesTransformer: ProgramTransformerFactory<"before"> = | ||
{ | ||
type: "program", | ||
factory: (program): TransformerFactory<ts.SourceFile> => { | ||
return (context) => { | ||
return (node) => { | ||
const dependencies = resolveDependencies(node.fileName); | ||
|
||
dependencies.forEach((dependency) => { | ||
const sourceFile = program.getSourceFile(dependency); | ||
|
||
try { | ||
program.emit(sourceFile); | ||
} catch {} | ||
}); | ||
|
||
return node; | ||
}; | ||
}; | ||
}, | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export * from "./config.js"; | ||
export { buildApp } from "./buildApp/index.js"; | ||
export type { BuildAppOptions } from "./buildApp/index.js"; | ||
export { getConfig } from "./getConfig.js"; | ||
export type { ParsedPluvConfig, PluvConfig } from "./getConfig.js"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.