mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-19 05:02:40 +08:00
Merge pull request #20002 from storybookjs/tech/gen-exports-file-single-pass
Build: generate the `exports.ts` file in a single pass without `exec`
This commit is contained in:
commit
b36691a303
@ -2,35 +2,39 @@
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { dedent } from 'ts-dedent';
|
||||
import { exec } from '../../../../scripts/utils/exec';
|
||||
import { ESLint } from '../../../../scripts/node_modules/eslint';
|
||||
import { values } from '../src/globals/runtime';
|
||||
|
||||
const removeDefault = (input: string) => input !== 'default';
|
||||
|
||||
const location = path.join(__dirname, '..', 'src', 'globals', 'exports.ts');
|
||||
|
||||
const run = async () => {
|
||||
const { values } = await import('../src/globals/runtime');
|
||||
const data = Object.entries(values).reduce<Record<string, string[]>>((acc, [key, value]) => {
|
||||
acc[key] = Object.keys(value).filter(removeDefault);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
console.log('Generating...');
|
||||
await fs.ensureFile(location);
|
||||
await fs.writeFile(
|
||||
location,
|
||||
dedent`
|
||||
// this file is generated by generate-exports-file.ts
|
||||
// this is done to prevent runtime dependencies from making it's way into the build/start script of the manager
|
||||
// the manager builder needs to know which dependencies are 'globalized' in the ui
|
||||
const readyToWrite = fs.ensureFile(location);
|
||||
const text = dedent`
|
||||
// this file is generated by generate-exports-file.ts
|
||||
// this is done to prevent runtime dependencies from making it's way into the build/start script of the manager
|
||||
// the manager builder needs to know which dependencies are 'globalized' in the ui
|
||||
|
||||
export default ${JSON.stringify(data, null, 2)} as const;`
|
||||
);
|
||||
export default ${JSON.stringify(data, null, 2)} as const;`;
|
||||
|
||||
console.log('Linting...');
|
||||
await exec(`yarn lint:js:cmd --fix ${location}`, {
|
||||
cwd: path.join(__dirname, '..', '..', '..'),
|
||||
|
||||
const eslint = new ESLint({
|
||||
cwd: path.join(__dirname, '..'),
|
||||
fix: true,
|
||||
});
|
||||
const output = await eslint.lintText(text, { filePath: location });
|
||||
|
||||
await readyToWrite;
|
||||
await fs.writeFile(location, output[0].output);
|
||||
|
||||
console.log('Done!');
|
||||
};
|
||||
|
||||
|
@ -113,6 +113,7 @@
|
||||
"enzyme-adapter-react-16": "^1.15.5",
|
||||
"esbuild": "^0.14.48",
|
||||
"esbuild-plugin-alias": "^0.2.1",
|
||||
"esbuild-register": "^3.4.1",
|
||||
"eslint": "^8.27.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-react": "^7.31.10",
|
||||
|
@ -18,10 +18,8 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
|
||||
bundler: { entries = [], untypedEntries = [], platform, pre, post },
|
||||
} = await fs.readJson(join(cwd, 'package.json'));
|
||||
|
||||
const tsnodePath = join(__dirname, '..', 'node_modules', '.bin', 'ts-node');
|
||||
|
||||
if (pre) {
|
||||
await exec(`${tsnodePath} ${pre}`, { cwd });
|
||||
await exec(`node -r ${__dirname}/../node_modules/esbuild-register/register.js ${pre}`, { cwd });
|
||||
}
|
||||
|
||||
const reset = hasFlag(flags, 'reset');
|
||||
@ -125,7 +123,11 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
|
||||
]);
|
||||
|
||||
if (post) {
|
||||
await exec(`${tsnodePath} ${post}`, { cwd }, { debug: true });
|
||||
await exec(
|
||||
`node -r ${__dirname}/../node_modules/esbuild-register/register.js ${post}`,
|
||||
{ cwd },
|
||||
{ debug: true }
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -3270,6 +3270,7 @@ __metadata:
|
||||
enzyme-adapter-react-16: ^1.15.5
|
||||
esbuild: ^0.14.48
|
||||
esbuild-plugin-alias: ^0.2.1
|
||||
esbuild-register: ^3.4.1
|
||||
eslint: ^8.27.0
|
||||
eslint-plugin-import: ^2.26.0
|
||||
eslint-plugin-react: ^7.31.10
|
||||
@ -7688,6 +7689,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"esbuild-register@npm:^3.4.1":
|
||||
version: 3.4.1
|
||||
resolution: "esbuild-register@npm:3.4.1"
|
||||
dependencies:
|
||||
debug: ^4.3.4
|
||||
peerDependencies:
|
||||
esbuild: ">=0.12 <1"
|
||||
checksum: 6364c96f83fc4720d907d6342605f5891986c2a30fbc0a249047195ea5b02c0f7e4e698aa262875b37088f44ca741331d35c026d2606778d114fe082d560957d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"esbuild-sunos-64@npm:0.14.54":
|
||||
version: 0.14.54
|
||||
resolution: "esbuild-sunos-64@npm:0.14.54"
|
||||
|
Loading…
x
Reference in New Issue
Block a user