@ms-cloudpack/storybook-builder 0.1.16 → 0.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAMA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAmBxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AAOnC,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAMF,wBAAsB,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BvD;AAED,eAAO,MAAM,KAAK;aAMP,OAAO;eACL,CAAC,MAAM,EAAE,MAAM,CAAC;YACnB,MAAM;YACN,MAAM;;;;;;;EAuLf,CAAC;AAEF,eAAO,MAAM,KAAK,SAAU;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,KAAG,IAG/E,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAMA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAmBxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AAOnC,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAMF,wBAAsB,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BvD;AAED,eAAO,MAAM,KAAK;aAMP,OAAO;eACL,CAAC,MAAM,EAAE,MAAM,CAAC;YACnB,MAAM;YACN,MAAM;;;;;;;EAuKf,CAAC;AAEF,eAAO,MAAM,KAAK,SAAU;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,KAAG,IAG/E,CAAC"}
package/lib/index.js CHANGED
@@ -146,19 +146,7 @@ export const start = async ({ options, startTime, router, server: devServer, })
146
146
  input: { name: definition.name, version: definition.version },
147
147
  ctx: apiContext,
148
148
  });
149
- // Kick off bundling some packages we know are required
150
- const preBundlePackages = ['lodash'];
151
- preBundlePackages.forEach((name) => {
152
- const packageEntry = findResolveMapEntry({ packageName: name, resolveMap: session.resolveMap });
153
- if (!packageEntry) {
154
- throw new Error(`Could not find package ${name} in the resolve map.`);
155
- }
156
- void ensurePackageBundled({
157
- input: { name, version: packageEntry.version },
158
- ctx: apiContext,
159
- });
160
- });
161
- // Then start bundle and app servers for hosting the app.
149
+ // Start bundle and app servers for hosting the app.
162
150
  bundleServer = await startBundleServer({
163
151
  context: {
164
152
  ...apiContext,
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkB,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAE,cAAc,EAAkB,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAqB,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,OAAO,EAAe,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,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E,UAAU,CAAC,aAAa;QACvC,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC;IAEH,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAE1B,qEAAqE;IACrE,uEAAuE;IAEvE,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE;QAC7B,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAuD,EAAQ,EAAE;IACrF,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { getLocalCachePath, type ApiServer } from '@ms-cloudpack/api-server';\nimport { createPartialApiContext, ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport { startAppServer, type AppServer } from '@ms-cloudpack/app-server';\nimport { startBundleServer, type BundleServer } from '@ms-cloudpack/bundle-server';\nimport { readConfig } from '@ms-cloudpack/config';\nimport type { PackageJson } from '@ms-cloudpack/config-types';\nimport { express, type Router } from '@ms-cloudpack/create-express-app';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n getExportsMap,\n getVersion,\n resolve,\n} from '@ms-cloudpack/package-utilities';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport {\n TaskReporter,\n bold,\n debugLoggingConfig,\n defaultLoggingConfig,\n noLoggingConfig,\n verboseLoggingConfig,\n} from '@ms-cloudpack/task-reporter';\nimport { createTelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { Options } from '@storybook/types';\nimport fsExtra from 'fs-extra';\nimport fsPromises from 'fs/promises';\nimport { type Server } from 'http';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { generateIframeHtml } from './generateIFrameHtml.js';\nimport { getNodeModuleDir } from './getNodeModuleDir.js';\nimport { listStories } from './listStories.js';\n\nexport type ClosableServer = {\n close: () => Promise<void>;\n url: string;\n};\n\nlet appServer: AppServer;\nlet apiServer: ApiServer;\nlet bundleServer: BundleServer;\n\nexport async function bail(error?: Error): Promise<void> {\n if (error) {\n console.error('Error:', error);\n }\n\n const servers = [\n ['appServer', appServer] as const,\n ['apiServer', apiServer] as const,\n ['bundleServer', bundleServer] as const,\n ];\n\n await Promise.all(\n servers.map(async ([name, server]) => {\n if (!server || !server.url) {\n console.info(`No ${name} to close.`);\n return;\n }\n console.info(`Closing ${name}: ${server.url}`);\n try {\n await server?.close();\n console.info(`Closed ${name}: ${server.url}`);\n } catch (err) {\n console.warn('Error closing server:', err);\n }\n }),\n );\n}\n\nexport const start = async ({\n options,\n startTime,\n router,\n server: devServer,\n}: {\n options: Options;\n startTime: [number, number];\n router: Router;\n server: Server;\n}) => {\n const previewResolvedDir = getNodeModuleDir('@storybook/preview');\n const previewDirOrigin = path.join(previewResolvedDir, 'dist');\n\n router.use('/sb-preview', express.static(previewDirOrigin, { immutable: true, maxAge: '5m' }));\n\n // TODO: This might be useful later on.\n // const env = await options.presets.apply<Record<string, string>>('env');\n\n // eslint-disable-next-line no-restricted-properties -- this is the one place we need cwd (for a default)\n const appPath = process.cwd();\n\n const config = await readConfig(appPath);\n\n // TODO: Move to won package.\n // runPrerequisites(config, appPath);\n\n // Make sure the package has a valid definition.\n const definition = (await readJson(path.join(appPath, 'package.json'))) as PackageJson;\n\n if (!definition.name || !definition.version) {\n throw new Error(`The package.json at \"${appPath}\" did not have a name and/or version.`);\n }\n\n // This part should be almost identical to the cli start command.\n const reporter = new TaskReporter({\n productName: `Cloudpack`,\n version: getVersion(import.meta.url),\n description: () => `Running \"${bold('storybook')}\"`,\n helpMessage: config.helpMessage,\n // TODO: Get options and enable this.\n plainTextMode: options.ci,\n ...(options.loglevel === 'debug'\n ? debugLoggingConfig\n : options.loglevel === 'verbose'\n ? verboseLoggingConfig\n : options.quiet || options.loglevel === 'quiet'\n ? noLoggingConfig\n : defaultLoggingConfig),\n });\n\n const connectionString = options.disableTelemetry\n ? undefined\n : config.telemetry?.connectionString || process.env.CLOUDPACK_TELEMETRY_CONNECTION_STRING;\n\n const logLevel = options.loglevel === 'verbose' ? 'VERBOSE' : options.loglevel === 'debug' ? 'DEBUG' : undefined;\n if (options.loglevel !== 'debug') {\n reporter.ignoreLogMessage('ApplicationInsights:');\n }\n\n const telemetryClient = await createTelemetryClient({\n productVersion: getVersion(import.meta.url),\n connectionString,\n logLevel,\n serviceNamespace: 'cloudpack',\n serviceName: 'cli',\n rootSpanName: 'CLI',\n });\n\n // Register performance observers to track performance metrics as events of CLI span.\n // registerPerformanceObservers(telemetryClient);\n\n const apiContext = await createPartialApiContext({\n appPath,\n config,\n reporter,\n telemetryClient,\n items: ['bus', 'watcher', 'taskRunner', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n overlayPath: await resolve('@ms-cloudpack/overlay', path.dirname(fileURLToPath(import.meta.url))),\n });\n\n const { packages, session, packageImportPaths } = apiContext;\n\n // TODO: Get options and enable this.\n // Increment the session version if caching is disabled.\n // if (options.cache === false) {\n // session.incrementSessionVersion();\n // }\n\n // Set shared telemetry attributes which will be sent with all telemetry events.\n telemetryClient.setSharedSpanAttribute('sessionId', session.id);\n\n // TODO: Get options and enable this.\n // if (options.logResolveMap) {\n // // Write the resolve map to disk.\n // await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n // }\n\n // Storybook set up is mostly done here.\n const generated = await generateIframeHtml(options, { packages, session });\n await fsExtra.ensureDir(getLocalCachePath(appPath));\n\n // TODO: Currently saving it to disk as the config only accepts a path.\n const iFramePath = path.join(getLocalCachePath(appPath), 'iFrame.html');\n await fsPromises.writeFile(iFramePath, generated, { encoding: 'utf-8' });\n\n // iFrame script is required for storybook to work.\n config.devServer ??= {};\n config.devServer.routes ??= [];\n config.devServer.routes.push({\n match: '/iframe.html',\n renderScript: iFramePath,\n });\n\n const storyEntries = Object.fromEntries(\n (await listStories(options)).map((story) => {\n const storyPath = normalizeRelativePath(path.relative(appPath, story));\n return [storyPath, storyPath];\n }),\n );\n\n const packagePath = findResolveMapEntry({ packageName: definition.name, resolveMap: session.resolveMap })?.path;\n if (!packagePath) {\n throw new Error(`Could not find package ${definition.name} in the resolve map.`);\n }\n\n const exports = await getExportsMap({ packagePath }, { packages, config: session.config });\n for (const [importPath, filePath] of Object.entries(storyEntries)) {\n await addExportsMapEntry({ exports, packagePath, importPath, filePath }, { packages, config: session.config });\n }\n\n const { startApiServer } = await import('@ms-cloudpack/api-server');\n\n // Start api server for tracking status and handling remote requests.\n apiServer = await startApiServer(apiContext);\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({\n input: { name: definition.name, version: definition.version },\n ctx: apiContext,\n });\n\n // Kick off bundling some packages we know are required\n const preBundlePackages = ['lodash'];\n\n preBundlePackages.forEach((name) => {\n const packageEntry = findResolveMapEntry({ packageName: name, resolveMap: session.resolveMap });\n\n if (!packageEntry) {\n throw new Error(`Could not find package ${name} in the resolve map.`);\n }\n\n void ensurePackageBundled({\n input: { name, version: packageEntry.version },\n ctx: apiContext,\n });\n });\n\n // Then start bundle and app servers for hosting the app.\n bundleServer = await startBundleServer({\n context: {\n ...apiContext,\n apiServer,\n disableCache: false, // TODO: Get options and enable this.\n },\n });\n\n // Finally start the app server.\n appServer = await startAppServer({\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n reporter,\n packages,\n packageImportPaths,\n packageHashes: apiContext.packageHashes,\n middlewareMode: true,\n server: devServer,\n });\n\n router.use(appServer.app);\n\n // TODO: Figure out if it is possible to know when browser will open.\n // performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n\n return {\n bail,\n stats: { toJson: () => null },\n totalTime: process.hrtime(startTime),\n };\n};\n\nexport const build = (_arg: { options: Options; startTime: [number, number] }): void => {\n console.log('Cloudpack Storybook build is not implemented yet.');\n process.exit(1);\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkB,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAE,cAAc,EAAkB,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAqB,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,OAAO,EAAe,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,UAAU,EACV,OAAO,GACR,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO/C,IAAI,SAAoB,CAAC;AACzB,IAAI,SAAoB,CAAC;AACzB,IAAI,YAA0B,CAAC;AAE/B,MAAM,CAAC,KAAK,UA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,SAAS;KAClB,CAAC,CAAC;IAEH,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAE1B,qEAAqE;IACrE,uEAAuE;IAEvE,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE;QAC7B,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAuD,EAAQ,EAAE;IACrF,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { getLocalCachePath, type ApiServer } from '@ms-cloudpack/api-server';\nimport { createPartialApiContext, ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport { startAppServer, type AppServer } from '@ms-cloudpack/app-server';\nimport { startBundleServer, type BundleServer } from '@ms-cloudpack/bundle-server';\nimport { readConfig } from '@ms-cloudpack/config';\nimport type { PackageJson } from '@ms-cloudpack/config-types';\nimport { express, type Router } from '@ms-cloudpack/create-express-app';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n getExportsMap,\n getVersion,\n resolve,\n} from '@ms-cloudpack/package-utilities';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport {\n TaskReporter,\n bold,\n debugLoggingConfig,\n defaultLoggingConfig,\n noLoggingConfig,\n verboseLoggingConfig,\n} from '@ms-cloudpack/task-reporter';\nimport { createTelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { Options } from '@storybook/types';\nimport fsExtra from 'fs-extra';\nimport fsPromises from 'fs/promises';\nimport { type Server } from 'http';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { generateIframeHtml } from './generateIFrameHtml.js';\nimport { getNodeModuleDir } from './getNodeModuleDir.js';\nimport { listStories } from './listStories.js';\n\nexport type ClosableServer = {\n close: () => Promise<void>;\n url: string;\n};\n\nlet appServer: AppServer;\nlet apiServer: ApiServer;\nlet bundleServer: BundleServer;\n\nexport async function bail(error?: Error): Promise<void> {\n if (error) {\n console.error('Error:', error);\n }\n\n const servers = [\n ['appServer', appServer] as const,\n ['apiServer', apiServer] as const,\n ['bundleServer', bundleServer] as const,\n ];\n\n await Promise.all(\n servers.map(async ([name, server]) => {\n if (!server || !server.url) {\n console.info(`No ${name} to close.`);\n return;\n }\n console.info(`Closing ${name}: ${server.url}`);\n try {\n await server?.close();\n console.info(`Closed ${name}: ${server.url}`);\n } catch (err) {\n console.warn('Error closing server:', err);\n }\n }),\n );\n}\n\nexport const start = async ({\n options,\n startTime,\n router,\n server: devServer,\n}: {\n options: Options;\n startTime: [number, number];\n router: Router;\n server: Server;\n}) => {\n const previewResolvedDir = getNodeModuleDir('@storybook/preview');\n const previewDirOrigin = path.join(previewResolvedDir, 'dist');\n\n router.use('/sb-preview', express.static(previewDirOrigin, { immutable: true, maxAge: '5m' }));\n\n // TODO: This might be useful later on.\n // const env = await options.presets.apply<Record<string, string>>('env');\n\n // eslint-disable-next-line no-restricted-properties -- this is the one place we need cwd (for a default)\n const appPath = process.cwd();\n\n const config = await readConfig(appPath);\n\n // TODO: Move to won package.\n // runPrerequisites(config, appPath);\n\n // Make sure the package has a valid definition.\n const definition = (await readJson(path.join(appPath, 'package.json'))) as PackageJson;\n\n if (!definition.name || !definition.version) {\n throw new Error(`The package.json at \"${appPath}\" did not have a name and/or version.`);\n }\n\n // This part should be almost identical to the cli start command.\n const reporter = new TaskReporter({\n productName: `Cloudpack`,\n version: getVersion(import.meta.url),\n description: () => `Running \"${bold('storybook')}\"`,\n helpMessage: config.helpMessage,\n // TODO: Get options and enable this.\n plainTextMode: options.ci,\n ...(options.loglevel === 'debug'\n ? debugLoggingConfig\n : options.loglevel === 'verbose'\n ? verboseLoggingConfig\n : options.quiet || options.loglevel === 'quiet'\n ? noLoggingConfig\n : defaultLoggingConfig),\n });\n\n const connectionString = options.disableTelemetry\n ? undefined\n : config.telemetry?.connectionString || process.env.CLOUDPACK_TELEMETRY_CONNECTION_STRING;\n\n const logLevel = options.loglevel === 'verbose' ? 'VERBOSE' : options.loglevel === 'debug' ? 'DEBUG' : undefined;\n if (options.loglevel !== 'debug') {\n reporter.ignoreLogMessage('ApplicationInsights:');\n }\n\n const telemetryClient = await createTelemetryClient({\n productVersion: getVersion(import.meta.url),\n connectionString,\n logLevel,\n serviceNamespace: 'cloudpack',\n serviceName: 'cli',\n rootSpanName: 'CLI',\n });\n\n // Register performance observers to track performance metrics as events of CLI span.\n // registerPerformanceObservers(telemetryClient);\n\n const apiContext = await createPartialApiContext({\n appPath,\n config,\n reporter,\n telemetryClient,\n items: ['bus', 'watcher', 'taskRunner', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n overlayPath: await resolve('@ms-cloudpack/overlay', path.dirname(fileURLToPath(import.meta.url))),\n });\n\n const { packages, session, packageImportPaths } = apiContext;\n\n // TODO: Get options and enable this.\n // Increment the session version if caching is disabled.\n // if (options.cache === false) {\n // session.incrementSessionVersion();\n // }\n\n // Set shared telemetry attributes which will be sent with all telemetry events.\n telemetryClient.setSharedSpanAttribute('sessionId', session.id);\n\n // TODO: Get options and enable this.\n // if (options.logResolveMap) {\n // // Write the resolve map to disk.\n // await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n // }\n\n // Storybook set up is mostly done here.\n const generated = await generateIframeHtml(options, { packages, session });\n await fsExtra.ensureDir(getLocalCachePath(appPath));\n\n // TODO: Currently saving it to disk as the config only accepts a path.\n const iFramePath = path.join(getLocalCachePath(appPath), 'iFrame.html');\n await fsPromises.writeFile(iFramePath, generated, { encoding: 'utf-8' });\n\n // iFrame script is required for storybook to work.\n config.devServer ??= {};\n config.devServer.routes ??= [];\n config.devServer.routes.push({\n match: '/iframe.html',\n renderScript: iFramePath,\n });\n\n const storyEntries = Object.fromEntries(\n (await listStories(options)).map((story) => {\n const storyPath = normalizeRelativePath(path.relative(appPath, story));\n return [storyPath, storyPath];\n }),\n );\n\n const packagePath = findResolveMapEntry({ packageName: definition.name, resolveMap: session.resolveMap })?.path;\n if (!packagePath) {\n throw new Error(`Could not find package ${definition.name} in the resolve map.`);\n }\n\n const exports = await getExportsMap({ packagePath }, { packages, config: session.config });\n for (const [importPath, filePath] of Object.entries(storyEntries)) {\n await addExportsMapEntry({ exports, packagePath, importPath, filePath }, { packages, config: session.config });\n }\n\n const { startApiServer } = await import('@ms-cloudpack/api-server');\n\n // Start api server for tracking status and handling remote requests.\n apiServer = await startApiServer(apiContext);\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({\n input: { name: definition.name, version: definition.version },\n ctx: apiContext,\n });\n\n // Start bundle and app servers for hosting the app.\n bundleServer = await startBundleServer({\n context: {\n ...apiContext,\n apiServer,\n disableCache: false, // TODO: Get options and enable this.\n },\n });\n\n // Finally start the app server.\n appServer = await startAppServer({\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n reporter,\n packages,\n packageImportPaths,\n packageHashes: apiContext.packageHashes,\n middlewareMode: true,\n server: devServer,\n });\n\n router.use(appServer.app);\n\n // TODO: Figure out if it is possible to know when browser will open.\n // performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n\n return {\n bail,\n stats: { toJson: () => null },\n totalTime: process.hrtime(startTime),\n };\n};\n\nexport const build = (_arg: { options: Options; startTime: [number, number] }): void => {\n console.log('Cloudpack Storybook build is not implemented yet.');\n process.exit(1);\n};\n"]}
@@ -7,9 +7,8 @@ import type { Session } from '@ms-cloudpack/api-server';
7
7
  *
8
8
  * For node_modules, we want bare imports (so cloudpack can process them),
9
9
  * and for files in the user's source, we want URLs absolute relative to project root.
10
- *
11
10
  */
12
- export declare function processPreviewAnnotation(path: PreviewAnnotation | undefined, context: {
11
+ export declare function processPreviewAnnotation(previewPath: PreviewAnnotation | undefined, context: {
13
12
  packages: PackageDefinitionsCache;
14
13
  session: Session;
15
14
  }): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"processPreviewAnnotation.d.ts","sourceRoot":"","sources":["../../src/utils/processPreviewAnnotation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAK1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,iBAAiB,GAAG,SAAS,EACnC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,mBA8DjE"}
1
+ {"version":3,"file":"processPreviewAnnotation.d.ts","sourceRoot":"","sources":["../../src/utils/processPreviewAnnotation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAK1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,iBAAiB,GAAG,SAAS,EAC1C,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,mBAgEjE"}
@@ -1,5 +1,5 @@
1
1
  // based on https://github.com/storybookjs/storybook/blob/v7.6.5/code/builders/builder-vite/src/utils/process-preview-annotation.ts
2
- import { resolve, isAbsolute, relative } from 'path';
2
+ import path from 'path';
3
3
  import { slash } from '@ms-cloudpack/path-string-parsing';
4
4
  import { stripAbsNodeModulesPath } from '@storybook/core-common';
5
5
  import { findPackageRoot } from '@ms-cloudpack/path-utilities';
@@ -9,9 +9,8 @@ import { findPackageRoot } from '@ms-cloudpack/path-utilities';
9
9
  *
10
10
  * For node_modules, we want bare imports (so cloudpack can process them),
11
11
  * and for files in the user's source, we want URLs absolute relative to project root.
12
- *
13
12
  */
14
- export async function processPreviewAnnotation(path, context) {
13
+ export async function processPreviewAnnotation(previewPath, context) {
15
14
  const { packages, session } = context;
16
15
  const { appPath } = session;
17
16
  // If entry is an object, take the first, which is the
@@ -20,22 +19,22 @@ export async function processPreviewAnnotation(path, context) {
20
19
  // continue supporting super-addons in pnp/pnpm without
21
20
  // requiring them to re-export their sub-addons as we do
22
21
  // in addon-essentials.
23
- if (typeof path === 'object') {
24
- return path.bare;
22
+ if (typeof previewPath === 'object') {
23
+ return previewPath.bare;
25
24
  }
26
25
  // This should not occur, since we use `.filter(Boolean)` prior to
27
26
  // calling this function, but this makes typescript happy
28
- if (!path) {
27
+ if (!previewPath) {
29
28
  throw new Error('Could not determine path for previewAnnotation');
30
29
  }
31
30
  // For addon dependencies that use require.resolve(), we need to convert to a bare path
32
31
  // so that cloudpack will process it as a dependency (cjs -> esm, etc).
33
32
  // TODO: Evaluate if searching for node_modules in a yarn pnp environment is correct
34
- if (path.includes('node_modules')) {
35
- return stripAbsNodeModulesPath(path);
33
+ if (previewPath.includes('node_modules') && !previewPath.includes('.store')) {
34
+ return stripAbsNodeModulesPath(previewPath);
36
35
  }
37
36
  // resolve absolute paths relative to project root
38
- const relativePath = isAbsolute(path) ? slash(relative(appPath, path)) : path;
37
+ const relativePath = path.isAbsolute(previewPath) ? slash(path.relative(appPath, previewPath)) : previewPath;
39
38
  // resolve relative paths into absolute urls
40
39
  // note: this only works if cloudpack's appPath === cwd.
41
40
  // Add package root to relative paths.
@@ -46,10 +45,12 @@ export async function processPreviewAnnotation(path, context) {
46
45
  }
47
46
  return slash(`${definition.name}/${relativePath.replace(/^\.\//, '')}`);
48
47
  }
49
- // If something is outside of root, convert to absolute. Uncommon?
48
+ // If something is outside of root, convert to absolute.
49
+ // This can happen with a store installation layout:
50
+ // /<repo>/node_modules/.store/@storybook-react-virtual-acd5c7bee4/package
50
51
  if (relativePath.startsWith('../')) {
51
52
  // Find package and add to root.
52
- const packagePath = findPackageRoot(resolve(appPath, relativePath));
53
+ const packagePath = findPackageRoot(path.resolve(appPath, relativePath));
53
54
  if (!packagePath) {
54
55
  throw new Error(`Could not find package root for ${relativePath}`);
55
56
  }
@@ -57,7 +58,7 @@ export async function processPreviewAnnotation(path, context) {
57
58
  if (!definition) {
58
59
  throw new Error(`Could not find package definition for ${relativePath}`);
59
60
  }
60
- return slash(`${definition.name}/${relative(packagePath, resolve(appPath, relativePath))}`);
61
+ return slash(`${definition.name}/${path.relative(packagePath, path.resolve(appPath, relativePath))}`);
61
62
  }
62
63
  // At this point, it must be relative to the root but not start with a ./ or ../
63
64
  // Add package root to relative paths.
@@ -1 +1 @@
1
- {"version":3,"file":"processPreviewAnnotation.js","sourceRoot":"","sources":["../../src/utils/processPreviewAnnotation.ts"],"names":[],"mappings":"AAAA,mIAAmI;AAGnI,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,IAAmC,EACnC,OAAgE;IAEhE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,sDAAsD;IACtD,iCAAiC;IACjC,wDAAwD;IACxD,uDAAuD;IACvD,wDAAwD;IACxD,uBAAuB;IACvB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,C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;QACnD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,yCAAyC,YAAY,EAAE,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC;IAED,gFAAgF;IAChF,sCAAsC;IACtC,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,yCAAyC,OAAO,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,YAAY,EAAE,CAAC,CAAC;AACrD,CAAC","sourcesContent":["// based on https://github.com/storybookjs/storybook/blob/v7.6.5/code/builders/builder-vite/src/utils/process-preview-annotation.ts\n\nimport type { PreviewAnnotation } from '@storybook/types';\nimport { resolve, isAbsolute, relative } from 'path';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { stripAbsNodeModulesPath } from '@storybook/core-common';\nimport { findPackageRoot } from '@ms-cloudpack/path-utilities';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { Session } from '@ms-cloudpack/api-server';\n\n/**\n * Preview annotations can take several forms, and cloudpack needs them to be\n * a bit more restrained.\n *\n * For node_modules, we want bare imports (so cloudpack can process them),\n * and for files in the user's source, we want URLs absolute relative to project root.\n *\n */\nexport async function processPreviewAnnotation(\n path: PreviewAnnotation | undefined,\n context: { packages: PackageDefinitionsCache; session: Session },\n) {\n const { packages, session } = context;\n const { appPath } = session;\n // If entry is an object, take the first, which is the\n // bare (non-absolute) specifier.\n // This is so that webpack can use an absolute path, and\n // continue supporting super-addons in pnp/pnpm without\n // requiring them to re-export their sub-addons as we do\n // in addon-essentials.\n if (typeof path === 'object') {\n return path.bare;\n }\n\n // This should not occur, since we use `.filter(Boolean)` prior to\n // calling this function, but this makes typescript happy\n if (!path) {\n throw new Error('Could not determine path for previewAnnotation');\n }\n\n // For addon dependencies that use require.resolve(), we need to convert to a bare path\n // so that cloudpack will process it as a dependency (cjs -> esm, etc).\n // TODO: Evaluate if searching for node_modules in a yarn pnp environment is correct\n if (path.includes('node_modules')) {\n return stripAbsNodeModulesPath(path);\n }\n\n // resolve absolute paths relative to project root\n const relativePath = isAbsolute(path) ? slash(relative(appPath, path)) : path;\n\n // resolve relative paths into absolute urls\n // note: this only works if cloudpack's appPath === cwd.\n // Add package root to relative paths.\n if (relativePath.startsWith('./')) {\n const definition = await packages.get(appPath);\n if (!definition) {\n throw new Error(`Could not find package definition for ${appPath}`);\n }\n return slash(`${definition.name}/${relativePath.replace(/^\\.\\//, '')}`);\n }\n\n // If something is outside of root, convert to absolute. Uncommon?\n if (relativePath.startsWith('../')) {\n // Find package and add to root.\n const packagePath = findPackageRoot(resolve(appPath, relativePath));\n if (!packagePath) {\n throw new Error(`Could not find package root for ${relativePath}`);\n }\n const definition = await packages.get(packagePath);\n if (!definition) {\n throw new Error(`Could not find package definition for ${relativePath}`);\n }\n return slash(`${definition.name}/${relative(packagePath, resolve(appPath, relativePath))}`);\n }\n\n // At this point, it must be relative to the root but not start with a ./ or ../\n // Add package root to relative paths.\n const definition = await packages.get(appPath);\n if (!definition) {\n throw new Error(`Could not find package definition for ${appPath}`);\n }\n return slash(`${definition.name}/${relativePath}`);\n}\n"]}
1
+ {"version":3,"file":"processPreviewAnnotation.js","sourceRoot":"","sources":["../../src/utils/processPreviewAnnotation.ts"],"names":[],"mappings":"AAAA,mIAAmI;AAGnI,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE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AC;QACD,OAAO,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,wDAAwD;IACxD,oDAAoD;IACpD,0EAA0E;IAC1E,IAAI,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,gCAAgC;QAChC,MAAM,WAAW,GAAG,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mCAAmC,YAAY,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,yCAAyC,YAAY,EAAE,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IACxG,CAAC;IAED,gFAAgF;IAChF,sCAAsC;IACtC,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,yCAAyC,OAAO,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,YAAY,EAAE,CAAC,CAAC;AACrD,CAAC","sourcesContent":["// based on https://github.com/storybookjs/storybook/blob/v7.6.5/code/builders/builder-vite/src/utils/process-preview-annotation.ts\n\nimport type { PreviewAnnotation } from '@storybook/types';\nimport path from 'path';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { stripAbsNodeModulesPath } from '@storybook/core-common';\nimport { findPackageRoot } from '@ms-cloudpack/path-utilities';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { Session } from '@ms-cloudpack/api-server';\n\n/**\n * Preview annotations can take several forms, and cloudpack needs them to be\n * a bit more restrained.\n *\n * For node_modules, we want bare imports (so cloudpack can process them),\n * and for files in the user's source, we want URLs absolute relative to project root.\n */\nexport async function processPreviewAnnotation(\n previewPath: PreviewAnnotation | undefined,\n context: { packages: PackageDefinitionsCache; session: Session },\n) {\n const { packages, session } = context;\n const { appPath } = session;\n // If entry is an object, take the first, which is the\n // bare (non-absolute) specifier.\n // This is so that webpack can use an absolute path, and\n // continue supporting super-addons in pnp/pnpm without\n // requiring them to re-export their sub-addons as we do\n // in addon-essentials.\n if (typeof previewPath === 'object') {\n return previewPath.bare;\n }\n\n // This should not occur, since we use `.filter(Boolean)` prior to\n // calling this function, but this makes typescript happy\n if (!previewPath) {\n throw new Error('Could not determine path for previewAnnotation');\n }\n\n // For addon dependencies that use require.resolve(), we need to convert to a bare path\n // so that cloudpack will process it as a dependency (cjs -> esm, etc).\n // TODO: Evaluate if searching for node_modules in a yarn pnp environment is correct\n if (previewPath.includes('node_modules') && !previewPath.includes('.store')) {\n return stripAbsNodeModulesPath(previewPath);\n }\n\n // resolve absolute paths relative to project root\n const relativePath = path.isAbsolute(previewPath) ? slash(path.relative(appPath, previewPath)) : previewPath;\n\n // resolve relative paths into absolute urls\n // note: this only works if cloudpack's appPath === cwd.\n // Add package root to relative paths.\n if (relativePath.startsWith('./')) {\n const definition = await packages.get(appPath);\n if (!definition) {\n throw new Error(`Could not find package definition for ${appPath}`);\n }\n return slash(`${definition.name}/${relativePath.replace(/^\\.\\//, '')}`);\n }\n\n // If something is outside of root, convert to absolute.\n // This can happen with a store installation layout:\n // /<repo>/node_modules/.store/@storybook-react-virtual-acd5c7bee4/package\n if (relativePath.startsWith('../')) {\n // Find package and add to root.\n const packagePath = findPackageRoot(path.resolve(appPath, relativePath));\n if (!packagePath) {\n throw new Error(`Could not find package root for ${relativePath}`);\n }\n const definition = await packages.get(packagePath);\n if (!definition) {\n throw new Error(`Could not find package definition for ${relativePath}`);\n }\n return slash(`${definition.name}/${path.relative(packagePath, path.resolve(appPath, relativePath))}`);\n }\n\n // At this point, it must be relative to the root but not start with a ./ or ../\n // Add package root to relative paths.\n const definition = await packages.get(appPath);\n if (!definition) {\n throw new Error(`Could not find package definition for ${appPath}`);\n }\n return slash(`${definition.name}/${relativePath}`);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/storybook-builder",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "A tool for building storybook bundles for the cloudpack ecosystem.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,21 +22,22 @@
22
22
  "lint": "cloudpack-scripts lint"
23
23
  },
24
24
  "dependencies": {
25
- "@ms-cloudpack/api-server": "^0.32.2",
26
- "@ms-cloudpack/app-server": "^0.2.3",
27
- "@ms-cloudpack/bundle-server": "^0.2.33",
28
- "@ms-cloudpack/config": "^0.17.35",
29
- "@ms-cloudpack/config-types": "^0.6.0",
30
- "@ms-cloudpack/create-express-app": "^1.5.1",
25
+ "@ms-cloudpack/api-server": "^0.32.4",
26
+ "@ms-cloudpack/app-server": "^0.2.5",
27
+ "@ms-cloudpack/bundle-server": "^0.2.35",
28
+ "@ms-cloudpack/config": "^0.17.36",
29
+ "@ms-cloudpack/config-types": "^0.7.0",
30
+ "@ms-cloudpack/create-express-app": "^1.5.2",
31
31
  "@ms-cloudpack/json-utilities": "^0.1.4",
32
- "@ms-cloudpack/package-utilities": "^6.0.1",
32
+ "@ms-cloudpack/package-utilities": "^6.0.2",
33
33
  "@ms-cloudpack/path-string-parsing": "^1.2.1",
34
34
  "@ms-cloudpack/path-utilities": "^2.6.1",
35
35
  "@ms-cloudpack/task-reporter": "^0.11.2",
36
- "@ms-cloudpack/telemetry": "^0.4.6",
36
+ "@ms-cloudpack/telemetry": "^0.4.8",
37
37
  "@storybook/core-common": "7.6.5",
38
38
  "@storybook/node-logger": "7.6.5",
39
39
  "@storybook/preview": "7.6.5",
40
+ "@storybook/preview-api": "7.6.5",
40
41
  "fast-glob": "^3.2.12",
41
42
  "fs-extra": "^11.2.0"
42
43
  },