@nx/js 16.6.0-beta.6 → 16.6.0-beta.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "16.6.0-beta.6",
3
+ "version": "16.6.0-beta.8",
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,9 +39,9 @@
39
39
  "@babel/preset-env": "^7.22.9",
40
40
  "@babel/preset-typescript": "^7.22.5",
41
41
  "@babel/runtime": "^7.22.6",
42
- "@nrwl/js": "16.6.0-beta.6",
43
- "@nx/devkit": "16.6.0-beta.6",
44
- "@nx/workspace": "16.6.0-beta.6",
42
+ "@nrwl/js": "16.6.0-beta.8",
43
+ "@nx/devkit": "16.6.0-beta.8",
44
+ "@nx/workspace": "16.6.0-beta.8",
45
45
  "@phenomnomnominal/tsquery": "~5.0.1",
46
46
  "babel-plugin-const-enum": "^1.0.1",
47
47
  "babel-plugin-macros": "^2.8.0",
@@ -71,5 +71,5 @@
71
71
  "access": "public"
72
72
  },
73
73
  "types": "./src/index.d.ts",
74
- "gitHead": "9aad21dbfb2b659e488b6626f59df58ab23c0032"
74
+ "gitHead": "d1d06349e703d903ac47fb7adc7d250ce140d77e"
75
75
  }
@@ -274,21 +274,14 @@ function getFileToRun(context, project, buildOptions, buildTargetExecutor) {
274
274
  return (0, path_1.join)(context.root, buildOptions.outputPath, outputFileName);
275
275
  }
276
276
  function fileToRunCorrectPath(fileToRun) {
277
- if (!(0, fileutils_1.fileExists)(fileToRun)) {
278
- const cjsFile = fileToRun.replace(/\.js$/, '.cjs');
279
- if ((0, fileutils_1.fileExists)(cjsFile)) {
280
- fileToRun = cjsFile;
281
- }
282
- else {
283
- const mjsFile = fileToRun.replace(/\.js$/, '.mjs');
284
- if ((0, fileutils_1.fileExists)(mjsFile)) {
285
- fileToRun = mjsFile;
286
- }
287
- else {
288
- throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);
289
- }
290
- }
277
+ if ((0, fileutils_1.fileExists)(fileToRun))
278
+ return fileToRun;
279
+ const extensionsToTry = ['.cjs', '.mjs', 'cjs.js', '.esm.js'];
280
+ for (const ext of extensionsToTry) {
281
+ const file = fileToRun.replace(/\.js$/, ext);
282
+ if ((0, fileutils_1.fileExists)(file))
283
+ return file;
291
284
  }
292
- return fileToRun;
285
+ throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);
293
286
  }
294
287
  exports.default = nodeExecutor;
