Skip to content

Commit

Permalink
feat!: default to serverModuleFormat esm (#6949)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com>
  • Loading branch information
jacob-ebey and markdalgleish authored Aug 9, 2023
1 parent 8ab2a0e commit 527a5d6
Show file tree
Hide file tree
Showing 125 changed files with 530 additions and 395 deletions.
6 changes: 6 additions & 0 deletions .changeset/v2-default-to-esm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@remix-run/dev": major
"@remix-run/serve": major
---

Default to serverModuleFormat esm, and update remix-serve to use dynamic import to support esm and cjs build outputs.
2 changes: 1 addition & 1 deletion docs/file-conventions/remix-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The URL prefix of the browser build with a trailing slash. Defaults to

## postcss

Whether to process CSS using [PostCSS][postcss] if `postcss.config.js` is present. Defaults to `true`.
Whether to process CSS using [PostCSS][postcss] if a PostCSS config file is present. Defaults to `true`.

## routes

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/migrating-react-router-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ If you are using TypeScript, you likely already have a `tsconfig.json` in your p
"esModuleInterop": true,
"jsx": "react-jsx",
"resolveJsonModule": true,
"moduleResolution": "node",
"moduleResolution": "Bundler",
"baseUrl": ".",
"noEmit": true,
"paths": {
Expand Down
8 changes: 4 additions & 4 deletions docs/guides/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,19 @@ For example, to use [Autoprefixer][autoprefixer], first install the PostCSS plug
npm install -D autoprefixer
```

Then add `postcss.config.js` in the Remix root referencing the plugin.
Then add a PostCSS config file in the Remix root referencing the plugin.

```js filename=postcss.config.js
```js filename=postcss.config.cjs
module.exports = {
plugins: {
autoprefixer: {},
},
};
```

If you're using [Vanilla Extract][vanilla-extract-2], since it's already playing the role of CSS preprocessor, you may want to apply a different set of PostCSS plugins relative to other styles. To support this, you can export a function from `postcss.config.js` which is given a context object that lets you know when Remix is processing a Vanilla Extract file.
If you're using [Vanilla Extract][vanilla-extract-2], since it's already playing the role of CSS preprocessor, you may want to apply a different set of PostCSS plugins relative to other styles. To support this, you can export a function from your PostCSS config file which is given a context object that lets you know when Remix is processing a Vanilla Extract file.

```js filename=postcss.config.js
```js filename=postcss.config.cjs
module.exports = (ctx) => {
return ctx.remix?.vanillaExtract
? {
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Remix has TypeScript type definitions built-in as well. The starter templates cr
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2019",
"strict": true,
Expand Down
6 changes: 3 additions & 3 deletions integration/abort-signal-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test } from "@playwright/test";

import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";

let fixture: Fixture;
let appFixture: AppFixture;
Expand Down
6 changes: 3 additions & 3 deletions integration/action-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";

import { createFixture, createAppFixture, js } from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture, selectHtml } from "./helpers/playwright-fixture";
import { createFixture, createAppFixture, js } from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture, selectHtml } from "./helpers/playwright-fixture.js";

test.describe("actions", () => {
let fixture: Fixture;
Expand Down
6 changes: 3 additions & 3 deletions integration/browser-entry-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";

import type { AppFixture, Fixture } from "./helpers/create-fixture";
import { createFixture, js, createAppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { AppFixture, Fixture } from "./helpers/create-fixture.js";
import { createFixture, js, createAppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";

let fixture: Fixture;
let appFixture: AppFixture;
Expand Down
6 changes: 3 additions & 3 deletions integration/bug-report-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";

import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";

let fixture: Fixture;
let appFixture: AppFixture;
Expand Down
6 changes: 3 additions & 3 deletions integration/catch-boundary-data-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";

import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";

let fixture: Fixture;
let appFixture: AppFixture;
Expand Down
6 changes: 3 additions & 3 deletions integration/catch-boundary-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";

import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";

test.describe("ErrorBoundary (thrown responses)", () => {
let fixture: Fixture;
Expand Down
3 changes: 2 additions & 1 deletion integration/cf-compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from "node:path";
import shell from "shelljs";
import glob from "glob";

import { createFixtureProject, js, json } from "./helpers/create-fixture";
import { createFixtureProject, js, json } from "./helpers/create-fixture.js";

const searchFiles = async (pattern: string | RegExp, files: string[]) => {
let result = shell.grep("-l", pattern, files);
Expand Down Expand Up @@ -36,6 +36,7 @@ test.describe("cloudflare compiler", () => {
private: true,
sideEffects: false,
main: "build/index.js",
type: "module",
dependencies: {
"@remix-run/cloudflare": "0.0.0-local-version",
"@remix-run/cloudflare-workers": "0.0.0-local-version",
Expand Down
2 changes: 1 addition & 1 deletion integration/compiler-mjs-output-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, expect } from "@playwright/test";
import * as fs from "node:fs";
import * as path from "node:path";

import { createFixtureProject, js } from "./helpers/create-fixture";
import { createFixtureProject, js } from "./helpers/create-fixture.js";

let projectDir: string;

Expand Down
23 changes: 15 additions & 8 deletions integration/compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
json,
createFixtureProject,
css,
} from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture";
} from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";

test.describe("compiler", () => {
let fixture: Fixture;
Expand All @@ -25,8 +25,11 @@ test.describe("compiler", () => {
// We need a custom config file here to test usage of `getDependenciesToBundle`
// since this can't be serialized from the fixture object.
"remix.config.js": js`
let { getDependenciesToBundle } = require("@remix-run/dev");
module.exports = {
import { getDependenciesToBundle } from "@remix-run/dev";
export default {
future: {
v2_routeConvention: true,
},
serverDependenciesToBundle: [
"esm-only-pkg",
"esm-only-single-export",
Expand Down Expand Up @@ -94,8 +97,8 @@ test.describe("compiler", () => {
return <div id="esm-only-single-export">{esmOnlyPkg}</div>;
}
`,
"app/routes/package-with-submodule.tsx": js`
import { submodule } from "@org/package/sub-package";
"app/routes/package-with-submodule.jsx": js`
import { submodule } from "@org/package/sub-package/index.js";
export default function PackageWithSubModule() {
return <div id="package-with-submodule">{submodule()}</div>;
Expand Down Expand Up @@ -146,7 +149,9 @@ test.describe("compiler", () => {
version: "1.0.0",
}),
"node_modules/@org/package/sub-package/package.json": json({
module: "./esm/index.js",
module: "./index.js",
exports: "./index.js",
main: "./index.js",
sideEffects: false,
}),
"node_modules/@org/package/sub-package/index.js": js`
Expand All @@ -160,6 +165,8 @@ test.describe("compiler", () => {
"node_modules/@org/package/sub-package/esm/package.json": json({
type: "module",
sideEffects: false,
exports: "./esm/index.js",
main: "./esm/index.js",
}),
"node_modules/@org/package/sub-package/esm/index.js": js`
export { default as submodule } from "./submodule.js";
Expand Down
6 changes: 3 additions & 3 deletions integration/css-modules-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { test, expect } from "@playwright/test";
import globby from "globby";
import fse from "fs-extra";

import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import {
createAppFixture,
createFixture,
css,
js,
} from "./helpers/create-fixture";
} from "./helpers/create-fixture.js";

const TEST_PADDING_VALUE = "20px";

Expand Down
13 changes: 8 additions & 5 deletions integration/css-side-effect-imports-test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { test, expect } from "@playwright/test";

import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import {
createAppFixture,
createFixture,
css,
js,
json,
} from "./helpers/create-fixture";
} from "./helpers/create-fixture.js";

const TEST_PADDING_VALUE = "20px";

Expand All @@ -19,7 +19,7 @@ test.describe("CSS side-effect imports", () => {
test.beforeAll(async () => {
fixture = await createFixture({
config: {
serverDependenciesToBundle: [/@test-package/],
serverDependenciesToBundle: ["react", /@test-package/],
},
files: {
"app/root.tsx": js`
Expand Down Expand Up @@ -287,7 +287,10 @@ test.describe("CSS side-effect imports", () => {
);
};
`,
"app/routes/commonjs-package-test.tsx": js`
"node_modules/@test-package/commonjs/package.json": json({
main: "./index.js",
}),
"app/routes/commonjs-package-test.jsx": js`
import { Test } from "@test-package/commonjs";
export default function() {
return <Test />;
Expand Down
6 changes: 3 additions & 3 deletions integration/custom-entry-server-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from "@playwright/test";

import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";

let fixture: Fixture;
let appFixture: AppFixture;
Expand Down
6 changes: 3 additions & 3 deletions integration/defer-loader-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";

import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";

let fixture: Fixture;
let appFixture: AppFixture;
Expand Down
6 changes: 3 additions & 3 deletions integration/defer-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { test, expect } from "@playwright/test";
import type { ConsoleMessage, Page } from "@playwright/test";

import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";

const ROOT_ID = "ROOT_ID";
const INDEX_ID = "INDEX_ID";
Expand Down
5 changes: 3 additions & 2 deletions integration/deno-compiler-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { test, expect } from "@playwright/test";
import * as fse from "fs-extra";
import fse from "fs-extra";
import path from "node:path";
import shell from "shelljs";
import glob from "glob";

import { createFixtureProject, js, json } from "./helpers/create-fixture";
import { createFixtureProject, js, json } from "./helpers/create-fixture.js";

let projectDir: string;

Expand Down Expand Up @@ -39,6 +39,7 @@ test.beforeAll(async () => {
"package.json": json({
private: true,
sideEffects: false,
type: "module",
dependencies: {
"@remix-run/deno": "0.0.0-local-version",
"@remix-run/react": "0.0.0-local-version",
Expand Down
6 changes: 3 additions & 3 deletions integration/deterministic-build-output-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import globby from "globby";
import fs from "node:fs";
import path from "node:path";

import type { FixtureInit } from "./helpers/create-fixture";
import { createFixtureProject, js, css } from "./helpers/create-fixture";
import type { FixtureInit } from "./helpers/create-fixture.js";
import { createFixtureProject, js, css } from "./helpers/create-fixture.js";

test("builds deterministically under different paths", async () => {
// This test validates various flavors of remix virtual modules to ensure
Expand All @@ -28,7 +28,7 @@ test("builds deterministically under different paths", async () => {
let init: FixtureInit = {
files: {
"postcss.config.js": js`
module.exports = {
export default {
plugins: {
"postcss-import": {},
},
Expand Down
8 changes: 4 additions & 4 deletions integration/error-boundary-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { test, expect } from "@playwright/test";
import { ServerMode } from "@remix-run/server-runtime/mode";

import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture";
import { ServerMode } from "../build/node_modules/@remix-run/server-runtime/dist/mode.js";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";

test.describe("ErrorBoundary", () => {
let fixture: Fixture;
Expand Down
8 changes: 4 additions & 4 deletions integration/error-boundary-v2-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Page } from "@playwright/test";
import { test, expect } from "@playwright/test";
import { ServerMode } from "@remix-run/server-runtime/mode";

import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture";
import { ServerMode } from "../build/node_modules/@remix-run/server-runtime/dist/mode.js";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";

test.describe("ErrorBoundary", () => {
let fixture: Fixture;
Expand Down
4 changes: 2 additions & 2 deletions integration/error-data-request-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";

import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";

test.describe("ErrorBoundary", () => {
let fixture: Fixture;
Expand Down
Loading

0 comments on commit 527a5d6

Please sign in to comment.