Skip to content

Commit 546d3b0

Browse files
committed
lint: rust/optimizer plugin
1 parent 4a22dd1 commit 546d3b0

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

packages/qwik/src/optimizer/core/src/transform.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,6 @@ impl<'a> QwikTransform<'a> {
959959
JsWord::from(
960960
self.options
961961
.dev_path
962-
.as_deref()
963962
.unwrap_or(&self.options.path_data.abs_path.to_slash_lossy()),
964963
),
965964
segment_data,
@@ -1032,7 +1031,6 @@ impl<'a> QwikTransform<'a> {
10321031
JsWord::from(
10331032
self.options
10341033
.dev_path
1035-
.as_deref()
10361034
.unwrap_or(&self.options.path_data.abs_path.to_slash_lossy()),
10371035
),
10381036
&segment_data,
@@ -1685,7 +1683,6 @@ impl<'a> QwikTransform<'a> {
16851683
JsWord::from(
16861684
self.options
16871685
.dev_path
1688-
.as_deref()
16891686
.unwrap_or(&self.options.path_data.abs_path.to_slash_lossy()),
16901687
),
16911688
&segment_data,

packages/qwik/src/optimizer/src/plugins/plugin.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,18 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
493493

494494
const resolvedParent = await ctx.resolve(parent, importerId, { skipSelf: true });
495495
if (resolvedParent) {
496+
// Vite likes to add ?v=1234... to the end of the id
497+
const parentId = resolvedParent.id.split('?')[0];
496498
/**
497499
* A request possibly from the browser. It could be our own QRL request or an import URL
498500
* generated by vite. In any case, only Vite fully knows how to resolve it. Therefore, we
499501
* must recombine the resolved parent path with the QRL name.
500502
*/
501503
const isDevUrl = devServer && importerId?.endsWith('.html');
502-
const resolvedId = isDevUrl ? `${resolvedParent.id}_${name}.js` : pathId;
503-
debug(`resolveId(${count})`, `resolved to QRL ${name} of ${resolvedParent.id}`);
504+
const resolvedId = isDevUrl ? `${parentId}_${name}.js` : pathId;
505+
debug(`resolveId(${count})`, `resolved to QRL ${name} of ${parentId}`);
504506
// Save for lookup by load()
505-
parentIds.set(resolvedId, resolvedParent.id);
507+
parentIds.set(resolvedId, parentId);
506508
result = {
507509
id: resolvedId + query,
508510
// QRL segments can't have side effects. Probably never useful, but it's here for consistency
@@ -689,7 +691,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
689691
const module = newOutput.modules.find((mod) => !isAdditionalFile(mod))!;
690692

691693
// uncomment to show transform results
692-
debug({ isServer, strip }, transformOpts, newOutput);
694+
// debug({ isServer, strip }, transformOpts, newOutput);
693695
diagnosticsCallback(newOutput.diagnostics, optimizer, srcDir);
694696

695697
if (isServer) {

packages/qwik/src/optimizer/src/plugins/plugin.unit.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ test('experimental[]', async () => {
221221
describe('resolveId', () => {
222222
test('qrls', async () => {
223223
const plugin = await mockPlugin();
224-
expect(plugin.resolveId(null!, 'foo', undefined)).toBeFalsy();
224+
expect(await plugin.resolveId(null!, 'foo', undefined)).toBeFalsy();
225225
const ctx = { resolve: async () => ({ id: 'Yey' }) } as any;
226226
await expect(
227227
plugin.resolveId(
@@ -236,7 +236,7 @@ describe('resolveId', () => {
236236
expect(
237237
await plugin.resolveId(ctx, '/root/src/routes/layout.tsx_s_7xk04rim0vu.js', undefined)
238238
).toHaveProperty('id', '/root/src/routes/layout.tsx_s_7xk04rim0vu.js');
239-
expect(plugin.resolveId(null!, './foo', '/root/src/routes/layout.tsx')).toBeFalsy();
239+
expect(await plugin.resolveId(null!, './foo', '/root/src/routes/layout.tsx')).toBeFalsy();
240240
expect(
241241
await plugin.resolveId(
242242
ctx,
@@ -263,25 +263,29 @@ describe('resolveId', () => {
263263
const plugin = await mockPlugin('win32');
264264
expect(
265265
await plugin.resolveId(
266-
{ resolve: async () => 'Yey' } as any,
266+
{
267+
resolve: async () => ({
268+
id: 'Yey',
269+
}),
270+
} as any,
267271
'C:\\src\\routes\\layout.tsx_s_7xk04rim0vu.js',
268272
undefined
269273
)
270274
).toHaveProperty('id', 'C:/src/routes/layout.tsx_s_7xk04rim0vu.js');
271275
});
272276
test('libs', async () => {
273277
const plugin = await mockPlugin();
274-
expect(plugin.resolveId(null!, '@builder.io/qwik/build', undefined)).toHaveProperty(
278+
expect(await plugin.resolveId(null!, '@builder.io/qwik/build', undefined)).toHaveProperty(
275279
'id',
276-
'/@builder.io/qwik/build'
280+
'@builder.io/qwik/build'
277281
);
278-
expect(plugin.resolveId(null!, '/@builder.io/qwik/build', undefined)).toHaveProperty(
282+
expect(await plugin.resolveId(null!, '/@builder.io/qwik/build', undefined)).toHaveProperty(
279283
'id',
280-
'/@builder.io/qwik/build'
284+
'@builder.io/qwik/build'
281285
);
282-
expect(plugin.resolveId(null!, '@qwik-client-manifest', '/foo/bar')).toHaveProperty(
286+
expect(await plugin.resolveId(null!, '@qwik-client-manifest', '/foo/bar')).toHaveProperty(
283287
'id',
284-
'/@qwik-client-manifest'
288+
'@qwik-client-manifest'
285289
);
286290
});
287291
});

packages/qwik/src/optimizer/src/plugins/vite-dev-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function createSymbolMapper(base: string): SymbolMapperFn {
4444
return [symbolName, `${base}${symbolName}.js`];
4545
}
4646
// In dev mode, the `parent` is the Vite URL for the parent, not the real absolute path.
47-
// It always has a starting slash.
48-
const qrlFile = `${base}${parent.slice(1)}_${symbolName}.js`;
47+
// It is always absolute but when on Windows that's without a /
48+
const qrlFile = `${base}${parent.startsWith('/') ? parent.slice(1) : parent}_${symbolName}.js`;
4949
return [symbolName, qrlFile];
5050
};
5151
}

0 commit comments

Comments
 (0)