From 695e43c14bf26f5fbe24b7dc6656882bbf58484b Mon Sep 17 00:00:00 2001 From: John Jenkins Date: Thu, 30 Apr 2026 21:02:19 +0100 Subject: [PATCH 1/2] fix: handle absolute output `buildDir` --- src/load-config-meta.ts | 18 +++- test-project/package-lock.json | 149 +++++++++++++++++++++++++++++++++ test-project/package.json | 8 ++ test-project/stencil.config.ts | 11 +++ test-project/test-config.mjs | 9 ++ 5 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 test-project/package-lock.json create mode 100644 test-project/package.json create mode 100644 test-project/stencil.config.ts create mode 100644 test-project/test-config.mjs diff --git a/src/load-config-meta.ts b/src/load-config-meta.ts index 4cc6213..4397a5f 100644 --- a/src/load-config-meta.ts +++ b/src/load-config-meta.ts @@ -2,7 +2,7 @@ import { loadConfig, OutputTargetWww } from '@stencil/core/compiler'; import { findUp } from 'find-up'; import { existsSync } from 'fs'; -import { isAbsolute, join, relative } from 'path'; +import { dirname, isAbsolute, join, relative } from 'path'; /** * Common shape for output targets with dir and buildDir properties. @@ -69,11 +69,23 @@ export const loadConfigMeta = async (cwd?: string) => { // Get path from dev-server root to 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; + + // Use stencil config directory as fallback if devServer.root is not usable + const configDir = dirname(stencilConfigPath); + const rootDir = devServer.root && devServer.root !== '/' ? devServer.root : configDir; + + const relativePath = isAbsolute(targetDir) ? relative(rootDir, targetDir) : targetDir; // dist/loader-bundle use empty string as default buildDir + // Stencil may resolve buildDir to absolute path, so we need to handle that + let buildDir = target.buildDir ?? ''; + if (buildDir && isAbsolute(buildDir)) { + // If buildDir is absolute, compute relative path from targetDir + // If buildDir equals targetDir, use empty string (no subdirectory) + buildDir = buildDir === targetDir ? '' : relative(targetDir, buildDir); + } + // Path structure: dir/buildDir/namespace/namespace (extra namespace folder) - const buildDir = target.buildDir ?? ''; const entryPath = join(relativePath, buildDir, fsNamespace, fsNamespace); stencilEntryPath = entryPath === '' ? '.' : entryPath.startsWith('.') ? entryPath : `./${entryPath}`; } else { diff --git a/test-project/package-lock.json b/test-project/package-lock.json new file mode 100644 index 0000000..c629133 --- /dev/null +++ b/test-project/package-lock.json @@ -0,0 +1,149 @@ +{ + "name": "test-stencil-project", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "test-stencil-project", + "devDependencies": { + "@stencil/core": "^4.0.0" + } + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.44.0.tgz", + "integrity": "sha512-VGF3wy0Eq1gcEIkSCr8Ke03CWT+Pm2yveKLaDvq51pPpZza3JX/ClxXOCmTYYq3us5MvEuNRTaeyFThCKRQhOA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.44.0.tgz", + "integrity": "sha512-fBkyrDhwquRvrTxSGH/qqt3/T0w5Rg0L7ZIDypvBPc1/gzjJle6acCpZ36blwuwcKD/u6oCE/sRWlUAcxLWQbQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.44.0.tgz", + "integrity": "sha512-ZTR2mxBHb4tK4wGf9b8SYg0Y6KQPjGpR4UWwTFdnmjB4qRtoATZ5dWn3KsDwGa5Z2ZBOE7K52L36J9LueKBdOQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.44.0.tgz", + "integrity": "sha512-GFWfAhVhWGd4r6UxmnKRTBwP1qmModHtd5gkraeW2G490BpFOZkFtem8yuX2NyafIP/mGpRJgTJ2PwohQkUY/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.44.0.tgz", + "integrity": "sha512-iUVJc3c0o8l9Sa/qlDL2Z9UP92UZZW1+EmQ4xfjTc1akr0iUFZNfxrXJ/R1T90h/ILm9iXEY6+iPrmYB3pXKjw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.44.0.tgz", + "integrity": "sha512-PQUobbhLTQT5yz/SPg116VJBgz+XOtXt8D1ck+sfJJhuEsMj2jSej5yTdp8CvWBSceu+WW+ibVL6dm0ptG5fcA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.44.0.tgz", + "integrity": "sha512-M0CpcHf8TWn+4oTxJfh7LQuTuaYeXGbk0eageVjQCKzYLsajWS/lFC94qlRqOlyC2KvRT90ZrfXULYmukeIy7w==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.44.0.tgz", + "integrity": "sha512-Q2Mgwt+D8hd5FIPUuPDsvPR7Bguza6yTkJxspDGkZj7tBRn2y4KSWYuIXpftFSjBra76TbKerCV7rgFPQrn+wQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@stencil/core": { + "version": "4.43.4", + "resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.43.4.tgz", + "integrity": "sha512-QWawMM1XIpSz4k+k+VyHZMr2YSxlCNAPWO/jTdJ+2kdgdN7ZQVEFZpc4WBm3E3mrDPTZ79lLcnIPa399bg4XOg==", + "dev": true, + "license": "MIT", + "bin": { + "stencil": "bin/stencil" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.10.0" + }, + "optionalDependencies": { + "@rollup/rollup-darwin-arm64": "4.44.0", + "@rollup/rollup-darwin-x64": "4.44.0", + "@rollup/rollup-linux-arm64-gnu": "4.44.0", + "@rollup/rollup-linux-arm64-musl": "4.44.0", + "@rollup/rollup-linux-x64-gnu": "4.44.0", + "@rollup/rollup-linux-x64-musl": "4.44.0", + "@rollup/rollup-win32-arm64-msvc": "4.44.0", + "@rollup/rollup-win32-x64-msvc": "4.44.0" + } + } + } +} diff --git a/test-project/package.json b/test-project/package.json new file mode 100644 index 0000000..827bccb --- /dev/null +++ b/test-project/package.json @@ -0,0 +1,8 @@ +{ + "name": "test-stencil-project", + "private": true, + "type": "module", + "devDependencies": { + "@stencil/core": "^4.0.0" + } +} diff --git a/test-project/stencil.config.ts b/test-project/stencil.config.ts new file mode 100644 index 0000000..e9194c7 --- /dev/null +++ b/test-project/stencil.config.ts @@ -0,0 +1,11 @@ +import { Config } from '@stencil/core'; + +export const config: Config = { + namespace: 'TestAssetsGlobalStyle', + outputTargets: [ + { + type: 'dist', + dir: 'dist/loader-bundle', + }, + ], +}; diff --git a/test-project/test-config.mjs b/test-project/test-config.mjs new file mode 100644 index 0000000..3778c8f --- /dev/null +++ b/test-project/test-config.mjs @@ -0,0 +1,9 @@ +import { createConfig } from '../dist/index.js'; + +try { + const config = await createConfig(); + console.log('stencilEntryPath:', process.env.STENCIL_ENTRY_PATH); + console.log('Config created successfully'); +} catch (e) { + console.error('Error:', e.message); +} From bfa3cf73efc50e9c421125b22f8b6d52d56f73f6 Mon Sep 17 00:00:00 2001 From: John Jenkins Date: Thu, 30 Apr 2026 21:52:20 +0100 Subject: [PATCH 2/2] fix: regression - default rootDir --- src/load-config-meta.ts | 20 +-- test-project/test-config.mjs | 9 -- .../explicit-dir}/package-lock.json | 0 .../explicit-dir}/package.json | 0 .../explicit-dir}/stencil.config.ts | 0 test-projects/explicit-dir/test-config.mjs | 4 + test-projects/www/package-lock.json | 149 ++++++++++++++++++ test-projects/www/package.json | 8 + test-projects/www/stencil.config.ts | 9 ++ test-projects/www/test-config.mjs | 4 + 10 files changed, 185 insertions(+), 18 deletions(-) delete mode 100644 test-project/test-config.mjs rename {test-project => test-projects/explicit-dir}/package-lock.json (100%) rename {test-project => test-projects/explicit-dir}/package.json (100%) rename {test-project => test-projects/explicit-dir}/stencil.config.ts (100%) create mode 100644 test-projects/explicit-dir/test-config.mjs create mode 100644 test-projects/www/package-lock.json create mode 100644 test-projects/www/package.json create mode 100644 test-projects/www/stencil.config.ts create mode 100644 test-projects/www/test-config.mjs diff --git a/src/load-config-meta.ts b/src/load-config-meta.ts index 4397a5f..efa0bfe 100644 --- a/src/load-config-meta.ts +++ b/src/load-config-meta.ts @@ -52,14 +52,22 @@ export const loadConfigMeta = async (cwd?: string) => { | OutputTargetWithDir | undefined; + // Use stencil config directory as fallback if devServer.root is not usable + const configDir = dirname(stencilConfigPath); + const rootDir = devServer.root && devServer.root !== '/' ? devServer.root : configDir; + if (wwwTarget) { // Get path from dev-server root to www - // 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; + const relativePath = isAbsolute(wwwDir) ? relative(rootDir, wwwDir) : wwwDir; // Use buildDir from config (defaults to 'build' for www target) - const buildDir = (wwwTarget as unknown as { buildDir?: string }).buildDir ?? 'build'; + // Stencil may resolve buildDir to absolute path, so we need to handle that + let buildDir = (wwwTarget as unknown as { buildDir?: string }).buildDir ?? 'build'; + if (buildDir && isAbsolute(buildDir)) { + buildDir = buildDir === wwwDir ? '' : relative(wwwDir, buildDir); + } + const entryPath = join(relativePath, buildDir, fsNamespace); stencilEntryPath = entryPath === '' ? '.' : entryPath.startsWith('.') ? entryPath : `./${entryPath}`; } else if (distTarget || loaderBundleTarget) { @@ -67,13 +75,7 @@ export const loadConfigMeta = async (cwd?: string) => { const target = distTarget ?? loaderBundleTarget!; // Get path from dev-server root to target dir - // If dir is relative, it's already relative to project root (same as devServer.root) const targetDir = target.dir!; - - // Use stencil config directory as fallback if devServer.root is not usable - const configDir = dirname(stencilConfigPath); - const rootDir = devServer.root && devServer.root !== '/' ? devServer.root : configDir; - const relativePath = isAbsolute(targetDir) ? relative(rootDir, targetDir) : targetDir; // dist/loader-bundle use empty string as default buildDir diff --git a/test-project/test-config.mjs b/test-project/test-config.mjs deleted file mode 100644 index 3778c8f..0000000 --- a/test-project/test-config.mjs +++ /dev/null @@ -1,9 +0,0 @@ -import { createConfig } from '../dist/index.js'; - -try { - const config = await createConfig(); - console.log('stencilEntryPath:', process.env.STENCIL_ENTRY_PATH); - console.log('Config created successfully'); -} catch (e) { - console.error('Error:', e.message); -} diff --git a/test-project/package-lock.json b/test-projects/explicit-dir/package-lock.json similarity index 100% rename from test-project/package-lock.json rename to test-projects/explicit-dir/package-lock.json diff --git a/test-project/package.json b/test-projects/explicit-dir/package.json similarity index 100% rename from test-project/package.json rename to test-projects/explicit-dir/package.json diff --git a/test-project/stencil.config.ts b/test-projects/explicit-dir/stencil.config.ts similarity index 100% rename from test-project/stencil.config.ts rename to test-projects/explicit-dir/stencil.config.ts diff --git a/test-projects/explicit-dir/test-config.mjs b/test-projects/explicit-dir/test-config.mjs new file mode 100644 index 0000000..50c0fc0 --- /dev/null +++ b/test-projects/explicit-dir/test-config.mjs @@ -0,0 +1,4 @@ +import { createConfig } from '../../dist/index.js'; + +const config = await createConfig(); +console.log('stencilEntryPath:', process.env.STENCIL_ENTRY_PATH); diff --git a/test-projects/www/package-lock.json b/test-projects/www/package-lock.json new file mode 100644 index 0000000..5fa4674 --- /dev/null +++ b/test-projects/www/package-lock.json @@ -0,0 +1,149 @@ +{ + "name": "test-www", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "test-www", + "devDependencies": { + "@stencil/core": "^4.0.0" + } + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.44.0.tgz", + "integrity": "sha512-VGF3wy0Eq1gcEIkSCr8Ke03CWT+Pm2yveKLaDvq51pPpZza3JX/ClxXOCmTYYq3us5MvEuNRTaeyFThCKRQhOA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.44.0.tgz", + "integrity": "sha512-fBkyrDhwquRvrTxSGH/qqt3/T0w5Rg0L7ZIDypvBPc1/gzjJle6acCpZ36blwuwcKD/u6oCE/sRWlUAcxLWQbQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.44.0.tgz", + "integrity": "sha512-ZTR2mxBHb4tK4wGf9b8SYg0Y6KQPjGpR4UWwTFdnmjB4qRtoATZ5dWn3KsDwGa5Z2ZBOE7K52L36J9LueKBdOQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.44.0.tgz", + "integrity": "sha512-GFWfAhVhWGd4r6UxmnKRTBwP1qmModHtd5gkraeW2G490BpFOZkFtem8yuX2NyafIP/mGpRJgTJ2PwohQkUY/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.44.0.tgz", + "integrity": "sha512-iUVJc3c0o8l9Sa/qlDL2Z9UP92UZZW1+EmQ4xfjTc1akr0iUFZNfxrXJ/R1T90h/ILm9iXEY6+iPrmYB3pXKjw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.44.0.tgz", + "integrity": "sha512-PQUobbhLTQT5yz/SPg116VJBgz+XOtXt8D1ck+sfJJhuEsMj2jSej5yTdp8CvWBSceu+WW+ibVL6dm0ptG5fcA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.44.0.tgz", + "integrity": "sha512-M0CpcHf8TWn+4oTxJfh7LQuTuaYeXGbk0eageVjQCKzYLsajWS/lFC94qlRqOlyC2KvRT90ZrfXULYmukeIy7w==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.44.0.tgz", + "integrity": "sha512-Q2Mgwt+D8hd5FIPUuPDsvPR7Bguza6yTkJxspDGkZj7tBRn2y4KSWYuIXpftFSjBra76TbKerCV7rgFPQrn+wQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@stencil/core": { + "version": "4.43.4", + "resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.43.4.tgz", + "integrity": "sha512-QWawMM1XIpSz4k+k+VyHZMr2YSxlCNAPWO/jTdJ+2kdgdN7ZQVEFZpc4WBm3E3mrDPTZ79lLcnIPa399bg4XOg==", + "dev": true, + "license": "MIT", + "bin": { + "stencil": "bin/stencil" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.10.0" + }, + "optionalDependencies": { + "@rollup/rollup-darwin-arm64": "4.44.0", + "@rollup/rollup-darwin-x64": "4.44.0", + "@rollup/rollup-linux-arm64-gnu": "4.44.0", + "@rollup/rollup-linux-arm64-musl": "4.44.0", + "@rollup/rollup-linux-x64-gnu": "4.44.0", + "@rollup/rollup-linux-x64-musl": "4.44.0", + "@rollup/rollup-win32-arm64-msvc": "4.44.0", + "@rollup/rollup-win32-x64-msvc": "4.44.0" + } + } + } +} diff --git a/test-projects/www/package.json b/test-projects/www/package.json new file mode 100644 index 0000000..aa30b3b --- /dev/null +++ b/test-projects/www/package.json @@ -0,0 +1,8 @@ +{ + "name": "test-www", + "private": true, + "type": "module", + "devDependencies": { + "@stencil/core": "^4.0.0" + } +} diff --git a/test-projects/www/stencil.config.ts b/test-projects/www/stencil.config.ts new file mode 100644 index 0000000..3ce82ae --- /dev/null +++ b/test-projects/www/stencil.config.ts @@ -0,0 +1,9 @@ +import { Config } from '@stencil/core'; + +export const config: Config = { + namespace: 'TestApp', + devServer: { + port: 3335, + }, + outputTargets: [{ type: 'www', serviceWorker: null }], +}; diff --git a/test-projects/www/test-config.mjs b/test-projects/www/test-config.mjs new file mode 100644 index 0000000..50c0fc0 --- /dev/null +++ b/test-projects/www/test-config.mjs @@ -0,0 +1,4 @@ +import { createConfig } from '../../dist/index.js'; + +const config = await createConfig(); +console.log('stencilEntryPath:', process.env.STENCIL_ENTRY_PATH);