@trops/dash-core 0.1.823 → 0.1.824

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.
@@ -4004,7 +4004,15 @@ function findWidgetsDir$2(widgetPath) {
4004
4004
  * package's listed libraries, never the app's (registry rebuilds)
4005
4005
  * @returns {Promise<string|null>} Path to the compiled bundle, or null if nothing to compile
4006
4006
  */
4007
- async function compileWidget$1(widgetPath, { ownLibrariesOnly = false } = {}) {
4007
+ /**
4008
+ * outDir: where the build goes (default <widgetPath>/dist). A folder the
4009
+ * user loaded in place is built into Dash's own folder instead, so nothing
4010
+ * is written into theirs — the build's entry file goes there too.
4011
+ */
4012
+ async function compileWidget$1(
4013
+ widgetPath,
4014
+ { ownLibrariesOnly = false, outDir = null } = {},
4015
+ ) {
4008
4016
  const widgetsDir = findWidgetsDir$2(widgetPath);
4009
4017
 
4010
4018
  if (!widgetsDir) {
@@ -4028,8 +4036,10 @@ async function compileWidget$1(widgetPath, { ownLibrariesOnly = false } = {}) {
4028
4036
  // Build a synthetic entry point that pairs each component with its config.
4029
4037
  // Compute relative path from the entry file (in widgetPath) to widgetsDir,
4030
4038
  // since widgetsDir may be nested (e.g., ./weather-widget/widgets/).
4031
- const relWidgetsDir =
4032
- "./" + path$n.relative(widgetPath, widgetsDir).split(path$n.sep).join("/");
4039
+ // Built elsewhere (outDir), the entry imports the sources by full path.
4040
+ const relWidgetsDir = outDir
4041
+ ? path$n.resolve(widgetsDir).split(path$n.sep).join("/")
4042
+ : "./" + path$n.relative(widgetPath, widgetsDir).split(path$n.sep).join("/");
4033
4043
  const imports = [];
4034
4044
  const exportParts = [];
4035
4045
 
@@ -4041,7 +4051,7 @@ async function compileWidget$1(widgetPath, { ownLibrariesOnly = false } = {}) {
4041
4051
 
4042
4052
  // Import the config (always)
4043
4053
  imports.push(
4044
- `import ${componentName}Config from "${relWidgetsDir}/${dashFile}";`,
4054
+ `import ${componentName}Config from ${JSON.stringify(`${relWidgetsDir}/${dashFile}`)};`,
4045
4055
  );
4046
4056
 
4047
4057
  if (hasComponent) {
@@ -4050,7 +4060,7 @@ async function compileWidget$1(widgetPath, { ownLibrariesOnly = false } = {}) {
4050
4060
  // export default function Foo → _Mod.default
4051
4061
  // export const Foo = ... → _Mod.Foo
4052
4062
  imports.push(
4053
- `import * as ${componentName}_Mod from "${relWidgetsDir}/${componentFile}";`,
4063
+ `import * as ${componentName}_Mod from ${JSON.stringify(`${relWidgetsDir}/${componentFile}`)};`,
4054
4064
  );
4055
4065
  imports.push(
4056
4066
  `const ${componentName}Comp = ${componentName}_Mod.default || ${componentName}_Mod.${componentName} || Object.values(${componentName}_Mod).find(v => typeof v === 'function');`,
@@ -4068,9 +4078,9 @@ async function compileWidget$1(widgetPath, { ownLibrariesOnly = false } = {}) {
4068
4078
 
4069
4079
  const entryContent = [...imports, "", ...exportParts, ""].join("\n");
4070
4080
 
4071
- // Write temporary entry file in the widget root
4072
- const entryPath = path$n.join(widgetPath, "__compile_entry.js");
4073
- const distDir = path$n.join(widgetPath, "dist");
4081
+ // Write temporary entry file in the widget root (or beside the build)
4082
+ const distDir = outDir || path$n.join(widgetPath, "dist");
4083
+ const entryPath = path$n.join(outDir || widgetPath, "__compile_entry.js");
4074
4084
  const outPath = path$n.join(distDir, "index.cjs.js");
4075
4085
  // The package's own libraries (package.json dependencies), downloaded
4076
4086
  // into a temp folder for this build (consolidation Phase 1a-3).
@@ -16070,10 +16080,15 @@ var schedulerController_1 = schedulerController$2;
16070
16080
  * → [problem] or null.
16071
16081
  */
16072
16082
  function botCallProblems(dir) {
16073
- const res = requireScanWidgetBotCalls().scanWidgetBotCalls(dir);
16074
- if (res.ok) return null;
16083
+ const { scanWidgetBotCalls } = requireScanWidgetBotCalls();
16084
+ // Dash's build of a folder loaded in place is the code that runs too.
16085
+ const built = buildDirFor(dir);
16086
+ const files = [dir, ...(built && fs.existsSync(built) ? [built] : [])]
16087
+ .map((d) => scanWidgetBotCalls(d))
16088
+ .flatMap((res) => (res.ok ? [] : res.files));
16089
+ if (!files.length) return null;
16075
16090
  return [
16076
- `It starts your bots directly (${res.files.slice(0, 3).join(", ")}). Widgets may only send events that you wire a bot to, under the bot's "Run on events".`,
16091
+ `It starts your bots directly (${files.slice(0, 3).join(", ")}). Widgets may only send events that you wire a bot to, under the bot's "Run on events".`,
16077
16092
  ];
16078
16093
  }
16079
16094
 
@@ -16098,11 +16113,45 @@ var schedulerController_1 = schedulerController$2;
16098
16113
  };
16099
16114
  }
16100
16115
 
16101
- // Marks a build Dash made (dist/.dash-build): it's rebuilt from the
16102
- // current source each time, unlike a developer's own build.
16116
+ /**
16117
+ * Where Dash builds a package. In its own widgets folder: the package's
16118
+ * dist/. A folder the user loaded in place: Dash's widget-builds/ (one
16119
+ * folder per path) — never a dist/ written into the user's folder.
16120
+ * → the build folder, or null for the package's own dist/.
16121
+ */
16122
+ function buildDirFor(dir) {
16123
+ if (!WIDGETS_CACHE_DIR || !dir || isInsideWidgetsDir(dir)) return null;
16124
+ const key = require$$0$4
16125
+ .createHash("sha256")
16126
+ .update(path.resolve(dir))
16127
+ .digest("hex")
16128
+ .slice(0, 16);
16129
+ return path.join(path.dirname(WIDGETS_CACHE_DIR), "widget-builds", key);
16130
+ }
16131
+
16132
+ // Marks a build Dash made (.dash-build beside it): it's rebuilt from the
16133
+ // current source each time, unlike a developer's own build. An older Dash
16134
+ // built in-place folders into their dist/ — that one counts too.
16103
16135
  const DASH_BUILD_MARK = ".dash-build";
16136
+
16137
+ /** The developer's own build in the package folder (unmarked), or null. */
16138
+ function developerBundle(dir) {
16139
+ const bundle = folderBundle(dir);
16140
+ if (!bundle) return null;
16141
+ return fs.existsSync(path.join(dir, "dist", DASH_BUILD_MARK)) ? null : bundle;
16142
+ }
16143
+
16104
16144
  function builtByDash(dir) {
16105
- return fs.existsSync(path.join(dir, "dist", DASH_BUILD_MARK));
16145
+ // A build the developer made since wins: it's kept, not rebuilt.
16146
+ if (developerBundle(dir)) return false;
16147
+ // Everything in widget-builds/ is Dash's.
16148
+ const built = buildDirFor(dir);
16149
+ return (
16150
+ (built &&
16151
+ (fs.existsSync(path.join(built, "index.cjs.js")) ||
16152
+ fs.existsSync(path.join(built, DASH_BUILD_MARK)))) ||
16153
+ fs.existsSync(path.join(dir, "dist", DASH_BUILD_MARK))
16154
+ );
16106
16155
  }
16107
16156
 
16108
16157
  /**
@@ -16181,15 +16230,17 @@ var schedulerController_1 = schedulerController$2;
16181
16230
  let rebuildError = null;
16182
16231
  const markDashBuild = () => {
16183
16232
  try {
16184
- fs.mkdirSync(path.join(dir, "dist"), { recursive: true });
16185
- fs.writeFileSync(path.join(dir, "dist", DASH_BUILD_MARK), "");
16233
+ const out = buildDirFor(dir) || path.join(dir, "dist");
16234
+ fs.mkdirSync(out, { recursive: true });
16235
+ fs.writeFileSync(path.join(out, DASH_BUILD_MARK), "");
16186
16236
  } catch (_e) {
16187
16237
  // unmarked: it's kept like a developer's build next time
16188
16238
  }
16189
16239
  };
16190
16240
  if (!findBundlePath(dir) || builtByDash(dir)) {
16241
+ let compiled;
16191
16242
  try {
16192
- await compileWidget(dir);
16243
+ compiled = await compileWidget(dir, { outDir: buildDirFor(dir) });
16193
16244
  } catch (e) {
16194
16245
  throw checksFailed(
16195
16246
  widgetName,
@@ -16197,7 +16248,7 @@ var schedulerController_1 = schedulerController$2;
16197
16248
  done,
16198
16249
  );
16199
16250
  }
16200
- markDashBuild();
16251
+ if (compiled) markDashBuild();
16201
16252
  build = "dash";
16202
16253
  } else if (rebuild) {
16203
16254
  // Only with the libraries it lists, never the app's copies: a
@@ -16210,7 +16261,12 @@ var schedulerController_1 = schedulerController$2;
16210
16261
  rebuildError = `It doesn't list the libraries it uses (${imports.join(", ")}).`;
16211
16262
  } else {
16212
16263
  try {
16213
- if (await compileWidget(dir, { ownLibrariesOnly: true })) {
16264
+ if (
16265
+ await compileWidget(dir, {
16266
+ ownLibrariesOnly: true,
16267
+ outDir: buildDirFor(dir),
16268
+ })
16269
+ ) {
16214
16270
  markDashBuild();
16215
16271
  build = "dash";
16216
16272
  }
@@ -17510,7 +17566,9 @@ var schedulerController_1 = schedulerController$2;
17510
17566
  // Auto-compile widget source to CJS bundle if none exists
17511
17567
  if (!findBundlePath(widgetPath)) {
17512
17568
  try {
17513
- await compileWidget(widgetPath);
17569
+ await compileWidget(widgetPath, {
17570
+ outDir: buildDirFor(widgetPath),
17571
+ });
17514
17572
  console.log(`[WidgetRegistry] Auto-compiled ${widgetName}`);
17515
17573
  } catch (compileError) {
17516
17574
  console.warn(
@@ -17646,11 +17704,18 @@ var schedulerController_1 = schedulerController$2;
17646
17704
  }
17647
17705
 
17648
17706
  try {
17707
+ // Dash's build of a folder loaded in place (worked out while the
17708
+ // path is still there to check).
17709
+ const built = widget.path ? buildDirFor(widget.path) : null;
17649
17710
  // A folder of widgets loads in place, so its path is the user's own
17650
17711
  // folder: forget the widget, never delete files outside Dash's own.
17651
17712
  if (fs.existsSync(widget.path) && isInsideWidgetsDir(widget.path)) {
17652
17713
  fs.rmSync(widget.path, { recursive: true });
17653
17714
  }
17715
+ // Its build goes; the folder stays.
17716
+ if (built && fs.existsSync(built)) {
17717
+ fs.rmSync(built, { recursive: true, force: true });
17718
+ }
17654
17719
 
17655
17720
  // Clean up empty scope directory (e.g. widgets/@trops/ after removing @trops/slack)
17656
17721
  const { scope } = parsePackageId(widgetName);
@@ -17874,6 +17939,19 @@ var schedulerController_1 = schedulerController$2;
17874
17939
  * @returns {string|null} Absolute path to the bundle, or null if not found
17875
17940
  */
17876
17941
  function findBundlePath(widgetPath) {
17942
+ // The developer's own build first; then Dash's build of a folder loaded
17943
+ // in place; then a build an older Dash left in the folder's dist/.
17944
+ const own = developerBundle(widgetPath);
17945
+ if (own) return own;
17946
+ const built = buildDirFor(widgetPath);
17947
+ if (built && fs.existsSync(path.join(built, "index.cjs.js"))) {
17948
+ return path.join(built, "index.cjs.js");
17949
+ }
17950
+ return folderBundle(widgetPath);
17951
+ }
17952
+
17953
+ /** A bundle in the package folder itself (dist/ or its root), or null. */
17954
+ function folderBundle(widgetPath) {
17877
17955
  const candidates = [
17878
17956
  path.join(widgetPath, "dist", "index.cjs.js"),
17879
17957
  path.join(widgetPath, "index.cjs.js"),
@@ -18134,7 +18212,9 @@ var schedulerController_1 = schedulerController$2;
18134
18212
  let compileError = null;
18135
18213
  if (!bundlePath) {
18136
18214
  try {
18137
- const compiled = await compileWidget(widget.path);
18215
+ const compiled = await compileWidget(widget.path, {
18216
+ outDir: buildDirFor(widget.path),
18217
+ });
18138
18218
  if (compiled) {
18139
18219
  bundlePath = compiled;
18140
18220
  }
@@ -18186,7 +18266,9 @@ var schedulerController_1 = schedulerController$2;
18186
18266
  // Auto-compile if no bundle exists
18187
18267
  if (!bundlePath) {
18188
18268
  try {
18189
- const compiled = await compileWidget(widgetPath);
18269
+ const compiled = await compileWidget(widgetPath, {
18270
+ outDir: buildDirFor(widgetPath),
18271
+ });
18190
18272
  if (compiled) {
18191
18273
  bundlePath = compiled;
18192
18274
  }
@@ -18251,6 +18333,7 @@ var schedulerController_1 = schedulerController$2;
18251
18333
  module.exports.validateZipEntries = validateZipEntries;
18252
18334
  module.exports.setInstallGate = setInstallGate;
18253
18335
  module.exports.checkPackage = checkPackage;
18336
+ module.exports.findBundlePath = findBundlePath;
18254
18337
  module.exports.isInsideWidgetsDir = isInsideWidgetsDir;
18255
18338
  module.exports.scopedLocalId = scopedLocalId;
18256
18339
  module.exports.localPackageName = localPackageName;