@nx/js 20.0.0-beta.0 → 20.0.0-beta.2

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.
package/generators.json CHANGED
@@ -48,6 +48,11 @@
48
48
  "description": "Synchronize TypeScript project references based on the project graph",
49
49
  "alias": ["sync"],
50
50
  "hidden": true
51
+ },
52
+ "setup-prettier": {
53
+ "factory": "./src/generators/setup-prettier/generator",
54
+ "schema": "./src/generators/setup-prettier/schema.json",
55
+ "description": "Setup Prettier as the formatting tool."
51
56
  }
52
57
  }
53
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "20.0.0-beta.0",
3
+ "version": "20.0.0-beta.2",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -39,8 +39,8 @@
39
39
  "@babel/preset-env": "^7.23.2",
40
40
  "@babel/preset-typescript": "^7.22.5",
41
41
  "@babel/runtime": "^7.22.6",
42
- "@nx/devkit": "20.0.0-beta.0",
43
- "@nx/workspace": "20.0.0-beta.0",
42
+ "@nx/devkit": "20.0.0-beta.2",
43
+ "@nx/workspace": "20.0.0-beta.2",
44
44
  "babel-plugin-const-enum": "^1.0.1",
45
45
  "babel-plugin-macros": "^2.8.0",
46
46
  "babel-plugin-transform-typescript-metadata": "^0.3.1",
@@ -61,7 +61,7 @@
61
61
  "ts-node": "10.9.1",
62
62
  "tsconfig-paths": "^4.1.2",
63
63
  "tslib": "^2.3.0",
64
- "@nrwl/js": "20.0.0-beta.0"
64
+ "@nrwl/js": "20.0.0-beta.2"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "verdaccio": "^5.0.4"
@@ -19,7 +19,9 @@ async function killTree(pid, signal) {
19
19
  };
20
20
  switch (process.platform) {
21
21
  case 'win32':
22
- (0, child_process_1.exec)('taskkill /pid ' + pid + ' /T /F', (error) => {
22
+ (0, child_process_1.exec)('taskkill /pid ' + pid + ' /T /F', {
23
+ windowsHide: true,
24
+ }, (error) => {
23
25
  // Ignore Fatal errors (128) because it might be due to the process already being killed.
24
26
  // On Linux/Mac we can check ESRCH (no such process), but on Windows we can't.
25
27
  callback(error?.code !== 128 ? error : null);
@@ -27,20 +29,18 @@ async function killTree(pid, signal) {
27
29
  break;
28
30
  case 'darwin':
29
31
  buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
30
- return (0, child_process_1.spawn)('pgrep', ['-P', parentPid]);
32
+ return (0, child_process_1.spawn)('pgrep', ['-P', parentPid], {
33
+ windowsHide: true,
34
+ });
31
35
  }, function () {
32
36
  killAll(tree, signal, callback);
33
37
  });
34
38
  break;
35
39
  default: // Linux
36
40
  buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
37
- return (0, child_process_1.spawn)('ps', [
38
- '-o',
39
- 'pid',
40
- '--no-headers',
41
- '--ppid',
42
- parentPid,
43
- ]);
41
+ return (0, child_process_1.spawn)('ps', ['-o', 'pid', '--no-headers', '--ppid', parentPid], {
42
+ windowsHide: true,
43
+ });
44
44
  }, function () {
45
45
  killAll(tree, signal, callback);
46
46
  });
@@ -96,6 +96,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
96
96
  env: processEnv(true),
97
97
  cwd: context.root,
98
98
  stdio: ['ignore', 'pipe', 'pipe'],
99
+ windowsHide: true,
99
100
  });
100
101
  const resultJson = JSON.parse(result.toString());
101
102
  const distTags = resultJson['dist-tags'] || {};
@@ -116,6 +117,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
116
117
  env: processEnv(true),
117
118
  cwd: context.root,
118
119
  stdio: 'ignore',
120
+ windowsHide: true,
119
121
  });
