@onlook/storybook-plugin 0.4.0-beta.16 → 0.4.0-beta.18
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/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { E as EnvContainmentOptions, a as EnvContainmentSubstitution, O as OnlookPluginOptions, e as envContainmentPlugin, s as storybookOnlookPlugin } from './storybook-onlook-plugin-
|
|
1
|
+
export { E as EnvContainmentOptions, a as EnvContainmentSubstitution, O as OnlookPluginOptions, e as envContainmentPlugin, s as storybookOnlookPlugin } from './storybook-onlook-plugin-J4qj72mN.js';
|
|
2
2
|
import { Plugin } from 'vite';
|
|
3
3
|
import { Indexer } from 'storybook/internal/types';
|
|
4
4
|
|
package/dist/index.js
CHANGED
|
@@ -857,6 +857,199 @@ function handleStoryFileChange({ file, modules }) {
|
|
|
857
857
|
}
|
|
858
858
|
}
|
|
859
859
|
|
|
860
|
+
// src/package-mock/clerk-mock.ts
|
|
861
|
+
var VALID_IDENT_RE2 = /^[A-Za-z_$][\w$]*$/;
|
|
862
|
+
var RESERVED_HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
863
|
+
"__user",
|
|
864
|
+
"__pass",
|
|
865
|
+
"__null",
|
|
866
|
+
"__clerk",
|
|
867
|
+
"__sessionId",
|
|
868
|
+
"__asyncNoop",
|
|
869
|
+
"__noop",
|
|
870
|
+
"createElement",
|
|
871
|
+
"Fragment"
|
|
872
|
+
]);
|
|
873
|
+
var BUILDERS = {
|
|
874
|
+
"@clerk/nextjs": buildClerkMockSource,
|
|
875
|
+
"@clerk/clerk-react": buildClerkMockSource
|
|
876
|
+
};
|
|
877
|
+
function isKnownMockPackage(pkg) {
|
|
878
|
+
return pkg in BUILDERS;
|
|
879
|
+
}
|
|
880
|
+
function buildPackageMockSource(pkg, usedExports) {
|
|
881
|
+
const build = BUILDERS[pkg];
|
|
882
|
+
if (!build) throw new Error(`no package mock for '${pkg}'`);
|
|
883
|
+
return build(usedExports);
|
|
884
|
+
}
|
|
885
|
+
var CLERK_KNOWN_HOOKS = {
|
|
886
|
+
useAuth: "({ isLoaded: true, isSignedIn: true, userId: __user.id, sessionId: __sessionId, actor: null, orgId: null, orgRole: null, orgSlug: null, has: () => true, signOut: __asyncNoop, getToken: async () => null })",
|
|
887
|
+
useUser: "({ isLoaded: true, isSignedIn: true, user: __user })",
|
|
888
|
+
useSession: '({ isLoaded: true, isSignedIn: true, session: { id: __sessionId, status: "active", user: __user } })',
|
|
889
|
+
useSessionList: "({ isLoaded: true, sessions: [], setActive: __asyncNoop })",
|
|
890
|
+
useClerk: "__clerk",
|
|
891
|
+
useOrganization: "({ isLoaded: true, organization: null, membership: null, memberships: undefined })",
|
|
892
|
+
useOrganizationList: "({ isLoaded: true, userMemberships: undefined, setActive: __asyncNoop })",
|
|
893
|
+
useSignIn: "({ isLoaded: true, signIn: undefined, setActive: __asyncNoop })",
|
|
894
|
+
useSignUp: "({ isLoaded: true, signUp: undefined, setActive: __asyncNoop })"
|
|
895
|
+
};
|
|
896
|
+
var CLERK_CHILDREN_COMPONENTS = /* @__PURE__ */ new Set([
|
|
897
|
+
"ClerkProvider",
|
|
898
|
+
"ClerkLoaded",
|
|
899
|
+
"SignedIn",
|
|
900
|
+
"Protect",
|
|
901
|
+
"SignInButton",
|
|
902
|
+
"SignUpButton",
|
|
903
|
+
"SignOutButton",
|
|
904
|
+
"SignInWithMetamaskButton"
|
|
905
|
+
]);
|
|
906
|
+
var CLERK_NULL_COMPONENTS = /* @__PURE__ */ new Set([
|
|
907
|
+
"SignedOut",
|
|
908
|
+
"ClerkLoading",
|
|
909
|
+
"RedirectToSignIn",
|
|
910
|
+
"RedirectToSignUp",
|
|
911
|
+
"RedirectToUserProfile",
|
|
912
|
+
"RedirectToOrganizationProfile",
|
|
913
|
+
"RedirectToCreateOrganization",
|
|
914
|
+
"AuthenticateWithRedirectCallback",
|
|
915
|
+
"UserButton",
|
|
916
|
+
"UserProfile",
|
|
917
|
+
"OrganizationSwitcher",
|
|
918
|
+
"OrganizationProfile",
|
|
919
|
+
"OrganizationList",
|
|
920
|
+
"CreateOrganization",
|
|
921
|
+
"SignIn",
|
|
922
|
+
"SignUp",
|
|
923
|
+
"Waitlist",
|
|
924
|
+
"GoogleOneTap"
|
|
925
|
+
]);
|
|
926
|
+
var CLERK_PREAMBLE = [
|
|
927
|
+
"// Auto-generated by @onlook/storybook-plugin (package mock). Zero-backend,",
|
|
928
|
+
"// signed-in Clerk stand-in so components that call useUser()/useAuth() render",
|
|
929
|
+
"// authenticated content in the canvas without a publishable key, clerk-js, or",
|
|
930
|
+
"// a network round-trip. Swap back to the real @clerk/* package for live data.",
|
|
931
|
+
"import { createElement, Fragment } from 'react';",
|
|
932
|
+
"const __asyncNoop = async () => {};",
|
|
933
|
+
"const __noop = () => {};",
|
|
934
|
+
// No `: any` param annotation: the virtual module is served extensionless
|
|
935
|
+
// (see header) so Vite parses it as PLAIN JS — a TS type annotation here is a
|
|
936
|
+
// runtime `Unexpected token ':'` that breaks every story importing the package.
|
|
937
|
+
"const __pass = (props) => createElement(Fragment, null, props ? props.children : undefined);",
|
|
938
|
+
"const __null = () => null;",
|
|
939
|
+
"const __sessionId = 'sess_onlookMock';",
|
|
940
|
+
"// A plausible signed-in Clerk user. Fields cover the common UserResource",
|
|
941
|
+
"// surface components read at render; no image URL (avoids a network fetch).",
|
|
942
|
+
"const __user = {",
|
|
943
|
+
" id: 'user_onlookMock',",
|
|
944
|
+
" firstName: 'Ada',",
|
|
945
|
+
" lastName: 'Lovelace',",
|
|
946
|
+
" fullName: 'Ada Lovelace',",
|
|
947
|
+
" username: 'ada',",
|
|
948
|
+
" imageUrl: '',",
|
|
949
|
+
" hasImage: false,",
|
|
950
|
+
" primaryEmailAddressId: 'idn_onlookMock',",
|
|
951
|
+
" primaryEmailAddress: { id: 'idn_onlookMock', emailAddress: 'ada@example.com' },",
|
|
952
|
+
" emailAddresses: [{ id: 'idn_onlookMock', emailAddress: 'ada@example.com' }],",
|
|
953
|
+
" primaryPhoneNumber: null,",
|
|
954
|
+
" phoneNumbers: [],",
|
|
955
|
+
" externalAccounts: [],",
|
|
956
|
+
" organizationMemberships: [],",
|
|
957
|
+
" publicMetadata: {},",
|
|
958
|
+
" unsafeMetadata: {},",
|
|
959
|
+
" reload: __asyncNoop,",
|
|
960
|
+
" update: __asyncNoop,",
|
|
961
|
+
"};",
|
|
962
|
+
"const __clerk = {",
|
|
963
|
+
" loaded: true,",
|
|
964
|
+
" user: __user,",
|
|
965
|
+
" session: { id: __sessionId, status: 'active', user: __user },",
|
|
966
|
+
" organization: null,",
|
|
967
|
+
" openSignIn: __noop,",
|
|
968
|
+
" openSignUp: __noop,",
|
|
969
|
+
" openUserProfile: __noop,",
|
|
970
|
+
" openOrganizationProfile: __noop,",
|
|
971
|
+
" closeSignIn: __noop,",
|
|
972
|
+
" closeSignUp: __noop,",
|
|
973
|
+
" signOut: __asyncNoop,",
|
|
974
|
+
" setActive: __asyncNoop,",
|
|
975
|
+
"};"
|
|
976
|
+
];
|
|
977
|
+
function clerkExportLine(name) {
|
|
978
|
+
if (name in CLERK_KNOWN_HOOKS) {
|
|
979
|
+
return `export const ${name} = () => ${CLERK_KNOWN_HOOKS[name]};`;
|
|
980
|
+
}
|
|
981
|
+
if (CLERK_CHILDREN_COMPONENTS.has(name)) {
|
|
982
|
+
return `export const ${name} = __pass;`;
|
|
983
|
+
}
|
|
984
|
+
if (CLERK_NULL_COMPONENTS.has(name)) {
|
|
985
|
+
return `export const ${name} = __null;`;
|
|
986
|
+
}
|
|
987
|
+
if (/^use[A-Z]/.test(name)) {
|
|
988
|
+
return `export const ${name} = () => ({ isLoaded: true, isSignedIn: true });`;
|
|
989
|
+
}
|
|
990
|
+
if (/^[A-Z]/.test(name)) {
|
|
991
|
+
return `export const ${name} = __pass;`;
|
|
992
|
+
}
|
|
993
|
+
return `export const ${name} = undefined;`;
|
|
994
|
+
}
|
|
995
|
+
function buildClerkMockSource(usedExports) {
|
|
996
|
+
const names = Array.from(
|
|
997
|
+
new Set(
|
|
998
|
+
usedExports.filter(
|
|
999
|
+
(n) => VALID_IDENT_RE2.test(n) && n !== "default" && !RESERVED_HELPER_NAMES.has(n)
|
|
1000
|
+
)
|
|
1001
|
+
)
|
|
1002
|
+
).sort();
|
|
1003
|
+
const lines = [
|
|
1004
|
+
...CLERK_PREAMBLE,
|
|
1005
|
+
"",
|
|
1006
|
+
...names.map(clerkExportLine),
|
|
1007
|
+
"",
|
|
1008
|
+
"// Rarely used, but `import Clerk from ...` must not fail: an inert object.",
|
|
1009
|
+
"export default {};",
|
|
1010
|
+
""
|
|
1011
|
+
];
|
|
1012
|
+
return lines.join("\n");
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// src/package-mock/package-mock.ts
|
|
1016
|
+
var PACKAGE_MOCK_PLUGIN_NAME = "onlook-package-mock";
|
|
1017
|
+
var PACKAGE_MOCK_VIRTUAL_PREFIX = "\0onlook-package-mock:";
|
|
1018
|
+
function stripQuery2(id) {
|
|
1019
|
+
const q = id.indexOf("?");
|
|
1020
|
+
return q === -1 ? id : id.slice(0, q);
|
|
1021
|
+
}
|
|
1022
|
+
function packageMockPlugin(options) {
|
|
1023
|
+
const entries = (options?.packages ?? []).filter(
|
|
1024
|
+
(e) => e && typeof e.package === "string" && e.package.length > 0 && // Only known auth packages get a functional mock — an unknown package
|
|
1025
|
+
// has no source builder, so silently drop it (honest skip) rather than
|
|
1026
|
+
// intercept it into a broken module.
|
|
1027
|
+
isKnownMockPackage(e.package)
|
|
1028
|
+
);
|
|
1029
|
+
if (entries.length === 0) return null;
|
|
1030
|
+
const usedByPackage = /* @__PURE__ */ new Map();
|
|
1031
|
+
for (const e of entries) usedByPackage.set(e.package, e.usedExports ?? []);
|
|
1032
|
+
return {
|
|
1033
|
+
name: PACKAGE_MOCK_PLUGIN_NAME,
|
|
1034
|
+
// `pre` so we intercept the specifier before Vite's resolve pipeline (and
|
|
1035
|
+
// before tsconfig-paths / node resolution) claims it.
|
|
1036
|
+
enforce: "pre",
|
|
1037
|
+
resolveId(source) {
|
|
1038
|
+
if (source.startsWith("\0")) return null;
|
|
1039
|
+
const cleaned = stripQuery2(source);
|
|
1040
|
+
if (!usedByPackage.has(cleaned)) return null;
|
|
1041
|
+
return PACKAGE_MOCK_VIRTUAL_PREFIX + cleaned;
|
|
1042
|
+
},
|
|
1043
|
+
load(id) {
|
|
1044
|
+
if (!id.startsWith(PACKAGE_MOCK_VIRTUAL_PREFIX)) return null;
|
|
1045
|
+
const pkg = id.slice(PACKAGE_MOCK_VIRTUAL_PREFIX.length);
|
|
1046
|
+
const used = usedByPackage.get(pkg);
|
|
1047
|
+
if (used === void 0) return null;
|
|
1048
|
+
return buildPackageMockSource(pkg, used);
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
|
|
860
1053
|
// src/screenshot-service/utils/console-logs/console-logs.ts
|
|
861
1054
|
async function captureConsoleLogs(storyId, theme = "light", storybookUrl = "http://localhost:6006", timeoutMs = 3e4) {
|
|
862
1055
|
const browser = await getBrowser();
|
|
@@ -1669,10 +1862,12 @@ function storybookOnlookPlugin(options = {}) {
|
|
|
1669
1862
|
handleHotUpdate: handleStoryFileChange
|
|
1670
1863
|
};
|
|
1671
1864
|
const envContainment = envContainmentPlugin(options.envContainment);
|
|
1865
|
+
const packageMock = packageMockPlugin(options.packageMock);
|
|
1672
1866
|
const moduleLoadCatchAll = options.moduleLoadCatchAll === false ? null : moduleLoadCatchAllPlugin();
|
|
1673
1867
|
return withDedupeApply(
|
|
1674
1868
|
[
|
|
1675
1869
|
...envContainment ? [envContainment] : [],
|
|
1870
|
+
...packageMock ? [packageMock] : [],
|
|
1676
1871
|
...moduleLoadCatchAll ? [moduleLoadCatchAll] : [],
|
|
1677
1872
|
componentLocPlugin(),
|
|
1678
1873
|
mainPlugin,
|
package/dist/preset/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as OnlookPluginOptions } from '../storybook-onlook-plugin-
|
|
1
|
+
import { O as OnlookPluginOptions } from '../storybook-onlook-plugin-J4qj72mN.js';
|
|
2
2
|
import 'vite';
|
|
3
3
|
|
|
4
4
|
declare function pluginOptionsFromPresetOptions(options: Record<string, unknown> | undefined): OnlookPluginOptions;
|
package/dist/preset/index.js
CHANGED
|
@@ -853,6 +853,199 @@ function moduleLoadCatchAllPlugin() {
|
|
|
853
853
|
};
|
|
854
854
|
}
|
|
855
855
|
|
|
856
|
+
// src/package-mock/clerk-mock.ts
|
|
857
|
+
var VALID_IDENT_RE2 = /^[A-Za-z_$][\w$]*$/;
|
|
858
|
+
var RESERVED_HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
859
|
+
"__user",
|
|
860
|
+
"__pass",
|
|
861
|
+
"__null",
|
|
862
|
+
"__clerk",
|
|
863
|
+
"__sessionId",
|
|
864
|
+
"__asyncNoop",
|
|
865
|
+
"__noop",
|
|
866
|
+
"createElement",
|
|
867
|
+
"Fragment"
|
|
868
|
+
]);
|
|
869
|
+
var BUILDERS = {
|
|
870
|
+
"@clerk/nextjs": buildClerkMockSource,
|
|
871
|
+
"@clerk/clerk-react": buildClerkMockSource
|
|
872
|
+
};
|
|
873
|
+
function isKnownMockPackage(pkg) {
|
|
874
|
+
return pkg in BUILDERS;
|
|
875
|
+
}
|
|
876
|
+
function buildPackageMockSource(pkg, usedExports) {
|
|
877
|
+
const build = BUILDERS[pkg];
|
|
878
|
+
if (!build) throw new Error(`no package mock for '${pkg}'`);
|
|
879
|
+
return build(usedExports);
|
|
880
|
+
}
|
|
881
|
+
var CLERK_KNOWN_HOOKS = {
|
|
882
|
+
useAuth: "({ isLoaded: true, isSignedIn: true, userId: __user.id, sessionId: __sessionId, actor: null, orgId: null, orgRole: null, orgSlug: null, has: () => true, signOut: __asyncNoop, getToken: async () => null })",
|
|
883
|
+
useUser: "({ isLoaded: true, isSignedIn: true, user: __user })",
|
|
884
|
+
useSession: '({ isLoaded: true, isSignedIn: true, session: { id: __sessionId, status: "active", user: __user } })',
|
|
885
|
+
useSessionList: "({ isLoaded: true, sessions: [], setActive: __asyncNoop })",
|
|
886
|
+
useClerk: "__clerk",
|
|
887
|
+
useOrganization: "({ isLoaded: true, organization: null, membership: null, memberships: undefined })",
|
|
888
|
+
useOrganizationList: "({ isLoaded: true, userMemberships: undefined, setActive: __asyncNoop })",
|
|
889
|
+
useSignIn: "({ isLoaded: true, signIn: undefined, setActive: __asyncNoop })",
|
|
890
|
+
useSignUp: "({ isLoaded: true, signUp: undefined, setActive: __asyncNoop })"
|
|
891
|
+
};
|
|
892
|
+
var CLERK_CHILDREN_COMPONENTS = /* @__PURE__ */ new Set([
|
|
893
|
+
"ClerkProvider",
|
|
894
|
+
"ClerkLoaded",
|
|
895
|
+
"SignedIn",
|
|
896
|
+
"Protect",
|
|
897
|
+
"SignInButton",
|
|
898
|
+
"SignUpButton",
|
|
899
|
+
"SignOutButton",
|
|
900
|
+
"SignInWithMetamaskButton"
|
|
901
|
+
]);
|
|
902
|
+
var CLERK_NULL_COMPONENTS = /* @__PURE__ */ new Set([
|
|
903
|
+
"SignedOut",
|
|
904
|
+
"ClerkLoading",
|
|
905
|
+
"RedirectToSignIn",
|
|
906
|
+
"RedirectToSignUp",
|
|
907
|
+
"RedirectToUserProfile",
|
|
908
|
+
"RedirectToOrganizationProfile",
|
|
909
|
+
"RedirectToCreateOrganization",
|
|
910
|
+
"AuthenticateWithRedirectCallback",
|
|
911
|
+
"UserButton",
|
|
912
|
+
"UserProfile",
|
|
913
|
+
"OrganizationSwitcher",
|
|
914
|
+
"OrganizationProfile",
|
|
915
|
+
"OrganizationList",
|
|
916
|
+
"CreateOrganization",
|
|
917
|
+
"SignIn",
|
|
918
|
+
"SignUp",
|
|
919
|
+
"Waitlist",
|
|
920
|
+
"GoogleOneTap"
|
|
921
|
+
]);
|
|
922
|
+
var CLERK_PREAMBLE = [
|
|
923
|
+
"// Auto-generated by @onlook/storybook-plugin (package mock). Zero-backend,",
|
|
924
|
+
"// signed-in Clerk stand-in so components that call useUser()/useAuth() render",
|
|
925
|
+
"// authenticated content in the canvas without a publishable key, clerk-js, or",
|
|
926
|
+
"// a network round-trip. Swap back to the real @clerk/* package for live data.",
|
|
927
|
+
"import { createElement, Fragment } from 'react';",
|
|
928
|
+
"const __asyncNoop = async () => {};",
|
|
929
|
+
"const __noop = () => {};",
|
|
930
|
+
// No `: any` param annotation: the virtual module is served extensionless
|
|
931
|
+
// (see header) so Vite parses it as PLAIN JS — a TS type annotation here is a
|
|
932
|
+
// runtime `Unexpected token ':'` that breaks every story importing the package.
|
|
933
|
+
"const __pass = (props) => createElement(Fragment, null, props ? props.children : undefined);",
|
|
934
|
+
"const __null = () => null;",
|
|
935
|
+
"const __sessionId = 'sess_onlookMock';",
|
|
936
|
+
"// A plausible signed-in Clerk user. Fields cover the common UserResource",
|
|
937
|
+
"// surface components read at render; no image URL (avoids a network fetch).",
|
|
938
|
+
"const __user = {",
|
|
939
|
+
" id: 'user_onlookMock',",
|
|
940
|
+
" firstName: 'Ada',",
|
|
941
|
+
" lastName: 'Lovelace',",
|
|
942
|
+
" fullName: 'Ada Lovelace',",
|
|
943
|
+
" username: 'ada',",
|
|
944
|
+
" imageUrl: '',",
|
|
945
|
+
" hasImage: false,",
|
|
946
|
+
" primaryEmailAddressId: 'idn_onlookMock',",
|
|
947
|
+
" primaryEmailAddress: { id: 'idn_onlookMock', emailAddress: 'ada@example.com' },",
|
|
948
|
+
" emailAddresses: [{ id: 'idn_onlookMock', emailAddress: 'ada@example.com' }],",
|
|
949
|
+
" primaryPhoneNumber: null,",
|
|
950
|
+
" phoneNumbers: [],",
|
|
951
|
+
" externalAccounts: [],",
|
|
952
|
+
" organizationMemberships: [],",
|
|
953
|
+
" publicMetadata: {},",
|
|
954
|
+
" unsafeMetadata: {},",
|
|
955
|
+
" reload: __asyncNoop,",
|
|
956
|
+
" update: __asyncNoop,",
|
|
957
|
+
"};",
|
|
958
|
+
"const __clerk = {",
|
|
959
|
+
" loaded: true,",
|
|
960
|
+
" user: __user,",
|
|
961
|
+
" session: { id: __sessionId, status: 'active', user: __user },",
|
|
962
|
+
" organization: null,",
|
|
963
|
+
" openSignIn: __noop,",
|
|
964
|
+
" openSignUp: __noop,",
|
|
965
|
+
" openUserProfile: __noop,",
|
|
966
|
+
" openOrganizationProfile: __noop,",
|
|
967
|
+
" closeSignIn: __noop,",
|
|
968
|
+
" closeSignUp: __noop,",
|
|
969
|
+
" signOut: __asyncNoop,",
|
|
970
|
+
" setActive: __asyncNoop,",
|
|
971
|
+
"};"
|
|
972
|
+
];
|
|
973
|
+
function clerkExportLine(name) {
|
|
974
|
+
if (name in CLERK_KNOWN_HOOKS) {
|
|
975
|
+
return `export const ${name} = () => ${CLERK_KNOWN_HOOKS[name]};`;
|
|
976
|
+
}
|
|
977
|
+
if (CLERK_CHILDREN_COMPONENTS.has(name)) {
|
|
978
|
+
return `export const ${name} = __pass;`;
|
|
979
|
+
}
|
|
980
|
+
if (CLERK_NULL_COMPONENTS.has(name)) {
|
|
981
|
+
return `export const ${name} = __null;`;
|
|
982
|
+
}
|
|
983
|
+
if (/^use[A-Z]/.test(name)) {
|
|
984
|
+
return `export const ${name} = () => ({ isLoaded: true, isSignedIn: true });`;
|
|
985
|
+
}
|
|
986
|
+
if (/^[A-Z]/.test(name)) {
|
|
987
|
+
return `export const ${name} = __pass;`;
|
|
988
|
+
}
|
|
989
|
+
return `export const ${name} = undefined;`;
|
|
990
|
+
}
|
|
991
|
+
function buildClerkMockSource(usedExports) {
|
|
992
|
+
const names = Array.from(
|
|
993
|
+
new Set(
|
|
994
|
+
usedExports.filter(
|
|
995
|
+
(n) => VALID_IDENT_RE2.test(n) && n !== "default" && !RESERVED_HELPER_NAMES.has(n)
|
|
996
|
+
)
|
|
997
|
+
)
|
|
998
|
+
).sort();
|
|
999
|
+
const lines = [
|
|
1000
|
+
...CLERK_PREAMBLE,
|
|
1001
|
+
"",
|
|
1002
|
+
...names.map(clerkExportLine),
|
|
1003
|
+
"",
|
|
1004
|
+
"// Rarely used, but `import Clerk from ...` must not fail: an inert object.",
|
|
1005
|
+
"export default {};",
|
|
1006
|
+
""
|
|
1007
|
+
];
|
|
1008
|
+
return lines.join("\n");
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// src/package-mock/package-mock.ts
|
|
1012
|
+
var PACKAGE_MOCK_PLUGIN_NAME = "onlook-package-mock";
|
|
1013
|
+
var PACKAGE_MOCK_VIRTUAL_PREFIX = "\0onlook-package-mock:";
|
|
1014
|
+
function stripQuery2(id) {
|
|
1015
|
+
const q = id.indexOf("?");
|
|
1016
|
+
return q === -1 ? id : id.slice(0, q);
|
|
1017
|
+
}
|
|
1018
|
+
function packageMockPlugin(options) {
|
|
1019
|
+
const entries = (options?.packages ?? []).filter(
|
|
1020
|
+
(e) => e && typeof e.package === "string" && e.package.length > 0 && // Only known auth packages get a functional mock — an unknown package
|
|
1021
|
+
// has no source builder, so silently drop it (honest skip) rather than
|
|
1022
|
+
// intercept it into a broken module.
|
|
1023
|
+
isKnownMockPackage(e.package)
|
|
1024
|
+
);
|
|
1025
|
+
if (entries.length === 0) return null;
|
|
1026
|
+
const usedByPackage = /* @__PURE__ */ new Map();
|
|
1027
|
+
for (const e of entries) usedByPackage.set(e.package, e.usedExports ?? []);
|
|
1028
|
+
return {
|
|
1029
|
+
name: PACKAGE_MOCK_PLUGIN_NAME,
|
|
1030
|
+
// `pre` so we intercept the specifier before Vite's resolve pipeline (and
|
|
1031
|
+
// before tsconfig-paths / node resolution) claims it.
|
|
1032
|
+
enforce: "pre",
|
|
1033
|
+
resolveId(source) {
|
|
1034
|
+
if (source.startsWith("\0")) return null;
|
|
1035
|
+
const cleaned = stripQuery2(source);
|
|
1036
|
+
if (!usedByPackage.has(cleaned)) return null;
|
|
1037
|
+
return PACKAGE_MOCK_VIRTUAL_PREFIX + cleaned;
|
|
1038
|
+
},
|
|
1039
|
+
load(id) {
|
|
1040
|
+
if (!id.startsWith(PACKAGE_MOCK_VIRTUAL_PREFIX)) return null;
|
|
1041
|
+
const pkg = id.slice(PACKAGE_MOCK_VIRTUAL_PREFIX.length);
|
|
1042
|
+
const used = usedByPackage.get(pkg);
|
|
1043
|
+
if (used === void 0) return null;
|
|
1044
|
+
return buildPackageMockSource(pkg, used);
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
|
|
856
1049
|
// src/screenshot-service/utils/console-logs/console-logs.ts
|
|
857
1050
|
async function captureConsoleLogs(storyId, theme = "light", storybookUrl = "http://localhost:6006", timeoutMs = 3e4) {
|
|
858
1051
|
const browser = await getBrowser();
|
|
@@ -1665,10 +1858,12 @@ function storybookOnlookPlugin(options = {}) {
|
|
|
1665
1858
|
handleHotUpdate: handleStoryFileChange
|
|
1666
1859
|
};
|
|
1667
1860
|
const envContainment = envContainmentPlugin(options.envContainment);
|
|
1861
|
+
const packageMock = packageMockPlugin(options.packageMock);
|
|
1668
1862
|
const moduleLoadCatchAll = options.moduleLoadCatchAll === false ? null : moduleLoadCatchAllPlugin();
|
|
1669
1863
|
return withDedupeApply(
|
|
1670
1864
|
[
|
|
1671
1865
|
...envContainment ? [envContainment] : [],
|
|
1866
|
+
...packageMock ? [packageMock] : [],
|
|
1672
1867
|
...moduleLoadCatchAll ? [moduleLoadCatchAll] : [],
|
|
1673
1868
|
componentLocPlugin(),
|
|
1674
1869
|
mainPlugin,
|
|
@@ -1749,6 +1944,7 @@ var OPTION_KEY_MAP = {
|
|
|
1749
1944
|
storyGlobs: true,
|
|
1750
1945
|
tailwindEntryCss: true,
|
|
1751
1946
|
envContainment: true,
|
|
1947
|
+
packageMock: true,
|
|
1752
1948
|
moduleLoadCatchAll: true,
|
|
1753
1949
|
resolveAliases: true
|
|
1754
1950
|
};
|
package/dist/{storybook-onlook-plugin-B9Eo_OIq.d.ts → storybook-onlook-plugin-J4qj72mN.d.ts}
RENAMED
|
@@ -42,6 +42,28 @@ type EnvContainmentOptions = {
|
|
|
42
42
|
*/
|
|
43
43
|
declare function envContainmentPlugin(options: EnvContainmentOptions | undefined): Plugin | null;
|
|
44
44
|
|
|
45
|
+
/** One package to replace with a functional zero-backend mock. */
|
|
46
|
+
interface PackageMockEntry {
|
|
47
|
+
/** Bare npm specifier to intercept, e.g. `@clerk/nextjs`. */
|
|
48
|
+
package: string;
|
|
49
|
+
/**
|
|
50
|
+
* Named exports the customer actually imports from the package (the union
|
|
51
|
+
* across story-reachable component sources). The generated mock provides a
|
|
52
|
+
* stand-in for each so no `import { X } from '@clerk/nextjs'` produces a
|
|
53
|
+
* Vite "no matching export" build error. Optional on the wire — the plugin
|
|
54
|
+
* treats an absent list as empty (a customer-edited config may omit it).
|
|
55
|
+
*/
|
|
56
|
+
usedExports?: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The `packageMock` plugin-options surface. Written by the preflight engine
|
|
60
|
+
* into `.storybook/main.*` (`storybookOnlookPlugin({ packageMock })`) and read
|
|
61
|
+
* by the plugin's package-mock Vite plugin factory.
|
|
62
|
+
*/
|
|
63
|
+
interface PackageMockOptions {
|
|
64
|
+
packages?: PackageMockEntry[];
|
|
65
|
+
}
|
|
66
|
+
|
|
45
67
|
type OnlookPluginOptions = {
|
|
46
68
|
/** Storybook port (default: 6006) */
|
|
47
69
|
port?: number;
|
|
@@ -54,6 +76,7 @@ type OnlookPluginOptions = {
|
|
|
54
76
|
storyGlobs?: string[];
|
|
55
77
|
tailwindEntryCss?: string | false;
|
|
56
78
|
envContainment?: EnvContainmentOptions;
|
|
79
|
+
packageMock?: PackageMockOptions;
|
|
57
80
|
moduleLoadCatchAll?: boolean;
|
|
58
81
|
resolveAliases?: boolean;
|
|
59
82
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlook/storybook-plugin",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"onlook-storybook": "./dist/cli/index.js"
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"storybook": "^10.1.11"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@onbook/
|
|
55
|
+
"@onbook/shared": "0.1.0",
|
|
56
|
+
"@onbook/tsconfig": "0.1.0",
|
|
56
57
|
"@types/babel__generator": "^7.6.8",
|
|
57
58
|
"@types/babel__traverse": "^7.20.6",
|
|
58
59
|
"@types/node": "^22.15.32",
|