Skip to content

Commit a2b8f63

Browse files
gregbergeclaude
andcommitted
Convert @gitbook/cli to ESM and consume the ESM content-engine
The content-engine is now built as a self-contained ESM bundle (tsdown), so the CLI bundle switches to ESM output: - package.json: type module, postinstall script renamed to .cjs - build.sh: esm format, with a banner shimming require/__dirname for bundled CommonJS dependencies and the cloudflared tunnel path - cli.js bin shim: import instead of require Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 38a5a28 commit a2b8f63

6 files changed

Lines changed: 18 additions & 7 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ rm -rf ./dist/
44
esbuild ./src/cli.ts \
55
--bundle \
66
--platform=node \
7+
--format=esm \
8+
--banner:js="$(cat ./esm-shims.js)" \
79
--external:esbuild \
810
--external:miniflare \
911
--external:fsevents \

packages/cli/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
* To avoid the probem of bun/npm only linking the CLI at the installation time.
55
* We use a fixed file that will be linked to the bin folder and requires the actual CLI.
66
*/
7-
require('./dist/cli.js');
7+
import './dist/cli.js';

packages/cli/esm-shims.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Shims for CommonJS globals used by bundled dependencies (require) and by
2+
// the CLI itself (__dirname), injected as a banner in the ESM bundle.
3+
import { createRequire as __createRequire } from 'node:module';
4+
import { fileURLToPath as __fileURLToPath } from 'node:url';
5+
import { dirname as __pathDirname } from 'node:path';
6+
const require = __createRequire(import.meta.url);
7+
const __filename = __fileURLToPath(import.meta.url);
8+
const __dirname = __pathDirname(__filename);

packages/cli/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"name": "@gitbook/cli",
33
"description": "CLI to build and publish integrations on GitBook.com",
44
"version": "0.28.0",
5+
"type": "module",
56
"dependencies": {
67
"@gitbook/api": "*",
7-
"@gitbook/content-engine": "file:../../../gitbook-x/packages/content-engine/dist-pkg",
8+
"@gitbook/content-engine": "file:../../../gitbook-x/packages/content-engine/dist",
89
"check-node-version": "^4.2.1",
910
"commander": "^9.2.0",
1011
"conf": "^13.1.0",
@@ -27,11 +28,11 @@
2728
},
2829
"files": [
2930
"dist/**",
30-
"postinstall.js"
31+
"postinstall.cjs"
3132
],
3233
"scripts": {
3334
"build": "./build.sh",
34-
"postinstall": "node postinstall.js",
35+
"postinstall": "node postinstall.cjs",
3536
"typecheck": "tsc --noEmit"
3637
},
3738
"engines": {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Script to install cloudflared binary on the current platform.
33
* Reference: https://github.com/JacobLinCool/node-cloudflared/blob/main/src/install.ts
44
*/
5-
const { execSync } = require('child_process');
5+
const { execSync } = require('node:child_process');
66
const fs = require('fs');
77
const https = require('https');
88
const path = require('path');

0 commit comments

Comments
 (0)