Skip to content

Commit

Permalink
Calm esm warnings (#3872)
Browse files Browse the repository at this point in the history
* chore: don't show esm warning on dynamic imports

* add changeset

* add test
  • Loading branch information
jacob-ebey authored Jul 30, 2022
1 parent 696290e commit a2914cd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-trains-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Don't show ESM warnings when consumed via dynamic import.
49 changes: 48 additions & 1 deletion integration/esm-only-warning-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ test.beforeAll(async () => {
import b from "esm-only-exports";
import c from "esm-only-sub-exports";
import d from "esm-cjs-exports";
import e from "cjs-dynamic-import";
export function loader() {
export async function loader() {
let { default: f } = await import("esm-only-exports-b");
return json({
a: a(),
b: b(),
c: c(),
d: d(),
e: e(),
f: f(),
});
}
Expand Down Expand Up @@ -79,6 +83,40 @@ test.beforeAll(async () => {
"node_modules/esm-only-exports/index.js": js`
export default () => "esm-only-no-exports";
`,
"node_modules/esm-only-exports-b/package.json": json({
name: "esm-only-exports-b",
version: "1.0.0",
type: "module",
main: "index.js",
exports: {
".": "./index.js",
"./package.json": "./package.json",
},
}),
"node_modules/esm-only-exports-b/index.js": js`
export default () => "esm-only-no-exports-b";
`,
"node_modules/esm-only-exports-c/package.json": json({
name: "esm-only-exports-c",
version: "1.0.0",
type: "module",
main: "index.js",
exports: {
".": "./index.js",
"./package.json": "./package.json",
},
}),
"node_modules/esm-only-exports-c/index.js": js`
export default () => "esm-only-no-exports-c";
`,
"node_modules/cjs-dynamic-import/package.json": json({
name: "cjs-dynamic-import",
version: "1.0.0",
main: "index.js",
}),
"node_modules/cjs-dynamic-import/index.js": js`
module.exports = async () => "esm-only-no-exports-d" + (await import("esm-only-exports-c")).default();
`,
"node_modules/esm-only-sub-exports/package.json": json({
name: "esm-only-sub-exports",
version: "1.0.0",
Expand Down Expand Up @@ -143,6 +181,15 @@ test("logs warnings for ESM only packages", async () => {
expect(buildOutput).toContain(
"esm-only-exports is possibly an ESM only package"
);
expect(buildOutput).not.toContain(
"esm-only-exports-b is possibly an ESM only package"
);
expect(buildOutput).not.toContain(
"esm-only-exports-c is possibly an ESM only package"
);
expect(buildOutput).not.toContain(
"cjs-dynamic-import is possibly an ESM only package"
);
expect(buildOutput).toContain(
"esm-only-sub-exports is possibly an ESM only package"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function serverBareModulesPlugin(
return {
name: "server-bare-modules",
setup(build) {
build.onResolve({ filter: /.*/ }, ({ importer, path }) => {
build.onResolve({ filter: /.*/ }, ({ importer, kind, path }) => {
// If it's not a bare module ID, bundle it.
if (!isBareModuleId(resolvePath(path))) {
return undefined;
Expand Down Expand Up @@ -103,6 +103,7 @@ export function serverBareModulesPlugin(
if (
onWarning &&
!isNodeBuiltIn(packageName) &&
kind !== "dynamic-import" &&
(!remixConfig.serverBuildTarget ||
remixConfig.serverBuildTarget === "node-cjs")
) {
Expand Down

0 comments on commit a2914cd

Please sign in to comment.