@web/storybook-builder 0.1.6 → 0.1.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @web/storybook-builder
2
2
 
3
+ ## 0.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - cbcc56f2: fix tocbot exports for addon-docs
8
+ - 5a428555: prebundle required CommonJS modules for addon-docs
9
+ - 916da5f0: resolve @storybook/react-dom-shim for addon-docs
10
+
3
11
  ## 0.1.6
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'esbuild';
2
+ export declare function esbuildPluginCommonjsNamedExports(module: string, namedExports: string[]): Plugin;
3
+ //# sourceMappingURL=esbuild-plugin-commonjs-named-exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild-plugin-commonjs-named-exports.d.ts","sourceRoot":"","sources":["../src/esbuild-plugin-commonjs-named-exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,CA0BhG"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.esbuildPluginCommonjsNamedExports = void 0;
4
+ function esbuildPluginCommonjsNamedExports(module, namedExports) {
5
+ return {
6
+ name: 'commonjs-named-exports',
7
+ setup(build) {
8
+ build.onResolve({ filter: new RegExp(`^${module}$`) }, args => {
9
+ return {
10
+ path: args.path,
11
+ namespace: `commonjs-named-exports-${module}`,
12
+ pluginData: {
13
+ resolveDir: args.resolveDir,
14
+ },
15
+ };
16
+ });
17
+ build.onLoad({ filter: /.*/, namespace: `commonjs-named-exports-${module}` }, async (args) => {
18
+ return {
19
+ resolveDir: args.pluginData.resolveDir,
20
+ contents: `
21
+ import { default as commonjsExports } from '${module}?force-original';
22
+ ${namedExports
23
+ .map(name => `export const ${name} = commonjsExports.${name};`)
24
+ .join('\n')}
25
+ `,
26
+ };
27
+ });
28
+ },
29
+ };
30
+ }
31
+ exports.esbuildPluginCommonjsNamedExports = esbuildPluginCommonjsNamedExports;
32
+ //# sourceMappingURL=esbuild-plugin-commonjs-named-exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild-plugin-commonjs-named-exports.js","sourceRoot":"","sources":["../src/esbuild-plugin-commonjs-named-exports.ts"],"names":[],"mappings":";;;AAEA,SAAgB,iCAAiC,CAAC,MAAc,EAAE,YAAsB;IACtF,OAAO;QACL,IAAI,EAAE,wBAAwB;QAC9B,KAAK,CAAC,KAAK;YACT,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE;gBAC5D,OAAO;oBACL,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,SAAS,EAAE,0BAA0B,MAAM,EAAE;oBAC7C,UAAU,EAAE;wBACV,UAAU,EAAE,IAAI,CAAC,UAAU;qBAC5B;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,0BAA0B,MAAM,EAAE,EAAE,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;gBACzF,OAAO;oBACL,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU;oBACtC,QAAQ,EAAE;0DACsC,MAAM;cAClD,YAAY;yBACX,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,gBAAgB,IAAI,sBAAsB,IAAI,GAAG,CAAC;yBAC9D,IAAI,CAAC,IAAI,CAAC;WACd;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AA1BD,8EA0BC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-plugin-prebundle-modules.d.ts","sourceRoot":"","sources":["../src/rollup-plugin-prebundle-modules.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,eAAO,MAAM,sBAAsB,qCAAqC,CAAC;AAEzE,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CA0ChF;AAiBD,eAAO,MAAM,UAAU,UAoBtB,CAAC"}
1
+ {"version":3,"file":"rollup-plugin-prebundle-modules.d.ts","sourceRoot":"","sources":["../src/rollup-plugin-prebundle-modules.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIrC,eAAO,MAAM,sBAAsB,qCAAqC,CAAC;AAEzE,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAsDhF;AAKD,eAAO,MAAM,UAAU,UA2BtB,CAAC"}
@@ -27,6 +27,7 @@ exports.CANDIDATES = exports.rollupPluginPrebundleModules = exports.PREBUNDLED_M
27
27
  const core_common_1 = require("@storybook/core-common");
28
28
  const esbuild_1 = require("esbuild");
29
29
  const path_1 = require("path");
30
+ const esbuild_plugin_commonjs_named_exports_js_1 = require("./esbuild-plugin-commonjs-named-exports.js");
30
31
  const get_node_module_dir_js_1 = require("./get-node-module-dir.js");
31
32
  exports.PREBUNDLED_MODULES_DIR = 'node_modules/.prebundled_modules';
32
33
  function rollupPluginPrebundleModules(env) {
@@ -34,8 +35,8 @@ function rollupPluginPrebundleModules(env) {
34
35
  return {
35
36
  name: 'rollup-plugin-prebundle-modules',
36
37
  async buildStart() {
37
- const esbuildCommonjsPlugin = (await Promise.resolve().then(() => __importStar(require('@chialab/esbuild-plugin-commonjs')))).default; // for CJS compatibility
38
- const modules = getModules();
38
+ const esbuildPluginCommonjs = (await Promise.resolve().then(() => __importStar(require('@chialab/esbuild-plugin-commonjs')))).default; // for CJS compatibility
39
+ const modules = exports.CANDIDATES.filter(moduleExists);
39
40
  for (const module of modules) {
40
41
  modulePaths[module] = (0, path_1.join)(process.cwd(), exports.PREBUNDLED_MODULES_DIR, module.endsWith('.js') ? module : `${module}.js`);
41
42
  }
@@ -46,13 +47,17 @@ function rollupPluginPrebundleModules(env) {
46
47
  format: 'esm',
47
48
  splitting: true,
48
49
  sourcemap: true,
49
- alias: {
50
- assert: require.resolve('browser-assert'),
51
- lodash: (0, get_node_module_dir_js_1.getNodeModuleDir)('lodash-es'),
52
- path: require.resolve('path-browserify'),
53
- },
50
+ alias: Object.assign({ assert: require.resolve('browser-assert'), lodash: (0, get_node_module_dir_js_1.getNodeModuleDir)('lodash-es'), path: require.resolve('path-browserify') }, (moduleExists('@storybook/react-dom-shim') && {
51
+ '@storybook/react-dom-shim': getReactDomShimAlias(),
52
+ })),
54
53
  define: Object.assign({}, (0, core_common_1.stringifyProcessEnvs)(env)),
55
- plugins: [esbuildCommonjsPlugin()],
54
+ plugins: [
55
+ /* for @storybook/addon-docs */
56
+ // tocbot can't be automatically transformed by @chialab/esbuild-plugin-commonjs
57
+ // so we need a manual wrapper
58
+ (0, esbuild_plugin_commonjs_named_exports_js_1.esbuildPluginCommonjsNamedExports)('tocbot', ['init', 'destroy']),
59
+ esbuildPluginCommonjs(),
60
+ ],
56
61
  });
57
62
  },
58
63
  async resolveId(source) {
@@ -61,22 +66,14 @@ function rollupPluginPrebundleModules(env) {
61
66
  };
62
67
  }
63
68
  exports.rollupPluginPrebundleModules = rollupPluginPrebundleModules;
64
- function getModules() {
65
- const include = exports.CANDIDATES.filter(id => {
66
- try {
67
- require.resolve(id, { paths: [process.cwd()] });
68
- return true;
69
- }
70
- catch (e) {
71
- return false;
72
- }
73
- });
74
- return include;
75
- }
76
69
  // this is different to https://github.com/storybookjs/storybook/blob/v7.0.0/code/lib/builder-vite/src/optimizeDeps.ts#L7
77
70
  // builder-vite bundles different dependencies for performance reasons
78
71
  // we aim only at browserifying NodeJS dependencies (CommonJS/process.env/...)
79
72
  exports.CANDIDATES = [
73
+ /* for different packages */
74
+ 'tiny-invariant',
75
+ /* for @storybook/addon-interactions */
76
+ 'jest-mock',
80
77
  // @testing-library has ESM, but imports/exports are not working correctly between packages
81
78
  // specifically "@testing-library/user-event" has "dist/esm/utils/misc/getWindow.js" (see https://cdn.jsdelivr.net/npm/@testing-library/user-event@14.4.3/dist/esm/utils/misc/getWindow.js)
82
79
  // which uses "@testing-library/dom" in `import { getWindowFromNode } from '@testing-library/dom/dist/helpers.js';`
@@ -84,13 +81,33 @@ exports.CANDIDATES = [
84
81
  // and instead gets resolved to "@testing-library/dom" CommonJS "dist/helpers.js" (see https://cdn.jsdelivr.net/npm/@testing-library/dom@9.3.1/dist/helpers.js)
85
82
  '@testing-library/dom',
86
83
  '@testing-library/user-event',
87
- // CommonJS module used in Storybook MJS files
84
+ /* for @storybook/addon-docs */
85
+ '@storybook/react-dom-shim',
86
+ 'color-convert',
88
87
  'doctrine',
89
- // CommonJS module used in Storybook MJS files
90
- 'jest-mock',
91
- // CommonJS module used in Storybook MJS files
88
+ 'lodash/cloneDeep.js',
92
89
  'lodash/mapValues.js',
93
- // ESM, but uses `process.env.NODE_ENV`
94
- 'tiny-invariant',
90
+ 'lodash/pickBy.js',
91
+ 'lodash/throttle.js',
92
+ 'lodash/uniq.js',
93
+ 'memoizerific',
94
+ 'react',
95
+ 'react-dom',
96
+ 'tocbot',
95
97
  ];
98
+ function getReactDomShimAlias() {
99
+ const { version } = require('react-dom');
100
+ return version.startsWith('18')
101
+ ? require.resolve('@storybook/react-dom-shim/dist/react-18').replace(/\.js$/, '.mjs')
102
+ : require.resolve('@storybook/react-dom-shim').replace(/\.js$/, '.mjs');
103
+ }
104
+ function moduleExists(moduleName) {
105
+ try {
106
+ require.resolve(moduleName, { paths: [process.cwd()] });
107
+ return true;
108
+ }
109
+ catch (e) {
110
+ return false;
111
+ }
112
+ }
96
113
  //# sourceMappingURL=rollup-plugin-prebundle-modules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-plugin-prebundle-modules.js","sourceRoot":"","sources":["../src/rollup-plugin-prebundle-modules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA8D;AAC9D,qCAAgC;AAChC,+BAA4B;AAE5B,qEAA4D;AAE/C,QAAA,sBAAsB,GAAG,kCAAkC,CAAC;AAEzE,SAAgB,4BAA4B,CAAC,GAA2B;IACtE,MAAM,WAAW,GAA2B,EAAE,CAAC;IAE/C,OAAO;QACL,IAAI,EAAE,iCAAiC;QAEvC,KAAK,CAAC,UAAU;YACd,MAAM,qBAAqB,GAAG,CAAC,wDAAa,kCAAkC,GAAC,CAAC,CAAC,OAAO,CAAC,CAAC,wBAAwB;YAElH,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAE7B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,WAAW,CAAC,MAAM,CAAC,GAAG,IAAA,WAAI,EACxB,OAAO,CAAC,GAAG,EAAE,EACb,8BAAsB,EACtB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,CACjD,CAAC;aACH;YAED,MAAM,IAAA,eAAK,EAAC;gBACV,WAAW,EAAE,OAAO;gBACpB,MAAM,EAAE,8BAAsB;gBAC9B,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,IAAI;gBACf,KAAK,EAAE;oBACL,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC;oBACzC,MAAM,EAAE,IAAA,yCAAgB,EAAC,WAAW,CAAC;oBACrC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;iBACzC;gBACD,MAAM,oBACD,IAAA,kCAAoB,EAAC,GAAG,CAAC,CAC7B;gBACD,OAAO,EAAE,CAAC,qBAAqB,EAAE,CAAC;aACnC,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,MAAM;YACpB,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC;AA1CD,oEA0CC;AAED,SAAS,UAAU;IACjB,MAAM,OAAO,GAAG,kBAAU,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;QACrC,IAAI;YACF,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,KAAK,CAAC;SACd;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,yHAAyH;AACzH,sEAAsE;AACtE,8EAA8E;AACjE,QAAA,UAAU,GAAG;IACxB,2FAA2F;IAC3F,2LAA2L;IAC3L,mHAAmH;IACnH,uKAAuK;IACvK,+JAA+J;IAC/J,sBAAsB;IACtB,6BAA6B;IAE7B,8CAA8C;IAC9C,UAAU;IAEV,8CAA8C;IAC9C,WAAW;IAEX,8CAA8C;IAC9C,qBAAqB;IAErB,uCAAuC;IACvC,gBAAgB;CACjB,CAAC"}
1
+ {"version":3,"file":"rollup-plugin-prebundle-modules.js","sourceRoot":"","sources":["../src/rollup-plugin-prebundle-modules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA8D;AAC9D,qCAAgC;AAChC,+BAA4B;AAE5B,yGAA+F;AAC/F,qEAA4D;AAE/C,QAAA,sBAAsB,GAAG,kCAAkC,CAAC;AAEzE,SAAgB,4BAA4B,CAAC,GAA2B;IACtE,MAAM,WAAW,GAA2B,EAAE,CAAC;IAE/C,OAAO;QACL,IAA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,MAAM,CAAC,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC;AAtDD,oEAsDC;AAED,yHAAyH;AACzH,sEAAsE;AACtE,8EAA8E;AACjE,QAAA,UAAU,GAAG;IACxB,4BAA4B;IAC5B,gBAAgB;IAEhB,uCAAuC;IACvC,WAAW;IACX,2FAA2F;IAC3F,2LAA2L;IAC3L,mHAAmH;IACnH,uKAAuK;IACvK,+JAA+J;IAC/J,sBAAsB;IACtB,6BAA6B;IAE7B,+BAA+B;IAC/B,2BAA2B;IAC3B,eAAe;IACf,UAAU;IACV,qBAAqB;IACrB,qBAAqB;IACrB,kBAAkB;IAClB,oBAAoB;IACpB,gBAAgB;IAChB,cAAc;IACd,OAAO;IACP,WAAW;IACX,QAAQ;CACT,CAAC;AAEF,SAAS,oBAAoB;IAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;QAC7B,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,yCAAyC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;QACrF,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,YAAY,CAAC,UAAkB;IACtC,IAAI;QACF,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@web/storybook-builder",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },