From 16cc3b594e3db04029948b2a973c9847331d8c56 Mon Sep 17 00:00:00 2001 From: dsh-ci-bot Date: Fri, 13 Nov 2026 11:40:46 +0800 Subject: [PATCH 1/2] fix(client): key stylesheets by the real package path Rolldown canonicalizes module ids through symbolic links, while the package directory arrives as the caller wrote it. On macOS, whose temporary directory sits below the /var -> /private/var link, relative(packageDir, fileId) no longer starts inside the package, so the package's own stylesheets were named node_modules//... Compares both paths after resolving links, as the asset paths in the same config already do. --- packages/client/tsdown.client.ts | 8 +++++--- scripts/client-bundle-purity.spec.ts | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/client/tsdown.client.ts b/packages/client/tsdown.client.ts index 7bc2922be9..6a45cef805 100644 --- a/packages/client/tsdown.client.ts +++ b/packages/client/tsdown.client.ts @@ -73,15 +73,17 @@ function compiledClientStyle( fileId: string, expression: string, ): CompiledClientStyle { - const path = relative(packageDir, fileId).split(sep).join('/').replace(/^lib\/types\//, 'src/') + // Rolldown canonicalizes module ids through symbolic links; the package directory arrives as the caller wrote it. + const file = realpathSync(fileId) + const path = relative(realpathSync(packageDir), file).split(sep).join('/').replace(/^lib\/types\//, 'src/') if (!path.startsWith('../')) return { path, expression } - let directory = dirname(fileId) + let directory = dirname(file) while (dirname(directory) !== directory) { const manifestPath = join(directory, 'package.json') if (existsSync(manifestPath)) { const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as { name?: string } if (typeof manifest.name === 'string') { - return { path: `node_modules/${manifest.name}/${relative(directory, fileId).split(sep).join('/')}`, expression } + return { path: `node_modules/${manifest.name}/${relative(directory, file).split(sep).join('/')}`, expression } } } directory = dirname(directory) diff --git a/scripts/client-bundle-purity.spec.ts b/scripts/client-bundle-purity.spec.ts index 84623469d7..c8264baaeb 100644 --- a/scripts/client-bundle-purity.spec.ts +++ b/scripts/client-bundle-purity.spec.ts @@ -2,7 +2,7 @@ * Pins shared client-bundle preset rules: build modes, module-edge purity, * source-map chaining, and physical watch dependencies hidden behind virtual CSS Modules. */ -import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' +import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { dirname, join, relative } from 'node:path' import { fileURLToPath } from 'node:url' @@ -298,6 +298,25 @@ describe('static Client dependency delivery', () => { expect(stylesheets!['src/global.css']!.text(require)) .toContain('.overlay{position:fixed}') }) + + it('names local styles below the package when the package directory is a symbolic link', async () => { + const outer = mkdtempSync(join(tmpdir(), 'dsh-static-symlink-')) + onTestFinished(() => { rmSync(outer, { recursive: true, force: true }) }) + const real = join(outer, 'package') + mkdirSync(join(real, 'lib/types'), { recursive: true }) + mkdirSync(join(real, 'src'), { recursive: true }) + writeFileSync(join(real, 'package.json'), JSON.stringify({ name: REQUESTING_PACKAGE, type: 'module' })) + writeFileSync(join(real, 'lib/types/index.js'), 'import classes from "./Panel.module.css"\nexport { classes }\n') + writeFileSync(join(real, 'src/Panel.module.css'), '.panel { display: flex; }\n') + const linked = join(outer, 'linked') + symlinkSync(real, linked, 'dir') + + const output = await clientChunkOutput(linked, config(linked), 'index.js') + const artifact = await import(`data:text/javascript,${encodeURIComponent(output)}`) as StaticArtifact + const meta = artifact[STATIC_MODULE_MANIFEST_EXPORT].meta + if (meta === undefined) throw new Error('static CSS metadata missing') + expect(Object.keys(meta().stylesheets ?? {})).toEqual(['src/Panel.module.css']) + }) }) function dynamicImportFixture(prefix: string): string { From 1732b2685b559d90096e68bec378d46f18fababc Mon Sep 17 00:00:00 2001 From: dsh-ci-bot Date: Fri, 13 Nov 2026 12:02:19 +0800 Subject: [PATCH 2/2] fix(client): judge stylesheet containment with pathBelow relative() returns an absolute path when a Windows package and its stylesheet sit on different drives, and startsWith('../') read that as inside the package. Reuse the file's pathBelow() so the '..' prefix, an absolute result, and the package root all take the dependency branch, matching resource(). The new symbolic-link case also follows the repository's junction convention on Windows and asserts the compiled text still resolves. --- packages/client/tsdown.client.ts | 4 ++-- scripts/client-bundle-purity.spec.ts | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/client/tsdown.client.ts b/packages/client/tsdown.client.ts index 6a45cef805..6b4fb97491 100644 --- a/packages/client/tsdown.client.ts +++ b/packages/client/tsdown.client.ts @@ -75,8 +75,8 @@ function compiledClientStyle( ): CompiledClientStyle { // Rolldown canonicalizes module ids through symbolic links; the package directory arrives as the caller wrote it. const file = realpathSync(fileId) - const path = relative(realpathSync(packageDir), file).split(sep).join('/').replace(/^lib\/types\//, 'src/') - if (!path.startsWith('../')) return { path, expression } + const local = pathBelow(realpathSync(packageDir), file) + if (local !== undefined) return { path: local.split(sep).join('/').replace(/^lib\/types\//, 'src/'), expression } let directory = dirname(file) while (dirname(directory) !== directory) { const manifestPath = join(directory, 'package.json') diff --git a/scripts/client-bundle-purity.spec.ts b/scripts/client-bundle-purity.spec.ts index c8264baaeb..2ed0bd3d5e 100644 --- a/scripts/client-bundle-purity.spec.ts +++ b/scripts/client-bundle-purity.spec.ts @@ -300,22 +300,22 @@ describe('static Client dependency delivery', () => { }) it('names local styles below the package when the package directory is a symbolic link', async () => { - const outer = mkdtempSync(join(tmpdir(), 'dsh-static-symlink-')) - onTestFinished(() => { rmSync(outer, { recursive: true, force: true }) }) - const real = join(outer, 'package') - mkdirSync(join(real, 'lib/types'), { recursive: true }) - mkdirSync(join(real, 'src'), { recursive: true }) - writeFileSync(join(real, 'package.json'), JSON.stringify({ name: REQUESTING_PACKAGE, type: 'module' })) - writeFileSync(join(real, 'lib/types/index.js'), 'import classes from "./Panel.module.css"\nexport { classes }\n') - writeFileSync(join(real, 'src/Panel.module.css'), '.panel { display: flex; }\n') - const linked = join(outer, 'linked') - symlinkSync(real, linked, 'dir') + const root = fixture('import classes from "./Panel.module.css"\nexport { classes }\n') + mkdirSync(join(root, 'src'), { recursive: true }) + writeFileSync(join(root, 'src/Panel.module.css'), '.panel { display: flex; }\n') + const linked = join(root, 'linked') + symlinkSync(root, linked, process.platform === 'win32' ? 'junction' : 'dir') const output = await clientChunkOutput(linked, config(linked), 'index.js') const artifact = await import(`data:text/javascript,${encodeURIComponent(output)}`) as StaticArtifact - const meta = artifact[STATIC_MODULE_MANIFEST_EXPORT].meta + const manifest = artifact[STATIC_MODULE_MANIFEST_EXPORT] + const meta = manifest.meta if (meta === undefined) throw new Error('static CSS metadata missing') - expect(Object.keys(meta().stylesheets ?? {})).toEqual(['src/Panel.module.css']) + const stylesheets = meta().stylesheets + expect(Object.keys(stylesheets ?? {})).toEqual(['src/Panel.module.css']) + const exports = manifest.factory(unusedRequire) as { classes: { panel: string } } + expect(stylesheets?.['src/Panel.module.css']?.text(unusedRequire)) + .toContain(`.${exports.classes.panel}{display:flex}`) }) })