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 esbuild if srcDir is different from the default #217

Open
wants to merge 1 commit into
base: master
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
4 changes: 2 additions & 2 deletions src/esbuild/esbuildBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const svelteHandler = async ({ elderConfig, svelteConfig, replacements, restartH

// eslint-disable-next-line global-require
const pkg = require(path.resolve(elderConfig.rootDir, './package.json'));
const globPath = path.resolve(elderConfig.rootDir, `./src/**/*.svelte`);
const globPath = path.resolve(elderConfig.rootDir, elderConfig.srcDir, `/**/*.svelte`);
const initialEntryPoints = glob.sync(globPath);
const sveltePackages = getPackagesWithSvelte(pkg, elderConfig);
const elderPlugins = getPluginLocations(elderConfig);
Expand Down Expand Up @@ -161,7 +161,7 @@ const svelteHandler = async ({ elderConfig, svelteConfig, replacements, restartH
splitting: true,
chunkNames: 'chunks/[name].[hash]',
logLevel: 'error',
outbase: 'src',
outbase: elderConfig.srcDir,
define: {
'process.env.componentType': "'browser'",
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ describe('#prepareFindSvelteComponent', () => {
const common = {
ssrFolder: path.resolve(`./test/___ELDER___/compiled`),
rootDir: path.resolve(`./test/`),
srcDir: path.resolve('./test/src'),
clientComponents: path.resolve(`./test/public/_elderjs/svelte/`),
distDir: path.resolve(`./test/public`),
};
Expand Down
4 changes: 2 additions & 2 deletions src/partialHydration/prepareFindSvelteComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const removeHash = (pathWithHash) => {
return pathWithHash;
};

const prepareFindSvelteComponent = ({ ssrFolder, rootDir, clientComponents: clientFolder, distDir }) => {
const prepareFindSvelteComponent = ({ ssrFolder, rootDir, srcDir, clientComponents: clientFolder, distDir }) => {
const rootDirFixed = windowsPathFix(rootDir);
const ssrComponents = glob.sync(`${ssrFolder}/**/*.js`).map(windowsPathFix);
const clientComponents = glob
Expand All @@ -29,7 +29,7 @@ const prepareFindSvelteComponent = ({ ssrFolder, rootDir, clientComponents: clie

// abs path first
if (nameFixed.includes(rootDirFixed)) {
const rel = windowsPathFix(path.relative(path.join(rootDirFixed, 'src'), name))
const rel = windowsPathFix(path.relative(path.join(rootDirFixed, srcDir.replace(rootDir, '')), name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I'm having a brain fart here. Can you confirm there.

.replace('.svelte', '.js')
.toLowerCase();
const parsed = path.parse(rel);
Expand Down
1 change: 1 addition & 0 deletions src/utils/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function getConfig(initializationOptions: InitializationOptions = {}): SettingsO
findComponent: prepareFindSvelteComponent({
ssrFolder: ssrComponents,
rootDir,
srcDir: config.srcDir,
clientComponents,
distDir: config.distDir,
}),
Expand Down