Skip to content

Commit

Permalink
wip part 2 suddenly broken
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Oct 7, 2024
1 parent 22b7bac commit 51c4a69
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
24 changes: 15 additions & 9 deletions packages/qwik/src/optimizer/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,20 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
const match = /^(.*\.[mc]?[jt]sx?)_([^/]+)_([^_]+)\.js($|\?)/.exec(pathId);
if (match) {
const [, parentId, name, hash] = match;
debug(`resolveId(${count})`, `resolved to QRL ${name}_${hash} of ${parentId}`);
// Save for quick lookup
knownQrls.set(hash, parentId);
result = {
id: pathId + parsedId.query,
// QRL segments can't have side effects. Probably never useful, but it's here for consistency
moduleSideEffects: false,
};
return ctx.resolve(parentId, importerId, { skipSelf: true }).then((resolved) => {
if (resolved) {
debug(`resolveId(${count})`, `resolved to QRL ${name}_${hash} of ${parentId}`);
// Save for quick lookup
knownQrls.set(hash, resolved.id);
return {
id: pathId + parsedId.query,
// QRL segments can't have side effects. Probably never useful, but it's here for consistency
moduleSideEffects: false,
};
} else {
debug(`resolveId(${count})`, `${parentId} does not exist`);
}
});
} else if (importerId) {
/**
* When we get here it's neither a virtual module nor a QRL segment. However, Rollup can ask
Expand Down Expand Up @@ -861,7 +867,7 @@ export const manifest = ${JSON.stringify(manifest)};\n`;
for (const outputs of [clientTransformedOutputs, serverTransformedOutputs]) {
for (const [key, [_, parentId]] of outputs) {
if (parentId === id) {
debug('handleHotUpdate()', `invalidate segment ${key}`);
debug('handleHotUpdate()', `invalidate ${id} segment ${key}`);
outputs.delete(key);
const mod = ctx.server.moduleGraph.getModuleById(key);
if (mod) {
Expand Down
30 changes: 19 additions & 11 deletions packages/qwik/src/optimizer/src/plugins/plugin.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,43 +222,51 @@ describe('resolveId', () => {
test('qrls', async () => {
const plugin = await mockPlugin();
expect(plugin.resolveId(null!, 'foo', undefined)).toBeFalsy();
expect(
const ctx = { resolve: async () => ({ id: 'Yey' }) } as any;
await expect(
plugin.resolveId(
null!,
ctx,
'/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js',
undefined
)
).toHaveProperty('id', '/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js');
).resolves.toHaveProperty(
'id',
'/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js'
);
expect(
plugin.resolveId(null!, '/root/src/routes/layout.tsx_s_7xk04rim0vu.js', undefined)
await plugin.resolveId(ctx, '/root/src/routes/layout.tsx_s_7xk04rim0vu.js', undefined)
).toHaveProperty('id', '/root/src/routes/layout.tsx_s_7xk04rim0vu.js');
expect(plugin.resolveId(null!, './foo', '/root/src/routes/layout.tsx')).toBeFalsy();
expect(
plugin.resolveId(
null!,
await plugin.resolveId(
ctx,
'./layout.tsx_layout_component_usetask_1_7xk04rim0vu.js',
'/root/src/routes/layout.tsx'
)
).toHaveProperty('id', '/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js');
// this uses the already populated id we created above
expect(
plugin.resolveId(
await plugin.resolveId(
{
resolve: (id: string, importer: string) => {
expect(id).toBe('/root/src/routes/foo');
expect(importer).toBe('/root/src/routes/layout.tsx');
return 'hi';
expect(importer).toBe('Yey');
return { id: 'hi' };
},
} as any,
'./foo',
'/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js'
)
).toBe('hi');
).toEqual({ id: 'hi' });
});
test('win32', async () => {
const plugin = await mockPlugin('win32');
expect(
plugin.resolveId(null!, 'C:\\src\\routes\\layout.tsx_s_7xk04rim0vu.js', undefined)
await plugin.resolveId(
{ resolve: async () => 'Yey' } as any,
'C:\\src\\routes\\layout.tsx_s_7xk04rim0vu.js',
undefined
)
).toHaveProperty('id', 'C:/src/routes/layout.tsx_s_7xk04rim0vu.js');
});
test('libs', async () => {
Expand Down

0 comments on commit 51c4a69

Please sign in to comment.