pob 15.0.3 → 15.2.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 (25) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/lib/generators/app/PobAppGenerator.js +50 -19
  3. package/lib/generators/app/e2e-testing/AppE2ETestingGenerator.js +45 -0
  4. package/lib/generators/common/babel/CommonBabelGenerator.js +18 -311
  5. package/lib/generators/common/format-lint/CommonLintGenerator.js +15 -15
  6. package/lib/generators/common/release/CommonReleaseGenerator.js +8 -1
  7. package/lib/generators/common/testing/CommonTestingGenerator.js +24 -14
  8. package/lib/generators/common/transpiler/CommonTranspilerGenerator.js +491 -0
  9. package/lib/generators/common/transpiler/templates/app.rollup.config.mjs.ejs +26 -0
  10. package/lib/generators/common/transpiler/templates/lib.rollup.config.mjs.ejs +8 -0
  11. package/lib/generators/common/typescript/CommonTypescriptGenerator.js +44 -1
  12. package/lib/generators/common/typescript/templates/tsconfig.json.ejs +17 -19
  13. package/lib/generators/core/ci/CoreCIGenerator.js +7 -0
  14. package/lib/generators/core/ci/templates/github-action-push-workflow-split.yml.ejs +29 -0
  15. package/lib/generators/core/ci/templates/github-action-push-workflow.yml.ejs +5 -0
  16. package/lib/generators/core/git/CoreGitGenerator.js +2 -2
  17. package/lib/generators/core/package/CorePackageGenerator.js +19 -10
  18. package/lib/generators/core/package/askName.js +59 -0
  19. package/lib/generators/core/yarn/CoreYarnGenerator.js +2 -1
  20. package/lib/generators/lib/PobLibGenerator.js +39 -35
  21. package/lib/generators/monorepo/PobMonorepoGenerator.js +13 -12
  22. package/lib/generators/pob/PobBaseGenerator.js +12 -12
  23. package/lib/pob.js +12 -0
  24. package/lib/utils/templateUtils.js +6 -0
  25. package/package.json +20 -21
