@nx/js 23.0.0-beta.15 → 23.0.0-beta.16
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/dist/internal.d.ts +2 -1
- package/dist/internal.js +9 -2
- package/dist/src/executors/node/lib/detect-module-format.d.ts +2 -1
- package/dist/src/executors/node/lib/detect-module-format.js +7 -23
- package/dist/src/generators/init/init.js +8 -4
- package/dist/src/utils/module-format/is-esm-project.d.ts +16 -0
- package/dist/src/utils/module-format/is-esm-project.js +32 -0
- package/dist/src/utils/module-format/module-format.d.ts +17 -0
- package/dist/src/utils/module-format/module-format.js +43 -0
- package/package.json +4 -4
package/dist/internal.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { registerTsProject, registerTsConfigPaths, } from 'nx/src/plugins/js/utils/register';
|
|
1
|
+
export { forceRegisterEsmLoader, loadTsFile, registerTsProject, registerTsConfigPaths, requireWithTsconfigFallback, } from 'nx/src/plugins/js/utils/register';
|
|
2
2
|
export { TargetProjectLocator, isBuiltinModuleImport, } from 'nx/src/plugins/js/project-graph/build-dependencies/target-project-locator';
|
|
3
3
|
export { findProjectsNpmDependencies } from 'nx/src/plugins/js/package-json/create-package-json';
|
|
4
4
|
export { walkTsconfigExtendsChain, type RawTsconfigJsonCache, } from './src/utils/typescript/raw-tsconfig';
|
|
5
|
+
export { isEsmProject } from './src/utils/module-format/is-esm-project';
|
|
5
6
|
export { TS_SOLUTION_SETUP_TSCONFIG_INPUT, addProjectToTsSolutionWorkspace, assertNotUsingTsSolutionSetup, findRuntimeTsConfigName, getDefinedCustomConditionName, getProjectSourceRoot, getProjectType, isUsingTsSolutionSetup, shouldConfigureTsSolutionSetup, updateTsconfigFiles, } from './src/utils/typescript/ts-solution-setup';
|
|
6
7
|
export { ensureTypescript } from './src/utils/typescript/ensure-typescript';
|
|
7
8
|
export { getNeededCompilerOptionOverrides } from './src/utils/typescript/configuration';
|
package/dist/internal.js
CHANGED
|
@@ -5,13 +5,16 @@
|
|
|
5
5
|
// internal consumers and may change without semver protection. Consider it
|
|
6
6
|
// the @nx/js equivalent of `@nx/devkit/internal`.
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
9
|
-
exports.typesNodeVersion = exports.tsLibVersion = exports.swcNodeVersion = void 0;
|
|
8
|
+
exports.esbuildVersion = exports.nxVersion = exports.releaseTasks = exports.addReleaseConfigForTsSolution = exports.addReleaseConfigForNonTsSolution = exports.addLocalRegistryScripts = exports.stripGlobToBaseDir = exports.getImportPath = exports.createGlobPatternsForDependencies = exports.normalizeUnitTestRunnerOption = exports.normalizeLinterOption = exports.isValidPackageJsonBuildConfig = exports.addBuildAndWatchDepsTargets = exports.findNpmDependencies = exports.getProjectPackageManagerWorkspaceStateWarningTask = exports.getProjectPackageManagerWorkspaceState = exports.getNpmScope = exports.sortPackageJsonFields = exports.CopyAssetsHandler = exports.addSwcRegisterDependencies = exports.addSwcDependencies = exports.addSwcTestConfig = exports.addSwcConfig = exports.createTmpTsConfig = exports.computeCompilerOptionsPaths = exports.calculateProjectDependencies = exports.calculateProjectBuildableDependencies = exports.compileTypeScript = exports.getNeededCompilerOptionOverrides = exports.ensureTypescript = exports.updateTsconfigFiles = exports.shouldConfigureTsSolutionSetup = exports.isUsingTsSolutionSetup = exports.getProjectType = exports.getProjectSourceRoot = exports.getDefinedCustomConditionName = exports.findRuntimeTsConfigName = exports.assertNotUsingTsSolutionSetup = exports.addProjectToTsSolutionWorkspace = exports.TS_SOLUTION_SETUP_TSCONFIG_INPUT = exports.isEsmProject = exports.walkTsconfigExtendsChain = exports.findProjectsNpmDependencies = exports.isBuiltinModuleImport = exports.TargetProjectLocator = exports.requireWithTsconfigFallback = exports.registerTsConfigPaths = exports.registerTsProject = exports.loadTsFile = exports.forceRegisterEsmLoader = void 0;
|
|
9
|
+
exports.typesNodeVersion = exports.tsLibVersion = exports.swcNodeVersion = exports.swcHelpersVersion = exports.swcCoreVersion = exports.swcCliVersion = exports.prettierVersion = void 0;
|
|
10
10
|
// Re-exports of nx-source internals (need `no-restricted-imports` overrides).
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
12
12
|
var register_1 = require("nx/src/plugins/js/utils/register");
|
|
13
|
+
Object.defineProperty(exports, "forceRegisterEsmLoader", { enumerable: true, get: function () { return register_1.forceRegisterEsmLoader; } });
|
|
14
|
+
Object.defineProperty(exports, "loadTsFile", { enumerable: true, get: function () { return register_1.loadTsFile; } });
|
|
13
15
|
Object.defineProperty(exports, "registerTsProject", { enumerable: true, get: function () { return register_1.registerTsProject; } });
|
|
14
16
|
Object.defineProperty(exports, "registerTsConfigPaths", { enumerable: true, get: function () { return register_1.registerTsConfigPaths; } });
|
|
17
|
+
Object.defineProperty(exports, "requireWithTsconfigFallback", { enumerable: true, get: function () { return register_1.requireWithTsconfigFallback; } });
|
|
15
18
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
16
19
|
var target_project_locator_1 = require("nx/src/plugins/js/project-graph/build-dependencies/target-project-locator");
|
|
17
20
|
Object.defineProperty(exports, "TargetProjectLocator", { enumerable: true, get: function () { return target_project_locator_1.TargetProjectLocator; } });
|
|
@@ -22,6 +25,10 @@ Object.defineProperty(exports, "findProjectsNpmDependencies", { enumerable: true
|
|
|
22
25
|
// Raw tsconfig walkers (the other AST utils ship via the public @nx/js entry)
|
|
23
26
|
var raw_tsconfig_1 = require("./src/utils/typescript/raw-tsconfig");
|
|
24
27
|
Object.defineProperty(exports, "walkTsconfigExtendsChain", { enumerable: true, get: function () { return raw_tsconfig_1.walkTsconfigExtendsChain; } });
|
|
28
|
+
// Module-format detection for generators (project package.json `type` field +
|
|
29
|
+
// TS solution awareness; mirrors Node's nearest-package.json semantics).
|
|
30
|
+
var is_esm_project_1 = require("./src/utils/module-format/is-esm-project");
|
|
31
|
+
Object.defineProperty(exports, "isEsmProject", { enumerable: true, get: function () { return is_esm_project_1.isEsmProject; } });
|
|
25
32
|
// TS solution setup detection
|
|
26
33
|
var ts_solution_setup_1 = require("./src/utils/typescript/ts-solution-setup");
|
|
27
34
|
Object.defineProperty(exports, "TS_SOLUTION_SETUP_TSCONFIG_INPUT", { enumerable: true, get: function () { return ts_solution_setup_1.TS_SOLUTION_SETUP_TSCONFIG_INPUT; } });
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.detectModuleFormat = detectModuleFormat;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const fs_1 = require("fs");
|
|
7
6
|
const path_1 = require("path");
|
|
8
7
|
const ts_config_1 = require("../../../utils/typescript/ts-config");
|
|
9
|
-
const
|
|
8
|
+
const module_format_1 = require("../../../utils/module-format/module-format");
|
|
10
9
|
function detectModuleFormat(options) {
|
|
11
10
|
if (options.buildOptions?.format) {
|
|
12
11
|
const formats = Array.isArray(options.buildOptions.format)
|
|
@@ -28,13 +27,9 @@ function detectModuleFormat(options) {
|
|
|
28
27
|
const packageJsonPath = (0, path_1.join)(options.workspaceRoot, options.projectRoot, 'package.json');
|
|
29
28
|
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
30
29
|
try {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
if (packageJson.type === 'commonjs') {
|
|
36
|
-
return 'cjs';
|
|
37
|
-
}
|
|
30
|
+
const fmt = (0, module_format_1.getPackageJsonModuleFormat)((0, devkit_1.readJsonFile)(packageJsonPath));
|
|
31
|
+
if (fmt)
|
|
32
|
+
return fmt;
|
|
38
33
|
}
|
|
39
34
|
catch {
|
|
40
35
|
// Continue to next detection method
|
|
@@ -42,20 +37,9 @@ function detectModuleFormat(options) {
|
|
|
42
37
|
}
|
|
43
38
|
if (options.tsConfig && (0, fs_1.existsSync)(options.tsConfig)) {
|
|
44
39
|
try {
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
tsConfig.options.module === ts.ModuleKind.ES2022 ||
|
|
49
|
-
tsConfig.options.module === ts.ModuleKind.ESNext ||
|
|
50
|
-
tsConfig.options.module === ts.ModuleKind.NodeNext) {
|
|
51
|
-
// For NodeNext, we need to check moduleResolution
|
|
52
|
-
if (tsConfig.options.module === ts.ModuleKind.NodeNext) {
|
|
53
|
-
// NodeNext uses package.json type field, which we already checked
|
|
54
|
-
// Default to CJS if no type field
|
|
55
|
-
return 'cjs';
|
|
56
|
-
}
|
|
57
|
-
return 'esm';
|
|
58
|
-
}
|
|
40
|
+
const fmt = (0, module_format_1.getTsConfigModuleFormat)((0, ts_config_1.readTsConfig)(options.tsConfig).options);
|
|
41
|
+
if (fmt)
|
|
42
|
+
return fmt;
|
|
59
43
|
}
|
|
60
44
|
catch {
|
|
61
45
|
// Continue to default
|
|
@@ -99,12 +99,16 @@ async function initGeneratorInternal(tree, schema) {
|
|
|
99
99
|
}
|
|
100
100
|
const devDependencies = {
|
|
101
101
|
'@nx/js': versions_1.nxVersion,
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
// Required by SWC-compiled output (decorators -> @swc/helpers/_/_ts_decorate
|
|
103
|
+
// imports). The default @nx/jest setup transforms with @swc/jest, so any
|
|
104
|
+
// workspace using decorators (NestJS, Angular, etc.) needs @swc/helpers
|
|
105
|
+
// resolvable at test time. Cheap to ship and avoids per-generator install.
|
|
106
106
|
'@swc/helpers': versions_1.swcHelpersVersion,
|
|
107
107
|
};
|
|
108
|
+
// @swc-node/register and @swc/core are no longer installed by init - native
|
|
109
|
+
// Node.js type stripping handles .ts config loading on Node 23+ (or 22.6+
|
|
110
|
+
// with --experimental-strip-types). loadTsFile registers swc/ts-node lazily
|
|
111
|
+
// when a config uses syntax native strip can't handle.
|
|
108
112
|
if (!schema.js && !schema.keepExistingVersions) {
|
|
109
113
|
const installedTsVersion = await getInstalledTypescriptVersion(tree);
|
|
110
114
|
if (!installedTsVersion ||
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* Determine whether a project should be treated as ESM for the purpose of
|
|
4
|
+
* emitting `.ts` config and source files (e.g. choosing between
|
|
5
|
+
* `__filename`/`__dirname` and `import.meta.dirname`, or `require()` and
|
|
6
|
+
* `import` for sibling subpath imports).
|
|
7
|
+
*
|
|
8
|
+
* Mirrors Node's package.json `type` resolution: the **closest**
|
|
9
|
+
* package.json with a recognized `type` field wins.
|
|
10
|
+
*
|
|
11
|
+
* Resolution order:
|
|
12
|
+
* 1. The project's package.json `type`, if present and recognized.
|
|
13
|
+
* 2. The workspace-root package.json `type`, if present and recognized.
|
|
14
|
+
* 3. Default: `false` (CJS).
|
|
15
|
+
*/
|
|
16
|
+
export declare function isEsmProject(tree: Tree, projectRoot: string): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEsmProject = isEsmProject;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const module_format_1 = require("./module-format");
|
|
6
|
+
/**
|
|
7
|
+
* Determine whether a project should be treated as ESM for the purpose of
|
|
8
|
+
* emitting `.ts` config and source files (e.g. choosing between
|
|
9
|
+
* `__filename`/`__dirname` and `import.meta.dirname`, or `require()` and
|
|
10
|
+
* `import` for sibling subpath imports).
|
|
11
|
+
*
|
|
12
|
+
* Mirrors Node's package.json `type` resolution: the **closest**
|
|
13
|
+
* package.json with a recognized `type` field wins.
|
|
14
|
+
*
|
|
15
|
+
* Resolution order:
|
|
16
|
+
* 1. The project's package.json `type`, if present and recognized.
|
|
17
|
+
* 2. The workspace-root package.json `type`, if present and recognized.
|
|
18
|
+
* 3. Default: `false` (CJS).
|
|
19
|
+
*/
|
|
20
|
+
function isEsmProject(tree, projectRoot) {
|
|
21
|
+
const projectPackageJsonPath = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
|
|
22
|
+
if (tree.exists(projectPackageJsonPath)) {
|
|
23
|
+
const projectFmt = (0, module_format_1.getPackageJsonModuleFormat)((0, devkit_1.readJson)(tree, projectPackageJsonPath));
|
|
24
|
+
// Only honor an explicit type field; fall through to workspace when
|
|
25
|
+
// unset so we match Node's "walk up to nearest type field" behavior.
|
|
26
|
+
if (projectFmt !== null) {
|
|
27
|
+
return projectFmt === 'esm';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const workspaceFmt = (0, module_format_1.getPackageJsonModuleFormat)((0, devkit_1.readJson)(tree, 'package.json'));
|
|
31
|
+
return workspaceFmt === 'esm';
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
export type ModuleFormat = 'cjs' | 'esm';
|
|
3
|
+
/**
|
|
4
|
+
* Decide module format from a parsed package.json `type` field alone.
|
|
5
|
+
* Returns `null` when the field is unset or holds an unrecognized value -
|
|
6
|
+
* callers can then fall back to other signals (tsconfig, defaults).
|
|
7
|
+
*/
|
|
8
|
+
export declare function getPackageJsonModuleFormat(packageJson: {
|
|
9
|
+
type?: string;
|
|
10
|
+
} | null | undefined): ModuleFormat | null;
|
|
11
|
+
/**
|
|
12
|
+
* Decide module format from tsconfig compiler options' `module` setting.
|
|
13
|
+
* Returns `null` when the setting is unset OR when it is `NodeNext` /
|
|
14
|
+
* `Node16` (those defer to the package.json `type` field, so the caller
|
|
15
|
+
* should have already checked package.json).
|
|
16
|
+
*/
|
|
17
|
+
export declare function getTsConfigModuleFormat(compilerOptions: ts.CompilerOptions | null | undefined): ModuleFormat | null;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPackageJsonModuleFormat = getPackageJsonModuleFormat;
|
|
4
|
+
exports.getTsConfigModuleFormat = getTsConfigModuleFormat;
|
|
5
|
+
/**
|
|
6
|
+
* Decide module format from a parsed package.json `type` field alone.
|
|
7
|
+
* Returns `null` when the field is unset or holds an unrecognized value -
|
|
8
|
+
* callers can then fall back to other signals (tsconfig, defaults).
|
|
9
|
+
*/
|
|
10
|
+
function getPackageJsonModuleFormat(packageJson) {
|
|
11
|
+
if (!packageJson)
|
|
12
|
+
return null;
|
|
13
|
+
if (packageJson.type === 'module')
|
|
14
|
+
return 'esm';
|
|
15
|
+
if (packageJson.type === 'commonjs')
|
|
16
|
+
return 'cjs';
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Decide module format from tsconfig compiler options' `module` setting.
|
|
21
|
+
* Returns `null` when the setting is unset OR when it is `NodeNext` /
|
|
22
|
+
* `Node16` (those defer to the package.json `type` field, so the caller
|
|
23
|
+
* should have already checked package.json).
|
|
24
|
+
*/
|
|
25
|
+
function getTsConfigModuleFormat(compilerOptions) {
|
|
26
|
+
const m = compilerOptions?.module;
|
|
27
|
+
if (m === undefined)
|
|
28
|
+
return null;
|
|
29
|
+
// Lazy-require typescript so importing this module (e.g. via
|
|
30
|
+
// @nx/js/internal -> is-esm-project) doesn't fail in workspaces that
|
|
31
|
+
// haven't installed typescript yet (fresh CNW projects before a
|
|
32
|
+
// generator adds it).
|
|
33
|
+
const tsMod = require('typescript');
|
|
34
|
+
if (m === tsMod.ModuleKind.NodeNext || m === tsMod.ModuleKind.Node16)
|
|
35
|
+
return null;
|
|
36
|
+
if (m === tsMod.ModuleKind.ES2015 ||
|
|
37
|
+
m === tsMod.ModuleKind.ES2020 ||
|
|
38
|
+
m === tsMod.ModuleKind.ES2022 ||
|
|
39
|
+
m === tsMod.ModuleKind.ESNext) {
|
|
40
|
+
return 'esm';
|
|
41
|
+
}
|
|
42
|
+
return 'cjs';
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "23.0.0-beta.
|
|
3
|
+
"version": "23.0.0-beta.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -136,11 +136,11 @@
|
|
|
136
136
|
"source-map-support": "0.5.19",
|
|
137
137
|
"tinyglobby": "^0.2.12",
|
|
138
138
|
"tslib": "^2.3.0",
|
|
139
|
-
"@nx/
|
|
140
|
-
"@nx/
|
|
139
|
+
"@nx/devkit": "23.0.0-beta.16",
|
|
140
|
+
"@nx/workspace": "23.0.0-beta.16"
|
|
141
141
|
},
|
|
142
142
|
"devDependencies": {
|
|
143
|
-
"nx": "23.0.0-beta.
|
|
143
|
+
"nx": "23.0.0-beta.16"
|
|
144
144
|
},
|
|
145
145
|
"peerDependencies": {
|
|
146
146
|
"verdaccio": "^6.0.5"
|