@fabricorg/experiments 0.6.2 → 0.6.3
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/README.md +11 -0
- package/dist/bin/fx.cjs +86 -12
- package/dist/bin/fx.cjs.map +1 -1
- package/dist/bin/fx.js +86 -12
- package/dist/bin/fx.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,8 +41,19 @@ fx dev Start local dev server.
|
|
|
41
41
|
fx publish Sign current manifest; optionally push to manifest-worker.
|
|
42
42
|
fx report <experimentId> Print results for an experiment.
|
|
43
43
|
fx kill <experimentId> Kill a running experiment. Requires --reason.
|
|
44
|
+
fx import-mojito <dir> Convert Mojito waves and emit a compatibility report.
|
|
44
45
|
```
|
|
45
46
|
|
|
47
|
+
For a migration gate that fails until every trigger and asset is portable:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
fx import-mojito ./waves --out ./experiments --strict
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Common pathname, URL-contains, DOM-ready, and wait-for-element triggers are
|
|
54
|
+
converted automatically. `import-report.json` inventories every conversion and
|
|
55
|
+
manual-review warning.
|
|
56
|
+
|
|
46
57
|
## Docs
|
|
47
58
|
|
|
48
59
|
Full documentation: [https://experiments.fabric.pro](https://experiments.fabric.pro)
|
package/dist/bin/fx.cjs
CHANGED
|
@@ -7089,7 +7089,8 @@ async function cmdImportMojito(inputDir, options = {}) {
|
|
|
7089
7089
|
results.push({
|
|
7090
7090
|
source: waveDir,
|
|
7091
7091
|
target: "",
|
|
7092
|
-
warnings: [`failed to convert: ${e.message}`]
|
|
7092
|
+
warnings: [`failed to convert: ${e.message}`],
|
|
7093
|
+
trigger: "manual"
|
|
7093
7094
|
});
|
|
7094
7095
|
}
|
|
7095
7096
|
}
|
|
@@ -7106,8 +7107,36 @@ async function cmdImportMojito(inputDir, options = {}) {
|
|
|
7106
7107
|
for (const w of r.warnings) process.stdout.write(` ! ${w}
|
|
7107
7108
|
`);
|
|
7108
7109
|
}
|
|
7110
|
+
const reportFile = path.resolve(options.reportFile ?? path.join(outDir, "import-report.json"));
|
|
7111
|
+
await promises.writeFile(
|
|
7112
|
+
reportFile,
|
|
7113
|
+
`${JSON.stringify(
|
|
7114
|
+
{
|
|
7115
|
+
schemaVersion: 1,
|
|
7116
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7117
|
+
input: root,
|
|
7118
|
+
output: outDir,
|
|
7119
|
+
summary: {
|
|
7120
|
+
waves: results.length,
|
|
7121
|
+
converted: results.filter((result) => result.target).length,
|
|
7122
|
+
failed: results.filter((result) => !result.target).length,
|
|
7123
|
+
manualReview: results.filter((result) => result.warnings.length > 0).length
|
|
7124
|
+
},
|
|
7125
|
+
waves: results
|
|
7126
|
+
},
|
|
7127
|
+
null,
|
|
7128
|
+
2
|
|
7129
|
+
)}
|
|
7130
|
+
`,
|
|
7131
|
+
"utf8"
|
|
7132
|
+
);
|
|
7133
|
+
process.stdout.write(`
|
|
7134
|
+
Compatibility report: ${reportFile}
|
|
7135
|
+
`);
|
|
7109
7136
|
const failed = results.filter((r) => !r.target).length;
|
|
7110
|
-
|
|
7137
|
+
if (failed > 0) return 2;
|
|
7138
|
+
if (options.strict && results.some((result) => result.warnings.length > 0)) return 3;
|
|
7139
|
+
return 0;
|
|
7111
7140
|
}
|
|
7112
7141
|
async function findWaves(root) {
|
|
7113
7142
|
const out = [];
|
|
@@ -7162,12 +7191,23 @@ async function convertWave(waveDir, outDir) {
|
|
|
7162
7191
|
variants.push(variant);
|
|
7163
7192
|
}
|
|
7164
7193
|
let triggerNote = null;
|
|
7194
|
+
let convertedTrigger;
|
|
7195
|
+
let triggerMigration = "none";
|
|
7165
7196
|
if (cfg.trigger) {
|
|
7166
7197
|
triggerNote = await promises.readFile(path.join(waveDir, cfg.trigger), "utf8").catch(() => "");
|
|
7167
7198
|
if (triggerNote) {
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7199
|
+
const translated = translateCommonTrigger(triggerNote);
|
|
7200
|
+
convertedTrigger = translated.trigger;
|
|
7201
|
+
triggerMigration = translated.kind;
|
|
7202
|
+
if (!translated.trigger) {
|
|
7203
|
+
warnings.push(
|
|
7204
|
+
"trigger.js was not auto-converted \u2014 review and translate to a Trigger DSL or host-supplied trigger override."
|
|
7205
|
+
);
|
|
7206
|
+
triggerMigration = "manual";
|
|
7207
|
+
}
|
|
7208
|
+
} else {
|
|
7209
|
+
warnings.push(`trigger file not found: ${cfg.trigger}`);
|
|
7210
|
+
triggerMigration = "manual";
|
|
7171
7211
|
}
|
|
7172
7212
|
}
|
|
7173
7213
|
let sharedJs;
|
|
@@ -7194,20 +7234,47 @@ async function convertWave(waveDir, outDir) {
|
|
|
7194
7234
|
if (cfg.manualExposure) spec.manualExposure = true;
|
|
7195
7235
|
if (sharedJs) spec.sharedJs = sharedJs;
|
|
7196
7236
|
if (sharedCss) spec.sharedCss = sharedCss;
|
|
7197
|
-
if (triggerNote) spec.trigger = { kind: "auto" };
|
|
7237
|
+
if (triggerNote) spec.trigger = convertedTrigger ?? { kind: "auto" };
|
|
7198
7238
|
const header = [
|
|
7199
7239
|
"# Imported from Mojito wave",
|
|
7200
7240
|
`# Source: ${waveDir}`,
|
|
7201
7241
|
cfg.state ? `# Original state: ${cfg.state}` : null,
|
|
7202
7242
|
triggerNote ? "#" : null,
|
|
7203
|
-
triggerNote ? "# Original trigger.js (NOT auto-applied):" : null,
|
|
7243
|
+
triggerNote ? convertedTrigger ? `# Original trigger.js (auto-converted to ${String(convertedTrigger.kind)}):` : "# Original trigger.js (NOT auto-applied):" : null,
|
|
7204
7244
|
triggerNote ? triggerNote.split("\n").map((l) => `# ${l}`).join("\n") : null
|
|
7205
7245
|
].filter((l) => l !== null).join("\n");
|
|
7206
7246
|
const yamlBody = yaml.stringify(spec);
|
|
7207
7247
|
const target = path.join(outDir, `${spec.id}.yaml`);
|
|
7208
7248
|
await promises.writeFile(target, `${header}
|
|
7209
7249
|
${yamlBody}`, "utf8");
|
|
7210
|
-
return { source: waveDir, target, warnings };
|
|
7250
|
+
return { source: waveDir, target, warnings, trigger: triggerMigration };
|
|
7251
|
+
}
|
|
7252
|
+
function translateCommonTrigger(source) {
|
|
7253
|
+
const selector = source.match(/(?:waitForElement|waitForSelector)\s*\(\s*(['"])([^'"]+)\1/);
|
|
7254
|
+
if (selector?.[2]) {
|
|
7255
|
+
return {
|
|
7256
|
+
trigger: { kind: "waitForSelector", selector: selector[2] },
|
|
7257
|
+
kind: "waitForSelector"
|
|
7258
|
+
};
|
|
7259
|
+
}
|
|
7260
|
+
const pathname = source.match(/(?:document\.)?location\.pathname\s*={2,3}\s*(['"])([^'"]+)\1/);
|
|
7261
|
+
if (pathname?.[2]) {
|
|
7262
|
+
const escaped = pathname[2].replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7263
|
+
return {
|
|
7264
|
+
trigger: { kind: "urlMatch", pattern: `https?://[^/]+${escaped}(?:[?#]|$)`, regex: true },
|
|
7265
|
+
kind: "urlMatch"
|
|
7266
|
+
};
|
|
7267
|
+
}
|
|
7268
|
+
const hrefIncludes = source.match(
|
|
7269
|
+
/(?:document\.)?location\.href\.(?:includes|indexOf)\s*\(\s*(['"])([^'"]+)\1/
|
|
7270
|
+
);
|
|
7271
|
+
if (hrefIncludes?.[2]) {
|
|
7272
|
+
return { trigger: { kind: "urlMatch", pattern: hrefIncludes[2] }, kind: "urlMatch" };
|
|
7273
|
+
}
|
|
7274
|
+
if (/\bdomReady\s*\(/.test(source) && !/\bif\s*\(/.test(source)) {
|
|
7275
|
+
return { trigger: { kind: "auto" }, kind: "auto" };
|
|
7276
|
+
}
|
|
7277
|
+
return { kind: "manual" };
|
|
7211
7278
|
}
|
|
7212
7279
|
function normalizeKey(k) {
|
|
7213
7280
|
return k.toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
@@ -8139,7 +8206,7 @@ var FILES = {
|
|
|
8139
8206
|
devDependencies: {
|
|
8140
8207
|
"@cucumber/cucumber": "^13.0.0",
|
|
8141
8208
|
"@duckdb/node-api": "^1.5.0",
|
|
8142
|
-
"@fabricorg/databricks-bdd": "^0.3.
|
|
8209
|
+
"@fabricorg/databricks-bdd": "^0.3.2",
|
|
8143
8210
|
tsx: "^4.19.2",
|
|
8144
8211
|
typescript: "^5.8.3"
|
|
8145
8212
|
}
|
|
@@ -8754,10 +8821,13 @@ GLOBAL FLAGS
|
|
|
8754
8821
|
--external-id <id> test publish: idempotent CI run identifier
|
|
8755
8822
|
--run-url <url> test publish: CI artifact/run link
|
|
8756
8823
|
--key-id <id> publish: keyId to sign with (default: dev-default)
|
|
8824
|
+
--out <dir> import-mojito: output directory
|
|
8825
|
+
--report <file> import-mojito: compatibility report path
|
|
8826
|
+
--strict import-mojito: fail while manual-review warnings remain
|
|
8757
8827
|
-h, --help print this help
|
|
8758
8828
|
-v, --version print version
|
|
8759
8829
|
`;
|
|
8760
|
-
var VERSION2 = "0.6.
|
|
8830
|
+
var VERSION2 = "0.6.3";
|
|
8761
8831
|
function parse2(argv) {
|
|
8762
8832
|
const positional = [];
|
|
8763
8833
|
const flags = {};
|
|
@@ -8871,11 +8941,15 @@ async function main() {
|
|
|
8871
8941
|
});
|
|
8872
8942
|
case "import-mojito":
|
|
8873
8943
|
if (!args.positional[0]) {
|
|
8874
|
-
process.stderr.write(
|
|
8944
|
+
process.stderr.write(
|
|
8945
|
+
"Usage: fx import-mojito <dir> [--out <out-dir>] [--report <file>] [--strict]\n"
|
|
8946
|
+
);
|
|
8875
8947
|
return 1;
|
|
8876
8948
|
}
|
|
8877
8949
|
return cmdImportMojito(args.positional[0], {
|
|
8878
|
-
outputDir: args.flags.out
|
|
8950
|
+
outputDir: args.flags.out,
|
|
8951
|
+
reportFile: args.flags.report,
|
|
8952
|
+
strict: args.flags.strict === true});
|
|
8879
8953
|
case "preview":
|
|
8880
8954
|
if (!args.positional[0]) {
|
|
8881
8955
|
process.stderr.write(
|