diff --git a/.gitignore b/.gitignore index 68dedb8..4b6ced3 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,6 @@ yarn-error.log* .env .vercel + +# BaseHub .basehub \ No newline at end of file diff --git a/packages/basehub/CHANGELOG.md b/packages/basehub/CHANGELOG.md index 0f91398..7b97552 100644 --- a/packages/basehub/CHANGELOG.md +++ b/packages/basehub/CHANGELOG.md @@ -1,5 +1,43 @@ # basehub +## 5.0.0 + +### Major Changes + +- 335ae9a: + + ## Context + + Before this version, the default output path of the generated code `basehub` yielded was within the basehub node_module itself. This allowed a great starting point, as developers could instantly `import { basehub } from 'basehub'` and it would just work. + + But, generating the SDK and placing it in `node_modules` was problematic, because the TS server is generally not watching `node_modules`. Because of this, users were required to "Restart TS Server" every time they run the SDK generator. Although this is not a big deal once you get accustomed to it, it's very problematic for folks that don't know about this trick, and about the reason of why this doesn't work. So, in other words, this was shit. + + Because of this, we introduced the `--output` arg. With this argument, the developer could specify a custom output. One that their TS server would watch and therefore would know about when it changed. This worked great. + + After we introduced and started using `--watch`, the path forward became clear: it was preferrable to run `basehub --output .basehub` by default rather than start fast but then need to transition into a custom output because the default flow just wouldn't scale well. + + ## Breaking Change + + So this version introduces a single, potentially breaking, change: we now output to `.basehub` by default. This means, if you have a regular Next.js App, you'll now see a `.basehub` directory next to your `.next`, `node_modules`, etc. + + ### Will I need to change all my imports? + + No. This release includes a clever (hacky, maybe) trick: when you run `basehub`, we'll automatically alias the package that's stored in `node_modules` to target the new output path, and so the `import {} from 'basehub'` should work out of the box. + + ### Does .basehub need to be .gitignored? + + Yes. And we'll try to automatically do that for you if we find your .gitignore file. + + *** + + Please let us know if you encounter any issues. + +## 5.0.0-canary.0 + +### Major Changes + +- Default to outputting stuff into .basehub and aliasing basehub to it. + ## 4.0.17 ### Patch Changes diff --git a/packages/basehub/package.json b/packages/basehub/package.json index 66cada2..479f49c 100644 --- a/packages/basehub/package.json +++ b/packages/basehub/package.json @@ -2,7 +2,7 @@ "name": "basehub", "description": "The first AI-native content hub.", "author": "JB ", - "version": "4.0.17", + "version": "5.0.0", "license": "MIT", "repository": "basehub-ai/basehub", "bugs": "https://github.com/basehub-ai/basehub/issues", diff --git a/packages/basehub/src/bin/main.ts b/packages/basehub/src/bin/main.ts index 58518fc..1ca33ea 100644 --- a/packages/basehub/src/bin/main.ts +++ b/packages/basehub/src/bin/main.ts @@ -37,10 +37,18 @@ export const main = async ( ); } - const pathArgs = output - ? [output] - : ["node_modules", "basehub", "dist", "generated-client"]; // default output path - const isCustomOutput = !!output; + let shouldAppendToGitIgnore = ""; + let pathArgs: string[] = []; + if (output === "node_modules") { + // old default + pathArgs = ["node_modules", "basehub", "dist", "generated-client"]; + } else if (output) { + pathArgs = [output]; + } else { + // default + pathArgs = [".basehub"]; + shouldAppendToGitIgnore = ".basehub"; + } const basehubOutputPath = path.resolve(process.cwd(), ...pathArgs); @@ -188,7 +196,7 @@ export const main = async ( appendGeneratedCodeBanner(basehubOutputPath, args["--banner"]); - if (isCustomOutput) { + if (output !== "node_modules") { // alias react-rich-text and other packages to the generated client for better import experience ["react-rich-text", "api-transaction", "react-search"].map( (pathsToAlias) => { @@ -203,6 +211,79 @@ export const main = async ( ); } ); + + // override index.js and index.d.ts to point to the generated client + const indexJsPath = path.join(basehubModulePath, "index.js"); + const indexDtsPath = path.join(basehubModulePath, "index.d.ts"); + const reactPumpIndexJsPath = path.join( + basehubModulePath, + "react-pump.js" + ); + const reactPumpIndexDtsPath = path.join( + basehubModulePath, + "react-pump.d.ts" + ); + fs.writeFileSync( + indexJsPath, + `module.exports = require("${path.relative( + basehubModulePath, + generatedMainExportPath + )}");` + ); + fs.writeFileSync( + indexDtsPath, + `export * from "${path.relative( + basehubModulePath, + generatedMainExportPath + )}";` + ); + fs.writeFileSync( + reactPumpIndexJsPath, + `module.exports = require("${path.relative( + basehubModulePath, + path.join(reactPumpOutDir, "index.js") + )}");` + ); + fs.writeFileSync( + reactPumpIndexDtsPath, + `export * from "${path.relative( + basehubModulePath, + path.join(reactPumpOutDir, "index.d.ts") + )}";` + ); + } + + if (shouldAppendToGitIgnore) { + function findClosestGitignore(startDir: string) { + let currentDir = startDir; + let gitignorePath = null; + + while (currentDir !== "/") { + const potentialGitignore = path.join(currentDir, ".gitignore"); + if (fs.existsSync(potentialGitignore)) { + gitignorePath = potentialGitignore; + break; + } + currentDir = path.dirname(currentDir); + } + + return gitignorePath; + } + + const gitIgnorePath = findClosestGitignore(process.cwd()); + if (gitIgnorePath && fs.existsSync(gitIgnorePath)) { + const gitIgnoreContents = fs.readFileSync(gitIgnorePath, "utf-8"); + if (!gitIgnoreContents.includes(shouldAppendToGitIgnore)) { + fs.appendFileSync( + gitIgnorePath, + `\n\n# BaseHub\n${shouldAppendToGitIgnore}` + ); + logIfNotSilent( + silent, + `🤫 Added "${shouldAppendToGitIgnore}" .gitignore` + ); + } + } } logIfNotSilent(silent, "🪄 Generated `basehub` client"); diff --git a/playground/CHANGELOG.md b/playground/CHANGELOG.md index 2cb96e6..2ebacf4 100644 --- a/playground/CHANGELOG.md +++ b/playground/CHANGELOG.md @@ -1,5 +1,19 @@ # playground +## 0.0.88 + +### Patch Changes + +- Updated dependencies [335ae9a] + - basehub@5.0.0 + +## 0.0.88-canary.0 + +### Patch Changes + +- Updated dependencies + - basehub@5.0.0-canary.0 + ## 0.0.87 ### Patch Changes diff --git a/playground/package.json b/playground/package.json index fb756fb..fbedb84 100644 --- a/playground/package.json +++ b/playground/package.json @@ -1,10 +1,10 @@ { "name": "playground", "private": true, - "version": "0.0.87", + "version": "0.0.88", "scripts": { "dev": "basehub dev & next dev", - "build": "next build", + "build": "basehub & next build", "build:analyze": "cross-env ANALYZE=true pnpm build", "start": "next start", "lint": "next lint", diff --git a/playground/src/app/page.tsx b/playground/src/app/page.tsx index 573090f..3179d74 100644 --- a/playground/src/app/page.tsx +++ b/playground/src/app/page.tsx @@ -1,6 +1,6 @@ import { Search } from "./search"; -export default function HomePage() { +export default async function HomePage() { return (