Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d89713e
Create sandbox on init in empty folders
valentinpalkovic Jul 26, 2023
b687386
Update code/lib/cli/src/initiate.ts
valentinpalkovic Jul 26, 2023
06ff80f
Use main or next branch for sandbox creation depending on the Storybo…
valentinpalkovic Jul 26, 2023
c9ccf9f
Fix test suite
valentinpalkovic Jul 26, 2023
4db9686
Use template name instead of template key to select from
valentinpalkovic Jul 26, 2023
32ed67e
Adjust generated Readme. Delete stackblitz file and cleanup generated…
valentinpalkovic Jul 27, 2023
f1c3b00
Exclude Angular Prerelease version from init scaffolding
valentinpalkovic Jul 28, 2023
b6aa49f
Adjust copy
valentinpalkovic Jul 28, 2023
5ed5035
Identify parent process to detect package manager
valentinpalkovic Jul 31, 2023
577cb00
Use yarn berry if detected for scaffolding and sanitize package.json …
valentinpalkovic Jul 31, 2023
b6720f6
Update sandboxes and make sandbox creation script package-manager agn…
valentinpalkovic Aug 3, 2023
04eec3b
Fix pnpm generation
valentinpalkovic Aug 4, 2023
a2f1b44
Fix resolutions nesting in yarn berry
valentinpalkovic Aug 5, 2023
889e2cc
Exclude Next.js pnpm and yarn templates
valentinpalkovic Aug 5, 2023
d1f8013
Add tests for resolutions methods in yarn2 and pnpm
valentinpalkovic Aug 6, 2023
17d6967
Remove repro generators
valentinpalkovic Aug 6, 2023
5039673
Support pnpm sandboxes in local sandbox creation
valentinpalkovic Aug 6, 2023
f4bca3a
Revert async type for JsPackageManagerFactory.getPackageManager
valentinpalkovic Aug 6, 2023
1ed2ff4
Do not run shouldRunDev if installation is skipped
valentinpalkovic Aug 6, 2023
8f8a34f
Format welcome to storybook sandbox properly
valentinpalkovic Aug 6, 2023
658c631
Refactor logic for isPnpmTemplate
valentinpalkovic Aug 6, 2023
513fcf9
Adjust reproduction message for sandbox command to cover all supporte…
valentinpalkovic Aug 6, 2023
394d1ef
Remove unnecessary await
valentinpalkovic Aug 6, 2023
8fb4ac1
Add documentation to sandbox installation process
valentinpalkovic Aug 6, 2023
6741944
Remove inDevelopment flag from yarn and pnpm sandboxes
valentinpalkovic Aug 6, 2023
f05b763
Revert branch triggering changes in generate-sandboxes-next.yml
valentinpalkovic Aug 6, 2023
e27d42e
Remove unused file
valentinpalkovic Aug 6, 2023
94fae6a
Remove yarn setup in sandbox reproductions
valentinpalkovic Aug 6, 2023
c40281b
Add download spinner to 'storybook sandbox' command
valentinpalkovic Aug 6, 2023
026178b
Use proper versions for overrides to satisfy verdaccio
valentinpalkovic Aug 7, 2023
fdd6bba
Update generate-sandboxes-next action to deploy from this PR
valentinpalkovic Aug 7, 2023
790faee
Allow immutable installs for sandbox creation
valentinpalkovic Aug 7, 2023
02e7fb0
Fix isPnpmTemplate func usage
valentinpalkovic Aug 7, 2023
09c461d
Add description to function
valentinpalkovic Aug 7, 2023
4696890
Remove setRegistryUrl from JsPackageManager class
valentinpalkovic Aug 7, 2023
4f02140
Remove unneeded comments
valentinpalkovic Aug 7, 2023
0fb2f8c
Deactivate yarn and pnpm sandboxes in ci:daily
valentinpalkovic Aug 7, 2023
0a55f51
Remove unnecessary process.env.CI
valentinpalkovic Aug 7, 2023
3f9158c
Do not set preserve-symlinks in pnpm sandboxes
valentinpalkovic Aug 7, 2023
cb88026
Reset generate-sandboxes-next.yml to use next as triggering branch
valentinpalkovic Aug 7, 2023
80aaf2a
filter down available sandboxes in init
yannbf Aug 8, 2023
82d2a4f
resolve PR suggestions
yannbf Aug 8, 2023
bc43886
infer package manager via user agent
yannbf Aug 9, 2023
99ac248
Merge branch 'next' into valentin/create-sandbox-in-empty-project
yannbf Aug 9, 2023
c6b94fd
use all sandbox templates in sandbox command
yannbf Aug 9, 2023
6938843
improve template filtering
yannbf Aug 11, 2023
d83da13
trigger sandbox update
yannbf Aug 11, 2023
fee58c9
debug generate-sandboxes
yannbf Aug 11, 2023
2679b4b
Merge branch 'next' into valentin/create-sandbox-in-empty-project
yannbf Aug 16, 2023
2bb1e87
disable npm perf override
yannbf Aug 16, 2023
da7c320
wip
yannbf Aug 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ jobs:
path: test-results
## new workflow
create-sandboxes:
environment:
YARN_ENABLE_IMMUTABLE_INSTALLS: 'false'
parameters:
parallelism:
type: integer
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/generate-sandboxes-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
generate:
runs-on: ubuntu-latest
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
CLEANUP_SANDBOX_NODE_MODULES: true
steps:
- uses: actions/setup-node@v3
Expand All @@ -29,6 +28,8 @@ jobs:
run: |
git config --global user.name "Storybook Bot"
git config --global user.email "bot@storybook.js.org"
- name: Install PNPM
run: npm i -g pnpm
- name: Install dependencies
run: node ./scripts/check-dependencies.js
- name: Compile Storybook libraries
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/generate-sandboxes-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ on:
workflow_dispatch:
# To test fixes on push rather than wait for the scheduling, do the following:
# 1. Uncomment the lines below and add your branch.
# push:
# branches:
# - <your-branch-name>
push:
branches:
- valentin/create-sandbox-in-empty-project
# 2. change the "ref" value to <your-branch-name> in the actions/checkout step below.
# 3. 👉 DON'T FORGET TO UNDO THE VALUES BACK TO `next` BEFORE YOU MERGE YOUR CHANGES!

