storybook-builder-rsbuild 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,20 @@
1
1
  import * as rsbuildReal from '@rsbuild/core';
2
2
  import { RsbuildConfig } from '@rsbuild/core';
3
- import { Builder, Options, NormalizedStoriesSpecifier } from '@storybook/types';
3
+ import { TypescriptOptions as TypescriptOptions$1, Builder, Options, NormalizedStoriesSpecifier } from '@storybook/types';
4
+ import { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
4
5
 
5
6
  type RsbuildStats = {
6
7
  toJson: () => any;
7
8
  };
9
+ /**
10
+ * Options for TypeScript usage within Storybook.
11
+ */
12
+ interface TypescriptOptions extends TypescriptOptions$1 {
13
+ /**
14
+ * Configures `@rsbuild/plugin-type-check`, using `fork-ts-checker-webpack-plugin` under the hood.
15
+ */
16
+ checkOptions?: PluginTypeCheckerOptions;
17
+ }
8
18
  type RsbuildBuilder = Builder<RsbuildConfig, RsbuildStats>;
9
19
  type RsbuildFinal = (config: RsbuildConfig, options: Options) => RsbuildConfig | Promise<RsbuildConfig>;
10
20
  type StorybookConfigRsbuild = {
@@ -17,6 +27,10 @@ type BuilderOptions = {
17
27
  rsbuildConfigPath?: string;
18
28
  };
19
29
 
30
+ type RsbuildBuilderOptions = Options & {
31
+ typescriptOptions: TypescriptOptions;
32
+ };
33
+
20
34
  declare const getVirtualModules: (options: Options) => Promise<{
21
35
  virtualModules: Record<string, string>;
22
36
  entries: string[];
@@ -33,7 +47,7 @@ type BuilderStartOptions = Parameters<RsbuildBuilder['start']>['0'];
33
47
  declare const executor: {
34
48
  get: (options: Options) => Promise<typeof rsbuildReal>;
35
49
  };
36
- declare const rsbuild: (_: unknown, options: Options) => Promise<rsbuildReal.RsbuildConfig>;
50
+ declare const rsbuild: (_: unknown, options: RsbuildBuilderOptions) => Promise<rsbuildReal.RsbuildConfig>;
37
51
  declare const getConfig: RsbuildBuilder['getConfig'];
38
52
  declare function bail(): Promise<void>;
39
53
  declare const start: RsbuildBuilder['start'];
@@ -41,4 +55,4 @@ declare const build: ({ options }: BuilderStartOptions) => Promise<void>;
41
55
  declare const corePresets: string[];
42
56
  declare const previewMainTemplate: () => string;
43
57
 
44
- export { BuilderOptions, RsbuildBuilder, RsbuildFinal, StorybookConfigRsbuild, bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, rsbuild, start, toImportFn, toImportFnPart };
58
+ export { BuilderOptions, RsbuildBuilder, RsbuildFinal, StorybookConfigRsbuild, TypescriptOptions, bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, rsbuild, start, toImportFn, toImportFnPart };
package/dist/index.js CHANGED
@@ -162,7 +162,7 @@ var getVirtualModules = async (options) => {
162
162
  configDir: options.configDir,
163
163
  workingDir
164
164
  });
165
- const realPathRelativeToCwd = import_path.default.relative(workingDir, cwd);
165
+ const realPathRelativeToCwd = import_path.default.relative(workingDir, cwd).split(import_path.default.sep).join(import_path.default.posix.sep);
166
166
  const previewAnnotations = [
167
167
  ...(await options.presets.apply(
168
168
  "previewAnnotations",
@@ -272,6 +272,7 @@ function importPipeline() {
272
272
  // src/preview/iframe-rsbuild.config.ts
273
273
  var import_core = require("@rsbuild/core");
274
274
  var import_preset = require("@storybook/addon-docs/dist/preset");
275
+ var import_plugin_type_check = require("@rsbuild/plugin-type-check");
275
276
  var getAbsolutePath = (input) => (0, import_path3.dirname)(require.resolve((0, import_path3.join)(input, "package.json")));
276
277
  var maybeGetAbsolutePath = (input) => {
277
278
  try {
@@ -303,7 +304,7 @@ var iframe_rsbuild_config_default = async (options) => {
303
304
  configType,
304
305
  presets,
305
306
  previewUrl,
306
- // typescriptOptions,
307
+ typescriptOptions,
307
308
  features
308
309
  } = options;
309
310
  const isProd = configType === "PRODUCTION";
@@ -343,6 +344,8 @@ var iframe_rsbuild_config_default = async (options) => {
343
344
  configDir: options.configDir,
344
345
  workingDir
345
346
  });
347
+ const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler;
348
+ const tsCheckOptions = typescriptOptions.checkOptions || {};
346
349
  if (!template) {
347
350
  throw new Error(import_ts_dedent2.dedent`
348
351
  Storybook's Webpack5 builder requires a template to be specified.
@@ -411,6 +414,9 @@ var iframe_rsbuild_config_default = async (options) => {
411
414
  }
412
415
  }
413
416
  },
417
+ plugins: [shouldCheckTs ? (0, import_plugin_type_check.pluginTypeCheck)(tsCheckOptions) : null].filter(
418
+ Boolean
419
+ ),
414
420
  tools: {
415
421
  rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
416
422
  addRules({
package/dist/index.mjs CHANGED
@@ -12,6 +12,7 @@ import { dedent } from 'ts-dedent';
12
12
  import fs from 'fs';
13
13
  import { webpackIncludeRegexp } from '@storybook/core-webpack';
14
14
  import { webpack } from '@storybook/addon-docs/dist/preset';
15
+ import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
15
16
 
16
17
  // ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
17
18
  var require_pretty_hrtime = __commonJS({
@@ -103,7 +104,7 @@ var getVirtualModules = async (options) => {
103
104
  configDir: options.configDir,
104
105
  workingDir
105
106
  });
106
- const realPathRelativeToCwd = path.relative(workingDir, cwd);
107
+ const realPathRelativeToCwd = path.relative(workingDir, cwd).split(path.sep).join(path.posix.sep);
107
108
  const previewAnnotations = [
108
109
  ...(await options.presets.apply(
109
110
  "previewAnnotations",
@@ -242,7 +243,7 @@ var iframe_rsbuild_config_default = async (options) => {
242
243
  configType,
243
244
  presets,
244
245
  previewUrl,
245
- // typescriptOptions,
246
+ typescriptOptions,
246
247
  features
247
248
  } = options;
248
249
  const isProd = configType === "PRODUCTION";
@@ -282,6 +283,8 @@ var iframe_rsbuild_config_default = async (options) => {
282
283
  configDir: options.configDir,
283
284
  workingDir
284
285
  });
286
+ const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler;
287
+ const tsCheckOptions = typescriptOptions.checkOptions || {};
285
288
  if (!template) {
286
289
  throw new Error(dedent`
287
290
  Storybook's Webpack5 builder requires a template to be specified.
@@ -350,6 +353,9 @@ var iframe_rsbuild_config_default = async (options) => {
350
353
  }
351
354
  }
352
355
  },
356
+ plugins: [shouldCheckTs ? pluginTypeCheck(tsCheckOptions) : null].filter(
357
+ Boolean
358
+ ),
353
359
  tools: {
354
360
  rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
355
361
  addRules({
@@ -64,8 +64,16 @@ async function loader(source, map, meta) {
64
64
  `;module.exports.__namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
65
65
  );
66
66
  }
67
- const generatedMap = magicString.generateMap({ hires: true });
68
- return callback(null, magicString.toString(), generatedMap, meta);
67
+ return callback(
68
+ null,
69
+ magicString.toString(),
70
+ map ?? magicString.generateMap({
71
+ hires: true,
72
+ includeContent: true,
73
+ source: this.resourcePath
74
+ }),
75
+ meta
76
+ );
69
77
  } catch (err) {
70
78
  return callback(null, source, map, meta);
71
79
  }
@@ -31,8 +31,16 @@ async function loader(source, map, meta) {
31
31
  `;module.exports.__namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
32
32
  );
33
33
  }
34
- const generatedMap = magicString.generateMap({ hires: true });
35
- return callback(null, magicString.toString(), generatedMap, meta);
34
+ return callback(
35
+ null,
36
+ magicString.toString(),
37
+ map ?? magicString.generateMap({
38
+ hires: true,
39
+ includeContent: true,
40
+ source: this.resourcePath
41
+ }),
42
+ meta
43
+ );
36
44
  } catch (err) {
37
45
  return callback(null, source, map, meta);
38
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-builder-rsbuild",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Rsbuild builder for Storybook",
5
5
  "keywords": [
6
6
  "storybook",
@@ -56,6 +56,7 @@
56
56
  "!src/**/*"
57
57
  ],
58
58
  "dependencies": {
59
+ "@rsbuild/plugin-type-check": "0.6.15",
59
60
  "@storybook/addon-docs": "^8.0.10",
60
61
  "@storybook/channels": "^8.0.10",
61
62
  "@storybook/client-logger": "^8.0.10",