package/CHANGELOG.md CHANGED
@@ -3,6 +3,51 @@
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
+ ## [15.2.0](https://github.com/christophehurpeau/pob/compare/pob@15.1.0...pob@15.2.0) (2023-12-10)
7
+
8
+
9
+ ### Features
10
+
11
+ * **deps:** update @pob/eslint-config ([#1878](https://github.com/christophehurpeau/pob/issues/1878)) ([f5c1f83](https://github.com/christophehurpeau/pob/commit/f5c1f835fcf98dc963213c7e4620ce02d325d8db))
12
+ * **deps:** update dependency eslint to v8.54.0 ([#1855](https://github.com/christophehurpeau/pob/issues/1855)) ([3baf9c6](https://github.com/christophehurpeau/pob/commit/3baf9c68b9b020f5d069021df8a501d97491250c))
13
+ * **deps:** update dependency eslint to v8.55.0 ([#1872](https://github.com/christophehurpeau/pob/issues/1872)) ([ebee64a](https://github.com/christophehurpeau/pob/commit/ebee64abd61d9e40bd7dd507cd97505861a2496a))
14
+ * **deps:** update dependency validate-npm-package-name to v5 ([#1844](https://github.com/christophehurpeau/pob/issues/1844)) ([6d66f31](https://github.com/christophehurpeau/pob/commit/6d66f317fb9ad82e6c41d190fb1c8dc35198ff3c))
15
+ * **deps:** update dependency yeoman-environment to v4.1.1 ([#1849](https://github.com/christophehurpeau/pob/issues/1849)) ([bf6b70e](https://github.com/christophehurpeau/pob/commit/bf6b70e2b8f345190c03469b5b11417a02a6acdd))
16
+ * experimental alternate ways to compile typescript without babel ([4391b03](https://github.com/christophehurpeau/pob/commit/4391b03c89d94ca00d2a54a4662d09a4b25c860d))
17
+ * make sure check-package-dependencies is up-to-date ([7493e27](https://github.com/christophehurpeau/pob/commit/7493e2709a0a1eae062e3223b3eb64d918db87af))
18
+ * support next ts plugin and latest next version ([095fcde](https://github.com/christophehurpeau/pob/commit/095fcde48d866ee146ac9550f04b8f3acea0e887))
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * add missing libc in supportedArchitectures ([514c66b](https://github.com/christophehurpeau/pob/commit/514c66bf11a36f503afb6df1a19198527328c6aa))
24
+ * **deps:** update dependency @yeoman/types to v1.1.2 ([#1847](https://github.com/christophehurpeau/pob/issues/1847)) ([7479fe6](https://github.com/christophehurpeau/pob/commit/7479fe6b0d8087dd7318c98918f63d95a4ce851d))
25
+ * **deps:** update dependency yeoman-environment to v4.1.2 ([#1850](https://github.com/christophehurpeau/pob/issues/1850)) ([02ed137](https://github.com/christophehurpeau/pob/commit/02ed13735fd697cfbbe1aee900396ec4b50d31f0))
26
+ * **deps:** update dependency yeoman-environment to v4.1.3 ([#1851](https://github.com/christophehurpeau/pob/issues/1851)) ([06f8cc2](https://github.com/christophehurpeau/pob/commit/06f8cc270be64899f55f99c3584a3b6519a99bbe))
27
+ * **deps:** update dependency yeoman-generator to v7.1.1 ([#1848](https://github.com/christophehurpeau/pob/issues/1848)) ([d176ea7](https://github.com/christophehurpeau/pob/commit/d176ea74f4ee6d885f7fd9c58664a7e2ef699932))
28
+ * **deps:** update yarn monorepo to v4.0.2 ([#1846](https://github.com/christophehurpeau/pob/issues/1846)) ([1a61fa5](https://github.com/christophehurpeau/pob/commit/1a61fa51058c3a320d3c9e603376b2e189271ddd))
29
+ * remove legacy lib inquirer-npm-name ([6aae255](https://github.com/christophehurpeau/pob/commit/6aae25583d5f88f61132144246f2031ccf001018))
30
+
31
+ Version bump for dependency: sort-eslint-config
32
+ Version bump for dependency: sort-object
33
+ Version bump for dependency: sort-pkg
34
+ Version bump for dependency: yarn-workspace-utils
35
+ Version bump for dependency: root
36
+
37
+
38
+ ## [15.1.0](https://github.com/christophehurpeau/pob/compare/pob@15.0.3...pob@15.1.0) (2023-11-11)
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * **deps:** update dependency @types/inquirer to v9.0.7 ([#1839](https://github.com/christophehurpeau/pob/issues/1839)) ([0f2bfb3](https://github.com/christophehurpeau/pob/commit/0f2bfb3b020287c49aa6a0ee37254a11ed3089cd))
44
+ * **deps:** update yeoman group ([#1810](https://github.com/christophehurpeau/pob/issues/1810)) ([cd69295](https://github.com/christophehurpeau/pob/commit/cd692950f15e4f64c8e392f282f6981c797773eb))
45
+ * **pob:** add missing async/await with composeWith ([4b679d5](https://github.com/christophehurpeau/pob/commit/4b679d521430af32fcd6bf8f0fe5dce53c1e68e6))
46
+
47
+ Version bump for dependency: yarn-workspace-utils
48
+ Version bump for dependency: root
49
+
50
+
6
51
  ## [15.0.3](https://github.com/christophehurpeau/pob/compare/pob@15.0.2...pob@15.0.3) (2023-11-05)
7
52
 
8
53
 
@@ -127,7 +127,7 @@ export default class PobAppGenerator extends Generator {
127
127
  this.config.save();
128
128
  }
129
129
 
130
- default() {
130
+ async default() {
131
131
  const srcDirectory =
132
132
  this.appConfig.type === 'yarn-plugin' ? 'sources' : 'src';
133
133
  const isAppLibrary = this.appConfig.type === 'node-library';
@@ -137,7 +137,18 @@ export default class PobAppGenerator extends Generator {
137
137
  this.appConfig.type === 'node-library' ||
138
138
  this.appConfig.type === 'alp-node'
139
139
  ) {
140
- this.composeWith('pob:common:babel', {
140
+ await this.composeWith('pob:common:babel', {
141
+ updateOnly: this.options.updateOnly,
142
+ onlyLatestLTS: true,
143
+ isApp: true,
144
+ isAppLibrary,
145
+ useAppConfig: this.appConfig.type === 'alp-node',
146
+ testing: this.appConfig.testing,
147
+ documentation: false,
148
+ fromPob: this.options.fromPob,
149
+ buildDirectory: 'build',
150
+ });
151
+ await this.composeWith('pob:common:transpiler', {
141
152
  updateOnly: this.options.updateOnly,
142
153
  onlyLatestLTS: true,
143
154
  isApp: true,
@@ -153,12 +164,13 @@ export default class PobAppGenerator extends Generator {
153
164
  const pkg = this.fs.readJSON(this.destinationPath('package.json'));
154
165
 
155
166
  if (!inMonorepo || inMonorepo.root) {
156
- this.composeWith('pob:common:husky', {});
167
+ await this.composeWith('pob:common:husky', {});
157
168
  }
158
169
 
159
170
  const babelEnvs = (pkg.pob && pkg.pob.babelEnvs) || [];
160
171
  const babel =
161
172
  babelEnvs.length > 0 || appsWithTypescript.includes(this.appConfig.type);
173
+ const typescript = babel || pkg.pob?.typescript;
162
174
  const node = true;
163
175
  const browser = appsWithBrowser.includes(this.appConfig.type);
164
176
  const jsx =
@@ -175,8 +187,8 @@ export default class PobAppGenerator extends Generator {
175
187
  pkg,
176
188
  ).filter(Boolean);
177
189
 
178
- this.composeWith('pob:common:typescript', {
179
- enable: babel,
190
+ await this.composeWith('pob:common:typescript', {
191
+ enable: typescript,
180
192
  isApp: true,
181
193
  isAppLibrary,
182
194
  // nextjs now supports src
@@ -190,6 +202,7 @@ export default class PobAppGenerator extends Generator {
190
202
  forceAllowJs: this.appConfig.type === 'next.js',
191
203
  updateOnly: this.options.updateOnly,
192
204
  resolveJsonModule: true,
205
+ onlyLatestLTS: true,
193
206
  baseUrl: (() => {
194
207
  if (
195
208
  this.appConfig.type === 'alp' ||
@@ -204,21 +217,34 @@ export default class PobAppGenerator extends Generator {
204
217
  }
205
218
  return '';
206
219
  })(),
220
+ plugins: (() => {
221
+ if (this.appConfig.type === 'next.js') {
222
+ return 'next';
223
+ }
224
+ return '';
225
+ })(),
226
+ additionalIncludes: (() => {
227
+ if (this.appConfig.type === 'next.js') {
228
+ return '.next/types/**/*.ts';
229
+ }
230
+ return '';
231
+ })(),
207
232
  });
208
233
 
209
- this.composeWith('pob:common:remove-old-dependencies');
234
+ await this.composeWith('pob:common:remove-old-dependencies');
210
235
 
211
236
  const enableReleasePlease =
212
237
  !inMonorepo && this.appConfig.testing && this.appConfig.ci;
213
238
 
214
239
  if (this.appConfig.type !== 'remix') {
215
- this.composeWith('pob:common:testing', {
240
+ await this.composeWith('pob:common:testing', {
216
241
  enable: this.appConfig.testing,
217
242
  disableYarnGitCache: this.options.disableYarnGitCache,
218
243
  enableReleasePlease,
219
244
  testing: this.appConfig.testing,
220
- typescript: babel,
221
- build: babel && this.appConfig.type !== 'expo',
245
+ e2eTesting: this.appConfig.e2e ? '.' : '',
246
+ typescript,
247
+ build: typescript && this.appConfig.type !== 'expo',
222
248
  documentation: false,
223
249
  codecov: this.appConfig.codecov,
224
250
  ci: this.appConfig.ci,
@@ -229,11 +255,16 @@ export default class PobAppGenerator extends Generator {
229
255
  srcDirectory,
230
256
  });
231
257
 
232
- this.composeWith('pob:common:format-lint', {
258
+ await this.composeWith('pob:app:e2e-testing', {
259
+ enable: this.appConfig.e2e,
260
+ });
261
+
262
+ await this.composeWith('pob:common:format-lint', {
233
263
  isApp: true,
234
264
  documentation: false,
235
265
  testing: this.appConfig.testing,
236
266
  babel,
267
+ typescript,
237
268
  node,
238
269
  browser,
239
270
  // nextjs now supports src rootAsSrc: this.appConfig.type === 'next.js',
@@ -245,7 +276,7 @@ export default class PobAppGenerator extends Generator {
245
276
  buildDirectory: this.appConfig.type === 'expo' ? '.expo' : 'build',
246
277
  });
247
278
 
248
- this.composeWith('pob:common:release', {
279
+ await this.composeWith('pob:common:release', {
249
280
  enable:
250
281
  !inMonorepo &&
251
282
  this.appConfig.testing &&
@@ -260,12 +291,12 @@ export default class PobAppGenerator extends Generator {
260
291
  });
261
292
  }
262
293
 
263
- this.composeWith('pob:core:vscode', {
294
+ await this.composeWith('pob:core:vscode', {
264
295
  root: !inMonorepo,
265
296
  monorepo: false,
266
297
  packageManager: this.options.packageManager,
267
298
  yarnNodeLinker: this.options.yarnNodeLinker,
268
- typescript: babel,
299
+ typescript,
269
300
  testing: this.appConfig.testing,
270
301
  });
271
302
 
@@ -274,7 +305,7 @@ export default class PobAppGenerator extends Generator {
274
305
  ignorePaths.push('/.env*', '!/.env.example');
275
306
  }
276
307
 
277
- this.composeWith('pob:core:gitignore', {
308
+ await this.composeWith('pob:core:gitignore', {
278
309
  root: !inMonorepo || inMonorepo.root,
279
310
  documentation: false,
280
311
  testing: this.appConfig.testing,
@@ -283,16 +314,16 @@ export default class PobAppGenerator extends Generator {
283
314
  buildInGit: false,
284
315
  });
285
316
 
286
- this.composeWith('pob:core:npm', { enable: false });
317
+ await this.composeWith('pob:core:npm', { enable: false });
287
318
 
288
319
  switch (this.appConfig.type) {
289
320
  case 'next.js':
290
- this.composeWith('pob:app:nextjs', {
321
+ await this.composeWith('pob:app:nextjs', {
291
322
  export: this.appConfig.export,
292
323
  });
293
324
  break;
294
325
  case 'remix':
295
- this.composeWith('pob:app:remix', {});
326
+ await this.composeWith('pob:app:remix', {});
296
327
  break;
297
328
  }
298
329
 
@@ -305,7 +336,7 @@ export default class PobAppGenerator extends Generator {
305
336
  }
306
337
  }
307
338
 
308
- writing() {
339
+ async writing() {
309
340
  // Re-read the content at this point because a composed generator might modify it.
310
341
  const pkg = this.fs.readJSON(this.destinationPath('package.json'));
311
342
 
@@ -319,6 +350,6 @@ export default class PobAppGenerator extends Generator {
319
350
 
320
351
  this.fs.writeJSON(this.destinationPath('package.json'), pkg);
321
352
 
322
- this.composeWith('pob:core:sort-package');
353
+ await this.composeWith('pob:core:sort-package');
323
354
  }
324
355
  }
@@ -0,0 +1,45 @@
1
+ import Generator from 'yeoman-generator';
2
+ import * as packageUtils from '../../../utils/package.js';
3
+ // import * as templateUtils from '../../../utils/templateUtils.js';
4
+ import { writeAndFormatJson } from '../../../utils/writeAndFormat.js';
5
+
6
+ export default class AppE2ETestingGenerator extends Generator {
7
+ constructor(args, opts) {
8
+ super(args, opts);
9
+
10
+ this.option('enable', {
11
+ type: Boolean,
12
+ default: true,
13
+ desc: 'enable e2e testing',
14
+ });
15
+
16
+ this.option('ci', {
17
+ type: Boolean,
18
+ required: true,
19
+ desc: 'ci',
20
+ });
21
+ }
22
+
23
+ writing() {
24
+ const pkg = this.fs.readJSON(this.destinationPath('package.json'));
25
+
26
+ packageUtils.addOrRemoveDevDependencies(pkg, this.options.enable, [
27
+ '@playwright/test',
28
+ ]);
29
+
30
+ packageUtils.addOrRemoveScripts(pkg, this.options.enable, {
31
+ 'test:e2e': 'playwright test',
32
+ });
33
+
34
+ // templateUtils.addOrRemoveTemplate(
35
+ // this.fs,
36
+ // this.options.enable && this.options.ci,
37
+ // this.destinationPath('playwright.config.js'),
38
+ // );
39
+
40
+ if (this.options.enable) {
41
+ }
42
+
43
+ writeAndFormatJson(this.fs, this.destinationPath('package.json'), pkg);
44
+ }
45
+ }
@@ -1,4 +1,3 @@
1
- import fs from 'node:fs';
2
1
  import semver from 'semver';
3
2
  import Generator from 'yeoman-generator';
4
3
  import * as packageUtils from '../../../utils/package.js';
@@ -251,8 +250,10 @@ export default class CommonBabelGenerator extends Generator {
251
250
  delete pkg.pob.withReact;
252
251
  if (newBabelEnvs.length === 0) {
253
252
  delete pkg.pob.babelEnvs;
254
- delete pkg.pob.entries;
255
- delete pkg.pob.jsx;
253
+ if (!pkg.pob.typescript) {
254
+ delete pkg.pob.entries;
255
+ delete pkg.pob.jsx;
256
+ }
256
257
  } else {
257
258
  pkg.pob.babelEnvs = newBabelEnvs;
258
259
  pkg.pob.entries = pkg.pob.entries || ['index'];
@@ -271,10 +272,6 @@ export default class CommonBabelGenerator extends Generator {
271
272
  this.entries = pkg.pob.entries;
272
273
  this.babelEnvs = pkg.pob.babelEnvs || [];
273
274
 
274
- if (this.babelEnvs.length > 0) {
275
- fs.mkdirSync(this.destinationPath('src'), { recursive: true });
276
- }
277
-
278
275
  if (this.entries) {
279
276
  this.entries.forEach((entry) => {
280
277
  const entryDestPath = this.destinationPath(`${entry}.js`);
@@ -300,70 +297,16 @@ export default class CommonBabelGenerator extends Generator {
300
297
  }
301
298
 
302
299
  default() {
303
- const useBabel = this.babelEnvs && this.babelEnvs.length > 0;
304
300
  const pkg = this.fs.readJSON(this.destinationPath('package.json'));
305
- const hasTargetNode = this.babelEnvs.find((env) => env.target === 'node');
301
+ const useBabel = this.babelEnvs && this.babelEnvs.length > 0;
302
+ const useTypescript = useBabel || pkg.pob?.typescript;
303
+ const hasTargetNode = useBabel
304
+ ? this.babelEnvs.find((env) => env.target === 'node')
305
+ : useTypescript; // todo pkg.pob.typescriptTargets
306
306
  const hasTargetBrowser = this.babelEnvs.find(
307
307
  (env) => env.target === 'browser',
308
308
  );
309
309
 
310
- /* scripts */
311
-
312
- if (this.options.isApp) {
313
- packageUtils.removeScripts(['watch']);
314
- packageUtils.addOrRemoveScripts(pkg, useBabel, {
315
- 'clean:build': `pob-babel-clean-out ${this.options.buildDirectory}`,
316
- build: 'yarn clean:build && rollup --config rollup.config.mjs',
317
- start: 'yarn clean:build && rollup --config rollup.config.mjs --watch',
318
- clean: 'yarn clean:build',
319
- });
320
- } else {
321
- packageUtils.removeScripts(['start']);
322
- packageUtils.addScripts(pkg, {
323
- 'clean:build': useBabel
324
- ? `pob-babel-clean-out ${this.options.buildDirectory}`
325
- : 'true',
326
- });
327
- packageUtils.addOrRemoveScripts(pkg, useBabel, {
328
- build: 'yarn clean:build && rollup --config rollup.config.mjs',
329
- watch: 'yarn clean:build && rollup --config rollup.config.mjs --watch',
330
- clean: 'yarn clean:build',
331
- });
332
- }
333
-
334
- const shouldBuildDefinitions = !this.options.isApp && useBabel;
335
- packageUtils.addOrRemoveScripts(pkg, shouldBuildDefinitions, {
336
- 'build:definitions': 'tsc -p tsconfig.json',
337
- });
338
-
339
- if (shouldBuildDefinitions) {
340
- pkg.scripts.build += ' && yarn run build:definitions';
341
- } else if (!this.options.isApp && !useBabel) {
342
- // check definitions, but also force lerna to execute build:definitions in right order
343
- // example: nightingale-types depends on nightingale-levels
344
- if (this.fs.exists(this.destinationPath('lib/index.d.ts'))) {
345
- packageUtils.addScripts(pkg, {
346
- 'build:definitions':
347
- 'tsc --lib esnext --noEmit --skipLibCheck ./lib/index.d.ts',
348
- build: 'yarn run build:definitions',
349
- });
350
- }
351
-
352
- if (this.fs.exists(this.destinationPath('lib/index.ts'))) {
353
- packageUtils.addScripts(pkg, {
354
- 'build:definitions':
355
- 'tsc --lib esnext --noEmit --skipLibCheck ./lib/index.ts',
356
- build: 'yarn run build:definitions',
357
- });
358
- }
359
- }
360
-
361
- if (pkg.scripts) {
362
- delete pkg.scripts.postbuild;
363
- delete pkg.scripts['build:dev'];
364
- delete pkg.scripts['watch:dev'];
365
- }
366
-
367
310
  /* dependencies */
368
311
 
369
312
  packageUtils.addOrRemoveDevDependencies(
@@ -411,11 +354,14 @@ export default class CommonBabelGenerator extends Generator {
411
354
 
412
355
  if (hasTargetNode) {
413
356
  if (!pkg.engines) pkg.engines = {};
414
- const minNodeVersion = Math.min(
415
- ...this.babelEnvs
416
- .filter((env) => env.target === 'node')
417
- .map((env) => env.version),
418
- );
357
+ const minNodeVersion = useBabel
358
+ ? Math.min(
359
+ ...this.babelEnvs
360
+ .filter((env) => env.target === 'node')
361
+ .map((env) => env.version),
362
+ )
363
+ : // eslint-disable-next-line unicorn/no-unreadable-iife
364
+ (() => (this.options.onlyLatestLTS ? '20' : '18'))();
419
365
  switch (String(minNodeVersion)) {
420
366
  case '10':
421
367
  case '12':
@@ -492,245 +438,6 @@ export default class CommonBabelGenerator extends Generator {
492
438
  delete pkg.browserslist;
493
439
  }
494
440
 
495
- /* side effects */
496
-
497
- if (this.options.isApp && !this.options.isAppLibrary) {
498
- delete pkg.sideEffects;
499
- } else if (!('sideEffects' in pkg)) {
500
- pkg.sideEffects = true;
501
- console.warn('Setting pkg.sideEffects to true, as it was not defined');
502
- } else if (pkg.sideEffects) {
503
- console.warn(
504
- "pkg.sideEffects is true, are you sure you can't set it to false ?",
505
- );
506
- }
507
-
508
- /* main / aliases / typing */
509
-
510
- if (this.options.isApp) {
511
- delete pkg.types;
512
- delete pkg.typings;
513
- } else if (pkg.typings) {
514
- if (!pkg.types) pkg.types = pkg.typings;
515
- delete pkg.typings;
516
- }
517
-
518
- // if (!pkg.main || pkg.main.startsWith('./lib/')) {
519
- if (useBabel) {
520
- // see pkg.exports instead.
521
- delete pkg.main;
522
- if (!this.options.isApp) {
523
- pkg.types = `./${this.options.buildDirectory}/definitions/index.d.ts`;
524
- }
525
- } else {
526
- if (!pkg.main) {
527
- pkg.exports = './lib/index.js';
528
- }
529
- if (pkg.type === 'module' && this.fs.exists('./lib/index.cjs')) {
530
- pkg.main = './lib/index.cjs';
531
- } else {
532
- pkg.main = './lib/index.js';
533
- }
534
- if (!this.options.isApp) {
535
- if (this.fs.exists('./lib/index.ts')) {
536
- pkg.types = './lib/index.ts';
537
- } else if (this.fs.exists('./lib/index.d.ts') || pkg.types) {
538
- pkg.types = './lib/index.d.ts';
539
- }
540
- }
541
- if (!pkg.engines) pkg.engines = {};
542
- if (
543
- !pkg.engines.node ||
544
- semver.lt(
545
- semver.minVersion(pkg.engines.node),
546
- // pkg.type === 'commonjs' ? '12.10.0' : '12.20.0',
547
- '14.13.1',
548
- )
549
- ) {
550
- pkg.engines.node = '>=16.0.0';
551
- }
552
- }
553
-
554
- delete pkg['browser-dev'];
555
- delete pkg['module-dev'];
556
-
557
- const esAllBrowserEnv = this.babelEnvs.find(
558
- (env) =>
559
- env.target === 'browser' &&
560
- env.version === undefined &&
561
- (!env.formats || env.formats.includes('es')),
562
- );
563
-
564
- // Legacy "dev" builds
565
- delete pkg['module:browser'];
566
- delete pkg['module:browser-dev'];
567
- delete pkg['module:modern-browsers'];
568
- delete pkg['module:modern-browsers-dev'];
569
- delete pkg['module:node'];
570
- delete pkg['module:node-dev'];
571
-
572
- /* webpack 4 */
573
- if (esAllBrowserEnv) {
574
- pkg.module = `./${this.options.buildDirectory}/index-browser.es.js`;
575
- pkg.browser = `./${this.options.buildDirectory}/index-browser.es.js`;
576
- } else {
577
- delete pkg.module;
578
- delete pkg.browser;
579
- }
580
-
581
- /* webpack 5 and node with ESM support */
582
- if (useBabel) {
583
- pkg.exports = {
584
- './package.json': './package.json',
585
- };
586
-
587
- this.entries.forEach((entry) => {
588
- const isBrowserOnly =
589
- entry === 'browser' &&
590
- (this.babelEnvs.every((env) => env.target === 'browser') ||
591
- (this.entries.length === 2 && this.entries.includes('index')));
592
- const entryDistName = isBrowserOnly ? 'index' : entry;
593
- const exportName = entry === 'index' ? '.' : `./${entry}`;
594
-
595
- const targets = {
596
- types:
597
- pkg.private || this.options.isAppLibrary
598
- ? `./src/${entryDistName}.ts`
599
- : `./${this.options.buildDirectory}/definitions/${entryDistName}.d.ts`,
600
- };
601
-
602
- const defaultNodeEnv = this.babelEnvs.find(
603
- (env) => env.target === 'node',
604
- );
605
- const defaultNodeEnvVersion = defaultNodeEnv && defaultNodeEnv.version;
606
-
607
- this.babelEnvs.forEach(({ target, version, formats }) => {
608
- if (target === 'node' && entry === 'browser') return;
609
-
610
- const exportTarget = {};
611
-
612
- if (target === 'node') {
613
- const cjsExt = pkg.type === 'module' ? 'cjs' : 'cjs.js';
614
- if (!formats || formats.includes('es')) {
615
- exportTarget.import = `./${this.options.buildDirectory}/${entryDistName}-${target}${version}.mjs`;
616
-
617
- if (formats && formats.includes('cjs')) {
618
- exportTarget.require = `./${this.options.buildDirectory}/${entryDistName}-${target}${version}.${cjsExt}`;
619
- }
620
- } else if (formats && formats.includes('cjs')) {
621
- exportTarget.default = `./${this.options.buildDirectory}/${entryDistName}-${target}${version}.${cjsExt}`;
622
- }
623
- // eslint: https://github.com/benmosher/eslint-plugin-import/issues/2132
624
- // jest: https://github.com/facebook/jest/issues/9771
625
- if (!pkg.main && exportName === '.') {
626
- pkg.main =
627
- pkg.type === 'module'
628
- ? exportTarget.import
629
- : exportTarget.default ||
630
- exportTarget.require ||
631
- exportTarget.import;
632
- }
633
- } else if (target === 'browser') {
634
- if (!formats || formats.includes('es')) {
635
- exportTarget.import = `./${
636
- this.options.buildDirectory
637
- }/${entryDistName}-${target}${version || ''}.es.js`;
638
- }
639
-
640
- if (formats && formats.includes('cjs')) {
641
- exportTarget.require = `./${
642
- this.options.buildDirectory
643
- }/index-${target}${version || ''}.cjs.js`;
644
- }
645
- }
646
-
647
- if (
648
- !version ||
649
- (target === 'node' && version === defaultNodeEnvVersion)
650
- ) {
651
- targets[target] = {
652
- ...targets[target],
653
- ...exportTarget,
654
- };
655
- } else {
656
- targets[target] = {
657
- [`${target}:${version}`]: exportTarget,
658
- ...targets[target],
659
- };
660
- }
661
- });
662
-
663
- pkg.exports[exportName] = targets;
664
- });
665
-
666
- if (pkg.pob.extraEntries) {
667
- pkg.pob.extraEntries.forEach((extraEntryConfig) => {
668
- if (typeof extraEntryConfig === 'string') {
669
- extraEntryConfig = {
670
- name: extraEntryConfig,
671
- };
672
- }
673
-
674
- const calcExport = () => {
675
- if (pkg.type === 'module') {
676
- return extraEntryConfig.name.endsWith('.cjs') ||
677
- extraEntryConfig.name.endsWith('.d.ts')
678
- ? `./${extraEntryConfig.name}`
679
- : `./${extraEntryConfig.name}.js`;
680
- }
681
-
682
- return {
683
- import: `./${extraEntryConfig.name}.mjs`,
684
- require: `./${extraEntryConfig.name}.js`,
685
- };
686
- };
687
-
688
- let exportValue = calcExport();
689
-
690
- if (extraEntryConfig.types) {
691
- if (typeof exportValue === 'string') {
692
- exportValue = {
693
- types: `./${extraEntryConfig.types}`,
694
- default: exportValue,
695
- };
696
- } else {
697
- exportValue = {
698
- types: `./${extraEntryConfig.types}`,
699
- ...exportValue,
700
- };
701
- }
702
- }
703
-
704
- pkg.exports[`./${extraEntryConfig.name}`] = exportValue;
705
- });
706
- }
707
- } else if (!pkg.exports) {
708
- console.error('Please setup your package.exports manually.');
709
- } else {
710
- if (typeof pkg.exports === 'string') {
711
- pkg.exports = {
712
- '.': pkg.exports,
713
- };
714
- }
715
- if (!pkg.exports['./package.json']) {
716
- pkg.exports['./package.json'] = './package.json';
717
- }
718
-
719
- if (pkg.types && !pkg.exports['.'].types) {
720
- if (typeof pkg.exports['.'] === 'string') {
721
- pkg.exports['.'] = {
722
- default: pkg.exports['.'],
723
- };
724
- }
725
- pkg.exports['.'] = { types: pkg.types, ...pkg.exports['.'] };
726
- }
727
- }
728
-
729
- Object.keys(pkg).forEach((key) => {
730
- if (!key.startsWith('module:') && !key.startsWith('webpack:')) return;
731
- delete pkg[key];
732
- });
733
-
734
441
  this.fs.writeJSON(this.destinationPath('package.json'), pkg);
735
442
  }
736
443
 
@@ -778,7 +485,7 @@ export default class CommonBabelGenerator extends Generator {
778
485
  },
779
486
  );
780
487
  }
781
- } else {
488
+ } else if (!pkg.pob.typescript && pkg.pob.rollup !== false) {
782
489
  this.fs.delete('rollup.config.mjs');
783
490
  }
784
491