@akinon/next 2.0.10-beta.0 → 2.0.10

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/CHANGELOG.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # @akinon/next
2
2
 
3
- ## 2.0.10-beta.0
3
+ ## 2.0.10
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - cbbbfd75: ZERO-4376: Bootstrap beta cycle (next-main pre-release motor)
7
+ - 31f07bd7: ZERO-4459: Move migrate-eslint codemod into @akinon/projectzero and integrate into upgrade-to-2
8
8
 
9
9
  ## 2.0.9
10
10
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "2.0.10-beta.0",
4
+ "version": "2.0.10",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -11,8 +11,7 @@
11
11
  "pz-prestart": "bin/pz-prestart.js",
12
12
  "pz-poststart": "bin/pz-poststart.js",
13
13
  "pz-predev": "bin/pz-predev.js",
14
- "pz-postdev": "bin/pz-postdev.js",
15
- "pz-migrate-eslint": "bin/pz-migrate-eslint.js"
14
+ "pz-postdev": "bin/pz-postdev.js"
16
15
  },
17
16
  "scripts": {
18
17
  "test": "jest"
@@ -37,7 +36,7 @@
37
36
  "set-cookie-parser": "2.6.0"
38
37
  },
39
38
  "devDependencies": {
40
- "@akinon/eslint-plugin-projectzero": "2.0.10-beta.0",
39
+ "@akinon/eslint-plugin-projectzero": "2.0.10",
41
40
  "@babel/core": "7.26.10",
42
41
  "@babel/preset-env": "7.26.9",
43
42
  "@babel/preset-typescript": "7.27.0",
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require('path');
4
- const { migrate } = require(path.join(__dirname, '..', 'codemods', 'migrate-eslint-flat'));
5
-
6
- migrate(process.argv[2]);
@@ -1,247 +0,0 @@
1
- /**
2
- * ESLint flat config migration codemod.
3
- *
4
- * Converts a brand project from legacy `.eslintrc.js` to ESLint v9 flat config
5
- * (`eslint.config.mjs`), consuming the shared base from
6
- * `@akinon/next/eslint.config.base.mjs`.
7
- *
8
- * Idempotent: re-running on an already migrated project is a no-op for
9
- * already-applied steps.
10
- *
11
- * Steps:
12
- * 1. Read .eslintrc.js (if present) to detect brand-specific settings
13
- * (settings.next.rootDir, custom rules).
14
- * 2. Read .eslintignore (if present) to collect ignore patterns.
15
- * 3. Write eslint.config.mjs (skipped if already exists).
16
- * 4. Delete .eslintrc.js and .eslintignore.
17
- * 5. Rewrite .lintstagedrc.js to use `eslint --fix` instead of `next lint`.
18
- * 6. Patch package.json:
19
- * - scripts.lint: "next lint" -> "eslint ."
20
- * - eslint: ^8.x -> ^9.39.4
21
- * - eslint-config-prettier: ^8.x -> ^10.1.1
22
- * - remove @typescript-eslint/eslint-plugin and @typescript-eslint/parser
23
- * (now provided by eslint-config-next/typescript).
24
- */
25
-
26
- 'use strict';
27
-
28
- const fs = require('fs');
29
- const path = require('path');
30
-
31
- const ESLINT_TARGET = '9.39.4';
32
- const ESLINT_CONFIG_PRETTIER_TARGET = '10.1.1';
33
- const TYPESCRIPT_ESLINT_DROP = [
34
- '@typescript-eslint/eslint-plugin',
35
- '@typescript-eslint/parser'
36
- ];
37
-
38
- function buildFlatConfig({ rootDir, ignores, customRules }) {
39
- const lines = [
40
- "import { defineConfig, globalIgnores } from 'eslint/config';",
41
- "import baseConfig from '@akinon/next/eslint.config.base.mjs';",
42
- '',
43
- 'export default defineConfig([',
44
- ' ...baseConfig'
45
- ];
46
-
47
- if (rootDir) {
48
- lines[lines.length - 1] += ',';
49
- lines.push(
50
- ' {',
51
- ' settings: {',
52
- ' next: {',
53
- ` rootDir: ${JSON.stringify(rootDir)}`,
54
- ' }',
55
- ' }',
56
- ' }'
57
- );
58
- }
59
-
60
- if (customRules) {
61
- lines[lines.length - 1] += ',';
62
- const indented = JSON.stringify(customRules, null, 2)
63
- .split('\n')
64
- .map((l, i) => (i === 0 ? ' rules: ' + l : ' ' + l))
65
- .join('\n');
66
- lines.push(' {', indented, ' }');
67
- }
68
-
69
- if (ignores && ignores.length) {
70
- lines[lines.length - 1] += ',';
71
- lines.push(` globalIgnores(${JSON.stringify(ignores)})`);
72
- }
73
-
74
- lines.push(']);', '');
75
-
76
- return lines.join('\n');
77
- }
78
-
79
- const LINT_STAGED_TEMPLATE = `const path = require('path');
80
-
81
- const buildEslintCommand = (filenames) =>
82
- \`eslint --fix \${filenames
83
- .map((f) => \`"\${path.relative(process.cwd(), f)}"\`)
84
- .join(' ')}\`;
85
-
86
- module.exports = {
87
- '**/*.(ts|tsx)': () => 'yarn tsc --noEmit',
88
- '*.{js,jsx,ts,tsx}': [buildEslintCommand, 'prettier --write'],
89
- '*.{css,scss}': [
90
- 'stylelint --fix --allow-empty-input',
91
- 'prettier --write',
92
- 'stylelint --allow-empty-input'
93
- ]
94
- };
95
- `;
96
-
97
- function loadLegacyConfig(eslintrcPath) {
98
- try {
99
- delete require.cache[require.resolve(eslintrcPath)];
100
- return require(eslintrcPath);
101
- } catch (err) {
102
- return { __parseError: err.message };
103
- }
104
- }
105
-
106
- function readIgnoreFile(eslintignorePath) {
107
- if (!fs.existsSync(eslintignorePath)) return [];
108
- const raw = fs.readFileSync(eslintignorePath, 'utf8');
109
- return raw
110
- .split(/\r?\n/)
111
- .map((line) => line.trim())
112
- .filter((line) => line && !line.startsWith('#'))
113
- .map((pattern) => (pattern.endsWith('/**') ? pattern : pattern + '/**'));
114
- }
115
-
116
- function patchPackageJson(pkgPath) {
117
- const raw = fs.readFileSync(pkgPath, 'utf8');
118
- const pkg = JSON.parse(raw);
119
- const changes = [];
120
-
121
- if (pkg.scripts && typeof pkg.scripts.lint === 'string') {
122
- if (/^next\s+lint\b/.test(pkg.scripts.lint.trim())) {
123
- pkg.scripts.lint = 'eslint .';
124
- changes.push('scripts.lint -> "eslint ."');
125
- }
126
- }
127
-
128
- const bumpDev = (name, target) => {
129
- if (!pkg.devDependencies || !pkg.devDependencies[name]) return;
130
- const current = pkg.devDependencies[name].replace(/^\^|^~/, '');
131
- if (current === target) return;
132
- pkg.devDependencies[name] = target;
133
- changes.push(`devDependencies.${name} ${current} -> ${target}`);
134
- };
135
-
136
- bumpDev('eslint', ESLINT_TARGET);
137
- bumpDev('eslint-config-prettier', ESLINT_CONFIG_PRETTIER_TARGET);
138
-
139
- for (const dep of TYPESCRIPT_ESLINT_DROP) {
140
- if (pkg.devDependencies && pkg.devDependencies[dep]) {
141
- delete pkg.devDependencies[dep];
142
- changes.push(`removed devDependencies.${dep}`);
143
- }
144
- }
145
-
146
- if (changes.length === 0) return { changed: false, changes };
147
-
148
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
149
- return { changed: true, changes };
150
- }
151
-
152
- function migrate(projectRoot) {
153
- const root = path.resolve(projectRoot || process.cwd());
154
- const eslintrcPath = path.join(root, '.eslintrc.js');
155
- const eslintignorePath = path.join(root, '.eslintignore');
156
- const flatConfigPath = path.join(root, 'eslint.config.mjs');
157
- const lintStagedPath = path.join(root, '.lintstagedrc.js');
158
- const packageJsonPath = path.join(root, 'package.json');
159
-
160
- if (!fs.existsSync(packageJsonPath)) {
161
- console.error(`[migrate-eslint-flat] No package.json found in ${root}`);
162
- process.exit(1);
163
- }
164
-
165
- console.log(`[migrate-eslint-flat] Project root: ${root}`);
166
- const summary = [];
167
-
168
- const legacyConfig = fs.existsSync(eslintrcPath)
169
- ? loadLegacyConfig(eslintrcPath)
170
- : null;
171
-
172
- if (legacyConfig && legacyConfig.__parseError) {
173
- console.warn(
174
- `[migrate-eslint-flat] Could not parse .eslintrc.js: ${legacyConfig.__parseError}`
175
- );
176
- console.warn('Continuing with default brand-template settings.');
177
- }
178
-
179
- const rootDir = legacyConfig?.settings?.next?.rootDir;
180
- const customRules =
181
- legacyConfig && legacyConfig.rules && Object.keys(legacyConfig.rules).length
182
- ? legacyConfig.rules
183
- : null;
184
-
185
- let ignores = readIgnoreFile(eslintignorePath);
186
- if (ignores.length === 0) ignores = ['public/**'];
187
-
188
- if (!fs.existsSync(flatConfigPath)) {
189
- fs.writeFileSync(
190
- flatConfigPath,
191
- buildFlatConfig({ rootDir, ignores, customRules }),
192
- 'utf8'
193
- );
194
- summary.push('created eslint.config.mjs');
195
- } else {
196
- summary.push('eslint.config.mjs already exists (skipped)');
197
- }
198
-
199
- if (fs.existsSync(eslintrcPath)) {
200
- fs.unlinkSync(eslintrcPath);
201
- summary.push('removed .eslintrc.js');
202
- }
203
-
204
- if (fs.existsSync(eslintignorePath)) {
205
- fs.unlinkSync(eslintignorePath);
206
- summary.push('removed .eslintignore');
207
- }
208
-
209
- if (fs.existsSync(lintStagedPath)) {
210
- const before = fs.readFileSync(lintStagedPath, 'utf8');
211
- if (before !== LINT_STAGED_TEMPLATE) {
212
- fs.writeFileSync(lintStagedPath, LINT_STAGED_TEMPLATE, 'utf8');
213
- summary.push('rewrote .lintstagedrc.js');
214
- } else {
215
- summary.push('.lintstagedrc.js already up to date (skipped)');
216
- }
217
- }
218
-
219
- const pkgResult = patchPackageJson(packageJsonPath);
220
- if (pkgResult.changed) {
221
- summary.push(`patched package.json (${pkgResult.changes.join(', ')})`);
222
- } else {
223
- summary.push('package.json already up to date (skipped)');
224
- }
225
-
226
- console.log('\nESLint flat config migration summary:');
227
- for (const line of summary) console.log(` - ${line}`);
228
-
229
- if (customRules) {
230
- console.log(
231
- `\nNote: ${Object.keys(customRules).length} custom rule(s) from the old ` +
232
- '.eslintrc.js were carried over into eslint.config.mjs.\nReview if ' +
233
- 'they are still needed (some may already be covered by the base config).'
234
- );
235
- }
236
-
237
- console.log('\nNext steps:');
238
- console.log(' 1. yarn install');
239
- console.log(' 2. yarn lint # expect 0 errors (warnings ok)');
240
- console.log(' 3. yarn build # smoke test');
241
- }
242
-
243
- if (require.main === module) {
244
- migrate(process.argv[2]);
245
- }
246
-
247
- module.exports = { migrate };