pob 19.1.1 → 20.0.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/lib/generators/app/PobAppGenerator.js +120 -120
  3. package/lib/generators/app/e2e-testing/AppE2ETestingGenerator.js +11 -11
  4. package/lib/generators/app/ignorePaths.js +24 -24
  5. package/lib/generators/app/nextjs/AppNextjsGenerator.js +9 -9
  6. package/lib/generators/app/remix/AppRemixGenerator.js +7 -7
  7. package/lib/generators/common/babel/CommonBabelGenerator.js +146 -146
  8. package/lib/generators/common/format-lint/CommonLintGenerator.js +185 -185
  9. package/lib/generators/common/format-lint/updateEslintConfig.js +14 -15
  10. package/lib/generators/common/husky/CommonHuskyGenerator.js +44 -44
  11. package/lib/generators/common/old-dependencies/CommonRemoveOldDependenciesGenerator.js +44 -44
  12. package/lib/generators/common/release/CommonReleaseGenerator.js +40 -40
  13. package/lib/generators/common/testing/CommonTestingGenerator.js +190 -190
  14. package/lib/generators/common/testing/templates/index.js +3 -3
  15. package/lib/generators/common/transpiler/CommonTranspilerGenerator.js +163 -163
  16. package/lib/generators/common/typescript/CommonTypescriptGenerator.js +79 -79
  17. package/lib/generators/common/typescript/templates/tsconfig.js.json.ejs +12 -0
  18. package/lib/generators/core/ci/CoreCIGenerator.js +72 -72
  19. package/lib/generators/core/clean/CoreCleanGenerator.js +4 -4
  20. package/lib/generators/core/editorconfig/CoreEditorConfigGenerator.js +3 -3
  21. package/lib/generators/core/git/CoreGitGenerator.js +43 -43
  22. package/lib/generators/core/git/generators/github/CoreGitGithubGenerator.js +43 -43
  23. package/lib/generators/core/gitignore/CoreGitignoreGenerator.js +19 -19
  24. package/lib/generators/core/npm/CoreNpmGenerator.js +20 -20
  25. package/lib/generators/core/package/CorePackageGenerator.js +98 -98
  26. package/lib/generators/core/package/askName.js +4 -4
  27. package/lib/generators/core/renovate/CoreRenovateGenerator.js +28 -28
  28. package/lib/generators/core/sort-package/CoreSortPackageGenerator.js +6 -6
  29. package/lib/generators/core/vscode/CoreVSCodeGenerator.js +43 -43
  30. package/lib/generators/core/yarn/CoreYarnGenerator.js +70 -70
  31. package/lib/generators/lib/PobLibGenerator.js +111 -111
  32. package/lib/generators/lib/doc/LibDocGenerator.js +45 -45
  33. package/lib/generators/lib/readme/LibReadmeGenerator.js +21 -21
  34. package/lib/generators/monorepo/PobMonorepoGenerator.js +89 -89
  35. package/lib/generators/monorepo/lerna/MonorepoLernaGenerator.js +47 -47
  36. package/lib/generators/monorepo/typescript/MonorepoTypescriptGenerator.js +38 -38
  37. package/lib/generators/monorepo/workspaces/MonorepoWorkspacesGenerator.js +57 -57
  38. package/lib/generators/pob/PobBaseGenerator.js +81 -81
  39. package/lib/pob-dirname.cjs +1 -1
  40. package/lib/pob.js +143 -143
  41. package/lib/utils/dependenciesPackages.cjs +4 -4
  42. package/lib/utils/ensureJsonFileFormatted.js +5 -5
  43. package/lib/utils/inMonorepo.js +8 -8
  44. package/lib/utils/json5.js +1 -1
  45. package/lib/utils/package.js +43 -43
  46. package/lib/utils/packagejson.cjs +2 -2
  47. package/lib/utils/templateUtils.js +1 -1
  48. package/lib/utils/writeAndFormat.js +9 -10
  49. package/package.json +10 -10
@@ -1,131 +1,131 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import Generator from 'yeoman-generator';
4
- import inMonorepo from '../../../utils/inMonorepo.js';
5
- import * as packageUtils from '../../../utils/package.js';
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import Generator from "yeoman-generator";
4
+ import inMonorepo from "../../../utils/inMonorepo.js";
5
+ import * as packageUtils from "../../../utils/package.js";
6
6
  import {
7
7
  copyAndFormatTpl,
8
8
  writeAndFormatJson,
9
- } from '../../../utils/writeAndFormat.js';
9
+ } from "../../../utils/writeAndFormat.js";
10
10
 
