@storybook/cli 7.0.0-beta.61 → 7.0.0-beta.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-ZKUAYCCT.mjs → chunk-INFU6FKX.mjs} +3 -3
- package/dist/generate.js +233 -5545
- package/dist/generate.mjs +218 -4314
- package/dist/index.js +10 -845
- package/dist/index.mjs +1 -12
- package/package.json +10 -10
- package/dist/chunk-HBVTX4IN.mjs +0 -1239
package/dist/chunk-HBVTX4IN.mjs
DELETED
|
@@ -1,1239 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
// src/js-package-manager/deprecations.ts
|
|
10
|
-
import deprecate from "util-deprecate";
|
|
11
|
-
var useNpmWarning = deprecate(
|
|
12
|
-
() => {
|
|
13
|
-
},
|
|
14
|
-
`\`--use-npm\` is deprecated and will be removed in Storybook 8.0.
|
|
15
|
-
Please use the \`--package-manager=npm\` option instead.
|
|
16
|
-
Read more at https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#cli-option---use-npm-deprecated`
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
// src/js-package-manager/JsPackageManager.ts
|
|
20
|
-
import chalk2 from "chalk";
|
|
21
|
-
import { gt, satisfies as satisfies2 } from "semver";
|
|
22
|
-
import { sync as spawnSync } from "cross-spawn";
|
|
23
|
-
import path2 from "path";
|
|
24
|
-
import fs2 from "fs";
|
|
25
|
-
|
|
26
|
-
// src/helpers.ts
|
|
27
|
-
import path, { join as join2 } from "path";
|
|
28
|
-
import fs from "fs";
|
|
29
|
-
import fse from "fs-extra";
|
|
30
|
-
import chalk from "chalk";
|
|
31
|
-
import { satisfies } from "semver";
|
|
32
|
-
import stripJsonComments from "strip-json-comments";
|
|
33
|
-
|
|
34
|
-
// src/dirs.ts
|
|
35
|
-
import { dirname, join } from "path";
|
|
36
|
-
import downloadTarball from "@ndelangen/get-tarball";
|
|
37
|
-
import getNpmTarballUrl from "get-npm-tarball-url";
|
|
38
|
-
import * as tempy from "tempy";
|
|
39
|
-
|
|
40
|
-
// src/project_types.ts
|
|
41
|
-
import { minVersion, validRange } from "semver";
|
|
42
|
-
function ltMajor(versionRange, major) {
|
|
43
|
-
return validRange(versionRange) && minVersion(versionRange).major < major;
|
|
44
|
-
}
|
|
45
|
-
function gtMajor(versionRange, major) {
|
|
46
|
-
return validRange(versionRange) && minVersion(versionRange).major > major;
|
|
47
|
-
}
|
|
48
|
-
function eqMajor(versionRange, major) {
|
|
49
|
-
return validRange(versionRange) && minVersion(versionRange).major === major;
|
|
50
|
-
}
|
|
51
|
-
var externalFrameworks = [
|
|
52
|
-
{ name: "qwik", packageName: "storybook-framework-qwik" },
|
|
53
|
-
{ name: "solid", frameworks: ["storybook-solidjs-vite"], renderer: "storybook-solidjs" }
|
|
54
|
-
];
|
|
55
|
-
var SUPPORTED_RENDERERS = [
|
|
56
|
-
"react",
|
|
57
|
-
"react-native",
|
|
58
|
-
"vue",
|
|
59
|
-
"vue3",
|
|
60
|
-
"angular",
|
|
61
|
-
"mithril",
|
|
62
|
-
"riot",
|
|
63
|
-
"ember",
|
|
64
|
-
"marionette",
|
|
65
|
-
"marko",
|
|
66
|
-
"preact",
|
|
67
|
-
"svelte",
|
|
68
|
-
"qwik",
|
|
69
|
-
"rax",
|
|
70
|
-
"aurelia",
|
|
71
|
-
"solid"
|
|
72
|
-
];
|
|
73
|
-
var ProjectType = /* @__PURE__ */ ((ProjectType2) => {
|
|
74
|
-
ProjectType2["UNDETECTED"] = "UNDETECTED";
|
|
75
|
-
ProjectType2["UNSUPPORTED"] = "UNSUPPORTED";
|
|
76
|
-
ProjectType2["REACT_SCRIPTS"] = "REACT_SCRIPTS";
|
|
77
|
-
ProjectType2["REACT"] = "REACT";
|
|
78
|
-
ProjectType2["REACT_NATIVE"] = "REACT_NATIVE";
|
|
79
|
-
ProjectType2["REACT_PROJECT"] = "REACT_PROJECT";
|
|
80
|
-
ProjectType2["WEBPACK_REACT"] = "WEBPACK_REACT";
|
|
81
|
-
ProjectType2["NEXTJS"] = "NEXTJS";
|
|
82
|
-
ProjectType2["VUE"] = "VUE";
|
|
83
|
-
ProjectType2["VUE3"] = "VUE3";
|
|
84
|
-
ProjectType2["SFC_VUE"] = "SFC_VUE";
|
|
85
|
-
ProjectType2["ANGULAR"] = "ANGULAR";
|
|
86
|
-
ProjectType2["EMBER"] = "EMBER";
|
|
87
|
-
ProjectType2["WEB_COMPONENTS"] = "WEB_COMPONENTS";
|
|
88
|
-
ProjectType2["MITHRIL"] = "MITHRIL";
|
|
89
|
-
ProjectType2["MARIONETTE"] = "MARIONETTE";
|
|
90
|
-
ProjectType2["MARKO"] = "MARKO";
|
|
91
|
-
ProjectType2["HTML"] = "HTML";
|
|
92
|
-
ProjectType2["QWIK"] = "QWIK";
|
|
93
|
-
ProjectType2["RIOT"] = "RIOT";
|
|
94
|
-
ProjectType2["PREACT"] = "PREACT";
|
|
95
|
-
ProjectType2["SVELTE"] = "SVELTE";
|
|
96
|
-
ProjectType2["SVELTEKIT"] = "SVELTEKIT";
|
|
97
|
-
ProjectType2["RAX"] = "RAX";
|
|
98
|
-
ProjectType2["AURELIA"] = "AURELIA";
|
|
99
|
-
ProjectType2["SERVER"] = "SERVER";
|
|
100
|
-
ProjectType2["NX"] = "NX";
|
|
101
|
-
ProjectType2["SOLID"] = "SOLID";
|
|
102
|
-
return ProjectType2;
|
|
103
|
-
})(ProjectType || {});
|
|
104
|
-
var supportedTemplates = [
|
|
105
|
-
{
|
|
106
|
-
preset: "SFC_VUE" /* SFC_VUE */,
|
|
107
|
-
dependencies: {
|
|
108
|
-
"vue-loader": (versionRange) => ltMajor(versionRange, 16),
|
|
109
|
-
vuetify: (versionRange) => ltMajor(versionRange, 3)
|
|
110
|
-
},
|
|
111
|
-
matcherFunction: ({ dependencies }) => {
|
|
112
|
-
return dependencies.some(Boolean);
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
preset: "VUE" /* VUE */,
|
|
117
|
-
// This Vue template only works with Vue or Nuxt under v3
|
|
118
|
-
dependencies: {
|
|
119
|
-
vue: (versionRange) => ltMajor(versionRange, 3),
|
|
120
|
-
nuxt: (versionRange) => ltMajor(versionRange, 3)
|
|
121
|
-
},
|
|
122
|
-
matcherFunction: ({ dependencies }) => {
|
|
123
|
-
return dependencies.some(Boolean);
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
preset: "VUE3" /* VUE3 */,
|
|
128
|
-
dependencies: {
|
|
129
|
-
// This Vue template works with Vue 3
|
|
130
|
-
vue: (versionRange) => versionRange === "next" || eqMajor(versionRange, 3)
|
|
131
|
-
},
|
|
132
|
-
matcherFunction: ({ dependencies }) => {
|
|
133
|
-
return dependencies.some(Boolean);
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
preset: "EMBER" /* EMBER */,
|
|
138
|
-
dependencies: ["ember-cli"],
|
|
139
|
-
matcherFunction: ({ dependencies }) => {
|
|
140
|
-
return dependencies.every(Boolean);
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
preset: "NEXTJS" /* NEXTJS */,
|
|
145
|
-
dependencies: {
|
|
146
|
-
next: (versionRange) => eqMajor(versionRange, 9) || gtMajor(versionRange, 9)
|
|
147
|
-
},
|
|
148
|
-
matcherFunction: ({ dependencies }) => {
|
|
149
|
-
return dependencies.every(Boolean);
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
preset: "QWIK" /* QWIK */,
|
|
154
|
-
dependencies: ["@builder.io/qwik"],
|
|
155
|
-
matcherFunction: ({ dependencies }) => {
|
|
156
|
-
return dependencies.every(Boolean);
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
preset: "REACT_PROJECT" /* REACT_PROJECT */,
|
|
161
|
-
peerDependencies: ["react"],
|
|
162
|
-
matcherFunction: ({ peerDependencies }) => {
|
|
163
|
-
return peerDependencies.every(Boolean);
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
preset: "REACT_NATIVE" /* REACT_NATIVE */,
|
|
168
|
-
dependencies: ["react-native", "react-native-scripts"],
|
|
169
|
-
matcherFunction: ({ dependencies }) => {
|
|
170
|
-
return dependencies.some(Boolean);
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
preset: "REACT_SCRIPTS" /* REACT_SCRIPTS */,
|
|
175
|
-
// For projects using a custom/forked `react-scripts` package.
|
|
176
|
-
files: ["/node_modules/.bin/react-scripts"],
|
|
177
|
-
// For standard CRA projects
|
|
178
|
-
dependencies: ["react-scripts"],
|
|
179
|
-
matcherFunction: ({ dependencies, files }) => {
|
|
180
|
-
return dependencies.every(Boolean) || files.every(Boolean);
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
preset: "ANGULAR" /* ANGULAR */,
|
|
185
|
-
dependencies: ["@angular/core"],
|
|
186
|
-
matcherFunction: ({ dependencies }) => {
|
|
187
|
-
return dependencies.every(Boolean);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
preset: "WEB_COMPONENTS" /* WEB_COMPONENTS */,
|
|
192
|
-
dependencies: ["lit-element", "lit-html", "lit"],
|
|
193
|
-
matcherFunction: ({ dependencies }) => {
|
|
194
|
-
return dependencies.some(Boolean);
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
preset: "MITHRIL" /* MITHRIL */,
|
|
199
|
-
dependencies: ["mithril"],
|
|
200
|
-
matcherFunction: ({ dependencies }) => {
|
|
201
|
-
return dependencies.every(Boolean);
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
preset: "MARIONETTE" /* MARIONETTE */,
|
|
206
|
-
dependencies: ["backbone.marionette"],
|
|
207
|
-
matcherFunction: ({ dependencies }) => {
|
|
208
|
-
return dependencies.every(Boolean);
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
preset: "MARKO" /* MARKO */,
|
|
213
|
-
dependencies: ["marko"],
|
|
214
|
-
matcherFunction: ({ dependencies }) => {
|
|
215
|
-
return dependencies.every(Boolean);
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
preset: "RIOT" /* RIOT */,
|
|
220
|
-
dependencies: ["riot"],
|
|
221
|
-
matcherFunction: ({ dependencies }) => {
|
|
222
|
-
return dependencies.every(Boolean);
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
preset: "PREACT" /* PREACT */,
|
|
227
|
-
dependencies: ["preact"],
|
|
228
|
-
matcherFunction: ({ dependencies }) => {
|
|
229
|
-
return dependencies.every(Boolean);
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
// TODO: This only works because it is before the SVELTE template. could be more explicit
|
|
234
|
-
preset: "SVELTEKIT" /* SVELTEKIT */,
|
|
235
|
-
dependencies: ["@sveltejs/kit"],
|
|
236
|
-
matcherFunction: ({ dependencies }) => {
|
|
237
|
-
return dependencies.every(Boolean);
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
preset: "SVELTE" /* SVELTE */,
|
|
242
|
-
dependencies: ["svelte"],
|
|
243
|
-
matcherFunction: ({ dependencies }) => {
|
|
244
|
-
return dependencies.every(Boolean);
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
preset: "RAX" /* RAX */,
|
|
249
|
-
dependencies: ["rax"],
|
|
250
|
-
matcherFunction: ({ dependencies }) => {
|
|
251
|
-
return dependencies.every(Boolean);
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
preset: "AURELIA" /* AURELIA */,
|
|
256
|
-
dependencies: ["aurelia-bootstrapper"],
|
|
257
|
-
matcherFunction: ({ dependencies }) => {
|
|
258
|
-
return dependencies.every(Boolean);
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
preset: "SOLID" /* SOLID */,
|
|
263
|
-
dependencies: ["solid-js"],
|
|
264
|
-
matcherFunction: ({ dependencies }) => {
|
|
265
|
-
return dependencies.every(Boolean);
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
// DO NOT MOVE ANY TEMPLATES BELOW THIS LINE
|
|
269
|
-
// React is part of every Template, after Storybook is initialized once
|
|
270
|
-
{
|
|
271
|
-
preset: "WEBPACK_REACT" /* WEBPACK_REACT */,
|
|
272
|
-
dependencies: ["react", "webpack"],
|
|
273
|
-
matcherFunction: ({ dependencies }) => {
|
|
274
|
-
return dependencies.every(Boolean);
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
preset: "REACT" /* REACT */,
|
|
279
|
-
dependencies: ["react"],
|
|
280
|
-
matcherFunction: ({ dependencies }) => {
|
|
281
|
-
return dependencies.every(Boolean);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
];
|
|
285
|
-
var unsupportedTemplate = {
|
|
286
|
-
preset: "UNSUPPORTED" /* UNSUPPORTED */,
|
|
287
|
-
dependencies: {
|
|
288
|
-
// TODO(blaine): Remove when we support Nuxt 3
|
|
289
|
-
nuxt: (versionRange) => eqMajor(versionRange, 3)
|
|
290
|
-
},
|
|
291
|
-
matcherFunction: ({ dependencies }) => {
|
|
292
|
-
return dependencies.some(Boolean);
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
var notInstallableProjectTypes = ["UNDETECTED" /* UNDETECTED */, "UNSUPPORTED" /* UNSUPPORTED */];
|
|
296
|
-
var installableProjectTypes = Object.values(ProjectType).filter((type) => !notInstallableProjectTypes.includes(type)).map((type) => type.toLowerCase());
|
|
297
|
-
|
|
298
|
-
// src/versions.ts
|
|
299
|
-
var versions_default = {
|
|
300
|
-
"@storybook/addon-a11y": "7.0.0-beta.61",
|
|
301
|
-
"@storybook/addon-actions": "7.0.0-beta.61",
|
|
302
|
-
"@storybook/addon-backgrounds": "7.0.0-beta.61",
|
|
303
|
-
"@storybook/addon-controls": "7.0.0-beta.61",
|
|
304
|
-
"@storybook/addon-docs": "7.0.0-beta.61",
|
|
305
|
-
"@storybook/addon-essentials": "7.0.0-beta.61",
|
|
306
|
-
"@storybook/addon-highlight": "7.0.0-beta.61",
|
|
307
|
-
"@storybook/addon-interactions": "7.0.0-beta.61",
|
|
308
|
-
"@storybook/addon-jest": "7.0.0-beta.61",
|
|
309
|
-
"@storybook/addon-links": "7.0.0-beta.61",
|
|
310
|
-
"@storybook/addon-measure": "7.0.0-beta.61",
|
|
311
|
-
"@storybook/addon-outline": "7.0.0-beta.61",
|
|
312
|
-
"@storybook/addon-storyshots": "7.0.0-beta.61",
|
|
313
|
-
"@storybook/addon-storyshots-puppeteer": "7.0.0-beta.61",
|
|
314
|
-
"@storybook/addon-storysource": "7.0.0-beta.61",
|
|
315
|
-
"@storybook/addon-toolbars": "7.0.0-beta.61",
|
|
316
|
-
"@storybook/addon-viewport": "7.0.0-beta.61",
|
|
317
|
-
"@storybook/addons": "7.0.0-beta.61",
|
|
318
|
-
"@storybook/angular": "7.0.0-beta.61",
|
|
319
|
-
"@storybook/api": "7.0.0-beta.61",
|
|
320
|
-
"@storybook/builder-manager": "7.0.0-beta.61",
|
|
321
|
-
"@storybook/builder-vite": "7.0.0-beta.61",
|
|
322
|
-
"@storybook/builder-webpack5": "7.0.0-beta.61",
|
|
323
|
-
"@storybook/channel-postmessage": "7.0.0-beta.61",
|
|
324
|
-
"@storybook/channel-websocket": "7.0.0-beta.61",
|
|
325
|
-
"@storybook/channels": "7.0.0-beta.61",
|
|
326
|
-
"@storybook/cli": "7.0.0-beta.61",
|
|
327
|
-
"@storybook/client-api": "7.0.0-beta.61",
|
|
328
|
-
"@storybook/client-logger": "7.0.0-beta.61",
|
|
329
|
-
"@storybook/codemod": "7.0.0-beta.61",
|
|
330
|
-
"@storybook/core-client": "7.0.0-beta.61",
|
|
331
|
-
"@storybook/core-common": "7.0.0-beta.61",
|
|
332
|
-
"@storybook/core-events": "7.0.0-beta.61",
|
|
333
|
-
"@storybook/core-server": "7.0.0-beta.61",
|
|
334
|
-
"@storybook/core-webpack": "7.0.0-beta.61",
|
|
335
|
-
"@storybook/csf-plugin": "7.0.0-beta.61",
|
|
336
|
-
"@storybook/csf-tools": "7.0.0-beta.61",
|
|
337
|
-
"@storybook/docs-tools": "7.0.0-beta.61",
|
|
338
|
-
"@storybook/ember": "7.0.0-beta.61",
|
|
339
|
-
"@storybook/html": "7.0.0-beta.61",
|
|
340
|
-
"@storybook/html-vite": "7.0.0-beta.61",
|
|
341
|
-
"@storybook/html-webpack5": "7.0.0-beta.61",
|
|
342
|
-
"@storybook/instrumenter": "7.0.0-beta.61",
|
|
343
|
-
"@storybook/manager-api": "7.0.0-beta.61",
|
|
344
|
-
"@storybook/nextjs": "7.0.0-beta.61",
|
|
345
|
-
"@storybook/node-logger": "7.0.0-beta.61",
|
|
346
|
-
"@storybook/postinstall": "7.0.0-beta.61",
|
|
347
|
-
"@storybook/preact": "7.0.0-beta.61",
|
|
348
|
-
"@storybook/preact-vite": "7.0.0-beta.61",
|
|
349
|
-
"@storybook/preact-webpack5": "7.0.0-beta.61",
|
|
350
|
-
"@storybook/preset-create-react-app": "7.0.0-beta.61",
|
|
351
|
-
"@storybook/preset-html-webpack": "7.0.0-beta.61",
|
|
352
|
-
"@storybook/preset-preact-webpack": "7.0.0-beta.61",
|
|
353
|
-
"@storybook/preset-react-webpack": "7.0.0-beta.61",
|
|
354
|
-
"@storybook/preset-server-webpack": "7.0.0-beta.61",
|
|
355
|
-
"@storybook/preset-svelte-webpack": "7.0.0-beta.61",
|
|
356
|
-
"@storybook/preset-vue-webpack": "7.0.0-beta.61",
|
|
357
|
-
"@storybook/preset-vue3-webpack": "7.0.0-beta.61",
|
|
358
|
-
"@storybook/preset-web-components-webpack": "7.0.0-beta.61",
|
|
359
|
-
"@storybook/preview": "7.0.0-beta.61",
|
|
360
|
-
"@storybook/preview-api": "7.0.0-beta.61",
|
|
361
|
-
"@storybook/preview-web": "7.0.0-beta.61",
|
|
362
|
-
"@storybook/react": "7.0.0-beta.61",
|
|
363
|
-
"@storybook/react-dom-shim": "7.0.0-beta.61",
|
|
364
|
-
"@storybook/react-vite": "7.0.0-beta.61",
|
|
365
|
-
"@storybook/react-webpack5": "7.0.0-beta.61",
|
|
366
|
-
"@storybook/router": "7.0.0-beta.61",
|
|
367
|
-
"@storybook/server": "7.0.0-beta.61",
|
|
368
|
-
"@storybook/server-webpack5": "7.0.0-beta.61",
|
|
369
|
-
"@storybook/source-loader": "7.0.0-beta.61",
|
|
370
|
-
"@storybook/store": "7.0.0-beta.61",
|
|
371
|
-
"@storybook/svelte": "7.0.0-beta.61",
|
|
372
|
-
"@storybook/svelte-vite": "7.0.0-beta.61",
|
|
373
|
-
"@storybook/svelte-webpack5": "7.0.0-beta.61",
|
|
374
|
-
"@storybook/sveltekit": "7.0.0-beta.61",
|
|
375
|
-
"@storybook/telemetry": "7.0.0-beta.61",
|
|
376
|
-
"@storybook/theming": "7.0.0-beta.61",
|
|
377
|
-
"@storybook/types": "7.0.0-beta.61",
|
|
378
|
-
"@storybook/vue": "7.0.0-beta.61",
|
|
379
|
-
"@storybook/vue-vite": "7.0.0-beta.61",
|
|
380
|
-
"@storybook/vue-webpack5": "7.0.0-beta.61",
|
|
381
|
-
"@storybook/vue3": "7.0.0-beta.61",
|
|
382
|
-
"@storybook/vue3-vite": "7.0.0-beta.61",
|
|
383
|
-
"@storybook/vue3-webpack5": "7.0.0-beta.61",
|
|
384
|
-
"@storybook/web-components": "7.0.0-beta.61",
|
|
385
|
-
"@storybook/web-components-vite": "7.0.0-beta.61",
|
|
386
|
-
"@storybook/web-components-webpack5": "7.0.0-beta.61",
|
|
387
|
-
sb: "7.0.0-beta.61",
|
|
388
|
-
storybook: "7.0.0-beta.61"
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
// src/dirs.ts
|
|
392
|
-
function getCliDir() {
|
|
393
|
-
return dirname(__require.resolve("@storybook/cli/package.json"));
|
|
394
|
-
}
|
|
395
|
-
var resolveUsingBranchInstall = async (packageManager, request) => {
|
|
396
|
-
const tempDirectory = tempy.directory();
|
|
397
|
-
const name = request;
|
|
398
|
-
const version = versions_default[name] || await packageManager.latestVersion(request);
|
|
399
|
-
const url = getNpmTarballUrl(request, version, { registry: packageManager.getRegistryURL() });
|
|
400
|
-
await downloadTarball({ url, dir: tempDirectory });
|
|
401
|
-
return join(tempDirectory, "package");
|
|
402
|
-
};
|
|
403
|
-
async function getRendererDir(packageManager, renderer) {
|
|
404
|
-
const externalFramework = externalFrameworks.find((framework) => framework.name === renderer);
|
|
405
|
-
const frameworkPackageName = externalFramework?.renderer || externalFramework?.packageName || `@storybook/${renderer}`;
|
|
406
|
-
const packageJsonPath = `${frameworkPackageName}/package.json`;
|
|
407
|
-
const errors = [];
|
|
408
|
-
try {
|
|
409
|
-
return dirname(
|
|
410
|
-
__require.resolve(packageJsonPath, {
|
|
411
|
-
paths: [process.cwd()]
|
|
412
|
-
})
|
|
413
|
-
);
|
|
414
|
-
} catch (e) {
|
|
415
|
-
errors.push(e);
|
|
416
|
-
}
|
|
417
|
-
try {
|
|
418
|
-
return await resolveUsingBranchInstall(packageManager, frameworkPackageName);
|
|
419
|
-
} catch (e) {
|
|
420
|
-
errors.push(e);
|
|
421
|
-
}
|
|
422
|
-
throw new Error(`Cannot find ${packageJsonPath}, ${errors.map((e) => e.stack).join("\n\n")}`);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// src/helpers.ts
|
|
426
|
-
var logger = console;
|
|
427
|
-
function getBowerJson() {
|
|
428
|
-
const bowerJsonPath = path.resolve("bower.json");
|
|
429
|
-
if (!fs.existsSync(bowerJsonPath)) {
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
const jsonContent = fs.readFileSync(bowerJsonPath, "utf8");
|
|
433
|
-
return JSON.parse(jsonContent);
|
|
434
|
-
}
|
|
435
|
-
function readFileAsJson(jsonPath, allowComments) {
|
|
436
|
-
const filePath = path.resolve(jsonPath);
|
|
437
|
-
if (!fs.existsSync(filePath)) {
|
|
438
|
-
return false;
|
|
439
|
-
}
|
|
440
|
-
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
441
|
-
const jsonContent = allowComments ? stripJsonComments(fileContent) : fileContent;
|
|
442
|
-
try {
|
|
443
|
-
return JSON.parse(jsonContent);
|
|
444
|
-
} catch (e) {
|
|
445
|
-
logger.error(chalk.red(`Invalid json in file: ${filePath}`));
|
|
446
|
-
throw e;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
var writeFileAsJson = (jsonPath, content) => {
|
|
450
|
-
const filePath = path.resolve(jsonPath);
|
|
451
|
-
if (!fs.existsSync(filePath)) {
|
|
452
|
-
return false;
|
|
453
|
-
}
|
|
454
|
-
fs.writeFileSync(filePath, `${JSON.stringify(content, null, 2)}
|
|
455
|
-
`);
|
|
456
|
-
return true;
|
|
457
|
-
};
|
|
458
|
-
var commandLog = (message) => {
|
|
459
|
-
process.stdout.write(chalk.cyan(" \u2022 ") + message);
|
|
460
|
-
return (errorMessage, errorInfo) => {
|
|
461
|
-
if (errorMessage) {
|
|
462
|
-
process.stdout.write(`. ${chalk.red("\u2716")}
|
|
463
|
-
`);
|
|
464
|
-
logger.error(`
|
|
465
|
-
${chalk.red(errorMessage)}`);
|
|
466
|
-
if (!errorInfo) {
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
const newErrorInfo = errorInfo.split("\n").map((line) => ` ${chalk.dim(line)}`).join("\n");
|
|
470
|
-
logger.error(`${newErrorInfo}
|
|
471
|
-
`);
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
process.stdout.write(`. ${chalk.green("\u2713")}
|
|
475
|
-
`);
|
|
476
|
-
};
|
|
477
|
-
};
|
|
478
|
-
function paddedLog(message) {
|
|
479
|
-
const newMessage = message.split("\n").map((line) => ` ${line}`).join("\n");
|
|
480
|
-
logger.log(newMessage);
|
|
481
|
-
}
|
|
482
|
-
function getChars(char, amount) {
|
|
483
|
-
let line = "";
|
|
484
|
-
for (let lc = 0; lc < amount; lc += 1) {
|
|
485
|
-
line += char;
|
|
486
|
-
}
|
|
487
|
-
return line;
|
|
488
|
-
}
|
|
489
|
-
function codeLog(codeLines, leftPadAmount) {
|
|
490
|
-
let maxLength = 0;
|
|
491
|
-
const newLines = codeLines.map((line) => {
|
|
492
|
-
maxLength = line.length > maxLength ? line.length : maxLength;
|
|
493
|
-
return line;
|
|
494
|
-
});
|
|
495
|
-
const finalResult = newLines.map((line) => {
|
|
496
|
-
const rightPadAmount = maxLength - line.length;
|
|
497
|
-
let newLine = line + getChars(" ", rightPadAmount);
|
|
498
|
-
newLine = getChars(" ", leftPadAmount || 2) + chalk.inverse(` ${newLine} `);
|
|
499
|
-
return newLine;
|
|
500
|
-
}).join("\n");
|
|
501
|
-
logger.log(finalResult);
|
|
502
|
-
}
|
|
503
|
-
async function getBabelDependencies(packageManager, packageJson) {
|
|
504
|
-
const dependenciesToAdd = [];
|
|
505
|
-
let babelLoaderVersion = "^8.0.0-0";
|
|
506
|
-
const babelCoreVersion = packageJson.dependencies["babel-core"] || packageJson.devDependencies["babel-core"];
|
|
507
|
-
if (!babelCoreVersion) {
|
|
508
|
-
if (!packageJson.dependencies["@babel/core"] && !packageJson.devDependencies["@babel/core"]) {
|
|
509
|
-
const babelCoreInstallVersion = await packageManager.getVersion("@babel/core");
|
|
510
|
-
dependenciesToAdd.push(`@babel/core@${babelCoreInstallVersion}`);
|
|
511
|
-
}
|
|
512
|
-
} else {
|
|
513
|
-
const latestCompatibleBabelVersion = await packageManager.latestVersion(
|
|
514
|
-
"babel-core",
|
|
515
|
-
babelCoreVersion
|
|
516
|
-
);
|
|
517
|
-
if (satisfies(latestCompatibleBabelVersion, "^6.0.0")) {
|
|
518
|
-
babelLoaderVersion = "^7.0.0";
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (!packageJson.dependencies["babel-loader"] && !packageJson.devDependencies["babel-loader"]) {
|
|
522
|
-
const babelLoaderInstallVersion = await packageManager.getVersion(
|
|
523
|
-
"babel-loader",
|
|
524
|
-
babelLoaderVersion
|
|
525
|
-
);
|
|
526
|
-
dependenciesToAdd.push(`babel-loader@${babelLoaderInstallVersion}`);
|
|
527
|
-
}
|
|
528
|
-
return dependenciesToAdd;
|
|
529
|
-
}
|
|
530
|
-
function copyTemplate(templateRoot, destination = ".") {
|
|
531
|
-
const templateDir = path.resolve(templateRoot, `template-csf/`);
|
|
532
|
-
if (!fs.existsSync(templateDir)) {
|
|
533
|
-
throw new Error(`Couldn't find template dir`);
|
|
534
|
-
}
|
|
535
|
-
fse.copySync(templateDir, destination, { overwrite: true });
|
|
536
|
-
}
|
|
537
|
-
async function copyTemplateFiles({
|
|
538
|
-
packageManager,
|
|
539
|
-
renderer,
|
|
540
|
-
language,
|
|
541
|
-
destination,
|
|
542
|
-
includeCommonAssets = true
|
|
543
|
-
}) {
|
|
544
|
-
const languageFolderMapping = {
|
|
545
|
-
["javascript" /* JAVASCRIPT */]: "js",
|
|
546
|
-
["typescript-3-8" /* TYPESCRIPT_3_8 */]: "ts-3-8",
|
|
547
|
-
["typescript-4-9" /* TYPESCRIPT_4_9 */]: "ts-4-9"
|
|
548
|
-
};
|
|
549
|
-
const templatePath = async () => {
|
|
550
|
-
const baseDir = await getRendererDir(packageManager, renderer);
|
|
551
|
-
const assetsDir = join2(baseDir, "template/cli");
|
|
552
|
-
const assetsLanguage = join2(assetsDir, languageFolderMapping[language]);
|
|
553
|
-
const assetsJS = join2(assetsDir, languageFolderMapping["javascript" /* JAVASCRIPT */]);
|
|
554
|
-
const assetsTS38 = join2(assetsDir, languageFolderMapping["typescript-3-8" /* TYPESCRIPT_3_8 */]);
|
|
555
|
-
if (await fse.pathExists(assetsLanguage)) {
|
|
556
|
-
return assetsLanguage;
|
|
557
|
-
}
|
|
558
|
-
if (language === "typescript-4-9" /* TYPESCRIPT_4_9 */ && await fse.pathExists(assetsTS38)) {
|
|
559
|
-
return assetsTS38;
|
|
560
|
-
}
|
|
561
|
-
if (await fse.pathExists(assetsJS)) {
|
|
562
|
-
return assetsJS;
|
|
563
|
-
}
|
|
564
|
-
if (await fse.pathExists(assetsDir)) {
|
|
565
|
-
return assetsDir;
|
|
566
|
-
}
|
|
567
|
-
throw new Error(`Unsupported renderer: ${renderer} (${baseDir})`);
|
|
568
|
-
};
|
|
569
|
-
const targetPath = async () => {
|
|
570
|
-
if (await fse.pathExists("./src")) {
|
|
571
|
-
return "./src/stories";
|
|
572
|
-
}
|
|
573
|
-
return "./stories";
|
|
574
|
-
};
|
|
575
|
-
const destinationPath = destination ?? await targetPath();
|
|
576
|
-
if (includeCommonAssets) {
|
|
577
|
-
await fse.copy(join2(getCliDir(), "rendererAssets/common"), destinationPath, {
|
|
578
|
-
overwrite: true
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
await fse.copy(await templatePath(), destinationPath, { overwrite: true });
|
|
582
|
-
}
|
|
583
|
-
function getStorybookVersionSpecifier(packageJson) {
|
|
584
|
-
const allDeps = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
585
|
-
const storybookPackage = Object.keys(allDeps).find(
|
|
586
|
-
(name) => {
|
|
587
|
-
return versions_default[name];
|
|
588
|
-
}
|
|
589
|
-
);
|
|
590
|
-
if (!storybookPackage) {
|
|
591
|
-
throw new Error(`Couldn't find any official storybook packages in package.json`);
|
|
592
|
-
}
|
|
593
|
-
return allDeps[storybookPackage];
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
// src/js-package-manager/JsPackageManager.ts
|
|
597
|
-
var logger2 = console;
|
|
598
|
-
function getPackageDetails(pkg) {
|
|
599
|
-
const idx = pkg.lastIndexOf("@");
|
|
600
|
-
if (idx <= 0) {
|
|
601
|
-
return [pkg, void 0];
|
|
602
|
-
}
|
|
603
|
-
const packageName = pkg.slice(0, idx);
|
|
604
|
-
const packageVersion = pkg.slice(idx + 1);
|
|
605
|
-
return [packageName, packageVersion];
|
|
606
|
-
}
|
|
607
|
-
var JsPackageManager = class {
|
|
608
|
-
// NOTE: for some reason yarn prefers the npm registry in
|
|
609
|
-
// local development, so always use npm
|
|
610
|
-
setRegistryURL(url) {
|
|
611
|
-
if (url) {
|
|
612
|
-
this.executeCommand("npm", ["config", "set", "registry", url]);
|
|
613
|
-
} else {
|
|
614
|
-
this.executeCommand("npm", ["config", "delete", "registry"]);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
getRegistryURL() {
|
|
618
|
-
const url = this.executeCommand("npm", ["config", "get", "registry"]).trim();
|
|
619
|
-
return url === "undefined" ? void 0 : url;
|
|
620
|
-
}
|
|
621
|
-
constructor(options) {
|
|
622
|
-
this.cwd = options?.cwd;
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Install dependencies listed in `package.json`
|
|
626
|
-
*/
|
|
627
|
-
installDependencies() {
|
|
628
|
-
let done = commandLog("Preparing to install dependencies");
|
|
629
|
-
done();
|
|
630
|
-
logger2.log();
|
|
631
|
-
logger2.log();
|
|
632
|
-
done = commandLog("Installing dependencies");
|
|
633
|
-
try {
|
|
634
|
-
this.runInstall();
|
|
635
|
-
} catch (e) {
|
|
636
|
-
done("An error occurred while installing dependencies.");
|
|
637
|
-
process.exit(1);
|
|
638
|
-
}
|
|
639
|
-
done();
|
|
640
|
-
}
|
|
641
|
-
packageJsonPath() {
|
|
642
|
-
return this.cwd ? path2.resolve(this.cwd, "package.json") : path2.resolve("package.json");
|
|
643
|
-
}
|
|
644
|
-
readPackageJson() {
|
|
645
|
-
const packageJsonPath = this.packageJsonPath();
|
|
646
|
-
if (!fs2.existsSync(packageJsonPath)) {
|
|
647
|
-
throw new Error(`Could not read package.json file at ${packageJsonPath}`);
|
|
648
|
-
}
|
|
649
|
-
const jsonContent = fs2.readFileSync(packageJsonPath, "utf8");
|
|
650
|
-
return JSON.parse(jsonContent);
|
|
651
|
-
}
|
|
652
|
-
writePackageJson(packageJson) {
|
|
653
|
-
const packageJsonToWrite = { ...packageJson };
|
|
654
|
-
if (packageJsonToWrite.dependencies && Object.keys(packageJsonToWrite.dependencies).length === 0) {
|
|
655
|
-
delete packageJsonToWrite.dependencies;
|
|
656
|
-
}
|
|
657
|
-
if (packageJsonToWrite.devDependencies && Object.keys(packageJsonToWrite.devDependencies).length === 0) {
|
|
658
|
-
delete packageJsonToWrite.devDependencies;
|
|
659
|
-
}
|
|
660
|
-
if (packageJsonToWrite.dependencies && Object.keys(packageJsonToWrite.peerDependencies).length === 0) {
|
|
661
|
-
delete packageJsonToWrite.peerDependencies;
|
|
662
|
-
}
|
|
663
|
-
const content = `${JSON.stringify(packageJsonToWrite, null, 2)}
|
|
664
|
-
`;
|
|
665
|
-
fs2.writeFileSync(this.packageJsonPath(), content, "utf8");
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Read the `package.json` file available in the directory the command was call from
|
|
669
|
-
* If there is no `package.json` it will create one.
|
|
670
|
-
*/
|
|
671
|
-
retrievePackageJson() {
|
|
672
|
-
let packageJson;
|
|
673
|
-
try {
|
|
674
|
-
packageJson = this.readPackageJson();
|
|
675
|
-
} catch (err) {
|
|
676
|
-
this.initPackageJson();
|
|
677
|
-
packageJson = this.readPackageJson();
|
|
678
|
-
}
|
|
679
|
-
return {
|
|
680
|
-
...packageJson,
|
|
681
|
-
dependencies: { ...packageJson.dependencies },
|
|
682
|
-
devDependencies: { ...packageJson.devDependencies },
|
|
683
|
-
peerDependencies: { ...packageJson.peerDependencies }
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
getAllDependencies() {
|
|
687
|
-
const { dependencies, devDependencies, peerDependencies } = this.retrievePackageJson();
|
|
688
|
-
return {
|
|
689
|
-
...dependencies,
|
|
690
|
-
...devDependencies,
|
|
691
|
-
...peerDependencies
|
|
692
|
-
};
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* Add dependencies to a project using `yarn add` or `npm install`.
|
|
696
|
-
*
|
|
697
|
-
* @param {Object} options contains `skipInstall`, `packageJson` and `installAsDevDependencies` which we use to determine how we install packages.
|
|
698
|
-
* @param {Array} dependencies contains a list of packages to add.
|
|
699
|
-
* @example
|
|
700
|
-
* addDependencies(options, [
|
|
701
|
-
* `@storybook/react@${storybookVersion}`,
|
|
702
|
-
* `@storybook/addon-actions@${actionsVersion}`,
|
|
703
|
-
* `@storybook/addon-links@${linksVersion}`,
|
|
704
|
-
* `@storybook/preview-api@${addonsVersion}`,
|
|
705
|
-
* ]);
|
|
706
|
-
*/
|
|
707
|
-
addDependencies(options, dependencies) {
|
|
708
|
-
const { skipInstall } = options;
|
|
709
|
-
if (skipInstall) {
|
|
710
|
-
const { packageJson } = options;
|
|
711
|
-
const dependenciesMap = dependencies.reduce((acc, dep) => {
|
|
712
|
-
const [packageName, packageVersion] = getPackageDetails(dep);
|
|
713
|
-
return { ...acc, [packageName]: packageVersion };
|
|
714
|
-
}, {});
|
|
715
|
-
if (options.installAsDevDependencies) {
|
|
716
|
-
packageJson.devDependencies = {
|
|
717
|
-
...packageJson.devDependencies,
|
|
718
|
-
...dependenciesMap
|
|
719
|
-
};
|
|
720
|
-
} else {
|
|
721
|
-
packageJson.dependencies = {
|
|
722
|
-
...packageJson.dependencies,
|
|
723
|
-
...dependenciesMap
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
this.writePackageJson(packageJson);
|
|
727
|
-
} else {
|
|
728
|
-
try {
|
|
729
|
-
this.runAddDeps(dependencies, options.installAsDevDependencies);
|
|
730
|
-
} catch (e) {
|
|
731
|
-
logger2.error("An error occurred while installing dependencies.");
|
|
732
|
-
logger2.log(e.message);
|
|
733
|
-
process.exit(1);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Remove dependencies from a project using `yarn remove` or `npm uninstall`.
|
|
739
|
-
*
|
|
740
|
-
* @param {Object} options contains `skipInstall`, `packageJson` and `installAsDevDependencies` which we use to determine how we install packages.
|
|
741
|
-
* @param {Array} dependencies contains a list of packages to remove.
|
|
742
|
-
* @example
|
|
743
|
-
* removeDependencies(options, [
|
|
744
|
-
* `@storybook/react`,
|
|
745
|
-
* `@storybook/addon-actions`,
|
|
746
|
-
* ]);
|
|
747
|
-
*/
|
|
748
|
-
removeDependencies(options, dependencies) {
|
|
749
|
-
const { skipInstall } = options;
|
|
750
|
-
if (skipInstall) {
|
|
751
|
-
const { packageJson } = options;
|
|
752
|
-
dependencies.forEach((dep) => {
|
|
753
|
-
if (packageJson.devDependencies) {
|
|
754
|
-
delete packageJson.devDependencies[dep];
|
|
755
|
-
}
|
|
756
|
-
if (packageJson.dependencies) {
|
|
757
|
-
delete packageJson.dependencies[dep];
|
|
758
|
-
}
|
|
759
|
-
});
|
|
760
|
-
this.writePackageJson(packageJson);
|
|
761
|
-
} else {
|
|
762
|
-
try {
|
|
763
|
-
this.runRemoveDeps(dependencies);
|
|
764
|
-
} catch (e) {
|
|
765
|
-
logger2.error("An error occurred while removing dependencies.");
|
|
766
|
-
logger2.log(e.message);
|
|
767
|
-
process.exit(1);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* Return an array of strings matching following format: `<package_name>@<package_latest_version>`
|
|
773
|
-
*
|
|
774
|
-
* @param packages
|
|
775
|
-
*/
|
|
776
|
-
getVersionedPackages(packages) {
|
|
777
|
-
return Promise.all(
|
|
778
|
-
packages.map(async (pkg) => {
|
|
779
|
-
const [packageName, packageVersion] = getPackageDetails(pkg);
|
|
780
|
-
return `${packageName}@${await this.getVersion(packageName, packageVersion)}`;
|
|
781
|
-
})
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Return an array of string standing for the latest version of the input packages.
|
|
786
|
-
* To be able to identify which version goes with which package the order of the input array is keep.
|
|
787
|
-
*
|
|
788
|
-
* @param packageNames
|
|
789
|
-
*/
|
|
790
|
-
getVersions(...packageNames) {
|
|
791
|
-
return Promise.all(
|
|
792
|
-
packageNames.map((packageName) => {
|
|
793
|
-
return this.getVersion(packageName);
|
|
794
|
-
})
|
|
795
|
-
);
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Return the latest version of the input package available on npmjs registry.
|
|
799
|
-
* If constraint are provided it return the latest version matching the constraints.
|
|
800
|
-
*
|
|
801
|
-
* For `@storybook/*` packages the latest version is retrieved from `cli/src/versions.json` file directly
|
|
802
|
-
*
|
|
803
|
-
* @param packageName The name of the package
|
|
804
|
-
* @param constraint A valid semver constraint, example: '1.x || >=2.5.0 || 5.0.0 - 7.2.3'
|
|
805
|
-
*/
|
|
806
|
-
async getVersion(packageName, constraint) {
|
|
807
|
-
let current;
|
|
808
|
-
if (/(@storybook|^sb$|^storybook$)/.test(packageName)) {
|
|
809
|
-
current = versions_default[packageName];
|
|
810
|
-
}
|
|
811
|
-
let latest;
|
|
812
|
-
try {
|
|
813
|
-
latest = await this.latestVersion(packageName, constraint);
|
|
814
|
-
} catch (e) {
|
|
815
|
-
if (current) {
|
|
816
|
-
logger2.warn(`
|
|
817
|
-
${chalk2.yellow(e.message)}`);
|
|
818
|
-
return current;
|
|
819
|
-
}
|
|
820
|
-
logger2.error(`
|
|
821
|
-
${chalk2.red(e.message)}`);
|
|
822
|
-
process.exit(1);
|
|
823
|
-
}
|
|
824
|
-
const versionToUse = current && (!constraint || satisfies2(current, constraint)) && gt(current, latest) ? current : latest;
|
|
825
|
-
return `^${versionToUse}`;
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* Get the latest version of the package available on npmjs.com.
|
|
829
|
-
* If constraint is set then it returns a version satisfying it, otherwise the latest version available is returned.
|
|
830
|
-
*
|
|
831
|
-
* @param packageName Name of the package
|
|
832
|
-
* @param constraint Version range to use to constraint the returned version
|
|
833
|
-
*/
|
|
834
|
-
async latestVersion(packageName, constraint) {
|
|
835
|
-
if (!constraint) {
|
|
836
|
-
return this.runGetVersions(packageName, false);
|
|
837
|
-
}
|
|
838
|
-
const versions = await this.runGetVersions(packageName, true);
|
|
839
|
-
return versions.reverse().find((version) => satisfies2(version, constraint));
|
|
840
|
-
}
|
|
841
|
-
addStorybookCommandInScripts(options) {
|
|
842
|
-
const sbPort = options?.port ?? 6006;
|
|
843
|
-
const storybookCmd = `storybook dev -p ${sbPort}`;
|
|
844
|
-
const buildStorybookCmd = `storybook build`;
|
|
845
|
-
const preCommand = options?.preCommand ? this.getRunCommand(options.preCommand) : void 0;
|
|
846
|
-
this.addScripts({
|
|
847
|
-
storybook: [preCommand, storybookCmd].filter(Boolean).join(" && "),
|
|
848
|
-
"build-storybook": [preCommand, buildStorybookCmd].filter(Boolean).join(" && ")
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
addESLintConfig() {
|
|
852
|
-
const packageJson = this.retrievePackageJson();
|
|
853
|
-
this.writePackageJson({
|
|
854
|
-
...packageJson,
|
|
855
|
-
eslintConfig: {
|
|
856
|
-
...packageJson.eslintConfig,
|
|
857
|
-
overrides: [
|
|
858
|
-
...packageJson.eslintConfig?.overrides || [],
|
|
859
|
-
{
|
|
860
|
-
files: ["**/*.stories.*"],
|
|
861
|
-
rules: {
|
|
862
|
-
"import/no-anonymous-default-export": "off"
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
]
|
|
866
|
-
}
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
addScripts(scripts) {
|
|
870
|
-
const packageJson = this.retrievePackageJson();
|
|
871
|
-
this.writePackageJson({
|
|
872
|
-
...packageJson,
|
|
873
|
-
scripts: {
|
|
874
|
-
...packageJson.scripts,
|
|
875
|
-
...scripts
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
addPackageResolutions(versions) {
|
|
880
|
-
const packageJson = this.retrievePackageJson();
|
|
881
|
-
const resolutions = this.getResolutions(packageJson, versions);
|
|
882
|
-
this.writePackageJson({ ...packageJson, ...resolutions });
|
|
883
|
-
}
|
|
884
|
-
executeCommand(command, args, stdio, cwd) {
|
|
885
|
-
const commandResult = spawnSync(command, args, {
|
|
886
|
-
cwd: cwd ?? this.cwd,
|
|
887
|
-
stdio: stdio ?? "pipe",
|
|
888
|
-
encoding: "utf-8",
|
|
889
|
-
shell: true
|
|
890
|
-
});
|
|
891
|
-
if (commandResult.status !== 0) {
|
|
892
|
-
throw new Error(commandResult.stderr ?? "");
|
|
893
|
-
}
|
|
894
|
-
return commandResult.stdout ?? "";
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
|
|
898
|
-
// src/js-package-manager/JsPackageManagerFactory.ts
|
|
899
|
-
import path3 from "path";
|
|
900
|
-
import { sync as spawnSync2 } from "cross-spawn";
|
|
901
|
-
import { sync as findUpSync } from "find-up";
|
|
902
|
-
|
|
903
|
-
// src/js-package-manager/NPMProxy.ts
|
|
904
|
-
var NPMProxy = class extends JsPackageManager {
|
|
905
|
-
constructor() {
|
|
906
|
-
super(...arguments);
|
|
907
|
-
this.type = "npm";
|
|
908
|
-
}
|
|
909
|
-
initPackageJson() {
|
|
910
|
-
return this.executeCommand("npm", ["init", "-y"]);
|
|
911
|
-
}
|
|
912
|
-
getRunStorybookCommand() {
|
|
913
|
-
return "npm run storybook";
|
|
914
|
-
}
|
|
915
|
-
getRunCommand(command) {
|
|
916
|
-
return `npm run ${command}`;
|
|
917
|
-
}
|
|
918
|
-
getNpmVersion() {
|
|
919
|
-
return this.executeCommand("npm", ["--version"]);
|
|
920
|
-
}
|
|
921
|
-
getInstallArgs() {
|
|
922
|
-
if (!this.installArgs) {
|
|
923
|
-
this.installArgs = [];
|
|
924
|
-
}
|
|
925
|
-
return this.installArgs;
|
|
926
|
-
}
|
|
927
|
-
runPackageCommand(command, args, cwd) {
|
|
928
|
-
return this.executeCommand(`npm`, ["exec", "--", command, ...args], void 0, cwd);
|
|
929
|
-
}
|
|
930
|
-
getResolutions(packageJson, versions) {
|
|
931
|
-
return {
|
|
932
|
-
overrides: {
|
|
933
|
-
...packageJson.overrides,
|
|
934
|
-
...versions
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
runInstall() {
|
|
939
|
-
this.executeCommand("npm", ["install", ...this.getInstallArgs()], "inherit");
|
|
940
|
-
}
|
|
941
|
-
runAddDeps(dependencies, installAsDevDependencies) {
|
|
942
|
-
let args = [...dependencies];
|
|
943
|
-
if (installAsDevDependencies) {
|
|
944
|
-
args = ["-D", ...args];
|
|
945
|
-
}
|
|
946
|
-
this.executeCommand("npm", ["install", ...this.getInstallArgs(), ...args], "inherit");
|
|
947
|
-
}
|
|
948
|
-
runRemoveDeps(dependencies) {
|
|
949
|
-
const args = [...dependencies];
|
|
950
|
-
this.executeCommand("npm", ["uninstall", ...this.getInstallArgs(), ...args], "inherit");
|
|
951
|
-
}
|
|
952
|
-
runGetVersions(packageName, fetchAllVersions) {
|
|
953
|
-
const args = [fetchAllVersions ? "versions" : "version", "--json"];
|
|
954
|
-
const commandResult = this.executeCommand("npm", ["info", packageName, ...args]);
|
|
955
|
-
try {
|
|
956
|
-
const parsedOutput = JSON.parse(commandResult);
|
|
957
|
-
if (parsedOutput.error) {
|
|
958
|
-
throw new Error(parsedOutput.error.summary);
|
|
959
|
-
} else {
|
|
960
|
-
return parsedOutput;
|
|
961
|
-
}
|
|
962
|
-
} catch (e) {
|
|
963
|
-
throw new Error(`Unable to find versions of ${packageName} using npm`);
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
};
|
|
967
|
-
|
|
968
|
-
// src/js-package-manager/PNPMProxy.ts
|
|
969
|
-
import { pathExistsSync } from "fs-extra";
|
|
970
|
-
var PNPMProxy = class extends JsPackageManager {
|
|
971
|
-
constructor() {
|
|
972
|
-
super(...arguments);
|
|
973
|
-
this.type = "pnpm";
|
|
974
|
-
}
|
|
975
|
-
detectWorkspaceRoot() {
|
|
976
|
-
const CWD = process.cwd();
|
|
977
|
-
const pnpmWorkspaceYaml = `${CWD}/pnpm-workspace.yaml`;
|
|
978
|
-
return pathExistsSync(pnpmWorkspaceYaml);
|
|
979
|
-
}
|
|
980
|
-
initPackageJson() {
|
|
981
|
-
return this.executeCommand("pnpm", ["init", "-y"]);
|
|
982
|
-
}
|
|
983
|
-
getRunStorybookCommand() {
|
|
984
|
-
return "pnpm run storybook";
|
|
985
|
-
}
|
|
986
|
-
getRunCommand(command) {
|
|
987
|
-
return `pnpm run ${command}`;
|
|
988
|
-
}
|
|
989
|
-
getPnpmVersion() {
|
|
990
|
-
return this.executeCommand("pnpm", ["--version"]);
|
|
991
|
-
}
|
|
992
|
-
getInstallArgs() {
|
|
993
|
-
if (!this.installArgs) {
|
|
994
|
-
this.installArgs = [];
|
|
995
|
-
if (this.detectWorkspaceRoot()) {
|
|
996
|
-
this.installArgs.push("-w");
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
return this.installArgs;
|
|
1000
|
-
}
|
|
1001
|
-
runPackageCommand(command, args, cwd) {
|
|
1002
|
-
return this.executeCommand(`pnpm`, ["exec", command, ...args], void 0, cwd);
|
|
1003
|
-
}
|
|
1004
|
-
getResolutions(packageJson, versions) {
|
|
1005
|
-
return {
|
|
1006
|
-
overrides: {
|
|
1007
|
-
...packageJson.overrides,
|
|
1008
|
-
...versions
|
|
1009
|
-
}
|
|
1010
|
-
};
|
|
1011
|
-
}
|
|
1012
|
-
runInstall() {
|
|
1013
|
-
this.executeCommand("pnpm", ["install", ...this.getInstallArgs()], "inherit");
|
|
1014
|
-
}
|
|
1015
|
-
runAddDeps(dependencies, installAsDevDependencies) {
|
|
1016
|
-
let args = [...dependencies];
|
|
1017
|
-
if (installAsDevDependencies) {
|
|
1018
|
-
args = ["-D", ...args];
|
|
1019
|
-
}
|
|
1020
|
-
this.executeCommand("pnpm", ["add", ...args, ...this.getInstallArgs()], "inherit");
|
|
1021
|
-
}
|
|
1022
|
-
runRemoveDeps(dependencies) {
|
|
1023
|
-
const args = [...dependencies];
|
|
1024
|
-
this.executeCommand("pnpm", ["remove", ...args, ...this.getInstallArgs()], "inherit");
|
|
1025
|
-
}
|
|
1026
|
-
runGetVersions(packageName, fetchAllVersions) {
|
|
1027
|
-
const args = [fetchAllVersions ? "versions" : "version", "--json"];
|
|
1028
|
-
const commandResult = this.executeCommand("pnpm", ["info", packageName, ...args]);
|
|
1029
|
-
try {
|
|
1030
|
-
const parsedOutput = JSON.parse(commandResult);
|
|
1031
|
-
if (parsedOutput.error) {
|
|
1032
|
-
throw new Error(parsedOutput.error.summary);
|
|
1033
|
-
} else {
|
|
1034
|
-
return parsedOutput;
|
|
1035
|
-
}
|
|
1036
|
-
} catch (e) {
|
|
1037
|
-
throw new Error(`Unable to find versions of ${packageName} using pnpm`);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
|
|
1042
|
-
// src/js-package-manager/Yarn2Proxy.ts
|
|
1043
|
-
var Yarn2Proxy = class extends JsPackageManager {
|
|
1044
|
-
constructor() {
|
|
1045
|
-
super(...arguments);
|
|
1046
|
-
this.type = "yarn2";
|
|
1047
|
-
}
|
|
1048
|
-
getInstallArgs() {
|
|
1049
|
-
if (!this.installArgs) {
|
|
1050
|
-
this.installArgs = [];
|
|
1051
|
-
}
|
|
1052
|
-
return this.installArgs;
|
|
1053
|
-
}
|
|
1054
|
-
initPackageJson() {
|
|
1055
|
-
return this.executeCommand("yarn", ["init"]);
|
|
1056
|
-
}
|
|
1057
|
-
getRunStorybookCommand() {
|
|
1058
|
-
return "yarn storybook";
|
|
1059
|
-
}
|
|
1060
|
-
getRunCommand(command) {
|
|
1061
|
-
return `yarn ${command}`;
|
|
1062
|
-
}
|
|
1063
|
-
runPackageCommand(command, args, cwd) {
|
|
1064
|
-
return this.executeCommand(`yarn`, [command, ...args], void 0, cwd);
|
|
1065
|
-
}
|
|
1066
|
-
getResolutions(packageJson, versions) {
|
|
1067
|
-
return {
|
|
1068
|
-
resolutions: {
|
|
1069
|
-
...packageJson.resolutions,
|
|
1070
|
-
...versions
|
|
1071
|
-
}
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
runInstall() {
|
|
1075
|
-
this.executeCommand("yarn", ["install", ...this.getInstallArgs()], "inherit");
|
|
1076
|
-
}
|
|
1077
|
-
runAddDeps(dependencies, installAsDevDependencies) {
|
|
1078
|
-
let args = [...dependencies];
|
|
1079
|
-
if (installAsDevDependencies) {
|
|
1080
|
-
args = ["-D", ...args];
|
|
1081
|
-
}
|
|
1082
|
-
this.executeCommand("yarn", ["add", ...this.getInstallArgs(), ...args], "inherit");
|
|
1083
|
-
}
|
|
1084
|
-
runRemoveDeps(dependencies) {
|
|
1085
|
-
const args = [...dependencies];
|
|
1086
|
-
this.executeCommand("yarn", ["remove", ...this.getInstallArgs(), ...args], "inherit");
|
|
1087
|
-
}
|
|
1088
|
-
runGetVersions(packageName, fetchAllVersions) {
|
|
1089
|
-
const field = fetchAllVersions ? "versions" : "version";
|
|
1090
|
-
const args = ["--fields", field, "--json"];
|
|
1091
|
-
const commandResult = this.executeCommand("yarn", ["npm", "info", packageName, ...args]);
|
|
1092
|
-
try {
|
|
1093
|
-
const parsedOutput = JSON.parse(commandResult);
|
|
1094
|
-
return parsedOutput[field];
|
|
1095
|
-
} catch (e) {
|
|
1096
|
-
throw new Error(`Unable to find versions of ${packageName} using yarn 2`);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
};
|
|
1100
|
-
|
|
1101
|
-
// src/js-package-manager/Yarn1Proxy.ts
|
|
1102
|
-
var Yarn1Proxy = class extends JsPackageManager {
|
|
1103
|
-
constructor() {
|
|
1104
|
-
super(...arguments);
|
|
1105
|
-
this.type = "yarn1";
|
|
1106
|
-
}
|
|
1107
|
-
getInstallArgs() {
|
|
1108
|
-
if (!this.installArgs) {
|
|
1109
|
-
this.installArgs = ["--ignore-workspace-root-check"];
|
|
1110
|
-
}
|
|
1111
|
-
return this.installArgs;
|
|
1112
|
-
}
|
|
1113
|
-
initPackageJson() {
|
|
1114
|
-
return this.executeCommand("yarn", ["init", "-y"]);
|
|
1115
|
-
}
|
|
1116
|
-
getRunStorybookCommand() {
|
|
1117
|
-
return "yarn storybook";
|
|
1118
|
-
}
|
|
1119
|
-
getRunCommand(command) {
|
|
1120
|
-
return `yarn ${command}`;
|
|
1121
|
-
}
|
|
1122
|
-
runPackageCommand(command, args, cwd) {
|
|
1123
|
-
return this.executeCommand(`yarn`, [command, ...args], void 0, cwd);
|
|
1124
|
-
}
|
|
1125
|
-
getResolutions(packageJson, versions) {
|
|
1126
|
-
return {
|
|
1127
|
-
resolutions: {
|
|
1128
|
-
...packageJson.resolutions,
|
|
1129
|
-
...versions
|
|
1130
|
-
}
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
runInstall() {
|
|
1134
|
-
this.executeCommand("yarn", ["install", ...this.getInstallArgs()], "inherit");
|
|
1135
|
-
}
|
|
1136
|
-
runAddDeps(dependencies, installAsDevDependencies) {
|
|
1137
|
-
let args = [...dependencies];
|
|
1138
|
-
if (installAsDevDependencies) {
|
|
1139
|
-
args = ["-D", ...args];
|
|
1140
|
-
}
|
|
1141
|
-
this.executeCommand("yarn", ["add", ...this.getInstallArgs(), ...args], "inherit");
|
|
1142
|
-
}
|
|
1143
|
-
runRemoveDeps(dependencies) {
|
|
1144
|
-
const args = [...dependencies];
|
|
1145
|
-
this.executeCommand("yarn", ["remove", ...this.getInstallArgs(), ...args], "inherit");
|
|
1146
|
-
}
|
|
1147
|
-
runGetVersions(packageName, fetchAllVersions) {
|
|
1148
|
-
const args = [fetchAllVersions ? "versions" : "version", "--json"];
|
|
1149
|
-
const commandResult = this.executeCommand("yarn", ["info", packageName, ...args]);
|
|
1150
|
-
try {
|
|
1151
|
-
const parsedOutput = JSON.parse(commandResult);
|
|
1152
|
-
if (parsedOutput.type === "inspect") {
|
|
1153
|
-
return parsedOutput.data;
|
|
1154
|
-
}
|
|
1155
|
-
throw new Error(`Unable to find versions of ${packageName} using yarn`);
|
|
1156
|
-
} catch (e) {
|
|
1157
|
-
throw new Error(`Unable to find versions of ${packageName} using yarn`);
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
};
|
|
1161
|
-
|
|
1162
|
-
// src/js-package-manager/JsPackageManagerFactory.ts
|
|
1163
|
-
var NPM_LOCKFILE = "package-lock.json";
|
|
1164
|
-
var PNPM_LOCKFILE = "pnpm-lock.yaml";
|
|
1165
|
-
var YARN_LOCKFILE = "yarn.lock";
|
|
1166
|
-
var JsPackageManagerFactory = class {
|
|
1167
|
-
static getPackageManager({ force } = {}, cwd) {
|
|
1168
|
-
if (force === "npm") {
|
|
1169
|
-
return new NPMProxy({ cwd });
|
|
1170
|
-
}
|
|
1171
|
-
if (force === "pnpm") {
|
|
1172
|
-
return new PNPMProxy({ cwd });
|
|
1173
|
-
}
|
|
1174
|
-
if (force === "yarn1") {
|
|
1175
|
-
return new Yarn1Proxy({ cwd });
|
|
1176
|
-
}
|
|
1177
|
-
if (force === "yarn2") {
|
|
1178
|
-
return new Yarn2Proxy({ cwd });
|
|
1179
|
-
}
|
|
1180
|
-
const yarnVersion = getYarnVersion(cwd);
|
|
1181
|
-
const closestLockfilePath = findUpSync([YARN_LOCKFILE, PNPM_LOCKFILE, NPM_LOCKFILE], {
|
|
1182
|
-
cwd
|
|
1183
|
-
});
|
|
1184
|
-
const closestLockfile = closestLockfilePath && path3.basename(closestLockfilePath);
|
|
1185
|
-
const hasNPMCommand = hasNPM(cwd);
|
|
1186
|
-
const hasPNPMCommand = hasPNPM(cwd);
|
|
1187
|
-
if (yarnVersion && (closestLockfile === YARN_LOCKFILE || !hasNPMCommand && !hasPNPMCommand)) {
|
|
1188
|
-
return yarnVersion === 1 ? new Yarn1Proxy({ cwd }) : new Yarn2Proxy({ cwd });
|
|
1189
|
-
}
|
|
1190
|
-
if (hasPNPMCommand && closestLockfile === PNPM_LOCKFILE) {
|
|
1191
|
-
return new PNPMProxy({ cwd });
|
|
1192
|
-
}
|
|
1193
|
-
if (hasNPMCommand) {
|
|
1194
|
-
return new NPMProxy({ cwd });
|
|
1195
|
-
}
|
|
1196
|
-
throw new Error("Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2");
|
|
1197
|
-
}
|
|
1198
|
-
};
|
|
1199
|
-
function hasNPM(cwd) {
|
|
1200
|
-
const npmVersionCommand = spawnSync2("npm", ["--version"], { cwd, shell: true });
|
|
1201
|
-
return npmVersionCommand.status === 0;
|
|
1202
|
-
}
|
|
1203
|
-
function hasPNPM(cwd) {
|
|
1204
|
-
const pnpmVersionCommand = spawnSync2("pnpm", ["--version"], { cwd, shell: true });
|
|
1205
|
-
return pnpmVersionCommand.status === 0;
|
|
1206
|
-
}
|
|
1207
|
-
function getYarnVersion(cwd) {
|
|
1208
|
-
const yarnVersionCommand = spawnSync2("yarn", ["--version"], { cwd, shell: true });
|
|
1209
|
-
if (yarnVersionCommand.status !== 0) {
|
|
1210
|
-
return void 0;
|
|
1211
|
-
}
|
|
1212
|
-
const yarnVersion = yarnVersionCommand.output.toString().replace(/,/g, "").replace(/"/g, "");
|
|
1213
|
-
return /^1\.+/.test(yarnVersion) ? 1 : 2;
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
export {
|
|
1217
|
-
__require,
|
|
1218
|
-
externalFrameworks,
|
|
1219
|
-
SUPPORTED_RENDERERS,
|
|
1220
|
-
supportedTemplates,
|
|
1221
|
-
unsupportedTemplate,
|
|
1222
|
-
installableProjectTypes,
|
|
1223
|
-
versions_default,
|
|
1224
|
-
getCliDir,
|
|
1225
|
-
getBowerJson,
|
|
1226
|
-
readFileAsJson,
|
|
1227
|
-
writeFileAsJson,
|
|
1228
|
-
commandLog,
|
|
1229
|
-
paddedLog,
|
|
1230
|
-
codeLog,
|
|
1231
|
-
getBabelDependencies,
|
|
1232
|
-
copyTemplate,
|
|
1233
|
-
copyTemplateFiles,
|
|
1234
|
-
getStorybookVersionSpecifier,
|
|
1235
|
-
useNpmWarning,
|
|
1236
|
-
getPackageDetails,
|
|
1237
|
-
JsPackageManager,
|
|
1238
|
-
JsPackageManagerFactory
|
|
1239
|
-
};
|