@b9g/shovel 0.2.0-beta.5 → 0.2.0-beta.7

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.
Files changed (2) hide show
  1. package/bin/cli.js +21 -44
  2. package/package.json +11 -11
package/bin/cli.js CHANGED
@@ -23,9 +23,9 @@ import * as Platform from "@b9g/platform";
23
23
 
24
24
  // src/esbuild/watcher.ts
25
25
  import * as ESBuild from "esbuild";
26
- import { resolve, dirname as dirname2, join } from "path";
27
- import { readFileSync } from "fs";
28
- import { mkdir, unlink } from "fs/promises";
26
+ import { existsSync } from "fs";
27
+ import { resolve, join, dirname as dirname2 } from "path";
28
+ import { mkdir } from "fs/promises";
29
29
  import { assetsPlugin } from "@b9g/assets/plugin";
30
30
 
31
31
  // src/esbuild/import-meta-plugin.ts
@@ -80,27 +80,36 @@ function importMetaPlugin() {
80
80
  // src/esbuild/watcher.ts
81
81
  import { getLogger } from "@logtape/logtape";
82
82
  var logger = getLogger(["watcher"]);
83
+ function findProjectRoot() {
84
+ let dir = process.cwd();
85
+ while (dir !== dirname2(dir)) {
86
+ if (existsSync(join(dir, "package.json"))) {
87
+ return dir;
88
+ }
89
+ dir = dirname2(dir);
90
+ }
91
+ return process.cwd();
92
+ }
83
93
  var Watcher = class {
84
94
  #options;
85
95
  #ctx;
96
+ #projectRoot;
86
97
  #initialBuildComplete;
87
98
  #initialBuildResolve;
88
99
  #currentEntrypoint;
89
- #previousEntrypoint;
90
100
  constructor(options) {
91
101
  this.#options = options;
102
+ this.#projectRoot = findProjectRoot();
92
103
  this.#initialBuildComplete = false;
93
104
  this.#currentEntrypoint = "";
94
- this.#previousEntrypoint = "";
95
105
  }
96
106
  /**
97
107
  * Start watching and building
98
108
  * @returns Result with success status and the hashed entrypoint path
99
109
  */
100
110
  async start() {
101
- const entryPath = resolve(this.#options.entrypoint);
102
- const outputDir = resolve(this.#options.outDir);
103
- const workspaceRoot = this.#findWorkspaceRoot();
111
+ const entryPath = resolve(this.#projectRoot, this.#options.entrypoint);
112
+ const outputDir = resolve(this.#projectRoot, this.#options.outDir);
104
113
  await mkdir(join(outputDir, "server"), { recursive: true });
105
114
  await mkdir(join(outputDir, "static"), { recursive: true });
106
115
  const initialBuildPromise = new Promise((resolve3) => {
@@ -115,7 +124,7 @@ var Watcher = class {
115
124
  outdir: `${outputDir}/server`,
116
125
  entryNames: "[name]-[hash]",
117
126
  metafile: true,
118
- absWorkingDir: workspaceRoot,
127
+ absWorkingDir: this.#projectRoot,
119
128
  plugins: [
120
129
  importMetaPlugin(),
121
130
  assetsPlugin({
@@ -137,34 +146,20 @@ var Watcher = class {
137
146
  const outputs = Object.keys(result.metafile.outputs);
138
147
  const jsOutput = outputs.find((p) => p.endsWith(".js"));
139
148
  if (jsOutput) {
140
- outputPath = resolve(jsOutput);
149
+ outputPath = resolve(this.#projectRoot, jsOutput);
141
150
  }
142
151
  }
143
152
  if (success) {
144
153
  logger.info("Build complete", { entrypoint: outputPath });
145
- if (this.#currentEntrypoint && this.#currentEntrypoint !== outputPath) {
146
- try {
147
- await unlink(this.#currentEntrypoint);
148
- await unlink(this.#currentEntrypoint + ".map").catch(
149
- () => {
150
- }
151
- );
152
- logger.debug("Cleaned up old build", {
153
- oldEntrypoint: this.#currentEntrypoint
154
- });
155
- } catch {
156
- }
157
- }
158
154
  } else {
159
155
  logger.error("Build errors", { errors: result.errors });
160
156
  }
161
- this.#previousEntrypoint = this.#currentEntrypoint;
162
157
  this.#currentEntrypoint = outputPath;
163
158
  if (!this.#initialBuildComplete) {
164
159
  this.#initialBuildComplete = true;
165
160
  this.#initialBuildResolve?.({ success, entrypoint: outputPath });
166
161
  } else {
167
- this.#options.onBuild?.(success, outputPath);
162
+ await this.#options.onBuild?.(success, outputPath);
168
163
  }
169
164
  });
170
165
  }
@@ -187,27 +182,9 @@ var Watcher = class {
187
182
  this.#ctx = void 0;
188
183
  }
189
184
  }
190
- #findWorkspaceRoot() {
191
- const initialCwd = process.cwd();
192
- let workspaceRoot = initialCwd;
193
- while (workspaceRoot !== dirname2(workspaceRoot)) {
194
- try {
195
- const packageJSON = JSON.parse(
196
- readFileSync(resolve(workspaceRoot, "package.json"), "utf8")
197
- );
198
- if (packageJSON.workspaces) {
199
- return workspaceRoot;
200
- }
201
- } catch {
202
- }
203
- workspaceRoot = dirname2(workspaceRoot);
204
- }
205
- return initialCwd;
206
- }
207
185
  };
208
186
 
209
187
  // src/commands/develop.ts
210
- var logger2 = getLogger2(["cli"]);
211
188
  await configure({
212
189
  contextLocalStorage: new AsyncContext.Variable(),
213
190
  sinks: {
@@ -226,6 +203,7 @@ await configure({
226
203
  { category: ["worker"], level: "debug", sinks: ["console"] }
227
204
  ]
228
205
  });
206
+ var logger2 = getLogger2(["cli"]);
229
207
  async function developCommand(entrypoint, options) {
230
208
  try {
231
209
  const platformName = Platform.resolvePlatform(options);
@@ -374,7 +352,6 @@ import { configure as configure2, getConsoleSink as getConsoleSink2, getLogger a
374
352
  import { AsyncContext as AsyncContext2 } from "@b9g/async-context";
375
353
  await configure2({
376
354
  reset: true,
377
- // Allow reconfiguration if already configured
378
355
  contextLocalStorage: new AsyncContext2.Variable(),
379
356
  sinks: {
380
357
  console: getConsoleSink2()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/shovel",
3
- "version": "0.2.0-beta.5",
3
+ "version": "0.2.0-beta.7",
4
4
  "description": "ServiceWorker-first universal deployment platform. Write ServiceWorker apps once, deploy anywhere (Node/Bun/Cloudflare). Registry-based multi-app orchestration.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -21,27 +21,27 @@
21
21
  "source-map": "^0.7.4"
22
22
  },
23
23
  "devDependencies": {
24
- "@b9g/assets": "^0.1.12",
24
+ "@b9g/assets": "^0.1.13",
25
25
  "@b9g/cache": "^0.1.4",
26
26
  "@b9g/crank": "^0.7.2",
27
27
  "@b9g/filesystem": "^0.1.6",
28
28
  "@b9g/http-errors": "^0.1.5",
29
29
  "@b9g/libuild": "^0.1.17",
30
- "@b9g/platform": "^0.1.9",
31
- "@b9g/platform-bun": "^0.1.7",
32
- "@b9g/platform-cloudflare": "^0.1.6",
33
- "@b9g/platform-node": "^0.1.9",
34
- "@b9g/router": "^0.1.7",
30
+ "@b9g/platform": "^0.1.10",
31
+ "@b9g/platform-bun": "^0.1.8",
32
+ "@b9g/platform-cloudflare": "^0.1.7",
33
+ "@b9g/platform-node": "^0.1.10",
34
+ "@b9g/router": "^0.1.8",
35
35
  "@types/bun": "^1.2.2",
36
36
  "mitata": "^1.0.34",
37
37
  "typescript": "^5.7.3"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@b9g/node-webworker": "^0.1.3",
41
- "@b9g/platform": "^0.1.9",
42
- "@b9g/platform-node": "^0.1.9",
43
- "@b9g/platform-cloudflare": "^0.1.6",
44
- "@b9g/platform-bun": "^0.1.7",
41
+ "@b9g/platform": "^0.1.10",
42
+ "@b9g/platform-node": "^0.1.10",
43
+ "@b9g/platform-cloudflare": "^0.1.7",
44
+ "@b9g/platform-bun": "^0.1.8",
45
45
  "@b9g/cache": "^0.1.4",
46
46
  "@b9g/filesystem": "^0.1.6",
47
47
  "@b9g/http-errors": "^0.1.5"