@fabricorg/experiments 0.6.2 → 0.6.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/dist/bin/fx.js CHANGED
@@ -7086,7 +7086,8 @@ async function cmdImportMojito(inputDir, options = {}) {
7086
7086
  results.push({
7087
7087
  source: waveDir,
7088
7088
  target: "",
7089
- warnings: [`failed to convert: ${e.message}`]
7089
+ warnings: [`failed to convert: ${e.message}`],
7090
+ trigger: "manual"
7090
7091
  });
7091
7092
  }
7092
7093
  }
@@ -7103,8 +7104,36 @@ async function cmdImportMojito(inputDir, options = {}) {
7103
7104
  for (const w of r.warnings) process.stdout.write(` ! ${w}
7104
7105
  `);
7105
7106
  }
7107
+ const reportFile = resolve(options.reportFile ?? join(outDir, "import-report.json"));
7108
+ await writeFile(
7109
+ reportFile,
7110
+ `${JSON.stringify(
7111
+ {
7112
+ schemaVersion: 1,
7113
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
7114
+ input: root,
7115
+ output: outDir,
7116
+ summary: {
7117
+ waves: results.length,
7118
+ converted: results.filter((result) => result.target).length,
7119
+ failed: results.filter((result) => !result.target).length,
7120
+ manualReview: results.filter((result) => result.warnings.length > 0).length
7121
+ },
7122
+ waves: results
7123
+ },
7124
+ null,
7125
+ 2
7126
+ )}
7127
+ `,
7128
+ "utf8"
7129
+ );
7130
+ process.stdout.write(`
7131
+ Compatibility report: ${reportFile}
7132
+ `);
7106
7133
  const failed = results.filter((r) => !r.target).length;
7107
- return failed === 0 ? 0 : 2;
7134
+ if (failed > 0) return 2;
7135
+ if (options.strict && results.some((result) => result.warnings.length > 0)) return 3;
7136
+ return 0;
7108
7137
  }
