diff --git a/scripts/workspace-package-globs.spec.ts b/scripts/workspace-package-globs.spec.ts new file mode 100644 index 0000000000..1a8bebf075 --- /dev/null +++ b/scripts/workspace-package-globs.spec.ts @@ -0,0 +1,13 @@ +/** Windows manifest paths still select the packages whose artifacts Desktop bundles. */ +import { globSync } from 'node:fs' +import { resolve, win32 } from 'node:path' +import { expect, it } from 'vitest' +import { workspacePackageGlobs } from './workspace-package-globs.ts' + +it('selects workspace packages from Windows and POSIX manifest paths', () => { + const cwd = resolve(import.meta.dirname, '..') + const manifests = ['packages\\util\\atomic-write\\package.json', 'vendor/cordis/package.json'] + const selected = globSync(workspacePackageGlobs(manifests), { cwd }).map(path => path.replaceAll('\\', '/')).sort() + expect(selected).toEqual(['packages/util/atomic-write', 'vendor/cordis']) + expect(globSync(manifests.map(path => win32.dirname(path)), { cwd })).toEqual([]) +}) diff --git a/scripts/workspace-package-globs.ts b/scripts/workspace-package-globs.ts new file mode 100644 index 0000000000..dc1d597bff --- /dev/null +++ b/scripts/workspace-package-globs.ts @@ -0,0 +1,11 @@ +/** Convert discovered package manifests into portable bundler workspace patterns. */ +import { posix } from 'node:path' + +/** + * Keep filesystem separators from becoming escapes in workspace globs. + * @param manifests - Repository-relative manifest paths returned by filesystem discovery. + * @returns Package directory patterns using forward slashes on every host. + */ +export function workspacePackageGlobs(manifests: readonly string[]): string[] { + return manifests.map(path => posix.dirname(path.replaceAll('\\', '/'))) +} diff --git a/tsdown.config.ts b/tsdown.config.ts index 7dc713a8e8..b66a197ef1 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -1,8 +1,8 @@ import { globSync } from 'node:fs' -import { dirname } from 'node:path' import { defineConfig } from 'tsdown' import { typertPlugin } from './packages/typert/generator/lib/types/tsdown-plugin.js' import { WORKSPACE_TYPERT_FACES } from './scripts/typert-faces.ts' +import { workspacePackageGlobs } from './scripts/workspace-package-globs.ts' function isBuildFaceClient(value: unknown): boolean { if (value === undefined || value === 'host') return false @@ -21,7 +21,7 @@ function isBuildFaceClient(value: unknown): boolean { */ export default defineConfig(({ env }) => { const client = isBuildFaceClient(env?.DSH_BUILD_FACE) - const packages = globSync(['vendor/*/package.json', 'packages/*/*/package.json'], { cwd: import.meta.dirname }).map(dirname) + const packages = workspacePackageGlobs(globSync(['vendor/*/package.json', 'packages/*/*/package.json'], { cwd: import.meta.dirname })) return { workspace: [...packages, 'apps/cli', ...client ? [] : ['apps/desktop-host']], entry: client ? '' : ['lib/types/{index,startup}.js'],