@loupfeed/babel-plugin 0.1.0
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/LICENSE.md +114 -0
- package/dist/index.cjs +77 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 loupfeed
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to use,
|
|
27
|
+
copy, modify, create derivative works, publicly perform, publicly display and
|
|
28
|
+
redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or service
|
|
34
|
+
that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software that
|
|
39
|
+
exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee using
|
|
52
|
+
the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to the
|
|
59
|
+
infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software, you
|
|
68
|
+
must include a copy of or a link to these Terms and Conditions and not remove any
|
|
69
|
+
copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, INCLUDING
|
|
74
|
+
BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, NON-INFRINGEMENT AND TITLE.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN
|
|
79
|
+
IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of the
|
|
84
|
+
Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following will
|
|
93
|
+
apply:
|
|
94
|
+
|
|
95
|
+
We hereby grant you a license to the Software under the Apache License, Version
|
|
96
|
+
2.0, a copy of which is available at https://www.apache.org/licenses/LICENSE-2.0.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## In plain language (non-binding summary)
|
|
101
|
+
|
|
102
|
+
This is a **Fair Source** license. You can:
|
|
103
|
+
|
|
104
|
+
- **Self-host and run loupfeed** for your own purposes — including inside a
|
|
105
|
+
company, on your own servers or cloud account, for your own products.
|
|
106
|
+
- Read, modify, fork, and redistribute the source.
|
|
107
|
+
|
|
108
|
+
The one thing you may **not** do is offer loupfeed (or something substantially
|
|
109
|
+
similar built from it) **as a competing commercial product or hosted service**.
|
|
110
|
+
|
|
111
|
+
Two years after each release is published, that version automatically becomes
|
|
112
|
+
available to you under the **Apache License 2.0** (fully open source).
|
|
113
|
+
|
|
114
|
+
This summary is for convenience only; the Terms and Conditions above govern.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => loupfeedBabel,
|
|
34
|
+
getManifest: () => getManifest,
|
|
35
|
+
resetManifest: () => resetManifest
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
39
|
+
var import_build = require("@loupfeed/build");
|
|
40
|
+
var manifest = {};
|
|
41
|
+
function getManifest() {
|
|
42
|
+
return { ...manifest };
|
|
43
|
+
}
|
|
44
|
+
function resetManifest() {
|
|
45
|
+
for (const k of Object.keys(manifest)) delete manifest[k];
|
|
46
|
+
}
|
|
47
|
+
function loupfeedBabel(babel, options = {}) {
|
|
48
|
+
const t = babel.types;
|
|
49
|
+
const attribute = options.attribute ?? import_build.FB_ATTR;
|
|
50
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
51
|
+
return {
|
|
52
|
+
name: "loupfeed",
|
|
53
|
+
visitor: {
|
|
54
|
+
JSXOpeningElement(p, state) {
|
|
55
|
+
const node = p.node;
|
|
56
|
+
if (!node.loc) return;
|
|
57
|
+
const filename = state.file?.opts?.filename ?? "";
|
|
58
|
+
const rel = filename ? import_node_path.default.relative(projectRoot, filename) : "unknown";
|
|
59
|
+
const already = node.attributes.some(
|
|
60
|
+
(a) => a.type === "JSXAttribute" && a.name?.name === attribute
|
|
61
|
+
);
|
|
62
|
+
if (already) return;
|
|
63
|
+
const id = (0, import_build.fbId)(rel, node.loc.start.line, node.loc.start.column);
|
|
64
|
+
manifest[id] = `${rel}:${node.loc.start.line}`;
|
|
65
|
+
node.attributes.push(
|
|
66
|
+
t.jsxAttribute(t.jsxIdentifier(attribute), t.stringLiteral(id))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
getManifest,
|
|
75
|
+
resetManifest
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @loupfeed/babel-plugin — the generic JSX tagger. This is the fallback that also\n * powers React Native via Metro (RN runs Babel). On web it injects an opaque\n * `data-fb` attribute; for RN set `attribute: 'fbId'` so the id rides as a prop\n * threaded to the native view's testID (doc 03 §React Native).\n *\n * Babel runs per-file, so the manifest is accumulated in-process and flushed by a\n * build/CLI hook (`getManifest()` → upload). Types are kept minimal so we don't\n * hard-depend on @babel/core at build time (it's a peer).\n */\n\nimport path from 'node:path';\nimport { FB_ATTR, fbId } from '@loupfeed/build';\n\ninterface BabelTypes {\n jsxAttribute(name: unknown, value: unknown): unknown;\n jsxIdentifier(name: string): unknown;\n stringLiteral(value: string): unknown;\n}\ninterface Babel {\n types: BabelTypes;\n}\ninterface JSXAttr {\n type: string;\n name?: { name?: string };\n}\ninterface JSXOpeningElementNode {\n loc?: { start: { line: number; column: number } };\n attributes: JSXAttr[];\n}\ninterface VisitorPath {\n node: JSXOpeningElementNode;\n}\ninterface PluginState {\n file?: { opts?: { filename?: string } };\n}\n\nexport interface LoupfeedBabelOptions {\n /** 'data-fb' (web, default) or 'fbId' (React Native). */\n attribute?: string;\n projectRoot?: string;\n}\n\nconst manifest: Record<string, string> = {};\n\n/** The accumulated `{ id -> rel:line }` across all transformed files. */\nexport function getManifest(): Record<string, string> {\n return { ...manifest };\n}\n\nexport function resetManifest(): void {\n for (const k of Object.keys(manifest)) delete manifest[k];\n}\n\nexport default function loupfeedBabel(babel: Babel, options: LoupfeedBabelOptions = {}) {\n const t = babel.types;\n const attribute = options.attribute ?? FB_ATTR;\n const projectRoot = options.projectRoot ?? process.cwd();\n\n return {\n name: 'loupfeed',\n visitor: {\n JSXOpeningElement(p: VisitorPath, state: PluginState) {\n const node = p.node;\n if (!node.loc) return;\n const filename = state.file?.opts?.filename ?? '';\n const rel = filename ? path.relative(projectRoot, filename) : 'unknown';\n const already = node.attributes.some(\n (a) => a.type === 'JSXAttribute' && a.name?.name === attribute,\n );\n if (already) return;\n const id = fbId(rel, node.loc.start.line, node.loc.start.column);\n manifest[id] = `${rel}:${node.loc.start.line}`;\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier(attribute), t.stringLiteral(id)) as JSXAttr,\n );\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,uBAAiB;AACjB,mBAA8B;AA+B9B,IAAM,WAAmC,CAAC;AAGnC,SAAS,cAAsC;AACpD,SAAO,EAAE,GAAG,SAAS;AACvB;AAEO,SAAS,gBAAsB;AACpC,aAAW,KAAK,OAAO,KAAK,QAAQ,EAAG,QAAO,SAAS,CAAC;AAC1D;AAEe,SAAR,cAA+B,OAAc,UAAgC,CAAC,GAAG;AACtF,QAAM,IAAI,MAAM;AAChB,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,cAAc,QAAQ,eAAe,QAAQ,IAAI;AAEvD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,kBAAkB,GAAgB,OAAoB;AACpD,cAAM,OAAO,EAAE;AACf,YAAI,CAAC,KAAK,IAAK;AACf,cAAM,WAAW,MAAM,MAAM,MAAM,YAAY;AAC/C,cAAM,MAAM,WAAW,iBAAAA,QAAK,SAAS,aAAa,QAAQ,IAAI;AAC9D,cAAM,UAAU,KAAK,WAAW;AAAA,UAC9B,CAAC,MAAM,EAAE,SAAS,kBAAkB,EAAE,MAAM,SAAS;AAAA,QACvD;AACA,YAAI,QAAS;AACb,cAAM,SAAK,mBAAK,KAAK,KAAK,IAAI,MAAM,MAAM,KAAK,IAAI,MAAM,MAAM;AAC/D,iBAAS,EAAE,IAAI,GAAG,GAAG,IAAI,KAAK,IAAI,MAAM,IAAI;AAC5C,aAAK,WAAW;AAAA,UACd,EAAE,aAAa,EAAE,cAAc,SAAS,GAAG,EAAE,cAAc,EAAE,CAAC;AAAA,QAChE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["path"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @loupfeed/babel-plugin — the generic JSX tagger. This is the fallback that also
|
|
3
|
+
* powers React Native via Metro (RN runs Babel). On web it injects an opaque
|
|
4
|
+
* `data-fb` attribute; for RN set `attribute: 'fbId'` so the id rides as a prop
|
|
5
|
+
* threaded to the native view's testID (doc 03 §React Native).
|
|
6
|
+
*
|
|
7
|
+
* Babel runs per-file, so the manifest is accumulated in-process and flushed by a
|
|
8
|
+
* build/CLI hook (`getManifest()` → upload). Types are kept minimal so we don't
|
|
9
|
+
* hard-depend on @babel/core at build time (it's a peer).
|
|
10
|
+
*/
|
|
11
|
+
interface BabelTypes {
|
|
12
|
+
jsxAttribute(name: unknown, value: unknown): unknown;
|
|
13
|
+
jsxIdentifier(name: string): unknown;
|
|
14
|
+
stringLiteral(value: string): unknown;
|
|
15
|
+
}
|
|
16
|
+
interface Babel {
|
|
17
|
+
types: BabelTypes;
|
|
18
|
+
}
|
|
19
|
+
interface JSXAttr {
|
|
20
|
+
type: string;
|
|
21
|
+
name?: {
|
|
22
|
+
name?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface JSXOpeningElementNode {
|
|
26
|
+
loc?: {
|
|
27
|
+
start: {
|
|
28
|
+
line: number;
|
|
29
|
+
column: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
attributes: JSXAttr[];
|
|
33
|
+
}
|
|
34
|
+
interface VisitorPath {
|
|
35
|
+
node: JSXOpeningElementNode;
|
|
36
|
+
}
|
|
37
|
+
interface PluginState {
|
|
38
|
+
file?: {
|
|
39
|
+
opts?: {
|
|
40
|
+
filename?: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface LoupfeedBabelOptions {
|
|
45
|
+
/** 'data-fb' (web, default) or 'fbId' (React Native). */
|
|
46
|
+
attribute?: string;
|
|
47
|
+
projectRoot?: string;
|
|
48
|
+
}
|
|
49
|
+
/** The accumulated `{ id -> rel:line }` across all transformed files. */
|
|
50
|
+
declare function getManifest(): Record<string, string>;
|
|
51
|
+
declare function resetManifest(): void;
|
|
52
|
+
declare function loupfeedBabel(babel: Babel, options?: LoupfeedBabelOptions): {
|
|
53
|
+
name: string;
|
|
54
|
+
visitor: {
|
|
55
|
+
JSXOpeningElement(p: VisitorPath, state: PluginState): void;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { type LoupfeedBabelOptions, loupfeedBabel as default, getManifest, resetManifest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @loupfeed/babel-plugin — the generic JSX tagger. This is the fallback that also
|
|
3
|
+
* powers React Native via Metro (RN runs Babel). On web it injects an opaque
|
|
4
|
+
* `data-fb` attribute; for RN set `attribute: 'fbId'` so the id rides as a prop
|
|
5
|
+
* threaded to the native view's testID (doc 03 §React Native).
|
|
6
|
+
*
|
|
7
|
+
* Babel runs per-file, so the manifest is accumulated in-process and flushed by a
|
|
8
|
+
* build/CLI hook (`getManifest()` → upload). Types are kept minimal so we don't
|
|
9
|
+
* hard-depend on @babel/core at build time (it's a peer).
|
|
10
|
+
*/
|
|
11
|
+
interface BabelTypes {
|
|
12
|
+
jsxAttribute(name: unknown, value: unknown): unknown;
|
|
13
|
+
jsxIdentifier(name: string): unknown;
|
|
14
|
+
stringLiteral(value: string): unknown;
|
|
15
|
+
}
|
|
16
|
+
interface Babel {
|
|
17
|
+
types: BabelTypes;
|
|
18
|
+
}
|
|
19
|
+
interface JSXAttr {
|
|
20
|
+
type: string;
|
|
21
|
+
name?: {
|
|
22
|
+
name?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface JSXOpeningElementNode {
|
|
26
|
+
loc?: {
|
|
27
|
+
start: {
|
|
28
|
+
line: number;
|
|
29
|
+
column: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
attributes: JSXAttr[];
|
|
33
|
+
}
|
|
34
|
+
interface VisitorPath {
|
|
35
|
+
node: JSXOpeningElementNode;
|
|
36
|
+
}
|
|
37
|
+
interface PluginState {
|
|
38
|
+
file?: {
|
|
39
|
+
opts?: {
|
|
40
|
+
filename?: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface LoupfeedBabelOptions {
|
|
45
|
+
/** 'data-fb' (web, default) or 'fbId' (React Native). */
|
|
46
|
+
attribute?: string;
|
|
47
|
+
projectRoot?: string;
|
|
48
|
+
}
|
|
49
|
+
/** The accumulated `{ id -> rel:line }` across all transformed files. */
|
|
50
|
+
declare function getManifest(): Record<string, string>;
|
|
51
|
+
declare function resetManifest(): void;
|
|
52
|
+
declare function loupfeedBabel(babel: Babel, options?: LoupfeedBabelOptions): {
|
|
53
|
+
name: string;
|
|
54
|
+
visitor: {
|
|
55
|
+
JSXOpeningElement(p: VisitorPath, state: PluginState): void;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { type LoupfeedBabelOptions, loupfeedBabel as default, getManifest, resetManifest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { FB_ATTR, fbId } from "@loupfeed/build";
|
|
4
|
+
var manifest = {};
|
|
5
|
+
function getManifest() {
|
|
6
|
+
return { ...manifest };
|
|
7
|
+
}
|
|
8
|
+
function resetManifest() {
|
|
9
|
+
for (const k of Object.keys(manifest)) delete manifest[k];
|
|
10
|
+
}
|
|
11
|
+
function loupfeedBabel(babel, options = {}) {
|
|
12
|
+
const t = babel.types;
|
|
13
|
+
const attribute = options.attribute ?? FB_ATTR;
|
|
14
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
15
|
+
return {
|
|
16
|
+
name: "loupfeed",
|
|
17
|
+
visitor: {
|
|
18
|
+
JSXOpeningElement(p, state) {
|
|
19
|
+
const node = p.node;
|
|
20
|
+
if (!node.loc) return;
|
|
21
|
+
const filename = state.file?.opts?.filename ?? "";
|
|
22
|
+
const rel = filename ? path.relative(projectRoot, filename) : "unknown";
|
|
23
|
+
const already = node.attributes.some(
|
|
24
|
+
(a) => a.type === "JSXAttribute" && a.name?.name === attribute
|
|
25
|
+
);
|
|
26
|
+
if (already) return;
|
|
27
|
+
const id = fbId(rel, node.loc.start.line, node.loc.start.column);
|
|
28
|
+
manifest[id] = `${rel}:${node.loc.start.line}`;
|
|
29
|
+
node.attributes.push(
|
|
30
|
+
t.jsxAttribute(t.jsxIdentifier(attribute), t.stringLiteral(id))
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
loupfeedBabel as default,
|
|
38
|
+
getManifest,
|
|
39
|
+
resetManifest
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @loupfeed/babel-plugin — the generic JSX tagger. This is the fallback that also\n * powers React Native via Metro (RN runs Babel). On web it injects an opaque\n * `data-fb` attribute; for RN set `attribute: 'fbId'` so the id rides as a prop\n * threaded to the native view's testID (doc 03 §React Native).\n *\n * Babel runs per-file, so the manifest is accumulated in-process and flushed by a\n * build/CLI hook (`getManifest()` → upload). Types are kept minimal so we don't\n * hard-depend on @babel/core at build time (it's a peer).\n */\n\nimport path from 'node:path';\nimport { FB_ATTR, fbId } from '@loupfeed/build';\n\ninterface BabelTypes {\n jsxAttribute(name: unknown, value: unknown): unknown;\n jsxIdentifier(name: string): unknown;\n stringLiteral(value: string): unknown;\n}\ninterface Babel {\n types: BabelTypes;\n}\ninterface JSXAttr {\n type: string;\n name?: { name?: string };\n}\ninterface JSXOpeningElementNode {\n loc?: { start: { line: number; column: number } };\n attributes: JSXAttr[];\n}\ninterface VisitorPath {\n node: JSXOpeningElementNode;\n}\ninterface PluginState {\n file?: { opts?: { filename?: string } };\n}\n\nexport interface LoupfeedBabelOptions {\n /** 'data-fb' (web, default) or 'fbId' (React Native). */\n attribute?: string;\n projectRoot?: string;\n}\n\nconst manifest: Record<string, string> = {};\n\n/** The accumulated `{ id -> rel:line }` across all transformed files. */\nexport function getManifest(): Record<string, string> {\n return { ...manifest };\n}\n\nexport function resetManifest(): void {\n for (const k of Object.keys(manifest)) delete manifest[k];\n}\n\nexport default function loupfeedBabel(babel: Babel, options: LoupfeedBabelOptions = {}) {\n const t = babel.types;\n const attribute = options.attribute ?? FB_ATTR;\n const projectRoot = options.projectRoot ?? process.cwd();\n\n return {\n name: 'loupfeed',\n visitor: {\n JSXOpeningElement(p: VisitorPath, state: PluginState) {\n const node = p.node;\n if (!node.loc) return;\n const filename = state.file?.opts?.filename ?? '';\n const rel = filename ? path.relative(projectRoot, filename) : 'unknown';\n const already = node.attributes.some(\n (a) => a.type === 'JSXAttribute' && a.name?.name === attribute,\n );\n if (already) return;\n const id = fbId(rel, node.loc.start.line, node.loc.start.column);\n manifest[id] = `${rel}:${node.loc.start.line}`;\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier(attribute), t.stringLiteral(id)) as JSXAttr,\n );\n },\n },\n };\n}\n"],"mappings":";AAWA,OAAO,UAAU;AACjB,SAAS,SAAS,YAAY;AA+B9B,IAAM,WAAmC,CAAC;AAGnC,SAAS,cAAsC;AACpD,SAAO,EAAE,GAAG,SAAS;AACvB;AAEO,SAAS,gBAAsB;AACpC,aAAW,KAAK,OAAO,KAAK,QAAQ,EAAG,QAAO,SAAS,CAAC;AAC1D;AAEe,SAAR,cAA+B,OAAc,UAAgC,CAAC,GAAG;AACtF,QAAM,IAAI,MAAM;AAChB,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,cAAc,QAAQ,eAAe,QAAQ,IAAI;AAEvD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,kBAAkB,GAAgB,OAAoB;AACpD,cAAM,OAAO,EAAE;AACf,YAAI,CAAC,KAAK,IAAK;AACf,cAAM,WAAW,MAAM,MAAM,MAAM,YAAY;AAC/C,cAAM,MAAM,WAAW,KAAK,SAAS,aAAa,QAAQ,IAAI;AAC9D,cAAM,UAAU,KAAK,WAAW;AAAA,UAC9B,CAAC,MAAM,EAAE,SAAS,kBAAkB,EAAE,MAAM,SAAS;AAAA,QACvD;AACA,YAAI,QAAS;AACb,cAAM,KAAK,KAAK,KAAK,KAAK,IAAI,MAAM,MAAM,KAAK,IAAI,MAAM,MAAM;AAC/D,iBAAS,EAAE,IAAI,GAAG,GAAG,IAAI,KAAK,IAAI,MAAM,IAAI;AAC5C,aAAK,WAAW;AAAA,UACd,EAAE,aAAa,EAAE,cAAc,SAAS,GAAG,EAAE,cAAc,EAAE,CAAC;AAAA,QAChE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loupfeed/babel-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "loupfeed Babel plugin — the generic JSX tagger (Next/SWC fallback + RN/Metro). Injects an opaque data-fb attribute (web) or fbId prop (React Native).",
|
|
5
|
+
"license": "FSL-1.1-ALv2",
|
|
6
|
+
"homepage": "https://loupfeed.com",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@loupfeed/build": "0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@babel/core": "^7.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@babel/core": "^7.26.0",
|
|
35
|
+
"@babel/plugin-syntax-jsx": "^7.25.9",
|
|
36
|
+
"@types/babel__core": "^7.20.5",
|
|
37
|
+
"@types/node": "^22.10.2",
|
|
38
|
+
"tsup": "^8.3.5",
|
|
39
|
+
"typescript": "~5.7.2",
|
|
40
|
+
"vitest": "^2.1.8"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"dev": "tsup --watch",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"clean": "rm -rf dist .turbo"
|
|
48
|
+
}
|
|
49
|
+
}
|