@bonsae/nrg 0.18.3 → 0.18.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonsae/nrg",
3
- "version": "0.18.3",
3
+ "version": "0.18.4",
4
4
  "description": "NRG framework — build Node-RED nodes with Vue 3, TypeScript, and JSON Schema",
5
5
  "author": "Allan Oricil <allanoricil@duck.com>",
6
6
  "license": "MIT",
@@ -1998,7 +1998,7 @@ async function build2(clientBuildOptions, buildContext) {
1998
1998
  import { spawn, execSync } from "child_process";
1999
1999
  import getPort from "get-port";
2000
2000
  import detect from "detect-port";
2001
- import { builtinModules as builtinModules2 } from "module";
2001
+ import { builtinModules as builtinModules2, createRequire as createRequire3 } from "module";
2002
2002
  import treeKill from "tree-kill";
2003
2003
  import fs10 from "fs";
2004
2004
  import os from "os";
@@ -2132,7 +2132,7 @@ var NodeRedLauncher = class {
2132
2132
  }
2133
2133
  const outDir = path10.resolve(this.outDir).split(path10.sep).join("/");
2134
2134
  const cwd = process.cwd().split(path10.sep).join("/");
2135
- const userDir = path10.resolve(cwd, ".node-red");
2135
+ const userDir = path10.resolve(cwd, ".node-red").split(path10.sep).join("/");
2136
2136
  const finalRuntimeSettingsFile = compiledRuntimeSettingsFilepath ? `
2137
2137
  const compiledRuntimeSettings = require("${compiledRuntimeSettingsFilepath.split(path10.sep).join("/")}");
2138
2138
  const settings = compiledRuntimeSettings.default || compiledRuntimeSettings;
@@ -2165,7 +2165,30 @@ module.exports = settings;
2165
2165
  this.compiledRuntimeSettingsFilepath = finalRuntimeSettingsFilepath;
2166
2166
  return finalRuntimeSettingsFilepath;
2167
2167
  }
2168
+ resolveFromLocalNodeModules() {
2169
+ try {
2170
+ const require_ = createRequire3(path10.join(process.cwd(), "package.json"));
2171
+ const pkgJsonPath = require_.resolve("node-red/package.json");
2172
+ const pkgDir = path10.dirname(pkgJsonPath);
2173
+ const pkg = JSON.parse(fs10.readFileSync(pkgJsonPath, "utf-8"));
2174
+ const bin = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.["node-red"];
2175
+ if (!bin) return null;
2176
+ const entry = path10.resolve(pkgDir, bin);
2177
+ return fs10.existsSync(entry) ? entry : null;
2178
+ } catch {
2179
+ return null;
2180
+ }
2181
+ }
2168
2182
  resolveNodeRedEntryPoint() {
2183
+ this.logger.info(`Resolving ${this.nodeRedCommand} entry point...`);
2184
+ const localEntry = this.resolveFromLocalNodeModules();
2185
+ if (localEntry) {
2186
+ this.logger.info(`Resolved from local node_modules: ${localEntry}`);
2187
+ return localEntry;
2188
+ }
2189
+ this.logger.info(
2190
+ `Not found locally, downloading via npx (this may take a while)...`
2191
+ );
2169
2192
  const resolverScript = path10.join(
2170
2193
  os.tmpdir(),
2171
2194
  `nrg-resolve-node-red-${process.pid}.cjs`
@@ -2195,7 +2218,7 @@ for (const d of dirs) {
2195
2218
  try {
2196
2219
  const entryPoint = execSync(
2197
2220
  `npx --yes -p ${this.nodeRedCommand} -c "node ${resolverScript}"`,
2198
- { encoding: "utf-8", timeout: 12e4 }
2221
+ { encoding: "utf-8", timeout: 3e5 }
2199
2222
  ).trim();
2200
2223
  if (!entryPoint || !fs10.existsSync(entryPoint)) {
2201
2224
  throw new NodeRedStartError(
@@ -2204,6 +2227,7 @@ for (const d of dirs) {
2204
2227
  )
2205
2228
  );
2206
2229
  }
2230
+ this.logger.info(`Resolved via npx: ${entryPoint}`);
2207
2231
  return entryPoint;
2208
2232
  } finally {
2209
2233
  try {
package/vite/index.js CHANGED
@@ -110,7 +110,7 @@ function mergeOptions(defaults, overrides) {
110
110
  import { spawn, execSync } from "child_process";
111
111
  import getPort from "get-port";
112
112
  import detect from "detect-port";
113
- import { builtinModules } from "module";
113
+ import { builtinModules, createRequire } from "module";
114
114
  import treeKill from "tree-kill";
115
115
  import fs2 from "fs";
116
116
  import os from "os";
@@ -350,7 +350,7 @@ var NodeRedLauncher = class {
350
350
  }
351
351
  const outDir = path2.resolve(this.outDir).split(path2.sep).join("/");
352
352
  const cwd = process.cwd().split(path2.sep).join("/");
353
- const userDir = path2.resolve(cwd, ".node-red");
353
+ const userDir = path2.resolve(cwd, ".node-red").split(path2.sep).join("/");
354
354
  const finalRuntimeSettingsFile = compiledRuntimeSettingsFilepath ? `
355
355
  const compiledRuntimeSettings = require("${compiledRuntimeSettingsFilepath.split(path2.sep).join("/")}");
356
356
  const settings = compiledRuntimeSettings.default || compiledRuntimeSettings;
@@ -383,7 +383,30 @@ module.exports = settings;
383
383
  this.compiledRuntimeSettingsFilepath = finalRuntimeSettingsFilepath;
384
384
  return finalRuntimeSettingsFilepath;
385
385
  }
