Skip to content

Commit

Permalink
Merge branch 'main' into add-base-url
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx authored Dec 10, 2024
2 parents 5472ba9 + 100d81f commit 4ece46c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/vite/src/esbuild-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ export class EsBuildRequestAdapter implements RequestAdapter<Resolution<OnResolv
// and non-strict handlebars (which resolves
// components/helpers/modifiers against the app's global pool).
let pkg = this.packageCache.ownerOfFile(result.path);
if (pkg?.root === this.packageCache.appRoot) {
if (
pkg?.root === this.packageCache.appRoot &&
// vite provides node built-in polyfills under a custom namespace and we dont
// want to interrupt that. We'd prefer they get bundled in the dep optimizer normally,
// rather than getting deferred to the app build (which also works, but means they didn't
// get pre-optimized).
(result.namespace === 'file' || result.namespace.startsWith('embroider-'))
) {
let externalizedName = request.specifier;
if (!packageName(externalizedName)) {
// the request was a relative path. This won't remain valid once
Expand Down
14 changes: 14 additions & 0 deletions packages/vite/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ export function resolver(): Plugin {
}
}
});
return () => {
server.middlewares.use((req, _res, next) => {
const base = server.config.base || '/';
const originalUrl = req.originalUrl!.slice(base.length - 1);
if (originalUrl && originalUrl.length > 1) {
if (originalUrl?.match(/^\/tests($|\?)/)) {
req.originalUrl = `${base}tests/index.html`;
(req as any).url = `${base}tests/index.html`;
return next();
}
}
return next();
});
};
},

async resolveId(source, importer, options) {
Expand Down
2 changes: 1 addition & 1 deletion test-packages/support/testem-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function testemProxy(targetURL: string, base = '/') {
req.url = req.url.replace(base, '/');
return next();
}
let m = /^(\/\d+).*\/tests\/index.html/.exec(url);
let m = /^(\/\d+).*\/tests($|.)+/.exec(url);
if (m) {
url = url.slice(m[1].length);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/vite-internals-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function buildViteInternalsTest(testNonColocatedTemplates: boolean, app: Project
'use strict';
module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests?hidepassed',
disable_watching: true,
launch_in_ci: ['Chrome'],
launch_in_dev: ['Chrome'],
Expand Down

0 comments on commit 4ece46c

Please sign in to comment.