Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: remove auto globals install #7009

Merged
merged 7 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .changeset/v2-remove-auto-globals-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
"@remix-run/architect": major
"@remix-run/express": major
"@remix-run/netlify": major
"@remix-run/node": major
"@remix-run/serve": major
"@remix-run/vercel": major
---

For preparation of using Node's built in fetch implementation, installing the fetch globals is now a responsibility of the app server. If you are using `remix-serve`, nothing is required. If you are using your own app server, you will need to install the globals yourself.

```js filename=server.js
import { installGlobals } from "@remix-run/node";

installGlobals();
```

source-map-support is now a responsibility of the app server. If you are using `remix-serve`, nothing is required. If you are using your own app server, you will need to install [`source-map-support`](https://www.npmjs.com/package/source-map-support) yourself.

```sh
npm i source-map-support
```

```js filename=server.js
import sourceMapSupport from "source-map-support";
sourceMapSupport.install();
```
23 changes: 23 additions & 0 deletions docs/pages/v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,29 @@ remix dev --manual -c 'node ./server.js'

Check out the [manual mode guide][manual-mode] for more details.

## `installGlobals`

For preparation of using Node's built in fetch implementation, installing the fetch globals is now a responsibility of the app server. If you are using `remix-serve`, nothing is required. If you are using your own app server, you will need to install the globals yourself.

```js filename=server.js
import { installGlobals } from "@remix-run/node";

installGlobals();
```

## `source-map-support`

Source map support is now a responsibility of the app server. If you are using `remix-serve`, nothing is required. If you are using your own app server, you will need to install [`source-map-support`](https://www.npmjs.com/package/source-map-support) yourself.

```sh
npm i source-map-support
```

```js filename=server.js
import sourceMapSupport from "source-map-support";
sourceMapSupport.install();
```

[future-flags]: ./api-development-strategy
[remix-config]: ../file-conventions/remix-config
[flat-routes]: https://github.com/remix-run/remix/discussions/4482
Expand Down
6 changes: 6 additions & 0 deletions integration/helpers/create-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import type { JsonObject } from "type-fest";
import type { AppConfig } from "@remix-run/dev";
import { ServerMode } from "@remix-run/server-runtime/mode";

// @ts-ignore
import type { ServerBuild } from "../../build/node_modules/@remix-run/server-runtime";
// @ts-ignore
import { createRequestHandler } from "../../build/node_modules/@remix-run/server-runtime";
// @ts-ignore
import { createRequestHandler as createExpressHandler } from "../../build/node_modules/@remix-run/express";
// @ts-ignore
import { installGlobals } from "../../build/node_modules/@remix-run/node";

const TMP_DIR = path.join(process.cwd(), ".tmp", "integration");

Expand All @@ -37,6 +42,7 @@ export function json(value: JsonObject) {
}

export async function createFixture(init: FixtureInit, mode?: ServerMode) {
installGlobals();
let projectDir = await createFixtureProject(init, mode);
let buildPath = path.resolve(projectDir, "build");
let app: ServerBuild = await import(buildPath);
Expand Down
4 changes: 3 additions & 1 deletion integration/hmr-log-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ let fixture = (options: { appPort: number; devPort: number }): FixtureInit => ({
let path = require("node:path");
let express = require("express");
let { createRequestHandler } = require("@remix-run/express");
let { logDevReady } = require("@remix-run/node");
let { logDevReady, installGlobals } = require("@remix-run/node");

installGlobals();

const app = express();
app.use(express.static("public", { immutable: true, maxAge: "1y" }));
Expand Down
4 changes: 3 additions & 1 deletion integration/hmr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ let fixture = (options: { appPort: number; devPort: number }): FixtureInit => ({
let path = require("node:path");
let express = require("express");
let { createRequestHandler } = require("@remix-run/express");
let { broadcastDevReady } = require("@remix-run/node");
let { broadcastDevReady, installGlobals } = require("@remix-run/node");

installGlobals();

const app = express();
app.use(express.static("public", { immutable: true, maxAge: "1y" }));
Expand Down
2 changes: 0 additions & 2 deletions packages/remix-architect/globals.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/remix-architect/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "./globals";

export { createArcTableSessionStorage } from "./sessions/arcTableSessionStorage";

export type { GetLoadContextFunction, RequestHandler } from "./server";
Expand Down
2 changes: 0 additions & 2 deletions packages/remix-express/globals.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/remix-express/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import "./globals";

export type { GetLoadContextFunction, RequestHandler } from "./server";
export { createRequestHandler } from "./server";
2 changes: 0 additions & 2 deletions packages/remix-netlify/globals.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/remix-netlify/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import "./globals";

export type { GetLoadContextFunction, RequestHandler } from "./server";
export { createRequestHandler } from "./server";
4 changes: 0 additions & 4 deletions packages/remix-node/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import sourceMapSupport from "source-map-support";

sourceMapSupport.install();

export { AbortController } from "abort-controller";

export type {
Expand Down
6 changes: 5 additions & 1 deletion packages/remix-serve/cli.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import "./env";
import path from "node:path";
import os from "node:os";
import { broadcastDevReady } from "@remix-run/node";
import { broadcastDevReady, installGlobals } from "@remix-run/node";
import sourceMapSupport from "source-map-support";

import { createApp } from "./index";

sourceMapSupport.install();
installGlobals();

let port = process.env.PORT ? Number(process.env.PORT) : 3000;
if (Number.isNaN(port)) port = 3000;

Expand Down
6 changes: 4 additions & 2 deletions packages/remix-serve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"@remix-run/node": "1.19.1",
"compression": "^1.7.4",
"express": "^4.17.1",
"morgan": "^1.10.0"
"morgan": "^1.10.0",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@types/compression": "^1.7.0",
"@types/express": "^4.17.9",
"@types/morgan": "^1.9.2"
"@types/morgan": "^1.9.2",
"@types/source-map-support": "^0.5.6"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 0 additions & 2 deletions packages/remix-vercel/globals.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/remix-vercel/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "./globals";

const alreadyWarned: Record<string, boolean> = {};
const warnOnce = (message: string, key = message) => {
if (!alreadyWarned[key]) {
Expand Down
4 changes: 3 additions & 1 deletion templates/arc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
"cross-env": "^7.0.3",
"isbot": "^3.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@architect/architect": "^10.12.1",
"@remix-run/dev": "*",
"@remix-run/eslint-config": "*",
"@types/react": "^18.0.35",
"@types/react-dom": "^18.0.11",
"@types/source-map-support": "^0.5.6",
"eslint": "^8.38.0",
"typescript": "^5.1.0"
},
Expand Down
2 changes: 2 additions & 0 deletions templates/arc/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { createRequestHandler } from "@remix-run/architect";
import * as build from "@remix-run/dev/server-build";
import { installGlobals } from "@remix-run/node";
import sourceMapSupport from "source-map-support";

sourceMapSupport.install();
installGlobals();

export const handler = createRequestHandler({
Expand Down
4 changes: 3 additions & 1 deletion templates/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"isbot": "^3.6.8",
"morgan": "^1.10.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@remix-run/dev": "*",
Expand All @@ -29,6 +30,7 @@
"@types/morgan": "^1.9.4",
"@types/react": "^18.0.35",
"@types/react-dom": "^18.0.11",
"@types/source-map-support": "^0.5.6",
"chokidar": "^3.5.3",
"eslint": "^8.38.0",
"typescript": "^5.1.0"
Expand Down
2 changes: 2 additions & 0 deletions templates/express/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import chokidar from "chokidar";
import compression from "compression";
import express from "express";
import morgan from "morgan";
import sourceMapSupport from "source-map-support";

sourceMapSupport.install();
installGlobals();

const BUILD_PATH = "./build/index.js";
Expand Down
4 changes: 3 additions & 1 deletion templates/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
"cross-env": "^7.0.3",
"isbot": "^3.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@remix-run/dev": "*",
"@remix-run/eslint-config": "*",
"@remix-run/serve": "*",
"@types/react": "^18.0.35",
"@types/react-dom": "^18.0.11",
"@types/source-map-support": "^0.5.6",
"eslint": "^8.38.0",
"typescript": "^5.1.0"
},
Expand Down
2 changes: 2 additions & 0 deletions templates/netlify/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as build from "@remix-run/dev/server-build";
import { createRequestHandler } from "@remix-run/netlify";
import { installGlobals } from "@remix-run/node";
import sourceMapSupport from "source-map-support";

sourceMapSupport.install();
installGlobals();

export const handler = createRequestHandler({
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3398,10 +3398,10 @@
resolved "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.3.tgz"
integrity sha512-JYM8x9EGF163bEyhdJBpR2QX1R5naCJHC8ucJylJ3w9/CVBaskdQ8WqBf8MmQrd1kRvp/a4TS8HJ+bxzR7ZJYQ==

"@types/source-map-support@^0.5.4":
version "0.5.4"
resolved "https://registry.npmjs.org/@types/source-map-support/-/source-map-support-0.5.4.tgz"
integrity sha512-9zGujX1sOPg32XLyfgEB/0G9ZnrjthL/Iv1ZfuAjj8LEilHZEpQSQs1scpRXPhHzGYgWiLz9ldF1cI8JhL+yMw==
"@types/source-map-support@^0.5.4", "@types/source-map-support@^0.5.6":
version "0.5.6"
resolved "https://registry.npmjs.org/@types/source-map-support/-/source-map-support-0.5.6.tgz#aa4a8c98ec73a1f1f30a813573a9b2154a6eb39a"
integrity sha512-b2nJ9YyXmkhGaa2b8VLM0kJ04xxwNyijcq12/kDoomCt43qbHBeK2SLNJ9iJmETaAj+bKUT05PQUu3Q66GvLhQ==
dependencies:
source-map "^0.6.0"

Expand Down