@nx/storybook 22.1.0-beta.5 → 22.1.0-beta.7
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/migrations.json +2 -2
- package/package.json +6 -6
- package/src/migrations/update-22-1-0/files/ai-instructions-for-cjs-esm.md +175 -0
- package/src/migrations/update-22-1-0/migrate-to-storybook-10.d.ts +1 -1
- package/src/migrations/update-22-1-0/migrate-to-storybook-10.d.ts.map +1 -1
- package/src/migrations/update-22-1-0/migrate-to-storybook-10.js +13 -1
package/migrations.json
CHANGED
|
@@ -634,8 +634,8 @@
|
|
|
634
634
|
}
|
|
635
635
|
}
|
|
636
636
|
},
|
|
637
|
-
"
|
|
638
|
-
"version": "
|
|
637
|
+
"22.1.0": {
|
|
638
|
+
"version": "22.1.0-beta.6",
|
|
639
639
|
"x-prompt": "Do you want to update Storybook to version 10?",
|
|
640
640
|
"implementation": "./src/migrations/update-21-2-0/migrate-to-storybook-10",
|
|
641
641
|
"requires": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/storybook",
|
|
3
|
-
"version": "22.1.0-beta.
|
|
3
|
+
"version": "22.1.0-beta.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Storybook contains executors and generators for allowing your workspace to use the powerful Storybook integration testing & documenting capabilities.",
|
|
6
6
|
"repository": {
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
"migrations": "./migrations.json"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nx/devkit": "22.1.0-beta.
|
|
36
|
+
"@nx/devkit": "22.1.0-beta.7",
|
|
37
37
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
38
38
|
"semver": "^7.6.3",
|
|
39
39
|
"tslib": "^2.3.0",
|
|
40
|
-
"@nx/cypress": "22.1.0-beta.
|
|
41
|
-
"@nx/js": "22.1.0-beta.
|
|
42
|
-
"@nx/eslint": "22.1.0-beta.
|
|
40
|
+
"@nx/cypress": "22.1.0-beta.7",
|
|
41
|
+
"@nx/js": "22.1.0-beta.7",
|
|
42
|
+
"@nx/eslint": "22.1.0-beta.7"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"nx": "22.1.0-beta.
|
|
45
|
+
"nx": "22.1.0-beta.7"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"storybook": ">=7.0.0 <11.0.0"
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Instructions for LLM: Transform Storybook Config Files from CommonJS to ESM
|
|
2
|
+
|
|
3
|
+
## Task Overview
|
|
4
|
+
|
|
5
|
+
Find all .storybook/main.ts and .storybook/main.js files in the workspace and transform
|
|
6
|
+
any CommonJS (CJS) configurations to ES Modules (ESM).
|
|
7
|
+
|
|
8
|
+
### Step 1: Find All Storybook Config Files
|
|
9
|
+
|
|
10
|
+
Use glob patterns to locate all Storybook main configuration files:
|
|
11
|
+
**/.storybook/main.js
|
|
12
|
+
**/.storybook/main.ts
|
|
13
|
+
|
|
14
|
+
### Step 2: Identify CommonJS vs ESM
|
|
15
|
+
|
|
16
|
+
For each file found, read its contents and determine if it uses CommonJS syntax by
|
|
17
|
+
checking for:
|
|
18
|
+
|
|
19
|
+
CommonJS indicators:
|
|
20
|
+
|
|
21
|
+
- `module.exports =` or `module.exports.`
|
|
22
|
+
- `exports.`
|
|
23
|
+
- `require()` function calls
|
|
24
|
+
|
|
25
|
+
ESM indicators (already correct):
|
|
26
|
+
|
|
27
|
+
- export default
|
|
28
|
+
- export const/export function
|
|
29
|
+
- import statements
|
|
30
|
+
|
|
31
|
+
### Step 3: Transform CJS to ESM
|
|
32
|
+
|
|
33
|
+
For each file identified as CommonJS, perform the following transformations:
|
|
34
|
+
|
|
35
|
+
A. Convert `module.exports`
|
|
36
|
+
|
|
37
|
+
// FROM (CJS):
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
module.exports = {
|
|
41
|
+
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
|
|
42
|
+
addons: ['@storybook/addon-essentials']
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
// TO (ESM):
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
export default {
|
|
50
|
+
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
|
|
51
|
+
addons: ['@storybook/addon-essentials']
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
B. Convert `require()` to import
|
|
56
|
+
|
|
57
|
+
// FROM (CJS):
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
const { nxViteTsPaths } = require('@nx/vite/plugins/nx-tsconfig-paths.plugin');
|
|
61
|
+
const { mergeConfig } = require('vite');
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
// TO (ESM):
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
68
|
+
import { mergeConfig } from 'vite';
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
C. Handle `path.join()` patterns
|
|
72
|
+
|
|
73
|
+
// FROM (CJS):
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
const path = require('path');
|
|
77
|
+
const rootMain = require(path.join(__dirname, '../../.storybook/main'));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
// TO (ESM):
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
import { join } from 'path';
|
|
84
|
+
import rootMain from '../../.storybook/main';
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
D. Handle Dynamic Requires in Config Functions
|
|
88
|
+
|
|
89
|
+
// FROM (CJS):
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
module.exports = {
|
|
93
|
+
viteFinal: async (config) => {
|
|
94
|
+
const { mergeConfig } = require('vite');
|
|
95
|
+
return mergeConfig(config, {});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
// TO (ESM):
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
import { mergeConfig } from 'vite';
|
|
104
|
+
|
|
105
|
+
export default {
|
|
106
|
+
viteFinal: async (config) => {
|
|
107
|
+
return mergeConfig(config, {});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Step 4: Validation Checks
|
|
113
|
+
|
|
114
|
+
After transformation, verify:
|
|
115
|
+
|
|
116
|
+
1. All require() calls have been converted to import statements at the top of the file
|
|
117
|
+
2. All module.exports have been converted to export default or named exports
|
|
118
|
+
3. Imports are at the top of the file (before the export)
|
|
119
|
+
4. The file maintains proper TypeScript typing if it's a .ts file
|
|
120
|
+
|
|
121
|
+
### Step 5: Report Results
|
|
122
|
+
|
|
123
|
+
Provide a summary of:
|
|
124
|
+
|
|
125
|
+
- Total files found
|
|
126
|
+
- Files that were already ESM (no changes needed)
|
|
127
|
+
- Files that were transformed from CJS to ESM
|
|
128
|
+
- List the specific files that were modified
|
|
129
|
+
|
|
130
|
+
### Example Complete Transformation
|
|
131
|
+
|
|
132
|
+
Before (CJS):
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
const path = require('path');
|
|
136
|
+
const { mergeConfig } = require('vite');
|
|
137
|
+
|
|
138
|
+
module.exports = {
|
|
139
|
+
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
|
|
140
|
+
addons: ['@storybook/addon-essentials'],
|
|
141
|
+
viteFinal: async (config) => {
|
|
142
|
+
return mergeConfig(config, {
|
|
143
|
+
resolve: {
|
|
144
|
+
alias: {}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
After (ESM):
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
import { join } from 'path';
|
|
155
|
+
import { mergeConfig } from 'vite';
|
|
156
|
+
|
|
157
|
+
export default {
|
|
158
|
+
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
|
|
159
|
+
addons: ['@storybook/addon-essentials'],
|
|
160
|
+
viteFinal: async (config) => {
|
|
161
|
+
return mergeConfig(config, {
|
|
162
|
+
resolve: {
|
|
163
|
+
alias: {}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Important Notes
|
|
171
|
+
|
|
172
|
+
- Preserve all comments in the original files
|
|
173
|
+
- Maintain the same indentation and formatting style
|
|
174
|
+
- For TypeScript files (.ts), ensure type imports use import type when appropriate
|
|
175
|
+
- Test that the transformations don't break the Storybook configuration
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-to-storybook-10.d.ts","sourceRoot":"","sources":["../../../../../../packages/storybook/src/migrations/update-22-1-0/migrate-to-storybook-10.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"migrate-to-storybook-10.d.ts","sourceRoot":"","sources":["../../../../../../packages/storybook/src/migrations/update-22-1-0/migrate-to-storybook-10.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAOlC,wBAA8B,oBAAoB,CAAC,IAAI,EAAE,IAAI,qBA6B5D"}
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = migrateToStorybook10;
|
|
4
4
|
const output_1 = require("nx/src/utils/output");
|
|
5
5
|
const migrate_10_1 = require("../../generators/migrate-10/migrate-10");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const fs_1 = require("fs");
|
|
6
8
|
async function migrateToStorybook10(tree) {
|
|
7
9
|
output_1.output.log({
|
|
8
10
|
title: 'Migrating Storybook to v10',
|
|
@@ -13,7 +15,17 @@ async function migrateToStorybook10(tree) {
|
|
|
13
15
|
`https://nx.dev/nx-api/storybook/generators/migrate-10`,
|
|
14
16
|
],
|
|
15
17
|
});
|
|
16
|
-
|
|
18
|
+
await (0, migrate_10_1.default)(tree, {
|
|
17
19
|
autoAcceptAllPrompts: true,
|
|
18
20
|
});
|
|
21
|
+
const pathToAiInstructions = (0, path_1.join)(__dirname, 'files', 'ai-instructions-for-cjs-esm.md');
|
|
22
|
+
if (!(0, fs_1.existsSync)(pathToAiInstructions)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const contents = (0, fs_1.readFileSync)(pathToAiInstructions);
|
|
26
|
+
tree.write('MIGRATE_STORYBOOK_10.md', contents);
|
|
27
|
+
return [
|
|
28
|
+
`Storybook 10 requires Storybook Configs to use ESM.`,
|
|
29
|
+
`We created 'MIGRATE_STORYBOOK_10.md' with instructions for an AI Agent to convert CJS Storybook Configs to ESM in your workspace.`,
|
|
30
|
+
];
|
|
19
31
|
}
|