@loupfeed/vite-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 +95 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -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,95 @@
|
|
|
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
|
+
feedbackVite: () => feedbackVite,
|
|
34
|
+
loupfeedVite: () => loupfeedVite
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
38
|
+
var import_build = require("@loupfeed/build");
|
|
39
|
+
function loupfeedVite(options = {}) {
|
|
40
|
+
let tagger;
|
|
41
|
+
let root = options.root ?? process.cwd();
|
|
42
|
+
let srcRoot = "";
|
|
43
|
+
let release = options.release ?? "";
|
|
44
|
+
let isBuild = false;
|
|
45
|
+
return {
|
|
46
|
+
name: "loupfeed",
|
|
47
|
+
enforce: "pre",
|
|
48
|
+
config(_config, env) {
|
|
49
|
+
isBuild = env.command === "build";
|
|
50
|
+
release = options.release ?? (0, import_build.buildIdentity)({ cwd: options.root ?? process.cwd() }).release;
|
|
51
|
+
if (options.injectRelease !== false) {
|
|
52
|
+
return { define: { "import.meta.env.VITE_LOUPFEED_RELEASE": JSON.stringify(release) } };
|
|
53
|
+
}
|
|
54
|
+
return void 0;
|
|
55
|
+
},
|
|
56
|
+
configResolved(resolved) {
|
|
57
|
+
root = options.root ?? resolved.root;
|
|
58
|
+
const srcDir = options.srcDir ?? "src";
|
|
59
|
+
srcRoot = srcDir ? import_node_path.default.join(root, srcDir) : root;
|
|
60
|
+
tagger = (0, import_build.createTagger)({ projectRoot: root, include: options.include });
|
|
61
|
+
},
|
|
62
|
+
transform(code, id) {
|
|
63
|
+
if (!tagger) return null;
|
|
64
|
+
const cleanId = id.split("?")[0] ?? id;
|
|
65
|
+
if (!cleanId.startsWith(srcRoot)) return null;
|
|
66
|
+
const result = tagger.transform(code, cleanId);
|
|
67
|
+
return result ? { code: result.code, map: result.map } : null;
|
|
68
|
+
},
|
|
69
|
+
async buildEnd() {
|
|
70
|
+
if (!isBuild || !tagger) return;
|
|
71
|
+
const ids = tagger.manifest();
|
|
72
|
+
const count = Object.keys(ids).length;
|
|
73
|
+
if (count === 0) return;
|
|
74
|
+
if (options.writeManifest !== false) {
|
|
75
|
+
const file = (0, import_build.writeManifestFile)({ ids, release, outDir: options.manifestDir ?? root });
|
|
76
|
+
this.warn(`[loupfeed] wrote ${count} ids \u2192 ${import_node_path.default.relative(root, file)} (server-side; do not serve)`);
|
|
77
|
+
}
|
|
78
|
+
if (options.dsn && options.authToken) {
|
|
79
|
+
try {
|
|
80
|
+
await (0, import_build.uploadManifest)({ dsn: options.dsn, release, ids, authToken: options.authToken });
|
|
81
|
+
this.warn(`[loupfeed] uploaded manifest for release ${release} (${count} ids)`);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
this.error(`[loupfeed] manifest upload failed: ${err.message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
var feedbackVite = loupfeedVite;
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
feedbackVite,
|
|
93
|
+
loupfeedVite
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @loupfeed/vite-plugin — the existing Trivision `dataFbLocPlugin`, generalized.\n *\n * Runs as `enforce: 'pre'` so it tags JSX before @vitejs/plugin-react lowers\n * TSX → JS; the injected `data-fb` string attributes survive that lowering.\n * On a production build it writes (and optionally uploads) the server-side\n * manifest. No source paths ever reach the client bundle.\n */\n\nimport path from 'node:path';\nimport type { Plugin } from 'vite';\nimport {\n buildIdentity,\n createTagger,\n uploadManifest,\n writeManifestFile,\n type Tagger,\n} from '@loupfeed/build';\n\nexport interface LoupfeedViteOptions {\n /** DSN — when given together with `authToken`, the manifest is uploaded at build end. */\n dsn?: string;\n /** Privileged build/CI token for manifest upload (NOT the public DSN key). */\n authToken?: string;\n /** `version@commit` join key. Defaults to `buildIdentity()` (git + package.json). */\n release?: string;\n /** Files to tag. Default `/\\.(t|j)sx$/`. */\n include?: RegExp;\n /** Project root. Defaults to Vite's resolved root. */\n root?: string;\n /** Only tag files under `<root>/srcDir`. Default `'src'`. Set `''` to tag the whole root. */\n srcDir?: string;\n /** Write `fb-manifest.<release>.json` to disk at build end. Default true. */\n writeManifest?: boolean;\n /** Directory for the on-disk manifest (kept out of dist/). Default project root. */\n manifestDir?: string;\n /** Inject the release as `import.meta.env.VITE_LOUPFEED_RELEASE`. Default true. */\n injectRelease?: boolean;\n}\n\nexport function loupfeedVite(options: LoupfeedViteOptions = {}): Plugin {\n let tagger: Tagger | undefined;\n let root = options.root ?? process.cwd();\n let srcRoot = '';\n let release = options.release ?? '';\n let isBuild = false;\n\n return {\n name: 'loupfeed',\n enforce: 'pre',\n\n config(_config, env) {\n isBuild = env.command === 'build';\n release = options.release ?? buildIdentity({ cwd: options.root ?? process.cwd() }).release;\n if (options.injectRelease !== false) {\n return { define: { 'import.meta.env.VITE_LOUPFEED_RELEASE': JSON.stringify(release) } };\n }\n return undefined;\n },\n\n configResolved(resolved) {\n root = options.root ?? resolved.root;\n const srcDir = options.srcDir ?? 'src';\n srcRoot = srcDir ? path.join(root, srcDir) : root;\n tagger = createTagger({ projectRoot: root, include: options.include });\n },\n\n transform(code, id) {\n if (!tagger) return null;\n const cleanId = id.split('?')[0] ?? id;\n if (!cleanId.startsWith(srcRoot)) return null;\n const result = tagger.transform(code, cleanId);\n return result ? { code: result.code, map: result.map } : null;\n },\n\n async buildEnd() {\n // Only emit a manifest for real builds (not the dev server).\n if (!isBuild || !tagger) return;\n const ids = tagger.manifest();\n const count = Object.keys(ids).length;\n if (count === 0) return;\n\n if (options.writeManifest !== false) {\n const file = writeManifestFile({ ids, release, outDir: options.manifestDir ?? root });\n this.warn(`[loupfeed] wrote ${count} ids → ${path.relative(root, file)} (server-side; do not serve)`);\n }\n\n if (options.dsn && options.authToken) {\n try {\n await uploadManifest({ dsn: options.dsn, release, ids, authToken: options.authToken });\n this.warn(`[loupfeed] uploaded manifest for release ${release} (${count} ids)`);\n } catch (err) {\n this.error(`[loupfeed] manifest upload failed: ${(err as Error).message}`);\n }\n }\n },\n };\n}\n\n/** Alias matching the name re-exported by `@loupfeed/react` (doc 02). */\nexport const feedbackVite = loupfeedVite;\nexport type { LoupfeedViteOptions as FeedbackViteOptions };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,uBAAiB;AAEjB,mBAMO;AAuBA,SAAS,aAAa,UAA+B,CAAC,GAAW;AACtE,MAAI;AACJ,MAAI,OAAO,QAAQ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K,eAAU,iBAAAA,QAAK,SAAS,MAAM,IAAI,CAAC,8BAA8B;AAAA,MACtG;AAEA,UAAI,QAAQ,OAAO,QAAQ,WAAW;AACpC,YAAI;AACF,oBAAM,6BAAe,EAAE,KAAK,QAAQ,KAAK,SAAS,KAAK,WAAW,QAAQ,UAAU,CAAC;AACrF,eAAK,KAAK,4CAA4C,OAAO,KAAK,KAAK,OAAO;AAAA,QAChF,SAAS,KAAK;AACZ,eAAK,MAAM,sCAAuC,IAAc,OAAO,EAAE;AAAA,QAC3E;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAGO,IAAM,eAAe;","names":["path"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @loupfeed/vite-plugin — the existing Trivision `dataFbLocPlugin`, generalized.
|
|
5
|
+
*
|
|
6
|
+
* Runs as `enforce: 'pre'` so it tags JSX before @vitejs/plugin-react lowers
|
|
7
|
+
* TSX → JS; the injected `data-fb` string attributes survive that lowering.
|
|
8
|
+
* On a production build it writes (and optionally uploads) the server-side
|
|
9
|
+
* manifest. No source paths ever reach the client bundle.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface LoupfeedViteOptions {
|
|
13
|
+
/** DSN — when given together with `authToken`, the manifest is uploaded at build end. */
|
|
14
|
+
dsn?: string;
|
|
15
|
+
/** Privileged build/CI token for manifest upload (NOT the public DSN key). */
|
|
16
|
+
authToken?: string;
|
|
17
|
+
/** `version@commit` join key. Defaults to `buildIdentity()` (git + package.json). */
|
|
18
|
+
release?: string;
|
|
19
|
+
/** Files to tag. Default `/\.(t|j)sx$/`. */
|
|
20
|
+
include?: RegExp;
|
|
21
|
+
/** Project root. Defaults to Vite's resolved root. */
|
|
22
|
+
root?: string;
|
|
23
|
+
/** Only tag files under `<root>/srcDir`. Default `'src'`. Set `''` to tag the whole root. */
|
|
24
|
+
srcDir?: string;
|
|
25
|
+
/** Write `fb-manifest.<release>.json` to disk at build end. Default true. */
|
|
26
|
+
writeManifest?: boolean;
|
|
27
|
+
/** Directory for the on-disk manifest (kept out of dist/). Default project root. */
|
|
28
|
+
manifestDir?: string;
|
|
29
|
+
/** Inject the release as `import.meta.env.VITE_LOUPFEED_RELEASE`. Default true. */
|
|
30
|
+
injectRelease?: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare function loupfeedVite(options?: LoupfeedViteOptions): Plugin;
|
|
33
|
+
/** Alias matching the name re-exported by `@loupfeed/react` (doc 02). */
|
|
34
|
+
declare const feedbackVite: typeof loupfeedVite;
|
|
35
|
+
|
|
36
|
+
export { type LoupfeedViteOptions as FeedbackViteOptions, type LoupfeedViteOptions, feedbackVite, loupfeedVite };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @loupfeed/vite-plugin — the existing Trivision `dataFbLocPlugin`, generalized.
|
|
5
|
+
*
|
|
6
|
+
* Runs as `enforce: 'pre'` so it tags JSX before @vitejs/plugin-react lowers
|
|
7
|
+
* TSX → JS; the injected `data-fb` string attributes survive that lowering.
|
|
8
|
+
* On a production build it writes (and optionally uploads) the server-side
|
|
9
|
+
* manifest. No source paths ever reach the client bundle.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface LoupfeedViteOptions {
|
|
13
|
+
/** DSN — when given together with `authToken`, the manifest is uploaded at build end. */
|
|
14
|
+
dsn?: string;
|
|
15
|
+
/** Privileged build/CI token for manifest upload (NOT the public DSN key). */
|
|
16
|
+
authToken?: string;
|
|
17
|
+
/** `version@commit` join key. Defaults to `buildIdentity()` (git + package.json). */
|
|
18
|
+
release?: string;
|
|
19
|
+
/** Files to tag. Default `/\.(t|j)sx$/`. */
|
|
20
|
+
include?: RegExp;
|
|
21
|
+
/** Project root. Defaults to Vite's resolved root. */
|
|
22
|
+
root?: string;
|
|
23
|
+
/** Only tag files under `<root>/srcDir`. Default `'src'`. Set `''` to tag the whole root. */
|
|
24
|
+
srcDir?: string;
|
|
25
|
+
/** Write `fb-manifest.<release>.json` to disk at build end. Default true. */
|
|
26
|
+
writeManifest?: boolean;
|
|
27
|
+
/** Directory for the on-disk manifest (kept out of dist/). Default project root. */
|
|
28
|
+
manifestDir?: string;
|
|
29
|
+
/** Inject the release as `import.meta.env.VITE_LOUPFEED_RELEASE`. Default true. */
|
|
30
|
+
injectRelease?: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare function loupfeedVite(options?: LoupfeedViteOptions): Plugin;
|
|
33
|
+
/** Alias matching the name re-exported by `@loupfeed/react` (doc 02). */
|
|
34
|
+
declare const feedbackVite: typeof loupfeedVite;
|
|
35
|
+
|
|
36
|
+
export { type LoupfeedViteOptions as FeedbackViteOptions, type LoupfeedViteOptions, feedbackVite, loupfeedVite };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import {
|
|
4
|
+
buildIdentity,
|
|
5
|
+
createTagger,
|
|
6
|
+
uploadManifest,
|
|
7
|
+
writeManifestFile
|
|
8
|
+
} from "@loupfeed/build";
|
|
9
|
+
function loupfeedVite(options = {}) {
|
|
10
|
+
let tagger;
|
|
11
|
+
let root = options.root ?? process.cwd();
|
|
12
|
+
let srcRoot = "";
|
|
13
|
+
let release = options.release ?? "";
|
|
14
|
+
let isBuild = false;
|
|
15
|
+
return {
|
|
16
|
+
name: "loupfeed",
|
|
17
|
+
enforce: "pre",
|
|
18
|
+
config(_config, env) {
|
|
19
|
+
isBuild = env.command === "build";
|
|
20
|
+
release = options.release ?? buildIdentity({ cwd: options.root ?? process.cwd() }).release;
|
|
21
|
+
if (options.injectRelease !== false) {
|
|
22
|
+
return { define: { "import.meta.env.VITE_LOUPFEED_RELEASE": JSON.stringify(release) } };
|
|
23
|
+
}
|
|
24
|
+
return void 0;
|
|
25
|
+
},
|
|
26
|
+
configResolved(resolved) {
|
|
27
|
+
root = options.root ?? resolved.root;
|
|
28
|
+
const srcDir = options.srcDir ?? "src";
|
|
29
|
+
srcRoot = srcDir ? path.join(root, srcDir) : root;
|
|
30
|
+
tagger = createTagger({ projectRoot: root, include: options.include });
|
|
31
|
+
},
|
|
32
|
+
transform(code, id) {
|
|
33
|
+
if (!tagger) return null;
|
|
34
|
+
const cleanId = id.split("?")[0] ?? id;
|
|
35
|
+
if (!cleanId.startsWith(srcRoot)) return null;
|
|
36
|
+
const result = tagger.transform(code, cleanId);
|
|
37
|
+
return result ? { code: result.code, map: result.map } : null;
|
|
38
|
+
},
|
|
39
|
+
async buildEnd() {
|
|
40
|
+
if (!isBuild || !tagger) return;
|
|
41
|
+
const ids = tagger.manifest();
|
|
42
|
+
const count = Object.keys(ids).length;
|
|
43
|
+
if (count === 0) return;
|
|
44
|
+
if (options.writeManifest !== false) {
|
|
45
|
+
const file = writeManifestFile({ ids, release, outDir: options.manifestDir ?? root });
|
|
46
|
+
this.warn(`[loupfeed] wrote ${count} ids \u2192 ${path.relative(root, file)} (server-side; do not serve)`);
|
|
47
|
+
}
|
|
48
|
+
if (options.dsn && options.authToken) {
|
|
49
|
+
try {
|
|
50
|
+
await uploadManifest({ dsn: options.dsn, release, ids, authToken: options.authToken });
|
|
51
|
+
this.warn(`[loupfeed] uploaded manifest for release ${release} (${count} ids)`);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
this.error(`[loupfeed] manifest upload failed: ${err.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
var feedbackVite = loupfeedVite;
|
|
60
|
+
export {
|
|
61
|
+
feedbackVite,
|
|
62
|
+
loupfeedVite
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @loupfeed/vite-plugin — the existing Trivision `dataFbLocPlugin`, generalized.\n *\n * Runs as `enforce: 'pre'` so it tags JSX before @vitejs/plugin-react lowers\n * TSX → JS; the injected `data-fb` string attributes survive that lowering.\n * On a production build it writes (and optionally uploads) the server-side\n * manifest. No source paths ever reach the client bundle.\n */\n\nimport path from 'node:path';\nimport type { Plugin } from 'vite';\nimport {\n buildIdentity,\n createTagger,\n uploadManifest,\n writeManifestFile,\n type Tagger,\n} from '@loupfeed/build';\n\nexport interface LoupfeedViteOptions {\n /** DSN — when given together with `authToken`, the manifest is uploaded at build end. */\n dsn?: string;\n /** Privileged build/CI token for manifest upload (NOT the public DSN key). */\n authToken?: string;\n /** `version@commit` join key. Defaults to `buildIdentity()` (git + package.json). */\n release?: string;\n /** Files to tag. Default `/\\.(t|j)sx$/`. */\n include?: RegExp;\n /** Project root. Defaults to Vite's resolved root. */\n root?: string;\n /** Only tag files under `<root>/srcDir`. Default `'src'`. Set `''` to tag the whole root. */\n srcDir?: string;\n /** Write `fb-manifest.<release>.json` to disk at build end. Default true. */\n writeManifest?: boolean;\n /** Directory for the on-disk manifest (kept out of dist/). Default project root. */\n manifestDir?: string;\n /** Inject the release as `import.meta.env.VITE_LOUPFEED_RELEASE`. Default true. */\n injectRelease?: boolean;\n}\n\nexport function loupfeedVite(options: LoupfeedViteOptions = {}): Plugin {\n let tagger: Tagger | undefined;\n let root = options.root ?? process.cwd();\n let srcRoot = '';\n let release = options.release ?? '';\n let isBuild = false;\n\n return {\n name: 'loupfeed',\n enforce: 'pre',\n\n config(_config, env) {\n isBuild = env.command === 'build';\n release = options.release ?? buildIdentity({ cwd: options.root ?? process.cwd() }).release;\n if (options.injectRelease !== false) {\n return { define: { 'import.meta.env.VITE_LOUPFEED_RELEASE': JSON.stringify(release) } };\n }\n return undefined;\n },\n\n configResolved(resolved) {\n root = options.root ?? resolved.root;\n const srcDir = options.srcDir ?? 'src';\n srcRoot = srcDir ? path.join(root, srcDir) : root;\n tagger = createTagger({ projectRoot: root, include: options.include });\n },\n\n transform(code, id) {\n if (!tagger) return null;\n const cleanId = id.split('?')[0] ?? id;\n if (!cleanId.startsWith(srcRoot)) return null;\n const result = tagger.transform(code, cleanId);\n return result ? { code: result.code, map: result.map } : null;\n },\n\n async buildEnd() {\n // Only emit a manifest for real builds (not the dev server).\n if (!isBuild || !tagger) return;\n const ids = tagger.manifest();\n const count = Object.keys(ids).length;\n if (count === 0) return;\n\n if (options.writeManifest !== false) {\n const file = writeManifestFile({ ids, release, outDir: options.manifestDir ?? root });\n this.warn(`[loupfeed] wrote ${count} ids → ${path.relative(root, file)} (server-side; do not serve)`);\n }\n\n if (options.dsn && options.authToken) {\n try {\n await uploadManifest({ dsn: options.dsn, release, ids, authToken: options.authToken });\n this.warn(`[loupfeed] uploaded manifest for release ${release} (${count} ids)`);\n } catch (err) {\n this.error(`[loupfeed] manifest upload failed: ${(err as Error).message}`);\n }\n }\n },\n };\n}\n\n/** Alias matching the name re-exported by `@loupfeed/react` (doc 02). */\nexport const feedbackVite = loupfeedVite;\nexport type { LoupfeedViteOptions as FeedbackViteOptions };\n"],"mappings":";AASA,OAAO,UAAU;AAEjB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAuBA,SAAS,aAAa,UAA+B,CAAC,GAAW;AACtE,MAAI;AACJ,MAAI,OAAO,QAAQ,QAAQ,QAAQ,IAAI;AACvC,MAAI,UAAU;AACd,MAAI,UAAU,QAAQ,WAAW;AACjC,MAAI,UAAU;AAEd,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,OAAO,SAAS,KAAK;AACnB,gBAAU,IAAI,YAAY;AAC1B,gBAAU,QAAQ,WAAW,cAAc,EAAE,KAAK,QAAQ,QAAQ,QAAQ,IAAI,EAAE,CAAC,EAAE;AACnF,UAAI,QAAQ,kBAAkB,OAAO;AACnC,eAAO,EAAE,QAAQ,EAAE,yCAAyC,KAAK,UAAU,OAA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":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loupfeed/vite-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "loupfeed Vite plugin — injects opaque data-fb ids (enforce:'pre') and writes/uploads the server-side id→src:line manifest at build end.",
|
|
5
|
+
"license": "FSL-1.1-ALv2",
|
|
6
|
+
"homepage": "https://loupfeed.com",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/gilons/loupfeed.git",
|
|
10
|
+
"directory": "packages/vite-plugin"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@loupfeed/build": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"vite": "^5.0.0 || ^6.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.10.2",
|
|
40
|
+
"tsup": "^8.3.5",
|
|
41
|
+
"typescript": "~5.7.2",
|
|
42
|
+
"vite": "^6.0.5"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"dev": "tsup --watch",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"clean": "rm -rf dist .turbo"
|
|
49
|
+
}
|
|
50
|
+
}
|