@nx/js 19.5.2 → 19.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "19.5.2",
3
+ "version": "19.5.4",
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": {
@@ -58,9 +58,9 @@
58
58
  "semver": "^7.5.3",
59
59
  "source-map-support": "0.5.19",
60
60
  "tslib": "^2.3.0",
61
- "@nx/devkit": "19.5.2",
62
- "@nx/workspace": "19.5.2",
63
- "@nrwl/js": "19.5.2"
61
+ "@nx/devkit": "19.5.4",
62
+ "@nx/workspace": "19.5.4",
63
+ "@nrwl/js": "19.5.4"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "verdaccio": "^5.0.4"
@@ -102,9 +102,6 @@ async function* swcExecutor(_options, context) {
102
102
  format: [
103
103
  determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
104
104
  ],
105
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
106
- // TSC can match them correctly based on file names.
107
- skipTypings: true,
108
105
  }, context);
109
106
  removeTmpSwcrc(options.swcCliOptions.swcrcPath);
110
107
  disposeFn = () => {
@@ -122,9 +119,6 @@ async function* swcExecutor(_options, context) {
122
119
  format: [
123
120
  determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
124
121
  ],
125
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
126
- // TSC can match them correctly based on file names.
127
- skipTypings: true,
128
122
  extraDependencies: swcHelperDependency ? [swcHelperDependency] : [],
129
123
  }, context);
130
124
  removeTmpSwcrc(options.swcCliOptions.swcrcPath);
@@ -38,6 +38,11 @@
38
38
  "x-completion-type": "directory",
39
39
  "x-priority": "important"
40
40
  },
41
+ "outputFileName": {
42
+ "type": "string",
43
+ "description": "The path to the main file relative to the outputPath",
44
+ "x-completion-type": "file"
45
+ },
41
46
  "tsConfig": {
42
47
  "type": "string",
43
48
  "description": "The path to the Typescript configuration file.",
@@ -51,9 +51,6 @@ async function* tscBatchExecutor(taskGraph, inputs, overrides, context) {
51
51
  ...taskInfo.options,
52
52
  additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(taskInfo.options.additionalEntryPoints, context.root),
53
53
  format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(tsConfig)],
54
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
55
- // TSC can match them correctly based on file names.
56
- skipTypings: true,
57
54
  }, taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
58
55
  taskInfo.endTime = Date.now();
59
56
  }
@@ -80,9 +77,6 @@ async function* tscBatchExecutor(taskGraph, inputs, overrides, context) {
80
77
  ...t.options,
81
78
  additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(t.options.additionalEntryPoints, context.root),
82
79
  format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(t.options.tsConfig)],
83
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
84
- // TSC can match them correctly based on file names.
85
- skipTypings: true,
86
80
  }, t.context, t.projectGraphNode, t.buildableProjectNodeDependencies);
87
81
  }
88
82
  });
@@ -67,9 +67,6 @@ async function* tscExecutor(_options, context) {
67
67
  ...options,
68
68
  additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(options.additionalEntryPoints, context.root),
69
69
  format: [determineModuleFormatFromTsConfig(options.tsConfig)],
70
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
71
- // TSC can match them correctly based on file names.
72
- skipTypings: true,
73
70
  }, context, target, dependencies);
74
71
  (0, inline_1.postProcessInlinedDependencies)(tsCompilationOptions.outputPath, tsCompilationOptions.projectRoot, inlineProjectGraph);
75
72
  });
@@ -83,9 +80,6 @@ async function* tscExecutor(_options, context) {
83
80
  const disposePackageJsonChanges = await (0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)({
84
81
  ...options,
85
82
  additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(options.additionalEntryPoints, context.root),
86
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
87
- // TSC can match them correctly based on file names.
88
- skipTypings: true,
89
83
  format: [determineModuleFormatFromTsConfig(options.tsConfig)],
90
84
  }, context, target, dependencies));
