@storybook/cli 7.0.0-alpha.31 → 7.0.0-alpha.34

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.
Files changed (255) hide show
  1. package/.eslintrc.js +35 -0
  2. package/bin/index.js +1 -1
  3. package/dist/generate.d.ts +1 -0
  4. package/dist/generate.js +265 -0
  5. package/dist/generate.mjs +265 -0
  6. package/package.json +18 -12
  7. package/rendererAssets/svelte/Button.svelte +4 -3
  8. package/{dist/cjs/generators/ANGULAR → templates/angular}/template-csf/.storybook/tsconfig.json +0 -0
  9. package/{dist/cjs/generators/ANGULAR → templates/angular}/template-csf/.storybook/typings.d.ts +0 -0
  10. package/{dist/cjs/generators/AURELIA → templates/aurelia}/template-csf/.storybook/tsconfig.json +0 -0
  11. package/{dist/cjs/generators/AURELIA → templates/aurelia}/template-csf/.storybook/typings.d.ts +0 -0
  12. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/addons.js +1 -1
  13. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/index.js +13 -6
  14. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/rn-addons.js +1 -1
  15. package/templates/react-native/template-csf/storybook/stories/Button/Button.stories.js +20 -0
  16. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/stories/Button/index.js +8 -10
  17. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/stories/CenterView/index.js +8 -9
  18. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/stories/CenterView/style.js +3 -3
  19. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/stories/Welcome/Welcome.stories.js +2 -3
  20. package/templates/react-native/template-csf/storybook/stories/Welcome/index.js +57 -0
  21. package/templates/react-native/template-csf/storybook/stories/index.js +2 -0
  22. package/templates/server/template-csf/.storybook/preview.js +5 -0
  23. package/dist/cjs/NpmOptions.js +0 -1
  24. package/dist/cjs/add.js +0 -149
  25. package/dist/cjs/automigrate/fixes/angular12.js +0 -74
  26. package/dist/cjs/automigrate/fixes/builder-vite.js +0 -118
  27. package/dist/cjs/automigrate/fixes/cra5.js +0 -82
  28. package/dist/cjs/automigrate/fixes/eslint-plugin.js +0 -126
  29. package/dist/cjs/automigrate/fixes/index.js +0 -45
  30. package/dist/cjs/automigrate/fixes/mainjsFramework.js +0 -94
  31. package/dist/cjs/automigrate/fixes/new-frameworks.js +0 -258
  32. package/dist/cjs/automigrate/fixes/npm7.js +0 -57
  33. package/dist/cjs/automigrate/fixes/sb-scripts.js +0 -140
  34. package/dist/cjs/automigrate/fixes/vue3.js +0 -77
  35. package/dist/cjs/automigrate/fixes/webpack5.js +0 -151
  36. package/dist/cjs/automigrate/helpers/getEslintInfo.js +0 -28
  37. package/dist/cjs/automigrate/index.js +0 -98
  38. package/dist/cjs/automigrate/types.js +0 -5
  39. package/dist/cjs/babel-config.js +0 -65
  40. package/dist/cjs/build.js +0 -36
  41. package/dist/cjs/detect-nextjs.js +0 -33
  42. package/dist/cjs/detect-webpack.js +0 -39
  43. package/dist/cjs/detect.js +0 -179
  44. package/dist/cjs/dev.js +0 -66
  45. package/dist/cjs/dirs.js +0 -12
  46. package/dist/cjs/extract.js +0 -93
  47. package/dist/cjs/generate.js +0 -215
  48. package/dist/cjs/generators/ANGULAR/angular-helpers.js +0 -106
  49. package/dist/cjs/generators/ANGULAR/index.js +0 -95
  50. package/dist/cjs/generators/AURELIA/index.js +0 -41
  51. package/dist/cjs/generators/EMBER/index.js +0 -20
  52. package/dist/cjs/generators/HTML/index.js +0 -15
  53. package/dist/cjs/generators/MARIONETTE/index.js +0 -15
  54. package/dist/cjs/generators/MARKO/index.js +0 -15
  55. package/dist/cjs/generators/MITHRIL/index.js +0 -15
  56. package/dist/cjs/generators/PREACT/index.js +0 -15
  57. package/dist/cjs/generators/RAX/index.js +0 -28
  58. package/dist/cjs/generators/REACT/index.js +0 -15
  59. package/dist/cjs/generators/REACT_NATIVE/index.js +0 -55
  60. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/addons.js +0 -7
  61. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/index.js +0 -31
  62. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/rn-addons.js +0 -5
  63. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/Button/Button.stories.js +0 -23
  64. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/Button/index.js +0 -32
  65. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/CenterView/index.js +0 -31
  66. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/CenterView/style.js +0 -15
  67. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/Welcome/Welcome.stories.js +0 -15
  68. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/Welcome/index.js +0 -68
  69. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/index.js +0 -5
  70. package/dist/cjs/generators/REACT_SCRIPTS/index.js +0 -68
  71. package/dist/cjs/generators/RIOT/index.js +0 -17
  72. package/dist/cjs/generators/SERVER/index.js +0 -20
  73. package/dist/cjs/generators/SERVER/template-csf/.storybook/preview.js +0 -12
  74. package/dist/cjs/generators/SFC_VUE/index.js +0 -15
  75. package/dist/cjs/generators/SVELTE/index.js +0 -59
  76. package/dist/cjs/generators/VUE/index.js +0 -17
  77. package/dist/cjs/generators/VUE3/index.js +0 -17
  78. package/dist/cjs/generators/WEB-COMPONENTS/index.js +0 -17
  79. package/dist/cjs/generators/WEBPACK_REACT/index.js +0 -15
  80. package/dist/cjs/generators/baseGenerator.js +0 -208
  81. package/dist/cjs/generators/configure.js +0 -83
  82. package/dist/cjs/generators/types.js +0 -5
  83. package/dist/cjs/helpers.js +0 -258
  84. package/dist/cjs/initiate.js +0 -295
  85. package/dist/cjs/js-package-manager/JsPackageManager.js +0 -358
  86. package/dist/cjs/js-package-manager/JsPackageManagerFactory.js +0 -71
  87. package/dist/cjs/js-package-manager/NPMProxy.js +0 -112
  88. package/dist/cjs/js-package-manager/PackageJson.js +0 -5
  89. package/dist/cjs/js-package-manager/Yarn1Proxy.js +0 -72
  90. package/dist/cjs/js-package-manager/Yarn2Proxy.js +0 -68
  91. package/dist/cjs/js-package-manager/index.js +0 -44
  92. package/dist/cjs/link.js +0 -99
  93. package/dist/cjs/migrate.js +0 -33
  94. package/dist/cjs/project_types.js +0 -263
  95. package/dist/cjs/repro-generators/configs.js +0 -201
  96. package/dist/cjs/repro-generators/scripts.js +0 -338
  97. package/dist/cjs/repro-next.js +0 -182
  98. package/dist/cjs/repro-templates.js +0 -103
  99. package/dist/cjs/repro.js +0 -194
  100. package/dist/cjs/typings.d.ts +0 -3
  101. package/dist/cjs/upgrade.js +0 -170
  102. package/dist/cjs/utils.js +0 -22
  103. package/dist/cjs/versions.js +0 -89
  104. package/dist/cjs/warn.js +0 -32
  105. package/dist/cjs/window.d.js +0 -5
  106. package/dist/esm/NpmOptions.js +0 -0
  107. package/dist/esm/add.js +0 -121
  108. package/dist/esm/automigrate/fixes/angular12.js +0 -58
  109. package/dist/esm/automigrate/fixes/builder-vite.js +0 -103
  110. package/dist/esm/automigrate/fixes/cra5.js +0 -66
  111. package/dist/esm/automigrate/fixes/eslint-plugin.js +0 -111
  112. package/dist/esm/automigrate/fixes/index.js +0 -12
  113. package/dist/esm/automigrate/fixes/mainjsFramework.js +0 -76
  114. package/dist/esm/automigrate/fixes/new-frameworks.js +0 -234
  115. package/dist/esm/automigrate/fixes/npm7.js +0 -45
  116. package/dist/esm/automigrate/fixes/sb-scripts.js +0 -119
  117. package/dist/esm/automigrate/fixes/vue3.js +0 -60
  118. package/dist/esm/automigrate/fixes/webpack5.js +0 -131
  119. package/dist/esm/automigrate/helpers/getEslintInfo.js +0 -14
  120. package/dist/esm/automigrate/index.js +0 -80
  121. package/dist/esm/automigrate/types.js +0 -1
  122. package/dist/esm/babel-config.js +0 -42
  123. package/dist/esm/build.js +0 -22
  124. package/dist/esm/detect-nextjs.js +0 -24
  125. package/dist/esm/detect-webpack.js +0 -30
  126. package/dist/esm/detect.js +0 -152
  127. package/dist/esm/dev.js +0 -47
  128. package/dist/esm/dirs.js +0 -4
  129. package/dist/esm/extract.js +0 -77
  130. package/dist/esm/generate.js +0 -162
  131. package/dist/esm/generators/ANGULAR/angular-helpers.js +0 -82
  132. package/dist/esm/generators/ANGULAR/index.js +0 -76
  133. package/dist/esm/generators/ANGULAR/template-csf/.storybook/tsconfig.json +0 -10
  134. package/dist/esm/generators/ANGULAR/template-csf/.storybook/typings.d.ts +0 -4
  135. package/dist/esm/generators/AURELIA/index.js +0 -32
  136. package/dist/esm/generators/AURELIA/template-csf/.storybook/tsconfig.json +0 -9
  137. package/dist/esm/generators/AURELIA/template-csf/.storybook/typings.d.ts +0 -4
  138. package/dist/esm/generators/EMBER/index.js +0 -12
  139. package/dist/esm/generators/HTML/index.js +0 -7
  140. package/dist/esm/generators/MARIONETTE/index.js +0 -7
  141. package/dist/esm/generators/MARKO/index.js +0 -7
  142. package/dist/esm/generators/MITHRIL/index.js +0 -7
  143. package/dist/esm/generators/PREACT/index.js +0 -7
  144. package/dist/esm/generators/RAX/index.js +0 -20
  145. package/dist/esm/generators/REACT/index.js +0 -7
  146. package/dist/esm/generators/REACT_NATIVE/index.js +0 -42
  147. package/dist/esm/generators/REACT_NATIVE/template-csf/storybook/stories/Button/Button.stories.js +0 -12
  148. package/dist/esm/generators/REACT_NATIVE/template-csf/storybook/stories/Welcome/index.js +0 -54
  149. package/dist/esm/generators/REACT_NATIVE/template-csf/storybook/stories/index.js +0 -2
  150. package/dist/esm/generators/REACT_SCRIPTS/index.js +0 -49
  151. package/dist/esm/generators/RIOT/index.js +0 -9
  152. package/dist/esm/generators/SERVER/index.js +0 -11
  153. package/dist/esm/generators/SERVER/template-csf/.storybook/preview.js +0 -5
  154. package/dist/esm/generators/SFC_VUE/index.js +0 -7
  155. package/dist/esm/generators/SVELTE/index.js +0 -44
  156. package/dist/esm/generators/VUE/index.js +0 -9
  157. package/dist/esm/generators/VUE3/index.js +0 -9
  158. package/dist/esm/generators/WEB-COMPONENTS/index.js +0 -9
  159. package/dist/esm/generators/WEBPACK_REACT/index.js +0 -7
  160. package/dist/esm/generators/baseGenerator.js +0 -191
  161. package/dist/esm/generators/configure.js +0 -69
  162. package/dist/esm/generators/types.js +0 -1
  163. package/dist/esm/helpers.js +0 -207
  164. package/dist/esm/initiate.js +0 -254
  165. package/dist/esm/js-package-manager/JsPackageManager.js +0 -334
  166. package/dist/esm/js-package-manager/JsPackageManagerFactory.js +0 -57
  167. package/dist/esm/js-package-manager/NPMProxy.js +0 -99
  168. package/dist/esm/js-package-manager/PackageJson.js +0 -1
  169. package/dist/esm/js-package-manager/Yarn1Proxy.js +0 -62
  170. package/dist/esm/js-package-manager/Yarn2Proxy.js +0 -58
  171. package/dist/esm/js-package-manager/index.js +0 -3
  172. package/dist/esm/link.js +0 -69
  173. package/dist/esm/migrate.js +0 -25
  174. package/dist/esm/project_types.js +0 -248
  175. package/dist/esm/repro-generators/configs.js +0 -174
  176. package/dist/esm/repro-generators/scripts.js +0 -307
  177. package/dist/esm/repro-next.js +0 -163
  178. package/dist/esm/repro-templates.js +0 -94
  179. package/dist/esm/repro.js +0 -170
  180. package/dist/esm/typings.d.ts +0 -3
  181. package/dist/esm/upgrade.js +0 -132
  182. package/dist/esm/utils.js +0 -13
  183. package/dist/esm/versions.js +0 -82
  184. package/dist/esm/warn.js +0 -16
  185. package/dist/esm/window.d.js +0 -1
  186. package/dist/types/NpmOptions.d.ts +0 -4
  187. package/dist/types/add.d.ts +0 -10
  188. package/dist/types/automigrate/fixes/angular12.d.ts +0 -15
  189. package/dist/types/automigrate/fixes/builder-vite.d.ts +0 -19
  190. package/dist/types/automigrate/fixes/cra5.d.ts +0 -15
  191. package/dist/types/automigrate/fixes/eslint-plugin.d.ts +0 -15
  192. package/dist/types/automigrate/fixes/index.d.ts +0 -3
  193. package/dist/types/automigrate/fixes/mainjsFramework.d.ts +0 -8
  194. package/dist/types/automigrate/fixes/new-frameworks.d.ts +0 -31
  195. package/dist/types/automigrate/fixes/npm7.d.ts +0 -9
  196. package/dist/types/automigrate/fixes/sb-scripts.d.ts +0 -23
  197. package/dist/types/automigrate/fixes/vue3.d.ts +0 -15
  198. package/dist/types/automigrate/fixes/webpack5.d.ts +0 -26
  199. package/dist/types/automigrate/helpers/getEslintInfo.d.ts +0 -2
  200. package/dist/types/automigrate/index.d.ts +0 -7
  201. package/dist/types/automigrate/types.d.ts +0 -15
  202. package/dist/types/babel-config.d.ts +0 -4
  203. package/dist/types/build.d.ts +0 -1
  204. package/dist/types/detect-nextjs.d.ts +0 -2
  205. package/dist/types/detect-webpack.d.ts +0 -2
  206. package/dist/types/detect.d.ts +0 -16
  207. package/dist/types/dev.d.ts +0 -1
  208. package/dist/types/dirs.d.ts +0 -1
  209. package/dist/types/extract.d.ts +0 -1
  210. package/dist/types/generate.d.ts +0 -1
  211. package/dist/types/generators/ANGULAR/angular-helpers.d.ts +0 -6
  212. package/dist/types/generators/ANGULAR/index.d.ts +0 -3
  213. package/dist/types/generators/AURELIA/index.d.ts +0 -3
  214. package/dist/types/generators/EMBER/index.d.ts +0 -3
  215. package/dist/types/generators/HTML/index.d.ts +0 -3
  216. package/dist/types/generators/MARIONETTE/index.d.ts +0 -3
  217. package/dist/types/generators/MARKO/index.d.ts +0 -3
  218. package/dist/types/generators/MITHRIL/index.d.ts +0 -3
  219. package/dist/types/generators/PREACT/index.d.ts +0 -3
  220. package/dist/types/generators/RAX/index.d.ts +0 -3
  221. package/dist/types/generators/REACT/index.d.ts +0 -3
  222. package/dist/types/generators/REACT_NATIVE/index.d.ts +0 -4
  223. package/dist/types/generators/REACT_SCRIPTS/index.d.ts +0 -3
  224. package/dist/types/generators/RIOT/index.d.ts +0 -3
  225. package/dist/types/generators/SERVER/index.d.ts +0 -3
  226. package/dist/types/generators/SFC_VUE/index.d.ts +0 -3
  227. package/dist/types/generators/SVELTE/index.d.ts +0 -3
  228. package/dist/types/generators/VUE/index.d.ts +0 -3
  229. package/dist/types/generators/VUE3/index.d.ts +0 -3
  230. package/dist/types/generators/WEB-COMPONENTS/index.d.ts +0 -3
  231. package/dist/types/generators/WEBPACK_REACT/index.d.ts +0 -3
  232. package/dist/types/generators/baseGenerator.d.ts +0 -5
  233. package/dist/types/generators/configure.d.ts +0 -19
  234. package/dist/types/generators/types.d.ts +0 -38
  235. package/dist/types/helpers.d.ts +0 -26
  236. package/dist/types/initiate.d.ts +0 -3
  237. package/dist/types/js-package-manager/JsPackageManager.d.ts +0 -118
  238. package/dist/types/js-package-manager/JsPackageManagerFactory.d.ts +0 -4
  239. package/dist/types/js-package-manager/NPMProxy.d.ts +0 -23
  240. package/dist/types/js-package-manager/PackageJson.d.ts +0 -4
  241. package/dist/types/js-package-manager/Yarn1Proxy.d.ts +0 -17
  242. package/dist/types/js-package-manager/Yarn2Proxy.d.ts +0 -17
  243. package/dist/types/js-package-manager/index.d.ts +0 -3
  244. package/dist/types/link.d.ts +0 -7
  245. package/dist/types/migrate.d.ts +0 -1
  246. package/dist/types/project_types.d.ts +0 -64
  247. package/dist/types/repro-generators/configs.d.ts +0 -44
  248. package/dist/types/repro-generators/scripts.d.ts +0 -44
  249. package/dist/types/repro-next.d.ts +0 -8
  250. package/dist/types/repro-templates.d.ts +0 -73
  251. package/dist/types/repro.d.ts +0 -14
  252. package/dist/types/upgrade.d.ts +0 -19
  253. package/dist/types/utils.d.ts +0 -2
  254. package/dist/types/versions.d.ts +0 -82
  255. package/dist/types/warn.d.ts +0 -5
