pob 18.3.0 → 18.4.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 (24) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/lib/generators/app/PobAppGenerator.js +9 -4
  3. package/lib/generators/app/ignorePaths.js +2 -1
  4. package/lib/generators/common/babel/CommonBabelGenerator.js +0 -8
  5. package/lib/generators/common/format-lint/CommonLintGenerator.js +10 -7
  6. package/lib/generators/common/format-lint/templates/prettierignore.ejs +1 -1
  7. package/lib/generators/common/format-lint/updateEslintConfig.js +1 -1
  8. package/lib/generators/common/testing/CommonTestingGenerator.js +133 -27
  9. package/lib/generators/common/transpiler/CommonTranspilerGenerator.js +87 -27
  10. package/lib/generators/common/transpiler/templates/app.rollup.config.mjs.ejs +2 -2
  11. package/lib/generators/common/transpiler/templates/lib.rollup.config.mjs.ejs +1 -1
  12. package/lib/generators/common/typescript/CommonTypescriptGenerator.js +7 -3
  13. package/lib/generators/core/ci/templates/github-action-documentation-workflow.yml.ejs +1 -1
  14. package/lib/generators/core/gitignore/templates/gitignore.ejs +0 -4
  15. package/lib/generators/core/package/CorePackageGenerator.js +10 -0
  16. package/lib/generators/core/vscode/CoreVSCodeGenerator.js +7 -0
  17. package/lib/generators/core/vscode/templates/settings.json.ejs +1 -1
  18. package/lib/generators/lib/PobLibGenerator.js +1 -0
  19. package/lib/generators/monorepo/PobMonorepoGenerator.js +1 -0
  20. package/lib/generators/monorepo/workspaces/MonorepoWorkspacesGenerator.js +2 -0
  21. package/lib/generators/pob/PobBaseGenerator.js +10 -1
  22. package/lib/pob.js +2 -0
  23. package/lib/utils/package.js +2 -2
  24. package/package.json +15 -15