91
85
  const handleTermination = async (exitCode) => {
@@ -2,6 +2,8 @@ export interface VerdaccioExecutorSchema {
2
2
  location: 'global' | 'user' | 'project' | 'none';
3
3
  storage?: string;
4
4
  port?: number;
5
+ listenAddress?: string;
5
6
  config?: string;
6
7
  clear?: boolean;
8
+ scopes?: string[];
7
9
  }
@@ -20,6 +20,10 @@
20
20
  "type": "number",
21
21
  "description": "Port of local registry that Verdaccio should listen to"
22
22
  },
23
+ "listenAddress": {
24
+ "type": "string",
25
+ "description": "Listen address that Verdaccio should listen to"
26
+ },
23
27
  "config": {
24
28
  "type": "string",
25
29
  "description": "Path to the custom Verdaccio config file"
@@ -28,6 +32,13 @@
28
32
  "type": "boolean",
29
33
  "description": "Clear local registry storage before starting Verdaccio",
30
34
  "default": true
35
+ },
36
+ "scopes": {
37
+ "type": "array",
38
+ "description": "Scopes to be added to the Verdaccio config",
39
+ "items": {
40
+ "type": "string"
41
+ }
31
42
  }
32
43
  },
33
44
  "required": ["port"]
@@ -104,7 +104,10 @@ function createVerdaccioOptions(options, workspaceRoot) {
104
104
  options.port ??= 4873; // set default port if config is not provided
105
105
  }
106
106
  if (options.port) {
107
- verdaccioArgs.push('--listen', options.port.toString());
107
+ const listenAddress = options.listenAddress
108
+ ? `${options.listenAddress}:${options.port.toString()}`
109
+ : options.port.toString();
110
+ verdaccioArgs.push('--listen', listenAddress);
108
111
  }
109
112
  return verdaccioArgs;
110
113
  }