jobs:
generate:
runs-on: ubuntu-latest
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
CLEANUP_SANDBOX_NODE_MODULES: true
steps:
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/checkout@v3
with:
ref: next
ref: valentin/create-sandbox-in-empty-project
Comment thread
valentinpalkovic marked this conversation as resolved.
- name: Setup git user
run: |
git config --global user.name "Storybook Bot"
git config --global user.email "bot@storybook.js.org"
- name: Install PNPM
run: npm i -g pnpm
- name: Install dependencies
run: node ./scripts/check-dependencies.js
- name: Compile Storybook libraries
Expand All @@ -43,7 +44,7 @@ jobs:
run: yarn wait-on http://localhost:6001
working-directory: ./code
- name: Generate
run: yarn generate-sandboxes --local-registry
run: yarn generate-sandboxes --local-registry --debug
working-directory: ./code
- name: Publish
run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/sandboxes.git --push --branch=next
Expand Down
3 changes: 2 additions & 1 deletion code/lib/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"bundler": {
"entries": [
"./src/generate.ts",
"./src/index.ts"
"./src/index.ts",
"./src/scaffolding-readme-template.md"
],
"platform": "node"
},
Expand Down
9 changes: 2 additions & 7 deletions code/lib/cli/src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import { logger } from '@storybook/node-logger';
import { resolve } from 'path';
import prompts from 'prompts';
import type { TemplateConfiguration, TemplateMatcher } from './project_types';
import {
ProjectType,
supportedTemplates,
SupportedLanguage,
unsupportedTemplate,
CoreBuilder,
} from './project_types';
import { ProjectType, SupportedLanguage, CoreBuilder } from './project_types';
import { commandLog, isNxProject } from './helpers';
import type { JsPackageManager, PackageJsonWithMaybeDeps } from './js-package-manager';
import { supportedTemplates, unsupportedTemplate } from './templates';

