rwsdk 0.1.8-test.20250702232536 โ†’ 0.1.8

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/bin/rwsync CHANGED
@@ -1,12 +1,2 @@
1
1
  #!/bin/sh
2
- set -e
3
-
4
- # This script is a lightweight wrapper that passes all arguments to the underlying
5
- # debug:sync Node.js script.
6
- # The RWSDK_REPO env var should point to the root of the sdk repo.
7
-
8
- # Capture the current directory *before* changing it
9
- TARGET_DIR=$PWD
10
-
11
- cd "${RWSDK_REPO}/sdk"
12
- pnpm debug:sync "$TARGET_DIR" "$@"
2
+ DIR=$PWD && (cd "${@:-$RWSDK_REPO}/sdk" && pnpm debug:sync $DIR)
@@ -1,6 +1,8 @@
1
1
  export interface DebugSyncOptions {
2
2
  targetDir: string;
3
3
  sdkDir?: string;
4
- watch?: string | boolean;
4
+ dev?: boolean;
5
+ watch?: boolean;
6
+ build?: boolean;
5
7
  }
6
8
  export declare const debugSync: (opts: DebugSyncOptions) => Promise<void>;
@@ -1,9 +1,8 @@
1
1
  import path from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- import { $ } from "execa";
3
+ import { $ } from "../lib/$.mjs";
4
4
  import fs from "node:fs/promises";
5
5
  import { existsSync } from "node:fs";
