@happyvertical/smrt-playground 0.37.2 → 0.37.4

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,130 @@
1
+ import { t as coercePlaygroundModules } from "./runtime-85Dv9ms7.js";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import { dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
5
+ import { pathToFileURL } from "node:url";
6
+ import fg from "fast-glob";
7
+ //#region src/discovery.ts
8
+ var require = createRequire(import.meta.url);
9
+ var TS_SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
10
+ ".ts",
11
+ ".tsx",
12
+ ".mts",
13
+ ".cts"
14
+ ]);
15
+ function findWorkspaceRoot(startDir = process.cwd()) {
16
+ let current = resolve(startDir);
17
+ while (true) {
18
+ if (existsSync(join(current, "pnpm-workspace.yaml"))) return current;
19
+ const parent = dirname(current);
20
+ if (parent === current) return null;
21
+ current = parent;
22
+ }
23
+ }
24
+ function findSmrtWorkspaceRoot(startDir = process.cwd()) {
25
+ const workspaceRoot = findWorkspaceRoot(startDir);
26
+ if (!workspaceRoot) return null;
27
+ return existsSync(join(workspaceRoot, "packages", "smrt-playground", "host", "package.json")) ? workspaceRoot : null;
28
+ }
29
+ function detectPlaygroundMode(projectRoot = process.cwd()) {
30
+ return findSmrtWorkspaceRoot(projectRoot) ? "workspace" : "consumer";
31
+ }
32
+ function readJson(path) {
33
+ return JSON.parse(readFileSync(path, "utf-8"));
34
+ }
35
+ function resolveNodeModulePackageDir(projectRoot, packageName) {
36
+ const packageJsonPath = join(projectRoot, "node_modules", packageName, "package.json");
37
+ return existsSync(packageJsonPath) ? dirname(packageJsonPath) : null;
38
+ }
39
+ async function discoverWorkspacePlaygrounds(workspaceRoot, packagesPattern = "packages/*/src/svelte/playground.ts") {
40
+ const matches = await fg(packagesPattern, {
41
+ cwd: workspaceRoot,
42
+ absolute: true
43
+ });
44
+ const discovered = [];
45
+ for (const sourcePath of matches.sort()) {
46
+ const packageDir = dirname(dirname(dirname(sourcePath)));
47
+ const packageJsonPath = join(packageDir, "package.json");
48
+ if (!existsSync(packageJsonPath)) continue;
49
+ const packageJson = readJson(packageJsonPath);
50
+ const runtimePath = join(packageDir, "dist", "playground.js");
51
+ discovered.push({
52
+ packageName: packageJson.name,
53
+ packageDir,
54
+ sourcePath,
55
+ runtimePath: existsSync(runtimePath) ? runtimePath : null
56
+ });
57
+ }
58
+ return discovered;
59
+ }
60
+ async function discoverInstalledPlaygrounds(projectRoot = process.cwd()) {
61
+ const packageJsonPath = join(projectRoot, "package.json");
62
+ if (!existsSync(packageJsonPath)) return [];
63
+ const packageJson = readJson(packageJsonPath);
64
+ const dependencies = {
65
+ ...packageJson.dependencies,
66
+ ...packageJson.devDependencies,
67
+ ...packageJson.peerDependencies
68
+ };
69
+ const discovered = [];
70
+ for (const dependencyName of Object.keys(dependencies).sort()) {
71
+ if (!dependencyName.startsWith("@happyvertical/smrt-") || dependencyName === "@happyvertical/smrt-playground") continue;
72
+ const packageDir = resolveNodeModulePackageDir(projectRoot, dependencyName);
73
+ if (!packageDir) continue;
74
+ if (readJson(join(packageDir, "package.json")).exports?.["./playground"]) discovered.push({
75
+ packageName: dependencyName,
76
+ importSpecifier: `${dependencyName}/playground`
77
+ });
78
+ }
79
+ return discovered;
80
+ }
81
+ async function discoverPlaygroundTargets(projectRoot = process.cwd(), mode = "auto", localPlaygroundPath = "src/playground.ts") {
82
+ if ((mode === "auto" ? detectPlaygroundMode(projectRoot) : mode) === "workspace") {
83
+ const workspaceRoot = mode === "workspace" ? findWorkspaceRoot(projectRoot) : findSmrtWorkspaceRoot(projectRoot);
84
+ if (!workspaceRoot) return [];
85
+ return (await discoverWorkspacePlaygrounds(workspaceRoot)).map((item) => ({
86
+ packageName: item.packageName,
87
+ source: "workspace",
88
+ sourcePath: item.sourcePath,
89
+ runtimePath: item.runtimePath ?? void 0
90
+ }));
91
+ }
92
+ const targets = [];
93
+ const installed = await discoverInstalledPlaygrounds(projectRoot);
94
+ for (const item of installed) targets.push({
95
+ packageName: item.packageName,
96
+ source: "package",
97
+ importSpecifier: item.importSpecifier
98
+ });
99
+ const localPath = resolve(projectRoot, localPlaygroundPath);
100
+ if (existsSync(localPath)) targets.push({
101
+ source: "app",
102
+ sourcePath: localPath
103
+ });
104
+ return targets;
105
+ }
106
+ async function importPlaygroundModule(input) {
107
+ const imported = isAbsolute(input) || input.startsWith(".") ? await importPathModule(resolve(input)) : await import(input);
108
+ const module = imported.default ?? imported.playground ?? imported;
109
+ return module && typeof module === "object" ? coercePlaygroundModules(module) : [];
110
+ }
111
+ async function importPathModule(inputPath) {
112
+ if (!TS_SOURCE_EXTENSIONS.has(extname(inputPath))) return import(pathToFileURL(inputPath).href);
113
+ let tsxApiPath;
114
+ try {
115
+ tsxApiPath = require.resolve("tsx/esm/api");
116
+ } catch (tsxError) {
117
+ throw new Error(`Failed to load playground module from ${inputPath}: source playground discovery requires the "tsx" package.`, { cause: tsxError });
118
+ }
119
+ const { tsImport } = await import(pathToFileURL(tsxApiPath).href);
120
+ return tsImport(pathToFileURL(inputPath).href, { parentURL: import.meta.url });
121
+ }
122
+ function describePlaygroundSource(target, cwd = process.cwd()) {
123
+ if (target.source === "package") return target.importSpecifier || target.packageName || "installed package";
124
+ const path = target.sourcePath || target.runtimePath;
125
+ return path ? relative(cwd, path) || "." : target.source;
126
+ }
127
+ //#endregion
128
+ export { discoverWorkspacePlaygrounds as a, importPlaygroundModule as c, discoverPlaygroundTargets as i, detectPlaygroundMode as n, findSmrtWorkspaceRoot as o, discoverInstalledPlaygrounds as r, findWorkspaceRoot as s, describePlaygroundSource as t };
129
+
130
+ //# sourceMappingURL=discovery-ZfRkQSmn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery-ZfRkQSmn.js","names":[],"sources":["../../src/discovery.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport {\n dirname,\n extname,\n isAbsolute,\n join,\n relative,\n resolve,\n} from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport fg from 'fast-glob';\nimport { coercePlaygroundModules } from './runtime.js';\nimport type {\n DiscoveredInstalledPlayground,\n DiscoveredPlaygroundTarget,\n DiscoveredWorkspacePlayground,\n SmrtPlaygroundModule,\n} from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst TS_SOURCE_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);\n\nexport function findWorkspaceRoot(startDir = process.cwd()): string | null {\n let current = resolve(startDir);\n\n while (true) {\n if (existsSync(join(current, 'pnpm-workspace.yaml'))) {\n return current;\n }\n\n const parent = dirname(current);\n if (parent === current) {\n return null;\n }\n current = parent;\n }\n}\n\nexport function findSmrtWorkspaceRoot(startDir = process.cwd()): string | null {\n const workspaceRoot = findWorkspaceRoot(startDir);\n if (!workspaceRoot) {\n return null;\n }\n\n const hostPackageJsonPath = join(\n workspaceRoot,\n 'packages',\n 'smrt-playground',\n 'host',\n 'package.json',\n );\n\n return existsSync(hostPackageJsonPath) ? workspaceRoot : null;\n}\n\nexport function detectPlaygroundMode(\n projectRoot = process.cwd(),\n): 'workspace' | 'consumer' {\n return findSmrtWorkspaceRoot(projectRoot) ? 'workspace' : 'consumer';\n}\n\nfunction readJson(path: string): any {\n return JSON.parse(readFileSync(path, 'utf-8'));\n}\n\nfunction resolveNodeModulePackageDir(\n projectRoot: string,\n packageName: string,\n): string | null {\n const packageJsonPath = join(\n projectRoot,\n 'node_modules',\n packageName,\n 'package.json',\n );\n return existsSync(packageJsonPath) ? dirname(packageJsonPath) : null;\n}\n\nexport async function discoverWorkspacePlaygrounds(\n workspaceRoot: string,\n packagesPattern = 'packages/*/src/svelte/playground.ts',\n): Promise<DiscoveredWorkspacePlayground[]> {\n const matches = await fg(packagesPattern, {\n cwd: workspaceRoot,\n absolute: true,\n });\n\n const discovered: DiscoveredWorkspacePlayground[] = [];\n\n for (const sourcePath of matches.sort()) {\n const packageDir = dirname(dirname(dirname(sourcePath)));\n const packageJsonPath = join(packageDir, 'package.json');\n\n if (!existsSync(packageJsonPath)) {\n continue;\n }\n\n const packageJson = readJson(packageJsonPath);\n const runtimePath = join(packageDir, 'dist', 'playground.js');\n\n discovered.push({\n packageName: packageJson.name,\n packageDir,\n sourcePath,\n runtimePath: existsSync(runtimePath) ? runtimePath : null,\n });\n }\n\n return discovered;\n}\n\nexport async function discoverInstalledPlaygrounds(\n projectRoot = process.cwd(),\n): Promise<DiscoveredInstalledPlayground[]> {\n const packageJsonPath = join(projectRoot, 'package.json');\n if (!existsSync(packageJsonPath)) {\n return [];\n }\n\n const packageJson = readJson(packageJsonPath);\n const dependencies = {\n ...packageJson.dependencies,\n ...packageJson.devDependencies,\n ...packageJson.peerDependencies,\n };\n\n const discovered: DiscoveredInstalledPlayground[] = [];\n\n for (const dependencyName of Object.keys(dependencies).sort()) {\n if (\n !dependencyName.startsWith('@happyvertical/smrt-') ||\n dependencyName === '@happyvertical/smrt-playground'\n ) {\n continue;\n }\n\n const packageDir = resolveNodeModulePackageDir(projectRoot, dependencyName);\n if (!packageDir) {\n continue;\n }\n\n const dependencyPackageJson = readJson(join(packageDir, 'package.json'));\n if (dependencyPackageJson.exports?.['./playground']) {\n discovered.push({\n packageName: dependencyName,\n importSpecifier: `${dependencyName}/playground`,\n });\n }\n }\n\n return discovered;\n}\n\nexport async function discoverPlaygroundTargets(\n projectRoot = process.cwd(),\n mode: 'auto' | 'workspace' | 'consumer' = 'auto',\n localPlaygroundPath = 'src/playground.ts',\n): Promise<DiscoveredPlaygroundTarget[]> {\n const effectiveMode =\n mode === 'auto' ? detectPlaygroundMode(projectRoot) : mode;\n\n if (effectiveMode === 'workspace') {\n const workspaceRoot =\n mode === 'workspace'\n ? findWorkspaceRoot(projectRoot)\n : findSmrtWorkspaceRoot(projectRoot);\n if (!workspaceRoot) {\n return [];\n }\n\n const packages = await discoverWorkspacePlaygrounds(workspaceRoot);\n return packages.map((item) => ({\n packageName: item.packageName,\n source: 'workspace' as const,\n sourcePath: item.sourcePath,\n runtimePath: item.runtimePath ?? undefined,\n }));\n }\n\n const targets: DiscoveredPlaygroundTarget[] = [];\n const installed = await discoverInstalledPlaygrounds(projectRoot);\n\n for (const item of installed) {\n targets.push({\n packageName: item.packageName,\n source: 'package',\n importSpecifier: item.importSpecifier,\n });\n }\n\n const localPath = resolve(projectRoot, localPlaygroundPath);\n if (existsSync(localPath)) {\n targets.push({\n source: 'app',\n sourcePath: localPath,\n });\n }\n\n return targets;\n}\n\nexport async function importPlaygroundModule(\n input: string,\n): Promise<SmrtPlaygroundModule[]> {\n const imported =\n isAbsolute(input) || input.startsWith('.')\n ? await importPathModule(resolve(input))\n : await import(input);\n\n const module = imported.default ?? imported.playground ?? imported;\n return module && typeof module === 'object'\n ? coercePlaygroundModules(module as SmrtPlaygroundModule)\n : [];\n}\n\nasync function importPathModule(inputPath: string): Promise<unknown> {\n if (!TS_SOURCE_EXTENSIONS.has(extname(inputPath))) {\n return import(pathToFileURL(inputPath).href);\n }\n\n let tsxApiPath: string;\n try {\n tsxApiPath = require.resolve('tsx/esm/api');\n } catch (tsxError) {\n throw new Error(\n `Failed to load playground module from ${inputPath}: source playground discovery requires the \"tsx\" package.`,\n { cause: tsxError },\n );\n }\n\n const { tsImport } = await import(pathToFileURL(tsxApiPath).href);\n return tsImport(pathToFileURL(inputPath).href, {\n parentURL: import.meta.url,\n });\n}\n\nexport function describePlaygroundSource(\n target: DiscoveredPlaygroundTarget,\n cwd = process.cwd(),\n): string {\n if (target.source === 'package') {\n return target.importSpecifier || target.packageName || 'installed package';\n }\n\n const path = target.sourcePath || target.runtimePath;\n return path ? relative(cwd, path) || '.' : target.source;\n}\n"],"mappings":";;;;;;;AAoBA,IAAM,UAAU,cAAc,OAAA,KAAY,GAAG;AAC7C,IAAM,uCAAuB,IAAI,IAAI;CAAC;CAAO;CAAQ;CAAQ;AAAM,CAAC;AAE7D,SAAS,kBAAkB,WA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,KAAK;EACX,QAAQ;EACR,YAAY;CACd,CAAC;CAGH,OAAO;AACT;AAEA,eAAsB,uBACpB,OACiC;CACjC,MAAM,WACJ,WAAW,KAAK,KAAK,MAAM,WAAW,GAAG,IACrC,MAAM,iBAAiB,QAAQ,KAAK,CAAC,IACrC,MAAM,OAAO;CAEnB,MAAM,SAAS,SAAS,WAAW,SAAS,cAAc;CAC1D,OAAO,UAAU,OAAO,WAAW,WAC/B,wBAAwB,MAA8B,IACtD,CAAC;AACP;AAEA,eAAe,iBAAiB,WAAqC;CACnE,IAAI,CAAC,qBAAqB,IAAI,QAAQ,SAAS,CAAC,GAC9C,OAAO,OAAO,cAAc,SAAS,CAAA,CAAE;CAGzC,IAAI;CACJ,IAAI;EACF,aAAa,QAAQ,QAAQ,aAAa;CAC5C,SAAS,UAAU;EACjB,MAAM,IAAI,MACR,yCAAyC,UAAS,4DAClD,EAAE,OAAO,SAAS,CACpB;CACF;CAEA,MAAM,EAAE,aAAa,MAAM,OAAO,cAAc,UAAU,CAAA,CAAE;CAC5D,OAAO,SAAS,cAAc,SAAS,CAAA,CAAE,MAAM,EAC7C,WAAW,OAAA,KAAY,IACzB,CAAC;AACH;AAEO,SAAS,yBACd,QACA,MAAM,QAAQ,IAAI,GACV;CACR,IAAI,OAAO,WAAW,WACpB,OAAO,OAAO,mBAAmB,OAAO,eAAe;CAGzD,MAAM,OAAO,OAAO,cAAc,OAAO;CACzC,OAAO,OAAO,SAAS,KAAK,IAAI,KAAK,MAAM,OAAO;AACpD"}
@@ -0,0 +1,91 @@
1
+ //#region src/utils.ts
2
+ function titleCase(value) {
3
+ return value.split(/[-_/]/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join(" ");
4
+ }
5
+ function displayNameForSmrtPackage(packageName) {
6
+ return titleCase(packageName.replace(/^@happyvertical\/smrt-/, ""));
7
+ }
8
+ function displayNameForScopedPackage(packageName) {
9
+ return titleCase(packageName.replace(/^@/, "").replace(/\//g, " "));
10
+ }
11
+ //#endregion
12
+ //#region src/runtime.ts
13
+ function normalizeModeConfig(value) {
14
+ if (!value) return;
15
+ return value === true ? {} : value;
16
+ }
17
+ function qualifyPlaygroundEntryId(packageName, entryId) {
18
+ return `${packageName}:${entryId}`;
19
+ }
20
+ function coercePlaygroundModules(input) {
21
+ if (!input) return [];
22
+ if (Array.isArray(input)) return input.filter(Boolean);
23
+ if ("modules" in input && Array.isArray(input.modules)) return input.modules.filter(Boolean);
24
+ return [input];
25
+ }
26
+ function normalizePlaygroundModule(module) {
27
+ const displayName = module.displayName || module.moduleMeta?.displayName || displayNameForSmrtPackage(module.packageName);
28
+ const entries = [...module.entries || []].map((entry) => {
29
+ const modes = {
30
+ mock: normalizeModeConfig(entry.modes?.mock),
31
+ live: normalizeModeConfig(entry.modes?.live)
32
+ };
33
+ const availableModes = ["mock", "live"].filter((mode) => Boolean(modes[mode]));
34
+ if (availableModes.length === 0) {
35
+ modes.mock = {};
36
+ availableModes.push("mock");
37
+ }
38
+ return {
39
+ ...entry,
40
+ displayName,
41
+ packageName: module.packageName,
42
+ qualifiedId: qualifyPlaygroundEntryId(module.packageName, entry.id),
43
+ availableModes,
44
+ modes
45
+ };
46
+ }).sort((left, right) => {
47
+ const orderDiff = (left.order ?? 999) - (right.order ?? 999);
48
+ return orderDiff !== 0 ? orderDiff : left.title.localeCompare(right.title);
49
+ });
50
+ return {
51
+ ...module,
52
+ displayName,
53
+ entries
54
+ };
55
+ }
56
+ function mergePlaygroundModules(modules) {
57
+ const mergedByPackage = /* @__PURE__ */ new Map();
58
+ for (const inputModule of modules) {
59
+ const module = normalizePlaygroundModule(inputModule);
60
+ const existing = mergedByPackage.get(module.packageName);
61
+ if (!existing) {
62
+ mergedByPackage.set(module.packageName, {
63
+ module: {
64
+ ...module,
65
+ entries: []
66
+ },
67
+ entries: new Map(module.entries.map((entry) => [entry.qualifiedId, entry]))
68
+ });
69
+ continue;
70
+ }
71
+ existing.module = {
72
+ ...existing.module,
73
+ ...module,
74
+ entries: [],
75
+ displayName: module.displayName || existing.module.displayName,
76
+ moduleMeta: module.moduleMeta || existing.module.moduleMeta
77
+ };
78
+ for (const entry of module.entries) existing.entries.set(entry.qualifiedId, entry);
79
+ }
80
+ return [...mergedByPackage.values()].map(({ module, entries }) => ({
81
+ ...module,
82
+ entries: [...entries.values()].sort((left, right) => {
83
+ const orderDiff = (left.order ?? 999) - (right.order ?? 999);
84
+ return orderDiff !== 0 ? orderDiff : left.title.localeCompare(right.title);
85
+ })
86
+ })).sort((left, right) => left.displayName.localeCompare(right.displayName));
87
+ }
88
+ //#endregion
89
+ export { displayNameForScopedPackage as a, qualifyPlaygroundEntryId as i, mergePlaygroundModules as n, displayNameForSmrtPackage as o, normalizePlaygroundModule as r, coercePlaygroundModules as t };
90
+
91
+ //# sourceMappingURL=runtime-85Dv9ms7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-85Dv9ms7.js","names":[],"sources":["../../src/utils.ts","../../src/runtime.ts"],"sourcesContent":["export function titleCase(value: string): string {\n return value\n .split(/[-_/]/)\n .filter(Boolean)\n .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))\n .join(' ');\n}\n\nexport function displayNameForSmrtPackage(packageName: string): string {\n return titleCase(packageName.replace(/^@happyvertical\\/smrt-/, ''));\n}\n\nexport function displayNameForScopedPackage(packageName: string): string {\n return titleCase(packageName.replace(/^@/, '').replace(/\\//g, ' '));\n}\n","import type {\n ResolvedSmrtPlaygroundEntry,\n ResolvedSmrtPlaygroundModule,\n SmrtPlaygroundMode,\n SmrtPlaygroundModeConfig,\n SmrtPlaygroundModule,\n SmrtPlaygroundModuleExport,\n} from './types.js';\nimport { displayNameForSmrtPackage } from './utils.js';\n\nfunction normalizeModeConfig(\n value: SmrtPlaygroundModeConfig | true | undefined,\n): SmrtPlaygroundModeConfig | undefined {\n if (!value) {\n return undefined;\n }\n return value === true ? {} : value;\n}\n\nexport function qualifyPlaygroundEntryId(\n packageName: string,\n entryId: string,\n): string {\n return `${packageName}:${entryId}`;\n}\n\nexport function coercePlaygroundModules(\n input: SmrtPlaygroundModuleExport | null | undefined,\n): SmrtPlaygroundModule[] {\n if (!input) {\n return [];\n }\n\n if (Array.isArray(input)) {\n return input.filter(Boolean);\n }\n\n if ('modules' in input && Array.isArray(input.modules)) {\n return input.modules.filter(Boolean);\n }\n\n return [input as SmrtPlaygroundModule];\n}\n\nexport function normalizePlaygroundModule(\n module: SmrtPlaygroundModule,\n): ResolvedSmrtPlaygroundModule {\n const displayName =\n module.displayName ||\n module.moduleMeta?.displayName ||\n displayNameForSmrtPackage(module.packageName);\n\n const entries: ResolvedSmrtPlaygroundEntry[] = [...(module.entries || [])]\n .map((entry) => {\n const modes = {\n mock: normalizeModeConfig(entry.modes?.mock),\n live: normalizeModeConfig(entry.modes?.live),\n };\n const availableModes = (['mock', 'live'] as SmrtPlaygroundMode[]).filter(\n (mode) => Boolean(modes[mode]),\n );\n\n if (availableModes.length === 0) {\n modes.mock = {};\n availableModes.push('mock');\n }\n\n return {\n ...entry,\n displayName,\n packageName: module.packageName,\n qualifiedId: qualifyPlaygroundEntryId(module.packageName, entry.id),\n availableModes,\n modes,\n };\n })\n .sort((left, right) => {\n const orderDiff = (left.order ?? 999) - (right.order ?? 999);\n return orderDiff !== 0\n ? orderDiff\n : left.title.localeCompare(right.title);\n });\n\n return {\n ...module,\n displayName,\n entries,\n };\n}\n\nexport function mergePlaygroundModules(\n modules: SmrtPlaygroundModule[],\n): ResolvedSmrtPlaygroundModule[] {\n // Later modules intentionally override earlier ones so app-local entries can\n // replace installed package previews by packageName + entry id.\n const mergedByPackage = new Map<\n string,\n {\n module: ResolvedSmrtPlaygroundModule;\n entries: Map<string, ResolvedSmrtPlaygroundEntry>;\n }\n >();\n\n for (const inputModule of modules) {\n const module = normalizePlaygroundModule(inputModule);\n const existing = mergedByPackage.get(module.packageName);\n\n if (!existing) {\n mergedByPackage.set(module.packageName, {\n module: { ...module, entries: [] },\n entries: new Map(\n module.entries.map((entry) => [entry.qualifiedId, entry]),\n ),\n });\n continue;\n }\n\n existing.module = {\n ...existing.module,\n ...module,\n entries: [],\n displayName: module.displayName || existing.module.displayName,\n moduleMeta: module.moduleMeta || existing.module.moduleMeta,\n };\n\n for (const entry of module.entries) {\n existing.entries.set(entry.qualifiedId, entry);\n }\n }\n\n return [...mergedByPackage.values()]\n .map(({ module, entries }) => ({\n ...module,\n entries: [...entries.values()].sort((left, right) => {\n const orderDiff = (left.order ?? 999) - (right.order ?? 999);\n return orderDiff !== 0\n ? orderDiff\n : left.title.localeCompare(right.title);\n }),\n }))\n .sort((left, right) => left.displayName.localeCompare(right.displayName));\n}\n"],"mappings":";AAAO,SAAS,UAAU,OAAuB;CAC/C,OAAO,MACJ,MAAM,OAAO,CAAA,CACb,OAAO,OAAO,CAAA,CACd,KAAK,YAAY,QAAQ,OAAO,CAAC,CAAA,CAAE,YAAY,IAAI,QAAQ,MAAM,CAAC,CAAC,CAAA,CACnE,KAAK,GAAG;AACb;AAEO,SAAS,0BAA0B,aAA6B;CACrE,OAAO,UAAU,YAAY,QAAQ,0BAA0B,EAAE,CAAC;AACpE;AAEO,SAAS,4BAA4B,aAA6B;CACvE,OAAO,UAAU,YAAY,QAAQ,MAAM,EAAE,CAAA,CAAE,QAAQ,OAAO,GAAG,CAAC;AACpE;;;ACJA,SAAS,oBACP,OACsC;CACtC,IAAI,CAAC,OACH;CAEF,OAAO,UAAU,OAAO,CAAC,IAAI;AAC/B;AAEO,SAAS,yBACd,aACA,SACQ;CACR,OAAO,GAAG,YAAW,GAAI;AAC3B;AAEO,SAAS,wBACd,OACwB;CACxB,IAAI,CAAC,OACH,OAAO,CAAC;CAGV,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,OAAO,OAAO;CAG7B,IAAI,aAAa,SAAS,MAAM,QAAQ,MAAM,OAAO,GACnD,OAAO,MAAM,QAAQ,OAAO,OAAO;CAGrC,OAAO,CAAC,KAA6B;AACvC;AAEO,SAAS,0B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,YAAY,OAAO,cAAc,SAAS,OAAO;EACnD;EAEA,KAAA,MAAW,SAAS,OAAO,SACzB,SAAS,QAAQ,IAAI,MAAM,aAAa,KAAK;CAEjD;CAEA,OAAO,CAAC,GAAG,gBAAgB,OAAO,CAAC,CAAA,CAChC,KAAK,EAAE,QAAQ,eAAe;EAC7B,GAAG;EACH,SAAS,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAA,CAAE,MAAM,MAAM,UAAU;GACnD,MAAM,aAAa,KAAK,SAAS,QAAQ,MAAM,SAAS;GACxD,OAAO,cAAc,IACjB,YACA,KAAK,MAAM,cAAc,MAAM,KAAK;EAC1C,CAAC;CACH,EAAE,CAAA,CACD,MAAM,MAAM,UAAU,KAAK,YAAY,cAAc,MAAM,WAAW,CAAC;AAC5E"}
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { d, a, b, c, e, f, g, i } from "./chunks/discovery-C0r-nDQB.js";
2
- import { d as displayNameForScopedPackage, a as displayNameForSmrtPackage } from "./chunks/runtime-BtfwY7PF.js";
3
- import { c as c2, m, n, q } from "./chunks/runtime-BtfwY7PF.js";
1
+ import { a as displayNameForScopedPackage, i as qualifyPlaygroundEntryId, n as mergePlaygroundModules, o as displayNameForSmrtPackage, r as normalizePlaygroundModule, t as coercePlaygroundModules } from "./chunks/runtime-85Dv9ms7.js";
2
+ import { a as discoverWorkspacePlaygrounds, c as importPlaygroundModule, i as discoverPlaygroundTargets, n as detectPlaygroundMode, o as findSmrtWorkspaceRoot, r as discoverInstalledPlaygrounds, s as findWorkspaceRoot, t as describePlaygroundSource } from "./chunks/discovery-ZfRkQSmn.js";
3
+ //#region src/templates.ts
4
4
  function createPackagePlaygroundTemplate(packageName) {
5
- const displayName = displayNameForSmrtPackage(packageName);
6
- return `/**
5
+ const displayName = displayNameForSmrtPackage(packageName);
6
+ return `/**
7
7
  * ${displayName} playground definitions
8
8
  *
9
9
  * Export preview entries for the shared SMRT playground host here.
@@ -17,8 +17,7 @@ export default {
17
17
  `;
18
18
  }
19
19
  function createAppPlaygroundTemplate(packageName) {
20
- const displayName = displayNameForScopedPackage(packageName);
21
- return `/**
20
+ return `/**
22
21
  * Local app playground overrides
23
22
  *
24
23
  * Add app-specific previews here, or override installed package entries by
@@ -28,14 +27,14 @@ function createAppPlaygroundTemplate(packageName) {
28
27
  export default [
29
28
  {
30
29
  packageName: '${packageName}',
31
- displayName: '${displayName}',
30
+ displayName: '${displayNameForScopedPackage(packageName)}',
32
31
  entries: [],
33
32
  },
34
33
  ];
35
34
  `;
36
35
  }
37
36
  function createAppPlaygroundRouteTemplate() {
38
- return `<script lang="ts">
37
+ return `<script lang="ts">
39
38
  import { PlaygroundHost } from '@happyvertical/smrt-playground/svelte';
40
39
  import { playgroundModules } from 'virtual:smrt-playground/modules';
41
40
  <\/script>
@@ -47,21 +46,7 @@ import { playgroundModules } from 'virtual:smrt-playground/modules';
47
46
  />
48
47
  `;
49
48
  }
50
- export {
51
- c2 as coercePlaygroundModules,
52
- createAppPlaygroundRouteTemplate,
53
- createAppPlaygroundTemplate,
54
- createPackagePlaygroundTemplate,
55
- d as describePlaygroundSource,
56
- a as detectPlaygroundMode,
57
- b as discoverInstalledPlaygrounds,
58
- c as discoverPlaygroundTargets,
59
- e as discoverWorkspacePlaygrounds,
60
- f as findSmrtWorkspaceRoot,
61
- g as findWorkspaceRoot,
62
- i as importPlaygroundModule,
63
- m as mergePlaygroundModules,
64
- n as normalizePlaygroundModule,
65
- q as qualifyPlaygroundEntryId
66
- };
67
- //# sourceMappingURL=index.js.map
49
+ //#endregion
50
+ export { coercePlaygroundModules, createAppPlaygroundRouteTemplate, createAppPlaygroundTemplate, createPackagePlaygroundTemplate, describePlaygroundSource, detectPlaygroundMode, discoverInstalledPlaygrounds, discoverPlaygroundTargets, discoverWorkspacePlaygrounds, findSmrtWorkspaceRoot, findWorkspaceRoot, importPlaygroundModule, mergePlaygroundModules, normalizePlaygroundModule, qualifyPlaygroundEntryId };
51
+
52
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/templates.ts"],"sourcesContent":["import {\n displayNameForScopedPackage,\n displayNameForSmrtPackage,\n} from './utils.js';\n\nexport function createPackagePlaygroundTemplate(packageName: string): string {\n const displayName = displayNameForSmrtPackage(packageName);\n\n return `/**\n * ${displayName} playground definitions\n *\n * Export preview entries for the shared SMRT playground host here.\n */\n\nexport default {\n packageName: '${packageName}',\n displayName: '${displayName}',\n entries: [],\n};\n`;\n}\n\nexport function createAppPlaygroundTemplate(packageName: string): string {\n const displayName = displayNameForScopedPackage(packageName);\n\n return `/**\n * Local app playground overrides\n *\n * Add app-specific previews here, or override installed package entries by\n * exporting an additional module with the same packageName + entry id.\n */\n\nexport default [\n {\n packageName: '${packageName}',\n displayName: '${displayName}',\n entries: [],\n },\n];\n`;\n}\n\nexport function createAppPlaygroundRouteTemplate(): string {\n return `<script lang=\"ts\">\nimport { PlaygroundHost } from '@happyvertical/smrt-playground/svelte';\nimport { playgroundModules } from 'virtual:smrt-playground/modules';\n</script>\n\n<PlaygroundHost\n title=\"SMRT Playground\"\n subtitle=\"Package previews and local app overrides\"\n modules={playgroundModules}\n/>\n`;\n}\n"],"names":[],"mappings":";;;AAKO,SAAS,gCAAgC,aAA6B;AAC3E,QAAM,cAAc,0BAA0B,WAAW;AAEzD,SAAO;AAAA,KACJ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAME,WAAW;AAAA,kBACX,WAAW;AAAA;AAAA;AAAA;AAI7B;AAEO,SAAS,4BAA4B,aAA6B;AACvE,QAAM,cAAc,4BAA4B,WAAW;AAE3D,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBASW,WAAW;AAAA,oBACX,WAAW;AAAA;AAAA;AAAA;AAAA;AAK/B;AAEO,SAAS,mCAA2C;AACzD,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWT;"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/templates.ts"],"sourcesContent":["import {\n displayNameForScopedPackage,\n displayNameForSmrtPackage,\n} from './utils.js';\n\nexport function createPackagePlaygroundTemplate(packageName: string): string {\n const displayName = displayNameForSmrtPackage(packageName);\n\n return `/**\n * ${displayName} playground definitions\n *\n * Export preview entries for the shared SMRT playground host here.\n */\n\nexport default {\n packageName: '${packageName}',\n displayName: '${displayName}',\n entries: [],\n};\n`;\n}\n\nexport function createAppPlaygroundTemplate(packageName: string): string {\n const displayName = displayNameForScopedPackage(packageName);\n\n return `/**\n * Local app playground overrides\n *\n * Add app-specific previews here, or override installed package entries by\n * exporting an additional module with the same packageName + entry id.\n */\n\nexport default [\n {\n packageName: '${packageName}',\n displayName: '${displayName}',\n entries: [],\n },\n];\n`;\n}\n\nexport function createAppPlaygroundRouteTemplate(): string {\n return `<script lang=\"ts\">\nimport { PlaygroundHost } from '@happyvertical/smrt-playground/svelte';\nimport { playgroundModules } from 'virtual:smrt-playground/modules';\n</script>\n\n<PlaygroundHost\n title=\"SMRT Playground\"\n subtitle=\"Package previews and local app overrides\"\n modules={playgroundModules}\n/>\n`;\n}\n"],"mappings":";;;AAKO,SAAS,gCAAgC,aAA6B;CAC3E,MAAM,cAAc,0BAA0B,WAAW;CAEzD,OAAO;KACJ,YAAW;;;;;;kBAME,YAAW;kBACX,YAAW;;;;AAI7B;AAEO,SAAS,4BAA4B,aAA6B;CAGvE,OAAO;;;;;;;;;oBASW,YAAW;oBAXT,4BAA4B,WAY9B,EAAW;;;;;AAK/B;AAEO,SAAS,mCAA2C;CACzD,OAAO;;;;;;;;;;;AAWT"}
package/dist/runtime.js CHANGED
@@ -1,8 +1,2 @@
1
- import { c, m, n, q } from "./chunks/runtime-BtfwY7PF.js";
2
- export {
3
- c as coercePlaygroundModules,
4
- m as mergePlaygroundModules,
5
- n as normalizePlaygroundModule,
6
- q as qualifyPlaygroundEntryId
7
- };
8
- //# sourceMappingURL=runtime.js.map
1
+ import { i as qualifyPlaygroundEntryId, n as mergePlaygroundModules, r as normalizePlaygroundModule, t as coercePlaygroundModules } from "./chunks/runtime-85Dv9ms7.js";
2
+ export { coercePlaygroundModules, mergePlaygroundModules, normalizePlaygroundModule, qualifyPlaygroundEntryId };
package/dist/types.js CHANGED
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
package/dist/vite.js CHANGED
@@ -1,22 +1,17 @@
1
+ import { n as detectPlaygroundMode, r as discoverInstalledPlaygrounds, s as findWorkspaceRoot } from "./chunks/discovery-ZfRkQSmn.js";
1
2
  import { existsSync } from "node:fs";
2
- import { resolve, isAbsolute } from "node:path";
3
+ import { isAbsolute, resolve } from "node:path";
3
4
  import fg from "fast-glob";
4
5
  import { normalizePath } from "vite";
5
- import { a as detectPlaygroundMode, g as findWorkspaceRoot, b as discoverInstalledPlaygrounds } from "./chunks/discovery-C0r-nDQB.js";
6
- const VIRTUAL_PLAYGROUND_MODULE_ID = "virtual:smrt-playground/modules";
7
- const RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID = `\0${VIRTUAL_PLAYGROUND_MODULE_ID}`;
6
+ //#region src/vite.ts
7
+ var VIRTUAL_PLAYGROUND_MODULE_ID = "virtual:smrt-playground/modules";
8
+ var RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID = `\0${VIRTUAL_PLAYGROUND_MODULE_ID}`;
8
9
  function toViteImportSpecifier(specifier) {
9
- if (!isAbsolute(specifier)) {
10
- return specifier;
11
- }
12
- return `/@fs/${normalizePath(specifier)}`;
10
+ if (!isAbsolute(specifier)) return specifier;
11
+ return `/@fs/${normalizePath(specifier)}`;
13
12
  }
14
13
  function buildVirtualModuleCode(specifiers) {
15
- const imports = specifiers.map(
16
- (specifier, index) => `import module${index} from ${JSON.stringify(toViteImportSpecifier(specifier))};`
17
- ).join("\n");
18
- const moduleList = specifiers.map((_, index) => `...toModules(module${index})`).join(", ");
19
- return `${imports}
14
+ return `${specifiers.map((specifier, index) => `import module${index} from ${JSON.stringify(toViteImportSpecifier(specifier))};`).join("\n")}
20
15
 
21
16
  const toModules = (value) => {
22
17
  if (!value) return [];
@@ -25,91 +20,58 @@ const toModules = (value) => {
25
20
  return [value];
26
21
  };
27
22
 
28
- export const playgroundModules = [${moduleList}].filter(Boolean);
23
+ export const playgroundModules = [${specifiers.map((_, index) => `...toModules(module${index})`).join(", ")}].filter(Boolean);
29
24
  export default playgroundModules;
30
25
  `;
31
26
  }
32
27
  async function discoverWorkspaceSpecifiers(projectRoot, options) {
33
- const workspaceRoot = options.workspaceRoot || findWorkspaceRoot(projectRoot);
34
- if (!workspaceRoot) {
35
- return [];
36
- }
37
- const matches = await fg(
38
- options.packagesPattern || "packages/*/src/svelte/playground.ts",
39
- {
40
- cwd: workspaceRoot,
41
- absolute: true
42
- }
43
- );
44
- return matches.sort().map((path) => normalizePath(path));
28
+ const workspaceRoot = options.workspaceRoot || findWorkspaceRoot(projectRoot);
29
+ if (!workspaceRoot) return [];
30
+ return (await fg(options.packagesPattern || "packages/*/src/svelte/playground.ts", {
31
+ cwd: workspaceRoot,
32
+ absolute: true
33
+ })).sort().map((path) => normalizePath(path));
45
34
  }
46
35
  async function discoverConsumerSpecifiers(projectRoot, options) {
47
- const installed = await discoverInstalledPlaygrounds(projectRoot);
48
- const specifiers = installed.map((item) => item.importSpecifier);
49
- const localPlayground = resolve(
50
- projectRoot,
51
- options.localPlaygroundPath || "src/playground.ts"
52
- );
53
- if (existsSync(localPlayground)) {
54
- specifiers.push(normalizePath(localPlayground));
55
- }
56
- return specifiers;
36
+ const specifiers = (await discoverInstalledPlaygrounds(projectRoot)).map((item) => item.importSpecifier);
37
+ const localPlayground = resolve(projectRoot, options.localPlaygroundPath || "src/playground.ts");
38
+ if (existsSync(localPlayground)) specifiers.push(normalizePath(localPlayground));
39
+ return specifiers;
57
40
  }
58
41
  function smrtPlaygroundVitePlugin(options = {}) {
59
- let projectRoot = process.cwd();
60
- return {
61
- name: "smrt-playground-vite-plugin",
62
- enforce: "pre",
63
- configResolved(config) {
64
- projectRoot = config.root ? resolve(config.root) : process.cwd();
65
- },
66
- resolveId(id) {
67
- if (id === VIRTUAL_PLAYGROUND_MODULE_ID) {
68
- return RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID;
69
- }
70
- return null;
71
- },
72
- async load(id) {
73
- if (id !== RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID) {
74
- return null;
75
- }
76
- const effectiveMode = options.mode === "auto" || !options.mode ? detectPlaygroundMode(projectRoot) : options.mode;
77
- const specifiers = effectiveMode === "workspace" ? await discoverWorkspaceSpecifiers(projectRoot, options) : await discoverConsumerSpecifiers(projectRoot, options);
78
- if (effectiveMode === "workspace") {
79
- const workspaceRoot = options.workspaceRoot || findWorkspaceRoot(projectRoot);
80
- if (workspaceRoot) {
81
- const workspaceConfigPath = resolve(
82
- workspaceRoot,
83
- "pnpm-workspace.yaml"
84
- );
85
- if (existsSync(workspaceConfigPath)) {
86
- this.addWatchFile(workspaceConfigPath);
87
- }
88
- }
89
- } else {
90
- const packageJsonPath = resolve(projectRoot, "package.json");
91
- if (existsSync(packageJsonPath)) {
92
- this.addWatchFile(packageJsonPath);
93
- }
94
- const localPlayground = resolve(
95
- projectRoot,
96
- options.localPlaygroundPath || "src/playground.ts"
97
- );
98
- if (existsSync(localPlayground)) {
99
- this.addWatchFile(localPlayground);
100
- }
101
- }
102
- for (const specifier of specifiers) {
103
- if (isAbsolute(specifier)) {
104
- this.addWatchFile(specifier);
105
- }
106
- }
107
- return buildVirtualModuleCode(specifiers);
108
- }
109
- };
42
+ let projectRoot = process.cwd();
43
+ return {
44
+ name: "smrt-playground-vite-plugin",
45
+ enforce: "pre",
46
+ configResolved(config) {
47
+ projectRoot = config.root ? resolve(config.root) : process.cwd();
48
+ },
49
+ resolveId(id) {
50
+ if (id === "virtual:smrt-playground/modules") return RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID;
51
+ return null;
52
+ },
53
+ async load(id) {
54
+ if (id !== RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID) return null;
55
+ const effectiveMode = options.mode === "auto" || !options.mode ? detectPlaygroundMode(projectRoot) : options.mode;
56
+ const specifiers = effectiveMode === "workspace" ? await discoverWorkspaceSpecifiers(projectRoot, options) : await discoverConsumerSpecifiers(projectRoot, options);
57
+ if (effectiveMode === "workspace") {
58
+ const workspaceRoot = options.workspaceRoot || findWorkspaceRoot(projectRoot);
59
+ if (workspaceRoot) {
60
+ const workspaceConfigPath = resolve(workspaceRoot, "pnpm-workspace.yaml");
61
+ if (existsSync(workspaceConfigPath)) this.addWatchFile(workspaceConfigPath);
62
+ }
63
+ } else {
64
+ const packageJsonPath = resolve(projectRoot, "package.json");
65
+ if (existsSync(packageJsonPath)) this.addWatchFile(packageJsonPath);
66
+ const localPlayground = resolve(projectRoot, options.localPlaygroundPath || "src/playground.ts");
67
+ if (existsSync(localPlayground)) this.addWatchFile(localPlayground);
68
+ }
69
+ for (const specifier of specifiers) if (isAbsolute(specifier)) this.addWatchFile(specifier);
70
+ return buildVirtualModuleCode(specifiers);
71
+ }
72
+ };
110
73
  }
111
- export {
112
- VIRTUAL_PLAYGROUND_MODULE_ID,
113
- smrtPlaygroundVitePlugin
114
- };
115
- //# sourceMappingURL=vite.js.map
74
+ //#endregion
75
+ export { VIRTUAL_PLAYGROUND_MODULE_ID, smrtPlaygroundVitePlugin };
76
+
77
+ //# sourceMappingURL=vite.js.map
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","sources":["../src/vite.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { isAbsolute, resolve } from 'node:path';\nimport fg from 'fast-glob';\nimport { normalizePath, type Plugin } from 'vite';\nimport {\n detectPlaygroundMode,\n discoverInstalledPlaygrounds,\n findWorkspaceRoot,\n} from './discovery.js';\nimport type { SmrtPlaygroundVitePluginOptions } from './types.js';\n\nconst VIRTUAL_PLAYGROUND_MODULE_ID = 'virtual:smrt-playground/modules';\nconst RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID = `\\0${VIRTUAL_PLAYGROUND_MODULE_ID}`;\n\nfunction toViteImportSpecifier(specifier: string): string {\n if (!isAbsolute(specifier)) {\n return specifier;\n }\n\n return `/@fs/${normalizePath(specifier)}`;\n}\n\nfunction buildVirtualModuleCode(specifiers: string[]): string {\n const imports = specifiers\n .map(\n (specifier, index) =>\n `import module${index} from ${JSON.stringify(toViteImportSpecifier(specifier))};`,\n )\n .join('\\n');\n\n const moduleList = specifiers\n .map((_, index) => `...toModules(module${index})`)\n .join(', ');\n\n return `${imports}\n\nconst toModules = (value) => {\n if (!value) return [];\n if (Array.isArray(value)) return value.filter(Boolean);\n if (Array.isArray(value.modules)) return value.modules.filter(Boolean);\n return [value];\n};\n\nexport const playgroundModules = [${moduleList}].filter(Boolean);\nexport default playgroundModules;\n`;\n}\n\nasync function discoverWorkspaceSpecifiers(\n projectRoot: string,\n options: SmrtPlaygroundVitePluginOptions,\n): Promise<string[]> {\n const workspaceRoot = options.workspaceRoot || findWorkspaceRoot(projectRoot);\n if (!workspaceRoot) {\n return [];\n }\n\n const matches = await fg(\n options.packagesPattern || 'packages/*/src/svelte/playground.ts',\n {\n cwd: workspaceRoot,\n absolute: true,\n },\n );\n\n return matches.sort().map((path) => normalizePath(path));\n}\n\nasync function discoverConsumerSpecifiers(\n projectRoot: string,\n options: SmrtPlaygroundVitePluginOptions,\n): Promise<string[]> {\n const installed = await discoverInstalledPlaygrounds(projectRoot);\n const specifiers = installed.map((item) => item.importSpecifier);\n const localPlayground = resolve(\n projectRoot,\n options.localPlaygroundPath || 'src/playground.ts',\n );\n\n if (existsSync(localPlayground)) {\n specifiers.push(normalizePath(localPlayground));\n }\n\n return specifiers;\n}\n\nexport function smrtPlaygroundVitePlugin(\n options: SmrtPlaygroundVitePluginOptions = {},\n): Plugin {\n let projectRoot = process.cwd();\n\n return {\n name: 'smrt-playground-vite-plugin',\n enforce: 'pre',\n configResolved(config) {\n projectRoot = config.root ? resolve(config.root) : process.cwd();\n },\n resolveId(id) {\n if (id === VIRTUAL_PLAYGROUND_MODULE_ID) {\n return RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID;\n }\n return null;\n },\n async load(id) {\n if (id !== RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID) {\n return null;\n }\n\n const effectiveMode =\n options.mode === 'auto' || !options.mode\n ? detectPlaygroundMode(projectRoot)\n : options.mode;\n\n const specifiers =\n effectiveMode === 'workspace'\n ? await discoverWorkspaceSpecifiers(projectRoot, options)\n : await discoverConsumerSpecifiers(projectRoot, options);\n\n if (effectiveMode === 'workspace') {\n const workspaceRoot =\n options.workspaceRoot || findWorkspaceRoot(projectRoot);\n if (workspaceRoot) {\n const workspaceConfigPath = resolve(\n workspaceRoot,\n 'pnpm-workspace.yaml',\n );\n if (existsSync(workspaceConfigPath)) {\n this.addWatchFile(workspaceConfigPath);\n }\n }\n } else {\n const packageJsonPath = resolve(projectRoot, 'package.json');\n if (existsSync(packageJsonPath)) {\n this.addWatchFile(packageJsonPath);\n }\n const localPlayground = resolve(\n projectRoot,\n options.localPlaygroundPath || 'src/playground.ts',\n );\n if (existsSync(localPlayground)) {\n this.addWatchFile(localPlayground);\n }\n }\n\n for (const specifier of specifiers) {\n if (isAbsolute(specifier)) {\n this.addWatchFile(specifier);\n }\n }\n\n return buildVirtualModuleCode(specifiers);\n },\n };\n}\n\nexport { VIRTUAL_PLAYGROUND_MODULE_ID };\n"],"names":[],"mappings":";;;;;AAWA,MAAM,+BAA+B;AACrC,MAAM,wCAAwC,KAAK,4BAA4B;AAE/E,SAAS,sBAAsB,WAA2B;AACxD,MAAI,CAAC,WAAW,SAAS,GAAG;AAC1B,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,cAAc,SAAS,CAAC;AACzC;AAEA,SAAS,uBAAuB,YAA8B;AAC5D,QAAM,UAAU,WACb;AAAA,IACC,CAAC,WAAW,UACV,gBAAgB,KAA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AI,OAAO,uCAAuC;AAChD,eAAO;AAAA,MACT;AAEA,YAAM,gBACJ,QAAQ,SAAS,UAAU,CAAC,QAAQ,OAChC,qBAAqB,WAAW,IAChC,QAAQ;AAEd,YAAM,aACJ,kBAAkB,cACd,MAAM,4BAA4B,aAAa,OAAO,IACtD,MAAM,2BAA2B,aAAa,OAAO;AAE3D,UAAI,kBAAkB,aAAa;AACjC,cAAM,gBACJ,QAAQ,iBAAiB,kBAAkB,WAAW;AACxD,YAAI,eAAe;AACjB,gBAAM,sBAAsB;AAAA,YAC1B;AAAA,YACA;AAAA,UAAA;AAEF,cAAI,WAAW,mBAAmB,GAAG;AACnC,iBAAK,aAAa,mBAAmB;AAAA,UACvC;AAAA,QACF;AAAA,MACF,OAAO;AACL,cAAM,kBAAkB,QAAQ,aAAa,cAAc;AAC3D,YAAI,WAAW,eAAe,GAAG;AAC/B,eAAK,aAAa,eAAe;AAAA,QACnC;AACA,cAAM,kBAAkB;AAAA,UACtB;AAAA,UACA,QAAQ,uBAAuB;AAAA,QAAA;AAEjC,YAAI,WAAW,eAAe,GAAG;AAC/B,eAAK,aAAa,eAAe;AAAA,QACnC;AAAA,MACF;AAEA,iBAAW,aAAa,YAAY;AAClC,YAAI,WAAW,SAAS,GAAG;AACzB,eAAK,aAAa,SAAS;AAAA,QAC7B;AAAA,MACF;AAEA,aAAO,uBAAuB,UAAU;AAAA,IAC1C;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { isAbsolute, resolve } from 'node:path';\nimport fg from 'fast-glob';\nimport { normalizePath, type Plugin } from 'vite';\nimport {\n detectPlaygroundMode,\n discoverInstalledPlaygrounds,\n findWorkspaceRoot,\n} from './discovery.js';\nimport type { SmrtPlaygroundVitePluginOptions } from './types.js';\n\nconst VIRTUAL_PLAYGROUND_MODULE_ID = 'virtual:smrt-playground/modules';\nconst RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID = `\\0${VIRTUAL_PLAYGROUND_MODULE_ID}`;\n\nfunction toViteImportSpecifier(specifier: string): string {\n if (!isAbsolute(specifier)) {\n return specifier;\n }\n\n return `/@fs/${normalizePath(specifier)}`;\n}\n\nfunction buildVirtualModuleCode(specifiers: string[]): string {\n const imports = specifiers\n .map(\n (specifier, index) =>\n `import module${index} from ${JSON.stringify(toViteImportSpecifier(specifier))};`,\n )\n .join('\\n');\n\n const moduleList = specifiers\n .map((_, index) => `...toModules(module${index})`)\n .join(', ');\n\n return `${imports}\n\nconst toModules = (value) => {\n if (!value) return [];\n if (Array.isArray(value)) return value.filter(Boolean);\n if (Array.isArray(value.modules)) return value.modules.filter(Boolean);\n return [value];\n};\n\nexport const playgroundModules = [${moduleList}].filter(Boolean);\nexport default playgroundModules;\n`;\n}\n\nasync function discoverWorkspaceSpecifiers(\n projectRoot: string,\n options: SmrtPlaygroundVitePluginOptions,\n): Promise<string[]> {\n const workspaceRoot = options.workspaceRoot || findWorkspaceRoot(projectRoot);\n if (!workspaceRoot) {\n return [];\n }\n\n const matches = await fg(\n options.packagesPattern || 'packages/*/src/svelte/playground.ts',\n {\n cwd: workspaceRoot,\n absolute: true,\n },\n );\n\n return matches.sort().map((path) => normalizePath(path));\n}\n\nasync function discoverConsumerSpecifiers(\n projectRoot: string,\n options: SmrtPlaygroundVitePluginOptions,\n): Promise<string[]> {\n const installed = await discoverInstalledPlaygrounds(projectRoot);\n const specifiers = installed.map((item) => item.importSpecifier);\n const localPlayground = resolve(\n projectRoot,\n options.localPlaygroundPath || 'src/playground.ts',\n );\n\n if (existsSync(localPlayground)) {\n specifiers.push(normalizePath(localPlayground));\n }\n\n return specifiers;\n}\n\nexport function smrtPlaygroundVitePlugin(\n options: SmrtPlaygroundVitePluginOptions = {},\n): Plugin {\n let projectRoot = process.cwd();\n\n return {\n name: 'smrt-playground-vite-plugin',\n enforce: 'pre',\n configResolved(config) {\n projectRoot = config.root ? resolve(config.root) : process.cwd();\n },\n resolveId(id) {\n if (id === VIRTUAL_PLAYGROUND_MODULE_ID) {\n return RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID;\n }\n return null;\n },\n async load(id) {\n if (id !== RESOLVED_VIRTUAL_PLAYGROUND_MODULE_ID) {\n return null;\n }\n\n const effectiveMode =\n options.mode === 'auto' || !options.mode\n ? detectPlaygroundMode(projectRoot)\n : options.mode;\n\n const specifiers =\n effectiveMode === 'workspace'\n ? await discoverWorkspaceSpecifiers(projectRoot, options)\n : await discoverConsumerSpecifiers(projectRoot, options);\n\n if (effectiveMode === 'workspace') {\n const workspaceRoot =\n options.workspaceRoot || findWorkspaceRoot(projectRoot);\n if (workspaceRoot) {\n const workspaceConfigPath = resolve(\n workspaceRoot,\n 'pnpm-workspace.yaml',\n );\n if (existsSync(workspaceConfigPath)) {\n this.addWatchFile(workspaceConfigPath);\n }\n }\n } else {\n const packageJsonPath = resolve(projectRoot, 'package.json');\n if (existsSync(packageJsonPath)) {\n this.addWatchFile(packageJsonPath);\n }\n const localPlayground = resolve(\n projectRoot,\n options.localPlaygroundPath || 'src/playground.ts',\n );\n if (existsSync(localPlayground)) {\n this.addWatchFile(localPlayground);\n }\n }\n\n for (const specifier of specifiers) {\n if (isAbsolute(specifier)) {\n this.addWatchFile(specifier);\n }\n }\n\n return buildVirtualModuleCode(specifiers);\n },\n };\n}\n\nexport { VIRTUAL_PLAYGROUND_MODULE_ID };\n"],"mappings":";;;;;;AAWA,IAAM,+BAA+B;AACrC,IAAM,wCAAwC,KAAK;AAEnD,SAAS,sBAAsB,WAA2B;CACxD,IAAI,CAAC,WAAW,SAAS,GACvB,OAAO;CAGT,OAAO,QAAQ,cAAc,SAAS;AACxC;AAEA,SAAS,uBAAuB,YAA8B;CAY5D,OAAO,GAXS,WACb,KACE,WAAW,UACV,gBAAgB,MAAK,QAAS,KAAK,UAAU,sBAAsB,SAAS,CAAC,EAAC,EAClF,CAAA,CACC,KAAK,IAME,EAAO;;;;;;;;;oCAJE,WA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aAAa,mBAAmB;IAEzC;GACF,OAAO;IACL,MAAM,kBAAkB,QAAQ,aAAa,cAAc;IAC3D,IAAI,WAAW,eAAe,GAC5B,KAAK,aAAa,eAAe;IAEnC,MAAM,kBAAkB,QACtB,aACA,QAAQ,uBAAuB,mBACjC;IACA,IAAI,WAAW,eAAe,GAC5B,KAAK,aAAa,eAAe;GAErC;GAEA,KAAA,MAAW,aAAa,YACtB,IAAI,WAAW,SAAS,GACtB,KAAK,aAAa,SAAS;GAI/B,OAAO,uBAAuB,UAAU;EAC1C;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-playground",
3
- "version": "0.37.2",
3
+ "version": "0.37.4",
4
4
  "description": "Shared playground discovery, runtime, and host components for SMRT UI packages",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,12 +28,12 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "fast-glob": "3.3.3",
31
- "tsx": "^4.21.0",
32
- "@happyvertical/smrt-ui": "0.37.2"
31
+ "tsx": "^4.22.4",
32
+ "@happyvertical/smrt-ui": "0.37.4"
33
33
  },
34
34
  "peerDependencies": {
35
- "svelte": "^5.18.0",
36
- "vite": "^7.0.0"
35
+ "svelte": "^5.56.4",
36
+ "vite": "^8.1.2"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "svelte": {
@@ -44,13 +44,13 @@
44
44
  }
45
45
  },
46
46
  "devDependencies": {
47
- "@sveltejs/package": "^2.5.7",
48
- "@sveltejs/vite-plugin-svelte": "^6.2.4",
49
- "@types/node": "25.0.9",
50
- "svelte": "^5.46.4",
51
- "svelte-check": "^4.3.5",
47
+ "@sveltejs/package": "^2.5.8",
48
+ "@sveltejs/vite-plugin-svelte": "^7.1.2",
49
+ "@types/node": "24.13.2",
50
+ "svelte": "^5.56.4",
51
+ "svelte-check": "^4.7.1",
52
52
  "typescript": "^5.9.3",
53
- "vite": "^7.3.6"
53
+ "vite": "^8.1.2"
54
54
  },
55
55
  "publishConfig": {
56
56
  "registry": "https://registry.npmjs.org",
@@ -1,177 +0,0 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { createRequire } from "node:module";
3
- import { relative, join, resolve, dirname, isAbsolute, extname } from "node:path";
4
- import { pathToFileURL } from "node:url";
5
- import fg from "fast-glob";
6
- import { c as coercePlaygroundModules } from "./runtime-BtfwY7PF.js";
7
- const require$1 = createRequire(import.meta.url);
8
- const TS_SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".mts", ".cts"]);
9
- function findWorkspaceRoot(startDir = process.cwd()) {
10
- let current = resolve(startDir);
11
- while (true) {
12
- if (existsSync(join(current, "pnpm-workspace.yaml"))) {
13
- return current;
14
- }
15
- const parent = dirname(current);
16
- if (parent === current) {
17
- return null;
18
- }
19
- current = parent;
20
- }
21
- }
22
- function findSmrtWorkspaceRoot(startDir = process.cwd()) {
23
- const workspaceRoot = findWorkspaceRoot(startDir);
24
- if (!workspaceRoot) {
25
- return null;
26
- }
27
- const hostPackageJsonPath = join(
28
- workspaceRoot,
29
- "packages",
30
- "smrt-playground",
31
- "host",
32
- "package.json"
33
- );
34
- return existsSync(hostPackageJsonPath) ? workspaceRoot : null;
35
- }
36
- function detectPlaygroundMode(projectRoot = process.cwd()) {
37
- return findSmrtWorkspaceRoot(projectRoot) ? "workspace" : "consumer";
38
- }
39
- function readJson(path) {
40
- return JSON.parse(readFileSync(path, "utf-8"));
41
- }
42
- function resolveNodeModulePackageDir(projectRoot, packageName) {
43
- const packageJsonPath = join(
44
- projectRoot,
45
- "node_modules",
46
- packageName,
47
- "package.json"
48
- );
49
- return existsSync(packageJsonPath) ? dirname(packageJsonPath) : null;
50
- }
51
- async function discoverWorkspacePlaygrounds(workspaceRoot, packagesPattern = "packages/*/src/svelte/playground.ts") {
52
- const matches = await fg(packagesPattern, {
53
- cwd: workspaceRoot,
54
- absolute: true
55
- });
56
- const discovered = [];
57
- for (const sourcePath of matches.sort()) {
58
- const packageDir = dirname(dirname(dirname(sourcePath)));
59
- const packageJsonPath = join(packageDir, "package.json");
60
- if (!existsSync(packageJsonPath)) {
61
- continue;
62
- }
63
- const packageJson = readJson(packageJsonPath);
64
- const runtimePath = join(packageDir, "dist", "playground.js");
65
- discovered.push({
66
- packageName: packageJson.name,
67
- packageDir,
68
- sourcePath,
69
- runtimePath: existsSync(runtimePath) ? runtimePath : null
70
- });
71
- }
72
- return discovered;
73
- }
74
- async function discoverInstalledPlaygrounds(projectRoot = process.cwd()) {
75
- const packageJsonPath = join(projectRoot, "package.json");
76
- if (!existsSync(packageJsonPath)) {
77
- return [];
78
- }
79
- const packageJson = readJson(packageJsonPath);
80
- const dependencies = {
81
- ...packageJson.dependencies,
82
- ...packageJson.devDependencies,
83
- ...packageJson.peerDependencies
84
- };
85
- const discovered = [];
86
- for (const dependencyName of Object.keys(dependencies).sort()) {
87
- if (!dependencyName.startsWith("@happyvertical/smrt-") || dependencyName === "@happyvertical/smrt-playground") {
88
- continue;
89
- }
90
- const packageDir = resolveNodeModulePackageDir(projectRoot, dependencyName);
91
- if (!packageDir) {
92
- continue;
93
- }
94
- const dependencyPackageJson = readJson(join(packageDir, "package.json"));
95
- if (dependencyPackageJson.exports?.["./playground"]) {
96
- discovered.push({
97
- packageName: dependencyName,
98
- importSpecifier: `${dependencyName}/playground`
99
- });
100
- }
101
- }
102
- return discovered;
103
- }
104
- async function discoverPlaygroundTargets(projectRoot = process.cwd(), mode = "auto", localPlaygroundPath = "src/playground.ts") {
105
- const effectiveMode = mode === "auto" ? detectPlaygroundMode(projectRoot) : mode;
106
- if (effectiveMode === "workspace") {
107
- const workspaceRoot = mode === "workspace" ? findWorkspaceRoot(projectRoot) : findSmrtWorkspaceRoot(projectRoot);
108
- if (!workspaceRoot) {
109
- return [];
110
- }
111
- const packages = await discoverWorkspacePlaygrounds(workspaceRoot);
112
- return packages.map((item) => ({
113
- packageName: item.packageName,
114
- source: "workspace",
115
- sourcePath: item.sourcePath,
116
- runtimePath: item.runtimePath ?? void 0
117
- }));
118
- }
119
- const targets = [];
120
- const installed = await discoverInstalledPlaygrounds(projectRoot);
121
- for (const item of installed) {
122
- targets.push({
123
- packageName: item.packageName,
124
- source: "package",
125
- importSpecifier: item.importSpecifier
126
- });
127
- }
128
- const localPath = resolve(projectRoot, localPlaygroundPath);
129
- if (existsSync(localPath)) {
130
- targets.push({
131
- source: "app",
132
- sourcePath: localPath
133
- });
134
- }
135
- return targets;
136
- }
137
- async function importPlaygroundModule(input) {
138
- const imported = isAbsolute(input) || input.startsWith(".") ? await importPathModule(resolve(input)) : await import(input);
139
- const module = imported.default ?? imported.playground ?? imported;
140
- return module && typeof module === "object" ? coercePlaygroundModules(module) : [];
141
- }
142
- async function importPathModule(inputPath) {
143
- if (!TS_SOURCE_EXTENSIONS.has(extname(inputPath))) {
144
- return import(pathToFileURL(inputPath).href);
145
- }
146
- let tsxApiPath;
147
- try {
148
- tsxApiPath = require$1.resolve("tsx/esm/api");
149
- } catch (tsxError) {
150
- throw new Error(
151
- `Failed to load playground module from ${inputPath}: source playground discovery requires the "tsx" package.`,
152
- { cause: tsxError }
153
- );
154
- }
155
- const { tsImport } = await import(pathToFileURL(tsxApiPath).href);
156
- return tsImport(pathToFileURL(inputPath).href, {
157
- parentURL: import.meta.url
158
- });
159
- }
160
- function describePlaygroundSource(target, cwd = process.cwd()) {
161
- if (target.source === "package") {
162
- return target.importSpecifier || target.packageName || "installed package";
163
- }
164
- const path = target.sourcePath || target.runtimePath;
165
- return path ? relative(cwd, path) || "." : target.source;
166
- }
167
- export {
168
- detectPlaygroundMode as a,
169
- discoverInstalledPlaygrounds as b,
170
- discoverPlaygroundTargets as c,
171
- describePlaygroundSource as d,
172
- discoverWorkspacePlaygrounds as e,
173
- findSmrtWorkspaceRoot as f,
174
- findWorkspaceRoot as g,
175
- importPlaygroundModule as i
176
- };
177
- //# sourceMappingURL=discovery-C0r-nDQB.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discovery-C0r-nDQB.js","sources":["../../src/discovery.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport {\n dirname,\n extname,\n isAbsolute,\n join,\n relative,\n resolve,\n} from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport fg from 'fast-glob';\nimport { coercePlaygroundModules } from './runtime.js';\nimport type {\n DiscoveredInstalledPlayground,\n DiscoveredPlaygroundTarget,\n DiscoveredWorkspacePlayground,\n SmrtPlaygroundModule,\n} from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst TS_SOURCE_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);\n\nexport function findWorkspaceRoot(startDir = process.cwd()): string | null {\n let current = resolve(startDir);\n\n while (true) {\n if (existsSync(join(current, 'pnpm-workspace.yaml'))) {\n return current;\n }\n\n const parent = dirname(current);\n if (parent === current) {\n return null;\n }\n current = parent;\n }\n}\n\nexport function findSmrtWorkspaceRoot(startDir = process.cwd()): string | null {\n const workspaceRoot = findWorkspaceRoot(startDir);\n if (!workspaceRoot) {\n return null;\n }\n\n const hostPackageJsonPath = join(\n workspaceRoot,\n 'packages',\n 'smrt-playground',\n 'host',\n 'package.json',\n );\n\n return existsSync(hostPackageJsonPath) ? workspaceRoot : null;\n}\n\nexport function detectPlaygroundMode(\n projectRoot = process.cwd(),\n): 'workspace' | 'consumer' {\n return findSmrtWorkspaceRoot(projectRoot) ? 'workspace' : 'consumer';\n}\n\nfunction readJson(path: string): any {\n return JSON.parse(readFileSync(path, 'utf-8'));\n}\n\nfunction resolveNodeModulePackageDir(\n projectRoot: string,\n packageName: string,\n): string | null {\n const packageJsonPath = join(\n projectRoot,\n 'node_modules',\n packageName,\n 'package.json',\n );\n return existsSync(packageJsonPath) ? dirname(packageJsonPath) : null;\n}\n\nexport async function discoverWorkspacePlaygrounds(\n workspaceRoot: string,\n packagesPattern = 'packages/*/src/svelte/playground.ts',\n): Promise<DiscoveredWorkspacePlayground[]> {\n const matches = await fg(packagesPattern, {\n cwd: workspaceRoot,\n absolute: true,\n });\n\n const discovered: DiscoveredWorkspacePlayground[] = [];\n\n for (const sourcePath of matches.sort()) {\n const packageDir = dirname(dirname(dirname(sourcePath)));\n const packageJsonPath = join(packageDir, 'package.json');\n\n if (!existsSync(packageJsonPath)) {\n continue;\n }\n\n const packageJson = readJson(packageJsonPath);\n const runtimePath = join(packageDir, 'dist', 'playground.js');\n\n discovered.push({\n packageName: packageJson.name,\n packageDir,\n sourcePath,\n runtimePath: existsSync(runtimePath) ? runtimePath : null,\n });\n }\n\n return discovered;\n}\n\nexport async function discoverInstalledPlaygrounds(\n projectRoot = process.cwd(),\n): Promise<DiscoveredInstalledPlayground[]> {\n const packageJsonPath = join(projectRoot, 'package.json');\n if (!existsSync(packageJsonPath)) {\n return [];\n }\n\n const packageJson = readJson(packageJsonPath);\n const dependencies = {\n ...packageJson.dependencies,\n ...packageJson.devDependencies,\n ...packageJson.peerDependencies,\n };\n\n const discovered: DiscoveredInstalledPlayground[] = [];\n\n for (const dependencyName of Object.keys(dependencies).sort()) {\n if (\n !dependencyName.startsWith('@happyvertical/smrt-') ||\n dependencyName === '@happyvertical/smrt-playground'\n ) {\n continue;\n }\n\n const packageDir = resolveNodeModulePackageDir(projectRoot, dependencyName);\n if (!packageDir) {\n continue;\n }\n\n const dependencyPackageJson = readJson(join(packageDir, 'package.json'));\n if (dependencyPackageJson.exports?.['./playground']) {\n discovered.push({\n packageName: dependencyName,\n importSpecifier: `${dependencyName}/playground`,\n });\n }\n }\n\n return discovered;\n}\n\nexport async function discoverPlaygroundTargets(\n projectRoot = process.cwd(),\n mode: 'auto' | 'workspace' | 'consumer' = 'auto',\n localPlaygroundPath = 'src/playground.ts',\n): Promise<DiscoveredPlaygroundTarget[]> {\n const effectiveMode =\n mode === 'auto' ? detectPlaygroundMode(projectRoot) : mode;\n\n if (effectiveMode === 'workspace') {\n const workspaceRoot =\n mode === 'workspace'\n ? findWorkspaceRoot(projectRoot)\n : findSmrtWorkspaceRoot(projectRoot);\n if (!workspaceRoot) {\n return [];\n }\n\n const packages = await discoverWorkspacePlaygrounds(workspaceRoot);\n return packages.map((item) => ({\n packageName: item.packageName,\n source: 'workspace' as const,\n sourcePath: item.sourcePath,\n runtimePath: item.runtimePath ?? undefined,\n }));\n }\n\n const targets: DiscoveredPlaygroundTarget[] = [];\n const installed = await discoverInstalledPlaygrounds(projectRoot);\n\n for (const item of installed) {\n targets.push({\n packageName: item.packageName,\n source: 'package',\n importSpecifier: item.importSpecifier,\n });\n }\n\n const localPath = resolve(projectRoot, localPlaygroundPath);\n if (existsSync(localPath)) {\n targets.push({\n source: 'app',\n sourcePath: localPath,\n });\n }\n\n return targets;\n}\n\nexport async function importPlaygroundModule(\n input: string,\n): Promise<SmrtPlaygroundModule[]> {\n const imported =\n isAbsolute(input) || input.startsWith('.')\n ? await importPathModule(resolve(input))\n : await import(input);\n\n const module = imported.default ?? imported.playground ?? imported;\n return module && typeof module === 'object'\n ? coercePlaygroundModules(module as SmrtPlaygroundModule)\n : [];\n}\n\nasync function importPathModule(inputPath: string): Promise<unknown> {\n if (!TS_SOURCE_EXTENSIONS.has(extname(inputPath))) {\n return import(pathToFileURL(inputPath).href);\n }\n\n let tsxApiPath: string;\n try {\n tsxApiPath = require.resolve('tsx/esm/api');\n } catch (tsxError) {\n throw new Error(\n `Failed to load playground module from ${inputPath}: source playground discovery requires the \"tsx\" package.`,\n { cause: tsxError },\n );\n }\n\n const { tsImport } = await import(pathToFileURL(tsxApiPath).href);\n return tsImport(pathToFileURL(inputPath).href, {\n parentURL: import.meta.url,\n });\n}\n\nexport function describePlaygroundSource(\n target: DiscoveredPlaygroundTarget,\n cwd = process.cwd(),\n): string {\n if (target.source === 'package') {\n return target.importSpecifier || target.packageName || 'installed package';\n }\n\n const path = target.sourcePath || target.runtimePath;\n return path ? relative(cwd, path) || '.' : target.source;\n}\n"],"names":["require"],"mappings":";;;;;;AAoBA,MAAMA,YAAU,cAAc,YAAY,GAA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;AAC5D,SAAO,SAAS,cAAc,SAAS,EAAE,MAAM;AAAA,IAC7C,WAAW,YAAY;AAAA,EAAA,CACxB;AACH;AAEO,SAAS,yBACd,QACA,MAAM,QAAQ,OACN;AACR,MAAI,OAAO,WAAW,WAAW;AAC/B,WAAO,OAAO,mBAAmB,OAAO,eAAe;AAAA,EACzD;AAEA,QAAM,OAAO,OAAO,cAAc,OAAO;AACzC,SAAO,OAAO,SAAS,KAAK,IAAI,KAAK,MAAM,OAAO;AACpD;"}
@@ -1,104 +0,0 @@
1
- function titleCase(value) {
2
- return value.split(/[-_/]/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join(" ");
3
- }
4
- function displayNameForSmrtPackage(packageName) {
5
- return titleCase(packageName.replace(/^@happyvertical\/smrt-/, ""));
6
- }
7
- function displayNameForScopedPackage(packageName) {
8
- return titleCase(packageName.replace(/^@/, "").replace(/\//g, " "));
9
- }
10
- function normalizeModeConfig(value) {
11
- if (!value) {
12
- return void 0;
13
- }
14
- return value === true ? {} : value;
15
- }
16
- function qualifyPlaygroundEntryId(packageName, entryId) {
17
- return `${packageName}:${entryId}`;
18
- }
19
- function coercePlaygroundModules(input) {
20
- if (!input) {
21
- return [];
22
- }
23
- if (Array.isArray(input)) {
24
- return input.filter(Boolean);
25
- }
26
- if ("modules" in input && Array.isArray(input.modules)) {
27
- return input.modules.filter(Boolean);
28
- }
29
- return [input];
30
- }
31
- function normalizePlaygroundModule(module) {
32
- const displayName = module.displayName || module.moduleMeta?.displayName || displayNameForSmrtPackage(module.packageName);
33
- const entries = [...module.entries || []].map((entry) => {
34
- const modes = {
35
- mock: normalizeModeConfig(entry.modes?.mock),
36
- live: normalizeModeConfig(entry.modes?.live)
37
- };
38
- const availableModes = ["mock", "live"].filter(
39
- (mode) => Boolean(modes[mode])
40
- );
41
- if (availableModes.length === 0) {
42
- modes.mock = {};
43
- availableModes.push("mock");
44
- }
45
- return {
46
- ...entry,
47
- displayName,
48
- packageName: module.packageName,
49
- qualifiedId: qualifyPlaygroundEntryId(module.packageName, entry.id),
50
- availableModes,
51
- modes
52
- };
53
- }).sort((left, right) => {
54
- const orderDiff = (left.order ?? 999) - (right.order ?? 999);
55
- return orderDiff !== 0 ? orderDiff : left.title.localeCompare(right.title);
56
- });
57
- return {
58
- ...module,
59
- displayName,
60
- entries
61
- };
62
- }
63
- function mergePlaygroundModules(modules) {
64
- const mergedByPackage = /* @__PURE__ */ new Map();
65
- for (const inputModule of modules) {
66
- const module = normalizePlaygroundModule(inputModule);
67
- const existing = mergedByPackage.get(module.packageName);
68
- if (!existing) {
69
- mergedByPackage.set(module.packageName, {
70
- module: { ...module, entries: [] },
71
- entries: new Map(
72
- module.entries.map((entry) => [entry.qualifiedId, entry])
73
- )
74
- });
75
- continue;
76
- }
77
- existing.module = {
78
- ...existing.module,
79
- ...module,
80
- entries: [],
81
- displayName: module.displayName || existing.module.displayName,
82
- moduleMeta: module.moduleMeta || existing.module.moduleMeta
83
- };
84
- for (const entry of module.entries) {
85
- existing.entries.set(entry.qualifiedId, entry);
86
- }
87
- }
88
- return [...mergedByPackage.values()].map(({ module, entries }) => ({
89
- ...module,
90
- entries: [...entries.values()].sort((left, right) => {
91
- const orderDiff = (left.order ?? 999) - (right.order ?? 999);
92
- return orderDiff !== 0 ? orderDiff : left.title.localeCompare(right.title);
93
- })
94
- })).sort((left, right) => left.displayName.localeCompare(right.displayName));
95
- }
96
- export {
97
- displayNameForSmrtPackage as a,
98
- coercePlaygroundModules as c,
99
- displayNameForScopedPackage as d,
100
- mergePlaygroundModules as m,
101
- normalizePlaygroundModule as n,
102
- qualifyPlaygroundEntryId as q
103
- };
104
- //# sourceMappingURL=runtime-BtfwY7PF.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime-BtfwY7PF.js","sources":["../../src/utils.ts","../../src/runtime.ts"],"sourcesContent":["export function titleCase(value: string): string {\n return value\n .split(/[-_/]/)\n .filter(Boolean)\n .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))\n .join(' ');\n}\n\nexport function displayNameForSmrtPackage(packageName: string): string {\n return titleCase(packageName.replace(/^@happyvertical\\/smrt-/, ''));\n}\n\nexport function displayNameForScopedPackage(packageName: string): string {\n return titleCase(packageName.replace(/^@/, '').replace(/\\//g, ' '));\n}\n","import type {\n ResolvedSmrtPlaygroundEntry,\n ResolvedSmrtPlaygroundModule,\n SmrtPlaygroundMode,\n SmrtPlaygroundModeConfig,\n SmrtPlaygroundModule,\n SmrtPlaygroundModuleExport,\n} from './types.js';\nimport { displayNameForSmrtPackage } from './utils.js';\n\nfunction normalizeModeConfig(\n value: SmrtPlaygroundModeConfig | true | undefined,\n): SmrtPlaygroundModeConfig | undefined {\n if (!value) {\n return undefined;\n }\n return value === true ? {} : value;\n}\n\nexport function qualifyPlaygroundEntryId(\n packageName: string,\n entryId: string,\n): string {\n return `${packageName}:${entryId}`;\n}\n\nexport function coercePlaygroundModules(\n input: SmrtPlaygroundModuleExport | null | undefined,\n): SmrtPlaygroundModule[] {\n if (!input) {\n return [];\n }\n\n if (Array.isArray(input)) {\n return input.filter(Boolean);\n }\n\n if ('modules' in input && Array.isArray(input.modules)) {\n return input.modules.filter(Boolean);\n }\n\n return [input as SmrtPlaygroundModule];\n}\n\nexport function normalizePlaygroundModule(\n module: SmrtPlaygroundModule,\n): ResolvedSmrtPlaygroundModule {\n const displayName =\n module.displayName ||\n module.moduleMeta?.displayName ||\n displayNameForSmrtPackage(module.packageName);\n\n const entries: ResolvedSmrtPlaygroundEntry[] = [...(module.entries || [])]\n .map((entry) => {\n const modes = {\n mock: normalizeModeConfig(entry.modes?.mock),\n live: normalizeModeConfig(entry.modes?.live),\n };\n const availableModes = (['mock', 'live'] as SmrtPlaygroundMode[]).filter(\n (mode) => Boolean(modes[mode]),\n );\n\n if (availableModes.length === 0) {\n modes.mock = {};\n availableModes.push('mock');\n }\n\n return {\n ...entry,\n displayName,\n packageName: module.packageName,\n qualifiedId: qualifyPlaygroundEntryId(module.packageName, entry.id),\n availableModes,\n modes,\n };\n })\n .sort((left, right) => {\n const orderDiff = (left.order ?? 999) - (right.order ?? 999);\n return orderDiff !== 0\n ? orderDiff\n : left.title.localeCompare(right.title);\n });\n\n return {\n ...module,\n displayName,\n entries,\n };\n}\n\nexport function mergePlaygroundModules(\n modules: SmrtPlaygroundModule[],\n): ResolvedSmrtPlaygroundModule[] {\n // Later modules intentionally override earlier ones so app-local entries can\n // replace installed package previews by packageName + entry id.\n const mergedByPackage = new Map<\n string,\n {\n module: ResolvedSmrtPlaygroundModule;\n entries: Map<string, ResolvedSmrtPlaygroundEntry>;\n }\n >();\n\n for (const inputModule of modules) {\n const module = normalizePlaygroundModule(inputModule);\n const existing = mergedByPackage.get(module.packageName);\n\n if (!existing) {\n mergedByPackage.set(module.packageName, {\n module: { ...module, entries: [] },\n entries: new Map(\n module.entries.map((entry) => [entry.qualifiedId, entry]),\n ),\n });\n continue;\n }\n\n existing.module = {\n ...existing.module,\n ...module,\n entries: [],\n displayName: module.displayName || existing.module.displayName,\n moduleMeta: module.moduleMeta || existing.module.moduleMeta,\n };\n\n for (const entry of module.entries) {\n existing.entries.set(entry.qualifiedId, entry);\n }\n }\n\n return [...mergedByPackage.values()]\n .map(({ module, entries }) => ({\n ...module,\n entries: [...entries.values()].sort((left, right) => {\n const orderDiff = (left.order ?? 999) - (right.order ?? 999);\n return orderDiff !== 0\n ? orderDiff\n : left.title.localeCompare(right.title);\n }),\n }))\n .sort((left, right) => left.displayName.localeCompare(right.displayName));\n}\n"],"names":[],"mappings":"AAAO,SAAS,UAAU,OAAuB;AAC/C,SAAO,MACJ,MAAM,OAAO,EACb,OAAO,OAAO,EACd,IAAI,CAAC,YAAY,QAAQ,OAAO,CAAC,EAAE,gBAAgB,QAAQ,MAAM,CAAC,CAAC,EACnE,KAAK,GAAG;AACb;AAEO,SAAS,0BAA0B,aAA6B;AACrE,SAAO,UAAU,YAAY,QAAQ,0BAA0B,EAAE,CAAC;AACpE;AAEO,SAAS,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,EAAA,EACD,EACD,KAAK,CAAC,MAAM,UAAU,KAAK,YAAY,cAAc,MAAM,WAAW,CAAC;AAC5E;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}