120
122
  console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`);
121
123
  }
@@ -202,6 +204,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
202
204
  env: processEnv(true),
203
205
  cwd: context.root,
204
206
  stdio: ['ignore', 'pipe', 'pipe'],
207
+ windowsHide: true,
205
208
  });
206
209
  /**
207
210
  * We cannot JSON.parse the output directly because if the user is using lifecycle scripts, npm/pnpm will mix its publish output with the JSON output all on stdout.
@@ -113,7 +113,7 @@ function createVerdaccioOptions(options, workspaceRoot) {
113
113
  }
114
114
  function setupNpm(options) {
115
115
  try {
116
- (0, child_process_1.execSync)('npm --version', { env });
116
+ (0, child_process_1.execSync)('npm --version', { env, windowsHide: true });
117
117
  }
118
118
  catch (e) {
119
119
  return () => { };
@@ -124,13 +124,13 @@ function setupNpm(options) {
124
124
  scopes.forEach((scope) => {
125
125
  const registryName = scope ? `${scope}:registry` : 'registry';
126
126
  try {
127
- npmRegistryPaths.push((0, child_process_1.execSync)(`npm config get ${registryName} --location ${options.location}`, { env })
127
+ npmRegistryPaths.push((0, child_process_1.execSync)(`npm config get ${registryName} --location ${options.location}`, { env, windowsHide: true })
128
128
  ?.toString()
129
129
  ?.trim()
130
130
  ?.replace('\u001b[2K\u001b[1G', '') // strip out ansi codes
131
131
  );
132
- (0, child_process_1.execSync)(`npm config set ${registryName} http://localhost:${options.port}/ --location ${options.location}`, { env });
133
- (0, child_process_1.execSync)(`npm config set //localhost:${options.port}/:_authToken="secretVerdaccioToken" --location ${options.location}`, { env });
132
+ (0, child_process_1.execSync)(`npm config set ${registryName} http://localhost:${options.port}/ --location ${options.location}`, { env, windowsHide: true });
133
+ (0, child_process_1.execSync)(`npm config set //localhost:${options.port}/:_authToken="secretVerdaccioToken" --location ${options.location}`, { env, windowsHide: true });
134
134
  devkit_1.logger.info(`Set npm ${registryName} to http://localhost:${options.port}/`);
135
135
  }
136
136
  catch (e) {
@@ -139,7 +139,7 @@ function setupNpm(options) {
139
139
  });
140
140
  return () => {
141
141
  try {
142
- const currentNpmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`, { env })
142
+ const currentNpmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`, { env, windowsHide: true })
143
143
  ?.toString()
144
144
  ?.trim()
145
145
  ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
@@ -147,17 +147,18 @@ function setupNpm(options) {
147
147
  const registryName = scope ? `${scope}:registry` : 'registry';
148
148
  if (npmRegistryPaths[index] &&
149
149
  currentNpmRegistryPath.includes('localhost')) {
150
- (0, child_process_1.execSync)(`npm config set ${registryName} ${npmRegistryPaths[index]} --location ${options.location}`, { env });
150
+ (0, child_process_1.execSync)(`npm config set ${registryName} ${npmRegistryPaths[index]} --location ${options.location}`, { env, windowsHide: true });
151
151
  devkit_1.logger.info(`Reset npm ${registryName} to ${npmRegistryPaths[index]}`);
152
152
  }
153
153
  else {
154
154
  (0, child_process_1.execSync)(`npm config delete ${registryName} --location ${options.location}`, {
155
155
  env,
156
+ windowsHide: true,
156
157
  });
157
158
  devkit_1.logger.info('Cleared custom npm registry');
158
159
  }
159
160
  });
160
- (0, child_process_1.execSync)(`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`, { env });
161
+ (0, child_process_1.execSync)(`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`, { env, windowsHide: true });
161
162
  }