@@ -1,358 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JsPackageManager = void 0;
7
- exports.getPackageDetails = getPackageDetails;
8
-
9
- var _chalk = _interopRequireDefault(require("chalk"));
10
-
11
- var _semver = require("@storybook/semver");
12
-
13
- var _crossSpawn = require("cross-spawn");
14
-
15
- var _path = _interopRequireDefault(require("path"));
16
-
17
- var _fs = _interopRequireDefault(require("fs"));
18
-
19
- var _helpers = require("../helpers");
20
-
21
- var _versions = _interopRequireDefault(require("../versions"));
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
25
- const logger = console;
26
- /**
27
- * Extract package name and version from input
28
- *
29
- * @param pkg A string like `@storybook/cli`, `react` or `react@^16`
30
- * @return A tuple of 2 elements: [packageName, packageVersion]
31
- */
32
-
33
- function getPackageDetails(pkg) {
34
- const idx = pkg.lastIndexOf('@'); // If the only `@` is the first character, it is a scoped package
35
- // If it isn't in the string, it will be -1
36
-
37
- if (idx <= 0) {
38
- return [pkg, undefined];
39
- }
40
-
41
- const packageName = pkg.slice(0, idx);
42
- const packageVersion = pkg.slice(idx + 1);
43
- return [packageName, packageVersion];
44
- }
45
-
46
- class JsPackageManager {
47
- // NOTE: for some reason yarn prefers the npm registry in
48
- // local development, so always use npm
49
- setRegistryURL(url) {
50
- if (url) {
51
- this.executeCommand('npm', ['config', 'set', 'registry', url]);
52
- } else {
53
- this.executeCommand('npm', ['config', 'delete', 'registry']);
54
- }
55
- }
56
-
57
- getRegistryURL() {
58
- const url = this.executeCommand('npm', ['config', 'get', 'registry']).trim();
59
- return url === 'undefined' ? undefined : url;
60
- }
61
-
62
- constructor(options) {
63
- this.type = void 0;
64
- this.cwd = void 0;
65
- this.cwd = options === null || options === void 0 ? void 0 : options.cwd;
66
- }
67
- /**
68
- * Install dependencies listed in `package.json`
69
- */
70
-
71
-
72
- installDependencies() {
73
- let done = (0, _helpers.commandLog)('Preparing to install dependencies');
74
- done();
75
- logger.log();
76
- logger.log();
77
- done = (0, _helpers.commandLog)('Installing dependencies');
78
-
79
- try {
80
- this.runInstall();
81
- } catch (e) {
82
- done('An error occurred while installing dependencies.');
83
- process.exit(1);
84
- }
85
-
86
- done();
87
- }
88
-
89
- packageJsonPath() {
90
- return this.cwd ? _path.default.resolve(this.cwd, 'package.json') : _path.default.resolve('package.json');
91
- }
92
-
93
- readPackageJson() {
94
- const packageJsonPath = this.packageJsonPath();
95
-
96
- if (!_fs.default.existsSync(packageJsonPath)) {
97
- throw new Error(`Could not read package.json file at ${packageJsonPath}`);
98
- }
99
-
100
- const jsonContent = _fs.default.readFileSync(packageJsonPath, 'utf8');
101
-
102
- return JSON.parse(jsonContent);
103
- }
104
-
105
- writePackageJson(packageJson) {
106
- const content = `${JSON.stringify(packageJson, null, 2)}\n`;
107
-
108
- _fs.default.writeFileSync(this.packageJsonPath(), content, 'utf8');
109
- }
110
- /**
111
- * Read the `package.json` file available in the directory the command was call from
112
- * If there is no `package.json` it will create one.
113
- */
114
-
115
-
116
- retrievePackageJson() {
117
- let packageJson;
118
-
119
- try {
120
- packageJson = this.readPackageJson();
121
- } catch (err) {
122
- this.initPackageJson();
123
- packageJson = this.readPackageJson();
124
- }
125
-
126
- return Object.assign({}, packageJson, {
127
- dependencies: Object.assign({}, packageJson.dependencies),
128
- devDependencies: Object.assign({}, packageJson.devDependencies)
129
- });
130
- }
131
- /**
132
- * Add dependencies to a project using `yarn add` or `npm install`.
133
- *
134
- * @param {Object} options contains `skipInstall`, `packageJson` and `installAsDevDependencies` which we use to determine how we install packages.
135
- * @param {Array} dependencies contains a list of packages to add.
136
- * @example
137
- * addDependencies(options, [
138
- * `@storybook/react@${storybookVersion}`,
139
- * `@storybook/addon-actions@${actionsVersion}`,
140
- * `@storybook/addon-links@${linksVersion}`,
141
- * `@storybook/addons@${addonsVersion}`,
142
- * ]);
143
- */
144
-
145
-
146
- addDependencies(options, dependencies) {
147
- const {
148
- skipInstall
149
- } = options;
150
-
151
- if (skipInstall) {
152
- const {
153
- packageJson
154
- } = options;
155
- const dependenciesMap = dependencies.reduce((acc, dep) => {
156
- const [packageName, packageVersion] = getPackageDetails(dep);
157
- return Object.assign({}, acc, {
158
- [packageName]: packageVersion
159
- });
160
- }, {});
161
-
162
- if (options.installAsDevDependencies) {
163
- packageJson.devDependencies = Object.assign({}, packageJson.devDependencies, dependenciesMap);
164
- } else {
165
- packageJson.dependencies = Object.assign({}, packageJson.dependencies, dependenciesMap);
166
- }
167
-
168
- this.writePackageJson(packageJson);
169
- } else {
170
- try {
171
- this.runAddDeps(dependencies, options.installAsDevDependencies);
172
- } catch (e) {
173
- logger.error('An error occurred while installing dependencies.');
174
- logger.log(e.message);
175
- process.exit(1);
176
- }
177
- }
178
- }
179
- /**
180
- * Remove dependencies from a project using `yarn remove` or `npm uninstall`.
181
- *
182
- * @param {Object} options contains `skipInstall`, `packageJson` and `installAsDevDependencies` which we use to determine how we install packages.
183
- * @param {Array} dependencies contains a list of packages to remove.
184
- * @example
185
- * removeDependencies(options, [
186
- * `@storybook/react`,
187
- * `@storybook/addon-actions`,
188
- * ]);
189
- */
190
-
191
-
192
- removeDependencies(options, dependencies) {
193
- const {
194
- skipInstall
195
- } = options;
196
-
197
- if (skipInstall) {
198
- const {
199
- packageJson
200
- } = options;
201
- dependencies.forEach(dep => {
202
- if (packageJson.devDependencies) {
203
- delete packageJson.devDependencies[dep];
204
- }
205
-
206
- if (packageJson.dependencies) {
207
- delete packageJson.dependencies[dep];
208
- }
209
- });
210
- this.writePackageJson(packageJson);
211
- } else {
212
- try {
213
- this.runRemoveDeps(dependencies);
214
- } catch (e) {
215
- logger.error('An error occurred while removing dependencies.');
216
- logger.log(e.message);
217
- process.exit(1);
218
- }
219
- }
220
- }
221
- /**
222
- * Return an array of strings matching following format: `<package_name>@<package_latest_version>`
223
- *
224
- * @param packages
225
- */
226
-
227
-
228
- getVersionedPackages(packages) {
229
- return Promise.all(packages.map(async pkg => {
230
- const [packageName, packageVersion] = getPackageDetails(pkg);
231
- return `${packageName}@${await this.getVersion(packageName, packageVersion)}`;
232
- }));
233
- }
234
- /**
235
- * Return an array of string standing for the latest version of the input packages.
236
- * To be able to identify which version goes with which package the order of the input array is keep.
237
- *
238
- * @param packageNames
239
- */
240
-
241
-
242
- getVersions(...packageNames) {
243
- return Promise.all(packageNames.map(packageName => {
244
- return this.getVersion(packageName);
245
- }));
246
- }
247
- /**
248
- * Return the latest version of the input package available on npmjs registry.
249
- * If constraint are provided it return the latest version matching the constraints.
250
- *
251
- * For `@storybook/*` packages the latest version is retrieved from `cli/src/versions.json` file directly
252
- *
253
- * @param packageName The name of the package
254
- * @param constraint A valid semver constraint, example: '1.x || >=2.5.0 || 5.0.0 - 7.2.3'
255
- */
256
-
257
-
258
- async getVersion(packageName, constraint) {
259
- let current;
260
-
261
- if (/(@storybook|^sb$|^storybook$)/.test(packageName)) {
262
- // @ts-ignore
263
- current = _versions.default[packageName];
264
- }
265
-
266
- let latest;
267
-
268
- try {
269
- latest = await this.latestVersion(packageName, constraint);
270
- } catch (e) {
271
- if (current) {
272
- logger.warn(`\n ${_chalk.default.yellow(e.message)}`);
273
- return current;
274
- }
275
-
276
- logger.error(`\n ${_chalk.default.red(e.message)}`);
277
- process.exit(1);
278
- }
279
-
280
- const versionToUse = current && (!constraint || (0, _semver.satisfies)(current, constraint)) && (0, _semver.gt)(current, latest) ? current : latest;
281
- return `^${versionToUse}`;
282
- }
283
- /**
284
- * Get the latest version of the package available on npmjs.com.
285
- * If constraint is set then it returns a version satisfying it, otherwise the latest version available is returned.
286
- *
287
- * @param packageName Name of the package
288
- * @param constraint Version range to use to constraint the returned version
289
- */
290
-
291
-
292
- async latestVersion(packageName, constraint) {
293
- if (!constraint) {
294
- return this.runGetVersions(packageName, false);
295
- }
296
-
297
- const versions = await this.runGetVersions(packageName, true); // Get the latest version satisfying the constraint
298
-
299
- return versions.reverse().find(version => (0, _semver.satisfies)(version, constraint));
300
- }
301
-
302
- addStorybookCommandInScripts(options) {
303
- const sbPort = (options === null || options === void 0 ? void 0 : options.port) ?? 6006;
304
- const storybookCmd = options !== null && options !== void 0 && options.staticFolder ? `npx storybook dev -p ${sbPort} -s ${options.staticFolder}` : `npx storybook dev -p ${sbPort}`;
305
- const buildStorybookCmd = options !== null && options !== void 0 && options.staticFolder ? `npx storybook build -s ${options.staticFolder}` : `npx storybook build`;
306
- const preCommand = options !== null && options !== void 0 && options.preCommand ? this.getRunCommand(options.preCommand) : undefined;
307
- this.addScripts({
308
- storybook: [preCommand, storybookCmd].filter(Boolean).join(' && '),
309
- 'build-storybook': [preCommand, buildStorybookCmd].filter(Boolean).join(' && ')
310
- });
311
- }
312
-
313
- addESLintConfig() {
314
- var _packageJson$eslintCo;
315
-
316
- const packageJson = this.retrievePackageJson();
317
- this.writePackageJson(Object.assign({}, packageJson, {
318
- eslintConfig: Object.assign({}, packageJson.eslintConfig, {
319
- overrides: [...(((_packageJson$eslintCo = packageJson.eslintConfig) === null || _packageJson$eslintCo === void 0 ? void 0 : _packageJson$eslintCo.overrides) || []), {
320
- files: ['**/*.stories.*'],
321
- rules: {
322
- 'import/no-anonymous-default-export': 'off'
323
- }
324
- }]
325
- })
326
- }));
327
- }
328
-
329
- addScripts(scripts) {
330
- const packageJson = this.retrievePackageJson();
331
- this.writePackageJson(Object.assign({}, packageJson, {
332
- scripts: Object.assign({}, packageJson.scripts, scripts)
333
- }));
334
- }
335
-
336
- addPackageResolutions(versions) {
337
- const packageJson = this.retrievePackageJson();
338
- const resolutions = this.getResolutions(packageJson, versions);
339
- this.writePackageJson(Object.assign({}, packageJson, resolutions));
340
- }
341
-
342
- executeCommand(command, args, stdio) {
343
- const commandResult = (0, _crossSpawn.sync)(command, args, {
344
- cwd: this.cwd,
345
- stdio: stdio ?? 'pipe',
346
- encoding: 'utf-8'
347
- });
348
-
349
- if (commandResult.status !== 0) {
350
- throw new Error(commandResult.stderr ?? '');
351
- }
352
-
353
- return commandResult.stdout ?? '';
354
- }
355
-
356
- }
357
-
358
- exports.JsPackageManager = JsPackageManager;
@@ -1,71 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JsPackageManagerFactory = void 0;
7
-
8
- var _crossSpawn = require("cross-spawn");
9
-
10
- var _findUp = require("find-up");
11
-
12
- var _NPMProxy = require("./NPMProxy");
13
-
14
- var _Yarn2Proxy = require("./Yarn2Proxy");
15
-
16
- var _Yarn1Proxy = require("./Yarn1Proxy");
17
-
18
- class JsPackageManagerFactory {
19
- static getPackageManager(forceNpmUsage = false, cwd) {
20
- if (forceNpmUsage) {
21
- return new _NPMProxy.NPMProxy({
22
- cwd
23
- });
24
- }
25
-
26
- const yarnVersion = getYarnVersion(cwd);
27
- const hasYarnLockFile = (0, _findUp.sync)('yarn.lock', {
28
- cwd
29
- });
30
- const hasNPMCommand = hasNPM(cwd);
31
-
32
- if (yarnVersion && (hasYarnLockFile || !hasNPMCommand)) {
33
- return yarnVersion === 1 ? new _Yarn1Proxy.Yarn1Proxy({
34
- cwd
35
- }) : new _Yarn2Proxy.Yarn2Proxy({
36
- cwd
37
- });
38
- }
39
-
40
- if (hasNPMCommand) {
41
- return new _NPMProxy.NPMProxy({
42
- cwd
43
- });
44
- }
45
-
46
- throw new Error('Unable to find a usable package manager within NPM, Yarn and Yarn 2');
47
- }
48
-
49
- }
50
-
51
- exports.JsPackageManagerFactory = JsPackageManagerFactory;
52
-
53
- function hasNPM(cwd) {
54
- const npmVersionCommand = (0, _crossSpawn.sync)('npm', ['--version'], {
55
- cwd
56
- });
57
- return npmVersionCommand.status === 0;
58
- }
59
-
60
- function getYarnVersion(cwd) {
61
- const yarnVersionCommand = (0, _crossSpawn.sync)('yarn', ['--version'], {
62
- cwd
63
- });
64
-
65
- if (yarnVersionCommand.status !== 0) {
66
- return undefined;
67
- }
68
-
69
- const yarnVersion = yarnVersionCommand.output.toString().replace(/,/g, '').replace(/"/g, '');
70
- return /^1\.+/.test(yarnVersion) ? 1 : 2;
71
- }
@@ -1,112 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.NPMProxy = void 0;
7
-
8
- var _semver = _interopRequireDefault(require("@storybook/semver"));
9
-
10
- var _JsPackageManager = require("./JsPackageManager");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- class NPMProxy extends _JsPackageManager.JsPackageManager {
15
- constructor(...args) {
16
- super(...args);
17
- this.type = 'npm';
18
- this.installArgs = void 0;
19
- this.uninstallArgs = void 0;
20
- }
21
-
22
- initPackageJson() {
23
- return this.executeCommand('npm', ['init', '-y']);
24
- }
25
-
26
- getRunStorybookCommand() {
27
- return 'npm run storybook';
28
- }
29
-
30
- getRunCommand(command) {
31
- return `npm run ${command}`;
32
- }
33
-
34
- getNpmVersion() {
35
- return this.executeCommand('npm', ['--version']);
36
- }
37
-
38
- hasLegacyPeerDeps() {
39
- const result = this.executeCommand('npm', ['config', 'get', 'legacy-peer-deps', '--location=project']);
40
- return result.trim() === 'true';
41
- }
42
-
43
- setLegacyPeerDeps() {
44
- this.executeCommand('npm', ['config', 'set', 'legacy-peer-deps=true', '--location=project']);
45
- }
46
-
47
- needsLegacyPeerDeps(version) {
48
- return _semver.default.gte(version, '7.0.0') && !this.hasLegacyPeerDeps();
49
- }
50
-
51
- getInstallArgs() {
52
- if (!this.installArgs) {
53
- this.installArgs = this.needsLegacyPeerDeps(this.getNpmVersion()) ? ['install', '--legacy-peer-deps'] : ['install'];
54
- }
55
-
56
- return this.installArgs;
57
- }
58
-
59
- getUninstallArgs() {
60
- if (!this.uninstallArgs) {
61
- this.uninstallArgs = this.needsLegacyPeerDeps(this.getNpmVersion()) ? ['uninstall', '--legacy-peer-deps'] : ['uninstall'];
62
- }
63
-
64
- return this.uninstallArgs;
65
- }
66
-
67
- getResolutions(packageJson, versions) {
68
- return {
69
- overrides: Object.assign({}, packageJson.overrides, versions)
70
- };
71
- }
72
-
73
- runInstall() {
74
- this.executeCommand('npm', this.getInstallArgs(), 'inherit');
75
- }
76
-
77
- runAddDeps(dependencies, installAsDevDependencies) {
78
- let args = [...dependencies];
79
-
80
- if (installAsDevDependencies) {
81
- args = ['-D', ...args];
82
- }
83
-
84
- this.executeCommand('npm', [...this.getInstallArgs(), ...args], 'inherit');
85
- }
86
-
87
- runRemoveDeps(dependencies) {
88
- const args = [...dependencies];
89
- this.executeCommand('npm', [...this.getUninstallArgs(), ...args], 'inherit');
90
- }
91
-
92
- runGetVersions(packageName, fetchAllVersions) {
93
- const args = [fetchAllVersions ? 'versions' : 'version', '--json'];
94
- const commandResult = this.executeCommand('npm', ['info', packageName, ...args]);
95
-
96
- try {
97
- const parsedOutput = JSON.parse(commandResult);
98
-
99
- if (parsedOutput.error) {
100
- // FIXME: improve error handling
101
- throw new Error(parsedOutput.error.summary);
102
- } else {
103
- return parsedOutput;
104
- }
105
- } catch (e) {
106
- throw new Error(`Unable to find versions of ${packageName} using npm`);
107
- }
108
- }
109
-
110
- }
111
-
112
- exports.NPMProxy = NPMProxy;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,72 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Yarn1Proxy = void 0;
7
-
8
- var _JsPackageManager = require("./JsPackageManager");
9
-
10
- class Yarn1Proxy extends _JsPackageManager.JsPackageManager {
11
- constructor(...args) {
12
- super(...args);
13
- this.type = 'yarn1';
14
- }
15
-
16
- initPackageJson() {
17
- return this.executeCommand('yarn', ['init', '-y']);
18
- }
19
-
20
- getRunStorybookCommand() {
21
- return 'yarn storybook';
22
- }
23
-
24
- getRunCommand(command) {
25
- return `yarn ${command}`;
26
- }
27
-
28
- getResolutions(packageJson, versions) {
29
- return {
30
- resolutions: Object.assign({}, packageJson.resolutions, versions)
31
- };
32
- }
33
-
34
- runInstall() {
35
- this.executeCommand('yarn', [], 'inherit');
36
- }
37
-
38
- runAddDeps(dependencies, installAsDevDependencies) {
39
- let args = ['--ignore-workspace-root-check', ...dependencies];
40
-
41
- if (installAsDevDependencies) {
42
- args = ['-D', ...args];
43
- }
44
-
45
- this.executeCommand('yarn', ['add', ...args], 'inherit');
46
- }
47
-
48
- runRemoveDeps(dependencies) {
49
- const args = ['--ignore-workspace-root-check', ...dependencies];
50
- this.executeCommand('yarn', ['remove', ...args], 'inherit');
51
- }
52
-
53
- runGetVersions(packageName, fetchAllVersions) {
54
- const args = [fetchAllVersions ? 'versions' : 'version', '--json'];
55
- const commandResult = this.executeCommand('yarn', ['info', packageName, ...args]);
56
-
57
- try {
58
- const parsedOutput = JSON.parse(commandResult);
59
-
60
- if (parsedOutput.type === 'inspect') {
61
- return parsedOutput.data;
62
- }
63
-
64
- throw new Error(`Unable to find versions of ${packageName} using yarn`);
65
- } catch (e) {
66
- throw new Error(`Unable to find versions of ${packageName} using yarn`);
67
- }
68
- }
69
-
70
- }
71
-
72
- exports.Yarn1Proxy = Yarn1Proxy;
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Yarn2Proxy = void 0;
7
-
8
- var _JsPackageManager = require("./JsPackageManager");
9
-
10
- class Yarn2Proxy extends _JsPackageManager.JsPackageManager {
11
- constructor(...args) {
12
- super(...args);
13
- this.type = 'yarn2';
14
- }
15
-
16
- initPackageJson() {
17
- return this.executeCommand('yarn', ['init']);
18
- }
19
-
20
- getRunStorybookCommand() {
21
- return 'yarn storybook';
22
- }
23
-
24
- getRunCommand(command) {
25
- return `yarn ${command}`;
26
- }
27
-
28
- getResolutions(packageJson, versions) {
29
- return {
30
- resolutions: Object.assign({}, packageJson.resolutions, versions)
31
- };
32
- }
33
-
34
- runInstall() {
35
- this.executeCommand('yarn', [], 'inherit');
36
- }
37
-
38
- runAddDeps(dependencies, installAsDevDependencies) {
39
- let args = [...dependencies];
40
-
41
- if (installAsDevDependencies) {
42
- args = ['-D', ...args];
43
- }
44
-
45
- this.executeCommand('yarn', ['add', ...args], 'inherit');
46
- }
47
-
48
- runRemoveDeps(dependencies) {
49
- const args = [...dependencies];
50
- this.executeCommand('yarn', ['remove', ...args], 'inherit');
51
- }
52
-
53
- runGetVersions(packageName, fetchAllVersions) {
54
- const field = fetchAllVersions ? 'versions' : 'version';
55
- const args = ['--fields', field, '--json'];
56
- const commandResult = this.executeCommand('yarn', ['npm', 'info', packageName, ...args]);
57
-
58
- try {
59
- const parsedOutput = JSON.parse(commandResult);
60
- return parsedOutput[field];
61
- } catch (e) {
62
- throw new Error(`Unable to find versions of ${packageName} using yarn 2`);
63
- }
64
- }
65
-
66
- }
67
-
68
- exports.Yarn2Proxy = Yarn2Proxy;