Skip to content

Commit

Permalink
[fix] externalize middlewares.js when using adapter-node's entryPoint (
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry authored Sep 24, 2021
1 parent 4c47afb commit 7dff79b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-ears-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-node': patch
---

[fix] Correctly treat `middlewares.js` as external when using `entryPoint` option
11 changes: 7 additions & 4 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
statSync,
writeFileSync
} from 'fs';
import { join } from 'path';
import { join, resolve } from 'path';
import { pipeline } from 'stream';
import glob from 'tiny-glob';
import { fileURLToPath } from 'url';
Expand Down Expand Up @@ -81,7 +81,6 @@ export default function ({
entryPoints: [entryPoint],
outfile: join(out, 'index.js'),
bundle: true,
external: ['./middlewares.js'], // does not work, eslint does not exclude middlewares from target
format: 'esm',
platform: 'node',
target: 'node12',
Expand All @@ -90,8 +89,12 @@ export default function ({
{
name: 'fix-middlewares-exclude',
setup(build) {
// Match an import called "./middlewares.js" and mark it as external
build.onResolve({ filter: /^\.\/middlewares\.js$/ }, () => ({ external: true }));
// Match an import of "middlewares.js" and mark it as external
build.onResolve({ filter: /\/middlewares\.js$/ }, ({ path, resolveDir }) => {
if (resolve(resolveDir, path) === resolve(out, 'middlewares.js')) {
return { path: './middlewares.js', external: true };
}
});
}
}
]
Expand Down

0 comments on commit 7dff79b

Please sign in to comment.