Skip to content

Commit

Permalink
Merge pull request #2481 from michaelwarren1106/master
Browse files Browse the repository at this point in the history
feat(dev-server): don't deepmerge exportConditions. allow user config to fully replace the default
  • Loading branch information
thepassle authored Oct 12, 2023
2 parents b20cc19 + 99d4734 commit 3854e03
Show file tree
Hide file tree
Showing 6 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>
4 changes: 3 additions & 1 deletion packages/dev-server/src/plugins/nodeResolvePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export function nodeResolvePlugin(
moduleDirectories: ['node_modules', 'web_modules'],
// allow resolving polyfills for nodejs libs
preferBuiltins: false,
exportConditions: ['development'],
},
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
2 changes: 1 addition & 1 deletion packages/test-runner-commands/browser/commands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function sendMouse(payload: SendMousePayload): Promise<void>;

/**
* Selects an option in a <select> element by value or label
*
*
* @example
* ```
* it('natively selects an option by value', async () => {
Expand Down

0 comments on commit 3854e03

Please sign in to comment.