@nx/js 16.8.0-beta.4 → 16.8.0-beta.6

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 (46) hide show
  1. package/babel.js +7 -8
  2. package/package.json +5 -5
  3. package/src/executors/node/lib/kill-tree.js +42 -45
  4. package/src/executors/node/node.impl.js +190 -189
  5. package/src/executors/swc/swc.impl.js +82 -70
  6. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +7 -4
  7. package/src/executors/tsc/lib/batch/watch.js +42 -49
  8. package/src/executors/tsc/lib/get-task-options.js +8 -6
  9. package/src/executors/tsc/lib/get-tsconfig.js +16 -5
  10. package/src/executors/tsc/lib/normalize-options.js +9 -2
  11. package/src/executors/tsc/lib/typescript-compilation.js +21 -24
  12. package/src/executors/tsc/tsc.batch-impl.js +133 -132
  13. package/src/executors/tsc/tsc.impl.js +54 -50
  14. package/src/executors/verdaccio/verdaccio.impl.js +64 -55
  15. package/src/generators/convert-to-swc/convert-to-swc.js +6 -9
  16. package/src/generators/init/init.js +86 -92
  17. package/src/generators/library/library.js +289 -245
  18. package/src/generators/setup-build/generator.js +119 -123
  19. package/src/generators/setup-verdaccio/generator.js +45 -50
  20. package/src/migrations/update-13-8-5/update-node-executor.js +17 -21
  21. package/src/migrations/update-13-8-5/update-swcrc.js +23 -27
  22. package/src/migrations/update-14-1-5/update-swcrc-path.js +17 -20
  23. package/src/migrations/update-15-8-0/rename-swcrc-config.js +57 -60
  24. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  25. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +19 -24
  26. package/src/plugins/jest/start-local-registry.js +4 -6
  27. package/src/plugins/rollup/type-definitions.js +21 -24
  28. package/src/utils/add-babel-inputs.js +1 -2
  29. package/src/utils/assets/assets.js +1 -2
  30. package/src/utils/assets/copy-assets-handler.js +48 -59
  31. package/src/utils/assets/index.js +20 -23
  32. package/src/utils/buildable-libs-utils.js +9 -13
  33. package/src/utils/find-npm-dependencies.js +9 -11
  34. package/src/utils/generate-globs.js +3 -3
  35. package/src/utils/inline.js +5 -10
  36. package/src/utils/package-json/get-npm-scope.js +2 -2
  37. package/src/utils/package-json/index.js +22 -25
  38. package/src/utils/package-json/update-package-json.js +23 -21
  39. package/src/utils/prettier.js +21 -24
  40. package/src/utils/swc/compile-swc.js +101 -106
  41. package/src/utils/typescript/compile-typescript-files.js +7 -8
  42. package/src/utils/typescript/print-diagnostics.js +13 -16
  43. package/src/utils/typescript/run-type-check.js +62 -59
  44. package/src/utils/typescript/ts-config.js +3 -5
  45. package/src/utils/typescript/tsnode-register.js +1 -1
  46. package/src/utils/watch-for-single-file-changes.js +13 -17
@@ -18,9 +18,9 @@ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, project
18
18
  }
19
19
  const results = {};
20
20
  function collectAll(currentProject, collectedDeps) {
21
- if (seen === null || seen === void 0 ? void 0 : seen.has(currentProject.name))
21
+ if (seen?.has(currentProject.name))
22
22
  return;
23
- seen === null || seen === void 0 ? void 0 : seen.add(currentProject.name);
23
+ seen?.add(currentProject.name);
24
24
  collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, options.ignoredFiles, collectedDeps);
25
25
  collectHelperDependencies(workspaceRoot, currentProject, projectGraph, buildTarget, collectedDeps);
