Skip to content

Commit 5c07b02

Browse files
CopilotElMassimo
andauthored
fix: handle prefixed virtual ids in pages filter hooks
Agent-Logs-Url: https://github.com/ElMassimo/iles/sessions/2f29b5ee-5bf6-4265-aed8-abd9fd19681f Co-authored-by: ElMassimo <1158253+ElMassimo@users.noreply.github.com>
1 parent 8a3191b commit 5c07b02

2 files changed

Lines changed: 15 additions & 27 deletions

File tree

packages/iles/src/node/build/islands.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,21 @@ export async function bundleIslands (config: AppConfig, islandsByPath: IslandsBy
5656
}
5757

5858
function virtualEntrypointsPlugin (root: string, entrypoints: Record<string, string>): Plugin {
59-
const escapeRegex = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
60-
const entryIds = Object.keys(entrypoints)
61-
const entrypointIdFilter = entryIds.length > 0
62-
? new RegExp(`^(?:${entryIds.map(escapeRegex).join('|')})$`)
63-
: /^$/
64-
const turboIdFilter = /(?:^|[\\/])iles[\\/]turbo(?:\?|$)/
65-
6659
return {
6760
name: 'iles:entrypoints',
68-
resolveId: {
69-
filter: { id: [entrypointIdFilter, turboIdFilter] },
70-
handler (id, importer) {
71-
if (id in entrypoints)
72-
return VIRTUAL_PREFIX + id
61+
resolveId (id, importer) {
62+
if (id in entrypoints)
63+
return VIRTUAL_PREFIX + id
7364

74-
if (relative(root, id.split('?', 2)[0]) === VIRTUAL_TURBO_ID)
75-
return VIRTUAL_TURBO_ID
76-
},
65+
if (relative(root, id.split('?', 2)[0]) === VIRTUAL_TURBO_ID)
66+
return VIRTUAL_TURBO_ID
7767
},
78-
load: {
79-
filter: { id: { include: [/^virtual_ile_/, VIRTUAL_TURBO_ID] } },
80-
async handler (id) {
81-
if (id.startsWith(VIRTUAL_PREFIX))
82-
return entrypoints[id.slice(VIRTUAL_PREFIX.length)]
68+
async load (id) {
69+
if (id.startsWith(VIRTUAL_PREFIX))
70+
return entrypoints[id.slice(VIRTUAL_PREFIX.length)]
8371

84-
if (id === VIRTUAL_TURBO_ID)
85-
return await fs.readFile(TURBO_SCRIPT_PATH, 'utf-8')
86-
},
72+
if (id === VIRTUAL_TURBO_ID)
73+
return await fs.readFile(TURBO_SCRIPT_PATH, 'utf-8')
8774
},
8875
}
8976
}

packages/pages/src/pages.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { MODULE_ID } from './types'
88

99
export * from './types'
1010

11-
const moduleIdRegex = new RegExp(`^${MODULE_ID.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`)
11+
const escapedModuleId = MODULE_ID.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
12+
const moduleIdRegex = new RegExp(`^(?:\\0|/@id/)?${escapedModuleId}(?:\\?.*)?$`)
1213

1314
/**
1415
* An iles module that injects remark plugins to parse pages and expose it
@@ -68,14 +69,14 @@ export default function IlesPages (): any {
6869
resolveId: {
6970
filter: { id: moduleIdRegex },
7071
async handler (id) {
71-
if (id === MODULE_ID)
72+
if (moduleIdRegex.test(id))
7273
return MODULE_ID
7374
},
7475
},
7576
load: {
76-
filter: { id: MODULE_ID },
77+
filter: { id: moduleIdRegex },
7778
async handler (id) {
78-
if (id === MODULE_ID)
79+
if (moduleIdRegex.test(id))
7980
return generatedRoutes ||= await api.generateRoutesModule()
8081
},
8182
},

0 commit comments

Comments
 (0)