386
+ resolveFromLocalNodeModules() {
387
+ try {
388
+ const require_ = createRequire(path2.join(process.cwd(), "package.json"));
389
+ const pkgJsonPath = require_.resolve("node-red/package.json");
390
+ const pkgDir = path2.dirname(pkgJsonPath);
391
+ const pkg = JSON.parse(fs2.readFileSync(pkgJsonPath, "utf-8"));
392
+ const bin = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.["node-red"];
393
+ if (!bin) return null;
394
+ const entry = path2.resolve(pkgDir, bin);
395
+ return fs2.existsSync(entry) ? entry : null;
396
+ } catch {
397
+ return null;
398
+ }
399
+ }
386
400
  resolveNodeRedEntryPoint() {
401
+ this.logger.info(`Resolving ${this.nodeRedCommand} entry point...`);
402
+ const localEntry = this.resolveFromLocalNodeModules();
403
+ if (localEntry) {
404
+ this.logger.info(`Resolved from local node_modules: ${localEntry}`);
405
+ return localEntry;
406
+ }
407
+ this.logger.info(
408
+ `Not found locally, downloading via npx (this may take a while)...`
409
+ );
387
410
  const resolverScript = path2.join(
388
411
  os.tmpdir(),
389
412
  `nrg-resolve-node-red-${process.pid}.cjs`
@@ -413,7 +436,7 @@ for (const d of dirs) {
413
436
  try {
414
437
  const entryPoint = execSync(
415
438
  `npx --yes -p ${this.nodeRedCommand} -c "node ${resolverScript}"`,
416
- { encoding: "utf-8", timeout: 12e4 }
439
+ { encoding: "utf-8", timeout: 3e5 }
417
440
  ).trim();
418
441
  if (!entryPoint || !fs2.existsSync(entryPoint)) {
419
442
  throw new NodeRedStartError(
@@ -422,6 +445,7 @@ for (const d of dirs) {
422
445
  )
423
446
  );
424
447
  }
448
+ this.logger.info(`Resolved via npx: ${entryPoint}`);
425
449
  return entryPoint;
426
450
  } finally {
427
451
  try {
@@ -1311,7 +1335,7 @@ import path11 from "path";
1311
1335
  import fs6 from "fs";
1312
1336
  import path6 from "path";
1313
1337
  import { pathToFileURL as pathToFileURL2 } from "url";
1314
- import { createRequire } from "module";
1338
+ import { createRequire as createRequire2 } from "module";
1315
1339
 
1316
1340
  // src/vite/client/plugins/help-i18n.ts
1317
1341
  var translations = {
@@ -1752,7 +1776,7 @@ function helpGenerator(options) {
1752
1776
  const mod = await import(fileUrl);
1753
1777
  packageFn = mod?.default ?? mod;
1754
1778
  } else if (fs6.existsSync(cjsPath)) {
1755
- const require2 = createRequire(import.meta.url);
1779
+ const require2 = createRequire2(import.meta.url);
1756
1780
  delete require2.cache[cjsPath];
1757
1781
  const rawMod = require2(cjsPath);
1758
1782
  packageFn = rawMod?.default ?? rawMod;
@@ -2096,7 +2120,7 @@ function minifier() {
2096
2120
  }
2097
2121
 
2098
2122
  // src/vite/client/plugins/node-definitions-inliner.ts
2099
- import { createRequire as createRequire2 } from "module";
2123
+ import { createRequire as createRequire3 } from "module";
2100
2124
  import { pathToFileURL as pathToFileURL3 } from "url";
2101
2125
  import path9 from "path";
2102
2126
  import fs9 from "fs";
@@ -2157,7 +2181,7 @@ function nodeDefinitionsInliner(serverOutDir, entryPath, iconsDir, componentsDir
2157
2181
  const mod = await import(fileUrl);
2158
2182
  packageFn = mod?.default ?? mod;
2159
2183
  } else if (fs9.existsSync(cjsEntryPath)) {
2160
- const require2 = createRequire2(import.meta.url);
2184
+ const require2 = createRequire3(import.meta.url);
2161
2185
  delete require2.cache[cjsEntryPath];
2162
2186
  const rawMod = require2(cjsEntryPath);
2163
2187
  packageFn = rawMod?.default ?? rawMod;