mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
Remove unused postinstall package
This commit is contained in:
parent
1e933494b7
commit
458afe7aa1
@ -10,6 +10,7 @@
|
||||
- [New UI and props for Button and IconButton components](#new-ui-and-props-for-button-and-iconbutton-components)
|
||||
- [Icons is deprecated](#icons-is-deprecated)
|
||||
- [React-docgen component analysis by default](#react-docgen-component-analysis-by-default)
|
||||
- [Removed postinstall](#removed-postinstall)
|
||||
- [Framework-specific changes](#framework-specific-changes)
|
||||
- [Angular: Drop support for Angular \< 15](#angular-drop-support-for-angular--15)
|
||||
- [Next.js: Drop support for version \< 13.5](#nextjs-drop-support-for-version--135)
|
||||
@ -463,6 +464,10 @@ export default {
|
||||
|
||||
For more information see: https://storybook.js.org/docs/react/api/main-config-typescript#reactdocgen
|
||||
|
||||
#### Removed postinstall
|
||||
|
||||
We removed the `@storybook/postinstall` package, which provided some utilities for addons to programmatically modify user configuration files on install. This package was years out of date, so this should be a non-disruptive change. If your addon used the package, you can view the old source code [here](https://github.com/storybookjs/storybook/tree/release-7-5/code/lib/postinstall) and adapt it into your addon.
|
||||
|
||||
### Framework-specific changes
|
||||
|
||||
#### Angular: Drop support for Angular \< 15
|
||||
|
@ -83,7 +83,6 @@
|
||||
"ember/**/*",
|
||||
"html/**/*",
|
||||
"svelte/**/*",
|
||||
"postinstall/**/*",
|
||||
"react/**/*",
|
||||
"vue/**/*",
|
||||
"web-components/**/*",
|
||||
@ -108,7 +107,6 @@
|
||||
"@storybook/global": "^5.0.0",
|
||||
"@storybook/mdx2-csf": "^1.0.0",
|
||||
"@storybook/node-logger": "workspace:*",
|
||||
"@storybook/postinstall": "workspace:*",
|
||||
"@storybook/preview-api": "workspace:*",
|
||||
"@storybook/react-dom-shim": "workspace:*",
|
||||
"@storybook/theming": "workspace:*",
|
||||
|
@ -1,36 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import { presetsAddPreset, getFrameworks } from '@storybook/postinstall';
|
||||
import { logger } from '@storybook/node-logger';
|
||||
|
||||
export default function transformer(file, api) {
|
||||
const packageJson = JSON.parse(fs.readFileSync('./package.json'));
|
||||
const frameworks = getFrameworks(packageJson);
|
||||
|
||||
let err = null;
|
||||
let framework = null;
|
||||
let presetOptions = null;
|
||||
if (frameworks.length !== 1) {
|
||||
err = `${frameworks.length === 0 ? 'No' : 'Multiple'} frameworks found: ${frameworks}`;
|
||||
logger.error(`${err}, please configure '@storybook/addon-docs' manually.`);
|
||||
return file.source;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
framework = frameworks[0];
|
||||
|
||||
const { dependencies, devDependencies } = packageJson;
|
||||
if (
|
||||
framework === 'react' &&
|
||||
((dependencies && dependencies['react-scripts']) ||
|
||||
(devDependencies && devDependencies['react-scripts']))
|
||||
) {
|
||||
presetOptions = {};
|
||||
}
|
||||
|
||||
const j = api.jscodeshift;
|
||||
const root = j(file.source);
|
||||
|
||||
presetsAddPreset(`@storybook/addon-docs/preset`, presetOptions, { root, api });
|
||||
|
||||
return root.toSource({ quote: 'single' });
|
||||
}
|
@ -43,7 +43,6 @@ export default {
|
||||
'@storybook/manager-api': '8.0.0-alpha.1',
|
||||
'@storybook/nextjs': '8.0.0-alpha.1',
|
||||
'@storybook/node-logger': '8.0.0-alpha.1',
|
||||
'@storybook/postinstall': '8.0.0-alpha.1',
|
||||
'@storybook/preact': '8.0.0-alpha.1',
|
||||
'@storybook/preact-vite': '8.0.0-alpha.1',
|
||||
'@storybook/preact-webpack5': '8.0.0-alpha.1',
|
||||
|
@ -1,20 +0,0 @@
|
||||
# Storybook Postinstall Utilities
|
||||
|
||||
A minimal utility library for addons to update project configurations after the addon is installed via the [Storybook CLI](https://github.com/storybookjs/storybook/tree/main/lib/cli), e.g. `sb add docs`.
|
||||
|
||||
Each postinstall is written as a [jscodeshift](https://github.com/facebook/jscodeshift) codemod, with the naming convention `addon-name/postinstall/<file>.js` where `file` is one of { `config`, `addons`, `presets` }.
|
||||
|
||||
If these files are present in the addon, the CLI will run them on the existing file in the user's project (or create a new empty file if one doesn't exist). This library exists to make it really easy to make common modifications without having to muck with jscodeshift internals.
|
||||
|
||||
## Adding a preset
|
||||
|
||||
To add a preset to `presets.js`, simply create a file `postinstall/presets.js` in your addon:
|
||||
|
||||
```js
|
||||
import { presetsAddPreset } = require('@storybook/postinstall');
|
||||
export default function transformer(file, api) {
|
||||
const root = api.jscodeshift(file.source);
|
||||
presetsAddPreset(`@storybook/addon-docs/preset`, { some: 'options' }, { root, api });
|
||||
return root.toSource();
|
||||
};
|
||||
```
|
@ -1,7 +0,0 @@
|
||||
const path = require('path');
|
||||
const baseConfig = require('../../jest.config.node');
|
||||
|
||||
module.exports = {
|
||||
...baseConfig,
|
||||
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
|
||||
};
|
@ -1,62 +0,0 @@
|
||||
{
|
||||
"name": "@storybook/postinstall",
|
||||
"version": "8.0.0-alpha.1",
|
||||
"description": "Storybook addons postinstall utilities",
|
||||
"keywords": [
|
||||
"api",
|
||||
"storybook"
|
||||
],
|
||||
"homepage": "https://github.com/storybookjs/storybook/tree/next/code/lib/postinstall",
|
||||
"bugs": {
|
||||
"url": "https://github.com/storybookjs/storybook/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/storybookjs/storybook.git",
|
||||
"directory": "code/lib/postinstall"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/storybook"
|
||||
},
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"node": "./dist/index.js",
|
||||
"require": "./dist/index.js",
|
||||
"import": "./dist/index.mjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.mjs",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist/**/*",
|
||||
"README.md",
|
||||
"*.js",
|
||||
"*.d.ts",
|
||||
"!src/**/*"
|
||||
],
|
||||
"scripts": {
|
||||
"check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts",
|
||||
"prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.7.0",
|
||||
"jest-specific-snapshot": "^8.0.0",
|
||||
"jscodeshift": "^0.15.1",
|
||||
"typescript": "^5.3.2"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"bundler": {
|
||||
"entries": [
|
||||
"./src/index.ts"
|
||||
]
|
||||
},
|
||||
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae17"
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "@storybook/postinstall",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"implicitDependencies": [],
|
||||
"type": "library"
|
||||
}
|
@ -1 +0,0 @@
|
||||
module.exports = ['foo'];
|
@ -1,8 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`presets-add-preset-options transforms correctly using "basic.input.js" data 1`] = `
|
||||
"module.exports = ['foo', {
|
||||
name: 'test',
|
||||
options: {\\"a\\":[1,2,3],\\"b\\":{\\"foo\\":\\"bar\\"},\\"c\\":\\"baz\\"}
|
||||
}];"
|
||||
`;
|
@ -1,8 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`presets-add-preset-options transforms correctly using "empty.input.js" data 1`] = `
|
||||
"module.exports = [{
|
||||
name: 'test',
|
||||
options: {\\"a\\":[1,2,3],\\"b\\":{\\"foo\\":\\"bar\\"},\\"c\\":\\"baz\\"}
|
||||
}];"
|
||||
`;
|
@ -1 +0,0 @@
|
||||
module.exports = ['foo'];
|
@ -1,3 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`presets-add-preset transforms correctly using "basic.input.js" data 1`] = `"module.exports = ['foo', 'test'];"`;
|
@ -1,3 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`presets-add-preset transforms correctly using "empty.input.js" data 1`] = `"module.exports = ['test'];"`;
|
@ -1,16 +0,0 @@
|
||||
import { addPreset } from '../presets';
|
||||
|
||||
export default function transformer(file, api) {
|
||||
const j = api.jscodeshift;
|
||||
const root = j(file.source);
|
||||
|
||||
const options = {
|
||||
a: [1, 2, 3],
|
||||
b: { foo: 'bar' },
|
||||
c: 'baz',
|
||||
};
|
||||
|
||||
addPreset('test', options, { root, api });
|
||||
|
||||
return root.toSource({ quote: 'single' });
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
import { addPreset } from '../presets';
|
||||
|
||||
export default function transformer(file, api) {
|
||||
const j = api.jscodeshift;
|
||||
const root = j(file.source);
|
||||
|
||||
addPreset('test', null, { root, api });
|
||||
|
||||
return root.toSource({ quote: 'single' });
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import 'jest-specific-snapshot';
|
||||
// @ts-expect-error (broken types)
|
||||
import { applyTransform } from 'jscodeshift/dist/testUtils';
|
||||
|
||||
jest.mock('@storybook/node-logger');
|
||||
|
||||
const inputRegExp = /\.input\.js$/;
|
||||
|
||||
const fixturesDir = path.resolve(__dirname, './__testfixtures__');
|
||||
fs.readdirSync(fixturesDir).forEach((transformName) => {
|
||||
const transformFixturesDir = path.join(fixturesDir, transformName);
|
||||
describe(`${transformName}`, () => {
|
||||
fs.readdirSync(transformFixturesDir)
|
||||
.filter((fileName) => inputRegExp.test(fileName))
|
||||
.forEach((fileName) => {
|
||||
const inputPath = path.join(transformFixturesDir, fileName);
|
||||
it(`transforms correctly using "${fileName}" data`, () =>
|
||||
expect(
|
||||
applyTransform(
|
||||
// eslint-disable-next-line global-require,import/no-dynamic-require
|
||||
require(path.join(__dirname, '__testtransforms__', transformName)),
|
||||
null,
|
||||
{ path: inputPath, source: fs.readFileSync(inputPath, 'utf8') }
|
||||
)
|
||||
).toMatchSpecificSnapshot(inputPath.replace(inputRegExp, '.output.snapshot')));
|
||||
});
|
||||
});
|
||||
});
|
@ -1,42 +0,0 @@
|
||||
import { it, describe, expect } from '@jest/globals';
|
||||
import { getFrameworks } from './frameworks';
|
||||
|
||||
const REACT = {
|
||||
'@storybook/react': '5.2.5',
|
||||
};
|
||||
|
||||
const VUE = {
|
||||
'@storybook/vue': '5.2.5',
|
||||
};
|
||||
|
||||
const NONE = {
|
||||
'@storybook/preview-api': '5.2.5',
|
||||
lodash: '^4.17.15',
|
||||
};
|
||||
|
||||
describe('getFrameworks', () => {
|
||||
it('single framework', () => {
|
||||
const frameworks = getFrameworks({
|
||||
dependencies: NONE,
|
||||
devDependencies: REACT,
|
||||
});
|
||||
expect(frameworks).toEqual(['react']);
|
||||
});
|
||||
it('multi-framework', () => {
|
||||
const frameworks = getFrameworks({
|
||||
dependencies: VUE,
|
||||
devDependencies: REACT,
|
||||
});
|
||||
expect(frameworks.sort()).toEqual(['react', 'vue']);
|
||||
});
|
||||
it('no deps', () => {
|
||||
const frameworks = getFrameworks({});
|
||||
expect(frameworks).toEqual([]);
|
||||
});
|
||||
it('no framework', () => {
|
||||
const frameworks = getFrameworks({
|
||||
dependencies: NONE,
|
||||
});
|
||||
expect(frameworks).toEqual([]);
|
||||
});
|
||||
});
|
@ -1,25 +0,0 @@
|
||||
type Deps = Record<string, string>;
|
||||
interface PackageJson {
|
||||
dependencies?: Deps;
|
||||
devDependencies?: Deps;
|
||||
}
|
||||
|
||||
const FRAMEWORKS = [
|
||||
'angular',
|
||||
'ember',
|
||||
'html',
|
||||
'preact',
|
||||
'react',
|
||||
'react-native',
|
||||
'svelte',
|
||||
'vue',
|
||||
'web-components',
|
||||
];
|
||||
|
||||
export const getFrameworks = ({ dependencies, devDependencies }: PackageJson): string[] => {
|
||||
const allDeps: Deps = {};
|
||||
Object.assign(allDeps, dependencies || {});
|
||||
Object.assign(allDeps, devDependencies || {});
|
||||
|
||||
return FRAMEWORKS.filter((f) => !!allDeps[`@storybook/${f}`]);
|
||||
};
|
@ -1,2 +0,0 @@
|
||||
export { addPreset as presetsAddPreset } from './presets';
|
||||
export * from './frameworks';
|
@ -1,50 +0,0 @@
|
||||
interface PostinstallContext {
|
||||
root: any;
|
||||
api: any;
|
||||
}
|
||||
|
||||
export function addPreset(preset: string, presetOptions: any, { api, root }: PostinstallContext) {
|
||||
const j = api.jscodeshift;
|
||||
const moduleExports: any[] = [];
|
||||
root
|
||||
.find(j.AssignmentExpression)
|
||||
.filter(
|
||||
(assignment: any) =>
|
||||
assignment.node.left.type === 'MemberExpression' &&
|
||||
assignment.node.left.object.name === 'module' &&
|
||||
assignment.node.left.property.name === 'exports'
|
||||
)
|
||||
.forEach((exp: any) => moduleExports.push(exp));
|
||||
|
||||
let exportArray = null;
|
||||
switch (moduleExports.length) {
|
||||
case 0: {
|
||||
exportArray = j.arrayExpression([]);
|
||||
const exportStatement = j.assignmentStatement(
|
||||
'=',
|
||||
j.memberExpression(j.identifier('module'), j.identifier('exports')),
|
||||
exportArray
|
||||
);
|
||||
root.get().node.program.body.push(exportStatement);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
exportArray = moduleExports[0].node.right;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Multiple module export statements');
|
||||
}
|
||||
|
||||
let presetConfig = j.literal(preset);
|
||||
if (presetOptions) {
|
||||
const optionsJson = `const x = ${JSON.stringify(presetOptions)}`;
|
||||
const optionsRoot = j(optionsJson);
|
||||
const optionsNode = optionsRoot.find(j.VariableDeclarator).get().node.init;
|
||||
|
||||
presetConfig = j.objectExpression([
|
||||
j.property('init', j.identifier('name'), j.literal(preset)),
|
||||
j.property('init', j.identifier('options'), optionsNode),
|
||||
]);
|
||||
}
|
||||
exportArray.elements.push(presetConfig);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node"],
|
||||
"strict": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
@ -149,7 +149,6 @@
|
||||
"@storybook/manager-api": "workspace:*",
|
||||
"@storybook/nextjs": "workspace:*",
|
||||
"@storybook/node-logger": "workspace:*",
|
||||
"@storybook/postinstall": "workspace:*",
|
||||
"@storybook/preact": "workspace:*",
|
||||
"@storybook/preact-vite": "workspace:*",
|
||||
"@storybook/preact-webpack5": "workspace:*",
|
||||
|
@ -49,7 +49,6 @@
|
||||
"@storybook/manager": "portal:../../code/ui/manager",
|
||||
"@storybook/nextjs": "portal:../../code/frameworks/nextjs",
|
||||
"@storybook/node-logger": "portal:../../code/lib/node-logger",
|
||||
"@storybook/postinstall": "portal:../../code/lib/postinstall",
|
||||
"@storybook/preact": "portal:../../code/renderers/preact",
|
||||
"@storybook/preact-webpack5": "portal:../../code/frameworks/preact-webpack5",
|
||||
"@storybook/preset-html-webpack": "portal:../../code/presets/html-webpack",
|
||||
|
@ -50,7 +50,6 @@
|
||||
"@storybook/manager-api": "portal:../../code/lib/manager-api",
|
||||
"@storybook/nextjs": "portal:../../code/frameworks/nextjs",
|
||||
"@storybook/node-logger": "portal:../../code/lib/node-logger",
|
||||
"@storybook/postinstall": "portal:../../code/lib/postinstall",
|
||||
"@storybook/preact": "portal:../../code/renderers/preact",
|
||||
"@storybook/preact-webpack5": "portal:../../code/frameworks/preact-webpack5",
|
||||
"@storybook/preset-html-webpack": "portal:../../code/presets/html-webpack",
|
||||
@ -116,4 +115,4 @@
|
||||
"typescript": "~5.2.2",
|
||||
"webpack": "5"
|
||||
}
|
||||
}
|
||||
}
|
@ -52,7 +52,6 @@
|
||||
"@storybook/manager": "portal:../../code/ui/manager",
|
||||
"@storybook/nextjs": "portal:../../code/frameworks/nextjs",
|
||||
"@storybook/node-logger": "portal:../../code/lib/node-logger",
|
||||
"@storybook/postinstall": "portal:../../code/lib/postinstall",
|
||||
"@storybook/preact": "portal:../../code/renderers/preact",
|
||||
"@storybook/preact-webpack5": "portal:../../code/frameworks/preact-webpack5",
|
||||
"@storybook/preset-html-webpack": "portal:../../code/presets/html-webpack",
|
||||
|
@ -45,7 +45,6 @@
|
||||
"@storybook/manager": "portal:../../code/ui/manager",
|
||||
"@storybook/nextjs": "portal:../../code/frameworks/nextjs",
|
||||
"@storybook/node-logger": "portal:../../code/lib/node-logger",
|
||||
"@storybook/postinstall": "portal:../../code/lib/postinstall",
|
||||
"@storybook/preact": "portal:../../code/renderers/preact",
|
||||
"@storybook/preact-webpack5": "portal:../../code/frameworks/preact-webpack5",
|
||||
"@storybook/preset-html-webpack": "portal:../../code/presets/html-webpack",
|
||||
|
Loading…
x
Reference in New Issue
Block a user