26
26
  if (options.includeTransitiveDependencies) {
@@ -63,7 +63,7 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
63
63
  const target = (0, project_graph_1.fileDataDepTarget)(dep);
64
64
  // If the node is external, then read package info from `data`.
65
65
  const externalDep = projectGraph.externalNodes[target];
66
- if ((externalDep === null || externalDep === void 0 ? void 0 : externalDep.type) === 'npm') {
66
+ if (externalDep?.type === 'npm') {
67
67
  npmDeps[externalDep.data.packageName] = externalDep.data.version;
68
68
  continue;
69
69
  }
@@ -80,9 +80,8 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
80
80
  if (
81
81
  // Check that this is a buildable project, otherwise it cannot be a dependency in package.json.
82
82
  workspaceDep.data.targets[buildTarget] &&
83
- (
84
83
  // Make sure package.json exists and has a valid name.
85
- packageJson === null || packageJson === void 0 ? void 0 : packageJson.name)) {
84
+ packageJson?.name) {
86
85
  // This is a workspace lib so we can't reliably read in a specific version since it depends on how the workspace is set up.
87
86
  // ASSUMPTION: Most users will use '*' for workspace lib versions. Otherwise, they can manually update it.
88
87
  npmDeps[packageJson.name] = '*';
@@ -102,14 +101,13 @@ function readPackageJson(project, workspaceRoot) {
102
101
  return null;
103
102
  }
104
103
  function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, buildTarget, npmDeps) {
105
- var _a, _b, _c, _d;
106
104
  const target = sourceProject.data.targets[buildTarget];
107
105
  if (!target)
108
106
  return;
109
- if (target.executor === '@nx/js:tsc' && ((_a = target.options) === null || _a === void 0 ? void 0 : _a.tsConfig)) {
107
+ if (target.executor === '@nx/js:tsc' && target.options?.tsConfig) {
110
108
  const tsConfig = (0, ts_config_1.readTsConfig)((0, path_1.join)(workspaceRoot, target.options.tsConfig));
111
- if (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.options['importHelpers']) {
112
- npmDeps['tslib'] = (_b = projectGraph.externalNodes['npm:tslib']) === null || _b === void 0 ? void 0 : _b.data.version;
109
+ if (tsConfig?.options['importHelpers']) {
110
+ npmDeps['tslib'] = projectGraph.externalNodes['npm:tslib']?.data.version;
113
111
  }
114
112
  }
115
113
  if (target.executor === '@nx/js:swc') {
@@ -119,9 +117,9 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
119
117
  const swcConfig = (0, fileutils_1.fileExists)(swcConfigPath)
120
118
  ? (0, devkit_1.readJsonFile)(swcConfigPath)
121
119
  : {};
122
- if ((_c = swcConfig === null || swcConfig === void 0 ? void 0 : swcConfig.jsc) === null || _c === void 0 ? void 0 : _c.externalHelpers) {
120
+ if (swcConfig?.jsc?.externalHelpers) {
123
121
  npmDeps['@swc/helpers'] =
124
- (_d = projectGraph.externalNodes['npm:@swc/helpers']) === null || _d === void 0 ? void 0 : _d.data.version;
122
+ projectGraph.externalNodes['npm:@swc/helpers']?.data.version;
125
123
  }
126
124
  }
127
125
  }
@@ -37,7 +37,7 @@ function createGlobPatternsForDependencies(dirPath, fileGlobPattern) {
37
37
  }
38
38
  }
39
39
  catch (e) {
40
- throw new Error(`createGlobPatternsForDependencies: Error when trying to determine main project.\n${e === null || e === void 0 ? void 0 : e.message}`);
40
+ throw new Error(`createGlobPatternsForDependencies: Error when trying to determine main project.\n${e?.message}`);
41
41
  }
42
42
  // generate the glob
43
43
  try {
@@ -47,7 +47,7 @@ function createGlobPatternsForDependencies(dirPath, fileGlobPattern) {
47
47
  const children = (0, fs_1.readdirSync)((0, path_1.resolve)(workspace_root_1.workspaceRoot, dirPath));
48
48
  for (const child of children) {
49
49
  const childPath = (0, path_1.join)(dirPath, child);
50
- if ((ig === null || ig === void 0 ? void 0 : ig.ignores(childPath)) ||
50
+ if (ig?.ignores(childPath) ||
51
51
  !(0, fs_1.lstatSync)((0, path_1.resolve)(workspace_root_1.workspaceRoot, childPath)).isDirectory()) {
52
52
  continue;
53
53
  }
@@ -74,7 +74,7 @@ due to missing "sourceRoot" in the dependencies' project configuration
74
74
  return dirsToUse.map((sourceDir) => (0, path_1.resolve)(workspace_root_1.workspaceRoot, (0, devkit_1.joinPathFragments)(sourceDir, fileGlobPattern)));
75
75
  }
76
76
  catch (e) {
77
- throw new Error(`createGlobPatternsForDependencies: Error when generating globs.\n${e === null || e === void 0 ? void 0 : e.message}`);
77
+ throw new Error(`createGlobPatternsForDependencies: Error when generating globs.\n${e?.message}`);
78
78
  }
79
79
  }
80
80
  exports.createGlobPatternsForDependencies = createGlobPatternsForDependencies;
@@ -10,9 +10,8 @@ function isInlineGraphEmpty(inlineGraph) {
10
10
  }
11
11
  exports.isInlineGraphEmpty = isInlineGraphEmpty;
12
12
  function handleInliningBuild(context, options, tsConfigPath, projectName = context.projectName) {
13
- var _a;
14
13
  const tsConfigJson = (0, devkit_1.readJsonFile)(tsConfigPath);
15
- const pathAliases = ((_a = tsConfigJson['compilerOptions']) === null || _a === void 0 ? void 0 : _a['paths']) || readBasePathAliases(context);
14
+ const pathAliases = tsConfigJson['compilerOptions']?.['paths'] || readBasePathAliases(context);
16
15
  const inlineGraph = createInlineGraph(context, options, pathAliases, projectName);
17
16
  if (isInlineGraphEmpty(inlineGraph)) {
18
17
  return inlineGraph;
@@ -56,8 +55,7 @@ function postProcessInlinedDependencies(outputPath, parentOutputPath, inlineGrap
56
55
  }
57
56
  exports.postProcessInlinedDependencies = postProcessInlinedDependencies;
58
57
  function readBasePathAliases(context) {
59
- var _a;
60
- return (_a = (0, devkit_1.readJsonFile)(getRootTsConfigPath(context))) === null || _a === void 0 ? void 0 : _a['compilerOptions']['paths'];
58
+ return (0, devkit_1.readJsonFile)(getRootTsConfigPath(context))?.['compilerOptions']['paths'];
61
59
  }
62
60
  function getRootTsConfigPath(context) {
63
61
  for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
@@ -82,8 +80,6 @@ function projectNodeToInlineProjectNode(projectNode, pathAlias = '', buildOutput
82
80
  };
83
81
  }
84
82
  function createInlineGraph(context, options, pathAliases, projectName, inlineGraph = emptyInlineGraph()) {
85
- var _a;
86
- var _b;
87
83
  if (options.external == null)
88
84
  return inlineGraph;
89
85
  const projectDependencies = context.projectGraph.dependencies[projectName] || [];
@@ -124,7 +120,7 @@ function createInlineGraph(context, options, pathAliases, projectName, inlineGra
124
120
  !options.external.includes(projectDependency.target)) ||
125
121
  !buildOutputPath;
126
122
  if (shouldInline) {
127
- (_a = (_b = inlineGraph.dependencies)[projectName]) !== null && _a !== void 0 ? _a : (_b[projectName] = []);
123
+ inlineGraph.dependencies[projectName] ??= [];
128
124
  inlineGraph.dependencies[projectName].push(projectDependency.target);
129
125
  }
130
126
  inlineGraph.nodes[projectDependency.target] =
@@ -136,7 +132,7 @@ function createInlineGraph(context, options, pathAliases, projectName, inlineGra
136
132
  return inlineGraph;
137
133
  }
138
134
  function buildInlineGraphExternals(context, inlineProjectGraph, pathAliases) {
139
- const allNodes = Object.assign({}, context.projectGraph.nodes);
135
+ const allNodes = { ...context.projectGraph.nodes };
140
136
  for (const [parent, dependencies] of Object.entries(inlineProjectGraph.dependencies)) {
141
137
  if (allNodes[parent]) {
142
138
  delete allNodes[parent];
@@ -204,8 +200,7 @@ function getPathAliasForPackage(packageNode, pathAliases) {
204
200
  return '';
205
201
  }
206
202
  function getBuildOutputPath(projectName, context, options) {
207
- var _a, _b;
208
- const projectTargets = (_b = (_a = context.projectGraph.nodes[projectName]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.targets;
203
+ const projectTargets = context.projectGraph.nodes[projectName]?.data?.targets;
209
204
  if (!projectTargets)
210
205
  return '';
211
206
  const buildTarget = options.externalBuildTargets.find((buildTarget) => projectTargets[buildTarget]);
@@ -8,13 +8,13 @@ const devkit_1 = require("@nx/devkit");
8
8
  function getNpmScope(tree) {
9
9
  const nxJson = (0, devkit_1.readNxJson)(tree);
10
10
  // TODO(v17): Remove reading this from nx.json
11
- if (nxJson === null || nxJson === void 0 ? void 0 : nxJson.npmScope) {
11
+ if (nxJson?.npmScope) {
12
12
  return nxJson.npmScope;
13
13
  }
14
14
  const { name } = tree.exists('package.json')
15
15
  ? (0, devkit_1.readJson)(tree, 'package.json')
16
16
  : { name: null };
17
- if (name === null || name === void 0 ? void 0 : name.startsWith('@')) {
17
+ if (name?.startsWith('@')) {
18
18
  return name.split('/')[0].substring(1);
19
19
  }
20
20
  }
@@ -1,33 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.copyPackageJson = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const watch_for_single_file_changes_1 = require("../watch-for-single-file-changes");
6
5
  const update_package_json_1 = require("./update-package-json");
7
6
  const check_dependencies_1 = require("../check-dependencies");
8
- function copyPackageJson(_options, context) {
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- if (!context.target.options.tsConfig) {
11
- throw new Error(`Could not find tsConfig option for "${context.targetName}" target of "${context.projectName}" project. Check that your project configuration is correct.`);
12
- }
13
- let { target, dependencies, projectRoot } = (0, check_dependencies_1.checkDependencies)(context, context.target.options.tsConfig);
14
- const options = Object.assign(Object.assign({}, _options), { projectRoot });
15
- if (options.extraDependencies) {
16
- dependencies.push(...options.extraDependencies);
17
- }
18
- if (options.overrideDependencies) {
19
- dependencies = options.overrideDependencies;
20
- }
21
- if (options.watch) {
22
- const dispose = yield (0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)(options, context, target, dependencies));
23
- // Copy it once before changes
24
- (0, update_package_json_1.updatePackageJson)(options, context, target, dependencies);
25
- return { success: true, stop: dispose };
26
- }
27
- else {
28
- (0, update_package_json_1.updatePackageJson)(options, context, target, dependencies);
29
- return { success: true };
30
- }
31
- });
7
+ async function copyPackageJson(_options, context) {
8
+ if (!context.target.options.tsConfig) {
9
+ throw new Error(`Could not find tsConfig option for "${context.targetName}" target of "${context.projectName}" project. Check that your project configuration is correct.`);
10
+ }
11
+ let { target, dependencies, projectRoot } = (0, check_dependencies_1.checkDependencies)(context, context.target.options.tsConfig);
12
+ const options = { ..._options, projectRoot };
13
+ if (options.extraDependencies) {
14
+ dependencies.push(...options.extraDependencies);
15
+ }
16
+ if (options.overrideDependencies) {
17
+ dependencies = options.overrideDependencies;
18
+ }
19
+ if (options.watch) {
20
+ const dispose = await (0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)(options, context, target, dependencies));
21
+ // Copy it once before changes
22
+ (0, update_package_json_1.updatePackageJson)(options, context, target, dependencies);
23
+ return { success: true, stop: dispose };
24
+ }
25
+ else {
26
+ (0, update_package_json_1.updatePackageJson)(options, context, target, dependencies);
27
+ return { success: true };
28
+ }
32
29
  }
33
30
  exports.copyPackageJson = copyPackageJson;
@@ -14,10 +14,9 @@ const fs_1 = require("fs");
14
14
  const nx_deps_cache_1 = require("nx/src/project-graph/nx-deps-cache");
15
15
  const get_main_file_dir_1 = require("../get-main-file-dir");
16
16
  function updatePackageJson(options, context, target, dependencies, fileMap = null) {
17
- var _a;
18
17
  let packageJson;
19
18
  if (fileMap == null) {
20
- fileMap = ((_a = (0, nx_deps_cache_1.readProjectFileMapCache)()) === null || _a === void 0 ? void 0 : _a.projectFileMap) || {};
19
+ fileMap = (0, nx_deps_cache_1.readProjectFileMapCache)()?.projectFileMap || {};
21
20
  }
22
21
  if (options.updateBuildableProjectDepsInPackageJson) {
23
22
  packageJson = (0, create_package_json_1.createPackageJson)(context.projectName, context.projectGraph, {
@@ -53,24 +52,23 @@ exports.updatePackageJson = updatePackageJson;
53
52
  function addMissingDependencies(packageJson, { projectName, targetName, configurationName, root }, dependencies, propType = 'dependencies') {
54
53
  const workspacePackageJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'package.json'));
55
54
  dependencies.forEach((entry) => {
56
- var _a, _b, _c, _d, _e, _f, _g, _h;
57
55
  if ((0, operators_1.isNpmProject)(entry.node)) {
58
56
  const { packageName, version } = entry.node.data;
59
- if (((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a[packageName]) ||
60
- ((_b = packageJson.devDependencies) === null || _b === void 0 ? void 0 : _b[packageName]) ||
61
- ((_c = packageJson.peerDependencies) === null || _c === void 0 ? void 0 : _c[packageName])) {
57
+ if (packageJson.dependencies?.[packageName] ||
58
+ packageJson.devDependencies?.[packageName] ||
59
+ packageJson.peerDependencies?.[packageName]) {
62
60
  return;
63
61
  }
64
- if ((_d = workspacePackageJson.devDependencies) === null || _d === void 0 ? void 0 : _d[packageName]) {
62
+ if (workspacePackageJson.devDependencies?.[packageName]) {
65
63
  return;
66
64
  }
67
- (_e = packageJson[propType]) !== null && _e !== void 0 ? _e : (packageJson[propType] = {});
65
+ packageJson[propType] ??= {};
68
66
  packageJson[propType][packageName] = version;
69
67
  }
70
68
  else {
71
69
  const packageName = entry.name;
72
- if (!((_f = packageJson.dependencies) === null || _f === void 0 ? void 0 : _f[packageName]) &&
73
- !((_g = packageJson.peerDependencies) === null || _g === void 0 ? void 0 : _g[packageName])) {
70
+ if (!packageJson.dependencies?.[packageName] &&
71
+ !packageJson.peerDependencies?.[packageName]) {
74
72
  const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({
75
73
  overrides: {},
76
74
  target: {
@@ -82,7 +80,7 @@ function addMissingDependencies(packageJson, { projectName, targetName, configur
82
80
  const depPackageJsonPath = (0, path_1.join)(root, outputs[0], 'package.json');
83
81
  if ((0, fs_1.existsSync)(depPackageJsonPath)) {
84
82
  const version = (0, devkit_1.readJsonFile)(depPackageJsonPath).version;
85
- (_h = packageJson[propType]) !== null && _h !== void 0 ? _h : (packageJson[propType] = {});
83
+ packageJson[propType] ??= {};
86
84
  packageJson[propType][packageName] = version;
87
85
  }
88
86
  }
@@ -115,22 +113,23 @@ function getExports(options) {
115
113
  }
116
114
  exports.getExports = getExports;
117
115
  function getUpdatedPackageJsonContent(packageJson, options) {
118
- var _a, _b, _c, _d, _e, _f, _g;
119
- var _h;
120
116
  // Default is CJS unless esm is explicitly passed.
121
- const hasCjsFormat = !options.format || ((_a = options.format) === null || _a === void 0 ? void 0 : _a.includes('cjs'));
122
- const hasEsmFormat = (_b = options.format) === null || _b === void 0 ? void 0 : _b.includes('esm');
117
+ const hasCjsFormat = !options.format || options.format?.includes('cjs');
118
+ const hasEsmFormat = options.format?.includes('esm');
123
119
  if (options.generateExportsField) {
124
120
  packageJson.exports =
125
- typeof packageJson.exports === 'string' ? {} : Object.assign({}, packageJson.exports);
121
+ typeof packageJson.exports === 'string' ? {} : { ...packageJson.exports };
126
122
  packageJson.exports['./package.json'] = './package.json';
127
123
  }
128
124
  if (hasEsmFormat) {
129
- const esmExports = getExports(Object.assign(Object.assign({}, options), { fileExt: (_c = options.outputFileExtensionForEsm) !== null && _c !== void 0 ? _c : '.js' }));
125
+ const esmExports = getExports({
126
+ ...options,
127
+ fileExt: options.outputFileExtensionForEsm ?? '.js',
128
+ });
130
129
  packageJson.module = esmExports['.'];
131
130
  if (!hasCjsFormat) {
132
131
  packageJson.type = 'module';
133
- (_d = packageJson.main) !== null && _d !== void 0 ? _d : (packageJson.main = esmExports['.']);
132
+ packageJson.main ??= esmExports['.'];
134
133
  }
135
134
  if (options.generateExportsField) {
136
135
  for (const [exportEntry, filePath] of Object.entries(esmExports)) {
@@ -144,7 +143,10 @@ function getUpdatedPackageJsonContent(packageJson, options) {
144
143
  // Bundlers like rollup and esbuild supports .cjs for CJS and .js for ESM.
145
144
  // Bundlers/Compilers like webpack, tsc, swc do not have different file extensions (unless you use .mts or .cts in source).
146
145
  if (hasCjsFormat) {
147
- const cjsExports = getExports(Object.assign(Object.assign({}, options), { fileExt: (_e = options.outputFileExtensionForCjs) !== null && _e !== void 0 ? _e : '.js' }));
146
+ const cjsExports = getExports({
147
+ ...options,
148
+ fileExt: options.outputFileExtensionForCjs ?? '.js',
149
+ });
148
150
  packageJson.main = cjsExports['.'];
149
151
  if (!hasEsmFormat) {
150
152
  packageJson.type = 'commonjs';
@@ -152,7 +154,7 @@ function getUpdatedPackageJsonContent(packageJson, options) {
152
154
  if (options.generateExportsField) {
153
155
  for (const [exportEntry, filePath] of Object.entries(cjsExports)) {
154
156
  if (hasEsmFormat) {
155
- (_f = (_h = packageJson.exports[exportEntry])['default']) !== null && _f !== void 0 ? _f : (_h['default'] = filePath);
157
+ packageJson.exports[exportEntry]['default'] ??= filePath;
156
158
  }
157
159
  else {
158
160
  packageJson.exports[exportEntry] = filePath;
@@ -164,7 +166,7 @@ function getUpdatedPackageJsonContent(packageJson, options) {
164
166
  const mainFile = (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
165
167
  const relativeMainFileDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(options.main, options.projectRoot);
166
168
  const typingsFile = `${relativeMainFileDir}${mainFile}.d.ts`;
167
- packageJson.types = (_g = packageJson.types) !== null && _g !== void 0 ? _g : typingsFile;
169
+ packageJson.types = packageJson.types ?? typingsFile;
168
170
  }
169
171
  return packageJson;
170
172
  }
@@ -1,37 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveUserExistingPrettierConfig = void 0;
4
- const tslib_1 = require("tslib");
5
4
  let prettier;
6
5
  try {
7
6
  prettier = require('prettier');
8
7
  }
9
- catch (_a) { }
10
- function resolveUserExistingPrettierConfig() {
11
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- if (!prettier) {
8
+ catch { }
9
+ async function resolveUserExistingPrettierConfig() {
10
+ if (!prettier) {
11
+ return null;
12
+ }
13
+ try {
14
+ const filepath = await prettier.resolveConfigFile();
15
+ if (!filepath) {
13
16
  return null;
14
17
  }
15
- try {
16
- const filepath = yield prettier.resolveConfigFile();
17
- if (!filepath) {
18
- return null;
19
- }
20
- const config = yield prettier.resolveConfig(process.cwd(), {
21
- useCache: false,
22
- config: filepath,
23
- });
24
- if (!config) {
25
- return null;
26
- }
27
- return {
28
- sourceFilepath: filepath,
29
- config: config,
30
- };
31
- }
32
- catch (_a) {
18
+ const config = await prettier.resolveConfig(process.cwd(), {
19
+ useCache: false,
20
+ config: filepath,
21
+ });
22
+ if (!config) {
33
23
  return null;
34
24
  }
35
- });
25
+ return {
26
+ sourceFilepath: filepath,
27
+ config: config,
28
+ };
29
+ }
30
+ catch {
31
+ return null;
32
+ }
36
33
  }
37
34
  exports.resolveUserExistingPrettierConfig = resolveUserExistingPrettierConfig;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compileSwcWatch = exports.compileSwc = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const child_process_1 = require("child_process");
7
6
  const fs_extra_1 = require("fs-extra");
@@ -31,117 +30,113 @@ function getTypeCheckOptions(normalizedOptions) {
31
30
  }
32
31
  return typeCheckOptions;
33
32
  }
34
- function compileSwc(context, normalizedOptions, postCompilationCallback) {
35
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
36
- devkit_1.logger.log(`Compiling with SWC for ${context.projectName}...`);
37
- if (normalizedOptions.clean) {
38
- (0, fs_extra_1.removeSync)(normalizedOptions.outputPath);
39
- }
40
- const swcCmdLog = (0, child_process_1.execSync)(getSwcCmd(normalizedOptions.swcCliOptions), {
41
- encoding: 'utf8',
42
- cwd: normalizedOptions.swcCliOptions.swcCwd,
43
- });
44
- devkit_1.logger.log(swcCmdLog.replace(/\n/, ''));
45
- const isCompileSuccess = swcCmdLog.includes('Successfully compiled');
46
- if (normalizedOptions.skipTypeCheck) {
47
- yield postCompilationCallback();
48
- return { success: isCompileSuccess };
49
- }
50
- const { errors, warnings } = yield (0, run_type_check_1.runTypeCheck)(getTypeCheckOptions(normalizedOptions));
51
- const hasErrors = errors.length > 0;
52
- const hasWarnings = warnings.length > 0;
53
- if (hasErrors || hasWarnings) {
54
- yield (0, print_diagnostics_1.printDiagnostics)(errors, warnings);
55
- }
56
- yield postCompilationCallback();
57
- return {
58
- success: !hasErrors && isCompileSuccess,
59
- outfile: normalizedOptions.mainOutputPath,
60
- };
33
+ async function compileSwc(context, normalizedOptions, postCompilationCallback) {
34
+ devkit_1.logger.log(`Compiling with SWC for ${context.projectName}...`);
35
+ if (normalizedOptions.clean) {
36
+ (0, fs_extra_1.removeSync)(normalizedOptions.outputPath);
37
+ }
38
+ const swcCmdLog = (0, child_process_1.execSync)(getSwcCmd(normalizedOptions.swcCliOptions), {
39
+ encoding: 'utf8',
40
+ cwd: normalizedOptions.swcCliOptions.swcCwd,
61
41
  });
42
+ devkit_1.logger.log(swcCmdLog.replace(/\n/, ''));
43
+ const isCompileSuccess = swcCmdLog.includes('Successfully compiled');
44
+ if (normalizedOptions.skipTypeCheck) {
45
+ await postCompilationCallback();
46
+ return { success: isCompileSuccess };
47
+ }
48
+ const { errors, warnings } = await (0, run_type_check_1.runTypeCheck)(getTypeCheckOptions(normalizedOptions));
49
+ const hasErrors = errors.length > 0;
50
+ const hasWarnings = warnings.length > 0;
51
+ if (hasErrors || hasWarnings) {
52
+ await (0, print_diagnostics_1.printDiagnostics)(errors, warnings);
53
+ }
54
+ await postCompilationCallback();
55
+ return {
56
+ success: !hasErrors && isCompileSuccess,
57
+ outfile: normalizedOptions.mainOutputPath,
58
+ };
62
59
  }
63
60
  exports.compileSwc = compileSwc;
64
- function compileSwcWatch(context, normalizedOptions, postCompilationCallback) {
65
- return tslib_1.__asyncGenerator(this, arguments, function* compileSwcWatch_1() {
66
- const getResult = (success) => ({
67
- success,
68
- outfile: normalizedOptions.mainOutputPath,
69
- });
70
- let typeCheckOptions;
71
- let initialPostCompile = true;
72
- if (normalizedOptions.clean) {
73
- (0, fs_extra_1.removeSync)(normalizedOptions.outputPath);
74
- }
75
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.createAsyncIterable)(({ next, done }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
76
- let processOnExit;
77
- let stdoutOnData;
78
- let stderrOnData;
79
- let watcherOnExit;
80
- const swcWatcher = (0, child_process_1.exec)(getSwcCmd(normalizedOptions.swcCliOptions, true), { cwd: normalizedOptions.swcCliOptions.swcCwd });
81
- processOnExit = () => {
82
- swcWatcher.kill();
83
- done();
84
- process.off('SIGINT', processOnExit);
85
- process.off('SIGTERM', processOnExit);
86
- process.off('exit', processOnExit);
87
- };
88
- stdoutOnData = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
89
- process.stdout.write(data);
90
- if (!data.startsWith('Watching')) {
91
- const swcStatus = data.includes('Successfully');
92
- if (initialPostCompile) {
93
- yield postCompilationCallback();
94
- initialPostCompile = false;
95
- }
96
- if (normalizedOptions.skipTypeCheck) {
97
- next(getResult(swcStatus));
98
- return;
99
- }
100
- if (!typeCheckOptions) {
101
- typeCheckOptions = getTypeCheckOptions(normalizedOptions);
102
- }
103
- const delayed = delay(5000);
104
- next(getResult(yield Promise.race([
105
- delayed
106
- .start()
107
- .then(() => ({ tscStatus: false, type: 'timeout' })),
108
- (0, run_type_check_1.runTypeCheck)(typeCheckOptions).then(({ errors, warnings }) => {
109
- const hasErrors = errors.length > 0;
110
- if (hasErrors) {
111
- (0, print_diagnostics_1.printDiagnostics)(errors, warnings);
112
- }
113
- return {
114
- tscStatus: !hasErrors,
115
- type: 'tsc',
116
- };
117
- }),
118
- ]).then(({ type, tscStatus }) => {
119
- if (type === 'tsc') {
120
- delayed.cancel();
121
- return tscStatus && swcStatus;
122
- }
123
- return swcStatus;
124
- })));
61
+ async function* compileSwcWatch(context, normalizedOptions, postCompilationCallback) {
62
+ const getResult = (success) => ({
63
+ success,
64
+ outfile: normalizedOptions.mainOutputPath,
65
+ });
66
+ let typeCheckOptions;
67
+ let initialPostCompile = true;
68
+ if (normalizedOptions.clean) {
69
+ (0, fs_extra_1.removeSync)(normalizedOptions.outputPath);
70
+ }
71
+ return yield* (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
72
+ let processOnExit;
73
+ let stdoutOnData;
74
+ let stderrOnData;
75
+ let watcherOnExit;
76
+ const swcWatcher = (0, child_process_1.exec)(getSwcCmd(normalizedOptions.swcCliOptions, true), { cwd: normalizedOptions.swcCliOptions.swcCwd });
77
+ processOnExit = () => {
78
+ swcWatcher.kill();
79
+ done();
80
+ process.off('SIGINT', processOnExit);
81
+ process.off('SIGTERM', processOnExit);
82
+ process.off('exit', processOnExit);
83
+ };
84
+ stdoutOnData = async (data) => {
85
+ process.stdout.write(data);
86
+ if (!data.startsWith('Watching')) {
87
+ const swcStatus = data.includes('Successfully');
88
+ if (initialPostCompile) {
89
+ await postCompilationCallback();
90
+ initialPostCompile = false;
125
91
  }
126
- });
127
- stderrOnData = (err) => {
128
- process.stderr.write(err);
129
- if (err.includes('Debugger attached.')) {
92
+ if (normalizedOptions.skipTypeCheck) {
93
+ next(getResult(swcStatus));
130
94
  return;
131
95
  }
132
- next(getResult(false));
133
- };
134
- watcherOnExit = () => {
135
- done();
136
- swcWatcher.off('exit', watcherOnExit);
137
- };
138
- swcWatcher.stdout.on('data', stdoutOnData);
139
- swcWatcher.stderr.on('data', stderrOnData);
140
- process.on('SIGINT', processOnExit);
141
- process.on('SIGTERM', processOnExit);
142
- process.on('exit', processOnExit);
143
- swcWatcher.on('exit', watcherOnExit);
144
- }))))));
96
+ if (!typeCheckOptions) {
97
+ typeCheckOptions = getTypeCheckOptions(normalizedOptions);
98
+ }
99
+ const delayed = delay(5000);
100
+ next(getResult(await Promise.race([
101
+ delayed
102
+ .start()
103
+ .then(() => ({ tscStatus: false, type: 'timeout' })),
104
+ (0, run_type_check_1.runTypeCheck)(typeCheckOptions).then(({ errors, warnings }) => {
105
+ const hasErrors = errors.length > 0;
106
+ if (hasErrors) {
107
+ (0, print_diagnostics_1.printDiagnostics)(errors, warnings);
108
+ }
109
+ return {
110
+ tscStatus: !hasErrors,
111
+ type: 'tsc',
112
+ };
113
+ }),
114
+ ]).then(({ type, tscStatus }) => {
115
+ if (type === 'tsc') {
116
+ delayed.cancel();
117
+ return tscStatus && swcStatus;
118
+ }
119
+ return swcStatus;
120
+ })));
121
+ }
122
+ };
123
+ stderrOnData = (err) => {
124
+ process.stderr.write(err);
125
+ if (err.includes('Debugger attached.')) {
126
+ return;
127
+ }
128
+ next(getResult(false));
129
+ };
130
+ watcherOnExit = () => {
131
+ done();
132
+ swcWatcher.off('exit', watcherOnExit);
133
+ };
134
+ swcWatcher.stdout.on('data', stdoutOnData);
135
+ swcWatcher.stderr.on('data', stderrOnData);
136
+ process.on('SIGINT', processOnExit);
137
+ process.on('SIGTERM', processOnExit);
138
+ process.on('exit', processOnExit);
139
+ swcWatcher.on('exit', watcherOnExit);
145
140
  });
146
141
  }
147
142
  exports.compileSwcWatch = compileSwcWatch;