@nx/js 21.2.1 → 21.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "21.2.1",
3
+ "version": "21.2.2",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -39,8 +39,8 @@
39
39
  "@babel/preset-env": "^7.23.2",
40
40
  "@babel/preset-typescript": "^7.22.5",
41
41
  "@babel/runtime": "^7.22.6",
42
- "@nx/devkit": "21.2.1",
43
- "@nx/workspace": "21.2.1",
42
+ "@nx/devkit": "21.2.2",
43
+ "@nx/workspace": "21.2.2",
44
44
  "@zkochan/js-yaml": "0.0.7",
45
45
  "babel-plugin-const-enum": "^1.0.1",
46
46
  "babel-plugin-macros": "^3.1.0",
@@ -384,14 +384,14 @@ function createFiles(tree, options) {
384
384
  hasUnitTestRunner: options.unitTestRunner !== 'none',
385
385
  });
386
386
  }
387
- if (options.bundler === 'swc' || options.bundler === 'rollup') {
387
+ if (options.includeBabelRc) {
388
+ addBabelRc(tree, options);
389
+ }
390
+ else if (options.bundler === 'swc' || options.bundler === 'rollup') {
388
391
  (0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' && !options.isUsingTsSolutionConfig
389
392
  ? 'commonjs'
390
393
  : 'es6');
391
394
  }
392
- else if (options.includeBabelRc) {
393
- addBabelRc(tree, options);
394
- }
395
395
  if (options.unitTestRunner === 'none') {
396
396
  tree.delete((0, path_1.join)(options.projectRoot, 'src/lib', `${options.fileName}.spec.ts`));
397
397
  tree.delete((0, path_1.join)(options.projectRoot, 'src/app', `${options.fileName}.spec.ts`));
@@ -6,6 +6,7 @@ const devkit_1 = require("@nx/devkit");
6
6
  const node_fs_1 = require("node:fs");
7
7
  const node_path_1 = require("node:path");
8
8
  const path_1 = require("path");
9
+ const picomatch = require("picomatch");
9
10
  /**
10
11
  * Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
11
12
  */
@@ -46,22 +47,98 @@ function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
46
47
  return true;
47
48
  }
48
49
  const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
49
- const outDir = tsConfig.options.outFile
50
- ? (0, node_path_1.dirname)(tsConfig.options.outFile)
51
- : tsConfig.options.outDir;
52
- const resolvedOutDir = outDir
53
- ? (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, outDir)
54
- : undefined;
50
+ const projectAbsolutePath = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath);
51
+ // Handle outFile first (has precedence over outDir)
52
+ if (tsConfig.options.outFile) {
53
+ const outFile = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, tsConfig.options.outFile);
54
+ const relativeToProject = (0, node_path_1.relative)(projectAbsolutePath, outFile);
55
+ // If outFile is outside project root: buildable
56
+ if (relativeToProject.startsWith('..')) {
57
+ return true;
58
+ }
59
+ // If outFile is inside project root: check if entry points point to outFile
60
+ const isPathSourceFile = (path) => {
61
+ const normalizedPath = (0, node_path_1.isAbsolute)(path)
62
+ ? (0, node_path_1.resolve)(workspaceRoot, path.startsWith('/') ? path.slice(1) : path)
63
+ : (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
64
+ // For outFile case, check if path points to the specific outFile
65
+ return normalizedPath === outFile;
66
+ };
67
+ // Check if any entry points match the outFile
68
+ const exports = packageJson?.exports;
69
+ if (exports) {
70
+ if (typeof exports === 'string') {
71
+ return !isPathSourceFile(exports);
72
+ }
73
+ if (typeof exports === 'object' && '.' in exports) {
74
+ const dotExport = exports['.'];
75
+ if (typeof dotExport === 'string') {
76
+ return !isPathSourceFile(dotExport);
77
+ }
78
+ else if (typeof dotExport === 'object') {
79
+ const hasMatch = Object.entries(dotExport).some(([key, value]) => {
80
+ if (key === 'types' || key === 'development')
81
+ return false;
82
+ return typeof value === 'string' && isPathSourceFile(value);
83
+ });
84
+ return !hasMatch;
85
+ }
86
+ }
87
+ }
88
+ const buildPaths = ['main', 'module'];
89
+ for (const field of buildPaths) {
90
+ if (packageJson[field] && isPathSourceFile(packageJson[field])) {
91
+ return false;
92
+ }
93
+ }
94
+ return true;
95
+ }
96
+ // Handle outDir
97
+ const outDir = tsConfig.options.outDir;
98
+ let resolvedOutDir;
99
+ if (outDir) {
100
+ const potentialOutDir = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, outDir);
101
+ const relativePath = (0, node_path_1.relative)(projectAbsolutePath, potentialOutDir);
102
+ // If outDir is outside project root: buildable
103
+ if (relativePath.startsWith('..')) {
104
+ return true;
105
+ }
106
+ // If outDir is inside project root, then we should check entry points
107
+ if (!relativePath.startsWith('..')) {
108
+ resolvedOutDir = potentialOutDir;
109
+ }
110
+ }
55
111
  const isPathSourceFile = (path) => {
112
+ const normalizedPath = (0, node_path_1.isAbsolute)(path)
113
+ ? (0, node_path_1.resolve)(workspaceRoot, path.startsWith('/') ? path.slice(1) : path)
114
+ : (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
56
115
  if (resolvedOutDir) {
57
- const pathToCheck = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
58
- return !pathToCheck.startsWith(resolvedOutDir);
116
+ // If the path is within the outDir, we assume it's not a source file.
117
+ const relativePath = (0, node_path_1.relative)(resolvedOutDir, normalizedPath);
118
+ if (!relativePath.startsWith('..')) {
119
+ return false;
120
+ }
59
121
  }
60
- const ext = (0, node_path_1.extname)(path);
61
- // Check that the file extension is a TS file extension. As the source files are in the same directory as the output files.
62
- return ['.ts', '.tsx', '.cts', '.mts'].includes(ext);
122
+ // If no include patterns, TypeScript includes all TS files by default
123
+ const include = tsConfig.raw?.include;
124
+ if (!include || !Array.isArray(include)) {
125
+ const ext = (0, node_path_1.extname)(path);
126
+ const tsExtensions = ['.ts', '.tsx', '.cts', '.mts'];
127
+ if (tsExtensions.includes(ext)) {
128
+ return true;
129
+ }
130
+ // If include is not defined and it's not a TS file, assume it's not a source file
131
+ return false;
132
+ }
133
+ const projectAbsolutePath = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath);
134
+ const relativeToProject = (0, node_path_1.relative)(projectAbsolutePath, normalizedPath);
135
+ for (const pattern of include) {
136
+ if (picomatch(pattern)(relativeToProject)) {
137
+ return true;
138
+ }
139
+ }
140
+ return false;
63
141
  };
