Skip to content

Commit 313caf6

Browse files
committed
fixup! docs: split qraft tree-shaking plans
1 parent 2ab9d83 commit 313caf6

1 file changed

Lines changed: 58 additions & 8 deletions

File tree

docs/superpowers/plans/2026-05-08-qraft-tree-shaking-source-maps.md

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
**Tech Stack:** TypeScript, Babel generator, unplugin, `@jridgewell/trace-mapping`, Vitest, Yarn 4.
1010

11+
**File Structure:**
12+
- `packages/tree-shaking-plugin/src/lib/plugin/create-qraft-tree-shake-plugin.ts` forwards `this.inputSourceMap` from the bundler context into the core transform.
13+
- `packages/tree-shaking-plugin/src/core.ts` accepts an optional incoming map and passes it to Babel generator through `inputSourceMap`.
14+
- `packages/tree-shaking-plugin/src/core.test.ts` adds the regression test, updates the local test helper to pass the optional map, and verifies the composed position with `@jridgewell/trace-mapping`.
15+
- `packages/tree-shaking-plugin/package.json` and `yarn.lock` add the direct dev dependency required by the new test.
16+
- `e2e/projects/tree-shaking-bundlers/` is not expected to change for this feature, but it is the external validation target.
17+
1118
---
1219

1320
### Task 1: Add the failing composed-map regression test
@@ -19,6 +26,40 @@
1926

2027
- [ ] **Step 1: Add a source-map test that traces the rewritten call site back to the original source**
2128

29+
Update the local test helper first so the new regression test can pass the incoming map through to the real transform:
30+
31+
```ts
32+
async function transformQraftTreeShaking(
33+
code: string,
34+
id: string,
35+
options: TransformOptions,
36+
inputSourceMap?: unknown
37+
) {
38+
const fixtureRoot = path.dirname(path.dirname(id));
39+
const fixtureResolver = createFixtureResolver(fixtureRoot);
40+
const resolver = async (specifier: string, importer: string) => {
41+
if (options.resolve) {
42+
try {
43+
const resolved = await options.resolve(specifier, importer);
44+
if (resolved) return resolved;
45+
} catch {
46+
// Fall through to the fixture resolver.
47+
}
48+
}
49+
50+
return fixtureResolver(specifier, importer);
51+
};
52+
53+
return transformQraftTreeShakingImpl(
54+
code,
55+
id,
56+
options,
57+
resolver,
58+
inputSourceMap
59+
);
60+
}
61+
```
62+
2263
```ts
2364
import { originalPositionFor, TraceMap } from '@jridgewell/trace-mapping';
2465

@@ -65,25 +106,25 @@ export function App() {
65106
});
66107
```
67108

68-
- [ ] **Step 2: Run the focused test before plumbing exists and confirm it fails**
109+
- [ ] **Step 2: Add `@jridgewell/trace-mapping` as a direct dev dependency**
69110

70111
Run:
71112

72113
```bash
73-
yarn workspace @openapi-qraft/tree-shaking-plugin test -- src/core.test.ts -t "keeps the rewritten call site traceable through the composed source map"
114+
yarn workspace @openapi-qraft/tree-shaking-plugin add -D @jridgewell/trace-mapping
74115
```
75116

76-
Expected: FAIL because the incoming bundler map is not threaded into the transform yet.
117+
Expected: `packages/tree-shaking-plugin/package.json` and `yarn.lock` now list `@jridgewell/trace-mapping` directly, so the new test can compile under Yarn PnP.
77118

78-
- [ ] **Step 3: Record the dependency update**
119+
- [ ] **Step 3: Run the focused test before plumbing exists and confirm it fails**
79120

80121
Run:
81122

82123
```bash
83-
yarn workspace @openapi-qraft/tree-shaking-plugin add -D @jridgewell/trace-mapping
124+
yarn workspace @openapi-qraft/tree-shaking-plugin test -- src/core.test.ts -t "keeps the rewritten call site traceable through the composed source map"
84125
```
85126

86-
Expected: the package manifest and lockfile both include the source-map assertion dependency.
127+
Expected: FAIL because the incoming bundler map is not threaded into the transform yet, so the composed-map assertion still points at generated-only positions.
87128

88129
### Task 2: Thread the incoming map through the plugin and generator
89130

@@ -103,17 +144,26 @@ handler(this: any, code, id) {
103144
}
104145
```
105146

106-
- [ ] **Step 2: Pass the incoming map into Babel generator**
147+
- [ ] **Step 2: Extend the core transform signature and pass the incoming map into Babel generator**
107148

108-
Use this generator call in `src/core.ts`:
149+
Update `packages/tree-shaking-plugin/src/core.ts` so the function accepts the optional map and forwards it unchanged:
109150

110151
```ts
152+
export async function transformQraftTreeShaking(
153+
code: string,
154+
id: string,
155+
options: QraftTreeShakeOptions,
156+
resolver: QraftResolver = createAgnosticResolver(options.resolve),
157+
inputSourceMap?: unknown
158+
) {
159+
// ...
111160
const result = generate(ast, {
112161
sourceMaps: true,
113162
sourceFileName: id,
114163
inputSourceMap,
115164
jsescOption: { minimal: true },
116165
});
166+
}
117167
```
118168

119169
Keep the rest of the transform unchanged. This spec is only about source-map composition for rewritten user call sites; synthetic generated statements do not need bespoke original-source mapping.

0 commit comments

Comments
 (0)