@mosierdata/emdash-plugin-analytics 1.0.0 → 1.0.1
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 +8 -3
- package/scripts/postinstall.mjs +43 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mosierdata/emdash-plugin-analytics",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Tag Manager, Call Tracking, and Marketing Analytics for EmDash",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -19,9 +19,11 @@
|
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"dist",
|
|
22
|
-
"patches"
|
|
22
|
+
"patches",
|
|
23
|
+
"scripts"
|
|
23
24
|
],
|
|
24
25
|
"scripts": {
|
|
26
|
+
"postinstall": "node scripts/postinstall.mjs",
|
|
25
27
|
"prepack": "npm run build",
|
|
26
28
|
"build": "tsdown",
|
|
27
29
|
"dev": "tsdown --watch",
|
|
@@ -29,7 +31,10 @@
|
|
|
29
31
|
"test": "vitest run",
|
|
30
32
|
"test:watch": "vitest",
|
|
31
33
|
"bundle": "emdash plugin bundle",
|
|
32
|
-
"
|
|
34
|
+
"deploy": "emdash plugin publish --build"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
33
38
|
},
|
|
34
39
|
"devDependencies": {
|
|
35
40
|
"@testing-library/dom": "^10.4.1",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Conditionally applies the emdash compatibility patch.
|
|
4
|
+
*
|
|
5
|
+
* The patch adds ctx.kv.getRaw() and ctx.kv.commitIfValueUnchanged() to emdash.
|
|
6
|
+
* Once a future emdash release ships these methods natively this script becomes
|
|
7
|
+
* a no-op automatically — no consumer action required.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { readFileSync, readdirSync } from 'fs';
|
|
11
|
+
import { resolve, join } from 'path';
|
|
12
|
+
import { execSync } from 'child_process';
|
|
13
|
+
|
|
14
|
+
const PATCH_METHODS = ['getRaw', 'commitIfValueUnchanged'];
|
|
15
|
+
const tag = '[emdash-plugin-analytics]';
|
|
16
|
+
|
|
17
|
+
function emdashAlreadyHasMethods() {
|
|
18
|
+
try {
|
|
19
|
+
const distDir = resolve('node_modules/emdash/dist');
|
|
20
|
+
const files = readdirSync(distDir).filter(f => f.endsWith('.mjs'));
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
const content = readFileSync(join(distDir, file), 'utf8');
|
|
23
|
+
if (PATCH_METHODS.every(m => content.includes(m))) return true;
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
// emdash not installed or dist missing — proceed to patch attempt
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (emdashAlreadyHasMethods()) {
|
|
32
|
+
console.log(`${tag} emdash already has required KV APIs — skipping patch.`);
|
|
33
|
+
} else {
|
|
34
|
+
console.log(`${tag} Applying emdash compatibility patch…`);
|
|
35
|
+
try {
|
|
36
|
+
execSync('npx --yes patch-package', { stdio: 'inherit' });
|
|
37
|
+
console.log(`${tag} Patch applied successfully.`);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.error(`${tag} Failed to apply patch: ${err.message}`);
|
|
40
|
+
console.error(`${tag} Run "npx patch-package" manually in your project root.`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|