From 031008eb5b1a5a860f0d69b7bfcd6f13d77b18ca Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Thu, 3 Sep 2026 11:35:56 +0200 Subject: [PATCH] fix: Add compilerOptions: {paths: {}} --- .../src/configuration/get-esbuild-config.ts | 9 ++- modules/dev-tools/test/configuration.spec.ts | 58 ++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/modules/dev-tools/src/configuration/get-esbuild-config.ts b/modules/dev-tools/src/configuration/get-esbuild-config.ts index 6dbb84f..4c13125 100644 --- a/modules/dev-tools/src/configuration/get-esbuild-config.ts +++ b/modules/dev-tools/src/configuration/get-esbuild-config.ts @@ -109,6 +109,7 @@ export async function getCJSExportConfig(opts: { // Node 16 is out of support, kept for compatibility. Move to 18? target: 'node16', packages: 'external', + tsconfigRaw: {compilerOptions: {paths: {}}}, sourcemap: true, sourcesContent: false, logLevel: 'info' @@ -252,7 +253,13 @@ export async function getBundleConfig(opts: BundleOptions): Promise { + const config = await getCJSExportConfig({ + input: './dist/index.js', + output: './dist/index.cjs' + }); + + expect(config.packages).toBe('external'); + expect(config.tsconfigRaw).toEqual({compilerOptions: {paths: {}}}); +}); + +test('dev-tools#getCJSExportConfig keeps workspace packages out of the bundle', async () => { + const fixtureDirectory = mkdtempSync(path.join(tmpdir(), 'ocular-cjs-')); + + try { + // A monorepo that maps its own scope to sibling sources, as vis.gl repos do. + writeFileSync( + path.join(fixtureDirectory, 'tsconfig.json'), + JSON.stringify({ + compilerOptions: { + moduleResolution: 'bundler', + paths: {'@example/sibling': ['./sibling/src/index.js']} + } + }) + ); + mkdirSync(path.join(fixtureDirectory, 'sibling', 'src'), {recursive: true}); + writeFileSync( + path.join(fixtureDirectory, 'sibling', 'src', 'index.js'), + "export const sibling = 'incorrectly bundled';\n" + ); + mkdirSync(path.join(fixtureDirectory, 'dist'), {recursive: true}); + writeFileSync( + path.join(fixtureDirectory, 'dist', 'index.js'), + "import {sibling} from '@example/sibling';\nexport const value = sibling;\n" + ); + + const config = await getCJSExportConfig({ + input: path.join(fixtureDirectory, 'dist', 'index.js'), + output: path.join(fixtureDirectory, 'dist', 'index.cjs') + }); + await build({...config, logLevel: 'silent'}); + + const output = readFileSync(path.join(fixtureDirectory, 'dist', 'index.cjs'), 'utf8'); + expect(output).toContain('require("@example/sibling")'); + expect(output).not.toContain('incorrectly bundled'); + } finally { + rmSync(fixtureDirectory, {recursive: true, force: true}); + } +}); + test('ocular-bundle CLI bundles the requested entry point', () => { const fixtureDirectory = mkdtempSync(path.join(tmpdir(), 'ocular-bundle-')); const scriptPath = fileURLToPath(new URL('../scripts/bundle.js', import.meta.url));