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,73 +1,73 @@
1
- import fs from 'node:fs';
2
- import semver from 'semver';
3
- import Generator from 'yeoman-generator';
4
- import * as packageUtils from '../../../utils/package.js';
5
- import { copyAndFormatTpl } from '../../../utils/writeAndFormat.js';
1
+ import fs from "node:fs";
2
+ import semver from "semver";
3
+ import Generator from "yeoman-generator";
4
+ import * as packageUtils from "../../../utils/package.js";
5
+ import { copyAndFormatTpl } from "../../../utils/writeAndFormat.js";
6
6
 
7
7
  export default class CommonTranspilerGenerator extends Generator {
8
8
  constructor(args, opts) {
9
9
  super(args, opts);
10
10
 
11
- this.option('updateOnly', {
11
+ this.option("updateOnly", {
12
12
  type: Boolean,
13
13
  required: false,
14
14
  default: false,
15
- desc: 'Avoid asking questions',
15
+ desc: "Avoid asking questions",
16
16
  });
17
17
 
18
- this.option('testing', {
18
+ this.option("testing", {
19
19
  type: Boolean,
20
20
  required: false,
21
21
  default: false,
22
- desc: 'Has testing.',
22
+ desc: "Has testing.",
23
23
  });
24
24
 
25
- this.option('fromPob', {
25
+ this.option("fromPob", {
26
26
  type: Boolean,
27
27
  required: false,
28
28
  default: false,
29
29
  });
30
30
 
31
- this.option('isApp', {
31
+ this.option("isApp", {
32
32
  type: Boolean,
33
33
  required: false,
34
34
  default: false,
35
35
  });
36
36
 
37
- this.option('isAppLibrary', {
37
+ this.option("isAppLibrary", {
38
38
  type: Boolean,
39
39
  required: false,
40
40
  default: false,
41
41
  });
42
42
 
43
- this.option('useAppConfig', {
43
+ this.option("useAppConfig", {
44
44
  type: Boolean,
45
45
  required: false,
46
46
  default: false,
47
47
  });
48
48
 
49
- this.option('srcDirectory', {
49
+ this.option("srcDirectory", {
50
50
  type: String,
51
51
  required: false,
52
- default: 'src',
52
+ default: "src",
53
53
  });
54
54
 
55
- this.option('buildDirectory', {
55
+ this.option("buildDirectory", {
56
56
  type: String,
57
57
  required: false,
58
- default: 'dist',
58
+ default: "dist",
59
59
  });
60
60
 
61
- this.option('onlyLatestLTS', {
61
+ this.option("onlyLatestLTS", {
62
62
  type: Boolean,
63
63
  required: false,
64
64
  default: false,
65
- desc: 'only latest lts',
65
+ desc: "only latest lts",
66
66
  });
67
67
  }
68
68
 
69
69
  async prompting() {
70
- const pkg = this.fs.readJSON(this.destinationPath('package.json'));
70
+ const pkg = this.fs.readJSON(this.destinationPath("package.json"));
71
71
 
72
72
  let pobConfig = pkg.pob;
73
73
 
@@ -84,22 +84,22 @@ export default class CommonTranspilerGenerator extends Generator {
84
84
  if (!hasInitialPkgPob || !this.options.updateOnly) {
85
85
  pobConfig = await this.prompt([
86
86
  {
87
- type: 'confirm',
88
- name: 'typescript',
89
- message: 'Enable Typescript ?',
87
+ type: "confirm",
88
+ name: "typescript",
89
+ message: "Enable Typescript ?",
90
90
  default: false,
91
91
  },
92
92
  {
93
- type: 'confirm',
94
- name: 'rollup',
95
- message: 'Enable Rollup ?',
93
+ type: "confirm",
94
+ name: "rollup",
95
+ message: "Enable Rollup ?",
96
96
  default: true,
97
97
  when: ({ typescript }) => !!typescript,
98
98
  },
99
99
  {
100
- type: 'confirm',
101
- name: 'jsx',
102
- message: 'Enable JSX ?',
100
+ type: "confirm",
101
+ name: "jsx",
102
+ message: "Enable JSX ?",
103
103
  when: ({ typescript }) => !!typescript,
104
104
  },
105
105
  ]);
@@ -112,145 +112,145 @@ export default class CommonTranspilerGenerator extends Generator {
112
112
  delete pkg.pob.jsx;
113
113
  }
114
114
 
115
- this.fs.writeJSON(this.destinationPath('package.json'), pkg);
115
+ this.fs.writeJSON(this.destinationPath("package.json"), pkg);
116
116
  }
117
117
 
118
118
  configuring() {
119
- const pkg = this.fs.readJSON(this.destinationPath('package.json'));
119
+ const pkg = this.fs.readJSON(this.destinationPath("package.json"));
120
120
  this.entries = pkg.pob.entries;
121
121
  this.babelEnvs = pkg.pob.babelEnvs || [];
122
122
 
123
123
  if (this.babelEnvs.length > 0 || pkg.pob.typescript) {
124
- fs.mkdirSync(this.destinationPath('src'), { recursive: true });
124
+ fs.mkdirSync(this.destinationPath("src"), { recursive: true });
125
125
  } else {
126
126
  // recursive does not throw if directory already exists
127
- fs.mkdirSync(this.destinationPath('lib'), { recursive: true });
127
+ fs.mkdirSync(this.destinationPath("lib"), { recursive: true });
128
128
  }
129
129
  }
130
130
 
131
131
  default() {
132
- const pkg = this.fs.readJSON(this.destinationPath('package.json'));
132
+ const pkg = this.fs.readJSON(this.destinationPath("package.json"));
133
133
  const withBabel = this.babelEnvs && this.babelEnvs.length > 0;
134
134
  const withTypescript = pkg.pob.typescript || withBabel || !!pkg.pob.bundler;
135
135
  const bundler =
136
136
  withTypescript &&
137
137
  (pkg.pob.rollup === false
138
- ? 'tsc'
138
+ ? "tsc"
139
139
  : pkg.pob.bundler ??
140
- (pkg.pob.typescript ? 'rollup-typescript' : 'rollup'));
140
+ (pkg.pob.typescript ? "rollup-typescript" : "rollup"));
141
141
  this.bundler = bundler;
142
142
 
143
143
  const cleanCommand = (() => {
144
- if (bundler === 'rollup-typescript') return 'pob-typescript-clean-out';
145
- if (bundler === 'rollup-esbuild') return 'pob-esbuild-clean-out';
146
- if (bundler === 'rollup') {
147
- return 'pob-babel-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") {
147
+ return "pob-babel-clean-out";
148
148
  }
149
- if (bundler === 'esbuild') return 'pob-esbuild-clean-out';
149
+ if (bundler === "esbuild") return "pob-esbuild-clean-out";
150
150
  return null;
151
151
  })();
152
152
 
153
153
  /* scripts */
154
154
 
155
155
  if (this.options.isApp) {
156
- packageUtils.removeScripts(['watch']);
157
- packageUtils.addOrRemoveScripts(pkg, bundler && bundler !== 'tsc', {
158
- 'clean:build': `${cleanCommand} ${this.options.buildDirectory}`,
159
- clean: 'yarn clean:build',
156
+ packageUtils.removeScripts(["watch"]);
157
+ packageUtils.addOrRemoveScripts(pkg, bundler && bundler !== "tsc", {
158
+ "clean:build": `${cleanCommand} ${this.options.buildDirectory}`,
159
+ clean: "yarn clean:build",
160
160
  });
161
161
 
162
162
  packageUtils.addOrRemoveScripts(pkg, bundler, {
163
163
  start: (() => {
164
- if (bundler && bundler.startsWith('rollup')) {
165
- return 'yarn clean:build && rollup --config rollup.config.mjs --watch';
164
+ if (bundler && bundler.startsWith("rollup")) {
165
+ return "yarn clean:build && rollup --config rollup.config.mjs --watch";
166
166
  }
167
- if (bundler === 'tsc') return 'tsc --watch';
168
- if (bundler === 'esbuild') return 'pob-esbuild-watch';
167
+ if (bundler === "tsc") return "tsc --watch";
168
+ if (bundler === "esbuild") return "pob-esbuild-watch";
169
169
  })(),
170
170
  });
171
171
  } else {
172
- packageUtils.removeScripts(['start']);
173
- packageUtils.addOrRemoveScripts(pkg, bundler && bundler !== 'tsc', {
174
- 'clean:build': `${cleanCommand} ${this.options.buildDirectory}`,
172
+ packageUtils.removeScripts(["start"]);
173
+ packageUtils.addOrRemoveScripts(pkg, bundler && bundler !== "tsc", {
174
+ "clean:build": `${cleanCommand} ${this.options.buildDirectory}`,
175
175
  });
176
176
  }
177
177
 
178
178
  packageUtils.addOrRemoveScripts(pkg, bundler, {
179
179
  build: (() => {
180
- if (bundler && bundler.startsWith('rollup')) {
181
- return 'yarn clean:build && rollup --config rollup.config.mjs';
180
+ if (bundler && bundler.startsWith("rollup")) {
181
+ return "yarn clean:build && rollup --config rollup.config.mjs";
182
182
  }
183
- if (bundler === 'tsc') return 'tsc';
184
- if (bundler === 'esbuild') return 'pob-esbuild-build';
183
+ if (bundler === "tsc") return "tsc";
184
+ if (bundler === "esbuild") return "pob-esbuild-build";
185
185
  })(),
186
186
  });
187
187
 
188
188
  const shouldBuildDefinitions =
189
- !this.options.isApp && withTypescript && bundler !== 'tsc';
189
+ !this.options.isApp && withTypescript && bundler !== "tsc";
190
190
 
191
191
  packageUtils.addOrRemoveScripts(pkg, shouldBuildDefinitions, {
192
- 'build:definitions': 'tsc -p tsconfig.json',
192
+ "build:definitions": "tsc -p tsconfig.json",
193
193
  });
194
194
 
195
195
  if (shouldBuildDefinitions) {
196
- pkg.scripts.build += ' && yarn run build:definitions';
196
+ pkg.scripts.build += " && yarn run build:definitions";
197
197
  } else if (!this.options.isApp && !bundler && !withTypescript) {
198
198
  // check definitions, but also force lerna to execute build:definitions in right order
199
199
  // example: nightingale-types depends on nightingale-levels
200
- if (this.fs.exists(this.destinationPath('lib/index.d.ts'))) {
200
+ if (this.fs.exists(this.destinationPath("lib/index.d.ts"))) {
201
201
  packageUtils.addScripts(pkg, {
202
- 'build:definitions':
203
- 'tsc --lib esnext --noEmit --skipLibCheck ./lib/index.d.ts',
204
- build: 'yarn run build:definitions',
202
+ "build:definitions":
203
+ "tsc --lib esnext --noEmit --skipLibCheck ./lib/index.d.ts",
204
+ build: "yarn run build:definitions",
205
205
  });
206
206
  }
207
207
 
208
- if (this.fs.exists(this.destinationPath('lib/index.ts'))) {
208
+ if (this.fs.exists(this.destinationPath("lib/index.ts"))) {
209
209
  packageUtils.addScripts(pkg, {
210
- 'build:definitions':
211
- 'tsc --lib esnext --noEmit --skipLibCheck ./lib/index.ts',
212
- build: 'yarn run build:definitions',
210
+ "build:definitions":
211
+ "tsc --lib esnext --noEmit --skipLibCheck ./lib/index.ts",
212
+ build: "yarn run build:definitions",
213
213
  });
214
214
  }
215
215
  }
216
216
 
217
217
  if (pkg.scripts) {
218
218
  delete pkg.scripts.postbuild;
219
- delete pkg.scripts['build:dev'];
220
- delete pkg.scripts['watch:dev'];
219
+ delete pkg.scripts["build:dev"];
220
+ delete pkg.scripts["watch:dev"];
221
221
  }
222
222
 
223
223
  /* dependencies */
224
224
 
225
225
  packageUtils.addOrRemoveDevDependencies(
226
226
  pkg,
227
- bundler === 'rollup-typescript',
228
- ['@pob/rollup-typescript'],
227
+ bundler === "rollup-typescript",
228
+ ["@pob/rollup-typescript"]
229
229
  );
230
230
  packageUtils.addOrRemoveDevDependencies(
231
231
  pkg,
232
- bundler === 'esbuild' && withTypescript,
233
- ['@pob/esbuild'],
232
+ bundler === "esbuild" && withTypescript,
233
+ ["@pob/esbuild"]
234
234
  );
235
235
  packageUtils.addOrRemoveDevDependencies(
236
236
  pkg,
237
- bundler === 'rollup-esbuild' && withTypescript,
238
- ['@pob/rollup-esbuild'],
237
+ bundler === "rollup-esbuild" && withTypescript,
238
+ ["@pob/rollup-esbuild"]
239
239
  );
240
240
  packageUtils.addOrRemoveDependencies(
241
241
  pkg,
242
- (bundler === 'tsc' || bundler === 'rollup-typescript') && withTypescript,
243
- ['tslib'],
244
- '^',
242
+ (bundler === "tsc" || bundler === "rollup-typescript") && withTypescript,
243
+ ["tslib"],
244
+ "^"
245
245
  );
246
246
 
247
247
  packageUtils.addOrRemoveDevDependencies(
248
248
  pkg,
249
- bundler === 'rollup' &&
249
+ bundler === "rollup" &&
250
250
  this.options.isApp &&
251
251
  !this.options.isAppLibrary &&
252
252
  this.options.useAppConfig,
253
- ['alp-rollup-plugin-config'],
253
+ ["alp-rollup-plugin-config"]
254
254
  );
255
255
 
256
256
  /* engines */
@@ -260,12 +260,12 @@ export default class CommonTranspilerGenerator extends Generator {
260
260
 
261
261
  if (this.options.isApp && !this.options.isAppLibrary) {
262
262
  delete pkg.sideEffects;
263
- } else if (!('sideEffects' in pkg)) {
263
+ } else if (!("sideEffects" in pkg)) {
264
264
  pkg.sideEffects = true;
265
- console.warn('Setting pkg.sideEffects to true, as it was not defined');
265
+ console.warn("Setting pkg.sideEffects to true, as it was not defined");
266
266
  } else if (pkg.sideEffects) {
267
267
  console.warn(
268
- "pkg.sideEffects is true, are you sure you can't set it to false ?",
268
+ "pkg.sideEffects is true, are you sure you can't set it to false ?"
269
269
  );
270
270
  }
271
271
 
@@ -286,60 +286,60 @@ export default class CommonTranspilerGenerator extends Generator {
286
286
  if (!this.options.isApp) {
287
287
  pkg.types = `./${
288
288
  this.options.buildDirectory
289
- }/${'definitions/'}index.d.ts`;
289
+ }/${"definitions/"}index.d.ts`;
290
290
  } else if (this.options.isAppLibrary) {
291
291
  pkg.types = `./${this.options.srcDirectory}/index.ts`;
292
292
  }
293
293
  } else {
294
294
  if (!pkg.main) {
295
- pkg.exports = './lib/index.js';
295
+ pkg.exports = "./lib/index.js";
296
296
  }
297
- if (pkg.type === 'module' && this.fs.exists('./lib/index.cjs')) {
298
- pkg.main = './lib/index.cjs';
297
+ if (pkg.type === "module" && this.fs.exists("./lib/index.cjs")) {
298
+ pkg.main = "./lib/index.cjs";
299
299
  } else {
300
- pkg.main = './lib/index.js';
300
+ pkg.main = "./lib/index.js";
301
301
  }
302
302
  if (!this.options.isApp || this.options.isAppLibrary) {
303
- if (this.fs.exists('./lib/index.ts')) {
304
- pkg.types = './lib/index.ts';
305
- } else if (this.fs.exists('./lib/index.d.ts') || pkg.types) {
306
- pkg.types = './lib/index.d.ts';
303
+ if (this.fs.exists("./lib/index.ts")) {
304
+ pkg.types = "./lib/index.ts";
305
+ } else if (this.fs.exists("./lib/index.d.ts") || pkg.types) {
306
+ pkg.types = "./lib/index.d.ts";
307
307
  }
308
308
  }
309
309
  if (!pkg.engines) pkg.engines = {};
310
310
  if (
311
311
  !pkg.engines.node ||
312
- semver.lt(semver.minVersion(pkg.engines.node), '18.0.0')
312
+ semver.lt(semver.minVersion(pkg.engines.node), "18.0.0")
313
313
  ) {
314
- pkg.engines.node = '>=18.0.0';
314
+ pkg.engines.node = ">=18.0.0";
315
315
  }
316
316
  }
317
317
 
318
- delete pkg['browser-dev'];
319
- delete pkg['module-dev'];
318
+ delete pkg["browser-dev"];
319
+ delete pkg["module-dev"];
320
320
 
321
321
  const envs = pkg.pob.babelEnvs ||
322
322
  pkg.pob.envs || [
323
323
  {
324
- target: 'node',
325
- version: '18',
324
+ target: "node",
325
+ version: "18",
326
326
  },
327
327
  ];
328
328
 
329
329
  const esAllBrowserEnv = envs.find(
330
330
  (env) =>
331
- env.target === 'browser' &&
331
+ env.target === "browser" &&
332
332
  env.version === undefined &&
333
- (!env.formats || env.formats.includes('es')),
333
+ (!env.formats || env.formats.includes("es"))
334
334
  );
335
335
 
336
336
  // Legacy "dev" builds
337
- delete pkg['module:browser'];
338
- delete pkg['module:browser-dev'];
339
- delete pkg['module:modern-browsers'];
340
- delete pkg['module:modern-browsers-dev'];
341
- delete pkg['module:node'];
342
- delete pkg['module:node-dev'];
337
+ delete pkg["module:browser"];
338
+ delete pkg["module:browser-dev"];
339
+ delete pkg["module:modern-browsers"];
340
+ delete pkg["module:modern-browsers-dev"];
341
+ delete pkg["module:node"];
342
+ delete pkg["module:node-dev"];
343
343
 
344
344
  /* webpack 4 */
345
345
  if (esAllBrowserEnv) {
@@ -352,85 +352,85 @@ export default class CommonTranspilerGenerator extends Generator {
352
352
 
353
353
  /* webpack 5 and node with ESM support */
354
354
  if (bundler || withTypescript) {
355
- const omitTarget = bundler === 'esbuild';
355
+ const omitTarget = bundler === "esbuild";
356
356
  pkg.exports = {
357
- './package.json': './package.json',
357
+ "./package.json": "./package.json",
358
358
  };
359
359
 
360
360
  this.entries.forEach((entryWithOptionalExt) => {
361
- const entry = entryWithOptionalExt.replace(/\.[jt]sx?$/, '');
361
+ const entry = entryWithOptionalExt.replace(/\.[jt]sx?$/, "");
362
362
  const isBrowserOnly =
363
363
  withBabel &&
364
- entry === 'browser' &&
365
- (envs?.every((env) => env.target === 'browser') ||
366
- (this.entries.length === 2 && this.entries.includes('index')));
367
- const entryDistName = isBrowserOnly ? 'index' : entry;
368
- const exportName = entry === 'index' ? '.' : `./${entry}`;
364
+ entry === "browser" &&
365
+ (envs?.every((env) => env.target === "browser") ||
366
+ (this.entries.length === 2 && this.entries.includes("index")));
367
+ const entryDistName = isBrowserOnly ? "index" : entry;
368
+ const exportName = entry === "index" ? "." : `./${entry}`;
369
369
 
370
370
  const targets = {
371
371
  types:
372
372
  pkg.private || this.options.isAppLibrary
373
373
  ? `./src/${entryDistName}.ts`
374
374
  : `./${this.options.buildDirectory}/${
375
- bundler !== 'tsc' ? 'definitions/' : ''
375
+ bundler !== "tsc" ? "definitions/" : ""
376
376
  }${entryDistName}.d.ts`,
377
377
  };
378
378
 
379
379
  const defaultNodeEnv =
380
380
  withBabel || withTypescript
381
- ? envs.find((env) => env.target === 'node')
381
+ ? envs.find((env) => env.target === "node")
382
382
  : undefined;
383
383
 
384
384
  const defaultNodeEnvVersion = defaultNodeEnv && defaultNodeEnv.version;
385
385
 
386
386
  envs.forEach(({ target, version, formats, omitVersionInFileName }) => {
387
- if (target === 'node' && entry === 'browser') return;
387
+ if (target === "node" && entry === "browser") return;
388
388
 
389
389
  const exportTarget = {};
390
390
 
391
- if (target === 'node') {
392
- const cjsExt = pkg.type === 'module' ? 'cjs' : 'cjs.js';
391
+ if (target === "node") {
392
+ const cjsExt = pkg.type === "module" ? "cjs" : "cjs.js";
393
393
  const filenameWithoutExt = `${entryDistName}${
394
394
  omitTarget
395
- ? ''
396
- : `-${target}${omitVersionInFileName ? '' : version}`
395
+ ? ""
396
+ : `-${target}${omitVersionInFileName ? "" : version}`
397
397
  }`;
398
- if (!formats || formats.includes('es')) {
398
+ if (!formats || formats.includes("es")) {
399
399
  exportTarget.import = `./${this.options.buildDirectory}/${filenameWithoutExt}.mjs`;
400
400
 
401
- if (formats && formats.includes('cjs')) {
401
+ if (formats && formats.includes("cjs")) {
402
402
  exportTarget.require = `./${this.options.buildDirectory}/${filenameWithoutExt}.${cjsExt}`;
403
403
  }
404
- } else if (formats && formats.includes('cjs')) {
404
+ } else if (formats && formats.includes("cjs")) {
405
405
  exportTarget.default = `./${this.options.buildDirectory}/${filenameWithoutExt}.${cjsExt}`;
406
406
  }
407
407
  // eslint: https://github.com/benmosher/eslint-plugin-import/issues/2132
408
408
  // jest: https://github.com/facebook/jest/issues/9771
409
- if (!pkg.main && exportName === '.') {
409
+ if (!pkg.main && exportName === ".") {
410
410
  pkg.main =
411
- pkg.type === 'module'
411
+ pkg.type === "module"
412
412
  ? exportTarget.import
413
413
  : exportTarget.default ||
414
414
  exportTarget.require ||
415
415
  exportTarget.import;
416
416
  }
417
- } else if (target === 'browser') {
418
- if (!formats || formats.includes('es')) {
417
+ } else if (target === "browser") {
418
+ if (!formats || formats.includes("es")) {
419
419
  exportTarget.import = `./${
420
420
  this.options.buildDirectory
421
- }/${entryDistName}-${target}${version || ''}.es.js`;
421
+ }/${entryDistName}-${target}${version || ""}.es.js`;
422
422
  }
423
423
 
424
- if (formats && formats.includes('cjs')) {
424
+ if (formats && formats.includes("cjs")) {
425
425
  exportTarget.require = `./${
426
426
  this.options.buildDirectory
427
- }/index-${target}${version || ''}.cjs.js`;
427
+ }/index-${target}${version || ""}.cjs.js`;
428
428
  }
429
429
  }
430
430
 
431
431
  if (
432
432
  !version ||
433
- (target === 'node' && version === defaultNodeEnvVersion)
433
+ (target === "node" && version === defaultNodeEnvVersion)
434
434
  ) {
435
435
  targets[target] = {
436
436
  ...targets[target],
@@ -449,16 +449,16 @@ export default class CommonTranspilerGenerator extends Generator {
449
449
 
450
450
  if (pkg.pob.extraEntries) {
451
451
  pkg.pob.extraEntries.forEach((extraEntryConfig) => {
452
- if (typeof extraEntryConfig === 'string') {
452
+ if (typeof extraEntryConfig === "string") {
453
453
  extraEntryConfig = {
454
454
  name: extraEntryConfig,
455
455
  };
456
456
  }
457
457
 
458
458
  const calcExport = () => {
459
- if (pkg.type === 'module') {
460
- return extraEntryConfig.name.endsWith('.cjs') ||
461
- extraEntryConfig.name.endsWith('.d.ts')
459
+ if (pkg.type === "module") {
460
+ return extraEntryConfig.name.endsWith(".cjs") ||
461
+ extraEntryConfig.name.endsWith(".d.ts")
462
462
  ? `./${extraEntryConfig.name}`
463
463
  : `./${extraEntryConfig.name}.js`;
464
464
  }
@@ -472,7 +472,7 @@ export default class CommonTranspilerGenerator extends Generator {
472
472
  let exportValue = calcExport();
473
473
 
474
474
  if (extraEntryConfig.types) {
475
- if (typeof exportValue === 'string') {
475
+ if (typeof exportValue === "string") {
476
476
  exportValue = {
477
477
  types: `./${extraEntryConfig.types}`,
478
478
  default: exportValue,
@@ -489,76 +489,76 @@ export default class CommonTranspilerGenerator extends Generator {
489
489
  });
490
490
  }
491
491
  } else if (!pkg.exports) {
492
- console.error('Please setup your package.exports manually.');
492
+ console.error("Please setup your package.exports manually.");
493
493
  } else {
494
- if (typeof pkg.exports === 'string') {
494
+ if (typeof pkg.exports === "string") {
495
495
  pkg.exports = {
496
- '.': pkg.exports,
496
+ ".": pkg.exports,
497
497
  };
498
498
  }
499
- if (!pkg.exports['./package.json']) {
500
- pkg.exports['./package.json'] = './package.json';
499
+ if (!pkg.exports["./package.json"]) {
500
+ pkg.exports["./package.json"] = "./package.json";
501
501
  }
502
502
 
503
- if (pkg.types && !pkg.exports['.'].types) {
504
- if (typeof pkg.exports['.'] === 'string') {
505
- pkg.exports['.'] = {
506
- default: pkg.exports['.'],
503
+ if (pkg.types && !pkg.exports["."].types) {
504
+ if (typeof pkg.exports["."] === "string") {
505
+ pkg.exports["."] = {
506
+ default: pkg.exports["."],
507
507
  };
508
508
  }
509
- pkg.exports['.'] = { types: pkg.types, ...pkg.exports['.'] };
509
+ pkg.exports["."] = { types: pkg.types, ...pkg.exports["."] };
510
510
  }
511
511
  }
512
512
 
513
513
  Object.keys(pkg).forEach((key) => {
514
- if (!key.startsWith('module:') && !key.startsWith('webpack:')) return;
514
+ if (!key.startsWith("module:") && !key.startsWith("webpack:")) return;
515
515
  delete pkg[key];
516
516
  });
517
517
 
518
- this.fs.writeJSON(this.destinationPath('package.json'), pkg);
518
+ this.fs.writeJSON(this.destinationPath("package.json"), pkg);
519
519
  }
520
520
 
521
521
  writing() {
522
- const pkg = this.fs.readJSON(this.destinationPath('package.json'));
523
- const entries = pkg.pob.entries || ['index'];
522
+ const pkg = this.fs.readJSON(this.destinationPath("package.json"));
523
+ const entries = pkg.pob.entries || ["index"];
524
524
 
525
- this.fs.delete('rollup.config.js');
525
+ this.fs.delete("rollup.config.js");
526
526
  if (
527
527
  pkg.pob.typescript &&
528
528
  pkg.pob.rollup !== false &&
529
- (!pkg.pob.bundler || pkg.pob.bundler.startsWith('rollup'))
529
+ (!pkg.pob.bundler || pkg.pob.bundler.startsWith("rollup"))
530
530
  ) {
531
531
  if (this.options.isApp) {
532
532
  copyAndFormatTpl(
533
533
  this.fs,
534
- this.templatePath('app.rollup.config.mjs.ejs'),
535
- this.destinationPath('rollup.config.mjs'),
534
+ this.templatePath("app.rollup.config.mjs.ejs"),
535
+ this.destinationPath("rollup.config.mjs"),
536
536
  {
537
537
  rollupConfigLib: this.bundler,
538
538
  config: this.options.useAppConfig,
539
539
  outDirectory: this.options.buildDirectory,
540
- enableRun: !this.options.isAppLibrary && entries.includes('index'),
541
- },
540
+ enableRun: !this.options.isAppLibrary && entries.includes("index"),
541
+ }
542
542
  );
543
543
  } else {
544
544
  copyAndFormatTpl(
545
545
  this.fs,
546
- this.templatePath('lib.rollup.config.mjs.ejs'),
547
- this.destinationPath('rollup.config.mjs'),
546
+ this.templatePath("lib.rollup.config.mjs.ejs"),
547
+ this.destinationPath("rollup.config.mjs"),
548
548
  {
549
549
  rollupConfigLib: this.bundler,
550
550
  outDirectory: this.options.buildDirectory,
551
- },
551
+ }
552
552
  );
553
553
  }
554
554
  } else if (
555
555
  !pkg.pob.babelEnvs ||
556
556
  pkg.pob.babelEnvs.length === 0 ||
557
- pkg.pob?.bundler === 'esbuild'
557
+ pkg.pob?.bundler === "esbuild"
558
558
  ) {
559
- this.fs.delete('rollup.config.mjs');
559
+ this.fs.delete("rollup.config.mjs");
560
560
  }
561
561
 
562
- this.fs.writeJSON(this.destinationPath('package.json'), pkg);
562
+ this.fs.writeJSON(this.destinationPath("package.json"), pkg);
563
563
  }
564
564
  }