Skip to content
Merged
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
10 changes: 7 additions & 3 deletions src/load-config-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { loadConfig, OutputTargetWww } from '@stencil/core/compiler';
import { findUp } from 'find-up';
import { existsSync } from 'fs';
import { join, relative } from 'path';
import { isAbsolute, join, relative } from 'path';

/**
* Common shape for output targets with dir and buildDir properties.
Expand Down Expand Up @@ -54,7 +54,9 @@ export const loadConfigMeta = async (cwd?: string) => {

if (wwwTarget) {
// Get path from dev-server root to www
const relativePath = relative(devServer.root!, wwwTarget.dir!);
// If dir is relative, it's already relative to project root (same as devServer.root)
const wwwDir = wwwTarget.dir!;
const relativePath = isAbsolute(wwwDir) ? relative(devServer.root!, wwwDir) : wwwDir;

// Use buildDir from config (defaults to 'build' for www target)
const buildDir = (wwwTarget as unknown as { buildDir?: string }).buildDir ?? 'build';
Expand All @@ -65,7 +67,9 @@ export const loadConfigMeta = async (cwd?: string) => {
const target = distTarget ?? loaderBundleTarget!;

// Get path from dev-server root to target dir
const relativePath = relative(devServer.root!, target.dir!);
// If dir is relative, it's already relative to project root (same as devServer.root)
const targetDir = target.dir!;
const relativePath = isAbsolute(targetDir) ? relative(devServer.root!, targetDir) : targetDir;

// dist/loader-bundle use empty string as default buildDir
// Path structure: dir/buildDir/namespace/namespace (extra namespace folder)
Expand Down
20 changes: 20 additions & 0 deletions src/test/load-config-meta.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ describe('loadConfigMeta', () => {
});
});

it('should handle loader-bundle target with relative dir path', async () => {
stencilConfig.outputTargets = [
{
type: 'loader-bundle',
dir: 'dist/loader-bundle', // relative path, not absolute
},
];
existsSyncMock.mockReturnValueOnce(true);
findUpMock.mockResolvedValueOnce('/mock-path/stencil.config.ts');

const configMeta = await loadConfigMeta();

expect(configMeta).toEqual({
baseURL: 'http://localhost:4444',
stencilEntryPath: './dist/loader-bundle/mock-namespace/mock-namespace',
stencilNamespace: 'mock-namespace',
webServerUrl: 'http://localhost:4444/status',
});
});

it('should log a warning if no Stencil config path was found', async () => {
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});

Expand Down
Loading