11
11
  export default class CommonTestingGenerator extends Generator {
12
12
  constructor(args, opts) {
13
13
  super(args, opts);
14
14
 
15
- this.option('monorepo', {
15
+ this.option("monorepo", {
16
16
  type: Boolean,
17
17
  default: false,
18
- desc: 'is root monorepo',
18
+ desc: "is root monorepo",
19
19
  });
20
20
 
21
- this.option('enable', {
21
+ this.option("enable", {
22
22
  type: Boolean,
23
23
  default: true,
24
- desc: 'enable testing',
24
+ desc: "enable testing",
25
25
  });
26
26
 
27
- this.option('runner', {
27
+ this.option("runner", {
28
28
  type: String,
29
- default: 'jest',
30
- desc: 'test runner (jest or node)',
29
+ default: "jest",
30
+ desc: "test runner (jest or node)",
31
31
  });
32
32
 
33
- this.option('enableReleasePlease', {
33
+ this.option("enableReleasePlease", {
34
34
  type: Boolean,
35
35
  default: true,
36
- desc: 'enable release-please',
36
+ desc: "enable release-please",
37
37
  });
38
38
 
39
- this.option('enableYarnVersion', {
39
+ this.option("enableYarnVersion", {
40
40
  type: Boolean,
41
41
  default: true,
42
- desc: 'enable yarn version conventional commits',
42
+ desc: "enable yarn version conventional commits",
43
43
  });
44
44
 
45
- this.option('ci', {
45
+ this.option("ci", {
46
46
  type: Boolean,
47
47
  required: true,
48
- desc: 'ci',
48
+ desc: "ci",
49
49
  });
50
50
 
51
- this.option('typescript', {
51
+ this.option("typescript", {
52
52
  type: Boolean,
53
53
  required: true,
54
- desc: 'typescript',
54
+ desc: "typescript",
55
55
  });
56
56
 
57
- this.option('build', {
57
+ this.option("build", {
58
58
  type: Boolean,
59
59
  required: true,
60
- desc: 'build (with babel or typescript)',
60
+ desc: "build (with babel or typescript)",
61
61
  });
62
62
 
63
- this.option('codecov', {
63
+ this.option("codecov", {
64
64
  type: Boolean,
65
65
  required: true,
66
- desc: 'Include codecov report',
66
+ desc: "Include codecov report",
67
67
  });
68
68
 
69
- this.option('documentation', {
69
+ this.option("documentation", {
70
70
  type: Boolean,
71
71
  required: true,
72
- desc: 'Include documentation generation',
72
+ desc: "Include documentation generation",
73
73
  });
74
74
 
75
- this.option('packageManager', {
75
+ this.option("packageManager", {
76
76
  type: String,
77
- default: 'yarn',
78
- desc: 'yarn or npm',
77
+ default: "yarn",
78
+ desc: "yarn or npm",
79
79
  });
80
80
 
81
- this.option('isApp', {
81
+ this.option("isApp", {
82
82
  type: Boolean,
83
83
  required: true,
84
- desc: 'is app',
84
+ desc: "is app",
85
85
  });
86
86
 
87
- this.option('e2eTesting', {
87
+ this.option("e2eTesting", {
88
88
  type: String,
89
- default: '',
90
- desc: 'e2e testing package path',
89
+ default: "",
90
+ desc: "e2e testing package path",
91
91
  });
92
92
 
93
- this.option('splitCIJobs', {
93
+ this.option("splitCIJobs", {
94
94
  type: Boolean,
95
95
  required: true,
96
- desc: 'split CI jobs for faster result',
96
+ desc: "split CI jobs for faster result",
97
97
  });
98
98
 
99
- this.option('onlyLatestLTS', {
99
+ this.option("onlyLatestLTS", {
100
100
  type: Boolean,
101
101
  required: true,
102
- desc: 'only latest lts',
102
+ desc: "only latest lts",
103
103
  });
104
104
 
105
- this.option('srcDirectory', {
105
+ this.option("srcDirectory", {
106
106
  type: String,
107
- default: 'src',
107
+ default: "src",
108
108
  desc: 'customize srcDirectory, default to "src"',
109
109
  });
110
110
 
111
- this.option('disableYarnGitCache', {
111
+ this.option("disableYarnGitCache", {
112
112
  type: Boolean,
113
113
  required: false,
114
114
  default: false,
115
- desc: 'Disable git cache. See https://yarnpkg.com/features/caching#offline-mirror.',
115
+ desc: "Disable git cache. See https://yarnpkg.com/features/caching#offline-mirror.",
116
116
  });
117
117
 
118
- this.option('swc', {
118
+ this.option("swc", {
119
119
  type: Boolean,
120
120
  required: false,
121
121
  default: false,
122
- desc: 'Use swc to transpile code.',
122
+ desc: "Use swc to transpile code.",
123
123
  });
124
124
  }
125
125
 
126
126
  default() {
127
127
  if (!inMonorepo || inMonorepo.root) {
128
- this.composeWith('pob:core:ci', {
128
+ this.composeWith("pob:core:ci", {
129
129
  enable: this.options.ci,
130
130
  enableReleasePlease: this.options.enableReleasePlease,
131
131
  enableYarnVersion: this.options.enableYarnVersion,
@@ -143,23 +143,23 @@ export default class CommonTestingGenerator extends Generator {
143
143
  onlyLatestLTS: this.options.onlyLatestLTS,
144
144
  });
145
145
  } else {
146
- this.composeWith('pob:core:ci', {
146
+ this.composeWith("pob:core:ci", {
147
147
  enable: false,
148
148
  });
149
149
  }
150
150
  }
151
151
 
152
152
  writing() {
153
- const pkg = this.fs.readJSON(this.destinationPath('package.json'));
153
+ const pkg = this.fs.readJSON(this.destinationPath("package.json"));
154
154
 
155
155
  packageUtils.removeDevDependencies(pkg, [
156
- 'coveralls',
157
- 'mocha',
158
- 'istanbul',
159
- 'babel-core',
160
- 'ts-jest',
161
- 'babel-jest',
162
- 'pob-lcov-reporter',
156
+ "coveralls",
157
+ "mocha",
158
+ "istanbul",
159
+ "babel-core",
160
+ "ts-jest",
161
+ "babel-jest",
162
+ "pob-lcov-reporter",
163
163
  ]);
164
164
 
165
165
  const yoConfigPobMonorepo =
@@ -180,23 +180,23 @@ export default class CommonTestingGenerator extends Generator {
180
180
  ? yoConfigPobMonorepo.react ?? packageUtils.hasReact(pkg)
181
181
  : packageUtils.hasReact(pkg));
182
182
  const testRunner = globalTesting
183
- ? inMonorepo.pobConfig.monorepo.testRunner || 'jest'
183
+ ? inMonorepo.pobConfig.monorepo.testRunner || "jest"
184
184
  : this.options.runner;
185
185
 
186
- const isJestRunner = testRunner === 'jest';
186
+ const isJestRunner = testRunner === "jest";
187
187
 
188
188
  const tsTestUtil = (() => {
189
- if (testRunner === 'vitest') return undefined;
190
- if (this.options.swc || isJestRunner) return 'swc';
191
- return 'ts-node';
189
+ if (testRunner === "vitest") return undefined;
190
+ if (this.options.swc || isJestRunner) return "swc";
191
+ return "ts-node";
192
192
  })();
193
193
 
194
194
  const dependenciesForTestUtil = {
195
- 'ts-node': { devDependenciesShared: ['ts-node'] },
195
+ "ts-node": { devDependenciesShared: ["ts-node"] },
196
196
  swc: {
197
- devDependenciesShared: ['@swc/core'],
198
- devDependenciesWithJest: ['@swc/jest'],
199
- devDependenciesWithNode: ['@swc-node/register'],
197
+ devDependenciesShared: ["@swc/core"],
198
+ devDependenciesWithJest: ["@swc/jest"],
199
+ devDependenciesWithNode: ["@swc-node/register"],
200
200
  },
201
201
  };
202
202
 
@@ -217,8 +217,8 @@ export default class CommonTestingGenerator extends Generator {
217
217
  packageUtils.addOrRemoveDevDependencies(
218
218
  pkg,
219
219
  sharedCondition &&
220
- (testRunner === 'node' || (withTypescript && !transpileWithBabel)),
221
- devDependenciesShared,
220
+ (testRunner === "node" || (withTypescript && !transpileWithBabel)),
221
+ devDependenciesShared
222
222
  );
223
223
  if (devDependenciesWithJest) {
224
224
  packageUtils.addOrRemoveDevDependencies(
@@ -226,8 +226,8 @@ export default class CommonTestingGenerator extends Generator {
226
226
  sharedCondition &&
227
227
  withTypescript &&
228
228
  !transpileWithBabel &&
229
- testRunner === 'jest',
230
- devDependenciesWithJest,
229
+ testRunner === "jest",
230
+ devDependenciesWithJest
231
231
  );
232
232
  }
233
233
  if (devDependenciesWithNode) {
@@ -236,11 +236,11 @@ export default class CommonTestingGenerator extends Generator {
236
236
  sharedCondition &&
237
237
  withTypescript &&
238
238
  !transpileWithBabel &&
239
- testRunner === 'node',
240
- devDependenciesWithNode,
239
+ testRunner === "node",
240
+ devDependenciesWithNode
241
241
  );
242
242
  }
243
- },
243
+ }
244
244
  );
245
245
 
246
246
  if (
@@ -248,28 +248,28 @@ export default class CommonTestingGenerator extends Generator {
248
248
  !isJestRunner ||
249
249
  (globalTesting && !enableForMonorepo)
250
250
  ) {
251
- packageUtils.removeDevDependencies(pkg, ['jest', '@types/jest']);
251
+ packageUtils.removeDevDependencies(pkg, ["jest", "@types/jest"]);
252
252
 
253
253
  delete pkg.jest;
254
- this.fs.delete(this.destinationPath('jest.config.js'));
255
- this.fs.delete(this.destinationPath('jest.config.mjs'));
256
- this.fs.delete(this.destinationPath('jest.config.cjs'));
257
- this.fs.delete(this.destinationPath('jest.config.json'));
254
+ this.fs.delete(this.destinationPath("jest.config.js"));
255
+ this.fs.delete(this.destinationPath("jest.config.mjs"));
256
+ this.fs.delete(this.destinationPath("jest.config.cjs"));
257
+ this.fs.delete(this.destinationPath("jest.config.json"));
258
258
  }
259
259
 
260
260
  const tsTestLoaderOption = (() => {
261
261
  switch (tsTestUtil) {
262
- case 'ts-node':
263
- return '--loader=ts-node/esm --experimental-specifier-resolution=node';
264
- case 'swc':
265
- return '--import=@swc-node/register/esm';
262
+ case "ts-node":
263
+ return "--loader=ts-node/esm --experimental-specifier-resolution=node";
264
+ case "swc":
265
+ return "--import=@swc-node/register/esm";
266
266
 
267
267
  // no default
268
268
  }
269
269
  })();
270
270
 
271
271
  const hasTestFolder =
272
- !this.options.monorepo && fs.existsSync(this.destinationPath('test'));
272
+ !this.options.monorepo && fs.existsSync(this.destinationPath("test"));
273
273
 
274
274
  const createTestCommand = ({
275
275
  coverage,
@@ -281,54 +281,54 @@ export default class CommonTestingGenerator extends Generator {
281
281
  hasReact,
282
282
  }) => {
283
283
  switch (testRunner) {
284
- case 'jest': {
284
+ case "jest": {
285
285
  return `${
286
286
  shouldUseExperimentalVmModules
287
- ? 'NODE_OPTIONS=--experimental-vm-modules '
288
- : ''
289
- }jest${watch ? ' --watch' : ''}${
287
+ ? "NODE_OPTIONS=--experimental-vm-modules "
288
+ : ""
289
+ }jest${watch ? " --watch" : ""}${
290
290
  coverage || coverageJson || coverageLcov
291
291
  ? ` --coverage ${
292
292
  coverageLcov
293
- ? '--coverageReporters=lcov'
293
+ ? "--coverageReporters=lcov"
294
294
  : `--coverageReporters=json${
295
- coverageJson ? '' : ' --coverageReporters=text'
295
+ coverageJson ? "" : " --coverageReporters=text"
296
296
  }`
297
297
  }`
298
- : ''
298
+ : ""
299
299
  }`;
300
300
  }
301
- case 'node': {
301
+ case "node": {
302
302
  if (!workspacesPattern && this.options.monorepo) {
303
- throw new Error('Invalid workspacesPattern');
303
+ throw new Error("Invalid workspacesPattern");
304
304
  }
305
305
  return `${
306
- tsTestUtil === 'ts-node'
307
- ? 'TS_NODE_PROJECT=tsconfig.test.json '
308
- : ''
306
+ tsTestUtil === "ts-node"
307
+ ? "TS_NODE_PROJECT=tsconfig.test.json "
308
+ : ""
309
309
  }${
310
310
  coverage || coverageJson || coverageLcov
311
311
  ? `npx c8${
312
312
  coverageLcov || coverageJson
313
- ? ` --reporter=${coverageJson ? 'json' : 'lcov'}`
314
- : ''
313
+ ? ` --reporter=${coverageJson ? "json" : "lcov"}`
314
+ : ""
315
315
  } --src ./${this.options.srcDirectory} `
316
- : ''
316
+ : ""
317
317
  }node ${
318
- this.options.typescript ? `${tsTestLoaderOption} ` : ''
319
- }--test ${this.options.monorepo ? `${workspacesPattern}/` : ''}${`${
320
- hasTestFolder ? 'test/*' : `${this.options.srcDirectory}/**/*.test`
321
- }.${this.options.typescript ? 'ts' : 'js'}`}`;
318
+ this.options.typescript ? `${tsTestLoaderOption} ` : ""
319
+ }--test ${this.options.monorepo ? `${workspacesPattern}/` : ""}${`${
320
+ hasTestFolder ? "test/*" : `${this.options.srcDirectory}/**/*.test`
321
+ }.${this.options.typescript ? "ts" : "js"}`}`;
322
322
  }
323
- case 'vitest': {
323
+ case "vitest": {
324
324
  return `${
325
325
  coverage || coverageJson || coverageLcov
326
326
  ? `POB_VITEST_COVERAGE=${
327
- coverageLcov ? 'lcov' : `json${coverageJson ? '' : ',text'} `
327
+ coverageLcov ? "lcov" : `json${coverageJson ? "" : ",text"} `
328
328
  }`
329
- : ''
330
- }vitest${watch ? ' --watch' : ''}${
331
- coverage || coverageJson || coverageLcov ? ' run --coverage' : ''
329
+ : ""
330
+ }vitest${watch ? " --watch" : ""}${
331
+ coverage || coverageJson || coverageLcov ? " run --coverage" : ""
332
332
  }`;
333
333
  }
334
334
  default: {
@@ -337,13 +337,13 @@ export default class CommonTestingGenerator extends Generator {
337
337
  }
338
338
  };
339
339
 
340
- const jestConfigPath = this.destinationPath('jest.config.json');
340
+ const jestConfigPath = this.destinationPath("jest.config.json");
341
341
  packageUtils.addOrRemoveDevDependencies(
342
342
  pkg,
343
343
  this.options.enable &&
344
344
  (enableForMonorepo || !globalTesting) &&
345
- testRunner === 'jest',
346
- ['jest', '@types/jest'],
345
+ testRunner === "jest",
346
+ ["jest", "@types/jest"]
347
347
  );
348
348
 
349
349
  if (!this.options.enable) {
@@ -354,21 +354,21 @@ export default class CommonTestingGenerator extends Generator {
354
354
  // delete pkg.scripts['generate:test-coverage'];
355
355
  // }
356
356
  packageUtils.removeScripts([
357
- 'test',
358
- 'test:coverage',
359
- 'generate:test-coverage',
360
- 'test:watch',
361
- 'test:coverage',
362
- 'test:coverage:json',
363
- 'test:coverage:lcov',
357
+ "test",
358
+ "test:coverage",
359
+ "generate:test-coverage",
360
+ "test:watch",
361
+ "test:coverage",
362
+ "test:coverage:json",
363
+ "test:coverage:lcov",
364
364
  ]);
365
365
 
366
- writeAndFormatJson(this.fs, this.destinationPath('package.json'), pkg);
366
+ writeAndFormatJson(this.fs, this.destinationPath("package.json"), pkg);
367
367
  } else {
368
368
  let workspacesPattern;
369
369
  if (this.options.monorepo) {
370
370
  const workspacesWithoutStar = pkg.workspaces.map((workspace) => {
371
- if (!workspace.endsWith('/*')) {
371
+ if (!workspace.endsWith("/*")) {
372
372
  throw new Error(`Invalid workspace format: ${workspace}`);
373
373
  }
374
374
  return workspace.slice(0, -2);
@@ -376,37 +376,37 @@ export default class CommonTestingGenerator extends Generator {
376
376
  workspacesPattern =
377
377
  workspacesWithoutStar.length === 1
378
378
  ? workspacesWithoutStar[0]
379
- : `@(${workspacesWithoutStar.join('|')})`;
379
+ : `@(${workspacesWithoutStar.join("|")})`;
380
380
  }
381
381
 
382
382
  if (this.options.monorepo && !globalTesting) {
383
383
  packageUtils.addScripts(pkg, {
384
- test: 'yarn workspaces foreach --parallel -Av run test',
384
+ test: "yarn workspaces foreach --parallel -Av run test",
385
385
  });
386
386
  } else if (this.options.monorepo) {
387
- const shouldUseExperimentalVmModules = pkg.type === 'module';
387
+ const shouldUseExperimentalVmModules = pkg.type === "module";
388
388
 
389
389
  packageUtils.addScripts(pkg, {
390
390
  test: createTestCommand({
391
391
  workspacesPattern,
392
392
  shouldUseExperimentalVmModules,
393
393
  }),
394
- 'test:watch': createTestCommand({
394
+ "test:watch": createTestCommand({
395
395
  workspacesPattern,
396
396
  shouldUseExperimentalVmModules,
397
397
  watch: true,
398
398
  }),
399
- 'test:coverage': createTestCommand({
399
+ "test:coverage": createTestCommand({
400
400
  workspacesPattern,
401
401
  shouldUseExperimentalVmModules,
402
402
  coverage: true,
403
403
  }),
404
- 'test:coverage:lcov': createTestCommand({
404
+ "test:coverage:lcov": createTestCommand({
405
405
  workspacesPattern,
406
406
  shouldUseExperimentalVmModules,
407
407
  coverageLcov: true,
408
408
  }),
409
- 'test:coverage:json': createTestCommand({
409
+ "test:coverage:json": createTestCommand({
410
410
  workspacesPattern,
411
411
  shouldUseExperimentalVmModules,
412
412
  coverageJson: true,
@@ -415,7 +415,7 @@ export default class CommonTestingGenerator extends Generator {
415
415
 
416
416
  if (isJestRunner) {
417
417
  hasReact = yoConfigPobMonorepo.packageNames.some((pkgName) =>
418
- pkgName.startsWith('react-'),
418
+ pkgName.startsWith("react-")
419
419
  );
420
420
 
421
421
  const jestConfig = this.fs.readJSON(jestConfigPath, pkg.jest ?? {});
@@ -423,38 +423,38 @@ export default class CommonTestingGenerator extends Generator {
423
423
 
424
424
  const srcDirectory = this.options.srcDirectory;
425
425
  Object.assign(jestConfig, {
426
- cacheDirectory: './node_modules/.cache/jest',
427
- testEnvironment: 'node',
426
+ cacheDirectory: "./node_modules/.cache/jest",
427
+ testEnvironment: "node",
428
428
  testMatch: [
429
429
  `<rootDir>/${workspacesPattern}/*/@(${srcDirectory}|lib)/**/__tests__/**/*.${
430
- transpileWithBabel ? '(ts|js|cjs|mjs)' : '(js|cjs|mjs)'
431
- }${hasReact ? '?(x)' : ''}`,
430
+ transpileWithBabel ? "(ts|js|cjs|mjs)" : "(js|cjs|mjs)"
431
+ }${hasReact ? "?(x)" : ""}`,
432
432
  `<rootDir>/${workspacesPattern}/*/@(${srcDirectory}|lib)/**/*.test.${
433
- transpileWithBabel ? '(ts|js|cjs|mjs)' : '(js|cjs|mjs)'
434
- }${hasReact ? '?(x)' : ''}`,
433
+ transpileWithBabel ? "(ts|js|cjs|mjs)" : "(js|cjs|mjs)"
434
+ }${hasReact ? "?(x)" : ""}`,
435
435
  ],
436
436
  });
437
437
 
438
438
  if (shouldUseExperimentalVmModules) {
439
439
  jestConfig.extensionsToTreatAsEsm = [
440
- transpileWithBabel && '.ts',
441
- transpileWithBabel && hasReact && '.tsx',
440
+ transpileWithBabel && ".ts",
441
+ transpileWithBabel && hasReact && ".tsx",
442
442
  ].filter(Boolean);
443
443
  } else {
444
444
  delete jestConfig.extensionsToTreatAsEsm;
445
445
  }
446
446
 
447
- if (tsTestUtil === 'swc' && !transpileWithBabel && withTypescript) {
447
+ if (tsTestUtil === "swc" && !transpileWithBabel && withTypescript) {
448
448
  jestConfig.transform = {
449
- [hasReact ? '^.+\\.tsx?$' : '^.+\\.ts$']: ['@swc/jest'],
449
+ [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: ["@swc/jest"],
450
450
  };
451
451
  } else if (jestConfig.transform) {
452
452
  jestConfig.transform = Object.fromEntries(
453
453
  Object.entries(jestConfig.transform).filter(
454
454
  ([key, value]) =>
455
- value !== '@swc/jest' &&
456
- !(Array.isArray(value) && value[0] === '@swc/jest'),
457
- ),
455
+ value !== "@swc/jest" &&
456
+ !(Array.isArray(value) && value[0] === "@swc/jest")
457
+ )
458
458
  );
459
459
  if (Object.keys(jestConfig.transform).length === 0) {
460
460
  delete jestConfig.transform;
@@ -464,16 +464,16 @@ export default class CommonTestingGenerator extends Generator {
464
464
  writeAndFormatJson(this.fs, jestConfigPath, jestConfig);
465
465
  }
466
466
  } else {
467
- const tsconfigTestPath = this.destinationPath('tsconfig.test.json');
468
- if (testRunner === 'node' && withTypescript) {
469
- const nodeVersion = this.options.onlyLatestLTS ? '20' : '18';
467
+ const tsconfigTestPath = this.destinationPath("tsconfig.test.json");
468
+ if (testRunner === "node" && withTypescript) {
469
+ const nodeVersion = this.options.onlyLatestLTS ? "20" : "18";
470
470
  copyAndFormatTpl(
471
471
  this.fs,
472
- this.templatePath('tsconfig.test.json.ejs'),
472
+ this.templatePath("tsconfig.test.json.ejs"),
473
473
  tsconfigTestPath,
474
474
  {
475
475
  nodeVersion,
476
- },
476
+ }
477
477
  );
478
478
  } else {
479
479
  this.fs.delete(tsconfigTestPath);
@@ -481,14 +481,14 @@ export default class CommonTestingGenerator extends Generator {
481
481
 
482
482
  if (globalTesting) {
483
483
  if (pkg.scripts) {
484
- delete pkg.scripts['generate:test-coverage'];
485
- delete pkg.scripts['test:watch'];
486
- delete pkg.scripts['test:coverage'];
484
+ delete pkg.scripts["generate:test-coverage"];
485
+ delete pkg.scripts["test:watch"];
486
+ delete pkg.scripts["test:coverage"];
487
487
  }
488
488
  packageUtils.addScripts(pkg, {
489
489
  test: `yarn ../../ run test -- ${path
490
- .relative('../..', '.')
491
- .replace('\\', '/')}`,
490
+ .relative("../..", ".")
491
+ .replace("\\", "/")}`,
492
492
  });
493
493
  } else {
494
494
  const babelEnvs = pkg.pob?.babelEnvs || [];
@@ -496,57 +496,57 @@ export default class CommonTestingGenerator extends Generator {
496
496
  const withTypescript = babelEnvs.length > 0 || pkg.pob?.typescript;
497
497
 
498
498
  const shouldUseExperimentalVmModules =
499
- pkg.type === 'module' && !inMonorepo;
499
+ pkg.type === "module" && !inMonorepo;
500
500
 
501
501
  packageUtils.addScripts(pkg, {
502
502
  test: createTestCommand({ shouldUseExperimentalVmModules }),
503
- 'test:watch': createTestCommand({
503
+ "test:watch": createTestCommand({
504
504
  shouldUseExperimentalVmModules,
505
505
  watch: true,
506
506
  }),
507
- 'test:coverage': createTestCommand({
507
+ "test:coverage": createTestCommand({
508
508
  shouldUseExperimentalVmModules,
509
509
  coverage: true,
510
510
  }),
511
- 'test:coverage:lcov': createTestCommand({
511
+ "test:coverage:lcov": createTestCommand({
512
512
  shouldUseExperimentalVmModules,
513
513
  coverageLcov: true,
514
514
  }),
515
- 'test:coverage:json': createTestCommand({
515
+ "test:coverage:json": createTestCommand({
516
516
  shouldUseExperimentalVmModules,
517
517
  coverageJson: true,
518
518
  }),
519
519
  });
520
520
 
521
- if (testRunner === 'jest') {
521
+ if (testRunner === "jest") {
522
522
  const srcDirectory =
523
523
  transpileWithBabel || withTypescript
524
524
  ? this.options.srcDirectory
525
- : 'lib';
525
+ : "lib";
526
526
 
527
527
  const jestConfig = this.fs.readJSON(jestConfigPath, pkg.jest ?? {});
528
528
  delete pkg.jest;
529
529
  Object.assign(jestConfig, {
530
- cacheDirectory: './node_modules/.cache/jest',
530
+ cacheDirectory: "./node_modules/.cache/jest",
531
531
  testMatch: [
532
532
  `<rootDir>/${srcDirectory}/**/__tests__/**/*.${
533
- withTypescript ? 'ts' : '?(m)js'
534
- }${hasReact ? '?(x)' : ''}`,
533
+ withTypescript ? "ts" : "?(m)js"
534
+ }${hasReact ? "?(x)" : ""}`,
535
535
  `<rootDir>/${srcDirectory}/**/*.test.${
536
- withTypescript ? 'ts' : '?(m)js'
537
- }${hasReact ? '?(x)' : ''}`,
536
+ withTypescript ? "ts" : "?(m)js"
537
+ }${hasReact ? "?(x)" : ""}`,
538
538
  ],
539
539
  collectCoverageFrom: [
540
- `${srcDirectory}/**/*.${withTypescript ? 'ts' : '?(m)js'}${
541
- hasReact ? '?(x)' : ''
540
+ `${srcDirectory}/**/*.${withTypescript ? "ts" : "?(m)js"}${
541
+ hasReact ? "?(x)" : ""
542
542
  }`,
543
543
  ],
544
544
  moduleFileExtensions: [
545
- withTypescript && 'ts',
546
- withTypescript && hasReact && 'tsx',
547
- 'js',
545
+ withTypescript && "ts",
546
+ withTypescript && hasReact && "tsx",
547
+ "js",
548
548
  // 'jsx',
549
- 'json',
549
+ "json",
550
550
  ].filter(Boolean),
551
551
  // transform: {
552
552
  // [`^.+\\.ts${hasReact ? 'x?' : ''}$`]: 'babel-jest',
@@ -554,10 +554,10 @@ export default class CommonTestingGenerator extends Generator {
554
554
  });
555
555
  if (transpileWithEsbuild) {
556
556
  jestConfig.transform = {
557
- [hasReact ? '^.+\\.tsx?$' : '^.+\\.ts$']: [
558
- 'jest-esbuild',
557
+ [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: [
558
+ "jest-esbuild",
559
559
  {
560
- format: shouldUseExperimentalVmModules ? 'esm' : 'cjs',
560
+ format: shouldUseExperimentalVmModules ? "esm" : "cjs",
561
561
  },
562
562
  ],
563
563
  };
@@ -565,20 +565,20 @@ export default class CommonTestingGenerator extends Generator {
565
565
  delete jestConfig.transform;
566
566
  } else {
567
567
  if (
568
- tsTestUtil === 'swc' &&
568
+ tsTestUtil === "swc" &&
569
569
  !transpileWithBabel &&
570
570
  withTypescript
571
571
  ) {
572
572
  jestConfig.transform = {
573
- [hasReact ? '^.+\\.tsx?$' : '^.+\\.ts$']: ['@swc/jest'],
573
+ [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: ["@swc/jest"],
574
574
  };
575
575
  } else if (jestConfig.transform) {
576
576
  jestConfig.transform = Object.fromEntries(
577
577
  Object.entries(jestConfig.transform).filter(
578
578
  ([key, value]) =>
579
- value !== '@swc/jest' &&
580
- !(Array.isArray(value) && value[0] === '@swc/jest'),
581
- ),
579
+ value !== "@swc/jest" &&
580
+ !(Array.isArray(value) && value[0] === "@swc/jest")
581
+ )
582
582
  );
583
583
  if (Object.keys(jestConfig.transform).length === 0) {
584
584
  delete jestConfig.transform;
@@ -592,9 +592,9 @@ export default class CommonTestingGenerator extends Generator {
592
592
  !(
593
593
  value &&
594
594
  Array.isArray(value) &&
595
- value[0] === 'jest-esbuild'
596
- ),
597
- ),
595
+ value[0] === "jest-esbuild"
596
+ )
597
+ )
598
598
  );
599
599
  if (Object.keys(jestConfig.transform).length === 0) {
600
600
  delete jestConfig.transform;
@@ -604,8 +604,8 @@ export default class CommonTestingGenerator extends Generator {
604
604
 
605
605
  if (shouldUseExperimentalVmModules) {
606
606
  jestConfig.extensionsToTreatAsEsm = [
607
- withTypescript && '.ts',
608
- withTypescript && hasReact && '.tsx',
607
+ withTypescript && ".ts",
608
+ withTypescript && hasReact && ".tsx",
609
609
  ].filter(Boolean);
610
610
  } else {
611
611
  delete jestConfig.extensionsToTreatAsEsm;
@@ -613,7 +613,7 @@ export default class CommonTestingGenerator extends Generator {
613
613
 
614
614
  if (
615
615
  babelEnvs.length === 0 ||
616
- babelEnvs.some((env) => env.target === 'node')
616
+ babelEnvs.some((env) => env.target === "node")
617
617
  ) {
618
618
  // jestConfig.testEnvironment = 'node'; this is the default now
619
619
  delete jestConfig.testEnvironment;
@@ -630,13 +630,13 @@ export default class CommonTestingGenerator extends Generator {
630
630
  if (
631
631
  transpileWithBabel &&
632
632
  ((this.options.monorepo && globalTesting) || !globalTesting) &&
633
- testRunner === 'jest'
633
+ testRunner === "jest"
634
634
  ) {
635
635
  // cjs for jest compat
636
636
  copyAndFormatTpl(
637
637
  this.fs,
638
- this.templatePath('babel.config.cjs.ejs'),
639
- this.destinationPath('babel.config.cjs'),
638
+ this.templatePath("babel.config.cjs.ejs"),
639
+ this.destinationPath("babel.config.cjs"),
640
640
  {
641
641
  only: !this.options.monorepo
642
642
  ? `'${this.options.srcDirectory}'`
@@ -645,19 +645,19 @@ export default class CommonTestingGenerator extends Generator {
645
645
  `'${workspace}/${this.options.srcDirectory}'`,
646
646
  `'${workspace}/lib'`,
647
647
  ])
648
- .join(', '),
648
+ .join(", "),
649
649
  hasReact,
650
650
  hasLinaria:
651
- !!pkg.devDependencies?.['@linaria/babel-preset'] ||
652
- !!pkg.devDependencies?.['alp-dev'],
651
+ !!pkg.devDependencies?.["@linaria/babel-preset"] ||
652
+ !!pkg.devDependencies?.["alp-dev"],
653
653
  testing: this.options.testing,
654
- jestExperimentalESM: pkg.type === 'module',
655
- },
654
+ jestExperimentalESM: pkg.type === "module",
655
+ }
656
656
  );
657
657
  } else {
658
- this.fs.delete('babel.config.cjs');
658
+ this.fs.delete("babel.config.cjs");
659
659
  }
660
660
 
661
- writeAndFormatJson(this.fs, this.destinationPath('package.json'), pkg);
661
+ writeAndFormatJson(this.fs, this.destinationPath("package.json"), pkg);
662
662
  }
663
663
  }