Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows generation through vscode always outputting to the root workspace directory if the path was ../ #1247

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions engine/baml-schema-wasm/src/runtime_wasm/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub struct WasmGeneratorOutput {
#[wasm_bindgen(readonly)]
pub output_dir: String,
#[wasm_bindgen(readonly)]
pub output_dir_relative_to_baml_src: String,
#[wasm_bindgen(readonly)]
pub files: Vec<WasmGeneratedFile>,
}

Expand All @@ -22,6 +24,10 @@ impl Into<WasmGeneratorOutput> for GenerateOutput {
fn into(self) -> WasmGeneratorOutput {
WasmGeneratorOutput {
output_dir: self.output_dir_full.to_string_lossy().to_string(),
output_dir_relative_to_baml_src: self
.output_dir_shorthand
.to_string_lossy()
.to_string(),
files: self
.files
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ sugar_path = "1.2.0"
walkdir.workspace = true
semver = "1.0.23"
colored = "2.1.0"
itertools = "0.13.0"
itertools = "0.13.0"
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ class Project {
// Creating the tmpdir next to the output dir can cause some weird issues with vscode, if we recover
// from an error and delete the tmpdir - vscode's explorer UI will still show baml_client.tmp even
// though it doesn't exist anymore, and vscode has no good way of letting the user purge it from the UI
console.log(`outputdir ${g.output_dir}`)
console.log(`relative output dir ${g.output_dir_relative_to_baml_src}`)

const out_dir = path.join(this.rootPath(), g.output_dir_relative_to_baml_src)

const tmpDir = path.join(path.dirname(g.output_dir), path.basename(g.output_dir) + '.tmp')
const backupDir = path.join(path.dirname(g.output_dir), path.basename(g.output_dir) + '.bak')

Expand All @@ -386,8 +391,8 @@ class Project {
if (existsSync(backupDir)) {
await rm(backupDir, { recursive: true, force: true })
}
if (existsSync(g.output_dir)) {
const contents = await readdir(g.output_dir, { withFileTypes: true })
if (existsSync(out_dir)) {
const contents = await readdir(out_dir, { withFileTypes: true })
const contentsWithSafeToRemove = await Promise.all(
contents.map(async (c) => {
if (c.isDirectory()) {
Expand All @@ -414,15 +419,16 @@ class Project {
`Output dir ${g.output_dir} contains this file(s) not generated by BAML: ${notSafeToRemove.join(', ')}`,
)
}
await rename(g.output_dir, backupDir)
await rename(out_dir, backupDir)
}
await rename(tmpDir, g.output_dir)
await rename(tmpDir, out_dir)

try {
// some filewatchers don't trigger unless the file is touched. Creating the new dir alone doesn't work.
// if we remove this, TS will still have the old types, and nextjs will not hot-reload.
g.files.map((f) => {
const fpath = path.join(g.output_dir, f.path_in_output_dir)
const fpath = path.join(out_dir, f.path_in_output_dir)
console.log(`fpath ${fpath}`)
const currentTime = new Date()
const newTime = new Date(currentTime.getTime() + 100)
utimes(fpath, newTime, newTime, (err) => {
Expand Down
Loading