waku 0.15.0 → 0.15.1

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.
@@ -28,7 +28,7 @@ _export(exports, {
28
28
  }
29
29
  });
30
30
  var _react = require("react");
31
- var _client = require("react-server-dom-webpack/client");
31
+ var _client = /*#__PURE__*/ _interop_require_default(require("react-server-dom-webpack/client"));
32
32
  function _array_like_to_array(arr, len) {
33
33
  if (len == null || len > arr.length) len = arr.length;
34
34
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -79,6 +79,11 @@ function _define_property(obj, key, value) {
79
79
  }
80
80
  return obj;
81
81
  }
82
+ function _interop_require_default(obj) {
83
+ return obj && obj.__esModule ? obj : {
84
+ default: obj
85
+ };
86
+ }
82
87
  function _iterable_to_array_limit(arr, i) {
83
88
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
84
89
  if (_i == null) return;
@@ -227,6 +232,7 @@ function _ts_generator(thisArg, body) {
227
232
  };
228
233
  }
229
234
  }
235
+ var createFromFetch = _client.default.createFromFetch, encodeReply = _client.default.encodeReply;
230
236
  var checkStatus = function() {
231
237
  var _ref = _async_to_generator(function(responsePromise) {
232
238
  var response, err;
@@ -293,7 +299,6 @@ var mergeElements = (0, _react.cache)(function() {
293
299
  var fetchRSC = (0, _react.cache)(function(input, rerender) {
294
300
  var basePath = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "/RSC/";
295
301
  var _globalThis;
296
- input || (input = "__DEFAULT__");
297
302
  var options = {
298
303
  callServer: function callServer(actionId, args) {
299
304
  return _async_to_generator(function() {
@@ -309,13 +314,13 @@ var fetchRSC = (0, _react.cache)(function(input, rerender) {
309
314
  };
310
315
  return [
311
316
  4,
312
- (0, _client.encodeReply)(args)
317
+ encodeReply(args)
313
318
  ];
314
319
  case 1:
315
320
  response = fetch.apply(void 0, _tmp.concat([
316
321
  (_tmp1.body = _state.sent(), _tmp1)
317
322
  ]));
318
- data = (0, _client.createFromFetch)(checkStatus(response), options);
323
+ data = createFromFetch(checkStatus(response), options);
319
324
  (0, _react.startTransition)(function() {
320
325
  // FIXME this causes rerenders even if data is empty
321
326
  rerender(function(prev) {
@@ -337,9 +342,9 @@ var fetchRSC = (0, _react.cache)(function(input, rerender) {
337
342
  }
338
343
  };
339
344
  var prefetched = (_globalThis = globalThis).__WAKU_PREFETCHED__ || (_globalThis.__WAKU_PREFETCHED__ = {});
340
- var response = prefetched[input] || fetch(basePath + input);
345
+ var response = prefetched[input] || fetch(basePath + (input || "__DEFAULT__"));
341
346
  delete prefetched[input];
342
- var data = (0, _client.createFromFetch)(checkStatus(response), options);
347
+ var data = createFromFetch(checkStatus(response), options);
343
348
  return data;
344
349
  });
345
350
  var RefetchContext = (0, _react.createContext)(null);
@@ -312,6 +312,9 @@ var analyzeEntries = function() {
312
312
  return serverEntryFileSet.add(id);
313
313
  })
314
314
  ],
315
+ ssr: {
316
+ noExternal: /^(?!node:)/
317
+ },
315
318
  resolve: {
316
319
  conditions: [
317
320
  "react-server"
@@ -396,6 +399,12 @@ var buildServerBundle = function() {
396
399
  return [
397
400
  4,
398
401
  (0, _vite.build)(_object_spread_props(_object_spread({}, (0, _config.configFileConfig)()), {
402
+ ssr: {
403
+ noExternal: Object.values(clientEntryFiles).map(// FIXME this might not work with pnpm
404
+ function(fname) {
405
+ return _nodepath.default.relative(_nodepath.default.join(config.root, "node_modules"), fname).split("/")[0];
406
+ })
407
+ },
399
408
  resolve: {
400
409
  conditions: [
401
410
  "react-server"
@@ -585,7 +594,7 @@ var emitRscFiles = function() {
585
594
  case 0:
586
595
  _step_value = _sliced_to_array(_step.value, 1), input = _step_value[0];
587
596
  destFile = _nodepath.default.join(config.root, config.framework.distDir, config.framework.publicDir, // HACK to support windows filesystem
588
- (config.framework.rscPrefix + (input === "" ? "__DEFAULT__" : input)).replaceAll("/", _nodepath.default.sep));
597
+ (config.framework.rscPrefix + (input || "__DEFAULT__")).replaceAll("/", _nodepath.default.sep));
589
598
  if (!!rscFileSet.has(destFile)) return [
590
599
  3,
591
600
  3
@@ -234,7 +234,7 @@ function devServer() {
234
234
  });
235
235
  return function() {
236
236
  var _ref = _async_to_generator(function(req, res, next) {
237
- var _req_url, vite, fname, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item;
237
+ var vite, fname, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item;
238
238
  return _ts_generator(this, function(_state) {
239
239
  switch(_state.label){
240
240
  case 0:
@@ -244,8 +244,8 @@ function devServer() {
244
244
  ];
245
245
  case 1:
246
246
  vite = _state.sent();
247
- if ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith("/node_modules/")) {
248
- fname = _nodepath.default.join(vite.config.root, req.url);
247
+ if (req.url) {
248
+ fname = req.url.startsWith("/@fs/") ? req.url.slice(4) : _nodepath.default.join(vite.config.root, req.url);
249
249
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
250
250
  try {
251
251
  for(_iterator = vite.moduleGraph.idToModuleMap.values()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -37,7 +37,7 @@ var generatePrefetchCode = function(basePrefix, inputs, moduleIds) {
37
37
  var code = "";
38
38
  if (inputsArray.length) {
39
39
  code += "\nglobalThis.__WAKU_PREFETCHED__ = {\n".concat(inputsArray.map(function(input) {
40
- return " '".concat(input, "': fetch('").concat(basePrefix).concat(input, "')");
40
+ return " '".concat(input, "': fetch('").concat(basePrefix).concat(input || "__DEFAULT__", "')");
41
41
  }).join(",\n"), "\n};");
42
42
  }
43
43
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -616,6 +616,9 @@ var getEntriesFile = function() {
616
616
  };
617
617
  }();
618
618
  var resolveClientEntry = function(filePath, config, command) {
619
+ if (filePath.startsWith("file://")) {
620
+ filePath = filePath.slice(7);
621
+ }
619
622
  var root = _nodepath.default.join(config.root, command === "dev" ? config.framework.srcDir : config.framework.distDir);
620
623
  if (_nodepath.default.sep !== "/") {
621
624
  // HACK to support windows filesystem
package/dist/client.js CHANGED
@@ -199,7 +199,8 @@ function _ts_generator(thisArg, body) {
199
199
  }
200
200
  }
201
201
  import { cache, createContext, createElement, memo, use, useCallback, useState, startTransition } from "react";
202
- import { createFromFetch, encodeReply } from "react-server-dom-webpack/client";
202
+ import RSDWClient from "react-server-dom-webpack/client";
203
+ var createFromFetch = RSDWClient.createFromFetch, encodeReply = RSDWClient.encodeReply;
203
204
  var checkStatus = function() {
204
205
  var _ref = _async_to_generator(function(responsePromise) {
205
206
  var response, err;
@@ -267,7 +268,6 @@ var mergeElements = cache(function() {
267
268
  export var fetchRSC = cache(function(input, rerender) {
268
269
  var basePath = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "/RSC/";
269
270
  var _globalThis;
270
- input || (input = "__DEFAULT__");
271
271
  var options = {
272
272
  callServer: function callServer(actionId, args) {
273
273
  return _async_to_generator(function() {
@@ -311,7 +311,7 @@ export var fetchRSC = cache(function(input, rerender) {
311
311
  }
312
312
  };
313
313
  var prefetched = (_globalThis = globalThis).__WAKU_PREFETCHED__ || (_globalThis.__WAKU_PREFETCHED__ = {});
314
- var response = prefetched[input] || fetch(basePath + input);
314
+ var response = prefetched[input] || fetch(basePath + (input || "__DEFAULT__"));
315
315
  delete prefetched[input];
316
316
  var data = createFromFetch(checkStatus(response), options);
317
317
  return data;
@@ -297,6 +297,9 @@ var analyzeEntries = function() {
297
297
  return serverEntryFileSet.add(id);
298
298
  })
299
299
  ],
300
+ ssr: {
301
+ noExternal: /^(?!node:)/
302
+ },
300
303
  resolve: {
301
304
  conditions: [
302
305
  "react-server"
@@ -381,6 +384,12 @@ var buildServerBundle = function() {
381
384
  return [
382
385
  4,
383
386
  viteBuild(_object_spread_props(_object_spread({}, configFileConfig()), {
387
+ ssr: {
388
+ noExternal: Object.values(clientEntryFiles).map(// FIXME this might not work with pnpm
389
+ function(fname) {
390
+ return path.relative(path.join(config.root, "node_modules"), fname).split("/")[0];
391
+ })
392
+ },
384
393
  resolve: {
385
394
  conditions: [
386
395
  "react-server"
@@ -570,7 +579,7 @@ var emitRscFiles = function() {
570
579
  case 0:
571
580
  _step_value = _sliced_to_array(_step.value, 1), input = _step_value[0];
572
581
  destFile = path.join(config.root, config.framework.distDir, config.framework.publicDir, // HACK to support windows filesystem
573
- (config.framework.rscPrefix + (input === "" ? "__DEFAULT__" : input)).replaceAll("/", path.sep));
582
+ (config.framework.rscPrefix + (input || "__DEFAULT__")).replaceAll("/", path.sep));
574
583
  if (!!rscFileSet.has(destFile)) return [
575
584
  3,
576
585
  3
@@ -219,7 +219,7 @@ export function devServer() {
219
219
  });
220
220
  return function() {
221
221
  var _ref = _async_to_generator(function(req, res, next) {
222
- var _req_url, vite, fname, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item;
222
+ var vite, fname, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item;
223
223
  return _ts_generator(this, function(_state) {
224
224
  switch(_state.label){
225
225
  case 0:
@@ -229,8 +229,8 @@ export function devServer() {
229
229
  ];
230
230
  case 1:
231
231
  vite = _state.sent();
232
- if ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith("/node_modules/")) {
233
- fname = path.join(vite.config.root, req.url);
232
+ if (req.url) {
233
+ fname = req.url.startsWith("/@fs/") ? req.url.slice(4) : path.join(vite.config.root, req.url);
234
234
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
235
235
  try {
236
236
  for(_iterator = vite.moduleGraph.idToModuleMap.values()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -10,7 +10,7 @@ export var generatePrefetchCode = function(basePrefix, inputs, moduleIds) {
10
10
  var code = "";
11
11
  if (inputsArray.length) {
12
12
  code += "\nglobalThis.__WAKU_PREFETCHED__ = {\n".concat(inputsArray.map(function(input) {
13
- return " '".concat(input, "': fetch('").concat(basePrefix).concat(input, "')");
13
+ return " '".concat(input, "': fetch('").concat(basePrefix).concat(input || "__DEFAULT__", "')");
14
14
  }).join(",\n"), "\n};");
15
15
  }
16
16
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -607,6 +607,9 @@ var getEntriesFile = function() {
607
607
  };
608
608
  }();
609
609
  var resolveClientEntry = function(filePath, config, command) {
610
+ if (filePath.startsWith("file://")) {
611
+ filePath = filePath.slice(7);
612
+ }
610
613
  var root = path.join(config.root, command === "dev" ? config.framework.srcDir : config.framework.distDir);
611
614
  if (path.sep !== "/") {
612
615
  // HACK to support windows filesystem
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "waku",
3
3
  "description": "Minimalistic React Framework",
4
- "version": "0.15.0",
4
+ "version": "0.15.1",
5
5
  "type": "module",
6
6
  "author": "Daishi Kato",
7
7
  "repository": {
package/src/client.ts CHANGED
@@ -13,7 +13,9 @@ import {
13
13
  startTransition,
14
14
  } from "react";
15
15
  import type { ReactNode } from "react";
16
- import { createFromFetch, encodeReply } from "react-server-dom-webpack/client";
16
+ import RSDWClient from "react-server-dom-webpack/client";
17
+
18
+ const { createFromFetch, encodeReply } = RSDWClient;
17
19
 
18
20
  const checkStatus = async (
19
21
  responsePromise: Promise<Response>,
@@ -45,7 +47,6 @@ export const fetchRSC = cache(
45
47
  rerender: (fn: (prev: Elements) => Elements) => void,
46
48
  basePath = "/RSC/",
47
49
  ): Elements => {
48
- input ||= "__DEFAULT__";
49
50
  const options = {
50
51
  async callServer(actionId: string, args: unknown[]) {
51
52
  const response = fetch(basePath + encodeURIComponent(actionId), {
@@ -61,7 +62,8 @@ export const fetchRSC = cache(
61
62
  },
62
63
  };
63
64
  const prefetched = ((globalThis as any).__WAKU_PREFETCHED__ ||= {});
64
- const response = prefetched[input] || fetch(basePath + input);
65
+ const response =
66
+ prefetched[input] || fetch(basePath + (input || "__DEFAULT__"));
65
67
  delete prefetched[input];
66
68
  const data = createFromFetch(checkStatus(response), options);
67
69
  return data;
@@ -59,6 +59,9 @@ const analyzeEntries = async (entriesFile: string) => {
59
59
  (id) => serverEntryFileSet.add(id),
60
60
  ),
61
61
  ],
62
+ ssr: {
63
+ noExternal: /^(?!node:)/,
64
+ },
62
65
  resolve: {
63
66
  conditions: ["react-server"],
64
67
  },
@@ -98,6 +101,15 @@ const buildServerBundle = async (
98
101
  ) => {
99
102
  const serverBuildOutput = await viteBuild({
100
103
  ...configFileConfig(),
104
+ ssr: {
105
+ noExternal: Object.values(clientEntryFiles).map(
106
+ // FIXME this might not work with pnpm
107
+ (fname) =>
108
+ path
109
+ .relative(path.join(config.root, "node_modules"), fname)
110
+ .split("/")[0]!,
111
+ ),
112
+ },
101
113
  resolve: {
102
114
  conditions: ["react-server"],
103
115
  },
@@ -239,9 +251,10 @@ const emitRscFiles = async (
239
251
  config.framework.distDir,
240
252
  config.framework.publicDir,
241
253
  // HACK to support windows filesystem
242
- (
243
- config.framework.rscPrefix + (input === "" ? "__DEFAULT__" : input)
244
- ).replaceAll("/", path.sep),
254
+ (config.framework.rscPrefix + (input || "__DEFAULT__")).replaceAll(
255
+ "/",
256
+ path.sep,
257
+ ),
245
258
  );
246
259
  if (!rscFileSet.has(destFile)) {
247
260
  rscFileSet.add(destFile);
@@ -44,9 +44,11 @@ export function devServer(): Middleware {
44
44
  });
45
45
  return async (req, res, next) => {
46
46
  const vite = await vitePromise;
47
- if (req.url?.startsWith("/node_modules/")) {
47
+ if (req.url) {
48
48
  // HACK re-export "?v=..." URL to avoid dual module hazard.
49
- const fname = path.join(vite.config.root, req.url);
49
+ const fname = req.url.startsWith("/@fs/")
50
+ ? req.url.slice(4)
51
+ : path.join(vite.config.root, req.url);
50
52
  for (const item of vite.moduleGraph.idToModuleMap.values()) {
51
53
  if (item.file === fname && item.url !== req.url) {
52
54
  res.setHeader("Content-Type", "application/javascript");
@@ -20,7 +20,9 @@ export const generatePrefetchCode = (
20
20
  code += `
21
21
  globalThis.__WAKU_PREFETCHED__ = {
22
22
  ${inputsArray
23
- .map((input) => ` '${input}': fetch('${basePrefix}${input}')`)
23
+ .map(
24
+ (input) => ` '${input}': fetch('${basePrefix}${input || "__DEFAULT__"}')`,
25
+ )
24
26
  .join(",\n")}
25
27
  };`;
26
28
  }
@@ -180,6 +180,9 @@ const resolveClientEntry = (
180
180
  config: Awaited<ReturnType<typeof resolveConfig>>,
181
181
  command: "dev" | "build" | "start",
182
182
  ) => {
183
+ if (filePath.startsWith("file://")) {
184
+ filePath = filePath.slice(7);
185
+ }
183
186
  let root = path.join(
184
187
  config.root,
185
188
  command === "dev" ? config.framework.srcDir : config.framework.distDir,