Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dev): path handling in dev #7180

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-spies-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik': patch
---

FIX: click-to-component works again, and path handling inside the optimizer is simplified.
4 changes: 2 additions & 2 deletions packages/docs/src/routes/api/qwik-optimizer/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@
}
],
"kind": "Interface",
"content": "```typescript\nexport interface TransformModuleInput \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[code](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[devPath?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[path](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"content": "```typescript\nexport interface TransformModuleInput \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[code](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[path](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts",
"mdFile": "qwik.transformmoduleinput.md"
},
Expand Down Expand Up @@ -922,4 +922,4 @@
"mdFile": "qwik.versions.md"
}
]
}
}
15 changes: 0 additions & 15 deletions packages/docs/src/routes/api/qwik-optimizer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3149,21 +3149,6 @@ string
</td></tr>
<tr><td>

[devPath?](#)

</td><td>

</td><td>

string

</td><td>

_(Optional)_

</td></tr>
<tr><td>

[path](#)

</td><td>
Expand Down
10 changes: 4 additions & 6 deletions packages/qwik-city/src/buildtime/vite/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {
RequestEvent,
RouteModule,
} from '../../runtime/src/types';
import { getExtension, normalizePath } from '../../utils/fs';
import { getExtension } from '../../utils/fs';
import { updateBuildContext } from '../build';
import type { BuildContext, BuildRoute } from '../types';
import { formatError } from './format-error';
Expand Down Expand Up @@ -416,9 +416,7 @@ const levenshteinDistance = (s: string, t: string) => {
*/
export function staticDistMiddleware({ config }: ViteDevServer) {
const distDirs = new Set(
['dist', config.build.outDir, config.publicDir].map((d) =>
normalizePath(resolve(config.root, d))
)
['dist', config.build.outDir, config.publicDir].map((d) => resolve(config.root, d))
);

return async (req: Connect.IncomingMessage, res: ServerResponse, next: Connect.NextFunction) => {
Expand Down Expand Up @@ -475,9 +473,9 @@ function formatDevSerializeError(err: any, routeModulePaths: WeakMap<RouteModule
try {
const code = fs.readFileSync(filePath, 'utf-8');
err.plugin = 'vite-plugin-qwik-city';
err.id = normalizePath(filePath);
err.id = filePath;
err.loc = {
file: err.id,
file: filePath,
line: undefined,
column: undefined,
};
Expand Down
3 changes: 1 addition & 2 deletions packages/qwik-city/src/buildtime/vite/format-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
findLocation,
generateCodeFrame,
} from '../../../../qwik/src/optimizer/src/plugins/vite-utils';
import { normalizePath } from '../../utils/fs';
import fs from 'node:fs';

export function formatError(e: any) {
Expand All @@ -16,7 +15,7 @@ export function formatError(e: any) {
if (loc) {
err.loc = loc;
if (loc.file) {
err.id = normalizePath(err.loc.file);
err.id = err.loc.file;
try {
const code = fs.readFileSync(err.loc.file, 'utf-8');
err.frame = generateCodeFrame(code, err.loc);
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-city/src/buildtime/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { loadEnv } from 'vite';
import { generateQwikCityPlan } from '../runtime-generation/generate-qwik-city-plan';
import type { BuildContext } from '../types';
import { createBuildContext, resetBuildContext } from '../context';
import { isMenuFileName, normalizePath, removeExtension } from '../../utils/fs';
import { isMenuFileName, removeExtension } from '../../utils/fs';
import { validatePlugin } from './validate-plugin';
import type { QwikCityPluginApi, QwikCityVitePluginOptions } from './types';
import { build } from '../build';
Expand Down Expand Up @@ -248,7 +248,7 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {
for (const fileName in bundles) {
const c = bundles[fileName];
if (c.type === 'chunk' && c.isDynamicEntry && c.facadeModuleId) {
const extensionlessFilePath = removeExtension(normalizePath(c.facadeModuleId));
const extensionlessFilePath = removeExtension(c.facadeModuleId);
if (entry.extensionlessFilePath === extensionlessFilePath) {
c.fileName = entry.chunkFileName;
continue;
Expand Down
66 changes: 0 additions & 66 deletions packages/qwik/src/optimizer/core/src/add_side_effect.rs

This file was deleted.

11 changes: 2 additions & 9 deletions packages/qwik/src/optimizer/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#[cfg(test)]
mod test;

mod add_side_effect;
mod clean_side_effects;
mod code_move;
mod collector;
Expand Down Expand Up @@ -82,7 +81,6 @@ pub struct TransformFsOptions {
#[serde(rename_all = "camelCase")]
pub struct TransformModuleInput {
pub path: String,
pub dev_path: Option<String>,
pub code: String,
}

Expand Down Expand Up @@ -135,10 +133,8 @@ pub fn transform_fs(config: TransformFsOptions) -> Result<TransformOutput, Error

let relative_path = pathdiff::diff_paths(path, &config.src_dir).unwrap();
transform_code(TransformCodeOptions {
src_dir,
src_path: relative_path.to_str().unwrap(),
root_dir,
relative_path: relative_path.to_str().unwrap(),
dev_path: None,
minify: config.minify,
code: &code,
explicit_extensions: config.explicit_extensions,
Expand Down Expand Up @@ -170,7 +166,6 @@ pub fn transform_modules(config: TransformModulesOptions) -> Result<TransformOut
let core_module = config
.core_module
.map_or(BUILDER_IO_QWIK.clone(), |s| s.into());
let src_dir = std::path::Path::new(&config.src_dir);
let root_dir = config.root_dir.as_ref().map(Path::new);

let entry_policy = &*parse_entry_strategy(&config.entry_strategy, config.manual_chunks);
Expand All @@ -182,10 +177,8 @@ pub fn transform_modules(config: TransformModulesOptions) -> Result<TransformOut

let iterator = iterator.map(|input| -> Result<TransformOutput, Error> {
transform_code(TransformCodeOptions {
src_dir,
src_path: &input.path,
root_dir,
relative_path: &input.path,
dev_path: input.dev_path.as_deref(),
code: &input.code,
minify: config.minify,
source_maps: config.source_maps,
Expand Down
Loading
Loading