7109
7138
  async function findWaves(root) {
7110
7139
  const out = [];
@@ -7159,12 +7188,23 @@ async function convertWave(waveDir, outDir) {
7159
7188
  variants.push(variant);
7160
7189
  }
7161
7190
  let triggerNote = null;
7191
+ let convertedTrigger;
7192
+ let triggerMigration = "none";
7162
7193
  if (cfg.trigger) {
7163
7194
  triggerNote = await readFile(join(waveDir, cfg.trigger), "utf8").catch(() => "");
7164
7195
  if (triggerNote) {
7165
- warnings.push(
7166
- "trigger.js was not auto-converted \u2014 review and translate to a Trigger DSL or host-supplied trigger override."
7167
- );
7196
+ const translated = translateCommonTrigger(triggerNote);
7197
+ convertedTrigger = translated.trigger;
7198
+ triggerMigration = translated.kind;
7199
+ if (!translated.trigger) {
7200
+ warnings.push(
7201
+ "trigger.js was not auto-converted \u2014 review and translate to a Trigger DSL or host-supplied trigger override."
7202
+ );
7203
+ triggerMigration = "manual";
7204
+ }
7205
+ } else {
7206
+ warnings.push(`trigger file not found: ${cfg.trigger}`);
7207
+ triggerMigration = "manual";
7168
7208
  }
7169
7209
  }
7170
7210
  let sharedJs;
@@ -7191,20 +7231,47 @@ async function convertWave(waveDir, outDir) {
7191
7231
  if (cfg.manualExposure) spec.manualExposure = true;
7192
7232
  if (sharedJs) spec.sharedJs = sharedJs;
7193
7233
  if (sharedCss) spec.sharedCss = sharedCss;
7194
- if (triggerNote) spec.trigger = { kind: "auto" };
7234
+ if (triggerNote) spec.trigger = convertedTrigger ?? { kind: "auto" };
7195
7235
  const header = [
7196
7236
  "# Imported from Mojito wave",
7197
7237
  `# Source: ${waveDir}`,
7198
7238
  cfg.state ? `# Original state: ${cfg.state}` : null,
7199
7239
  triggerNote ? "#" : null,
7200
- triggerNote ? "# Original trigger.js (NOT auto-applied):" : null,
7240
+ triggerNote ? convertedTrigger ? `# Original trigger.js (auto-converted to ${String(convertedTrigger.kind)}):` : "# Original trigger.js (NOT auto-applied):" : null,
7201
7241
  triggerNote ? triggerNote.split("\n").map((l) => `# ${l}`).join("\n") : null
7202
7242
  ].filter((l) => l !== null).join("\n");
7203
7243
  const yamlBody = stringify(spec);
7204
7244
  const target = join(outDir, `${spec.id}.yaml`);
7205
7245
  await writeFile(target, `${header}
7206
7246
  ${yamlBody}`, "utf8");
7207
- return { source: waveDir, target, warnings };
7247
+ return { source: waveDir, target, warnings, trigger: triggerMigration };
7248
+ }
7249
+ function translateCommonTrigger(source) {
7250
+ const selector = source.match(/(?:waitForElement|waitForSelector)\s*\(\s*(['"])([^'"]+)\1/);
7251
+ if (selector?.[2]) {
7252
+ return {
7253
+ trigger: { kind: "waitForSelector", selector: selector[2] },
7254
+ kind: "waitForSelector"
7255
+ };
7256
+ }
7257
+ const pathname = source.match(/(?:document\.)?location\.pathname\s*={2,3}\s*(['"])([^'"]+)\1/);
7258
+ if (pathname?.[2]) {
7259
+ const escaped = pathname[2].replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7260
+ return {
7261
+ trigger: { kind: "urlMatch", pattern: `https?://[^/]+${escaped}(?:[?#]|$)`, regex: true },
7262
+ kind: "urlMatch"
7263
+ };
7264
+ }
7265
+ const hrefIncludes = source.match(
7266
+ /(?:document\.)?location\.href\.(?:includes|indexOf)\s*\(\s*(['"])([^'"]+)\1/
7267
+ );
7268
+ if (hrefIncludes?.[2]) {
7269
+ return { trigger: { kind: "urlMatch", pattern: hrefIncludes[2] }, kind: "urlMatch" };
7270
+ }
7271
+ if (/\bdomReady\s*\(/.test(source) && !/\bif\s*\(/.test(source)) {
7272
+ return { trigger: { kind: "auto" }, kind: "auto" };
7273
+ }
7274
+ return { kind: "manual" };
7208
7275
  }
7209
7276
  function normalizeKey(k) {
7210
7277
  return k.toLowerCase().replace(/[^a-z0-9_-]/g, "-");
@@ -8136,7 +8203,7 @@ var FILES = {
8136
8203
  devDependencies: {
8137
8204
  "@cucumber/cucumber": "^13.0.0",
8138
8205
  "@duckdb/node-api": "^1.5.0",
8139
- "@fabricorg/databricks-bdd": "^0.3.1",
8206
+ "@fabricorg/databricks-bdd": "^0.4.0",
8140
8207
  tsx: "^4.19.2",
8141
8208
  typescript: "^5.8.3"
8142
8209
  }
@@ -8751,10 +8818,13 @@ GLOBAL FLAGS
8751
8818
  --external-id <id> test publish: idempotent CI run identifier
8752
8819
  --run-url <url> test publish: CI artifact/run link
8753
8820
  --key-id <id> publish: keyId to sign with (default: dev-default)
8821
+ --out <dir> import-mojito: output directory
8822
+ --report <file> import-mojito: compatibility report path
8823
+ --strict import-mojito: fail while manual-review warnings remain
8754
8824
  -h, --help print this help
8755
8825
  -v, --version print version
8756
8826
  `;
8757
- var VERSION2 = "0.6.2";
8827
+ var VERSION2 = "0.6.4";
8758
8828
  function parse2(argv) {
8759
8829
  const positional = [];
8760
8830
  const flags = {};
@@ -8868,11 +8938,15 @@ async function main() {
8868
8938
  });
8869
8939
  case "import-mojito":
8870
8940
  if (!args.positional[0]) {
8871
- process.stderr.write("Usage: fx import-mojito <dir> [--out <out-dir>]\n");
8941
+ process.stderr.write(
8942
+ "Usage: fx import-mojito <dir> [--out <out-dir>] [--report <file>] [--strict]\n"
8943
+ );
8872
8944
  return 1;
8873
8945
  }
8874
8946
  return cmdImportMojito(args.positional[0], {
8875
- outputDir: args.flags.out});
8947
+ outputDir: args.flags.out,
8948
+ reportFile: args.flags.report,
8949
+ strict: args.flags.strict === true});
8876
8950
  case "preview":
8877
8951
  if (!args.positional[0]) {
8878
8952
  process.stderr.write(