const viteConfigFiles = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs'];
const webpackConfigFiles = ['webpack.config.js'];
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ command('sandbox [filterValue]')
.description('Create a sandbox from a set of possible templates')
.option('-o --output <outDir>', 'Define an output directory')
.option('-b --branch <branch>', 'Define the branch to download from', 'next')
.option('-s --silent', 'Do not log any information to the console', false)
.option('--no-init', 'Whether to download a template without an initialized Storybook', false)
.action((filterValue, options) =>
sandbox({ filterValue, ...options }).catch((e) => {
Expand Down
36 changes: 36 additions & 0 deletions code/lib/cli/src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,40 @@ describe('Helpers', () => {
}).toThrowError("Couldn't find any official storybook packages in package.json");
});
});

describe('inferPackageManagerFromUserAgent', () => {
afterEach(() => {
delete process.env.npm_config_user_agent;
});

it('should return undefined for invalid user agent', () => {
process.env.npm_config_user_agent = '';
expect(helpers.inferPackageManagerFromUserAgent()).toBeUndefined();
});

it('should infer pnpm from user agent', () => {
process.env.npm_config_user_agent = 'pnpm/7.4.0';
expect(helpers.inferPackageManagerFromUserAgent()).toBe('pnpm');
});

it('should infer npm from user agent', () => {
process.env.npm_config_user_agent = 'npm/7.24.0';
expect(helpers.inferPackageManagerFromUserAgent()).toBe('npm');
});

it('should infer yarn 1 from user agent', () => {
process.env.npm_config_user_agent = 'yarn/1.22.11';
expect(helpers.inferPackageManagerFromUserAgent()).toBe('yarn1');
});

it('should infer yarn 2 from user agent', () => {
process.env.npm_config_user_agent = 'yarn/2.4.0';
expect(helpers.inferPackageManagerFromUserAgent()).toBe('yarn2');
});

it('should return undefined for unknown package manager', () => {
process.env.npm_config_user_agent = 'unknown';
expect(helpers.inferPackageManagerFromUserAgent()).toBeUndefined();
});
});
});
41 changes: 41 additions & 0 deletions code/lib/cli/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
JsPackageManager,
PackageJson,
PackageJsonWithDepsAndDevDeps,
PackageManagerName,
} from './js-package-manager';
import type { SupportedFrameworks, SupportedRenderers } from './project_types';
import { SupportedLanguage } from './project_types';
Expand Down Expand Up @@ -303,3 +304,43 @@ export function getStorybookVersionSpecifier(packageJson: PackageJsonWithDepsAnd
export async function isNxProject() {
return findUp.sync('nx.json');
}

/**
* Use this in switch statements in the default expression to assert that all enum values are handled.
* @example
* switch (foo: 'bar' | 'baz') {
* case 'bar':
* return 'bar';
* default:
* // Typescript will error here because `baz` is not handled
* return assertNever(foo);
*/
export function assertNever(x: never): never {
throw new Error(`Unexpected object: ${x}`);
}

/**
* Infer the package manager based on the command the user is running.
* Each package manager sets the `npm_config_user_agent` environment variable with its name and version e.g. "npm/7.24.0"
* Which is really useful when invoking commands via npx/pnpx/yarn create/etc.
*/
export function inferPackageManagerFromUserAgent(): PackageManagerName {
const userAgent = process.env.npm_config_user_agent;
if (!userAgent) return undefined;
const packageSpec = userAgent.split(' ')[0];
const [pkgMgrName, pkgMgrVersion] = packageSpec.split('/');

if (pkgMgrName === 'pnpm') {
return 'pnpm';
}

if (pkgMgrName === 'npm') {
return 'npm';
}

if (pkgMgrName === 'yarn') {
return `yarn${pkgMgrVersion?.startsWith('1.') ? '1' : '2'}`;
}

return undefined;
}
Loading