@tanstack/start-plugin-core 1.163.0 → 1.163.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/import-protection-plugin/plugin.d.ts +0 -1
- package/dist/esm/import-protection-plugin/plugin.js +30 -57
- package/dist/esm/import-protection-plugin/plugin.js.map +1 -1
- package/dist/esm/import-protection-plugin/virtualModules.d.ts +18 -6
- package/dist/esm/import-protection-plugin/virtualModules.js +50 -9
- package/dist/esm/import-protection-plugin/virtualModules.js.map +1 -1
- package/package.json +6 -6
- package/src/import-protection-plugin/INTERNALS.md +25 -17
- package/src/import-protection-plugin/plugin.ts +65 -96
- package/src/import-protection-plugin/virtualModules.ts +85 -13
|
@@ -6,7 +6,7 @@ import { relativizePath } from './utils'
|
|
|
6
6
|
import type { ViolationInfo } from './trace'
|
|
7
7
|
|
|
8
8
|
export const MOCK_MODULE_ID = 'tanstack-start-import-protection:mock'
|
|
9
|
-
|
|
9
|
+
const RESOLVED_MOCK_MODULE_ID = resolveViteId(MOCK_MODULE_ID)
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Per-violation mock prefix used in build+error mode.
|
|
@@ -14,17 +14,63 @@ export const RESOLVED_MOCK_MODULE_ID = resolveViteId(MOCK_MODULE_ID)
|
|
|
14
14
|
* survived tree-shaking in `generateBundle`.
|
|
15
15
|
*/
|
|
16
16
|
export const MOCK_BUILD_PREFIX = 'tanstack-start-import-protection:mock:build:'
|
|
17
|
-
|
|
17
|
+
const RESOLVED_MOCK_BUILD_PREFIX = resolveViteId(MOCK_BUILD_PREFIX)
|
|
18
18
|
|
|
19
19
|
export const MOCK_EDGE_PREFIX = 'tanstack-start-import-protection:mock-edge:'
|
|
20
|
-
|
|
20
|
+
const RESOLVED_MOCK_EDGE_PREFIX = resolveViteId(MOCK_EDGE_PREFIX)
|
|
21
21
|
|
|
22
22
|
export const MOCK_RUNTIME_PREFIX =
|
|
23
23
|
'tanstack-start-import-protection:mock-runtime:'
|
|
24
|
-
|
|
24
|
+
const RESOLVED_MOCK_RUNTIME_PREFIX = resolveViteId(MOCK_RUNTIME_PREFIX)
|
|
25
25
|
|
|
26
26
|
export const MARKER_PREFIX = 'tanstack-start-import-protection:marker:'
|
|
27
|
-
|
|
27
|
+
const RESOLVED_MARKER_PREFIX = resolveViteId(MARKER_PREFIX)
|
|
28
|
+
|
|
29
|
+
const RESOLVED_MARKER_SERVER_ONLY = resolveViteId(`${MARKER_PREFIX}server-only`)
|
|
30
|
+
const RESOLVED_MARKER_CLIENT_ONLY = resolveViteId(`${MARKER_PREFIX}client-only`)
|
|
31
|
+
|
|
32
|
+
export function resolvedMarkerVirtualModuleId(
|
|
33
|
+
kind: 'server' | 'client',
|
|
34
|
+
): string {
|
|
35
|
+
return kind === 'server'
|
|
36
|
+
? RESOLVED_MARKER_SERVER_ONLY
|
|
37
|
+
: RESOLVED_MARKER_CLIENT_ONLY
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Convenience list for plugin `load` filters/handlers.
|
|
42
|
+
*
|
|
43
|
+
* Vite/Rollup call `load(id)` with the *resolved* virtual id (prefixed by `\0`).
|
|
44
|
+
* `resolveId(source)` sees the *unresolved* id/prefix (without `\0`).
|
|
45
|
+
*/
|
|
46
|
+
export function getResolvedVirtualModuleMatchers(): ReadonlyArray<string> {
|
|
47
|
+
return RESOLVED_VIRTUAL_MODULE_MATCHERS
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const RESOLVED_VIRTUAL_MODULE_MATCHERS = [
|
|
51
|
+
RESOLVED_MOCK_MODULE_ID,
|
|
52
|
+
RESOLVED_MOCK_BUILD_PREFIX,
|
|
53
|
+
RESOLVED_MOCK_EDGE_PREFIX,
|
|
54
|
+
RESOLVED_MOCK_RUNTIME_PREFIX,
|
|
55
|
+
RESOLVED_MARKER_PREFIX,
|
|
56
|
+
] as const
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Resolve import-protection's internal virtual module IDs.
|
|
60
|
+
*
|
|
61
|
+
* `resolveId(source)` sees *unresolved* ids/prefixes (no `\0`).
|
|
62
|
+
* Returning a resolved id (with `\0`) ensures Vite/Rollup route it to `load`.
|
|
63
|
+
*/
|
|
64
|
+
export function resolveInternalVirtualModuleId(
|
|
65
|
+
source: string,
|
|
66
|
+
): string | undefined {
|
|
67
|
+
if (source === MOCK_MODULE_ID) return RESOLVED_MOCK_MODULE_ID
|
|
68
|
+
if (source.startsWith(MOCK_EDGE_PREFIX)) return resolveViteId(source)
|
|
69
|
+
if (source.startsWith(MOCK_RUNTIME_PREFIX)) return resolveViteId(source)
|
|
70
|
+
if (source.startsWith(MOCK_BUILD_PREFIX)) return resolveViteId(source)
|
|
71
|
+
if (source.startsWith(MARKER_PREFIX)) return resolveViteId(source)
|
|
72
|
+
return undefined
|
|
73
|
+
}
|
|
28
74
|
|
|
29
75
|
function toBase64Url(input: string): string {
|
|
30
76
|
return Buffer.from(input, 'utf8').toString('base64url')
|
|
@@ -87,7 +133,8 @@ export function makeMockEdgeModuleId(
|
|
|
87
133
|
* (property access for primitive coercion, calls, construction, sets).
|
|
88
134
|
*
|
|
89
135
|
* When `diagnostics` is omitted, the mock is completely silent — suitable
|
|
90
|
-
* for
|
|
136
|
+
* for base mock modules (e.g. `MOCK_MODULE_ID` or per-violation build mocks)
|
|
137
|
+
* that are consumed by mock-edge modules providing explicit named exports.
|
|
91
138
|
*/
|
|
92
139
|
function generateMockCode(diagnostics?: {
|
|
93
140
|
meta: {
|
|
@@ -170,7 +217,8 @@ function __report(action, accessPath) {
|
|
|
170
217
|
: ''
|
|
171
218
|
|
|
172
219
|
return `
|
|
173
|
-
${preamble}
|
|
220
|
+
${preamble}/* @__NO_SIDE_EFFECTS__ */
|
|
221
|
+
function ${fnName}(name) {
|
|
174
222
|
const fn = function () {};
|
|
175
223
|
fn.prototype.name = name;
|
|
176
224
|
const children = Object.create(null);
|
|
@@ -197,16 +245,13 @@ ${preamble}function ${fnName}(name) {
|
|
|
197
245
|
});
|
|
198
246
|
return proxy;
|
|
199
247
|
}
|
|
200
|
-
const mock = ${fnName}('mock');
|
|
248
|
+
const mock = /* @__PURE__ */ ${fnName}('mock');
|
|
201
249
|
export default mock;
|
|
202
250
|
`
|
|
203
251
|
}
|
|
204
252
|
|
|
205
|
-
export function loadSilentMockModule(): {
|
|
206
|
-
|
|
207
|
-
code: string
|
|
208
|
-
} {
|
|
209
|
-
return { syntheticNamedExports: true, code: generateMockCode() }
|
|
253
|
+
export function loadSilentMockModule(): { code: string } {
|
|
254
|
+
return { code: generateMockCode() }
|
|
210
255
|
}
|
|
211
256
|
|
|
212
257
|
export function loadMockEdgeModule(encodedPayload: string): { code: string } {
|
|
@@ -292,3 +337,30 @@ const MARKER_MODULE_RESULT = { code: 'export {}' } as const
|
|
|
292
337
|
export function loadMarkerModule(): { code: string } {
|
|
293
338
|
return MARKER_MODULE_RESULT
|
|
294
339
|
}
|
|
340
|
+
|
|
341
|
+
export function loadResolvedVirtualModule(
|
|
342
|
+
id: string,
|
|
343
|
+
): { code: string } | undefined {
|
|
344
|
+
if (id === RESOLVED_MOCK_MODULE_ID) {
|
|
345
|
+
return loadSilentMockModule()
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Per-violation build mock modules — same silent mock code
|
|
349
|
+
if (id.startsWith(RESOLVED_MOCK_BUILD_PREFIX)) {
|
|
350
|
+
return loadSilentMockModule()
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (id.startsWith(RESOLVED_MOCK_EDGE_PREFIX)) {
|
|
354
|
+
return loadMockEdgeModule(id.slice(RESOLVED_MOCK_EDGE_PREFIX.length))
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (id.startsWith(RESOLVED_MOCK_RUNTIME_PREFIX)) {
|
|
358
|
+
return loadMockRuntimeModule(id.slice(RESOLVED_MOCK_RUNTIME_PREFIX.length))
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (id.startsWith(RESOLVED_MARKER_PREFIX)) {
|
|
362
|
+
return loadMarkerModule()
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return undefined
|
|
366
|
+
}
|