6
- import chokidar from "chokidar";
7
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
7
  const getPackageManagerInfo = (targetDir) => {
9
8
  if (existsSync(path.join(targetDir, "yarn.lock"))) {
@@ -14,16 +13,14 @@ const getPackageManagerInfo = (targetDir) => {
14
13
  }
15
14
  return { name: "npm", lockFile: "package-lock.json", command: "install" };
16
15
  };
17
- const performFullSync = async (sdkDir, targetDir) => {
18
- console.log("๐Ÿ“ฆ Packing SDK...");
19
- const packResult = await $ `npm pack`;
16
+ const performSync = async (sdkDir, targetDir) => {
17
+ console.log("๐Ÿ—๏ธ rebuilding sdk...");
18
+ await $({ cwd: sdkDir, stdio: "inherit", shell: true }) `pnpm build`;
19
+ console.log("๐Ÿ“ฆ packing sdk...");
20
+ const packResult = await $({ cwd: sdkDir, shell: true }) `npm pack`;
20
21
  const tarballName = packResult.stdout?.trim() ?? "";
21
- if (!tarballName) {
22
- console.error("โŒ Failed to get tarball name from npm pack.");
23
- return;
24
- }
25
22
  const tarballPath = path.resolve(sdkDir, tarballName);
26
- console.log(`๐Ÿ’ฟ Installing ${tarballName} in ${targetDir}...`);
23
+ console.log(` installing ${tarballName} in ${targetDir}...`);
27
24
  const pm = getPackageManagerInfo(targetDir);
28
25
  const packageJsonPath = path.join(targetDir, "package.json");
29
26
  const lockfilePath = path.join(targetDir, pm.lockFile);
@@ -38,7 +35,11 @@ const performFullSync = async (sdkDir, targetDir) => {
38
35
  if (pm.name === "yarn") {
39
36
  installCommand = `yarn add file:${tarballPath}`;
40
37
  }
41
- await $ `${installCommand}`;
38
+ await $({
39
+ cwd: targetDir,
40
+ stdio: "inherit",
41
+ shell: true,
42
+ }) `${installCommand}`;
42
43
  }
43
44
  finally {
44
45
  if (originalPackageJson) {
@@ -53,113 +54,67 @@ const performFullSync = async (sdkDir, targetDir) => {
53
54
  // ignore if deletion fails
54
55
  });
55
56
  }
56
- };
57
- const performFastSync = async (sdkDir, targetDir) => {
58
- console.log("โšก๏ธ No dependency changes, performing fast sync...");
59
- const sdkPackageJson = JSON.parse(await fs.readFile(path.join(sdkDir, "package.json"), "utf-8"));
60
- const filesToSync = sdkPackageJson.files || [];
61
- for (const file of filesToSync) {
62
- const source = path.join(sdkDir, file);
63
- const destination = path.join(targetDir, "node_modules/rwsdk", file);
64
- if (existsSync(source)) {
65
- await fs.cp(source, destination, { recursive: true, force: true });
66
- }
67
- }
68
- // Always copy package.json
69
- await fs.copyFile(path.join(sdkDir, "package.json"), path.join(targetDir, "node_modules/rwsdk/package.json"));
70
- };
71
- const performSync = async (sdkDir, targetDir) => {
72
- console.log("๐Ÿ—๏ธ Rebuilding SDK...");
73
- await $ `pnpm build`;
74
- const sdkPackageJsonPath = path.join(sdkDir, "package.json");
75
- const installedSdkPackageJsonPath = path.join(targetDir, "node_modules/rwsdk/package.json");
76
- let packageJsonChanged = true;
77
- if (existsSync(installedSdkPackageJsonPath)) {
78
- const sdkPackageJsonContent = await fs.readFile(sdkPackageJsonPath, "utf-8");
79
- const installedSdkPackageJsonContent = await fs.readFile(installedSdkPackageJsonPath, "utf-8");
80
- if (sdkPackageJsonContent === installedSdkPackageJsonContent) {
81
- packageJsonChanged = false;
82
- }
83
- }
84
- if (packageJsonChanged) {
85
- console.log("๐Ÿ“ฆ package.json changed, performing full sync...");
86
- await performFullSync(sdkDir, targetDir);
87
- }
88
- else {
89
- await performFastSync(sdkDir, targetDir);
90
- }
91
- console.log("โœ… Done syncing");
57
+ console.log("โœ… done syncing");
92
58
  };
93
59
  export const debugSync = async (opts) => {
94
- const { targetDir, sdkDir = process.cwd(), watch } = opts;
60
+ const { targetDir, sdkDir = process.cwd(), dev, watch, build } = opts;
95
61
  if (!targetDir) {
96
62
  console.error("โŒ Please provide a target directory as an argument.");
97
63
  process.exit(1);
98
64
  }
99
- // Initial sync
65
+ const thisScriptPath = fileURLToPath(import.meta.url);
66
+ const syncCommand = `tsx ${thisScriptPath} --_sync ${sdkDir} ${targetDir}`;
67
+ // Run initial sync
100
68
  await performSync(sdkDir, targetDir);
101
- if (watch) {
102
- const sdkPackageJson = JSON.parse(await fs.readFile(path.join(sdkDir, "package.json"), "utf-8"));
103
- const filesToWatch = (sdkPackageJson.files || []).map((p) => path.join(sdkDir, p));
104
- filesToWatch.push(path.join(sdkDir, "package.json"));
69
+ if (!process.env.NO_CLEAN_VITE) {
70
+ console.log("๐Ÿงน Cleaning Vite cache...");
71
+ await $({
72
+ stdio: "inherit",
73
+ shell: true,
74
+ cwd: targetDir,
75
+ }) `rm -rf ${targetDir}/node_modules/.vite*`;
76
+ }
77
+ // If dev flag is present, clean vite cache and start dev server
78
+ if (dev) {
79
+ console.log("๐Ÿš€ Starting dev server...");
80
+ await $({ stdio: "inherit", shell: true, cwd: targetDir }) `npm run dev`;
81
+ }
82
+ // Start watching if watch flag is present
83
+ else if (watch) {
105
84
  console.log("๐Ÿ‘€ Watching for changes...");
106
- let childProc = null;
107
- const runWatchedCommand = () => {
108
- if (typeof watch === "string") {
109
- console.log(`\n> ${watch}\n`);
110
- childProc = $({
111
- stdio: "inherit",
112
- shell: true,
113
- cwd: targetDir,
114
- reject: false,
115
- }) `${watch}`;
116
- }
117
- };
118
- const watcher = chokidar.watch(filesToWatch, {
119
- ignoreInitial: true,
85
+ $({
86
+ stdio: "inherit",
87
+ shell: true,
120
88
  cwd: sdkDir,
121
- });
122
- watcher.on("all", async () => {
123
- console.log("\n Detected change, re-syncing...");
124
- if (childProc && !childProc.killed) {
125
- console.log("Stopping running process...");
126
- childProc.kill();
127
- await childProc.catch(() => {
128
- /* ignore kill errors */
129
- });
130
- }
131
- await performSync(sdkDir, targetDir);
132
- runWatchedCommand();
133
- });
134
- const cleanup = () => {
135
- if (childProc && !childProc.killed) {
136
- childProc.kill();
137
- }
138
- };
139
- process.on("SIGINT", cleanup);
140
- process.on("SIGTERM", cleanup);
141
- runWatchedCommand();
89
+ }) `npx chokidar-cli './src/**' './package.json' -c "${syncCommand}"`;
90
+ }
91
+ else if (build) {
92
+ console.log("๐Ÿ—๏ธ Running build in target directory...");
93
+ await $({
94
+ stdio: "inherit",
95
+ shell: true,
96
+ cwd: targetDir,
97
+ }) `npm run build`;
142
98
  }
143
99
  };
144
100
  if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
145
101
  const args = process.argv.slice(2);
146
- const watchFlagIndex = args.indexOf("--watch");
147
- let watchCmd = watchFlagIndex !== -1;
148
- let cmdArgs = args;
149
- if (watchFlagIndex !== -1) {
150
- if (watchFlagIndex + 1 < args.length &&
151
- !args[watchFlagIndex + 1].startsWith("--")) {
152
- watchCmd = args[watchFlagIndex + 1];
153
- }
154
- // remove --watch and its potential command from args
155
- const watchArgCount = typeof watchCmd === "string" ? 2 : 1;
156
- cmdArgs = args.filter((_, i) => i < watchFlagIndex || i >= watchFlagIndex + watchArgCount);
102
+ const flags = new Set(args.filter((arg) => arg.startsWith("--")));
103
+ const positionalArgs = args.filter((arg) => !arg.startsWith("--"));
104
+ if (flags.has("--_sync")) {
105
+ const [sdkDir, targetDir] = positionalArgs;
106
+ await performSync(sdkDir, targetDir);
107
+ }
108
+ else {
109
+ const targetDir = positionalArgs[0] ?? process.cwd();
110
+ debugSync({
111
+ targetDir,
112
+ sdkDir: process.env.RWSDK_REPO
113
+ ? path.resolve(__dirname, process.env.RWSDK_REPO, "sdk")
114
+ : path.resolve(__dirname, "..", ".."),
115
+ dev: flags.has("--dev"),
116
+ watch: flags.has("--watch"),
117
+ build: flags.has("--build"),
118
+ });
157
119
  }
158
- const targetDir = cmdArgs[0] ?? process.cwd();
159
- const sdkDir = path.resolve(__dirname, "..", "..");
160
- debugSync({
161
- targetDir,
162
- sdkDir,
163
- watch: watchCmd,
164
- });
165
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "0.1.8-test.20250702232536",
3
+ "version": "0.1.8",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {
@@ -120,7 +120,6 @@
120
120
  "@types/react-dom": "^19.1.2",
121
121
  "@types/react-is": "^19.0.0",
122
122
  "@vitejs/plugin-react": "^4.3.4",
123
- "chokidar": "^3.6.0",
124
123
  "debug": "^4.4.0",
125
124
  "enhanced-resolve": "^5.18.1",
126
125
  "eventsource-parser": "^3.0.0",