@nx/js 18.0.0-beta.1 → 18.0.0-beta.3

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": "18.0.0-beta.1",
3
+ "version": "18.0.0-beta.3",
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": {
@@ -57,9 +57,9 @@
57
57
  "semver": "^7.5.3",
58
58
  "source-map-support": "0.5.19",
59
59
  "tslib": "^2.3.0",
60
- "@nx/devkit": "18.0.0-beta.1",
61
- "@nx/workspace": "18.0.0-beta.1",
62
- "@nrwl/js": "18.0.0-beta.1"
60
+ "@nx/devkit": "18.0.0-beta.3",
61
+ "@nx/workspace": "18.0.0-beta.3",
62
+ "@nrwl/js": "18.0.0-beta.3"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "verdaccio": "^5.0.4"
@@ -11,6 +11,6 @@ export interface NormalizedSchema extends LibraryGeneratorSchema {
11
11
  parsedTags: string[];
12
12
  importPath?: string;
13
13
  }
14
- export type AddLintOptions = Pick<NormalizedSchema, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'setParserOptionsProject' | 'rootProject' | 'bundler'>;
14
+ export type AddLintOptions = Pick<NormalizedSchema, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'setParserOptionsProject' | 'rootProject' | 'bundler' | 'addPlugin'>;
15
15
  export declare function addLint(tree: Tree, options: AddLintOptions): Promise<GeneratorCallback>;
16
16
  export default libraryGenerator;
@@ -13,8 +13,10 @@ const init_1 = require("../init/init");
13
13
  const generator_1 = require("../setup-verdaccio/generator");
14
14
  const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
