@storybook/preset-server-webpack 7.0.0-alpha.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Kadira Inc. <hello@kadira.io>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Storybook Webpack preset for Server
2
+
3
+ This package is a [preset](https://storybook.js.org/docs/react/addons/writing-presets#presets-api) that configures Storybook's webpack settings for handling React.
4
+ It's an internal package that's not intended to be used directly by users.
5
+
6
+ - More info on [Storybook for Server](https://github.com/storybookjs/storybook/tree/main/frameworks/server-webpack5)
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.webpack = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var webpack = function webpack(config) {
13
+ config.module.rules.push({
14
+ type: 'javascript/auto',
15
+ test: /\.stories\.json$/,
16
+ use: _path.default.resolve(__dirname, './loader.js')
17
+ });
18
+ config.module.rules.push({
19
+ type: 'javascript/auto',
20
+ test: /\.stories\.ya?ml/,
21
+ use: [_path.default.resolve(__dirname, './loader.js'), 'yaml-loader']
22
+ });
23
+ return config;
24
+ };
25
+
26
+ exports.webpack = webpack;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.compileCsfModule = compileCsfModule;
7
+
8
+ require("core-js/modules/es.object.assign.js");
9
+
10
+ var _stringifier = require("./stringifier");
11
+
12
+ function createSection(args) {
13
+ return Object.assign({
14
+ imports: {},
15
+ decorators: []
16
+ }, args);
17
+ }
18
+
19
+ function compileCsfModule(args) {
20
+ return (0, _stringifier.stringifySection)(createSection(args));
21
+ }
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.js");
4
+
5
+ require("core-js/modules/es.symbol.description.js");
6
+
7
+ require("core-js/modules/es.object.to-string.js");
8
+
9
+ require("core-js/modules/es.symbol.iterator.js");
10
+
11
+ require("core-js/modules/es.array.iterator.js");
12
+
13
+ require("core-js/modules/es.string.iterator.js");
14
+
15
+ require("core-js/modules/web.dom-collections.iterator.js");
16
+
17
+ require("core-js/modules/es.array.slice.js");
18
+
19
+ require("core-js/modules/es.array.from.js");
20
+
21
+ require("core-js/modules/es.regexp.exec.js");
22
+
23
+ require("core-js/modules/es.object.freeze.js");
24
+
25
+ Object.defineProperty(exports, "__esModule", {
26
+ value: true
27
+ });
28
+ exports.stringifyDecorators = stringifyDecorators;
29
+ exports.stringifyDefault = stringifyDefault;
30
+ exports.stringifyImports = stringifyImports;
31
+ exports.stringifyObject = stringifyObject;
32
+ exports.stringifySection = stringifySection;
33
+ exports.stringifyStory = stringifyStory;
34
+
35
+ require("core-js/modules/es.string.repeat.js");
36
+
37
+ require("core-js/modules/es.array.map.js");
38
+
39
+ require("core-js/modules/es.array.join.js");
40
+
41
+ require("core-js/modules/es.array.concat.js");
42
+
43
+ require("core-js/modules/es.object.keys.js");
44
+
45
+ require("core-js/modules/es.object.entries.js");
46
+
47
+ require("core-js/modules/es.array.sort.js");
48
+
49
+ require("core-js/modules/es.function.name.js");
50
+
51
+ require("core-js/modules/es.object.assign.js");
52
+
53
+ var _tsDedent = _interopRequireDefault(require("ts-dedent"));
54
+
55
+ var _templateObject;
56
+
57
+ var _excluded = ["title", "imports", "decorators", "stories"],
58
+ _excluded2 = ["name"];
59
+
60
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
61
+
62
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
63
+
64
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
65
+
66
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
67
+
68
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
69
+
70
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
71
+
72
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
73
+
74
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
75
+
76
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
77
+
78
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
79
+
80
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
81
+
82
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
83
+
84
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
85
+
86
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
87
+
88
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
89
+
90
+ var _require = require('safe-identifier'),
91
+ identifier = _require.identifier;
92
+
93
+ function stringifyObject(object) {
94
+ var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
95
+ var excludeOuterParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
96
+
97
+ if (typeof object === 'string') {
98
+ return JSON.stringify(object);
99
+ }
100
+
101
+ var indent = ' '.repeat(level);
102
+
103
+ if (Array.isArray(object)) {
104
+ var arrayStrings = object.map(function (item) {
105
+ return stringifyObject(item, level + 1);
106
+ });
107
+ var arrayString = arrayStrings.join(",\n".concat(indent, " "));
108
+ if (excludeOuterParams) return arrayString;
109
+ return "[\n".concat(indent, " ").concat(arrayString, "\n").concat(indent, "]");
110
+ }
111
+
112
+ if (_typeof(object) === 'object') {
113
+ var objectString = '';
114
+
115
+ if (Object.keys(object).length > 0) {
116
+ var objectStrings = Object.keys(object).map(function (key) {
117
+ var value = stringifyObject(object[key], level + 1);
118
+ return "\n".concat(indent, " ").concat(key, ": ").concat(value);
119
+ });
120
+ objectString = objectStrings.join(',');
121
+ }
122
+
123
+ if (excludeOuterParams) return objectString;
124
+ if (objectString.length === 0) return '{}';
125
+ return "{".concat(objectString, "\n").concat(indent, "}");
126
+ }
127
+
128
+ return object;
129
+ }
130
+
131
+ function stringifyImports(imports) {
132
+ if (Object.keys(imports).length === 0) return '';
133
+ return Object.entries(imports).map(function (_ref) {
134
+ var _ref2 = _slicedToArray(_ref, 2),
135
+ module = _ref2[0],
136
+ names = _ref2[1];
137
+
138
+ return "import { ".concat(names.sort().join(', '), " } from '").concat(module, "';\n");
139
+ }).join('');
140
+ }
141
+
142
+ function stringifyDecorators(decorators) {
143
+ return decorators && decorators.length > 0 ? "\n decorators: [\n ".concat(decorators.join(',\n '), "\n ],") : '';
144
+ }
145
+
146
+ function stringifyDefault(section) {
147
+ var title = section.title,
148
+ imports = section.imports,
149
+ decorators = section.decorators,
150
+ stories = section.stories,
151
+ options = _objectWithoutProperties(section, _excluded);
152
+
153
+ var decoratorsString = stringifyDecorators(decorators);
154
+ var optionsString = stringifyObject(options, 0, true);
155
+ return (0, _tsDedent.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n export default {\n title: ", ",", "", "\n };\n \n "])), JSON.stringify(title), decoratorsString, optionsString);
156
+ }
157
+
158
+ function stringifyStory(story) {
159
+ var name = story.name,
160
+ options = _objectWithoutProperties(story, _excluded2);
161
+
162
+ var storyId = identifier(name);
163
+ var exportedStory = Object.assign({
164
+ name: name
165
+ }, options);
166
+ var storyStrings = ["export const ".concat(storyId, " = ").concat(stringifyObject(exportedStory), ";"), ''];
167
+ return storyStrings.join('\n');
168
+ }
169
+
170
+ function stringifySection(section) {
171
+ var sectionString = [stringifyImports(section.imports), stringifyDefault(section)].concat(_toConsumableArray(section.stories.map(function (story) {
172
+ return stringifyStory(story);
173
+ }))).join('\n');
174
+ return sectionString;
175
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _compiler = require("./lib/compiler");
9
+
10
+ var _default = function _default(content) {
11
+ try {
12
+ var after = (0, _compiler.compileCsfModule)(JSON.parse(content));
13
+ return after;
14
+ } catch (e) {//
15
+ }
16
+
17
+ return content;
18
+ };
19
+
20
+ exports.default = _default;
@@ -0,0 +1,14 @@
1
+ import path from 'path';
2
+ export const webpack = config => {
3
+ config.module.rules.push({
4
+ type: 'javascript/auto',
5
+ test: /\.stories\.json$/,
6
+ use: path.resolve(__dirname, './loader.js')
7
+ });
8
+ config.module.rules.push({
9
+ type: 'javascript/auto',
10
+ test: /\.stories\.ya?ml/,
11
+ use: [path.resolve(__dirname, './loader.js'), 'yaml-loader']
12
+ });
13
+ return config;
14
+ };
@@ -0,0 +1,12 @@
1
+ import { stringifySection } from './stringifier';
2
+
3
+ function createSection(args) {
4
+ return Object.assign({
5
+ imports: {},
6
+ decorators: []
7
+ }, args);
8
+ }
9
+
10
+ export function compileCsfModule(args) {
11
+ return stringifySection(createSection(args));
12
+ }
@@ -0,0 +1,83 @@
1
+ const _excluded = ["title", "imports", "decorators", "stories"],
2
+ _excluded2 = ["name"];
3
+
4
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5
+
6
+ import dedent from 'ts-dedent';
7
+
8
+ const {
9
+ identifier
10
+ } = require('safe-identifier');
11
+
12
+ export function stringifyObject(object, level = 0, excludeOuterParams = false) {
13
+ if (typeof object === 'string') {
14
+ return JSON.stringify(object);
15
+ }
16
+
17
+ const indent = ' '.repeat(level);
18
+
19
+ if (Array.isArray(object)) {
20
+ const arrayStrings = object.map(item => stringifyObject(item, level + 1));
21
+ const arrayString = arrayStrings.join(`,\n${indent} `);
22
+ if (excludeOuterParams) return arrayString;
23
+ return `[\n${indent} ${arrayString}\n${indent}]`;
24
+ }
25
+
26
+ if (typeof object === 'object') {
27
+ let objectString = '';
28
+
29
+ if (Object.keys(object).length > 0) {
30
+ const objectStrings = Object.keys(object).map(key => {
31
+ const value = stringifyObject(object[key], level + 1);
32
+ return `\n${indent} ${key}: ${value}`;
33
+ });
34
+ objectString = objectStrings.join(',');
35
+ }
36
+
37
+ if (excludeOuterParams) return objectString;
38
+ if (objectString.length === 0) return '{}';
39
+ return `{${objectString}\n${indent}}`;
40
+ }
41
+
42
+ return object;
43
+ }
44
+ export function stringifyImports(imports) {
45
+ if (Object.keys(imports).length === 0) return '';
46
+ return Object.entries(imports).map(([module, names]) => `import { ${names.sort().join(', ')} } from '${module}';\n`).join('');
47
+ }
48
+ export function stringifyDecorators(decorators) {
49
+ return decorators && decorators.length > 0 ? `\n decorators: [\n ${decorators.join(',\n ')}\n ],` : '';
50
+ }
51
+ export function stringifyDefault(section) {
52
+ const {
53
+ title,
54
+ decorators
55
+ } = section,
56
+ options = _objectWithoutPropertiesLoose(section, _excluded);
57
+
58
+ const decoratorsString = stringifyDecorators(decorators);
59
+ const optionsString = stringifyObject(options, 0, true);
60
+ return dedent`
61
+ export default {
62
+ title: ${JSON.stringify(title)},${decoratorsString}${optionsString}
63
+ };
64
+
65
+ `;
66
+ }
67
+ export function stringifyStory(story) {
68
+ const {
69
+ name
70
+ } = story,
71
+ options = _objectWithoutPropertiesLoose(story, _excluded2);
72
+
73
+ const storyId = identifier(name);
74
+ const exportedStory = Object.assign({
75
+ name
76
+ }, options);
77
+ const storyStrings = [`export const ${storyId} = ${stringifyObject(exportedStory)};`, ''];
78
+ return storyStrings.join('\n');
79
+ }
80
+ export function stringifySection(section) {
81
+ const sectionString = [stringifyImports(section.imports), stringifyDefault(section), ...section.stories.map(story => stringifyStory(story))].join('\n');
82
+ return sectionString;
83
+ }
File without changes
@@ -0,0 +1,10 @@
1
+ import { compileCsfModule } from './lib/compiler';
2
+ export default (content => {
3
+ try {
4
+ const after = compileCsfModule(JSON.parse(content));
5
+ return after;
6
+ } catch (e) {//
7
+ }
8
+
9
+ return content;
10
+ });
@@ -0,0 +1,2 @@
1
+ import type { StorybookConfig } from '@storybook/core-webpack';
2
+ export declare const webpack: StorybookConfig['webpack'];
@@ -0,0 +1,2 @@
1
+ import { CompileCsfModuleArgs } from './types';
2
+ export declare function compileCsfModule(args: CompileCsfModuleArgs): string;
@@ -0,0 +1,7 @@
1
+ import { StorybookStory, StorybookSection } from './types';
2
+ export declare function stringifyObject(object: any, level?: number, excludeOuterParams?: boolean): string;
3
+ export declare function stringifyImports(imports: Record<string, string[]>): string;
4
+ export declare function stringifyDecorators(decorators: string[]): string;
5
+ export declare function stringifyDefault(section: StorybookSection): string;
6
+ export declare function stringifyStory(story: StorybookStory): string;
7
+ export declare function stringifySection(section: StorybookSection): string;
@@ -0,0 +1,24 @@
1
+ export interface CompileStorybookStoryArgs {
2
+ name: string;
3
+ [x: string]: any;
4
+ }
5
+ export interface CompileStorybookSectionArgs {
6
+ title: string;
7
+ stories: CompileStorybookStoryArgs[];
8
+ [x: string]: any;
9
+ }
10
+ export interface CompileCsfModuleArgs extends CompileStorybookSectionArgs {
11
+ addons?: string[];
12
+ }
13
+ export interface StorybookStory {
14
+ name: string;
15
+ decorators?: string[];
16
+ [x: string]: any;
17
+ }
18
+ export interface StorybookSection {
19
+ imports: Record<string, string[]>;
20
+ decorators?: string[];
21
+ title: string;
22
+ stories: StorybookStory[];
23
+ [x: string]: any;
24
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: (content: string) => string;
2
+ export default _default;
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@storybook/preset-server-webpack",
3
+ "version": "7.0.0-alpha.0",
4
+ "description": "Storybook for Server: View HTML snippets from a server in isolation with Hot Reloading.",
5
+ "keywords": [
6
+ "storybook"
7
+ ],
8
+ "homepage": "https://github.com/storybookjs/storybook/tree/main/presets/server-webpack",
9
+ "bugs": {
10
+ "url": "https://github.com/storybookjs/storybook/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/storybookjs/storybook.git",
15
+ "directory": "presets/server-webpack"
16
+ },
17
+ "funding": {
18
+ "type": "opencollective",
19
+ "url": "https://opencollective.com/storybook"
20
+ },
21
+ "license": "MIT",
22
+ "main": "dist/cjs/index.js",
23
+ "module": "dist/esm/index.js",
24
+ "types": "dist/types/index.d.ts",
25
+ "files": [
26
+ "dist/**/*",
27
+ "README.md",
28
+ "*.js",
29
+ "*.d.ts"
30
+ ],
31
+ "scripts": {
32
+ "prepare": "node ../../scripts/prepare.js"
33
+ },
34
+ "dependencies": {
35
+ "@storybook/core-server": "7.0.0-alpha.0",
36
+ "@storybook/core-webpack": "7.0.0-alpha.0",
37
+ "@storybook/server": "7.0.0-alpha.0",
38
+ "@types/node": "^14.14.20 || ^16.0.0",
39
+ "core-js": "^3.8.2",
40
+ "global": "^4.4.0",
41
+ "react": "16.14.0",
42
+ "react-dom": "16.14.0",
43
+ "regenerator-runtime": "^0.13.7",
44
+ "safe-identifier": "^0.4.1",
45
+ "ts-dedent": "^2.0.0",
46
+ "yaml-loader": "^0.8.0"
47
+ },
48
+ "devDependencies": {
49
+ "fs-extra": "^9.0.1",
50
+ "jest-specific-snapshot": "^4.0.0",
51
+ "yaml": "^1.10.0"
52
+ },
53
+ "engines": {
54
+ "node": ">=10.13.0"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "gitHead": "c82d897ea765da8cf4fbbcc2af1f28c808a93e23"
60
+ }
package/preset.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/index');