-
Notifications
You must be signed in to change notification settings - Fork 214
chore(cli): bundle with bun target node and publish from staged dir #2637
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
Open
RomanHotsiy
wants to merge
12
commits into
main
Choose a base branch
from
codex/bun-node-publish-dir
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
84999a0
chore(cli): bundle with bun target node and publish from staged dir
RomanHotsiy d4754ad
style: format publish-dir script
RomanHotsiy 072a87b
fix(docker): install bun before pack preparation
RomanHotsiy 7dcbf5e
fix(cli): fallback to npx bun when bun is unavailable
RomanHotsiy 008c0e0
chore(realm): add bun to the docker
RomanHotsiy 62b8e8d
fix(docker): include docs files in build context
RomanHotsiy d35db98
fix(docker): remove obsolete build-docs template copy
RomanHotsiy 70fefcf
test(smoke): refresh pre-built docs fixture for bundled cli
RomanHotsiy 9515d93
chore: add changeset
RomanHotsiy b902fbf
Apply suggestion from @JLekawa
JLekawa 1b232c3
chore: fixes after review
RomanHotsiy 4077b74
Fix publish cleanup by throwing on non-zero status
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
| '@redocly/cli': patch | ||
| --- | ||
|
|
||
| Improved CLI install speed by bundling the CLI into a dependency-free package. |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,5 +3,7 @@ | |
| !tsconfig.build.json | ||
| !tsconfig.json | ||
| !package-lock.json | ||
| !README.md | ||
| !LICENSE.md | ||
| !packages/* | ||
| !scripts/local-pack.sh | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| import { spawnSync } from 'node:child_process'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const scriptDir = path.dirname(fileURLToPath(import.meta.url)); | ||
| const packageDir = path.resolve(scriptDir, '..'); | ||
| const bunBuildArgs = [ | ||
| 'build', | ||
| 'src/index.ts', | ||
| '--target', | ||
| 'node', | ||
| '--define', | ||
| 'process.env.NODE_ENV=process.env.NODE_ENV', | ||
| '--outfile', | ||
| 'lib/index.js', | ||
| ]; | ||
|
|
||
| export function compileCliBundle() { | ||
| const directBun = spawnSync('bun', bunBuildArgs, { | ||
| cwd: packageDir, | ||
| stdio: 'inherit', | ||
| }); | ||
|
|
||
| if (!directBun.error) { | ||
| return directBun; | ||
| } | ||
|
|
||
| if (directBun.error.code !== 'ENOENT') { | ||
| throw directBun.error; | ||
| } | ||
|
|
||
| console.warn('Bun binary not found on PATH; falling back to `npx bun@1.3.10`.'); | ||
| return spawnSync('npx', ['--yes', 'bun@1.3.10', ...bunBuildArgs], { | ||
tatomyr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cwd: packageDir, | ||
| stdio: 'inherit', | ||
| }); | ||
| } | ||
|
|
||
| if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { | ||
| const compileResult = compileCliBundle(); | ||
|
|
||
| if (compileResult.error) { | ||
| throw compileResult.error; | ||
| } | ||
|
|
||
| if (compileResult.status !== 0) { | ||
| process.exit(compileResult.status ?? 1); | ||
| } | ||
| } | ||
This file contains hidden or 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,64 @@ | ||
| import { copyFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| import { compileCliBundle } from './compile-bundle.mjs'; | ||
|
|
||
| const scriptDir = path.dirname(fileURLToPath(import.meta.url)); | ||
| const packageDir = path.resolve(scriptDir, '..'); | ||
| const rootDir = path.resolve(packageDir, '..', '..'); | ||
|
|
||
| const packageJsonPath = path.join(packageDir, 'package.json'); | ||
| const readmeSourcePath = path.join(rootDir, 'README.md'); | ||
| const licenseSourcePath = path.join(rootDir, 'LICENSE.md'); | ||
| const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); | ||
| const publishDirName = packageJson.publishConfig?.directory ?? '.publish'; | ||
| const publishDir = path.join(packageDir, publishDirName); | ||
|
|
||
| const compileResult = compileCliBundle(); | ||
|
|
||
| if (compileResult.error) { | ||
| throw compileResult.error; | ||
| } | ||
|
|
||
| if (compileResult.status !== 0) { | ||
| process.exit(compileResult.status ?? 1); | ||
| } | ||
|
|
||
| rmSync(publishDir, { recursive: true, force: true }); | ||
| mkdirSync(publishDir, { recursive: true }); | ||
|
|
||
| const binEntrypoint = packageJson.bin?.redocly ?? 'bin/cli.js'; | ||
| const binTargetPath = path.join(publishDir, binEntrypoint); | ||
|
|
||
| mkdirSync(path.dirname(binTargetPath), { recursive: true }); | ||
| mkdirSync(path.join(publishDir, 'lib'), { recursive: true }); | ||
|
|
||
| copyFileSync(path.join(packageDir, binEntrypoint), binTargetPath); | ||
| copyFileSync(path.join(packageDir, 'lib/index.js'), path.join(publishDir, 'lib/index.js')); | ||
| copyFileSync(readmeSourcePath, path.join(publishDir, 'README.md')); | ||
| copyFileSync(licenseSourcePath, path.join(publishDir, 'LICENSE')); | ||
|
|
||
| const publishPackageJson = { | ||
| name: packageJson.name, | ||
| version: packageJson.version, | ||
| description: packageJson.description, | ||
| license: packageJson.license, | ||
| type: packageJson.type, | ||
| repository: packageJson.repository, | ||
| homepage: packageJson.homepage, | ||
| keywords: packageJson.keywords, | ||
| contributors: packageJson.contributors, | ||
| engines: packageJson.engines, | ||
| engineStrict: packageJson.engineStrict, | ||
| bin: { | ||
| redocly: binEntrypoint, | ||
| openapi: binEntrypoint, | ||
| }, | ||
| files: [binEntrypoint, 'lib/index.js', 'README.md', 'LICENSE'], | ||
| }; | ||
|
|
||
| writeFileSync( | ||
| path.join(publishDir, 'package.json'), | ||
| `${JSON.stringify(publishPackageJson, null, 2)}\n` | ||
| ); |
This file contains hidden or 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 hidden or 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 hidden or 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,5 +1,4 @@ | ||
| import { createRequire } from 'node:module'; | ||
|
|
||
| const packageJson = createRequire(import.meta.url ?? __dirname)('../../package.json'); | ||
| import packageJson from '../../package.json' with { type: 'json' }; | ||
tatomyr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const { version, name, engines } = packageJson; | ||
| export const redocVersion = packageJson.dependencies.redoc; | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.