@react-router/node 7.0.0-pre.1 → 7.0.0-pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # `@remix-run/node`
2
2
 
3
+ ## 7.0.0-pre.2
4
+
5
+ ### Major Changes
6
+
7
+ - Drop support for Node 18, update minimum Node vestion to 20 ([#12171](https://github.com/remix-run/react-router/pull/12171))
8
+
9
+ - Remove `installGlobals()` as this should no longer be necessary
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies:
14
+ - `react-router@7.0.0-pre.2`
15
+
3
16
  ## 7.0.0-pre.1
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export { installGlobals } from "./globals";
2
1
  export { createFileSessionStorage } from "./sessions/fileStorage";
3
2
  export { createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable, } from "./stream";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/node v7.0.0-pre.1
2
+ * @react-router/node v7.0.0-pre.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -12,13 +12,11 @@
12
12
 
13
13
  Object.defineProperty(exports, '__esModule', { value: true });
14
14
 
15
- var globals = require('./globals.js');
16
15
  var fileStorage = require('./sessions/fileStorage.js');
17
16
  var stream = require('./stream.js');
18
17
 
19
18
 
20
19
 
21
- exports.installGlobals = globals.installGlobals;
22
20
  exports.createFileSessionStorage = fileStorage.createFileSessionStorage;
23
21
  exports.createReadableStreamFromReadable = stream.createReadableStreamFromReadable;
24
22
  exports.readableStreamToString = stream.readableStreamToString;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/node v7.0.0-pre.1
2
+ * @react-router/node v7.0.0-pre.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/stream.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/node v7.0.0-pre.1
2
+ * @react-router/node v7.0.0-pre.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-router/node",
3
- "version": "7.0.0-pre.1",
3
+ "version": "7.0.0-pre.2",
4
4
  "description": "Node.js platform abstractions for React Router",
5
5
  "bugs": {
6
6
  "url": "https://github.com/remix-run/react-router/issues"
@@ -16,13 +16,7 @@
16
16
  "exports": {
17
17
  ".": {
18
18
  "types": "./dist/index.d.ts",
19
- "import": "./dist/index.mjs",
20
- "require": "./dist/index.js"
21
- },
22
- "./install": {
23
- "types": "./dist/install.d.ts",
24
- "import": "./dist/install.mjs",
25
- "require": "./dist/install.js"
19
+ "default": "./dist/index.js"
26
20
  },
27
21
  "./package.json": "./package.json"
28
22
  },
@@ -39,11 +33,11 @@
39
33
  "devDependencies": {
40
34
  "@types/source-map-support": "^0.5.4",
41
35
  "typescript": "^5.1.6",
42
- "react-router": "7.0.0-pre.1"
36
+ "react-router": "7.0.0-pre.2"
43
37
  },
44
38
  "peerDependencies": {
45
39
  "typescript": "^5.1.0",
46
- "react-router": "7.0.0-pre.1"
40
+ "react-router": "7.0.0-pre.2"
47
41
  },
48
42
  "peerDependenciesMeta": {
49
43
  "typescript": {
@@ -51,7 +45,7 @@
51
45
  }
52
46
  },
53
47
  "engines": {
54
- "node": ">=18.0.0"
48
+ "node": ">=20.0.0"
55
49
  },
56
50
  "files": [
57
51
  "dist/",
package/dist/globals.d.ts DELETED
@@ -1,24 +0,0 @@
1
- /// <reference types="node" />
2
- import { webcrypto as nodeWebCrypto } from "node:crypto";
3
- declare global {
4
- namespace NodeJS {
5
- interface ProcessEnv {
6
- NODE_ENV: "development" | "production" | "test";
7
- }
8
- interface Global {
9
- File: typeof File;
10
- Headers: typeof Headers;
11
- Request: typeof Request;
12
- Response: typeof Response;
13
- fetch: typeof fetch;
14
- FormData: typeof FormData;
15
- ReadableStream: typeof ReadableStream;
16
- WritableStream: typeof WritableStream;
17
- crypto: typeof nodeWebCrypto;
18
- }
19
- }
20
- interface RequestInit {
21
- duplex?: "half";
22
- }
23
- }
24
- export declare function installGlobals(): void;
package/dist/globals.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var undici = require('undici');
16
- var node_crypto = require('node:crypto');
17
-
18
- function installGlobals() {
19
- global.File = undici.File;
20
- // @ts-ignore - this shows as an error in VSCode but is not an error via TSC so we can't use `ts-expect-error`
21
- global.Headers = undici.Headers;
22
- // @ts-expect-error - overriding globals
23
- global.Request = undici.Request;
24
- // @ts-expect-error - overriding globals
25
- global.Response = undici.Response;
26
- // @ts-expect-error - overriding globals
27
- global.fetch = undici.fetch;
28
- // @ts-expect-error - overriding globals
29
- global.FormData = undici.FormData;
30
- if (!global.crypto) {
31
- // @ts-expect-error - overriding globals
32
- global.crypto = node_crypto.webcrypto;
33
- }
34
- }
35
-
36
- exports.installGlobals = installGlobals;
package/dist/globals.mjs DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { File, Headers, Request, Response, fetch, FormData } from 'undici';
12
- import { webcrypto } from 'node:crypto';
13
-
14
- function installGlobals() {
15
- global.File = File;
16
- // @ts-ignore - this shows as an error in VSCode but is not an error via TSC so we can't use `ts-expect-error`
17
- global.Headers = Headers;
18
- // @ts-expect-error - overriding globals
19
- global.Request = Request;
20
- // @ts-expect-error - overriding globals
21
- global.Response = Response;
22
- // @ts-expect-error - overriding globals
23
- global.fetch = fetch;
24
- // @ts-expect-error - overriding globals
25
- global.FormData = FormData;
26
- if (!global.crypto) {
27
- // @ts-expect-error - overriding globals
28
- global.crypto = webcrypto;
29
- }
30
- }
31
-
32
- export { installGlobals };
package/dist/index.mjs DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- export { installGlobals } from './globals.mjs';
12
- export { createFileSessionStorage } from './sessions/fileStorage.mjs';
13
- export { createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable } from './stream.mjs';
package/dist/install.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/install.js DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- var globals = require('./globals.js');
14
-
15
- globals.installGlobals();
package/dist/install.mjs DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { installGlobals } from './globals.mjs';
12
-
13
- installGlobals();
@@ -1,106 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { promises } from 'node:fs';
12
- import * as path from 'node:path';
13
- import { createSessionStorage } from 'react-router';
14
-
15
- /**
16
- * Creates a SessionStorage that stores session data on a filesystem.
17
- *
18
- * The advantage of using this instead of cookie session storage is that
19
- * files may contain much more data than cookies.
20
- *
21
- * @see https://remix.run/utils/sessions#createfilesessionstorage-node
22
- */
23
- function createFileSessionStorage({
24
- cookie,
25
- dir
26
- }) {
27
- return createSessionStorage({
28
- cookie,
29
- async createData(data, expires) {
30
- let content = JSON.stringify({
31
- data,
32
- expires
33
- });
34
- while (true) {
35
- let randomBytes = crypto.getRandomValues(new Uint8Array(8));
36
- // This storage manages an id space of 2^64 ids, which is far greater
37
- // than the maximum number of files allowed on an NTFS or ext4 volume
38
- // (2^32). However, the larger id space should help to avoid collisions
39
- // with existing ids when creating new sessions, which speeds things up.
40
- let id = Buffer.from(randomBytes).toString("hex");
41
- try {
42
- let file = getFile(dir, id);
43
- await promises.mkdir(path.dirname(file), {
44
- recursive: true
45
- });
46
- await promises.writeFile(file, content, {
47
- encoding: "utf-8",
48
- flag: "wx"
49
- });
50
- return id;
51
- } catch (error) {
52
- if (error.code !== "EEXIST") throw error;
53
- }
54
- }
55
- },
56
- async readData(id) {
57
- try {
58
- let file = getFile(dir, id);
59
- let content = JSON.parse(await promises.readFile(file, "utf-8"));
60
- let data = content.data;
61
- let expires = typeof content.expires === "string" ? new Date(content.expires) : null;
62
- if (!expires || expires > new Date()) {
63
- return data;
64
- }
65
- // Remove expired session data.
66
- if (expires) await promises.unlink(file);
67
- return null;
68
- } catch (error) {
69
- if (error.code !== "ENOENT") throw error;
70
- return null;
71
- }
72
- },
73
- async updateData(id, data, expires) {
74
- let content = JSON.stringify({
75
- data,
76
- expires
77
- });
78
- let file = getFile(dir, id);
79
- await promises.mkdir(path.dirname(file), {
80
- recursive: true
81
- });
82
- await promises.writeFile(file, content, "utf-8");
83
- },
84
- async deleteData(id) {
85
- // Return early if the id is empty, otherwise we'll end up trying to
86
- // unlink the dir, which will cause the EPERM error.
87
- if (!id) {
88
- return;
89
- }
90
- try {
91
- await promises.unlink(getFile(dir, id));
92
- } catch (error) {
93
- if (error.code !== "ENOENT") throw error;
94
- }
95
- }
96
- });
97
- }
98
- function getFile(dir, id) {
99
- // Divide the session id up into a directory (first 2 bytes) and filename
100
- // (remaining 6 bytes) to reduce the chance of having very large directories,
101
- // which should speed up file access. This is a maximum of 2^16 directories,
102
- // each with 2^48 files.
103
- return path.join(dir, id.slice(0, 4), id.slice(4));
104
- }
105
-
106
- export { createFileSessionStorage, getFile };
package/dist/stream.mjs DELETED
@@ -1,139 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { Stream } from 'node:stream';
12
-
13
- async function writeReadableStreamToWritable(stream, writable) {
14
- let reader = stream.getReader();
15
- let flushable = writable;
16
- try {
17
- while (true) {
18
- let {
19
- done,
20
- value
21
- } = await reader.read();
22
- if (done) {
23
- writable.end();
24
- break;
25
- }
26
- writable.write(value);
27
- if (typeof flushable.flush === "function") {
28
- flushable.flush();
29
- }
30
- }
31
- } catch (error) {
32
- writable.destroy(error);
33
- throw error;
34
- }
35
- }
36
- async function writeAsyncIterableToWritable(iterable, writable) {
37
- try {
38
- for await (let chunk of iterable) {
39
- writable.write(chunk);
40
- }
41
- writable.end();
42
- } catch (error) {
43
- writable.destroy(error);
44
- throw error;
45
- }
46
- }
47
- async function readableStreamToString(stream, encoding) {
48
- let reader = stream.getReader();
49
- let chunks = [];
50
- while (true) {
51
- let {
52
- done,
53
- value
54
- } = await reader.read();
55
- if (done) {
56
- break;
57
- }
58
- if (value) {
59
- chunks.push(value);
60
- }
61
- }
62
- return Buffer.concat(chunks).toString(encoding);
63
- }
64
- const createReadableStreamFromReadable = source => {
65
- let pump = new StreamPump(source);
66
- let stream = new ReadableStream(pump, pump);
67
- return stream;
68
- };
69
- class StreamPump {
70
- constructor(stream) {
71
- this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
72
- this.accumalatedSize = 0;
73
- this.stream = stream;
74
- this.enqueue = this.enqueue.bind(this);
75
- this.error = this.error.bind(this);
76
- this.close = this.close.bind(this);
77
- }
78
- size(chunk) {
79
- return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
80
- }
81
- start(controller) {
82
- this.controller = controller;
83
- this.stream.on("data", this.enqueue);
84
- this.stream.once("error", this.error);
85
- this.stream.once("end", this.close);
86
- this.stream.once("close", this.close);
87
- }
88
- pull() {
89
- this.resume();
90
- }
91
- cancel(reason) {
92
- if (this.stream.destroy) {
93
- this.stream.destroy(reason);
94
- }
95
- this.stream.off("data", this.enqueue);
96
- this.stream.off("error", this.error);
97
- this.stream.off("end", this.close);
98
- this.stream.off("close", this.close);
99
- }
100
- enqueue(chunk) {
101
- if (this.controller) {
102
- try {
103
- let bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
104
- let available = (this.controller.desiredSize || 0) - bytes.byteLength;
105
- this.controller.enqueue(bytes);
106
- if (available <= 0) {
107
- this.pause();
108
- }
109
- } catch (error) {
110
- this.controller.error(new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
111
- this.cancel();
112
- }
113
- }
114
- }
115
- pause() {
116
- if (this.stream.pause) {
117
- this.stream.pause();
118
- }
119
- }
120
- resume() {
121
- if (this.stream.readable && this.stream.resume) {
122
- this.stream.resume();
123
- }
124
- }
125
- close() {
126
- if (this.controller) {
127
- this.controller.close();
128
- delete this.controller;
129
- }
130
- }
131
- error(error) {
132
- if (this.controller) {
133
- this.controller.error(error);
134
- delete this.controller;
135
- }
136
- }
137
- }
138
-
139
- export { createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable };