Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix: facade test timed out in CI

Damian Legawiec58a061041f56
diff --git a/packages/dashboard/src/facade.test.ts b/packages/dashboard/src/facade.test.ts
index 14d3189477..e0a1b27cf3 100644
--- a/packages/dashboard/src/facade.test.ts
+++ b/packages/dashboard/src/facade.test.ts
@@ -10,25 +10,34 @@ import { describe, expect, it } from 'vitest'
// This test fails when a new name appears in both packages. The fix is to add
// it to that explicit list, choosing the version an application should get
// (almost always the framework's: it fetches its own data).
-function exportsOf(entry: string) {
- const file = require.resolve(entry, { paths: [__dirname] })
- const program = ts.createProgram([file], {
- moduleResolution: ts.ModuleResolutionKind.Bundler,
- module: ts.ModuleKind.ESNext,
- target: ts.ScriptTarget.ES2022,
- jsx: ts.JsxEmit.ReactJSX,
- skipLibCheck: true,
- noEmit: true,
- })
- const checker = program.getTypeChecker()
+//
+// One program covers all three modules: src/index.ts re-exports the other two,
+// so they are already in its dependency graph. Compiling them separately costs
+// a full graph walk each, which is slow enough to time out on a cold CI runner.
+const entry = path.join(__dirname, 'index.ts')
+const core = require.resolve('@spree/dashboard-core', { paths: [__dirname] })
+const ui = require.resolve('@spree/dashboard-ui', { paths: [__dirname] })
+
+const program = ts.createProgram([entry], {
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
+ module: ts.ModuleKind.ESNext,
+ target: ts.ScriptTarget.ES2022,
+ jsx: ts.JsxEmit.ReactJSX,
+ skipLibCheck: true,
+ noEmit: true,
+})
+const checker = program.getTypeChecker()
+
+function exportsOf(file: string) {
const source = program.getSourceFile(file)
- if (!source) throw new Error(`could not load ${entry}`)
+ if (!source) throw new Error(`could not load ${file}`)
const symbol = checker.getSymbolAtLocation(source)
- if (!symbol) throw new Error(`no module symbol for ${entry}`)
- return { checker, exports: checker.getExportsOfModule(symbol) }
+ if (!symbol) throw new Error(`no module symbol for ${file}`)
+ return checker.getExportsOfModule(symbol)
}
-function resolve(checker: ts.TypeChecker, symbol?: ts.Symbol) {
+/** Follows alias chains to the declaration a name ultimately comes from. */
+function origin(symbol?: ts.Symbol) {
if (!symbol) return ''
let current = symbol
while (current.flags & ts.SymbolFlags.Alias) current = checker.getAliasedSymbol(current)
@@ -36,17 +45,17 @@ function resolve(checker: ts.TypeChecker, symbol?: ts.Symbol) {
}
describe('@spree/dashboard facade', () => {
- const core = exportsOf('@spree/dashboard-core')
- const ui = exportsOf('@spree/dashboard-ui')
- const duplicates = core.exports
- .map((s) => s.getName())
- .filter((name) => ui.exports.some((s) => s.getName() === name))
+ const coreExports = exportsOf(core)
+ const uiExports = exportsOf(ui)
+ const facadeExports = exportsOf(entry)
- it('re-exports every duplicate explicitly, resolved to the framework', () => {
- const { checker, exports } = exportsOf(path.join(__dirname, 'index.ts'))
+ const duplicates = coreExports
+ .map((symbol) => symbol.getName())
+ .filter((name) => uiExports.some((symbol) => symbol.getName() === name))
+ it('re-exports every duplicate explicitly, resolved to the framework', () => {
for (const name of duplicates) {
- const symbol = exports.find((s) => s.getName() === name)
+ const symbol = facadeExports.find((s) => s.getName() === name)
expect(
symbol,
`${name} is declared by both packages and was dropped from the facade`,
@@ -56,26 +65,19 @@ describe('@spree/dashboard facade', () => {
// so either resolution is correct. Only genuinely distinct pairs — the
// design system's presentational component and the framework's
// data-fetching wrapper — need the framework's version to win.
- const viaCore = resolve(
- core.checker,
- core.exports.find((s) => s.getName() === name),
- )
- const viaUi = resolve(
- ui.checker,
- ui.exports.find((s) => s.getName() === name),
- )
+ const viaCore = origin(coreExports.find((s) => s.getName() === name))
+ const viaUi = origin(uiExports.find((s) => s.getName() === name))
if (viaCore === viaUi) continue
- const from = resolve(checker, symbol)
- expect(from, `${name} resolves to the design system, not the framework`).toContain(
+ expect(origin(symbol), `${name} resolves to the design system, not the framework`).toContain(
'dashboard-core',
)
}
})
it('exposes the shell alongside the re-exports', () => {
- const { exports } = exportsOf(path.join(__dirname, 'index.ts'))
- const names = exports.map((s) => s.getName())
+ const names = facadeExports.map((symbol) => symbol.getName())
+
expect(names).toContain('Dashboard')
expect(names).toContain('createDashboardRouter')
expect(names).toContain('defineDashboardPlugin')
diff --git a/packages/dashboard/src/index.ts b/packages/dashboard/src/index.ts
index 504a9faa7a..ee7f26a2c7 100644
--- a/packages/dashboard/src/index.ts
+++ b/packages/dashboard/src/index.ts
@@ -14,24 +14,22 @@
// subpath exports (`@spree/dashboard-ui/icons`, `@spree/dashboard-core/vite`)
// are unaffected.
//
-// Order matters. A handful of names exist in both packages: the design system
-// ships a presentational component and the framework wraps it with data. The
-// framework is exported last so its version wins, which is the one an
-// application wants — `ResourceCombobox` that loads its own options rather
-// than the pure one that takes them as props. Reach past the facade when you
-// want the presentational half:
+// A handful of names exist in both packages, where the design system ships a
+// presentational component and the framework wraps it with data. Reach past
+// the facade when you want the presentational half:
//
// import { ResourceCombobox } from '@spree/dashboard-ui'
//
-// `pnpm --filter @spree/dashboard test` fails when a new duplicate appears,
-// so this list cannot drift silently.
+// `pnpm --filter @spree/dashboard test` checks that every such name resolves
+// to the framework, so a reordering or a new duplicate cannot change the
+// public API unnoticed.
export * from '@spree/dashboard-core'
-// `export *` drops a name declared by both modules rather than picking one,
-// so the duplicates below are re-exported explicitly. The framework's version
-// wins because it is the one an application wants: it fetches its own data,
-// where the design system's takes everything as props. Import from
-// `@spree/dashboard-ui` directly for the presentational half.
+// `export *` from two modules that both declare a name is an error (TS2308),
+// and the ambiguity is resolved by naming the winner explicitly. The
+// framework's version wins: it fetches its own data, where the design
+// system's takes everything as props. `pnpm test` checks every duplicate
+// resolves this way, so a new one cannot slip in unnoticed.
export {
type DateRange,
ResourceCombobox,
diff --git a/packages/seller-dashboard/src/index.ts b/packages/seller-dashboard/src/index.ts
index 8659c02862..552242644a 100644
--- a/packages/seller-dashboard/src/index.ts
+++ b/packages/seller-dashboard/src/index.ts
@@ -24,10 +24,10 @@ export {
// re-exported so a host writing its own pages never has to work out which
// package an export lives in. Both stay importable directly.
//
-// `export *` drops a name declared by both rather than picking one, so the
-// duplicates are re-exported explicitly below, resolving to the framework's
-// version — the one that fetches its own data. Import from
-// `@spree/dashboard-ui` for the presentational half.
+// `export *` from two modules that both declare a name is an error (TS2308),
+// resolved by naming the winner explicitly above. The framework's version
+// wins: it fetches its own data, where the design system's takes everything
+// as props. Import from `@spree/dashboard-ui` for the presentational half.
export * from '@spree/dashboard-ui'
export {