Skip to content

Commit

Permalink
feat(dev-server): don't deepmerge exportConditions. allow user config…
Browse files Browse the repository at this point in the history
… to fully replace the default
  • Loading branch information
michaelwarren1106 committed Oct 6, 2023
1 parent b20cc19 commit d9996d2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-spoons-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/dev-server': patch
---

Fix an issue where the nodeResolve plugin wasn't accepting user configuration correctly
10 changes: 10 additions & 0 deletions packages/dev-server/demo/export-conditions/config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { fileURLToPath } from 'url';
import { resolve } from 'path';

export default {
rootDir: resolve(fileURLToPath(import.meta.url), '..', '..', '..'),
appIndex: '/demo/export-conditions/index.html',
nodeResolve: {
exportConditions: ['default']
},
};
31 changes: 31 additions & 0 deletions packages/dev-server/demo/export-conditions/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<body>
<img width="100" src="../logo.png" />

<h1>Node resolve demo</h1>
<p>A demo which resolves bare module imports</p>

<div id="test"></div>

<script type="module">
// inline bare modules are resolved
import { render, html } from 'lit-html';

window.__inlineNodeResolve = !!render && !!html;
</script>

<script type="module">

window.__tests = {
// lit-html only adds this global in development mode
// so when the exportCondition is overwritten, it'll be undefined
prodExport: typeof window.litIssuedWarnings === 'undefined',
};
document.getElementById('test').innerHTML = `<pre>${JSON.stringify(
window.__tests,
null,
2,
)}</pre>`;
</script>
</body>
</html>
6 changes: 4 additions & 2 deletions packages/dev-server/src/plugins/nodeResolvePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export function nodeResolvePlugin(
extensions: ['.mjs', '.js', '.cjs', '.jsx', '.json', '.ts', '.tsx'],
moduleDirectories: ['node_modules', 'web_modules'],
// allow resolving polyfills for nodejs libs
preferBuiltins: false,
exportConditions: ['development'],
preferBuiltins: false
},
userOptionsObject,
);

// use user config exportConditions if present. otherwise use ['development']
options.exportConditions = userOptionsObject.exportConditions || ['development'];

return rollupAdapter(
nodeResolve(options),
{ preserveSymlinks },
Expand Down
4 changes: 4 additions & 0 deletions packages/dev-server/test/integration.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const testCases = [
name: 'syntax',
tests: ['stage4', 'inlineStage4', 'importMeta', 'staticImports', 'dynamicImports'],
},
{
name: 'export-conditions',
tests: ['prodExport'],
},
];

describe('integration tests', () => {
Expand Down

0 comments on commit d9996d2

Please sign in to comment.