yeoman-environment 4.0.0-beta.2 → 4.0.0-beta.4

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.
@@ -227,6 +227,14 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
227
227
  */
228
228
  alias(match: string | RegExp, value: string): this;
229
229
  alias(value: string): string;
230
+ /**
231
+ * Watch for package.json and queue package manager install task.
232
+ */
233
+ watchForPackageManagerInstall({ cwd, queueTask, installTask, }?: {
234
+ cwd?: string;
235
+ queueTask?: boolean;
236
+ installTask?: (nodePackageManager: string | undefined, defaultTask: () => Promise<boolean>) => void | Promise<void>;
237
+ }): void;
230
238
  /**
231
239
  * Start Environment queue
232
240
  * @param {Object} options - Conflicter options.
@@ -236,10 +244,6 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
236
244
  * Queue environment's commit task.
237
245
  */
238
246
  protected queueCommit(): void;
239
- /**
240
- * Queue environment's package manager install task.
241
- */
242
- protected queuePackageManagerInstall(): void;
243
247
  /**
244
248
  * Registers a specific `generator` to this environment. This generator is stored under
245
249
  * provided namespace, or a default namespace format if none if available.
@@ -85,6 +85,7 @@ const getComposeOptions = (...varargs) => {
85
85
  export function removePropertiesWithNullishValues(object) {
86
86
  return Object.fromEntries(Object.entries(object).filter(([_key, value]) => value !== undefined && value !== null));
87
87
  }
88
+ // eslint-disable-next-line unicorn/prefer-event-target
88
89
  export default class EnvironmentBase extends EventEmitter {
89
90
  cwd;
90
91
  adapter;
@@ -508,6 +509,41 @@ export default class EnvironmentBase extends EventEmitter {
508
509
  return resolved.replace(alias.match, alias.value);
509
510
  }, match);
510
511
  }
512
+ /**
513
+ * Watch for package.json and queue package manager install task.
514
+ */
515
+ watchForPackageManagerInstall({ cwd, queueTask, installTask, } = {}) {
516
+ if (cwd && !installTask) {
517
+ throw new Error(`installTask is required when using a custom cwd`);
518
+ }
519
+ const npmCwd = cwd ?? this.cwd;
520
+ const queueInstallTask = () => {
521
+ this.queueTask('install', async () => {
522
+ if (this.compatibilityMode === 'v4') {
523
+ debug('Running in generator < 5 compatibility. Package manager install is done by the generator.');
524
+ return;
525
+ }
526
+ const { adapter, sharedFs: memFs } = this;
527
+ const { skipInstall, nodePackageManager } = this.options;
528
+ await packageManagerInstallTask({
529
+ adapter,
530
+ memFs,
531
+ packageJsonLocation: npmCwd,
532
+ skipInstall,
533
+ nodePackageManager,
534
+ customInstallTask: installTask ?? this.composedStore.customInstallTask,
535
+ });
536
+ }, { once: `package manager install ${npmCwd}` });
537
+ };
538
+ this.sharedFs.on('change', file => {
539
+ if (file === join(npmCwd, 'package.json')) {
540
+ queueInstallTask();
541
+ }
542
+ });
543
+ if (queueTask) {
544
+ queueInstallTask();
545
+ }
546
+ }
511
547
  /**
512
548
  * Start Environment queue
513
549
  * @param {Object} options - Conflicter options.
@@ -519,7 +555,10 @@ export default class EnvironmentBase extends EventEmitter {
519
555
  this.conflicterOptions = pick(defaults({}, this.options, options), ['force', 'bail', 'ignoreWhitespace', 'dryRun', 'skipYoResolve']);
520
556
  this.conflicterOptions.cwd = this.logCwd;
521
557
  this.queueCommit();
522
- this.queuePackageManagerInstall();
558
+ this.queueTask('install', () => {
559
+ // Postpone watchForPackageManagerInstall to install priority since env's cwd can be changed by generators
560
+ this.watchForPackageManagerInstall({ queueTask: true });
561
+ });
523
562
  /*
524
563
  * Listen to errors and reject if emmited.
525
564
  * Some cases the generator relied at the behavior that the running process
@@ -586,32 +625,6 @@ export default class EnvironmentBase extends EventEmitter {
586
625
  };
587
626
  queueCommit();
588
627
  }
589
- /**
590
- * Queue environment's package manager install task.
591
- */
592
- queuePackageManagerInstall() {
593
- const { adapter, sharedFs: memFs } = this;
594
- const { skipInstall, nodePackageManager } = this.options;
595
- const { customInstallTask } = this.composedStore;
596
- this.queueTask('install', async () => {
597
- if (this.compatibilityMode === 'v4') {
598
- debug('Running in generator < 5 compatibility. Package manager install is done by the generator.');
599
- return;
600
- }
601
- await packageManagerInstallTask({
602
- adapter,
603
- memFs,
604
- packageJsonLocation: this.cwd,
605
- skipInstall,
606
- nodePackageManager,
607
- customInstallTask,
608
- });
609
- memFs.once('change', file => {
610
- if (file === join(this.cwd, 'package.json'))
611
- this.queuePackageManagerInstall();
612
- });
613
- }, { once: 'package manager install' });
614
- }
615
628
  /**
616
629
  * Registers a specific `generator` to this environment. This generator is stored under
617
630
  * provided namespace, or a default namespace format if none if available.
@@ -82,7 +82,7 @@ class FullEnvironment extends EnvironmentBase {
82
82
  out.push(` ${ns}`);
83
83
  }
84
84
  }
85
- return out.join('\n').replace(/:binary:/g, name);
85
+ return out.join('\n').replaceAll(':binary:', name);
86
86
  }
87
87
  /**
88
88
  * @protected
@@ -44,17 +44,17 @@ export const asNamespace = (filepath, { lookups = defaultLookups }) => {
44
44
  // If `ns` contains a lookup dir in its path, remove it.
45
45
  for (const lookup of nsLookups) {
46
46
  // Only match full directory (begin with leading slash or start of input, end with trailing slash)
47
- ns = ns.replace(new RegExp(`(?:/|^)${escapeRegExp(lookup)}(?=/)`, 'g'), '');
47
+ ns = ns.replaceAll(new RegExp(`(?:/|^)${escapeRegExp(lookup)}(?=/)`, 'g'), '');
48
48
  }
49
49
  const folders = ns.split('/');
50
50
  const scope = findLast(folders, folder => folder.startsWith('@'));
51
51
  // Cleanup `ns` from unwanted parts and then normalize slashes to `:`
52
52
  ns = ns
53
- .replace(/\/\//g, '') // Remove double `/`
53
+ .replaceAll('//', '') // Remove double `/`
54
54
  .replace(/(.*generator-)/, '') // Remove before `generator-`
55
55
  .replace(/\/(index|main)$/, '') // Remove `/index` or `/main`
56
56
  .replace(/^\//, '') // Remove leading `/`
57
- .replace(/\/+/g, ':'); // Replace slashes by `:`
57
+ .replaceAll(/\/+/g, ':'); // Replace slashes by `:`
58
58
  if (scope) {
59
59
  ns = `${scope}/${ns}`;
60
60
  }
package/dist/util/util.js CHANGED
@@ -24,7 +24,7 @@ export function splitArgsFromString(argsString) {
24
24
  const quoteSeparatedArgs = argsString.split(/("[^"]*")/).filter(Boolean);
25
25
  for (const arg of quoteSeparatedArgs) {
26
26
  if (arg.includes('"')) {
27
- result.push(arg.replace(/"/g, ''));
27
+ result.push(arg.replaceAll('"', ''));
28
28
  }
29
29
  else {
30
30
  result = result.concat(arg.trim().split(' '));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-environment",
3
- "version": "4.0.0-beta.2",
3
+ "version": "4.0.0-beta.4",
4
4
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
5
5
  "keywords": [
6
6
  "development",
@@ -63,9 +63,9 @@
63
63
  "@yeoman/transform": "^1.2.0",
64
64
  "arrify": "^3.0.0",
65
65
  "chalk": "^5.2.0",
66
- "commander": "^10.0.1",
66
+ "commander": "^11.0.0",
67
67
  "debug": "^4.3.4",
68
- "execa": "^7.1.1",
68
+ "execa": "^8.0.1",
69
69
  "fly-import": "^0.3.0",
70
70
  "globby": "^13.1.4",
71
71
  "grouped-queue": "^2.0.0",
@@ -82,21 +82,20 @@
82
82
  "@types/debug": "^4.1.8",
83
83
  "@types/lodash-es": "^4.17.7",
84
84
  "@types/semver": "^7.5.0",
85
- "c8": "^7.13.0",
86
- "cpy-cli": "^4.2.0",
85
+ "c8": "^8.0.0",
86
+ "cpy-cli": "^5.0.0",
87
87
  "esmocha": "^1.0.1",
88
88
  "fs-extra": "^11.1.1",
89
89
  "inquirer": "^9.2.6",
90
90
  "jsdoc": "^4.0.2",
91
- "prettier": "^2.8.8",
91
+ "prettier": "3.0.3",
92
92
  "prettier-plugin-packagejson": "^2.4.3",
93
93
  "rimraf": "^5.0.0",
94
94
  "sinon": "^15.0.4",
95
95
  "sinon-test": "^3.1.5",
96
96
  "strip-ansi": "^7.0.1",
97
- "tui-jsdoc-template": "^1.2.2",
98
- "typescript": "^5.0.4",
99
- "xo": "0.54.2",
97
+ "typescript": "5.2.2",
98
+ "xo": "0.56.0",
100
99
  "yeoman-assert": "^3.1.1",
101
100
  "yeoman-generator": "^5.9.0",
102
101
  "yeoman-test": "^8.0.0-rc.1"