15
15
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
16
+ const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
16
17
  async function libraryGenerator(tree, schema) {
17
18
  return await libraryGeneratorInternal(tree, {
19
+ addPlugin: false,
18
20
  // provide a default projectNameAndRootFormat to avoid breaking changes
19
21
  // to external generators invoking this one
20
22
  projectNameAndRootFormat: 'derived',
@@ -49,6 +51,7 @@ async function libraryGeneratorInternal(tree, schema) {
49
51
  includeLib: true,
50
52
  skipFormat: true,
51
53
  testEnvironment: options.testEnvironment,
54
+ addPlugin: options.addPlugin,
52
55
  });
53
56
  tasks.push(viteTask);
54
57
  createOrEditViteConfig(tree, {
@@ -117,8 +120,10 @@ function addProject(tree, options) {
117
120
  options.bundler !== 'none' &&
118
121
  options.config !== 'npm-scripts') {
119
122
  const outputPath = getOutputPath(options);
123
+ const executor = getBuildExecutor(options.bundler);
124
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, executor);
120
125
  projectConfiguration.targets.build = {
121
- executor: getBuildExecutor(options.bundler),
126
+ executor,
122
127
  outputs: ['{options.outputPath}'],
123
128
  options: {
124
129
  outputPath,
@@ -177,6 +182,7 @@ async function addLint(tree, options) {
177
182
  unitTestRunner: options.unitTestRunner,
178
183
  setParserOptionsProject: options.setParserOptionsProject,
179
184
  rootProject: options.rootProject,
185
+ addPlugin: options.addPlugin,
180
186
  });
181
187
  const { addOverrideToLintConfig, lintConfigHasOverride, isEslintConfigSupported, updateOverrideInLintConfig,
182
188
  // nx-ignore-next-line
@@ -388,6 +394,7 @@ function replaceJestConfig(tree, options, filesDir) {
388
394
  });
389
395
  }
390
396
  async function normalizeOptions(tree, options) {
397
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
391
398
  /**
392
399
  * We are deprecating the compiler and the buildable options.
393
400
  * However, we want to keep the existing behavior for now.
@@ -14,23 +14,30 @@ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
14
14
  }
15
15
  return [];
16
16
  }
17
+ const packageManager = (0, devkit_1.detectPackageManager)(cwd);
18
+ if (packageManager === 'yarn' &&
19
+ !(0, semver_1.gte)((0, devkit_1.getPackageManagerVersion)(packageManager), '2.0.0')) {
20
+ // yarn classic does not store workspace data in the lock file, so we don't need to update it
21
+ if (verbose) {
22
+ console.log('\nSkipped lock file update because it is not necessary for Yarn Classic.');
23
+ }
24
+ return [];
25
+ }
17
26
  const isDaemonEnabled = client_1.daemonClient.enabled();
18
27
  if (isDaemonEnabled) {
19
28
  // temporarily stop the daemon, as it will error if the lock file is updated
20
29
  await client_1.daemonClient.stop();
21
30
  }
22
- const packageManager = (0, devkit_1.detectPackageManager)(cwd);
23
31
  const packageManagerCommands = (0, devkit_1.getPackageManagerCommand)(packageManager);
24
32
  let installArgs = generatorOptions?.installArgs || '';
25
33
  devkit_1.output.logSingleLine(`Updating ${packageManager} lock file`);
26
34
  let env = {};
27
35
  if (generatorOptions?.installIgnoreScripts) {
28
- if (packageManager === 'yarn' &&
29
- (0, semver_1.gte)((0, devkit_1.getPackageManagerVersion)(packageManager), '2.0.0')) {
36
+ if (packageManager === 'yarn') {
30
37
  env = { YARN_ENABLE_SCRIPTS: 'false' };
31
38
  }
32
39
  else {
33
- // npm, pnpm, and yarn classic all use the same --ignore-scripts option
40
+ // npm and pnpm use the same --ignore-scripts option
34
41
  installArgs = `${installArgs} --ignore-scripts`.trim();
35
42
  }
36
43
  }
@@ -1,8 +1,9 @@
1
- import { type ProjectGraph, type ProjectGraphProjectNode, type ProjectFileMap } from '@nx/devkit';
1
+ import { type ProjectFileMap, type ProjectGraph, type ProjectGraphProjectNode } from '@nx/devkit';
2
2
  /**
3
3
  * Finds all npm dependencies and their expected versions for a given project.
4
4
  */
5
5
  export declare function findNpmDependencies(workspaceRoot: string, sourceProject: ProjectGraphProjectNode, projectGraph: ProjectGraph, projectFileMap: ProjectFileMap, buildTarget: string, options?: {
6
6
  includeTransitiveDependencies?: boolean;
7
7
  ignoredFiles?: string[];
8
+ useLocalPathsForWorkspaceDependencies?: boolean;
8
9
  }): Record<string, string>;
@@ -21,7 +21,7 @@ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, project
21
21
  if (seen?.has(currentProject.name))
22
22
  return;
23
23
  seen?.add(currentProject.name);
24
- collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, options.ignoredFiles, collectedDeps);
24
+ collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, options.ignoredFiles, options.useLocalPathsForWorkspaceDependencies, collectedDeps);
25
25
  collectHelperDependencies(workspaceRoot, currentProject, projectGraph, buildTarget, collectedDeps);
26
26
  if (options.includeTransitiveDependencies) {
27
27
  const projectDeps = projectGraph.dependencies[currentProject.name];
@@ -38,7 +38,7 @@ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, project
38
38
  exports.findNpmDependencies = findNpmDependencies;
39
39
  // Keep track of workspace libs we already read package.json for so we don't read from disk again.
40
40
  const seenWorkspaceDeps = {};
41
- function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, ignoredFiles, npmDeps) {
41
+ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, ignoredFiles, useLocalPathsForWorkspaceDependencies, npmDeps) {
42
42
  const rawFiles = projectFileMap[sourceProject.name];
43
43
  if (!rawFiles)
44
44
  return;
@@ -82,12 +82,27 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
82
82
  workspaceDep.data.targets[buildTarget] &&
83
83
  // Make sure package.json exists and has a valid name.
84
84
  packageJson?.name) {
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.
86
- // ASSUMPTION: Most users will use '*' for workspace lib versions. Otherwise, they can manually update it.
87
- npmDeps[packageJson.name] = '*';
85
+ let version;
86
+ if (useLocalPathsForWorkspaceDependencies) {
87
+ // Find the relative `file:...` path and use that as the version value.
88
+ // This is useful for monorepos like Nx where the release will handle setting the correct version in dist.
89
+ const depRoot = (0, path_1.join)(workspaceRoot, workspaceDep.data.root);
90
+ const ownRoot = (0, path_1.join)(workspaceRoot, sourceProject.data.root);
91
+ const relativePath = (0, path_1.relative)(ownRoot, depRoot);
92
+ const filePath = (0, devkit_1.normalizePath)(relativePath); // normalize slashes for windows
93
+ version = `file:${filePath}`;
94
+ }
95
+ else {
96
+ // Otherwise, read the version from the dependencies `package.json` file.
97
+ // This is useful for monorepos that commit release versions.
98
+ // Users can also set version as "*" in source `package.json` files, which will be the value set here.
99
+ // This is useful if they use custom scripts to update them in dist.
100
+ version = packageJson.version ?? '*'; // fallback in case version is missing
101
+ }
102
+ npmDeps[packageJson.name] = version;
88
103
  seenWorkspaceDeps[workspaceDep.name] = {
89
104
  name: packageJson.name,
90
- version: '*',
105
+ version,
91
106
  };
92
107
  }
93
108
  }
@@ -33,6 +33,7 @@ export interface LibraryGeneratorSchema {
33
33
  minimal?: boolean;
34
34
  rootProject?: boolean;
35
35
  simpleName?: boolean;
36
+ addPlugin?: boolean;
36
37
  }
37
38
 
38
39
  export interface ExecutorOptions {