@@ -115,41 +118,55 @@ function setupNpm(options) {
115
118
  catch (e) {
116
119
  return () => { };
117
120
  }
118
- let npmRegistryPath;
121
+ let npmRegistryPaths = [];
122
+ const scopes = ['', ...(options.scopes || [])];
119
123
  try {
120
- npmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`, { env })
121
- ?.toString()
122
- ?.trim()
123
- ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
124
- (0, child_process_1.execSync)(`npm config set registry http://localhost:${options.port}/ --location ${options.location}`, { env });
125
- (0, child_process_1.execSync)(`npm config set //localhost:${options.port}/:_authToken="secretVerdaccioToken" --location ${options.location}`, { env });
126
- devkit_1.logger.info(`Set npm registry to http://localhost:${options.port}/`);
124
+ scopes.forEach((scope) => {
125
+ const scopeName = scope ? `${scope}:` : '';
126
+ try {
127
+ npmRegistryPaths.push((0, child_process_1.execSync)(`npm config get '${scopeName}registry' --location ${options.location}`, { env })
128
+ ?.toString()
129
+ ?.trim()
130
+ ?.replace('\u001b[2K\u001b[1G', '') // strip out ansi codes
131
+ );
132
+ (0, child_process_1.execSync)(`npm config set '${scopeName}registry' 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 });
134
+ devkit_1.logger.info(`Set npm ${scopeName}registry to http://localhost:${options.port}/`);
135
+ }
136
+ catch (e) {
137
+ throw new Error(`Failed to set npm ${scopeName}registry to http://localhost:${options.port}/: ${e.message}`);
138
+ }
139
+ });
140
+ return () => {
141
+ try {
142
+ const currentNpmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`, { env })
143
+ ?.toString()
144
+ ?.trim()
145
+ ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
146
+ if (npmRegistryPaths.length > 0 &&
147
+ currentNpmRegistryPath.includes('localhost')) {
148
+ scopes.forEach((scope, index) => {
149
+ const scopeName = scope ? `${scope}:` : '';
150
+ (0, child_process_1.execSync)(`npm config set '${scopeName}registry' ${npmRegistryPaths[index]} --location ${options.location}`, { env });
151
+ devkit_1.logger.info(`Reset npm ${scopeName}registry to ${npmRegistryPaths[index]}`);
152
+ });
153
+ }
154
+ else {
155
+ (0, child_process_1.execSync)(`npm config delete registry --location ${options.location}`, {
156
+ env,
157
+ });
158
+ devkit_1.logger.info('Cleared custom npm registry');
159
+ }
160
+ (0, child_process_1.execSync)(`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`, { env });
161
+ }
162
+ catch (e) {
163
+ throw new Error(`Failed to reset npm registry: ${e.message}`);
164
+ }
165
+ };
127
166
  }
128
167
  catch (e) {
129
168
  throw new Error(`Failed to set npm registry to http://localhost:${options.port}/: ${e.message}`);
130
169
  }
131
- return () => {
132
- try {
133
- const currentNpmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`, { env })
134
- ?.toString()
135
- ?.trim()
136
- ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
137
- if (npmRegistryPath && currentNpmRegistryPath.includes('localhost')) {
138
- (0, child_process_1.execSync)(`npm config set registry ${npmRegistryPath} --location ${options.location}`, { env });
139
- devkit_1.logger.info(`Reset npm registry to ${npmRegistryPath}`);
140
- }
141
- else {
142
- (0, child_process_1.execSync)(`npm config delete registry --location ${options.location}`, {
143
- env,
144
- });
145
- devkit_1.logger.info('Cleared custom npm registry');
146
- }
147
- (0, child_process_1.execSync)(`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`, { env });
148
- }
149
- catch (e) {
150
- throw new Error(`Failed to reset npm registry: ${e.message}`);
151
- }
152
- };
153
170
  }
154
171
  function getYarnUnsafeHttpWhitelist(isYarnV1) {
155
172
  return !isYarnV1
@@ -169,6 +186,8 @@ function setYarnUnsafeHttpWhitelist(currentWhitelist, options) {
169
186
  }
170
187
  function setupYarn(options) {
171
188
  let isYarnV1;
189
+ let yarnRegistryPaths = [];
190
+ const scopes = ['', ...(options.scopes || [])];
172
191
  try {
173
192
  isYarnV1 =
174
193
  (0, semver_1.major)((0, child_process_1.execSync)('yarn --version', { env }).toString().trim()) === 1;
@@ -179,15 +198,19 @@ function setupYarn(options) {
179
198
  }
180
199
  try {
181
200
  const registryConfigName = isYarnV1 ? 'registry' : 'npmRegistryServer';
182
- const yarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`, {
183
- env,
184
- })
185
- ?.toString()
186
- ?.trim()
187
- ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
188
- (0, child_process_1.execSync)(`yarn config set ${registryConfigName} http://localhost:${options.port}/` +
189
- (options.location === 'user' ? ' --home' : ''), { env });
190
- devkit_1.logger.info(`Set yarn registry to http://localhost:${options.port}/`);
201
+ scopes.forEach((scope) => {
202
+ const scopeName = scope ? `${scope}:` : '';
203
+ yarnRegistryPaths.push((0, child_process_1.execSync)(`yarn config get ${scopeName}${registryConfigName}`, {
204
+ env,
205
+ })
206
+ ?.toString()
207
+ ?.trim()
208
+ ?.replace('\u001b[2K\u001b[1G', '') // strip out ansi codes
209
+ );
210
+ (0, child_process_1.execSync)(`yarn config set ${scopeName}${registryConfigName} http://localhost:${options.port}/` +
211
+ (options.location === 'user' ? ' --home' : ''), { env });
212
+ devkit_1.logger.info(`Set yarn ${scopeName}registry to http://localhost:${options.port}/`);
213
+ });
191
214
  const currentWhitelist = getYarnUnsafeHttpWhitelist(isYarnV1);
192
215
  let whitelistedLocalhost = false;
193
216
  if (!isYarnV1 && !currentWhitelist.has('localhost')) {
@@ -202,10 +225,14 @@ function setupYarn(options) {
202
225
  ?.toString()
203
226
  ?.trim()
204
227
  ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
205
- if (yarnRegistryPath && currentYarnRegistryPath.includes('localhost')) {
206
- (0, child_process_1.execSync)(`yarn config set ${registryConfigName} ${yarnRegistryPath}` +
207
- (options.location === 'user' ? ' --home' : ''), { env });
208
- devkit_1.logger.info(`Reset yarn ${registryConfigName} to ${yarnRegistryPath}`);
228
+ if (yarnRegistryPaths.length > 0 &&
229
+ currentYarnRegistryPath.includes('localhost')) {
230
+ scopes.forEach((scope, index) => {
231
+ const scopeName = scope ? `${scope}:` : '';
232
+ (0, child_process_1.execSync)(`yarn config set ${scopeName}${registryConfigName} ${yarnRegistryPaths[index]}` +
233
+ (options.location === 'user' ? ' --home' : ''), { env });
234
+ devkit_1.logger.info(`Reset yarn ${scopeName}${registryConfigName} to ${yarnRegistryPaths[index]}`);
235
+ });
209
236
  }
210
237
  else {
211
238
  (0, child_process_1.execSync)(`yarn config ${isYarnV1 ? 'delete' : 'unset'} ${registryConfigName}` +
@@ -13,7 +13,9 @@ const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
13
13
  const cache_directory_1 = require("nx/src/utils/cache-directory");
14
14
  const ts_config_1 = require("../../utils/typescript/ts-config");
15
15
  function readTargetsCache(cachePath) {
16
- return (0, node_fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
16
+ return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, node_fs_1.existsSync)(cachePath)
17
+ ? (0, devkit_1.readJsonFile)(cachePath)
18
+ : {};
17
19
  }
18
20
  function writeTargetsToCache(cachePath, results) {
19
21
  (0, devkit_1.writeJsonFile)(cachePath, results);
@@ -90,7 +92,7 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
90
92
  let internalProjectReferences;
91
93
  // Typecheck target
92
94
  if ((0, node_path_1.basename)(configFilePath) === 'tsconfig.json' && options.typecheck) {
93
- internalProjectReferences = resolveInternalProjectReferences(configFilePath, tsConfig);
95
+ internalProjectReferences = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
94
96
  const targetName = options.typecheck.targetName;
95
97
  if (!targets[targetName]) {
96
98
  let command = `tsc --build --emitDeclarationOnly --pretty --verbose`;
@@ -112,7 +114,7 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
112
114
  }
113
115
  // Build target
114
116
  if (options.build && (0, node_path_1.basename)(configFilePath) === options.build.configName) {
115
- internalProjectReferences ??= resolveInternalProjectReferences(configFilePath, tsConfig);
117
+ internalProjectReferences ??= resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
116
118
  const targetName = options.build.targetName;
117
119
  targets[targetName] = {
118
120
  dependsOn: [`^${targetName}`],
@@ -137,9 +139,11 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
137
139
  [configFilePath, tsConfig],
138
140
  ...Object.entries(internalProjectReferences),
139
141
  ];
142
+ const absoluteProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
140
143
  projectTsConfigFiles.forEach(([configPath, config]) => {
141
144
  configFiles.add(configPath);
142
- (config.raw?.include ?? []).forEach((p) => includePaths.add(p));
145
+ const offset = (0, node_path_1.relative)(absoluteProjectRoot, (0, node_path_1.dirname)(configPath));
146
+ (config.raw?.include ?? []).forEach((p) => includePaths.add((0, node_path_1.join)(offset, p)));
143
147
  if (config.raw?.exclude) {
144
148
  /**
145
149
  * We need to filter out the exclude paths that are already included in
@@ -173,7 +177,7 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
173
177
  if (excludePaths.size) {
174
178
  inputs.push(...Array.from(excludePaths).map((p) => `!${pathToInputOrOutput((0, devkit_1.joinPathFragments)(projectRoot, p), workspaceRoot, projectRoot)}`));
175
179
  }
176
- if (hasExternalProjectReferences(configFilePath, tsConfig)) {
180
+ if (hasExternalProjectReferences(configFilePath, tsConfig, workspaceRoot, projectRoot)) {
177
181
  // Importing modules from a referenced project will load its output declaration files (d.ts)
178
182
  // https://www.typescriptlang.org/docs/handbook/project-references.html#what-is-a-project-reference
179
183
  inputs.push({ dependentTasksOutputFiles: '**/*.d.ts' });
@@ -251,18 +255,17 @@ function getExtendedConfigFiles(tsConfigPath, tsConfig) {
251
255
  }
252
256
  return Array.from(extendedConfigFiles);
253
257
  }
254
- function resolveInternalProjectReferences(configFilePath, tsConfig, projectReferences = {}) {
258
+ function resolveInternalProjectReferences(tsConfig, workspaceRoot, projectRoot, projectReferences = {}) {
255
259
  if (!tsConfig.projectReferences?.length) {
256
260
  return projectReferences;
257
261
  }
258
- const basePath = getTsConfigBasePath(configFilePath);
259
262
  for (const ref of tsConfig.projectReferences) {
260
263
  let refConfigPath = ref.path;
261
264
  if (projectReferences[refConfigPath]) {
262
265
  // Already resolved
263
266
  continue;
264
267
  }
265
- if (isExternalProjectReference(refConfigPath, basePath)) {
268
+ if (isExternalProjectReference(refConfigPath, workspaceRoot, projectRoot)) {
266
269
  continue;
267
270
  }
268
271
  if (!refConfigPath.endsWith('.json')) {
@@ -270,51 +273,58 @@ function resolveInternalProjectReferences(configFilePath, tsConfig, projectRefer
270
273
  }
271
274
  const refTsConfig = readCachedTsConfig(refConfigPath);
272
275
  projectReferences[refConfigPath] = refTsConfig;
273
- resolveInternalProjectReferences(refConfigPath, refTsConfig, projectReferences);
276
+ resolveInternalProjectReferences(refTsConfig, workspaceRoot, projectRoot, projectReferences);
274
277
  }
275
278
  return projectReferences;
276
279
  }
277
- function hasExternalProjectReferences(tsConfigPath, tsConfig, seen = new Set()) {
280
+ function hasExternalProjectReferences(tsConfigPath, tsConfig, workspaceRoot, projectRoot, seen = new Set()) {
278
281
  if (!tsConfig.projectReferences?.length) {
279
282
  return false;
280
283
  }
281
284
  seen.add(tsConfigPath);
282
- const basePath = getTsConfigBasePath(tsConfigPath);
283
285
  for (const ref of tsConfig.projectReferences) {
284
286
  let refConfigPath = ref.path;
285
287
  if (seen.has(refConfigPath)) {
286
288
  // Already seen
287
289
  continue;
288
290
  }
289
- if (isExternalProjectReference(refConfigPath, basePath)) {
291
+ if (isExternalProjectReference(refConfigPath, workspaceRoot, projectRoot)) {
290
292
  return true;
291
293
  }
292
294
  if (!refConfigPath.endsWith('.json')) {
293
295
  refConfigPath = (0, node_path_1.join)(refConfigPath, 'tsconfig.json');
294
296
  }
295
297
  const refTsConfig = readCachedTsConfig(refConfigPath);
296
- const result = hasExternalProjectReferences(refConfigPath, refTsConfig);
298
+ const result = hasExternalProjectReferences(refConfigPath, refTsConfig, workspaceRoot, projectRoot, seen);
297
299
  if (result) {
298
300
  return true;
299
301
  }
300
302
  }
301
303
  return false;
302
304
  }
303
- function isExternalProjectReference(refTsConfigPath, basePath) {
304
- const refBasePath = getTsConfigBasePath(refTsConfigPath);
305
- // TODO: there could be internal project references in nested dirs (e.g.
306
- // our storybook generator generates a nested `.storybook/tsconfig.json`),
307
- // which would be considered an external project reference but it's not.
308
- // We could instead check if the referenced tsconfig is outside the project
309
- // root, but that would cause issues with standalone workspaces with nested
310
- // projects.
311
- return refBasePath !== basePath;
305
+ function isExternalProjectReference(refTsConfigPath, workspaceRoot, projectRoot) {
306
+ const absoluteProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
307
+ let currentPath = getTsConfigDirName(refTsConfigPath);
308
+ if ((0, node_path_1.relative)(absoluteProjectRoot, currentPath).startsWith('..')) {
309
+ // it's outside of the project root, so it's an external project reference
310
+ return true;
311
+ }
312
+ while (currentPath !== absoluteProjectRoot) {
313
+ if ((0, node_fs_1.existsSync)((0, node_path_1.join)(currentPath, 'package.json')) ||
314
+ (0, node_fs_1.existsSync)((0, node_path_1.join)(currentPath, 'project.json'))) {
315
+ // it's inside a nested project root, so it's and external project reference
316
+ return true;
317
+ }
318
+ currentPath = (0, node_path_1.dirname)(currentPath);
319
+ }
320
+ // it's inside the project root, so it's an internal project reference
321
+ return false;
312
322
  }
313
- function getTsConfigBasePath(tsConfigPath) {
314
- return (0, node_fs_1.statSync)(tsConfigPath).isFile() ? (0, node_path_1.dirname)(tsConfigPath) : tsConfigPath;
323
+ function getTsConfigDirName(tsConfigPath) {
324
+ return (0, node_fs_1.statSync)(tsConfigPath).isFile()
325
+ ? (0, node_path_1.dirname)(tsConfigPath)
326
+ : (0, node_path_1.normalize)(tsConfigPath);
315
327
  }
316
- // TODO: we could probably persist this to disk to avoid reading the same
317
- // tsconfig files over multiple runs
318
328
  const tsConfigCache = new Map();
319
329
  function readCachedTsConfig(tsConfigPath) {
320
330
  const cacheKey = getTsConfigCacheKey(tsConfigPath);
@@ -37,6 +37,18 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
37
37
  ? (0, devkit_1.readJsonFile)(pathToPackageJson)
38
38
  : { name: context.projectName, version: '0.0.1' };
39
39
  }
40
+ if (packageJson.type === 'module') {
41
+ if (options.format?.includes('cjs')) {
42
+ devkit_1.logger.warn(`Package type is set to "module" but "cjs" format is included. Going to use "esm" format instead. You can change the package type to "commonjs" or remove type in the package.json file.`);
43
+ }
44
+ options.format = ['esm'];
45
+ }
46
+ else if (packageJson.type === 'commonjs') {
47
+ if (options.format?.includes('esm')) {
48
+ devkit_1.logger.warn(`Package type is set to "commonjs" but "esm" format is included. Going to use "cjs" format instead. You can change the package type to "module" or remove type in the package.json file.`);
49
+ }
50
+ options.format = ['cjs'];
51
+ }
40
52
  // update package specific settings
41
53
  packageJson = getUpdatedPackageJsonContent(packageJson, options);
42
54
  // save files
@@ -115,8 +127,13 @@ function getExports(options) {
115
127
  const { ext: fileExt, name: fileName } = (0, path_1.parse)(file);
116
128
  const relativeDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(file, options.projectRoot);
117
129
  const sourceFilePath = relativeDir + fileName;
118
- const entryFilepath = sourceFilePath.replace(/^\.\/src\//, './');
130
+ const entryRelativeDir = relativeDir.replace(/^\.\/src\//, './');
131
+ const entryFilepath = entryRelativeDir + fileName;
119
132
  const isJsFile = jsRegex.test(fileExt);
133
+ if (isJsFile && fileName === 'index') {
134
+ const barrelEntry = entryRelativeDir.replace(/\/$/, '');
135
+ exports[barrelEntry] = sourceFilePath + options.fileExt;
136
+ }
120
137
  exports[isJsFile ? entryFilepath : entryFilepath + fileExt] =
121
138
  sourceFilePath + (isJsFile ? options.fileExt : fileExt);
122
139
  }
@@ -139,7 +156,7 @@ function getUpdatedPackageJsonContent(packageJson, options) {
139
156
  });
140
157
  packageJson.module ??= esmExports['.'];
141
158
  if (!hasCjsFormat) {
142
- packageJson.type = 'module';
159
+ packageJson.type ??= 'module';
143
160
  packageJson.main ??= esmExports['.'];
144
161
  }
145
162
  if (options.generateExportsField) {
@@ -160,7 +177,7 @@ function getUpdatedPackageJsonContent(packageJson, options) {
160
177
  });
161
178
  packageJson.main ??= cjsExports['.'];
162
179
  if (!hasEsmFormat) {
163
- packageJson.type = 'commonjs';
180
+ packageJson.type ??= 'commonjs';
164
181
  }
165
182
  if (options.generateExportsField) {
166
183
  for (const [exportEntry, filePath] of Object.entries(cjsExports)) {