162
163
  catch (e) {
163
164
  throw new Error(`Failed to reset npm registry: ${e.message}`);
@@ -172,16 +173,17 @@ function getYarnUnsafeHttpWhitelist(isYarnV1) {
172
173
  return !isYarnV1
173
174
  ? new Set(JSON.parse((0, child_process_1.execSync)(`yarn config get unsafeHttpWhitelist --json`, {
174
175
  env,
176
+ windowsHide: true,
175
177
  }).toString()))
176
178
  : null;
177
179
  }
178
180
  function setYarnUnsafeHttpWhitelist(currentWhitelist, options) {
179
181
  if (currentWhitelist.size > 0) {
180
- (0, child_process_1.execSync)(`yarn config set unsafeHttpWhitelist --json '${JSON.stringify(Array.from(currentWhitelist))}'` + (options.location === 'user' ? ' --home' : ''), { env });
182
+ (0, child_process_1.execSync)(`yarn config set unsafeHttpWhitelist --json '${JSON.stringify(Array.from(currentWhitelist))}'` + (options.location === 'user' ? ' --home' : ''), { env, windowsHide: true });
181
183
  }
182
184
  else {
183
185
  (0, child_process_1.execSync)(`yarn config unset unsafeHttpWhitelist` +
184
- (options.location === 'user' ? ' --home' : ''), { env });
186
+ (options.location === 'user' ? ' --home' : ''), { env, windowsHide: true });
185
187
  }
186
188
  }
187
189
  function setupYarn(options) {
@@ -190,7 +192,7 @@ function setupYarn(options) {
190
192
  const scopes = ['', ...(options.scopes || [])];
191
193
  try {
192
194
  isYarnV1 =
193
- (0, semver_1.major)((0, child_process_1.execSync)('yarn --version', { env }).toString().trim()) === 1;
195
+ (0, semver_1.major)((0, child_process_1.execSync)('yarn --version', { env, windowsHide: true }).toString().trim()) === 1;
194
196
  }
195
197
  catch {
196
198
  // This would fail if yarn is not installed which is okay
@@ -202,13 +204,14 @@ function setupYarn(options) {
202
204
  const scopeName = scope ? `${scope}:` : '';
203
205
  yarnRegistryPaths.push((0, child_process_1.execSync)(`yarn config get ${scopeName}${registryConfigName}`, {
204
206
  env,
207
+ windowsHide: true,
205
208
  })
206
209
  ?.toString()
207
210
  ?.trim()
208
211
  ?.replace('\u001b[2K\u001b[1G', '') // strip out ansi codes
209
212
  );
210
213
  (0, child_process_1.execSync)(`yarn config set ${scopeName}${registryConfigName} http://localhost:${options.port}/` +
211
- (options.location === 'user' ? ' --home' : ''), { env });
214
+ (options.location === 'user' ? ' --home' : ''), { env, windowsHide: true });
212
215
  devkit_1.logger.info(`Set yarn ${scopeName}registry to http://localhost:${options.port}/`);
213
216
  });
214
217
  const currentWhitelist = getYarnUnsafeHttpWhitelist(isYarnV1);
@@ -221,7 +224,7 @@ function setupYarn(options) {
221
224
  }
222
225
  return () => {
223
226
  try {
224
- const currentYarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`, { env })
227
+ const currentYarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`, { env, windowsHide: true })
225
228
  ?.toString()
226
229
  ?.trim()
227
230
  ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
@@ -232,12 +235,15 @@ function setupYarn(options) {
232
235
  if (yarnRegistryPaths[index] &&
233
236
  currentYarnRegistryPath.includes('localhost')) {
234
237
  (0, child_process_1.execSync)(`yarn config set ${registryName} ${yarnRegistryPaths[index]}` +
235
- (options.location === 'user' ? ' --home' : ''), { env });
238
+ (options.location === 'user' ? ' --home' : ''), {
239
+ env,
240
+ windowsHide: true,
241
+ });
236
242
  devkit_1.logger.info(`Reset yarn ${registryName} to ${yarnRegistryPaths[index]}`);
237
243
  }
238
244
  else {
239
245
  (0, child_process_1.execSync)(`yarn config ${isYarnV1 ? 'delete' : 'unset'} ${registryName}` +
240
- (options.location === 'user' ? ' --home' : ''), { env });
246
+ (options.location === 'user' ? ' --home' : ''), { env, windowsHide: true });
241
247
  devkit_1.logger.info(`Cleared custom yarn ${registryConfigName}`);
242
248
  }
243
249
  });
