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