@@ -1,6 +1,5 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
- import { NormalizedSwcExecutorOptions, SwcExecutorOptions } from '../../utils/schema';
3
- export declare function normalizeOptions(options: SwcExecutorOptions, contextRoot: string, sourceRoot?: string, projectRoot?: string): NormalizedSwcExecutorOptions;
2
+ import { SwcExecutorOptions } from '../../utils/schema';
4
3
  export declare function swcExecutor(_options: SwcExecutorOptions, context: ExecutorContext): AsyncGenerator<{
5
4
  success: boolean;
6
5
  outfile?: undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.swcExecutor = exports.normalizeOptions = void 0;
3
+ exports.swcExecutor = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const assets_1 = require("../../utils/assets/assets");
6
6
  const fs_extra_1 = require("fs-extra");
@@ -13,8 +13,8 @@ const package_json_1 = require("../../utils/package-json");
13
13
  const compile_swc_1 = require("../../utils/swc/compile-swc");
14
14
  const get_swcrc_path_1 = require("../../utils/swc/get-swcrc-path");
15
15
  const inline_2 = require("../../utils/swc/inline");
16
- function normalizeOptions(options, contextRoot, sourceRoot, projectRoot) {
17
- const outputPath = (0, path_1.join)(contextRoot, options.outputPath);
16
+ function normalizeOptions(options, root, sourceRoot, projectRoot) {
17
+ const outputPath = (0, path_1.join)(root, options.outputPath);
18
18
  if (options.skipTypeCheck == null) {
19
19
  options.skipTypeCheck = false;
20
20
  }
@@ -33,25 +33,20 @@ function normalizeOptions(options, contextRoot, sourceRoot, projectRoot) {
33
33
  options.external = firstItem;
34
34
  }
35
35
  }
36
- const files = (0, assets_1.assetGlobsToFiles)(options.assets, contextRoot, outputPath);
37
- const projectRootParts = projectRoot.split('/');
38
- // We pop the last part of the `projectRoot` to pass
39
- // the last part (projectDir) and the remainder (projectRootParts) to swc
40
- const projectDir = projectRootParts.pop();
41
- // default to current directory if projectRootParts is [].
42
- // Eg: when a project is at the root level, outside of layout dir
43
- const swcCwd = projectRootParts.join('/') || '.';
44
- const swcrcPath = (0, get_swcrc_path_1.getSwcrcPath)(options, contextRoot, projectRoot);
36
+ const files = (0, assets_1.assetGlobsToFiles)(options.assets, root, outputPath);
37
+ const swcrcPath = (0, get_swcrc_path_1.getSwcrcPath)(options, root, projectRoot);
38
+ // TODO(meeroslav): Check why this is needed in order for swc to properly nest folders
39
+ const distParent = outputPath.split('/').slice(0, -1).join('/');
45
40
  const swcCliOptions = {
46
- srcPath: projectDir,
47
- destPath: (0, path_1.relative)((0, path_1.join)(contextRoot, swcCwd), outputPath),
48
- swcCwd,
41
+ srcPath: projectRoot,
42
+ destPath: (0, path_1.relative)(root, distParent),
49
43
  swcrcPath,
50
44
  };
51
- return Object.assign(Object.assign({}, options), { mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')), files, root: contextRoot, sourceRoot,
52
- projectRoot, originalProjectRoot: projectRoot, outputPath, tsConfig: (0, path_1.join)(contextRoot, options.tsConfig), swcCliOptions });
45
+ return Object.assign(Object.assign({}, options), { mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')), files,
46
+ root,
47
+ sourceRoot,
48
+ projectRoot, originalProjectRoot: projectRoot, outputPath, tsConfig: (0, path_1.join)(root, options.tsConfig), swcCliOptions });
53
49
  }
54
- exports.normalizeOptions = normalizeOptions;
55
50
  function swcExecutor(_options, context) {
56
51
  return tslib_1.__asyncGenerator(this, arguments, function* swcExecutor_1() {
57
52
  const { sourceRoot, root } = context.projectsConfigurations.projects[context.projectName];
@@ -67,13 +62,8 @@ function swcExecutor(_options, context) {
67
62
  const inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, options.tsConfig);
68
63
  if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
69
64
  options.projectRoot = '.'; // set to root of workspace to include other libs for type check
70
- // remap paths for SWC compilation
71
- options.swcCliOptions.srcPath = options.swcCliOptions.swcCwd;
72
- options.swcCliOptions.swcCwd = '.';
73
- options.swcCliOptions.destPath = options.swcCliOptions.destPath
74
- .split('../')
75
- .at(-1)
76
- .concat('/', options.swcCliOptions.srcPath);
65
+ options.swcCliOptions.srcPath = root.split('/').slice(0, -1).join('/'); // set to root of libraries to include other libs
66
+ options.swcCliOptions.destPath = (0, path_1.join)(_options.outputPath, options.swcCliOptions.srcPath); // new destPath is dist/{libs}/{parentLib}/{libs}
77
67
  // tmp swcrc with dependencies to exclude
78
68
  // - buildable libraries
79
69
  // - other libraries that are not dependent on the current project
@@ -23,7 +23,7 @@ function processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOp
23
23
  if (!tsConfig) {
24
24
  continue;
25
25
  }
26
- let taskOptions = (_a = tasksOptions[taskName]) !== null && _a !== void 0 ? _a : (0, get_task_options_1.getTaskWithTscExecutorOptions)(taskName, context);
26
+ let taskOptions = (_a = tasksOptions[taskName]) !== null && _a !== void 0 ? _a : (0, get_task_options_1.getTaskOptions)(taskName, context);
27
27
  if (taskOptions) {
28
28
  const taskInfo = createTaskInfo(taskName, taskOptions, context, tsConfig);
29
29
  const tsConfigPath = (0, path_1.join)(context.root, (0, path_1.relative)(context.root, taskOptions.tsConfig)).replace(/\\/g, '/');
@@ -1,8 +1,3 @@
1
1
  import type { ExecutorContext } from '@nx/devkit';
2
2
  import type { NormalizedExecutorOptions } from '../../../utils/schema';
3
- export declare function getTaskOptions(taskName: string, context: ExecutorContext): NormalizedExecutorOptions | {
4
- tsConfig: string | null;
5
- rootDir: string;
6
- outputPath: string;
7
- };
8
- export declare function getTaskWithTscExecutorOptions(taskName: string, context: ExecutorContext): NormalizedExecutorOptions | null;
3
+ export declare function getTaskOptions(taskName: string, context: ExecutorContext): NormalizedExecutorOptions | null;
@@ -1,28 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTaskWithTscExecutorOptions = exports.getTaskOptions = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const path_1 = require("path");
3
+ exports.getTaskOptions = void 0;
6
4
  const normalize_options_1 = require("./normalize-options");
7
- function getTaskOptions(taskName, context) {
8
- const result = getTaskWithTscExecutorOptions(taskName, context);
9
- if (result) {
10
- return result;
11
- }
12
- const { taskOptions, root, projectNode, target } = parseTaskInfo(taskName, context);
13
- const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({ overrides: context.taskGraph.tasks[taskName].overrides, target }, projectNode);
14
- const outputPath = outputs.length
15
- ? (0, path_1.join)(context.root, outputs[0])
16
- : (0, path_1.join)(context.root, 'dist', root);
17
- const rootDir = (0, path_1.join)(context.root, root);
18
- const tsConfig = taskOptions.tsConfig
19
- ? (0, path_1.join)(context.root, taskOptions.tsConfig)
20
- : null;
21
- return { tsConfig, rootDir, outputPath };
22
- }
23
- exports.getTaskOptions = getTaskOptions;
24
5
  const tasksOptionsCache = new Map();
25
- function getTaskWithTscExecutorOptions(taskName, context) {
6
+ function getTaskOptions(taskName, context) {
26
7
  if (tasksOptionsCache.has(taskName)) {
27
8
  return tasksOptionsCache.get(taskName);
28
9
  }
@@ -37,7 +18,7 @@ function getTaskWithTscExecutorOptions(taskName, context) {
37
18
  return null;
38
19
  }
39
20
  }
40
- exports.getTaskWithTscExecutorOptions = getTaskWithTscExecutorOptions;
21
+ exports.getTaskOptions = getTaskOptions;
41
22
  function parseTaskInfo(taskName, context) {
42
23
  var _a, _b;
43
24
  const target = context.taskGraph.tasks[taskName].target;
@@ -1,4 +1,4 @@
1
- import { ExecutorContext } from '@nx/devkit';
1
+ import { type ExecutorContext } from '@nx/devkit';
2
2
  import type { NormalizedExecutorOptions } from '../../../utils/schema';
3
3
  import type { TypescriptInMemoryTsConfig } from './typescript-compilation';
4
4
  export declare function getProcessedTaskTsConfigs(tasks: string[], tasksOptions: Record<string, NormalizedExecutorOptions>, context: ExecutorContext): Record<string, TypescriptInMemoryTsConfig>;
@@ -2,112 +2,62 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getProcessedTaskTsConfigs = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const fileutils_1 = require("nx/src/utils/fileutils");
6
5
  const path_1 = require("path");
7
- const buildable_libs_utils_1 = require("../../../utils/buildable-libs-utils");
8
6
  const get_task_options_1 = require("./get-task-options");
9
7
  function getProcessedTaskTsConfigs(tasks, tasksOptions, context) {
10
8
  const taskInMemoryTsConfigMap = {};
11
9
  for (const task of tasks) {
12
- generateTaskTsConfigOrGetDependentBuildableProjectNode(task, tasksOptions, context, taskInMemoryTsConfigMap);
10
+ generateTaskProjectTsConfig(task, tasksOptions, context, taskInMemoryTsConfigMap);
13
11
  }
14
12
  return taskInMemoryTsConfigMap;
15
13
  }
16
14
  exports.getProcessedTaskTsConfigs = getProcessedTaskTsConfigs;
17
- const taskTsConfigGenerationCache = new Map();
18
- function generateTaskTsConfigOrGetDependentBuildableProjectNode(task, tasksOptions, context, taskInMemoryTsConfigMap) {
19
- var _a, _b, _c;
20
- if (taskTsConfigGenerationCache.has(task)) {
21
- return taskTsConfigGenerationCache.get(task);
22
- }
23
- let tsConfig = (_b = (_a = tasksOptions[task]) === null || _a === void 0 ? void 0 : _a.tsConfig) !== null && _b !== void 0 ? _b : (0, get_task_options_1.getTaskOptions)(task, context).tsConfig;
24
- let taskWithTsConfig = task;
25
- if (!tsConfig) {
26
- // check if other tasks in the task graph from the same project has a tsConfig
27
- const otherTasksInProject = getDependencyTasksInSameProject(task, context);
28
- const taskTsConfig = findTaskWithTsConfig(otherTasksInProject, context);
29
- if (taskTsConfig) {
30
- if (taskTsConfigGenerationCache.has(taskTsConfig.tsConfig)) {
31
- return taskTsConfigGenerationCache.get(taskTsConfig.tsConfig);
32
- }
33
- tsConfig = taskTsConfig.tsConfig;
34
- taskWithTsConfig = taskTsConfig.task;
35
- }
36
- }
37
- if (tsConfig) {
38
- const { projectReferences, dependentBuildableProjectNodes } = collectDependenciesFromTask(task, tasksOptions, context, taskInMemoryTsConfigMap);
39
- taskInMemoryTsConfigMap[taskWithTsConfig] = getInMemoryTsConfig(tsConfig, (_c = tasksOptions[taskWithTsConfig]) !== null && _c !== void 0 ? _c : (0, get_task_options_1.getTaskOptions)(taskWithTsConfig, context), projectReferences, dependentBuildableProjectNodes);
40
- const result = { tsConfig };
41
- taskTsConfigGenerationCache.set(task, result);
42
- return result;
43
- }
44
- // there's no tsConfig, return a buildable project node so the path mapping
45
- // is remapped to the output
46
- const result = taskToDependentBuildableProjectNode(task, context);
47
- taskTsConfigGenerationCache.set(task, result);
48
- return result;
49
- }
50
- const projectDependenciesCache = new Map();
51
- function collectDependenciesFromTask(task, tasksOptions, context, taskInMemoryTsConfigMap) {
15
+ const projectTsConfigCache = new Map();
16
+ function generateTaskProjectTsConfig(task, tasksOptions, context, taskInMemoryTsConfigMap) {
52
17
  var _a;
53
- const { project: taskProject } = (0, devkit_1.parseTargetString)(task, context.projectGraph);
54
- if (projectDependenciesCache.has(taskProject)) {
55
- return projectDependenciesCache.get(taskProject);
18
+ const { project } = (0, devkit_1.parseTargetString)(task, context.projectGraph);
19
+ if (projectTsConfigCache.has(project)) {
20
+ const { tsConfig, tsConfigPath } = projectTsConfigCache.get(project);
21
+ taskInMemoryTsConfigMap[task] = tsConfig;
22
+ return tsConfigPath;
56
23
  }
57
- const dependentBuildableProjectNodes = [];
58
- const projectReferences = new Set();
59
- const allProjectTasks = [
24
+ const tasksInProject = [
60
25
  task,
61
26
  ...getDependencyTasksInSameProject(task, context),
62
27
  ];
63
- for (const projectTask of allProjectTasks) {
64
- for (const depTask of (_a = context.taskGraph.dependencies[projectTask]) !== null && _a !== void 0 ? _a : []) {
65
- if (task === depTask) {
66
- continue;
67
- }
68
- const { project: depTaskProject } = (0, devkit_1.parseTargetString)(depTask, context.projectGraph);
69
- if (depTaskProject === taskProject) {
70
- // recursively collect dependencies for tasks in the same project
71
- const result = collectDependenciesFromTask(depTask, tasksOptions, context, taskInMemoryTsConfigMap);
72
- result.projectReferences.forEach((pr) => {
73
- projectReferences.add(pr);
74
- });
75
- result.dependentBuildableProjectNodes.forEach((node) => {
76
- dependentBuildableProjectNodes.push(node);
77
- });
78
- }
79
- else {
80
- // task is from a different project, get its project reference or buildable node
81
- const result = generateTaskTsConfigOrGetDependentBuildableProjectNode(depTask, tasksOptions, context, taskInMemoryTsConfigMap);
82
- if ('tsConfig' in result) {
83
- projectReferences.add(result.tsConfig);
84
- }
85
- else {
86
- dependentBuildableProjectNodes.push(result);
87
- }
88
- }
28
+ const taskWithTscExecutor = tasksInProject.find((t) => hasTscExecutor(t, context));
29
+ if (!taskWithTscExecutor) {
30
+ throw new Error((0, devkit_1.stripIndents) `The "@nx/js:tsc" batch executor requires all dependencies to use the "@nx/js:tsc" executor.
31
+ None of the following tasks in the "${project}" project use the "@nx/js:tsc" executor:
32
+ ${tasksInProject.map((t) => `- ${t}`).join('\n')}`);
33
+ }
34
+ const projectReferences = [];
35
+ for (const task of tasksInProject) {
36
+ for (const depTask of getDependencyTasksInOtherProjects(task, project, context)) {
37
+ const tsConfigPath = generateTaskProjectTsConfig(depTask, tasksOptions, context, taskInMemoryTsConfigMap);
38
+ projectReferences.push(tsConfigPath);
89
39
  }
90
40
  }
91
- projectDependenciesCache.set(taskProject, {
92
- projectReferences: Array.from(projectReferences),
93
- dependentBuildableProjectNodes,
41
+ const taskOptions = (_a = tasksOptions[taskWithTscExecutor]) !== null && _a !== void 0 ? _a : (0, get_task_options_1.getTaskOptions)(taskWithTscExecutor, context);
42
+ const tsConfigPath = taskOptions.tsConfig;
43
+ taskInMemoryTsConfigMap[taskWithTscExecutor] = getInMemoryTsConfig(tsConfigPath, taskOptions, projectReferences);
44
+ projectTsConfigCache.set(project, {
45
+ tsConfigPath: tsConfigPath,
46
+ tsConfig: taskInMemoryTsConfigMap[taskWithTscExecutor],
94
47
  });
95
- return projectDependenciesCache.get(taskProject);
48
+ return tsConfigPath;
96
49
  }
97
- function taskToDependentBuildableProjectNode(task, context) {
98
- const target = context.taskGraph.tasks[task].target;
99
- const projectGraphNode = context.projectGraph.nodes[target.project];
100
- const libPackageJsonPath = (0, path_1.join)(context.root, projectGraphNode.data.root, 'package.json');
101
- return {
102
- name: (0, fileutils_1.fileExists)(libPackageJsonPath)
103
- ? (0, devkit_1.readJsonFile)(libPackageJsonPath).name
104
- : target.project,
105
- outputs: (0, devkit_1.getOutputsForTargetAndConfiguration)({ overrides: {}, target }, projectGraphNode),
106
- node: projectGraphNode,
107
- };
50
+ function getDependencyTasksInOtherProjects(task, project, context) {
51
+ return context.taskGraph.dependencies[task].filter((t) => t !== task &&
52
+ (0, devkit_1.parseTargetString)(t, context.projectGraph).project !== project);
108
53
  }
109
- function getInMemoryTsConfig(tsConfig, taskOptions, projectReferences, dependentBuildableProjectNodes) {
110
- var _a, _b;
54
+ function getDependencyTasksInSameProject(task, context) {
55
+ const { project: taskProject } = (0, devkit_1.parseTargetString)(task, context.projectGraph);
56
+ return Object.keys(context.taskGraph.tasks).filter((t) => t !== task &&
57
+ (0, devkit_1.parseTargetString)(t, context.projectGraph).project === taskProject);
58
+ }
59
+ function getInMemoryTsConfig(tsConfig, taskOptions, projectReferences) {
60
+ var _a;
111
61
  const originalTsConfig = (0, devkit_1.readJsonFile)(tsConfig, {
112
62
  allowTrailingComma: true,
113
63
  disallowComments: false,
@@ -116,23 +66,12 @@ function getInMemoryTsConfig(tsConfig, taskOptions, projectReferences, dependent
116
66
  .map((r) => r.path)
117
67
  .concat(projectReferences)));
118
68
  return {
119
- content: JSON.stringify(Object.assign(Object.assign({}, originalTsConfig), { compilerOptions: Object.assign(Object.assign({}, originalTsConfig.compilerOptions), { rootDir: taskOptions.rootDir, outDir: taskOptions.outputPath, composite: true, declaration: true, declarationMap: true, tsBuildInfoFile: (0, path_1.join)(taskOptions.outputPath, 'tsconfig.tsbuildinfo'), paths: dependentBuildableProjectNodes.length
120
- ? (0, buildable_libs_utils_1.computeCompilerOptionsPaths)(tsConfig, dependentBuildableProjectNodes)
121
- : (_b = originalTsConfig.compilerOptions) === null || _b === void 0 ? void 0 : _b.paths }), references: allProjectReferences.map((pr) => ({ path: pr })) })),
69
+ content: JSON.stringify(Object.assign(Object.assign({}, originalTsConfig), { compilerOptions: Object.assign(Object.assign({}, originalTsConfig.compilerOptions), { rootDir: taskOptions.rootDir, outDir: taskOptions.outputPath, composite: true, declaration: true, declarationMap: true, tsBuildInfoFile: (0, path_1.join)(taskOptions.outputPath, 'tsconfig.tsbuildinfo') }), references: allProjectReferences.map((pr) => ({ path: pr })) })),
122
70
  path: tsConfig.replace(/\\/g, '/'),
123
71
  };
124
72
  }
125
- function findTaskWithTsConfig(tasks, context) {
126
- for (const task of tasks) {
127
- const depTaskOptions = (0, get_task_options_1.getTaskOptions)(task, context);
128
- if (depTaskOptions === null || depTaskOptions === void 0 ? void 0 : depTaskOptions.tsConfig) {
129
- return { task: task, tsConfig: depTaskOptions.tsConfig };
130
- }
131
- }
132
- return null;
133
- }
134
- function getDependencyTasksInSameProject(task, context) {
135
- const { project: taskProject } = (0, devkit_1.parseTargetString)(task, context.projectGraph);
136
- return Object.keys(context.taskGraph.tasks).filter((t) => t !== task &&
137
- (0, devkit_1.parseTargetString)(t, context.projectGraph).project === taskProject);
73
+ function hasTscExecutor(task, context) {
74
+ const { project, target } = (0, devkit_1.parseTargetString)(task, context.projectGraph);
75
+ return (context.projectGraph.nodes[project].data.targets[target].executor ===
76
+ '@nx/js:tsc');
138
77
  }
@@ -151,7 +151,7 @@ function addProject(tree, options, destinationDir) {
151
151
  function addLint(tree, options) {
152
152
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
153
153
  const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
154
- return lintProjectGenerator(tree, {
154
+ const task = lintProjectGenerator(tree, {
155
155
  project: options.name,
156
156
  linter: options.linter,
157
157
  skipFormat: true,
@@ -165,6 +165,23 @@ function addLint(tree, options) {
165
165
  setParserOptionsProject: options.setParserOptionsProject,
166
166
  rootProject: options.rootProject,
167
167
  });
168
+ // Also update the root .eslintrc.json lintProjectGenerator will not generate it for root projects.
169
+ // But we need to set the package.json checks.
170
+ if (options.rootProject) {
171
+ (0, devkit_1.updateJson)(tree, '.eslintrc.json', (json) => {
172
+ var _a;
173
+ (_a = json.overrides) !== null && _a !== void 0 ? _a : (json.overrides = []);
174
+ json.overrides.push({
175
+ files: ['*.json'],
176
+ parser: 'jsonc-eslint-parser',
177
+ rules: {
178
+ '@nx/dependency-checks': 'error',
179
+ },
180
+ });
181
+ return json;
182
+ });
183
+ }
184
+ return task;
168
185
  });
169
186
  }
170
187
  exports.addLint = addLint;
@@ -219,8 +236,8 @@ function createFiles(tree, options, filesDir) {
219
236
  (0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
220
237
  json.name = options.importPath;
221
238
  json.version = '0.0.1';
222
- // If the package is publishable, we should remove the private field.
223
- if (json.private && options.publishable) {
239
+ // If the package is publishable or root/standalone, we should remove the private field.
240
+ if (json.private && (options.publishable || options.rootProject)) {
224
241
  delete json.private;
225
242
  }
226
243
  return Object.assign(Object.assign(Object.assign({}, json), { dependencies: Object.assign(Object.assign({}, json.dependencies), determineDependencies(options)) }), determineEntryFields(options));
@@ -0,0 +1,8 @@
1
+ import type { OutputBundle } from 'rollup';
2
+ export declare function typeDefinitions(options: {
3
+ projectRoot: string;
4
+ main: string;
5
+ }): {
6
+ name: string;
7
+ generateBundle(_opts: unknown, bundle: OutputBundle): Promise<void>;
8
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typeDefinitions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = require("path");
6
+ const devkit_1 = require("@nx/devkit");
7
+ //NOTE: This is here so we can share between `@nx/rollup` and `@nx/vite`.
8
+ /*
9
+ * This plugin takes all entry-points from the generated bundle and creates a
10
+ * bundled version of corresponding d.ts files.
11
+ *
12
+ * For example, `src/index.ts` generates two corresponding files:
13
+ * - `dist/xyz/index.js`
14
+ * - `dist/xyz/src/index.d.ts`
15
+ *
16
+ * We want a third file: `dist/index.d.ts` that re-exports from `src/index.d.ts`.
17
+ * That way, when TSC or IDEs look for types, it will find them in the right place.
18
+ */
19
+ function typeDefinitions(options) {
20
+ return {
21
+ name: 'dts-bundle',
22
+ generateBundle(_opts, bundle) {
23
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
24
+ for (const [name, file] of Object.entries(bundle)) {
25
+ if (file.type === 'asset' ||
26
+ !file.isEntry ||
27
+ file.facadeModuleId == null) {
28
+ continue;
29
+ }
30
+ const hasDefaultExport = file.exports.includes('default');
31
+ const entrySourceFileName = (0, path_1.relative)(options.projectRoot, file.facadeModuleId);
32
+ const entrySourceDtsName = entrySourceFileName.replace(/\.[cm]?[jt]sx?$/, '');
33
+ const dtsFileName = file.fileName.replace(/\.[cm]?js$/, '.d.ts');
34
+ const relativeSourceDtsName = JSON.stringify('./' + entrySourceDtsName);
35
+ const dtsFileSource = hasDefaultExport
36
+ ? (0, devkit_1.stripIndents) `
37
+ export * from ${relativeSourceDtsName};
38
+ export { default } from ${relativeSourceDtsName};
39
+ `
40
+ : `export * from ${relativeSourceDtsName};\n`;
41
+ this.emitFile({
42
+ type: 'asset',
43
+ fileName: dtsFileName,
44
+ source: dtsFileSource,
45
+ });
46
+ }
47
+ });
48
+ },
49
+ };
50
+ }
51
+ exports.typeDefinitions = typeDefinitions;
@@ -9,7 +9,8 @@ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
9
9
  const print_diagnostics_1 = require("../typescript/print-diagnostics");
10
10
  const run_type_check_1 = require("../typescript/run-type-check");
11
11
  function getSwcCmd({ swcrcPath, srcPath, destPath }, watch = false) {
12
- let swcCmd = `npx swc ${
12
+ const packageManager = (0, devkit_1.getPackageManagerCommand)();
13
+ let swcCmd = `${packageManager.exec} swc ${
13
14
  // TODO(jack): clean this up when we remove inline module support
14
15
  // Handle root project
15
16
  srcPath === '.' ? 'src' : srcPath} -d ${destPath} --config-file=${swcrcPath}`;
@@ -32,14 +33,13 @@ function getTypeCheckOptions(normalizedOptions) {
32
33
  }
33
34
  function compileSwc(context, normalizedOptions, postCompilationCallback) {
34
35
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
- const isRootProject = context.projectGraph.nodes[context.projectName].data.root === '.';
36
36
  devkit_1.logger.log(`Compiling with SWC for ${context.projectName}...`);
37
37
  if (normalizedOptions.clean) {
38
38
  (0, fs_extra_1.removeSync)(normalizedOptions.outputPath);
39
39
  }
40
40
  const swcCmdLog = (0, child_process_1.execSync)(getSwcCmd(normalizedOptions.swcCliOptions), {
41
- cwd: normalizedOptions.swcCliOptions.swcCwd,
42
- }).toString();
41
+ encoding: 'utf8',
42
+ });
43
43
  devkit_1.logger.log(swcCmdLog.replace(/\n/, ''));
44
44
  const isCompileSuccess = swcCmdLog.includes('Successfully compiled');
45
45
  if (normalizedOptions.skipTypeCheck) {