@@ -5,10 +5,11 @@ exports.initGeneratorInternal = initGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const semver_1 = require("@nx/devkit/src/utils/semver");
7
7
  const package_json_1 = require("nx/src/utils/package-json");
8
+ const path_1 = require("path");
8
9
  const semver_2 = require("semver");
10
+ const prettier_1 = require("../../utils/prettier");
9
11
  const ts_config_1 = require("../../utils/typescript/ts-config");
10
12
  const versions_1 = require("../../utils/versions");
11
- const path_1 = require("path");
12
13
  async function getInstalledTypescriptVersion(tree) {
13
14
  const rootPackageJson = (0, devkit_1.readJson)(tree, 'package.json');
14
15
  const tsVersionInRootPackageJson = rootPackageJson.devDependencies?.['typescript'] ??
@@ -68,60 +69,23 @@ async function initGeneratorInternal(tree, schema) {
68
69
  }
69
70
  }
70
71
  if (schema.setUpPrettier) {
71
- devDependencies['prettier'] = versions_1.prettierVersion;
72
- // https://prettier.io/docs/en/configuration.html
73
- const prettierrcNameOptions = [
74
- '.prettierrc',
75
- '.prettierrc.json',
76
- '.prettierrc.yml',
77
- '.prettierrc.yaml',
78
- '.prettierrc.json5',
79
- '.prettierrc.js',
80
- '.prettierrc.cjs',
81
- '.prettierrc.mjs',
82
- '.prettierrc.toml',
83
- 'prettier.config.js',
84
- 'prettier.config.cjs',
85
- 'prettier.config.mjs',
86
- ];
87
- if (prettierrcNameOptions.every((name) => !tree.exists(name))) {
88
- (0, devkit_1.writeJson)(tree, '.prettierrc', {
89
- singleQuote: true,
90
- });
91
- }
92
- if (!tree.exists(`.prettierignore`)) {
93
- tree.write('.prettierignore', (0, devkit_1.stripIndents) `
94
- # Add files here to ignore them from prettier formatting
95
- /dist
96
- /coverage
97
- /.nx/cache
98
- /.nx/workspace-data
99
- `);
100
- }
101
- }
102
- if (tree.exists('.vscode/extensions.json')) {
103
- (0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
104
- json.recommendations ??= [];
105
- const extension = 'esbenp.prettier-vscode';
106
- if (!json.recommendations.includes(extension)) {
107
- json.recommendations.push(extension);
108
- }
109
- return json;
72
+ const prettierTask = (0, prettier_1.generatePrettierSetup)(tree, {
73
+ skipPackageJson: schema.skipPackageJson,
110
74
  });
75
+ tasks.push(prettierTask);
111
76
  }
112
77
  const installTask = !schema.skipPackageJson
113
78
  ? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions)
114
79
  : () => { };
115
80
  tasks.push(installTask);
116
- if (schema.setUpPrettier) {
117
- (0, devkit_1.ensurePackage)('prettier', versions_1.prettierVersion);
118
- if (!schema.skipFormat)
119
- await (0, devkit_1.formatFiles)(tree);
120
- }
121
- return async () => {
122
- for (const task of tasks) {
123
- await task();
81
+ if (!schema.skipFormat) {
82
+ if (!schema.skipPackageJson) {
83
+ (0, devkit_1.ensurePackage)('prettier', versions_1.prettierVersion);
124
84
  }
125
- };
85
+ // even if skipPackageJson === true, we can safely run formatFiles, prettier might
86
+ // have been installed earlier and if not, the formatFiles function still handles it
87
+ await (0, devkit_1.formatFiles)(tree);
88
+ }
89
+ return (0, devkit_1.runTasksInSerial)(...tasks);
126
90
  }
