pob 22.5.0 → 23.0.1

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
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [23.0.1](https://github.com/christophehurpeau/pob/compare/pob@23.0.0...pob@23.0.1) (2024-08-12)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **pob:** use copyAndFormatTpl to auto format eslint.config.js ([06b0707](https://github.com/christophehurpeau/pob/commit/06b0707532223f4c55c070d116f839af5f9aaa45))
11
+ * update pob eslint config ([981c435](https://github.com/christophehurpeau/pob/commit/981c435c6741f672eb96651726c879ace6c1ec63))
12
+
13
+ Version bump for dependency: yarn-workspace-utils
14
+
15
+
16
+ ## [23.0.0](https://github.com/christophehurpeau/pob/compare/pob@22.5.0...pob@23.0.0) (2024-08-11)
17
+
18
+ ### ⚠ BREAKING CHANGES
19
+
20
+ * update to eslint flat config
21
+
22
+ ### Features
23
+
24
+ * update to eslint flat config ([9e9b530](https://github.com/christophehurpeau/pob/commit/9e9b530e1c89ad4f0fafa1af8f4a13816544f16c))
25
+
26
+ Version bump for dependency: @pob/sort-eslint-config
27
+ Version bump for dependency: @pob/sort-object
28
+ Version bump for dependency: @pob/sort-pkg
29
+ Version bump for dependency: yarn-workspace-utils
30
+ Version bump for dependency: @pob/root
31
+
32
+
6
33
  ## [22.5.0](https://github.com/christophehurpeau/pob/compare/pob@22.4.1...pob@22.5.0) (2024-08-11)
7
34
 
8
35
  Version bump for dependency: @pob/root
@@ -1,12 +1,9 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
2
  import Generator from "yeoman-generator";
4
- import ensureJsonFileFormatted from "../../../utils/ensureJsonFileFormatted.js";
5
3
  import inMonorepo from "../../../utils/inMonorepo.js";
6
4
  import * as packageUtils from "../../../utils/package.js";
7
- import { writeAndFormatJson } from "../../../utils/writeAndFormat.js";
5
+ import { copyAndFormatTpl } from "../../../utils/writeAndFormat.js";
8
6
  import { appIgnorePaths } from "../../app/ignorePaths.js";
9
- import updateEslintConfig from "./updateEslintConfig.js";
10
7
 
11
8
  export default class CommonLintGenerator extends Generator {
12
9
  constructor(args, opts) {
@@ -59,6 +56,12 @@ export default class CommonLintGenerator extends Generator {
59
56
  description: "Typescript enabled",
60
57
  });
61
58
 
59
+ this.option("build", {
60
+ type: Boolean,
61
+ required: false,
62
+ description: "Build",
63
+ });
64
+
62
65
  this.option("enableSrcResolver", {
63
66
  type: Boolean,
64
67
  required: false,
@@ -132,7 +135,7 @@ export default class CommonLintGenerator extends Generator {
132
135
  this.options.babel !== "undefined"
133
136
  ? this.options.babel === "true"
134
137
  : babelEnvs.length > 0;
135
- const useTypescript = useBabel || pkg.pob?.typescript;
138
+ const useTypescript = this.options.typescript;
136
139
  const hasReact = useTypescript && packageUtils.hasReact(pkg);
137
140
  const useNode = !useBabel || babelEnvs.some((env) => env.target === "node");
138
141
  const useNodeOnly =
@@ -243,7 +246,6 @@ export default class CommonLintGenerator extends Generator {
243
246
  const globalEslint =
244
247
  this.options.monorepo ||
245
248
  (yoConfigPobMonorepo && yoConfigPobMonorepo.eslint !== false);
246
- const globalTesting = yoConfigPobMonorepo && yoConfigPobMonorepo.testing;
247
249
  const composite = yoConfigPobMonorepo && yoConfigPobMonorepo.typescript;
248
250
  const { rootPackageManager, rootYarnNodeLinker } = inMonorepo || {};
249
251
  const lernaProjectType =
@@ -259,7 +261,10 @@ export default class CommonLintGenerator extends Generator {
259
261
  globalEslint &&
260
262
  !((inMonorepo && inMonorepo.root) || this.options.monorepo)
261
263
  ) {
262
- if (!pkg.name.startsWith("@pob/eslint-config")) {
264
+ if (
265
+ !pkg.name.startsWith("@pob/eslint-config") &&
266
+ !pkg.name.startsWith("@pob/eslint-plugin")
267
+ ) {
263
268
  packageUtils.removeDevDependencies(
264
269
  pkg,
265
270
  [
@@ -348,113 +353,71 @@ export default class CommonLintGenerator extends Generator {
348
353
  }
349
354
  }
350
355
 
351
- const isPobEslintConfig =
352
- pkg.name === "eslint-config-pob" ||
353
- pkg.name.startsWith("@pob/eslint-config") ||
354
- pkg.name === "@pob/use-eslint-plugin";
355
-
356
- const extendsConfigRoot = (() => {
357
- if (isPobEslintConfig) {
358
- if (pkg.name === "@pob/eslint-config-monorepo") {
359
- return [
360
- pkg.type === "commonjs"
361
- ? "./@pob/eslint-config/lib/root-commonjs.js"
362
- : "./@pob/eslint-config/lib/root-module.js",
363
- ];
364
- }
365
- return [
366
- pkg.type === "commonjs"
367
- ? "../eslint-config/lib/root-commonjs.js"
368
- : "../eslint-config/lib/root-module.js",
369
- ];
356
+ const { imports, flatCascade } = (() => {
357
+ if (pkg.name === "@pob/eslint-config-monorepo") {
358
+ return {
359
+ imports: [
360
+ 'import pobTypescriptConfig from "@pob/eslint-config-typescript"',
361
+ 'import pobTypescriptConfigReact from "@pob/eslint-config-typescript-react"',
362
+ ],
363
+ flatCascade: [
364
+ // TODO
365
+ ],
366
+ };
370
367
  }
371
368
 
372
- return [
373
- pkg.type === "commonjs"
374
- ? "@pob/eslint-config/root-commonjs"
375
- : "@pob/eslint-config/root-module",
376
- ];
377
- })();
378
-
379
- const extendsConfigSrc = (() => {
380
- if (isPobEslintConfig) {
381
- return [
382
- pkg.type === "commonjs"
383
- ? "../../eslint-config/lib/node-commonjs"
384
- : "../../eslint-config/lib/node-module",
385
- ];
386
- }
369
+ return {
370
+ imports: [
371
+ useTypescript
372
+ ? 'import pobTypescriptConfig from "@pob/eslint-config-typescript"'
373
+ : 'import pobConfig from "@pob/eslint-config"',
374
+ useTypescript &&
375
+ hasReact &&
376
+ 'import pobTypescriptConfigReact from "@pob/eslint-config-typescript-react"',
377
+ ].filter(Boolean),
378
+ flatCascade: (() => {
379
+ // TODO do something with useNodeOnly ?
380
+ console.log({ useNodeOnly });
381
+
382
+ if (!useTypescript) {
383
+ return [
384
+ useNode
385
+ ? "...pobConfig(import.meta.url).configs.nodeModule"
386
+ : "...pobConfig(import.meta.url).configs.baseModule",
387
+ ];
388
+ }
389
+ if (!hasReact) {
390
+ return [
391
+ useNode
392
+ ? "...pobTypescriptConfig(import.meta.url).configs.node"
393
+ : "...pobTypescriptConfig(import.meta.url).configs.base",
394
+ ];
395
+ }
387
396
 
388
- if (useTypescript) {
389
- return [
390
- "@pob/eslint-config-typescript",
391
- useNodeOnly && "@pob/eslint-config-typescript/node",
392
- // useTypescript &&
393
- // pkg.pob?.rollup === false &&
394
- // '@pob/eslint-config-typescript/tsc-emit',
395
- this.options.isApp && "@pob/eslint-config-typescript/app",
396
- hasReact &&
397
- `@pob/eslint-config-typescript-react${
397
+ return [
398
+ useNode
399
+ ? "...pobTypescriptConfig(import.meta.url).configs.node"
400
+ : "...pobTypescriptConfig(import.meta.url).configs.base",
401
+ `...pobTypescriptReactConfig(import.meta.url).configs.${
398
402
  pkg.dependencies?.["react-native-web"] ? "/react-native-web" : ""
399
403
  }`,
400
- ].filter(Boolean);
401
- }
402
-
403
- return [
404
- pkg.type === "commonjs"
405
- ? "@pob/eslint-config/node-commonjs"
406
- : "@pob/eslint-config/node-module",
407
- ];
404
+ this.options.isApp &&
405
+ "...pobTypescriptConfig(import.meta.url).configs.app",
406
+ ];
407
+ })().filter(Boolean),
408
+ };
408
409
  })();
409
410
 
410
- const ext = !useTypescript
411
- ? `{${pkg.type === "commonjs" ? "mjs" : "cjs"},js}`
412
- : `${hasReact ? "{ts,tsx}" : "ts"}`;
413
-
414
- const testRunner = globalTesting
415
- ? inMonorepo.pobConfig.monorepo.testRunner
416
- : this.options.testRunner;
417
- const testsOverride =
418
- this.options.testing || globalTesting
419
- ? {
420
- files: [
421
- `**/*.test.${ext}`,
422
- `__tests__/**/*.${ext}`,
423
- `**/__mocks__/**/*.${ext}`,
424
- ],
425
- ...(testRunner == null || testRunner === "jest"
426
- ? { env: { jest: true } }
427
- : {}),
428
- rules: {
429
- "import/no-extraneous-dependencies": [
430
- "error",
431
- { devDependencies: true },
432
- ],
433
- },
434
- }
435
- : null;
436
-
437
- if (testsOverride) {
438
- // if (!useBabel) {
439
- // testsOverride.extends = ['pob/babel'];
440
- // }
441
-
442
- if (useTypescript) {
443
- testsOverride.extends = ["@pob/eslint-config-typescript/test"];
444
- delete testsOverride.rules["import/no-extraneous-dependencies"];
445
- }
446
- }
447
-
448
411
  const eslintrcBadPath = this.destinationPath(".eslintrc");
449
412
  this.fs.delete(eslintrcBadPath);
450
413
  this.fs.delete(`${eslintrcBadPath}.yml`);
451
414
  this.fs.delete(`${eslintrcBadPath}.js`);
452
415
 
453
- const rootEslintrcPath = this.options.rootAsSrc
416
+ const rootLegacyEslintrcPath = this.options.rootAsSrc
454
417
  ? false
455
418
  : this.destinationPath(".eslintrc.json");
456
419
 
457
- const srcEslintrcPath = this.options.rootAsSrc
420
+ const srcLegacyEslintrcPath = this.options.rootAsSrc
458
421
  ? this.destinationPath(".eslintrc.json")
459
422
  : this.destinationPath(
460
423
  `${
@@ -462,96 +425,69 @@ export default class CommonLintGenerator extends Generator {
462
425
  }.eslintrc.json`,
463
426
  );
464
427
 
465
- const getRootIgnorePatterns = () => {
466
- const ignorePatterns = new Set();
428
+ if (rootLegacyEslintrcPath) this.fs.delete(rootLegacyEslintrcPath);
429
+ this.fs.delete(srcLegacyEslintrcPath);
467
430
 
468
- if (inMonorepo && !inMonorepo.root && (useTypescript || pkg.types)) {
469
- ignorePatterns.add("*.d.ts");
470
- }
431
+ const eslintConfigPath = this.destinationPath("eslint.config.js");
471
432
 
472
- if (inMonorepo && inMonorepo.root && this.options.documentation) {
473
- ignorePatterns.add("/docs");
474
- }
433
+ if (!inMonorepo || inMonorepo.root) {
434
+ const getRootIgnorePatterns = () => {
435
+ const ignorePatterns = new Set();
475
436
 
476
- if ((!inMonorepo || !inMonorepo.root) && useTypescript) {
477
- const buildPath = `/${this.options.buildDirectory}`;
478
- if (
479
- !this.options.rootIgnorePaths ||
480
- !this.options.rootIgnorePaths.includes(buildPath)
481
- ) {
482
- ignorePatterns.add(buildPath);
437
+ if (useTypescript) {
438
+ ignorePatterns.add("*.d.ts");
483
439
  }
484
- }
485
- if (inMonorepo && inMonorepo.root && this.options.typescript) {
486
- ignorePatterns.add("/rollup.config.mjs");
487
- }
488
440
 
489
- if (this.options.rootIgnorePaths) {
490
- this.options.rootIgnorePaths
491
- .split("\n")
492
- .filter(Boolean)
493
- .forEach((ignorePath) => {
494
- if (ignorePath.startsWith("#")) return;
495
- ignorePatterns.add(ignorePath);
496
- });
497
- }
441
+ if (inMonorepo && inMonorepo.root && this.options.documentation) {
442
+ ignorePatterns.add("/docs");
443
+ }
498
444
 
499
- return ignorePatterns;
500
- };
445
+ if ((!inMonorepo || !inMonorepo.root) && useTypescript) {
446
+ const buildPath = `/${this.options.buildDirectory}`;
447
+ if (
448
+ !this.options.rootIgnorePaths ||
449
+ !this.options.rootIgnorePaths.includes(buildPath)
450
+ ) {
451
+ ignorePatterns.add(buildPath);
452
+ }
453
+ }
454
+ if (inMonorepo && inMonorepo.root && this.options.build) {
455
+ ignorePatterns.add("/rollup.config.mjs");
456
+ }
501
457
 
502
- if (rootEslintrcPath) {
503
- try {
504
- if (this.fs.exists(rootEslintrcPath)) {
505
- ensureJsonFileFormatted(rootEslintrcPath);
458
+ if (this.options.rootIgnorePaths) {
459
+ this.options.rootIgnorePaths
460
+ .split("\n")
461
+ .filter(Boolean)
462
+ .forEach((ignorePath) => {
463
+ if (ignorePath.startsWith("#")) return;
464
+ ignorePatterns.add(ignorePath);
465
+ });
506
466
  }
507
467
 
508
- const rootIgnorePatterns = getRootIgnorePatterns();
468
+ return ignorePatterns;
469
+ };
470
+
471
+ const ignorePatterns = getRootIgnorePatterns();
472
+ const srcDirectory =
473
+ useBabel || this.options.typescript ? this.options.srcDirectory : "lib";
509
474
 
510
- const rootEslintrcConfig = updateEslintConfig(
511
- this.fs.readJSON(rootEslintrcPath, {}),
475
+ if (this.fs.exists(eslintConfigPath)) {
476
+ // TODO update config !
477
+ } else {
478
+ copyAndFormatTpl(
479
+ this.fs,
480
+ this.templatePath("eslint.config.js.ejs"),
481
+ eslintConfigPath,
512
482
  {
513
- extendsConfig: extendsConfigRoot,
514
- ignorePatterns:
515
- rootIgnorePatterns.size === 0
516
- ? undefined
517
- : [...rootIgnorePatterns],
483
+ imports,
484
+ flatCascade,
485
+ srcDirectory,
486
+ ignorePatterns: [...ignorePatterns],
518
487
  },
519
488
  );
520
-
521
- writeAndFormatJson(this.fs, rootEslintrcPath, rootEslintrcConfig);
522
- } catch (error) {
523
- console.warn(`Could not parse/edit ${rootEslintrcPath}: `, error);
524
- }
525
- }
526
- // no else: dont delete root eslintrc, src is root
527
-
528
- if ((inMonorepo && inMonorepo.root) || this.options.monorepo) {
529
- if (this.fs.exists(srcEslintrcPath)) {
530
- this.fs.delete(srcEslintrcPath);
531
- }
532
- } else {
533
- try {
534
- if (this.fs.exists(srcEslintrcPath)) {
535
- ensureJsonFileFormatted(srcEslintrcPath);
536
- }
537
-
538
- const ignorePatterns = this.options.rootAsSrc
539
- ? getRootIgnorePatterns()
540
- : new Set();
541
- if (useTypescript || pkg.types) {
542
- ignorePatterns.add("*.d.ts");
543
- }
544
-
545
- const srcEslintrcConfig = updateEslintConfig(
546
- this.fs.readJSON(srcEslintrcPath, {}),
547
- {
548
- extendsConfig: extendsConfigSrc,
549
- testsOverride,
550
- useTypescript,
551
- globalEslint,
552
- ignorePatterns:
553
- ignorePatterns.size === 0 ? undefined : [...ignorePatterns],
554
- settings: {
489
+ // TODO
490
+ /* settings: {
555
491
  "import/resolver": this.options.enableSrcResolver
556
492
  ? {
557
493
  node: {
@@ -563,39 +499,22 @@ export default class CommonLintGenerator extends Generator {
563
499
  }
564
500
  : false,
565
501
  },
566
- relativePath: inMonorepo ? inMonorepo.relative : undefined,
567
- },
568
- );
569
-
570
- writeAndFormatJson(this.fs, srcEslintrcPath, srcEslintrcConfig);
571
- } catch (error) {
572
- console.warn(`Could not parse/edit ${srcEslintrcPath}: `, error);
502
+ */
573
503
  }
504
+ } else {
505
+ this.fs.delete(eslintConfigPath);
574
506
  }
575
507
 
576
508
  // see monorepo/lerna/index.js
577
509
  if (!(inMonorepo && inMonorepo.root) && !this.options.monorepo) {
578
- const srcDirectory =
579
- useBabel || this.options.typescript ? this.options.srcDirectory : "lib";
580
- const lintRootJsFiles = (useBabel && useNode) || !inMonorepo;
581
-
582
- const lintPaths = [srcDirectory, "bin", "scripts", "migrations"].filter(
583
- (dir) => fs.existsSync(this.destinationPath(dir)),
584
- );
585
-
586
- if (lintRootJsFiles) {
587
- lintPaths.unshift("*.{js,cjs,mjs}");
588
- }
589
-
590
- const args =
591
- "--report-unused-disable-directives --resolve-plugins-relative-to . --quiet";
510
+ const args = "--quiet";
592
511
 
593
512
  packageUtils.addScripts(pkg, {
594
513
  "lint:eslint": globalEslint
595
514
  ? `yarn ../.. run eslint ${args} ${path
596
515
  .relative("../..", ".")
597
516
  .replace("\\", "/")}`
598
- : `eslint ${args} ${lintPaths.join(" ")}`,
517
+ : `eslint ${args} .`,
599
518
  lint: `${
600
519
  useTypescript && !composite ? "tsc && " : ""
601
520
  }yarn run lint:eslint`,
@@ -0,0 +1,5 @@
1
+ <%- imports.map(v => `${v};\n`).join('') -%>
2
+
3
+ export default [
4
+ <%- flatCascade.map(v => ` ${v},\n`).join('') -%>
5
+ ];
@@ -50,6 +50,9 @@ export default class CoreNpmGenerator extends Generator {
50
50
 
51
51
  if (pkg.exports) {
52
52
  Object.values(pkg.exports).forEach((value) => {
53
+ if (typeof value === "string" && value.startsWith("./tsconfigs/")) {
54
+ files.add("tsconfigs");
55
+ }
53
56
  if (
54
57
  typeof value === "string" &&
55
58
  value.startsWith("./") &&
@@ -42,11 +42,14 @@
42
42
 
43
43
  // eslint config
44
44
  "eslint.workingDirectories": ["."],
45
- "eslint.options": {
46
- "resolvePluginsRelativeTo": ".",
47
- "reportUnusedDisableDirectives": "error"
48
- },
45
+ "eslint.useFlatConfig": true,
49
46
  "eslint.lintTask.enable": true,
47
+ "eslint.validate": [
48
+ "javascript",
49
+ "javascriptreact",
50
+ "typescript",
51
+ "typescriptreact"
52
+ ],
50
53
 
51
54
  // eslint & prettier formatter
52
55
  "eslint.format.enable": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pob",
3
- "version": "22.5.0",
3
+ "version": "23.0.1",
4
4
  "description": "Pile of bones, library generator with git/babel/typescript/typedoc/readme/jest",
5
5
  "keywords": [
6
6
  "skeleton"
@@ -34,18 +34,19 @@
34
34
  "scripts": {
35
35
  "format": "prettier --write",
36
36
  "lint": "yarn run lint:eslint",
37
- "lint:eslint": "yarn ../.. run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/pob",
38
- "tsc": "tsc -p ./tsconfig.json"
37
+ "lint:eslint": "yarn ../.. run eslint --quiet packages/pob"
38
+ },
39
+ "pob": {
40
+ "typescript": "check-only"
39
41
  },
40
- "pob": {},
41
42
  "prettier": "@pob/root/prettier-config",
42
43
  "dependencies": {
43
- "@pob/eslint-config": "56.1.0",
44
- "@pob/eslint-config-typescript": "56.1.0",
45
- "@pob/eslint-config-typescript-react": "56.1.0",
46
- "@pob/sort-eslint-config": "5.3.1",
47
- "@pob/sort-object": "6.3.1",
48
- "@pob/sort-pkg": "7.3.0",
44
+ "@pob/eslint-config": "57.3.0",
45
+ "@pob/eslint-config-typescript": "57.3.1",
46
+ "@pob/eslint-config-typescript-react": "57.3.1",
47
+ "@pob/sort-eslint-config": "6.0.0",
48
+ "@pob/sort-object": "7.0.0",
49
+ "@pob/sort-pkg": "8.0.0",
49
50
  "@prettier/sync": "0.5.2",
50
51
  "@types/inquirer": "9.0.7",
51
52
  "@yarnpkg/cli": "4.4.0",
@@ -64,16 +65,16 @@
64
65
  "mem-fs-editor": "11.0.1",
65
66
  "minimist": "1.2.8",
66
67
  "parse-author": "2.0.0",
67
- "pob-dependencies": "13.4.1",
68
+ "pob-dependencies": "14.0.1",
68
69
  "prettier": "3.3.3",
69
70
  "semver": "7.6.3",
70
71
  "validate-npm-package-name": "^5.0.0",
71
- "yarn-workspace-utils": "5.2.0",
72
+ "yarn-workspace-utils": "6.0.1",
72
73
  "yeoman-environment": "4.4.1",
73
74
  "yeoman-generator": "7.3.2"
74
75
  },
75
76
  "devDependencies": {
76
- "@pob/root": "12.4.0",
77
+ "@pob/root": "13.0.0",
77
78
  "@types/node": "20.14.15",
78
79
  "typescript": "5.5.4"
79
80
  }
@@ -1,27 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": ["@pob/eslint-config/node-module"],
4
- "rules": {
5
- "max-lines": "off",
6
- "no-multi-assign": "off",
7
- "no-nested-ternary": "off",
8
- "no-console": "off",
9
- "complexity": "off"
10
- },
11
- "overrides": [
12
- {
13
- "files": ["**/*.test.{cjs,js}", "__tests__/**/*.{cjs,js}"],
14
- "env": {
15
- "jest": true
16
- },
17
- "rules": {
18
- "import/no-extraneous-dependencies": [
19
- "error",
20
- {
21
- "devDependencies": true
22
- }
23
- ]
24
- }
25
- }
26
- ]
27
- }