@bonsae/nrg 0.18.3 → 0.18.5

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.
@@ -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,33 @@ 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 hasExplicitVersion = this.options.runtime?.version !== void 0 && this.options.runtime.version !== "latest";
2185
+ if (!hasExplicitVersion) {
2186
+ const localEntry = this.resolveFromLocalNodeModules();
2187
+ if (localEntry) {
2188
+ this.logger.info(`Resolved from local node_modules: ${localEntry}`);
2189
+ return localEntry;
2190
+ }
2191
+ }
2192
+ this.logger.info(
2193
+ hasExplicitVersion ? `Using configured version (${this.options.runtime.version}), downloading via npx...` : `Not found locally, downloading via npx (this may take a while)...`
2194
+ );
2169
2195
  const resolverScript = path10.join(
2170
2196
  os.tmpdir(),
2171
2197
  `nrg-resolve-node-red-${process.pid}.cjs`
@@ -2195,7 +2221,7 @@ for (const d of dirs) {
2195
2221
  try {
2196
2222
  const entryPoint = execSync(
2197
2223
  `npx --yes -p ${this.nodeRedCommand} -c "node ${resolverScript}"`,
2198
- { encoding: "utf-8", timeout: 12e4 }
2224
+ { encoding: "utf-8", timeout: 3e5 }
2199
2225
  ).trim();
2200
2226
  if (!entryPoint || !fs10.existsSync(entryPoint)) {
2201
2227
  throw new NodeRedStartError(
@@ -2204,6 +2230,7 @@ for (const d of dirs) {
2204
2230
  )
2205
2231
  );
2206
2232
  }
2233
+ this.logger.info(`Resolved via npx: ${entryPoint}`);
2207
2234
  return entryPoint;
2208
2235
  } finally {
2209
2236
  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,33 @@ 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 hasExplicitVersion = this.options.runtime?.version !== void 0 && this.options.runtime.version !== "latest";
403
+ if (!hasExplicitVersion) {
404
+ const localEntry = this.resolveFromLocalNodeModules();
405
+ if (localEntry) {
406
+ this.logger.info(`Resolved from local node_modules: ${localEntry}`);
407
+ return localEntry;
408
+ }
409
+ }
410
+ this.logger.info(
411
+ hasExplicitVersion ? `Using configured version (${this.options.runtime.version}), downloading via npx...` : `Not found locally, downloading via npx (this may take a while)...`
412
+ );
387
413
  const resolverScript = path2.join(
388
414
  os.tmpdir(),
389
415
  `nrg-resolve-node-red-${process.pid}.cjs`
@@ -413,7 +439,7 @@ for (const d of dirs) {
413
439
  try {
414
440
  const entryPoint = execSync(
415
441
  `npx --yes -p ${this.nodeRedCommand} -c "node ${resolverScript}"`,
416
- { encoding: "utf-8", timeout: 12e4 }
442
+ { encoding: "utf-8", timeout: 3e5 }
417
443
  ).trim();
418
444
  if (!entryPoint || !fs2.existsSync(entryPoint)) {
419
445
  throw new NodeRedStartError(
@@ -422,6 +448,7 @@ for (const d of dirs) {
422
448
  )
423
449
  );
424
450
  }
451
+ this.logger.info(`Resolved via npx: ${entryPoint}`);
425
452
  return entryPoint;
426
453
  } finally {
427
454
  try {
@@ -1311,7 +1338,7 @@ import path11 from "path";
1311
1338
  import fs6 from "fs";
1312
1339
  import path6 from "path";
1313
1340
  import { pathToFileURL as pathToFileURL2 } from "url";
1314
- import { createRequire } from "module";
1341
+ import { createRequire as createRequire2 } from "module";
1315
1342
 
1316
1343
  // src/vite/client/plugins/help-i18n.ts
1317
1344
  var translations = {
@@ -1752,7 +1779,7 @@ function helpGenerator(options) {
1752
1779
  const mod = await import(fileUrl);
1753
1780
  packageFn = mod?.default ?? mod;
1754
1781
  } else if (fs6.existsSync(cjsPath)) {
1755
- const require2 = createRequire(import.meta.url);
1782
+ const require2 = createRequire2(import.meta.url);
1756
1783
  delete require2.cache[cjsPath];
1757
1784
  const rawMod = require2(cjsPath);
1758
1785
  packageFn = rawMod?.default ?? rawMod;
@@ -2096,7 +2123,7 @@ function minifier() {
2096
2123
  }
2097
2124
 
2098
2125
  // src/vite/client/plugins/node-definitions-inliner.ts
2099
- import { createRequire as createRequire2 } from "module";
2126
+ import { createRequire as createRequire3 } from "module";
2100
2127
  import { pathToFileURL as pathToFileURL3 } from "url";
2101
2128
  import path9 from "path";
2102
2129
  import fs9 from "fs";
@@ -2157,7 +2184,7 @@ function nodeDefinitionsInliner(serverOutDir, entryPath, iconsDir, componentsDir
2157
2184
  const mod = await import(fileUrl);
2158
2185
  packageFn = mod?.default ?? mod;
2159
2186
  } else if (fs9.existsSync(cjsEntryPath)) {
2160
- const require2 = createRequire2(import.meta.url);
2187
+ const require2 = createRequire3(import.meta.url);
2161
2188
  delete require2.cache[cjsEntryPath];
2162
2189
  const rawMod = require2(cjsEntryPath);
2163
2190
  packageFn = rawMod?.default ?? rawMod;