127
91
  exports.default = initGenerator;
@@ -119,7 +119,9 @@ To fix this you will either need to add a package.json file at that location, or
119
119
  try {
120
120
  // Must be non-blocking async to allow spinner to render
121
121
  currentVersion = await new Promise((resolve, reject) => {
122
- (0, node_child_process_1.exec)(`npm view ${packageName} version --"${registryConfigKey}=${registry}" --tag=${tag}`, (error, stdout, stderr) => {
122
+ (0, node_child_process_1.exec)(`npm view ${packageName} version --"${registryConfigKey}=${registry}" --tag=${tag}`, {
123
+ windowsHide: true,
124
+ }, (error, stdout, stderr) => {
123
125
  if (error) {
124
126
  return reject(error);
125
127
  }
@@ -89,6 +89,7 @@ function execLockFileUpdate(command, cwd, env = {}) {
89
89
  ...process.env,
90
90
  ...env,
91
91
  },
92
+ windowsHide: true,
92
93
  });
93
94
  }
94
95
  catch (e) {
@@ -0,0 +1,4 @@
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
+ import type { GeneratorOptions } from './schema';
3
+ export declare function setupPrettierGenerator(tree: Tree, options: GeneratorOptions): Promise<GeneratorCallback>;
4
+ export default setupPrettierGenerator;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupPrettierGenerator = setupPrettierGenerator;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const prettier_1 = require("../../utils/prettier");
6
+ const versions_1 = require("../../utils/versions");
7
+ async function setupPrettierGenerator(tree, options) {
8
+ const prettierTask = (0, prettier_1.generatePrettierSetup)(tree, {
9
+ skipPackageJson: options.skipPackageJson,
10
+ });
11
+ if (!options.skipFormat) {
12
+ if (!options.skipPackageJson) {
13
+ (0, devkit_1.ensurePackage)('prettier', versions_1.prettierVersion);
14
+ }
15
+ // even if skipPackageJson === true, we can safely run formatFiles, prettier might
16
+ // have been installed earlier and if not, the formatFiles function still handles it
17
+ await (0, devkit_1.formatFiles)(tree);
18
+ }
19
+ return prettierTask;
20
+ }
21
+ exports.default = setupPrettierGenerator;
@@ -0,0 +1,4 @@
1
+ export interface GeneratorOptions {
2
+ skipFormat?: boolean;
3
+ skipPackageJson?: boolean;
4
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxJsSetupPrettier",
4
+ "title": "Setup Prettier",
5
+ "description": "Setup Prettier as the formatting tool.",
6
+ "type": "object",
7
+ "properties": {
8
+ "skipFormat": {
9
+ "description": "Skip formatting files.",
10
+ "type": "boolean",
11
+ "default": false,
12
+ "x-priority": "internal"
13
+ },
14
+ "skipPackageJson": {
15
+ "description": "Do not add dependencies to `package.json`.",
16
+ "type": "boolean",
17
+ "default": false,
18
+ "x-priority": "internal"
19
+ }
20
+ },
21
+ "required": []
22
+ }
@@ -8,8 +8,11 @@ const child_process_1 = require("child_process");
8
8
  async function setupVerdaccio(tree, options) {
9
9
  if (!tree.exists('.verdaccio/config.yml')) {
10
10
  (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files'), '.verdaccio', {
11
- npmUplinkRegistry: (0, child_process_1.execSync)('npm config get registry')?.toString()?.trim() ??
12
- 'https://registry.npmjs.org',
11
+ npmUplinkRegistry: (0, child_process_1.execSync)('npm config get registry', {
12
+ windowsHide: true,
13
+ })
14
+ ?.toString()
15
+ ?.trim() ?? 'https://registry.npmjs.org',
13
16
  });
14
17
  }
15
18
  const verdaccioTarget = {
package/src/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from './utils/package-json/update-package-json';
13
13
  export * from './utils/package-json/create-entry-points';
14
14
  export { libraryGenerator } from './generators/library/library';
15
15
  export { initGenerator } from './generators/init/init';
16
+ export { setupPrettierGenerator } from './generators/setup-prettier/generator';
16
17
  export { setupVerdaccio } from './generators/setup-verdaccio/generator';
17
18
  export { isValidVariable } from './utils/is-valid-variable';
18
19
  export { createLockFile, getLockFileName, } from 'nx/src/plugins/js/lock-file/lock-file';
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPackageJson = exports.getLockFileName = exports.createLockFile = exports.isValidVariable = exports.setupVerdaccio = exports.initGenerator = exports.libraryGenerator = void 0;
3
+ exports.createPackageJson = exports.getLockFileName = exports.createLockFile = exports.isValidVariable = exports.setupVerdaccio = exports.setupPrettierGenerator = exports.initGenerator = exports.libraryGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./utils/typescript/add-tslib-dependencies"), exports);
6
6
  tslib_1.__exportStar(require("./utils/typescript/load-ts-transformers"), exports);
@@ -19,8 +19,10 @@ var library_1 = require("./generators/library/library");
19
19
  Object.defineProperty(exports, "libraryGenerator", { enumerable: true, get: function () { return library_1.libraryGenerator; } });
20
20
  var init_1 = require("./generators/init/init");
21
21
  Object.defineProperty(exports, "initGenerator", { enumerable: true, get: function () { return init_1.initGenerator; } });
22
- var generator_1 = require("./generators/setup-verdaccio/generator");
23
- Object.defineProperty(exports, "setupVerdaccio", { enumerable: true, get: function () { return generator_1.setupVerdaccio; } });
22
+ var generator_1 = require("./generators/setup-prettier/generator");
23
+ Object.defineProperty(exports, "setupPrettierGenerator", { enumerable: true, get: function () { return generator_1.setupPrettierGenerator; } });
24
+ var generator_2 = require("./generators/setup-verdaccio/generator");
25
+ Object.defineProperty(exports, "setupVerdaccio", { enumerable: true, get: function () { return generator_2.setupVerdaccio; } });
24
26
  var is_valid_variable_1 = require("./utils/is-valid-variable");
25
27
  Object.defineProperty(exports, "isValidVariable", { enumerable: true, get: function () { return is_valid_variable_1.isValidVariable; } });
26
28
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
@@ -27,7 +27,9 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorag
27
27
  console.log('Local registry started on port ' + port);
28
28
  const registry = `http://localhost:${port}`;
29
29
  process.env.npm_config_registry = registry;
30
- (0, child_process_1.execSync)(`npm config set //localhost:${port}/:_authToken "secretVerdaccioToken"`);
30
+ (0, child_process_1.execSync)(`npm config set //localhost:${port}/:_authToken "secretVerdaccioToken"`, {
31
+ windowsHide: true,
32
+ });
31
33
  // yarnv1
32
34
  process.env.YARN_REGISTRY = registry;
33
35
  // yarnv2
@@ -36,7 +38,9 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorag
36
38
  console.log('Set npm and yarn config registry to ' + registry);
37
39
  resolve(() => {
38
40
  childProcess.kill();
39
- (0, child_process_1.execSync)(`npm config delete //localhost:${port}/:_authToken`);
41
+ (0, child_process_1.execSync)(`npm config delete //localhost:${port}/:_authToken`, {
42
+ windowsHide: true,
43
+ });
40
44
  });
41
45
  childProcess?.stdout?.off('data', listener);
42
46
  }
@@ -76,7 +76,7 @@ async function getNpmConfigValue(key, cwd) {
76
76
  async function execAsync(command, cwd) {
77
77
  // Must be non-blocking async to allow spinner to render
78
78
  return new Promise((resolve, reject) => {
79
- (0, child_process_1.exec)(command, { cwd }, (error, stdout, stderr) => {
79
+ (0, child_process_1.exec)(command, { cwd, windowsHide: true }, (error, stdout, stderr) => {
80
80
  if (error) {
81
81
  return reject(error);
82
82
  }
@@ -1,6 +1,10 @@
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
1
2
  import type { Options } from 'prettier';
2
3
  export interface ExistingPrettierConfig {
3
4
  sourceFilepath: string;
4
5
  config: Options;
5
6
  }
6
7
  export declare function resolveUserExistingPrettierConfig(): Promise<ExistingPrettierConfig | null>;
8
+ export declare function generatePrettierSetup(tree: Tree, options: {
9
+ skipPackageJson?: boolean;
10
+ }): GeneratorCallback;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveUserExistingPrettierConfig = resolveUserExistingPrettierConfig;
4
- let prettier;
5
- try {
6
- prettier = require('prettier');
7
- }
8
- catch { }
4
+ exports.generatePrettierSetup = generatePrettierSetup;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const versions_1 = require("./versions");
9
7
  async function resolveUserExistingPrettierConfig() {
10
- if (!prettier) {
8
+ let prettier;
9
+ try {
10
+ prettier = require('prettier');
11
+ }
12
+ catch {
11
13
  return null;
12
14
  }
13
15
  try {
@@ -31,3 +33,44 @@ async function resolveUserExistingPrettierConfig() {
31
33
  return null;
32
34
  }
33
35
  }
36
+ function generatePrettierSetup(tree, options) {
37
+ // https://prettier.io/docs/en/configuration.html
38
+ const prettierrcNameOptions = [
39
+ '.prettierrc',
40
+ '.prettierrc.json',
41
+ '.prettierrc.yml',
42
+ '.prettierrc.yaml',
43
+ '.prettierrc.json5',
44
+ '.prettierrc.js',
45
+ '.prettierrc.cjs',
46
+ '.prettierrc.mjs',
47
+ '.prettierrc.toml',
48
+ 'prettier.config.js',
49
+ 'prettier.config.cjs',
50
+ 'prettier.config.mjs',
51
+ ];
52
+ if (prettierrcNameOptions.every((name) => !tree.exists(name))) {
53
+ (0, devkit_1.writeJson)(tree, '.prettierrc', { singleQuote: true });
54
+ }
55
+ if (!tree.exists('.prettierignore')) {
56
+ tree.write('.prettierignore', (0, devkit_1.stripIndents) `# Add files here to ignore them from prettier formatting
57
+ /dist
58
+ /coverage
59
+ /.nx/cache
60
+ /.nx/workspace-data
61
+ `);
62
+ }
63
+ if (tree.exists('.vscode/extensions.json')) {
64
+ (0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
65
+ json.recommendations ??= [];
66
+ const extension = 'esbenp.prettier-vscode';
67
+ if (!json.recommendations.includes(extension)) {
68
+ json.recommendations.push(extension);
69
+ }
70
+ return json;
71
+ });
72
+ }
73
+ return options.skipPackageJson
74
+ ? () => { }
75
+ : (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { prettier: versions_1.prettierVersion });
76
+ }
@@ -62,6 +62,7 @@ async function compileSwc(context, normalizedOptions, postCompilationCallback) {
62
62
  const swcCmdLog = (0, node_child_process_1.execSync)(getSwcCmd(normalizedOptions), {
63
63
  encoding: 'utf8',
64
64
  cwd: normalizedOptions.swcCliOptions.swcCwd,
65
+ windowsHide: true,
65
66
  });
66
67
  devkit_1.logger.log(swcCmdLog.replace(/\n/, ''));
67
68
  const isCompileSuccess = swcCmdLog.includes('Successfully compiled');
@@ -98,6 +99,7 @@ async function* compileSwcWatch(context, normalizedOptions, postCompilationCallb
98
99
  let watcherOnExit;
99
100
  const swcWatcher = (0, node_child_process_1.exec)(getSwcCmd(normalizedOptions, true), {
100
101
  cwd: normalizedOptions.swcCliOptions.swcCwd,
102
+ windowsHide: true,
101
103
  });
102
104
  processOnExit = () => {
103
105
  swcWatcher.kill();