@variant-forge/unplugin 0.1.2 → 0.1.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.
@@ -0,0 +1,60 @@
1
+ // src/index.ts
2
+ import { createUnplugin } from "unplugin";
3
+ import { VariantNodeClient } from "@variant-forge/sdk-node";
4
+ var virtualModuleId = "virtual:variant-forge";
5
+ var resolvedVirtualModuleId = "\0" + virtualModuleId;
6
+ var unplugin = createUnplugin((options) => {
7
+ if (!options || !options.sdkKey || !options.apiUrl) {
8
+ throw new Error("Variant Forge unplugin requires sdkKey and apiUrl");
9
+ }
10
+ const fetchedConfigs = {};
11
+ return {
12
+ name: "variant-forge-unplugin",
13
+ async buildStart() {
14
+ const client = new VariantNodeClient({
15
+ sdkKey: options.sdkKey,
16
+ apiUrl: options.apiUrl
17
+ });
18
+ await client.sync();
19
+ const context = options.context || {};
20
+ for (const key of options.configs || []) {
21
+ fetchedConfigs[key] = client.getConfig(key, context);
22
+ if (fetchedConfigs[key] === void 0) {
23
+ fetchedConfigs[key] = client.isFeatureEnabled(key, context);
24
+ }
25
+ }
26
+ client.close();
27
+ },
28
+ resolveId(id) {
29
+ if (id === virtualModuleId) {
30
+ return resolvedVirtualModuleId;
31
+ }
32
+ return null;
33
+ },
34
+ load(id) {
35
+ if (id === resolvedVirtualModuleId) {
36
+ let code = "";
37
+ for (const [key, value] of Object.entries(fetchedConfigs)) {
38
+ code += `export const ${key} = ${JSON.stringify(value)};
39
+ `;
40
+ }
41
+ code += `export default {
42
+ `;
43
+ for (const key of Object.keys(fetchedConfigs)) {
44
+ code += ` ${key},
45
+ `;
46
+ }
47
+ code += `};
48
+ `;
49
+ return code;
50
+ }
51
+ return null;
52
+ }
53
+ };
54
+ });
55
+ var index_default = unplugin;
56
+
57
+ export {
58
+ unplugin,
59
+ index_default
60
+ };
package/dist/esbuild.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- declare const _default: (options: import("./index").VariantUnpluginOptions) => import("unplugin").EsbuildPlugin;
2
- export default _default;
3
- //# sourceMappingURL=esbuild.d.ts.map
1
+ import * as unplugin from 'unplugin';
2
+ import { VariantUnpluginOptions } from './index.js';
3
+
4
+ declare const _default: (options: VariantUnpluginOptions) => unplugin.EsbuildPlugin;
5
+
6
+ export { _default as default };
package/dist/esbuild.js CHANGED
@@ -1,2 +1,9 @@
1
- import { unplugin } from './index';
2
- export default unplugin.esbuild;
1
+ import {
2
+ unplugin
3
+ } from "./chunk-CUXQPZR7.js";
4
+
5
+ // src/esbuild.ts
6
+ var esbuild_default = unplugin.esbuild;
7
+ export {
8
+ esbuild_default as default
9
+ };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export interface VariantUnpluginOptions {
1
+ import * as unplugin$1 from 'unplugin';
2
+
3
+ interface VariantUnpluginOptions {
2
4
  /**
3
5
  * The Server SDK Key for your environment.
4
6
  */
@@ -13,6 +15,6 @@ export interface VariantUnpluginOptions {
13
15
  */
14
16
  context?: Record<string, string | number | boolean | null>;
15
17
  }
16
- export declare const unplugin: import("unplugin").UnpluginInstance<VariantUnpluginOptions, boolean>;
17
- export default unplugin;
18
- //# sourceMappingURL=index.d.ts.map
18
+ declare const unplugin: unplugin$1.UnpluginInstance<VariantUnpluginOptions, boolean>;
19
+
20
+ export { type VariantUnpluginOptions, unplugin as default, unplugin };
package/dist/index.js CHANGED
@@ -1,55 +1,8 @@
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;
1
+ import {
2
+ index_default,
3
+ unplugin
4
+ } from "./chunk-CUXQPZR7.js";
5
+ export {
6
+ index_default as default,
7
+ unplugin
8
+ };
package/dist/rollup.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- declare const _default: (options: import("./index").VariantUnpluginOptions) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
2
- export default _default;
3
- //# sourceMappingURL=rollup.d.ts.map
1
+ import * as unplugin from 'unplugin';
2
+ import { VariantUnpluginOptions } from './index.js';
3
+
4
+ declare const _default: (options: VariantUnpluginOptions) => unplugin.RollupPlugin<any> | unplugin.RollupPlugin<any>[];
5
+
6
+ export { _default as default };
package/dist/rollup.js CHANGED
@@ -1,2 +1,9 @@
1
- import { unplugin } from './index';
2
- export default unplugin.rollup;
1
+ import {
2
+ unplugin
3
+ } from "./chunk-CUXQPZR7.js";
4
+
5
+ // src/rollup.ts
6
+ var rollup_default = unplugin.rollup;
7
+ export {
8
+ rollup_default as default
9
+ };
package/dist/vite.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- declare const _default: (options: import("./index").VariantUnpluginOptions) => import("unplugin").VitePlugin<any> | import("unplugin").VitePlugin<any>[];
2
- export default _default;
3
- //# sourceMappingURL=vite.d.ts.map
1
+ import * as unplugin from 'unplugin';
2
+ import { VariantUnpluginOptions } from './index.js';
3
+
4
+ declare const _default: (options: VariantUnpluginOptions) => unplugin.VitePlugin<any> | unplugin.VitePlugin<any>[];
5
+
6
+ export { _default as default };
package/dist/vite.js CHANGED
@@ -1,2 +1,9 @@
1
- import { unplugin } from './index';
2
- export default unplugin.vite;
1
+ import {
2
+ unplugin
3
+ } from "./chunk-CUXQPZR7.js";
4
+
5
+ // src/vite.ts
6
+ var vite_default = unplugin.vite;
7
+ export {
8
+ vite_default as default
9
+ };
package/dist/webpack.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- declare const _default: (options: import("./index").VariantUnpluginOptions) => WebpackPluginInstance;
2
- export default _default;
3
- //# sourceMappingURL=webpack.d.ts.map
1
+ import { VariantUnpluginOptions } from './index.js';
2
+ import 'unplugin';
3
+
4
+ declare const _default: (options: VariantUnpluginOptions) => WebpackPluginInstance;
5
+
6
+ export { _default as default };
package/dist/webpack.js CHANGED
@@ -1,2 +1,9 @@
1
- import { unplugin } from './index';
2
- export default unplugin.webpack;
1
+ import {
2
+ unplugin
3
+ } from "./chunk-CUXQPZR7.js";
4
+
5
+ // src/webpack.ts
6
+ var webpack_default = unplugin.webpack;
7
+ export {
8
+ webpack_default as default
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@variant-forge/unplugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -15,12 +15,13 @@
15
15
  "devDependencies": {
16
16
  "@types/node": "^22.15.3",
17
17
  "eslint": "^9.39.1",
18
+ "tsup": "^8.4.0",
18
19
  "typescript": "5.9.2",
19
20
  "@package/typescript-config": "0.0.0",
20
21
  "@package/eslint-config": "0.0.0"
21
22
  },
22
23
  "scripts": {
23
- "build": "tsc",
24
+ "build": "tsup src/index.ts src/vite.ts src/webpack.ts src/rollup.ts src/esbuild.ts --format esm --dts --clean",
24
25
  "lint": "eslint . --max-warnings 0",
25
26
  "check-types": "tsc --noEmit",
26
27
  "release": "pnpm publish --access public"
@@ -1 +0,0 @@
1
- {"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../src/esbuild.ts"],"names":[],"mappings":";AACA,wBAAgC"}
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":";AACA,wBAA+B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":";AACA,wBAA6B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":";AACA,wBAAgC"}