Skip to content

Commit

Permalink
lint: rust/optimizer plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Nov 4, 2024
1 parent 4a22dd1 commit a9a9c96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
3 changes: 0 additions & 3 deletions packages/qwik/src/optimizer/core/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,6 @@ impl<'a> QwikTransform<'a> {
JsWord::from(
self.options
.dev_path
.as_deref()
.unwrap_or(&self.options.path_data.abs_path.to_slash_lossy()),
),
segment_data,
Expand Down Expand Up @@ -1032,7 +1031,6 @@ impl<'a> QwikTransform<'a> {
JsWord::from(
self.options
.dev_path
.as_deref()
.unwrap_or(&self.options.path_data.abs_path.to_slash_lossy()),
),
&segment_data,
Expand Down Expand Up @@ -1685,7 +1683,6 @@ impl<'a> QwikTransform<'a> {
JsWord::from(
self.options
.dev_path
.as_deref()
.unwrap_or(&self.options.path_data.abs_path.to_slash_lossy()),
),
&segment_data,
Expand Down
10 changes: 6 additions & 4 deletions packages/qwik/src/optimizer/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,18 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {

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

// uncomment to show transform results
debug({ isServer, strip }, transformOpts, newOutput);
// debug({ isServer, strip }, transformOpts, newOutput);
diagnosticsCallback(newOutput.diagnostics, optimizer, srcDir);

if (isServer) {
Expand Down
22 changes: 13 additions & 9 deletions packages/qwik/src/optimizer/src/plugins/plugin.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ test('experimental[]', async () => {
describe('resolveId', () => {
test('qrls', async () => {
const plugin = await mockPlugin();
expect(plugin.resolveId(null!, 'foo', undefined)).toBeFalsy();
expect(await plugin.resolveId(null!, 'foo', undefined)).toBeFalsy();
const ctx = { resolve: async () => ({ id: 'Yey' }) } as any;
await expect(
plugin.resolveId(
Expand All @@ -236,7 +236,7 @@ describe('resolveId', () => {
expect(
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(await plugin.resolveId(null!, './foo', '/root/src/routes/layout.tsx')).toBeFalsy();
expect(
await plugin.resolveId(
ctx,
Expand All @@ -263,25 +263,29 @@ describe('resolveId', () => {
const plugin = await mockPlugin('win32');
expect(
await plugin.resolveId(
{ resolve: async () => 'Yey' } as any,
{
resolve: async () => ({
id: '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 () => {
const plugin = await mockPlugin();
expect(plugin.resolveId(null!, '@builder.io/qwik/build', undefined)).toHaveProperty(
expect(await plugin.resolveId(null!, '@builder.io/qwik/build', undefined)).toHaveProperty(
'id',
'/@builder.io/qwik/build'
'@builder.io/qwik/build'
);
expect(plugin.resolveId(null!, '/@builder.io/qwik/build', undefined)).toHaveProperty(
expect(await plugin.resolveId(null!, '/@builder.io/qwik/build', undefined)).toHaveProperty(
'id',
'/@builder.io/qwik/build'
'@builder.io/qwik/build'
);
expect(plugin.resolveId(null!, '@qwik-client-manifest', '/foo/bar')).toHaveProperty(
expect(await plugin.resolveId(null!, '@qwik-client-manifest', '/foo/bar')).toHaveProperty(
'id',
'/@qwik-client-manifest'
'@qwik-client-manifest'
);
});
});
Expand Down

0 comments on commit a9a9c96

Please sign in to comment.