Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
66b3c93
autoresearch: setup bundle size optimization
gonzaloriestra Mar 13, 2026
74a2dbe
fix checks script - remove broken lint
gonzaloriestra Mar 13, 2026
80bec98
Replace brotli JS package with native Node.js zlib.brotliCompressSync…
gonzaloriestra Mar 13, 2026
7d2e82b
Enable minifyWhitespace in esbuild bundle — saves 14,112 KB (JS: -11,…
gonzaloriestra Mar 13, 2026
2fc10d7
Externalize prettier from bundle (~4MB input, ~11.7MB output+maps sav…
gonzaloriestra Mar 13, 2026
eabc031
Externalize ts-morph (+ typescript dep) from bundle — saves 23,140 KB…
gonzaloriestra Mar 13, 2026
303ce3b
Externalize typescript compiler from bundle — saves 19,176 KB. Availa…
gonzaloriestra Mar 13, 2026
cdf329f
Disable esbuild source maps — saves 35,752 KB. Stack traces still rea…
gonzaloriestra Mar 13, 2026
8f75609
Enable minifyIdentifiers in esbuild — saves 4,664 KB (JS: 16,500→11,8…
gonzaloriestra Mar 13, 2026
d31c979
Externalize @shopify/polaris, polaris-icons, polaris-tokens — saves 1…
gonzaloriestra Mar 13, 2026
6e2d804
Externalize react-dom (only used for GraphiQL SSR, not by ink) — save…
gonzaloriestra Mar 13, 2026
0c6f5ca
Externalize vscode language service packages (~2MB input) — saves 992…
gonzaloriestra Mar 13, 2026
715bdbd
Externalize @oclif/table (avoids bundling ink@5 + react@18 + react-re…
gonzaloriestra Mar 13, 2026
d9bb563
Externalize lodash — saves 112 KB (partial tree-shaking already reduc…
gonzaloriestra Mar 13, 2026
982d6c4
Externalize @opentelemetry packages (~1.3MB input) — saves 416 KB\n\n…
gonzaloriestra Mar 13, 2026
95b5321
Externalize theme-check/language-server packages, ohm-js, liquid-html…
gonzaloriestra Mar 13, 2026
a32d91d
Externalize ink, react, react-reconciler, ajv, archiver, liquidjs, se…
gonzaloriestra Mar 13, 2026
1eaab72
Exclude test files from bundle entry points (11 .test.ts files were b…
gonzaloriestra Mar 13, 2026
7099347
Externalize @oclif/core, graphql, zod, jose, node-fetch, got, ws, and…
gonzaloriestra Mar 13, 2026
6f58b49
Last step
gonzaloriestra Mar 13, 2026
766c9b6
Fix bundle issue
gonzaloriestra Mar 13, 2026
c2d577a
Fix lint and knip
gonzaloriestra Mar 13, 2026
2f363e9
Remove temp files
gonzaloriestra Mar 16, 2026
696e5f7
Only externalize some deps and enable sourcemap
gonzaloriestra Mar 17, 2026
195248b
Do not externalize required deps
gonzaloriestra Mar 18, 2026
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
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@
"ignoreBinaries": [
"playwright"
],
"ignoreDependencies": [
"@shopify/theme-check-node",
"@shopify/theme-check-docs-updater"
],
"ignoreDependencies": [],
"ignoreWorkspaces": [
"packages/eslint-plugin-cli",
"packages/e2e"
Expand Down Expand Up @@ -201,6 +198,7 @@
"**/graphql/**/generated/*.ts"
],
"ignoreDependencies": [
"@graphql-typed-document-node/core",
"@shopify/plugin-cloudflare"
],
"vite": {
Expand All @@ -217,7 +215,9 @@
],
"project": "**/*.ts!",
"ignoreDependencies": [
"@ast-grep/napi"
"@ast-grep/napi",
"@shopify/theme-check-docs-updater",
"@shopify/theme-check-node"
],
"vite": {
"config": [
Expand Down Expand Up @@ -290,6 +290,9 @@
"ignoreBinaries": [
"open"
],
"ignoreDependencies": [
"@graphql-typed-document-node/core"
],
"vite": {
"config": [
"vite.config.ts"
Expand All @@ -308,10 +311,7 @@
"**/scripts/*.ts!",
"**/src/testing/index.ts"
],
"project": "**/*.{ts,tsx}!",
"ignoreDependencies": [
"react-dom"
]
"project": "**/*.{ts,tsx}!"
},
"packages/ui-extensions-test-utils": {
"entry": [
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"ansi-escapes": "6.2.1",
"archiver": "5.3.2",
"bottleneck": "2.19.5",
"brotli": "1.3.3",

"chalk": "5.4.1",
"change-case": "4.1.2",
"color-json": "3.0.5",
Expand Down Expand Up @@ -168,7 +168,7 @@
"zod": "3.24.4"
},
"devDependencies": {
"@types/brotli": "^1.3.4",

"@types/commondir": "^1.0.0",
"@types/diff": "^5.2.3",
"@types/fs-extra": "9.0.13",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {joinPath, dirname} from './path.js'
import {exec} from './system.js'
import {describe, expect, test} from 'vitest'
import StreamZip from 'node-stream-zip'
import brotli from 'brotli'
import {brotliDecompressSync} from 'zlib'

import fs from 'fs'

Expand Down Expand Up @@ -92,8 +92,8 @@ describe('brotliCompress', () => {
// Brotli files start with the bytes 0x1B...
expect(compressedContent[0]).toBe(0x1b)

// Decompress using brotli library
const decompressed = brotli.decompress(compressedContent)
// Decompress using native zlib brotli
const decompressed = brotliDecompressSync(compressedContent)
expect(decompressed).toBeTruthy()
})
})
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('brotliCompress', () => {

// Save compressed content to a file
const compressedContent = fs.readFileSync(brotliPath)
const decompressed = brotli.decompress(compressedContent)
const decompressed = brotliDecompressSync(compressedContent)
const tmpTarPath = joinPath(tmpDir, 'output.tar')
fs.writeFileSync(tmpTarPath, decompressed)

Expand Down
14 changes: 6 additions & 8 deletions packages/cli-kit/src/public/node/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {createWriteStream, readFileSync, writeFileSync} from 'fs'
import {readFile} from 'fs/promises'
import {tmpdir} from 'os'
import {randomUUID} from 'crypto'
import {brotliCompressSync, constants as zlibConstants} from 'zlib'

interface ZipOptions {
/**
Expand Down Expand Up @@ -183,16 +184,13 @@ export async function brotliCompress(options: BrotliOptions): Promise<void> {
})

const tarContent = readFileSync(tempTarPath)
const brotli = await import('brotli')
const compressed = brotli.default.compress(tarContent, {
quality: 7,
mode: 0,
const compressed = brotliCompressSync(tarContent, {
params: {
[zlibConstants.BROTLI_PARAM_QUALITY]: 7,
[zlibConstants.BROTLI_PARAM_MODE]: zlibConstants.BROTLI_MODE_GENERIC,
},
})

if (!compressed) {
throw new Error('Brotli compression failed')
}

writeFileSync(options.outputPath, compressed)
} finally {
try {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/bin/bundle.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Ref Line 56) 🐛 Bug: The configuration uses sourcemap: true, which generates inline sourcemaps embedded directly in the .js files rather than separate .map files. This means the !/dist/**/*.map exclusion in package.json has no effect, and sourcemaps are shipped to npm users inside the bundles, directly contradicting the PR's goal of reducing bundle size by ~55%. An earlier commit noted that disabling sourcemaps saved 35,752 KB.

Suggestion:

Suggested change
sourcemap: 'external',

This will generate separate .map files that can be uploaded to Observe while being excluded from the npm package via the existing !/dist/**/*.map pattern.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const hydrogenAssets = joinPath(hydrogenPath, 'dist/assets/hydrogen/**/*')

esBuild({
bundle: true,
entryPoints: ['./src/**/*.ts'],
entryPoints: ['./src/index.ts'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from globbing all .ts files to a single "./src/index.ts" entry point breaks the oclif hooks configuration.

The Problem

The oclif configuration in packages/cli/package.json expects these hook files:

"hooks": {
  "prerun": "./dist/hooks/prerun.js",
  "postrun": "./dist/hooks/postrun.js"
}

These source files exist:

  • packages/cli/src/hooks/prerun.ts
  • packages/cli/src/hooks/postrun.ts

However, packages/cli/src/index.ts does NOT import or export these hooks. They are meant to be standalone files per oclif convention.

Impact

With the old config (entryPoints: ["./src/**/*.ts"]):

  • esbuild finds all .ts files via glob
  • Creates corresponding .js files maintaining directory structure
  • Outputs dist/hooks/prerun.js and dist/hooks/postrun.js

With the new config (entryPoints: ["./src/index.ts"]):

  • esbuild only bundles what's reachable from index.ts
  • Since prerun/postrun aren't imported by index.ts, they're unreachable
  • No dist/hooks/prerun.js or dist/hooks/postrun.js files are created
  • oclif will fail when trying to load these hooks at runtime

Fix Options

  1. Keep the glob pattern: entryPoints: ["./src/**/*.ts"]
  2. Add explicit entry points: entryPoints: ["./src/index.ts", "./src/hooks/prerun.ts", "./src/hooks/postrun.ts"]
  3. Import/export the hooks in index.ts (not recommended - they're meant to be separate files per oclif convention)

outdir: './dist',
platform: 'node',
format: 'esm',
Expand All @@ -58,9 +58,9 @@ esBuild({
splitting: true,
// these tree shaking and minify options remove any in-source tests from the bundle
treeShaking: true,
minifyWhitespace: false,
minifyWhitespace: true,
minifySyntax: true,
minifyIdentifiers: false,
minifyIdentifiers: true,

plugins: [
ShopifyVSCodePlugin,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"/bin/run.cmd",
"/bin/run.js",
"/dist",
"!/dist/**/*.map",
"/oclif.manifest.json"
],
"scripts": {
Expand Down
48 changes: 19 additions & 29 deletions pnpm-lock.yaml

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

Loading