@variant-forge/unplugin 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/client.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare module 'virtual:variant-forge' {
2
+ const config: Record<string, unknown>;
3
+ export default config;
4
+ }
@@ -0,0 +1,3 @@
1
+ declare const _default: (options: import("./index").VariantUnpluginOptions) => import("unplugin").EsbuildPlugin;
2
+ export default _default;
3
+ //# sourceMappingURL=esbuild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../src/esbuild.ts"],"names":[],"mappings":";AACA,wBAAgC"}
@@ -0,0 +1,2 @@
1
+ import { unplugin } from './index';
2
+ export default unplugin.esbuild;
@@ -0,0 +1,18 @@
1
+ export interface VariantUnpluginOptions {
2
+ /**
3
+ * The Server SDK Key for your environment.
4
+ */
5
+ sdkKey: string;
6
+ apiUrl: string;
7
+ /**
8
+ * A list of config or feature flag keys you want to fetch and bundle at build time.
9
+ */
10
+ configs: string[];
11
+ /**
12
+ * Optional context for targeting evaluation.
13
+ */
14
+ context?: Record<string, string | number | boolean | null>;
15
+ }
16
+ export declare const unplugin: import("unplugin").UnpluginInstance<VariantUnpluginOptions, boolean>;
17
+ export default unplugin;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;CAC5D;AAKD,eAAO,MAAM,QAAQ,sEA6DnB,CAAC;AAEH,eAAe,QAAQ,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ import { createUnplugin } from 'unplugin';
2
+ import { VariantNodeClient } from '@variant-forge/sdk-node';
3
+ const virtualModuleId = 'virtual:variant-forge';
4
+ const resolvedVirtualModuleId = '\0' + virtualModuleId;
5
+ export const unplugin = createUnplugin((options) => {
6
+ if (!options || !options.sdkKey || !options.apiUrl) {
7
+ throw new Error('Variant Forge unplugin requires sdkKey and apiUrl');
8
+ }
9
+ const fetchedConfigs = {};
10
+ return {
11
+ name: 'variant-forge-unplugin',
12
+ async buildStart() {
13
+ const client = new VariantNodeClient({
14
+ sdkKey: options.sdkKey,
15
+ apiUrl: options.apiUrl,
16
+ });
17
+ // Use sync to fetch once without starting the background polling interval
18
+ await client.sync();
19
+ const context = options.context || {};
20
+ for (const key of options.configs || []) {
21
+ fetchedConfigs[key] = client.getConfig(key, context);
22
+ // Also check if it's a feature flag if getConfig returned undefined, or assume it's merged
23
+ if (fetchedConfigs[key] === undefined) {
24
+ fetchedConfigs[key] = client.isFeatureEnabled(key, context);
25
+ }
26
+ }
27
+ // Cleanup to make sure process can exit
28
+ client.close();
29
+ },
30
+ resolveId(id) {
31
+ if (id === virtualModuleId) {
32
+ return resolvedVirtualModuleId;
33
+ }
34
+ return null;
35
+ },
36
+ load(id) {
37
+ if (id === resolvedVirtualModuleId) {
38
+ // Generate the JS module exporting the fetched configs
39
+ let code = '';
40
+ for (const [key, value] of Object.entries(fetchedConfigs)) {
41
+ code += `export const ${key} = ${JSON.stringify(value)};\n`;
42
+ }
43
+ // Also provide a default export containing all keys
44
+ code += `export default {\n`;
45
+ for (const key of Object.keys(fetchedConfigs)) {
46
+ code += ` ${key},\n`;
47
+ }
48
+ code += `};\n`;
49
+ return code;
50
+ }
51
+ return null;
52
+ },
53
+ };
54
+ });
55
+ export default unplugin;
@@ -0,0 +1,3 @@
1
+ declare const _default: (options: import("./index").VariantUnpluginOptions) => any;
2
+ export default _default;
3
+ //# sourceMappingURL=rollup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":";AACA,wBAA+B"}
package/dist/rollup.js ADDED
@@ -0,0 +1,2 @@
1
+ import { unplugin } from './index';
2
+ export default unplugin.rollup;
package/dist/vite.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const _default: (options: import("./index").VariantUnpluginOptions) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
2
+ export default _default;
3
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":";AACA,wBAA6B"}
package/dist/vite.js ADDED
@@ -0,0 +1,2 @@
1
+ import { unplugin } from './index';
2
+ export default unplugin.vite;
@@ -0,0 +1,3 @@
1
+ declare const _default: (options: import("./index").VariantUnpluginOptions) => WebpackPluginInstance;
2
+ export default _default;
3
+ //# sourceMappingURL=webpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":";AACA,wBAAgC"}
@@ -0,0 +1,2 @@
1
+ import { unplugin } from './index';
2
+ export default unplugin.webpack;
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@variant-forge/unplugin",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./src/index.ts",
6
+ "types": "./src/index.ts",
7
+ "publishConfig": {
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./vite": {
17
+ "types": "./dist/vite.d.ts",
18
+ "import": "./dist/vite.js",
19
+ "default": "./dist/vite.js"
20
+ },
21
+ "./webpack": {
22
+ "types": "./dist/webpack.d.ts",
23
+ "import": "./dist/webpack.js",
24
+ "default": "./dist/webpack.js"
25
+ },
26
+ "./rollup": {
27
+ "types": "./dist/rollup.d.ts",
28
+ "import": "./dist/rollup.js",
29
+ "default": "./dist/rollup.js"
30
+ },
31
+ "./esbuild": {
32
+ "types": "./dist/esbuild.d.ts",
33
+ "import": "./dist/esbuild.js",
34
+ "default": "./dist/esbuild.js"
35
+ }
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "client.d.ts"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsc",
44
+ "lint": "eslint . --max-warnings 0",
45
+ "check-types": "tsc --noEmit",
46
+ "publish": "pnpm publish --access public"
47
+ },
48
+ "dependencies": {
49
+ "@variant-forge/sdk-node": "workspace:*",
50
+ "unplugin": "^1.10.1"
51
+ },
52
+ "devDependencies": {
53
+ "@package/eslint-config": "workspace:*",
54
+ "@package/typescript-config": "workspace:*",
55
+ "@types/node": "^22.15.3",
56
+ "eslint": "^9.39.1",
57
+ "typescript": "5.9.2"
58
+ }
59
+ }