@nx/js 18.3.1 → 18.4.0-canary.20240418-e549ea2

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/migrations.json CHANGED
@@ -167,6 +167,15 @@
167
167
  "alwaysAddToPackageJson": false
168
168
  }
169
169
  }
170
+ },
171
+ "19.0.0": {
172
+ "version": "19.0.0-beta.0",
173
+ "packages": {
174
+ "@swc/cli": {
175
+ "version": "~0.3.12",
176
+ "alwaysAddToPackageJson": false
177
+ }
178
+ }
170
179
  }
171
180
  }
172
181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "18.3.1",
3
+ "version": "18.4.0-canary.20240418-e549ea2",
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.3.1",
61
- "@nx/workspace": "18.3.1",
62
- "@nrwl/js": "18.3.1"
60
+ "@nx/devkit": "18.4.0-canary.20240418-e549ea2",
61
+ "@nx/workspace": "18.4.0-canary.20240418-e549ea2",
62
+ "@nrwl/js": "18.4.0-canary.20240418-e549ea2"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "verdaccio": "^5.0.4"
@@ -97,7 +97,8 @@
97
97
  "type": "string"
98
98
  }
99
99
  }
100
- ]
100
+ ],
101
+ "x-deprecated": "Make sure all dependencies are buildable by running `nx g @nx/js:setup-build`. This option will be removed in Nx 20."
101
102
  },
102
103
  "externalBuildTargets": {
103
104
  "type": "array",
@@ -114,6 +115,11 @@
114
115
  "x-priority": "internal"
115
116
  }
116
117
  },
118
+ "stripLeadingPaths": {
119
+ "type": "boolean",
120
+ "description": "Remove leading directory from output (e.g. src). See: https://swc.rs/docs/usage/cli#--strip-leading-paths",
121
+ "default": false
122
+ },
117
123
  "required": ["main", "outputPath", "tsConfig"],
118
124
  "definitions": {
119
125
  "assetPattern": {
@@ -35,19 +35,15 @@ function normalizeOptions(options, root, sourceRoot, projectRoot) {
35
35
  }
36
36
  }
37
37
  const files = (0, assets_1.assetGlobsToFiles)(options.assets, root, outputPath);
38
- const projectRootParts = projectRoot.split('/');
39
- // We pop the last part of the `projectRoot` to pass
40
- // the last part (projectDir) and the remainder (projectRootParts) to swc
41
- const projectDir = projectRootParts.pop();
42
- // default to current directory if projectRootParts is [].
43
- // Eg: when a project is at the root level, outside of layout dir
44
- const swcCwd = projectRootParts.join('/') || '.';
38
+ // Always execute from root of project, same as with SWC CLI.
39
+ const swcCwd = (0, path_1.join)(root, projectRoot);
45
40
  const { swcrcPath, tmpSwcrcPath } = (0, get_swcrc_path_1.getSwcrcPath)(options, root, projectRoot);
46
41
  const swcCliOptions = {
47
- srcPath: projectDir,
48
- destPath: (0, path_1.relative)((0, path_1.join)(root, swcCwd), outputPath),
42
+ srcPath: projectRoot,
43
+ destPath: (0, path_1.relative)(swcCwd, outputPath),
49
44
  swcCwd,
50
45
  swcrcPath,
46
+ stripLeadingPaths: Boolean(options.stripLeadingPaths),
51
47
  };
52
48
  return {
53
49
  ...options,
@@ -76,10 +72,14 @@ async function* swcExecutor(_options, context) {
76
72
  }
77
73
  const inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, options.tsConfig);
78
74
  if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
75
+ if (options.stripLeadingPaths) {
76
+ throw new Error(`Cannot use --strip-leading-paths with inlining.`);
77
+ }
79
78
  options.projectRoot = '.'; // set to root of workspace to include other libs for type check
80
79
  // remap paths for SWC compilation
81
- options.swcCliOptions.srcPath = options.swcCliOptions.swcCwd;
80
+ options.inline = true;
82
81
  options.swcCliOptions.swcCwd = '.';
82
+ options.swcCliOptions.srcPath = options.swcCliOptions.swcCwd;
83
83
  options.swcCliOptions.destPath = (0, path_1.join)(options.swcCliOptions.destPath.split((0, path_1.normalize)('../')).at(-1), options.swcCliOptions.srcPath);
84
84
  // tmp swcrc with dependencies to exclude
85
85
  // - buildable libraries
@@ -85,7 +85,8 @@
85
85
  "type": "string"
86
86
  }
