@gxp-dev/tools 2.0.88 → 2.0.89

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.
@@ -218,6 +218,21 @@ function devCommand(argv) {
218
218
  const paths = resolveGxPaths()
219
219
  const projectPath = findProjectRoot()
220
220
 
221
+ // Surface which toolkit install is being used. resolveGxPaths() prefers
222
+ // <project>/node_modules/@gxp-dev/tools (local) and falls back to the
223
+ // CLI's own install location (global / npm link / workspace).
224
+ const localToolkitDir = path.join(
225
+ projectPath,
226
+ "node_modules",
227
+ "@gxp-dev",
228
+ "tools",
229
+ )
230
+ const installLocation =
231
+ paths.packageRoot === localToolkitDir ? "local" : "package"
232
+ logger.info(
233
+ `📦 Using ${installLocation} toolkit install: ${paths.packageRoot}`,
234
+ )
235
+
221
236
  // Load .env file if it exists for default values
222
237
  const envPath = path.join(projectPath, ".env")
223
238
  const envExamplePath = path.join(projectPath, ".env.example")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gxp-dev/tools",
3
- "version": "2.0.88",
3
+ "version": "2.0.89",
4
4
  "description": "Dev tools to create platform plugins",
5
5
  "type": "commonjs",
6
6
  "publishConfig": {
@@ -172,6 +172,22 @@ export default defineConfig(async (ctx) => {
172
172
  console.log(`📄 index.html: ${useLocalIndex ? "local" : "runtime"}`)
173
173
  console.log(`📄 main.js: ${useLocalMain ? "local" : "runtime"}`)
174
174
 
175
+ // Build /@fs/ URLs that work regardless of whether the toolkit is inside
176
+ // the project's node_modules or installed globally. Vite's /@fs/ handler
177
+ // serves these via server.fs.allow (which already includes toolkitPath),
178
+ // so absolute paths outside process.cwd() just work.
179
+ const realRuntimeDir = (() => {
180
+ try {
181
+ return fs.realpathSync(runtimeDir)
182
+ } catch {
183
+ return runtimeDir
184
+ }
185
+ })().replace(/\\/g, "/")
186
+ const toFsUrl = (relPath) =>
187
+ `/@fs${realRuntimeDir.startsWith("/") ? "" : "/"}${realRuntimeDir}/${relPath}`
188
+ const runtimeMainFsUrl = toFsUrl("main.js")
189
+ const runtimeLogoFsUrl = toFsUrl("logo.png")
190
+
175
191
  // Create plugin to serve runtime files (index.html and main.js) if no local ones exist
176
192
  const runtimeFilesPlugin = {
177
193
  name: "runtime-files",
@@ -205,15 +221,21 @@ export default defineConfig(async (ctx) => {
205
221
  ) {
206
222
  const runtimeIndexPath = path.join(runtimeDir, "index.html")
207
223
  if (fs.existsSync(runtimeIndexPath)) {
208
- // Read and transform the runtime index.html
224
+ // Rewrite hard-coded references to runtime assets so they
225
+ // resolve via Vite's /@fs/ handler instead of a guessed
226
+ // /node_modules/... path. This is what makes the same
227
+ // runtime work for local, linked, and global installs.
228
+ let html = fs.readFileSync(runtimeIndexPath, "utf-8")
229
+ html = html
230
+ .split("/node_modules/@gxp-dev/tools/runtime/logo.png")
231
+ .join(runtimeLogoFsUrl)
232
+ .split("/@gx-runtime/main.js")
233
+ .join(useLocalMain ? "/main.js" : runtimeMainFsUrl)
209
234
  server
210
- .transformIndexHtml(
211
- rawUrl,
212
- fs.readFileSync(runtimeIndexPath, "utf-8"),
213
- )
214
- .then((html) => {
235
+ .transformIndexHtml(rawUrl, html)
236
+ .then((transformed) => {
215
237
  res.setHeader("Content-Type", "text/html")
216
- res.end(html)
238
+ res.end(transformed)
217
239
  })
218
240
  .catch((err) => {
219
241
  console.error("Error transforming index.html:", err)
@@ -223,32 +245,24 @@ export default defineConfig(async (ctx) => {
223
245
  }
224
246
  }
225
247
 
226
- // Serve runtime main.js for @gx-runtime/main.js requests (unless local main.js is opted in)
248
+ // Back-compat: anything still hitting the legacy
249
+ // `/@gx-runtime/main.js` URL (e.g. a hand-rolled index.html)
250
+ // is redirected to the /@fs/ URL. The old transformRequest
251
+ // approach passed an absolute filesystem path and only worked
252
+ // when runtimeDir was inside process.cwd() — i.e. for local
253
+ // installs but not global ones.
227
254
  if (
228
255
  !useLocalMain &&
229
- (req.url === "/@gx-runtime/main.js" ||
230
- req.url?.startsWith("/@gx-runtime/main.js?"))
256
+ (urlPath === "/@gx-runtime/main.js" ||
257
+ urlPath.startsWith("/@gx-runtime/main.js"))
231
258
  ) {
232
- const runtimeMainPath = path.join(runtimeDir, "main.js")
233
- if (fs.existsSync(runtimeMainPath)) {
234
- // Use the real path to handle symlinks correctly
235
- const realMainPath = fs.realpathSync(runtimeMainPath)
236
- server
237
- .transformRequest(realMainPath)
238
- .then((result) => {
239
- if (result) {
240
- res.setHeader("Content-Type", "application/javascript")
241
- res.end(result.code)
242
- } else {
243
- next()
244
- }
245
- })
246
- .catch((err) => {
247
- console.error("Error transforming main.js:", err)
248
- next(err)
249
- })
250
- return
251
- }
259
+ const query = rawUrl.includes("?")
260
+ ? rawUrl.slice(rawUrl.indexOf("?"))
261
+ : ""
262
+ res.statusCode = 302
263
+ res.setHeader("Location", runtimeMainFsUrl + query)
264
+ res.end()
265
+ return
252
266
  }
253
267
 
254
268
  next()