64
- // Checks if the value is a path within the `src` directory.
65
142
  const containsInvalidPath = (value) => {
66
143
  if (typeof value === 'string') {
67
144
  return isPathSourceFile(value);
@@ -52,16 +52,19 @@ class CopyAssetsHandler {
52
52
  let input;
53
53
  let output;
54
54
  let ignore = null;
55
+ const resolvedOutputDir = path.isAbsolute(opts.outputDir)
56
+ ? opts.outputDir
57
+ : path.resolve(opts.rootDir, opts.outputDir);
55
58
  if (typeof f === 'string') {
56
59
  pattern = f;
57
60
  input = path.relative(opts.rootDir, opts.projectDir);
58
- output = path.relative(opts.rootDir, opts.outputDir);
61
+ output = path.relative(opts.rootDir, resolvedOutputDir);
59
62
  }
60
63
  else {
61
64
  isGlob = true;
62
65
  pattern = pathPosix.join(f.input, f.glob);
63
66
  input = f.input;
64
- output = pathPosix.join(path.relative(opts.rootDir, opts.outputDir), f.output);
67
+ output = pathPosix.join(path.relative(opts.rootDir, resolvedOutputDir), f.output);
65
68
  if (f.ignore)
66
69
  ignore = f.ignore.map((ig) => pathPosix.join(f.input, ig));
67
70
  }