87
87
  }
88
- ]
88
+ ],
89
+ "x-deprecated": "Make sure all dependencies are buildable by running `nx g @nx/js:setup-build`. This option will be removed in Nx 20."
89
90
  },
90
91
  "externalBuildTargets": {
91
92
  "type": "array",
@@ -51,6 +51,7 @@ export interface ExecutorOptions {
51
51
  external?: 'all' | 'none' | string[];
52
52
  externalBuildTargets?: string[];
53
53
  generateLockfile?: boolean;
54
+ stripLeadingPaths?: boolean;
54
55
  }
55
56
 
56
57
  export interface NormalizedExecutorOptions extends ExecutorOptions {
@@ -75,6 +76,7 @@ export interface SwcCliOptions {
75
76
  destPath: string;
76
77
  swcrcPath: string;
77
78
  swcCwd: string;
79
+ stripLeadingPaths: boolean;
78
80
  }
79
81
 
80
82
  export interface NormalizedSwcExecutorOptions
@@ -84,4 +86,7 @@ export interface NormalizedSwcExecutorOptions
84
86
  skipTypeCheck: boolean;
85
87
  swcCliOptions: SwcCliOptions;
86
88
  tmpSwcrcPath: string;
89
+ sourceRoot?: string;
90
+ // TODO(v20): remove inline feature
91
+ inline?: boolean;
87
92
  }
@@ -2,27 +2,50 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compileSwcWatch = exports.compileSwc = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const child_process_1 = require("child_process");
5
+ const node_child_process_1 = require("node:child_process");
6
+ const node_path_1 = require("node:path");
6
7
  const fs_extra_1 = require("fs-extra");
7
8
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
8
9
  const print_diagnostics_1 = require("../typescript/print-diagnostics");
9
10
  const run_type_check_1 = require("../typescript/run-type-check");
10
- function getSwcCmd({ swcrcPath, srcPath, destPath }, watch = false) {
11
+ const path_1 = require("path");
12
+ function getSwcCmd({ swcCliOptions: { swcrcPath, destPath, stripLeadingPaths }, root, projectRoot, originalProjectRoot, sourceRoot, inline, }, watch = false) {
11
13
  const swcCLI = require.resolve('@swc/cli/bin/swc.js');
12
- let swcCmd = `node ${swcCLI} ${
13
- // TODO(jack): clean this up when we remove inline module support
14
- // Handle root project
15
- srcPath === '.' ? 'src' : srcPath} -d ${srcPath === '.' ? `${destPath}/src` : destPath} --config-file=${swcrcPath}`;
14
+ let inputDir;
15
+ // TODO(v20): remove inline feature
16
+ if (inline) {
17
+ inputDir = originalProjectRoot.split('/')[0];
18
+ }
19
+ else {
20
+ if (sourceRoot) {
21
+ inputDir = (0, path_1.relative)(projectRoot, sourceRoot);
22
+ }
23
+ else {
24
+ // If sourceRoot is not provided, check if `src` exists and use that instead.
25
+ // This is important for root projects to avoid compiling too many directories.
26
+ inputDir = (0, fs_extra_1.existsSync)((0, node_path_1.join)(root, projectRoot, 'src')) ? 'src' : '.';
27
+ }
28
+ }
29
+ let swcCmd = `node ${swcCLI} ${inputDir || '.'} -d ${destPath} --config-file=${swcrcPath} ${stripLeadingPaths ? '--strip-leading-paths' : ''}`;
16
30
  return watch ? swcCmd.concat(' --watch') : swcCmd;
17
31
  }
18
32
  function getTypeCheckOptions(normalizedOptions) {
19
- const { projectRoot, watch, tsConfig, root, outputPath } = normalizedOptions;
33
+ const { sourceRoot, projectRoot, watch, tsConfig, root, outputPath } = normalizedOptions;
34
+ const inputDir =
35
+ // If `--strip-leading-paths` SWC option is used, we need to transpile from `src` directory.
36
+ !normalizedOptions.swcCliOptions.stripLeadingPaths
37
+ ? projectRoot
38
+ : sourceRoot
39
+ ? sourceRoot
40
+ : (0, fs_extra_1.existsSync)((0, node_path_1.join)(root, projectRoot, 'src'))
41
+ ? (0, node_path_1.join)(projectRoot, 'src')
42
+ : projectRoot;
20
43
  const typeCheckOptions = {
21
44
  mode: 'emitDeclarationOnly',
22
45
  tsConfigPath: tsConfig,
23
46
  outDir: outputPath,
24
47
  workspaceRoot: root,
25
- rootDir: projectRoot,
48
+ rootDir: inputDir,
26
49
  };
27
50
  if (watch) {
28
51
  typeCheckOptions.incremental = true;
@@ -35,7 +58,7 @@ async function compileSwc(context, normalizedOptions, postCompilationCallback) {
35
58
  if (normalizedOptions.clean) {
36
59
  (0, fs_extra_1.removeSync)(normalizedOptions.outputPath);
37
60
  }
38
- const swcCmdLog = (0, child_process_1.execSync)(getSwcCmd(normalizedOptions.swcCliOptions), {
61
+ const swcCmdLog = (0, node_child_process_1.execSync)(getSwcCmd(normalizedOptions), {
39
62
  encoding: 'utf8',
40
63
  cwd: normalizedOptions.swcCliOptions.swcCwd,
41
64
  });
@@ -73,7 +96,9 @@ async function* compileSwcWatch(context, normalizedOptions, postCompilationCallb
73
96
  let stdoutOnData;
74
97
  let stderrOnData;
75
98
  let watcherOnExit;
76
- const swcWatcher = (0, child_process_1.exec)(getSwcCmd(normalizedOptions.swcCliOptions, true), { cwd: normalizedOptions.swcCliOptions.swcCwd });
99
+ const swcWatcher = (0, node_child_process_1.exec)(getSwcCmd(normalizedOptions, true), {
100
+ cwd: normalizedOptions.swcCliOptions.swcCwd,
101
+ });
77
102
  processOnExit = () => {
78
103
  swcWatcher.kill();
79
104
  done();
@@ -1,7 +1,7 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const esbuildVersion = "^0.19.2";
3
3
  export declare const prettierVersion = "^2.6.2";
4
- export declare const swcCliVersion = "~0.1.62";
4
+ export declare const swcCliVersion = "~0.3.12";
5
5
  export declare const swcCoreVersion = "~1.3.85";
6
6
  export declare const swcHelpersVersion = "~0.5.2";
7
7
  export declare const swcNodeVersion = "~1.8.0";
@@ -4,7 +4,7 @@ exports.supportedTypescriptVersions = exports.typescriptVersion = exports.verdac
4
4
  exports.nxVersion = require('../../package.json').version;
5
5
  exports.esbuildVersion = '^0.19.2';
6
6
  exports.prettierVersion = '^2.6.2';
7
- exports.swcCliVersion = '~0.1.62';
7
+ exports.swcCliVersion = '~0.3.12';
8
8
  exports.swcCoreVersion = '~1.3.85';
9
9
  exports.swcHelpersVersion = '~0.5.2';
10
10
  exports.swcNodeVersion = '~1.8.0';