package/CHANGELOG.md CHANGED
@@ -3,6 +3,46 @@
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
+ ## [18.4.0](https://github.com/christophehurpeau/pob/compare/pob@18.3.0...pob@18.4.0) (2024-04-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * add app untranspiled-library ([c702f3e](https://github.com/christophehurpeau/pob/commit/c702f3e8170809b8c7b9ac5fe6cad4f6f7e70779))
12
+ * add rollup-esbuild ([a1085db](https://github.com/christophehurpeau/pob/commit/a1085dbe6ea69767596dd46813044b96fbf713dd))
13
+ * add swc support and improve jest without babel ([e7b050d](https://github.com/christophehurpeau/pob/commit/e7b050d3b7ac5ab2ec68d98095bb9832fdbc88bb))
14
+ * add vitest support ([db3344c](https://github.com/christophehurpeau/pob/commit/db3344c45197f4b1bdfaa78df7dff25b37d291e2))
15
+ * better support next and add example ([a60ce83](https://github.com/christophehurpeau/pob/commit/a60ce83d8277efb0eef65c5b3372ff89570919fb))
16
+ * **deps:** update @pob/eslint-config to v55 (major) ([#2020](https://github.com/christophehurpeau/pob/issues/2020)) ([434d5b3](https://github.com/christophehurpeau/pob/commit/434d5b3dce53b1925091138444881a13e2a962d9))
17
+ * **deps:** update @pob/eslint-config to v55.2.1 ([#2021](https://github.com/christophehurpeau/pob/issues/2021)) ([cdfe421](https://github.com/christophehurpeau/pob/commit/cdfe42126842ac1cb46d233ca7203fd241863a81))
18
+ * **deps:** update dependency @yeoman/types to v1.2.0 ([#1962](https://github.com/christophehurpeau/pob/issues/1962)) ([3566bfd](https://github.com/christophehurpeau/pob/commit/3566bfdbc71ee07662d4b10ec76887c5407118e7))
19
+ * **deps:** update dependency eslint to v8.57.0 ([#1942](https://github.com/christophehurpeau/pob/issues/1942)) ([69753af](https://github.com/christophehurpeau/pob/commit/69753aff1bea9e5801bd4deaa22d6d4eefba8e62))
20
+ * **deps:** update dependency mem-fs to v4.1.0 ([#1945](https://github.com/christophehurpeau/pob/issues/1945)) ([c5c31cf](https://github.com/christophehurpeau/pob/commit/c5c31cfdf15018fbdfa9a4511d86fd6a9d72f277))
21
+ * **deps:** update dependency yeoman-environment to v4.4.0 ([#1963](https://github.com/christophehurpeau/pob/issues/1963)) ([1a7dbb8](https://github.com/christophehurpeau/pob/commit/1a7dbb8fde589f3ad9e6e870cc767b9821832170))
22
+ * **pob:** add tslib ([fb4ead7](https://github.com/christophehurpeau/pob/commit/fb4ead72f5ae31ae894b4f7e9f65fdc05c5e6be0))
23
+ * simple esbuild bundler ([80659fa](https://github.com/christophehurpeau/pob/commit/80659fadb42190463585ff54e865af09e31fdc0d))
24
+ * update peaceiris/actions-gh-pages to v4 ([a67c672](https://github.com/christophehurpeau/pob/commit/a67c672c539c2662650e7b1c00bbc95a4c53fca3))
25
+
26
+
27
+ ### Bug Fixes
28
+
29
+ * **deps:** update @pob/eslint-config to v54.0.1 ([#1943](https://github.com/christophehurpeau/pob/issues/1943)) ([309437f](https://github.com/christophehurpeau/pob/commit/309437f195bfdfc9a6c00eec039fd74cba0a6ef8))
30
+ * **deps:** update @pob/eslint-config to v54.0.2 ([#2000](https://github.com/christophehurpeau/pob/issues/2000)) ([04366c3](https://github.com/christophehurpeau/pob/commit/04366c3fe1917595a4b52369837ba31868e84164))
31
+ * **deps:** update yarn monorepo to v4.1.1 ([#1955](https://github.com/christophehurpeau/pob/issues/1955)) ([872ccc1](https://github.com/christophehurpeau/pob/commit/872ccc1c51462a42edbce7b50c6d44dbf625647b))
32
+ * few fixes for monorepo migrate ([a36ab40](https://github.com/christophehurpeau/pob/commit/a36ab408456ced31d8512a1b30391273dffcbe73))
33
+ * fix previous commit ([cd870dc](https://github.com/christophehurpeau/pob/commit/cd870dccce1e4d80ed38e854915407084e8b0001))
34
+ * missing dependency alp-rollup-plugin-config ([9cdc4e4](https://github.com/christophehurpeau/pob/commit/9cdc4e40fb7fa9ee2140618da5eef978de0f5f31))
35
+ * **pob:** fix lint src directory with typescript and no babel ([b7d32a4](https://github.com/christophehurpeau/pob/commit/b7d32a4753ecf20742c8c4158f50f96e5d225e6d))
36
+ * properly determine node only with typescript and no babel ([3a8d958](https://github.com/christophehurpeau/pob/commit/3a8d9584ecb9c6810e577891f4c040b338364c10))
37
+ * tslib prefix ([b86d5e4](https://github.com/christophehurpeau/pob/commit/b86d5e47912fb16d0f58157d228772af43f00e80))
38
+
39
+ Version bump for dependency: sort-eslint-config
40
+ Version bump for dependency: sort-object
41
+ Version bump for dependency: sort-pkg
42
+ Version bump for dependency: yarn-workspace-utils
43
+ Version bump for dependency: root
44
+
45
+
6
46
  ## [18.3.0](https://github.com/christophehurpeau/pob/compare/pob@18.2.0...pob@18.3.0) (2024-02-17)
7
47
 
8
48
 
@@ -88,6 +88,7 @@ export default class PobAppGenerator extends Generator {
88
88
  'remix',
89
89
  'node',
90
90
  'node-library', // monorepo library for app. Not a real library
91
+ 'untranspiled-library', // monorepo library for app. Not a real library
91
92
  'alp-node',
92
93
  'expo',
93
94
  'other',
@@ -130,7 +131,9 @@ export default class PobAppGenerator extends Generator {
130
131
  default() {
131
132
  const srcDirectory =
132
133
  this.appConfig.type === 'yarn-plugin' ? 'sources' : 'src';
133
- const isAppLibrary = this.appConfig.type === 'node-library';
134
+ const isAppLibrary =
135
+ this.appConfig.type === 'node-library' ||
136
+ this.appConfig.type === 'untranspiled-library';
134
137
 
135
138
  if (
136
139
  this.appConfig.type === 'node' ||
@@ -228,9 +231,9 @@ export default class PobAppGenerator extends Generator {
228
231
  return '';
229
232
  })(),
230
233
  additionalIncludes: (() => {
231
- if (this.appConfig.type === 'next.js') {
232
- return '.next/types/**/*.ts';
233
- }
234
+ // if (this.appConfig.type === 'next.js') {
235
+ // return '.next/types/**/*.ts';
236
+ // }
234
237
  return '';
235
238
  })(),
236
239
  });
@@ -308,6 +311,7 @@ export default class PobAppGenerator extends Generator {
308
311
  yarnNodeLinker: this.options.yarnNodeLinker,
309
312
  typescript,
310
313
  testing: this.appConfig.testing,
314
+ testRunner: this.appConfig.testRunner,
311
315
  });
312
316
 
313
317
  // only for gitignore
@@ -335,6 +339,7 @@ export default class PobAppGenerator extends Generator {
335
339
  case 'remix':
336
340
  this.composeWith('pob:app:remix', {});
337
341
  break;
342
+ // no default
338
343
  }
339
344
 
340
345
  if (platform !== 'win32') {
@@ -14,6 +14,7 @@ export const appIgnorePaths = {
14
14
  pobpack: (config) => ['/build', '/public'],
15
15
  node: (config) => ['/build'],
16
16
  'node-library': (config) => ['/build'],
17
+ 'untranspiled-library': (config) => [],
17
18
  'alp-node': (config) => ['/build'],
18
19
  other: (config) => [],
19
20
  expo: (config) => [
@@ -27,7 +28,7 @@ export const appIgnorePaths = {
27
28
  '/web-build/',
28
29
 
29
30
  '# Temporary files created by Metro to check the health of the file watcher',
30
- '.metro-health-check*',
31
+ '/.metro-health-check*',
31
32
  ],
32
33
  'yarn-plugin': (config) => [],
33
34
  };
@@ -457,14 +457,6 @@ export default class CommonBabelGenerator extends Generator {
457
457
 
458
458
  packageUtils.removeDevDependencies(pkg, ['@rollup/plugin-run']);
459
459
  packageUtils.removeDependencies(pkg, ['alp-rollup-plugin-config']);
460
- packageUtils.addOrRemoveDevDependencies(
461
- pkg,
462
- useBabel &&
463
- this.options.isApp &&
464
- !this.options.isAppLibrary &&
465
- this.options.useAppConfig,
466
- ['alp-rollup-plugin-config'],
467
- );
468
460
 
469
461
  this.fs.delete('rollup.config.js');
470
462
  if (useBabel) {
@@ -133,12 +133,14 @@ export default class CommonLintGenerator extends Generator {
133
133
  const useNodeOnly =
134
134
  (!useBabel && !useTypescript) ||
135
135
  (useTypescript &&
136
- pkg.pob?.envs?.every((env) => env.target === 'node') &&
137
- pkg.pob?.entries.every(
138
- (entry) =>
139
- typeof entry === 'string' ||
140
- (entry.target && entry.target !== 'node'),
141
- )) ||
136
+ (!pkg.pob?.envs ||
137
+ pkg.pob?.envs?.every((env) => env.target === 'node')) &&
138
+ (!pkg.pob?.entries ||
139
+ pkg.pob?.entries.every(
140
+ (entry) =>
141
+ typeof entry === 'string' ||
142
+ (entry.target && entry.target !== 'node'),
143
+ ))) ||
142
144
  (babelEnvs.length > 0 && babelEnvs.every((env) => env.target === 'node'));
143
145
 
144
146
  if (this.fs.exists(this.destinationPath('.eslintignore'))) {
@@ -564,7 +566,8 @@ export default class CommonLintGenerator extends Generator {
564
566
 
565
567
  // see monorepo/lerna/index.js
566
568
  if (!(inMonorepo && inMonorepo.root) && !this.options.monorepo) {
567
- const srcDirectory = useBabel ? this.options.srcDirectory : 'lib';
569
+ const srcDirectory =
570
+ useBabel || this.options.typescript ? this.options.srcDirectory : 'lib';
568
571
  const lintRootJsFiles = (useBabel && useNode) || !inMonorepo;
569
572
 
570
573
  const lintPaths = [srcDirectory, 'bin', 'scripts', 'migrations'].filter(
@@ -15,7 +15,7 @@ CHANGELOG.md
15
15
  <% for (let workspace of workspaces) { -%>
16
16
  <% if (ignorePatterns) { -%>
17
17
  <% for (let ignorePattern of ignorePatterns) { -%>
18
- <%= '/' + workspace + ignorePattern %>
18
+ <%= ignorePattern.startsWith('*') ? ignorePattern : '/' + workspace + ignorePattern %>
19
19
  <% } -%>
20
20
  <% } -%>
21
21
  <% } -%>
@@ -132,7 +132,7 @@ export default function updateEslintConfig(
132
132
  config.root = true;
133
133
  config.extends = [
134
134
  ...extendsConfig,
135
- ...(config?.extends
135
+ ...(config?.extends && Array.isArray(config.extends)
136
136
  ? config.extends.filter(
137
137
  (extendsValue) =>
138
138
  extendsValue === '@pob/eslint-config-typescript/allow-unsafe',
@@ -114,6 +114,13 @@ export default class CommonTestingGenerator extends Generator {
114
114
  default: false,
115
115
  desc: 'Disable git cache. See https://yarnpkg.com/features/caching#offline-mirror.',
116
116
  });
117
+
118
+ this.option('swc', {
119
+ type: Boolean,
120
+ required: false,
121
+ default: false,
122
+ desc: 'Use swc to transpile code.',
123
+ });
117
124
  }
118
125
 
119
126
  default() {
@@ -155,7 +162,8 @@ export default class CommonTestingGenerator extends Generator {
155
162
  'pob-lcov-reporter',
156
163
  ]);
157
164
 
158
- const yoConfigPobMonorepo = inMonorepo && inMonorepo.pobMonorepoConfig;
165
+ const yoConfigPobMonorepo =
166
+ (inMonorepo && inMonorepo.pobMonorepoConfig) || {};
159
167
  const globalTesting = yoConfigPobMonorepo && yoConfigPobMonorepo.testing;
160
168
  const enableForMonorepo = this.options.monorepo && globalTesting;
161
169
  const transpileWithEsbuild = packageUtils.transpileWithEsbuild(pkg);
@@ -177,14 +185,62 @@ export default class CommonTestingGenerator extends Generator {
177
185
 
178
186
  const isJestRunner = testRunner === 'jest';
179
187
 
180
- const tsTestUtil = 'ts-node'; // : 'babel' | 'tsimp' | 'ts-node' | 'swc'
181
- packageUtils.addOrRemoveDevDependencies(
182
- pkg,
183
- this.options.enable &&
184
- (!inMonorepo || inMonorepo.root) &&
185
- testRunner === 'node' &&
186
- this.options.typescript,
187
- [tsTestUtil],
188
+ const tsTestUtil = (() => {
189
+ if (testRunner === 'vitest') return undefined;
190
+ if (this.options.swc || isJestRunner) return 'swc';
191
+ return 'ts-node';
192
+ })();
193
+
194
+ const dependenciesForTestUtil = {
195
+ 'ts-node': { devDependenciesShared: ['ts-node'] },
196
+ swc: {
197
+ devDependenciesShared: ['@swc/core'],
198
+ devDependenciesWithJest: ['@swc/jest'],
199
+ devDependenciesWithNode: ['@swc-node/register'],
200
+ },
201
+ };
202
+
203
+ Object.entries(dependenciesForTestUtil).forEach(
204
+ ([
205
+ key,
206
+ {
207
+ devDependenciesShared,
208
+ devDependenciesWithJest,
209
+ devDependenciesWithNode,
210
+ },
211
+ ]) => {
212
+ const sharedCondition =
213
+ this.options.enable &&
214
+ (!inMonorepo || inMonorepo.root) &&
215
+ this.options.typescript &&
216
+ key === tsTestUtil;
217
+ packageUtils.addOrRemoveDevDependencies(
218
+ pkg,
219
+ sharedCondition &&
220
+ (testRunner === 'node' || (withTypescript && !transpileWithBabel)),
221
+ devDependenciesShared,
222
+ );
223
+ if (devDependenciesWithJest) {
224
+ packageUtils.addOrRemoveDevDependencies(
225
+ pkg,
226
+ sharedCondition &&
227
+ withTypescript &&
228
+ !transpileWithBabel &&
229
+ testRunner === 'jest',
230
+ devDependenciesWithJest,
231
+ );
232
+ }
233
+ if (devDependenciesWithNode) {
234
+ packageUtils.addOrRemoveDevDependencies(
235
+ pkg,
236
+ sharedCondition &&
237
+ withTypescript &&
238
+ !transpileWithBabel &&
239
+ testRunner === 'node',
240
+ devDependenciesWithNode,
241
+ );
242
+ }
243
+ },
188
244
  );
189
245
 
190
246
  if (
@@ -203,12 +259,12 @@ export default class CommonTestingGenerator extends Generator {
203
259
 
204
260
  const tsTestLoaderOption = (() => {
205
261
  switch (tsTestUtil) {
206
- case 'tsimp':
207
- return '--import=tsimp/import';
208
262
  case 'ts-node':
209
263
  return '--loader=ts-node/esm --experimental-specifier-resolution=node';
210
- case '@swc-node/register':
264
+ case 'swc':
211
265
  return '--import=@swc-node/register/esm';
266
+
267
+ // no default
212
268
  }
213
269
  })();
214
270
 
@@ -246,7 +302,7 @@ export default class CommonTestingGenerator extends Generator {
246
302
  if (!workspacesPattern && this.options.monorepo) {
247
303
  throw new Error('Invalid workspacesPattern');
248
304
  }
249
- return `${tsTestUtil === 'tsimp' ? 'TSIMP_DIAG=ignore ' : ''}${
305
+ return `${
250
306
  tsTestUtil === 'ts-node'
251
307
  ? 'TS_NODE_PROJECT=tsconfig.test.json '
252
308
  : ''
@@ -264,6 +320,15 @@ export default class CommonTestingGenerator extends Generator {
264
320
  hasTestFolder ? 'test/*' : `${this.options.srcDirectory}/**/*.test`
265
321
  }.${this.options.typescript ? 'ts' : 'js'}`}`;
266
322
  }
323
+ case 'vitest': {
324
+ return `${
325
+ coverage || coverageJson || coverageLcov
326
+ ? `POB_VITEST_COVERAGE=${
327
+ coverageLcov ? 'lcov' : `json${coverageJson ? '' : ',text'} `
328
+ }`
329
+ : ''
330
+ }vitest${watch ? ' --watch' : ''}`;
331
+ }
267
332
  default: {
268
333
  throw new Error(`Invalid runner: "${testRunner}"`);
269
334
  }
@@ -376,6 +441,24 @@ export default class CommonTestingGenerator extends Generator {
376
441
  } else {
377
442
  delete jestConfig.extensionsToTreatAsEsm;
378
443
  }
444
+
445
+ if (tsTestUtil === 'swc' && !transpileWithBabel && withTypescript) {
446
+ jestConfig.transform = {
447
+ [hasReact ? '^.+\\.tsx?$' : '^.+\\.ts$']: ['@swc/jest'],
448
+ };
449
+ } else if (jestConfig.transform) {
450
+ jestConfig.transform = Object.fromEntries(
451
+ Object.entries(jestConfig.transform).filter(
452
+ ([key, value]) =>
453
+ value !== '@swc/jest' &&
454
+ !(Array.isArray(value) && value[0] === '@swc/jest'),
455
+ ),
456
+ );
457
+ if (Object.keys(jestConfig.transform).length === 0) {
458
+ delete jestConfig.transform;
459
+ }
460
+ }
461
+
379
462
  writeAndFormatJson(this.fs, jestConfigPath, jestConfig);
380
463
  }
381
464
  } else {
@@ -476,21 +559,44 @@ export default class CommonTestingGenerator extends Generator {
476
559
  },
477
560
  ],
478
561
  };
479
- } else if (!transpileWithBabel) {
562
+ } else if (!transpileWithBabel && !withTypescript) {
480
563
  delete jestConfig.transform;
481
- } else if (jestConfig.transform) {
482
- jestConfig.transform = Object.fromEntries(
483
- Object.entries(jestConfig.transform).filter(
484
- ([key, value]) =>
485
- !(
486
- value &&
487
- Array.isArray(value) &&
488
- value[0] === 'jest-esbuild'
489
- ),
490
- ),
491
- );
492
- if (Object.keys(jestConfig.transform).length === 0) {
493
- delete jestConfig.transform;
564
+ } else {
565
+ if (
566
+ tsTestUtil === 'swc' &&
567
+ !transpileWithBabel &&
568
+ withTypescript
569
+ ) {
570
+ jestConfig.transform = {
571
+ [hasReact ? '^.+\\.tsx?$' : '^.+\\.ts$']: ['@swc/jest'],
572
+ };
573
+ } else if (jestConfig.transform) {
574
+ jestConfig.transform = Object.fromEntries(
575
+ Object.entries(jestConfig.transform).filter(
576
+ ([key, value]) =>
577
+ value !== '@swc/jest' &&
578
+ !(Array.isArray(value) && value[0] === '@swc/jest'),
579
+ ),
580
+ );
581
+ if (Object.keys(jestConfig.transform).length === 0) {
582
+ delete jestConfig.transform;
583
+ }
584
+ }
585
+
586
+ if (jestConfig.transform) {
587
+ jestConfig.transform = Object.fromEntries(
588
+ Object.entries(jestConfig.transform).filter(
589
+ ([key, value]) =>
590
+ !(
591
+ value &&
592
+ Array.isArray(value) &&
593
+ value[0] === 'jest-esbuild'
594
+ ),
595
+ ),
596
+ );
597
+ if (Object.keys(jestConfig.transform).length === 0) {
598
+ delete jestConfig.transform;
599
+ }
494
600
  }
495
601
  }
496
602
 
@@ -130,15 +130,23 @@ export default class CommonTranspilerGenerator extends Generator {
130
130
 
131
131
  default() {
132
132
  const pkg = this.fs.readJSON(this.destinationPath('package.json'));
133
- const withTypescript = pkg.pob.typescript;
134
133
  const withBabel = this.babelEnvs && this.babelEnvs.length > 0;
135
- const useRollup = (withBabel || withTypescript) && pkg.pob.rollup !== false;
134
+ const withTypescript = pkg.pob.typescript || withBabel || !!pkg.pob.bundler;
135
+ const bundler =
136
+ withTypescript &&
137
+ (pkg.pob.rollup === false
138
+ ? 'tsc'
139
+ : pkg.pob.bundler ??
140
+ (pkg.pob.typescript ? 'rollup-typescript' : 'rollup'));
141
+ this.bundler = bundler;
136
142
 
137
143
  const cleanCommand = (() => {
138
- if (useRollup) {
139
- if (withTypescript) return 'pob-typescript-clean-out';
144
+ if (bundler === 'rollup-typescript') return 'pob-typescript-clean-out';
145
+ if (bundler === 'rollup-esbuild') return 'pob-esbuild-clean-out';
146
+ if (bundler === 'rollup') {
140
147
  return 'pob-babel-clean-out';
141
148
  }
149
+ if (bundler === 'esbuild') return 'pob-esbuild-clean-out';
142
150
  return null;
143
151
  })();
144
152
 
@@ -146,36 +154,47 @@ export default class CommonTranspilerGenerator extends Generator {
146
154
 
147
155
  if (this.options.isApp) {
148
156
  packageUtils.removeScripts(['watch']);
149
- packageUtils.addOrRemoveScripts(pkg, useRollup, {
157
+ packageUtils.addOrRemoveScripts(pkg, bundler && bundler !== 'tsc', {
150
158
  'clean:build': `${cleanCommand} ${this.options.buildDirectory}`,
151
159
  clean: 'yarn clean:build',
152
160
  });
153
161
 
154
- packageUtils.addOrRemoveScripts(pkg, useRollup || withTypescript, {
155
- start: useRollup
156
- ? 'yarn clean:build && rollup --config rollup.config.mjs --watch'
157
- : 'tsc --watch',
162
+ packageUtils.addOrRemoveScripts(pkg, bundler, {
163
+ start: (() => {
164
+ if (bundler && bundler.startsWith('rollup')) {
165
+ return 'yarn clean:build && rollup --config rollup.config.mjs --watch';
166
+ }
167
+ if (bundler === 'tsc') return 'tsc --watch';
168
+ if (bundler === 'esbuild') return 'pob-esbuild-watch';
169
+ })(),
158
170
  });
159
171
  } else {
160
172
  packageUtils.removeScripts(['start']);
161
- packageUtils.addOrRemoveScripts(pkg, useRollup, {
173
+ packageUtils.addOrRemoveScripts(pkg, bundler && bundler !== 'tsc', {
162
174
  'clean:build': `${cleanCommand} ${this.options.buildDirectory}`,
163
175
  });
164
176
  }
165
- packageUtils.addOrRemoveScripts(pkg, useRollup || withTypescript, {
166
- build: useRollup
167
- ? 'yarn clean:build && rollup --config rollup.config.mjs'
168
- : 'tsc',
177
+
178
+ packageUtils.addOrRemoveScripts(pkg, bundler, {
179
+ build: (() => {
180
+ if (bundler && bundler.startsWith('rollup')) {
181
+ return 'yarn clean:build && rollup --config rollup.config.mjs';
182
+ }
183
+ if (bundler === 'tsc') return 'tsc';
184
+ if (bundler === 'esbuild') return 'pob-esbuild-build';
185
+ })(),
169
186
  });
170
187
 
171
- const shouldBuildDefinitions = !this.options.isApp && useRollup;
188
+ const shouldBuildDefinitions =
189
+ !this.options.isApp && withTypescript && bundler !== 'tsc';
190
+
172
191
  packageUtils.addOrRemoveScripts(pkg, shouldBuildDefinitions, {
173
192
  'build:definitions': 'tsc -p tsconfig.json',
174
193
  });
175
194
 
176
195
  if (shouldBuildDefinitions) {
177
196
  pkg.scripts.build += ' && yarn run build:definitions';
178
- } else if (!this.options.isApp && !useRollup && !withTypescript) {
197
+ } else if (!this.options.isApp && !bundler && !withTypescript) {
179
198
  // check definitions, but also force lerna to execute build:definitions in right order
180
199
  // example: nightingale-types depends on nightingale-levels
181
200
  if (this.fs.exists(this.destinationPath('lib/index.d.ts'))) {
@@ -203,9 +222,36 @@ export default class CommonTranspilerGenerator extends Generator {
203
222
 
204
223
  /* dependencies */
205
224
 
206
- packageUtils.addOrRemoveDevDependencies(pkg, useRollup && withTypescript, [
207
- '@pob/rollup-typescript',
208
- ]);
225
+ packageUtils.addOrRemoveDevDependencies(
226
+ pkg,
227
+ bundler === 'rollup-typescript',
228
+ ['@pob/rollup-typescript'],
229
+ );
230
+ packageUtils.addOrRemoveDevDependencies(
231
+ pkg,
232
+ bundler === 'esbuild' && withTypescript,
233
+ ['@pob/esbuild'],
234
+ );
235
+ packageUtils.addOrRemoveDevDependencies(
236
+ pkg,
237
+ bundler === 'rollup-esbuild' && withTypescript,
238
+ ['@pob/rollup-esbuild'],
239
+ );
240
+ packageUtils.addOrRemoveDependencies(
241
+ pkg,
242
+ (bundler === 'tsc' || bundler === 'rollup-typescript') && withTypescript,
243
+ ['tslib'],
244
+ '^',
245
+ );
246
+
247
+ packageUtils.addOrRemoveDevDependencies(
248
+ pkg,
249
+ bundler === 'rollup' &&
250
+ this.options.isApp &&
251
+ !this.options.isAppLibrary &&
252
+ this.options.useAppConfig,
253
+ ['alp-rollup-plugin-config'],
254
+ );
209
255
 
210
256
  /* engines */
211
257
  // TODO move from CommonBabelGenerator
@@ -234,7 +280,7 @@ export default class CommonTranspilerGenerator extends Generator {
234
280
  }
235
281
 
236
282
  // if (!pkg.main || pkg.main.startsWith('./lib/')) {
237
- if (useRollup || withTypescript) {
283
+ if (bundler || withTypescript) {
238
284
  // see pkg.exports instead.
239
285
  delete pkg.main;
240
286
  if (!this.options.isApp) {
@@ -305,12 +351,14 @@ export default class CommonTranspilerGenerator extends Generator {
305
351
  }
306
352
 
307
353
  /* webpack 5 and node with ESM support */
308
- if (useRollup || withTypescript) {
354
+ if (bundler || withTypescript) {
355
+ const omitTarget = bundler === 'esbuild';
309
356
  pkg.exports = {
310
357
  './package.json': './package.json',
311
358
  };
312
359
 
313
- this.entries.forEach((entry) => {
360
+ this.entries.forEach((entryWithOptionalExt) => {
361
+ const entry = entryWithOptionalExt.replace(/\.[jt]sx?$/, '');
314
362
  const isBrowserOnly =
315
363
  withBabel &&
316
364
  entry === 'browser' &&
@@ -324,7 +372,7 @@ export default class CommonTranspilerGenerator extends Generator {
324
372
  pkg.private || this.options.isAppLibrary
325
373
  ? `./src/${entryDistName}.ts`
326
374
  : `./${this.options.buildDirectory}/${
327
- useRollup ? 'definitions/' : ''
375
+ bundler !== 'tsc' ? 'definitions/' : ''
328
376
  }${entryDistName}.d.ts`,
329
377
  };
330
378
 
@@ -342,8 +390,10 @@ export default class CommonTranspilerGenerator extends Generator {
342
390
 
343
391
  if (target === 'node') {
344
392
  const cjsExt = pkg.type === 'module' ? 'cjs' : 'cjs.js';
345
- const filenameWithoutExt = `${entryDistName}-${target}${
346
- omitVersionInFileName ? '' : version
393
+ const filenameWithoutExt = `${entryDistName}${
394
+ omitTarget
395
+ ? ''
396
+ : `-${target}${omitVersionInFileName ? '' : version}`
347
397
  }`;
348
398
  if (!formats || formats.includes('es')) {
349
399
  exportTarget.import = `./${this.options.buildDirectory}/${filenameWithoutExt}.mjs`;
@@ -473,13 +523,18 @@ export default class CommonTranspilerGenerator extends Generator {
473
523
  const entries = pkg.pob.entries || ['index'];
474
524
 
475
525
  this.fs.delete('rollup.config.js');
476
- if (pkg.pob.typescript && pkg.pob.rollup !== false) {
526
+ if (
527
+ pkg.pob.typescript &&
528
+ pkg.pob.rollup !== false &&
529
+ (!pkg.pob.bundler || pkg.pob.bundler.startsWith('rollup'))
530
+ ) {
477
531
  if (this.options.isApp) {
478
532
  copyAndFormatTpl(
479
533
  this.fs,
480
534
  this.templatePath('app.rollup.config.mjs.ejs'),
481
535
  this.destinationPath('rollup.config.mjs'),
482
536
  {
537
+ rollupConfigLib: this.bundler,
483
538
  config: this.options.useAppConfig,
484
539
  outDirectory: this.options.buildDirectory,
485
540
  enableRun: !this.options.isAppLibrary && entries.includes('index'),
@@ -491,11 +546,16 @@ export default class CommonTranspilerGenerator extends Generator {
491
546
  this.templatePath('lib.rollup.config.mjs.ejs'),
492
547
  this.destinationPath('rollup.config.mjs'),
493
548
  {
549
+ rollupConfigLib: this.bundler,
494
550
  outDirectory: this.options.buildDirectory,
495
551
  },
496
552
  );
497
553
  }
498
- } else if (!pkg.pob.babelEnvs || pkg.pob.babelEnvs.length === 0) {
554
+ } else if (
555
+ !pkg.pob.babelEnvs ||
556
+ pkg.pob.babelEnvs.length === 0 ||
557
+ pkg.pob?.bundler === 'esbuild'
558
+ ) {
499
559
  this.fs.delete('rollup.config.mjs');
500
560
  }
501
561
 
@@ -3,9 +3,9 @@ import { fileURLToPath } from 'node:url';
3
3
  <% if (config) { -%>
4
4
  import config from 'alp-rollup-plugin-config';
5
5
  <% } -%>
6
- import createRollupConfig from '@pob/rollup-typescript/createRollupConfig.js';
6
+ import createRollupConfig from '@pob/<%= rollupConfigLib %>/createRollupConfig.js';
7
7
  <% if (enableRun) { -%>
8
- import run from '@pob/rollup-typescript/plugin-run.cjs';
8
+ import run from '@pob/<%= rollupConfigLib %>/plugin-run.cjs';
9
9
 
10
10
  const watch = process.env.ROLLUP_WATCH === 'true';
11
11
  <% } -%>
@@ -1,6 +1,6 @@
1
1
  import { dirname } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
- import createRollupConfig from '@pob/rollup-typescript/createRollupConfig.js';
3
+ import createRollupConfig from '@pob/<%= rollupConfigLib %>/createRollupConfig.js';
4
4
 
5
5
  export default createRollupConfig({
6
6
  cwd: dirname(fileURLToPath(import.meta.url)),
@@ -135,12 +135,16 @@ export default class CommonTypescriptGenerator extends Generator {
135
135
  version: '18',
136
136
  },
137
137
  ];
138
- if (pkg.pob.rollup === false) {
138
+ if (pkg.pob.rollup === false || pkg.pob.bundler === false) {
139
139
  return [`@pob/root/tsconfigs/targets/node-${nodeVersion}.json`];
140
140
  }
141
141
  if (envs && envs.every((env) => env.target === 'node')) {
142
142
  return [
143
- `@pob/root/tsconfigs/targets/rollup-node-${nodeVersion}.json`,
143
+ `@pob/root/tsconfigs/targets/${
144
+ !pkg.pob.bundler || pkg.pob.bundler.startsWith('rollup')
145
+ ? 'rollup'
146
+ : pkg.pob.bundler
147
+ }-node-${nodeVersion}.json`,
144
148
  ];
145
149
  }
146
150
  return ['@pob/root/tsconfigs/targets/rollup-es2015.json'];
@@ -258,7 +262,7 @@ export default class CommonTypescriptGenerator extends Generator {
258
262
  tsconfigPath,
259
263
  {
260
264
  emitDefinitions: this.options.builddefs,
261
- build: pkg.pob?.rollup === false,
265
+ build: pkg.pob?.rollup === false || pkg.pob?.bundler === false,
262
266
  cacheEnabled: !this.options.isApp || this.options.isAppLibrary,
263
267
  monorepoPackageSrcPaths,
264
268
  monorepoPackageReferences,
@@ -42,7 +42,7 @@ jobs:
42
42
  run: touch docs/.nojekyll
43
43
 
44
44
  - name: Deploy
45
- uses: peaceiris/actions-gh-pages@v3
45
+ uses: peaceiris/actions-gh-pages@v4
46
46
  with:
47
47
  github_token: ${{ secrets.GITHUB_TOKEN }}
48
48
  publish_dir: ./docs
@@ -27,10 +27,6 @@ yarn-error.log*
27
27
  <% } -%>
28
28
  <% if (testing) { -%>
29
29
 
30
- <% if (typescript && !withBabel && tsTestUtil === 'tsimp') { -%>
31
- # tsimp cache
32
- /.tsimp
33
- <% } -%>
34
30
  # default coverage directory
35
31
  /coverage
36
32
  <% } -%>
@@ -36,6 +36,12 @@ export default class CorePackageGenerator extends Generator {
36
36
  default: false,
37
37
  desc: 'private package',
38
38
  });
39
+
40
+ this.option('packageType', {
41
+ type: String,
42
+ required: false,
43
+ desc: 'package type',
44
+ });
39
45
  }
40
46
 
41
47
  async initializing() {
@@ -106,6 +112,10 @@ export default class CorePackageGenerator extends Generator {
106
112
  pkg.name = name;
107
113
  }
108
114
 
115
+ if (this.options.packageType) {
116
+ pkg.type = this.options.packageType;
117
+ }
118
+
109
119
  let author = packageUtils.parsePkgAuthor(pkg);
110
120
 
111
121
  const props = await this.prompt(
@@ -34,6 +34,12 @@ export default class CoreVSCodeGenerator extends Generator {
34
34
  desc: 'Testing enabled',
35
35
  });
36
36
 
37
+ this.option('testRunner', {
38
+ type: String,
39
+ required: false,
40
+ desc: 'Test runner (jest, vitest, ...)',
41
+ });
42
+
37
43
  this.option('yarnNodeLinker', {
38
44
  type: String,
39
45
  required: false,
@@ -81,6 +87,7 @@ export default class CoreVSCodeGenerator extends Generator {
81
87
  npm: this.options.packageManager === 'npm',
82
88
  typescript: this.options.typescript,
83
89
  testing: this.options.testing,
90
+ testRunner: this.options.testRunner,
84
91
  module: pkg.type === 'module',
85
92
  },
86
93
  );
@@ -35,7 +35,7 @@
35
35
  },
36
36
 
37
37
 
38
- <% if (testing && module) { -%>
38
+ <% if (testing && module && (!testRunner || testRunner === 'jest')) { -%>
39
39
  // jest
40
40
  "jest.jestCommandLine": "NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest",
41
41
  <% } -%>
@@ -342,6 +342,7 @@ export default class PobLibGenerator extends Generator {
342
342
  yarnNodeLinker: this.options.yarnNodeLinker,
343
343
  typescript: withBabel || withTypescript,
344
344
  testing: this.pobjson.testing,
345
+ testRunner: this.pobjson.testRunner,
345
346
  });
346
347
 
347
348
  // must be after doc, testing
@@ -275,6 +275,7 @@ export default class PobMonorepoGenerator extends Generator {
275
275
  yarnNodeLinker: this.options.yarnNodeLinker,
276
276
  typescript: this.pobLernaConfig.typescript,
277
277
  testing: this.pobLernaConfig.testing,
278
+ testRunner: this.pobLernaConfig.testRunner,
278
279
  packageNames: JSON.stringify(packageNames),
279
280
  packageLocations: JSON.stringify(this.packageLocations),
280
281
  });
@@ -199,6 +199,8 @@ export default class MonorepoWorkspacesGenerator extends Generator {
199
199
  case 'yarn':
200
200
  // see CoreYarnGenerator
201
201
  break;
202
+ default:
203
+ throw new Error('Invalid packageManager');
202
204
  }
203
205
  }
204
206
  }
@@ -81,6 +81,13 @@ export default class PobBaseGenerator extends Generator {
81
81
  delete config.yarn2;
82
82
  }
83
83
 
84
+ if (!config.type) {
85
+ const pkg = this.fs.readJSON(this.destinationPath('package.json'), {});
86
+ if (pkg.dependencies?.next) {
87
+ config.type = 'app';
88
+ }
89
+ }
90
+
84
91
  const responses = await this.prompt([
85
92
  {
86
93
  when: () => !config.type,
@@ -123,10 +130,11 @@ export default class PobBaseGenerator extends Generator {
123
130
 
124
131
  this.composeWith('pob:core:package', {
125
132
  updateOnly: this.options.updateOnly,
126
- private: this.isMonorepo,
133
+ private: this.isMonorepo || this.projectConfig.type === 'app',
127
134
  isMonorepo: this.isMonorepo,
128
135
  inMonorepo: !!inMonorepo,
129
136
  isRoot: this.isRoot,
137
+ packageType: this.projectConfig.type === 'app' ? 'module' : undefined,
130
138
  });
131
139
 
132
140
  if (this.isMonorepo) {
@@ -244,6 +252,7 @@ export default class PobBaseGenerator extends Generator {
244
252
  this.spawnCommandSync('npm', ['install']);
245
253
  break;
246
254
  case 'yarn':
255
+ default:
247
256
  // see CoreYarnGenerator
248
257
  break;
249
258
  }
package/lib/pob.js CHANGED
@@ -306,6 +306,7 @@ if (action === 'migrate-to-monorepo') {
306
306
 
307
307
  const monorepoName = `${path.basename(process.cwd())}-monorepo`;
308
308
  const monorepoPkg = {
309
+ private: true,
309
310
  name: monorepoName,
310
311
  version: projectPkg.version,
311
312
  author: projectPkg.author,
@@ -313,6 +314,7 @@ if (action === 'migrate-to-monorepo') {
313
314
  repository: projectPkg.repository,
314
315
  engines: projectPkg.engines,
315
316
  packageManager: projectPkg.packageManager,
317
+ workspaces: ['packages/*'],
316
318
  };
317
319
 
318
320
  writeFileSync('package.json', JSON.stringify(monorepoPkg, null, 2));
@@ -222,8 +222,8 @@ export function removeDevDependencies(pkg, dependencies, forceEvenIfInPeerDep) {
222
222
  );
223
223
  }
224
224
 
225
- export function addOrRemoveDependencies(pkg, condition, dependencies) {
226
- if (condition) return addDependencies(pkg, dependencies);
225
+ export function addOrRemoveDependencies(pkg, condition, dependencies, prefix) {
226
+ if (condition) return addDependencies(pkg, dependencies, prefix);
227
227
  return removeDependencies(pkg, dependencies);
228
228
  }
229
229
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pob",
3
- "version": "18.3.0",
3
+ "version": "18.4.0",
4
4
  "description": "Pile of bones, library generator with git/babel/typescript/typedoc/readme/jest",
5
5
  "keywords": [
6
6
  "skeleton"
@@ -39,18 +39,18 @@
39
39
  "pob": {},
40
40
  "prettier": "@pob/root/prettier-config",
41
41
  "dependencies": {
42
- "@pob/eslint-config": "54.0.0",
43
- "@pob/eslint-config-typescript": "54.0.0",
44
- "@pob/eslint-config-typescript-react": "54.0.0",
45
- "@pob/sort-eslint-config": "5.2.1",
46
- "@pob/sort-object": "6.2.1",
47
- "@pob/sort-pkg": "7.0.0",
42
+ "@pob/eslint-config": "55.2.1",
43
+ "@pob/eslint-config-typescript": "55.2.1",
44
+ "@pob/eslint-config-typescript-react": "55.2.1",
45
+ "@pob/sort-eslint-config": "5.3.0",
46
+ "@pob/sort-object": "6.3.0",
47
+ "@pob/sort-pkg": "7.1.0",
48
48
  "@types/inquirer": "9.0.7",
49
- "@yarnpkg/cli": "4.1.0",
49
+ "@yarnpkg/cli": "4.1.1",
50
50
  "@yarnpkg/core": "4.0.3",
51
51
  "@yarnpkg/fslib": "3.0.2",
52
- "@yeoman/types": "1.1.2",
53
- "eslint": "8.56.0",
52
+ "@yeoman/types": "1.2.0",
53
+ "eslint": "8.57.0",
54
54
  "findup-sync": "^5.0.0",
55
55
  "git-remote-url": "^1.0.1",
56
56
  "github-username": "^7.0.0",
@@ -58,19 +58,19 @@
58
58
  "json5": "^2.2.2",
59
59
  "lodash.camelcase": "^4.3.0",
60
60
  "lodash.kebabcase": "^4.1.1",
61
- "mem-fs": "4.0.0",
61
+ "mem-fs": "4.1.0",
62
62
  "mem-fs-editor": "11.0.0",
63
63
  "minimist": "1.2.8",
64
64
  "parse-author": "2.0.0",
65
- "pob-dependencies": "11.1.0",
65
+ "pob-dependencies": "11.2.0",
66
66
  "prettier": "2.8.8",
67
67
  "semver": "7.6.0",
68
68
  "validate-npm-package-name": "^5.0.0",
69
- "yarn-workspace-utils": "3.2.0",
70
- "yeoman-environment": "4.3.0",
69
+ "yarn-workspace-utils": "3.3.0",
70
+ "yeoman-environment": "4.4.0",
71
71
  "yeoman-generator": "7.1.1"
72
72
  },
73
73
  "devDependencies": {
74
- "@pob/root": "9.2.0"
74
+ "@pob/root": "9.3.0"
75
75
  }
76
76
  }