@nx/js 20.3.0-beta.0 → 20.3.0-beta.1
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 +3 -3
- package/src/generators/library/files/lib/src/index.ts__tmpl__ +1 -1
- package/src/generators/library/library.js +19 -5
- package/src/generators/typescript-sync/typescript-sync.js +1 -1
- package/src/utils/typescript/ts-config.d.ts +1 -0
- package/src/utils/typescript/ts-config.js +11 -0
- package/src/utils/typescript/ts-solution-setup.js +14 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "20.3.0-beta.
|
|
3
|
+
"version": "20.3.0-beta.1",
|
|
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": "20.3.0-beta.
|
|
43
|
-
"@nx/workspace": "20.3.0-beta.
|
|
42
|
+
"@nx/devkit": "20.3.0-beta.1",
|
|
43
|
+
"@nx/workspace": "20.3.0-beta.1",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^2.8.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './lib/<%=
|
|
1
|
+
export * from './lib/<%= fileNameImport %>';
|
|
@@ -22,6 +22,7 @@ const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
|
22
22
|
const versions_1 = require("../../utils/versions");
|
|
23
23
|
const init_1 = require("../init/init");
|
|
24
24
|
const generator_1 = require("../setup-verdaccio/generator");
|
|
25
|
+
const ensure_typescript_1 = require("../../utils/typescript/ensure-typescript");
|
|
25
26
|
const defaultOutputDirectory = 'dist';
|
|
26
27
|
async function libraryGenerator(tree, schema) {
|
|
27
28
|
return await libraryGeneratorInternal(tree, {
|
|
@@ -335,6 +336,19 @@ function addBabelRc(tree, options) {
|
|
|
335
336
|
function createFiles(tree, options) {
|
|
336
337
|
const { className, name, propertyName } = (0, devkit_1.names)(options.projectNames.projectFileName);
|
|
337
338
|
createProjectTsConfigs(tree, options);
|
|
339
|
+
let fileNameImport = options.fileName;
|
|
340
|
+
if (options.bundler === 'vite') {
|
|
341
|
+
const tsConfig = (0, ts_config_1.readTsConfigFromTree)(tree, (0, path_1.join)(options.projectRoot, 'tsconfig.lib.json'));
|
|
342
|
+
const ts = (0, ensure_typescript_1.ensureTypescript)();
|
|
343
|
+
if (tsConfig.options.moduleResolution === ts.ModuleResolutionKind.Node16 ||
|
|
344
|
+
tsConfig.options.moduleResolution === ts.ModuleResolutionKind.NodeNext) {
|
|
345
|
+
// Node16 and NodeNext require explicit file extensions for relative
|
|
346
|
+
// import paths. Since we generate the file with the `.ts` extension,
|
|
347
|
+
// we import it from the same file with the `.js` extension.
|
|
348
|
+
// https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution
|
|
349
|
+
fileNameImport = `${options.fileName}.js`;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
338
352
|
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/lib'), options.projectRoot, {
|
|
339
353
|
...options,
|
|
340
354
|
dot: '.',
|
|
@@ -348,6 +362,7 @@ function createFiles(tree, options) {
|
|
|
348
362
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
349
363
|
buildable: options.bundler && options.bundler !== 'none',
|
|
350
364
|
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
365
|
+
fileNameImport,
|
|
351
366
|
});
|
|
352
367
|
if (!options.rootProject) {
|
|
353
368
|
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/readme'), options.projectRoot, {
|
|
@@ -686,6 +701,9 @@ function createProjectTsConfigs(tree, options) {
|
|
|
686
701
|
.map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`)
|
|
687
702
|
.join(',\n '),
|
|
688
703
|
tmpl: '',
|
|
704
|
+
outDir: options.bundler === 'tsc'
|
|
705
|
+
? 'dist'
|
|
706
|
+
: `out-tsc/${options.projectRoot.split('/').pop()}`,
|
|
689
707
|
});
|
|
690
708
|
// tsconfig.json
|
|
691
709
|
if (options.isUsingTsSolutionConfig) {
|
|
@@ -793,14 +811,10 @@ function determineEntryFields(options) {
|
|
|
793
811
|
};
|
|
794
812
|
case 'vite':
|
|
795
813
|
return {
|
|
796
|
-
|
|
797
|
-
// Bundlers or Node will determine the entry point to use.
|
|
814
|
+
type: 'module',
|
|
798
815
|
main: options.isUsingTsSolutionConfig
|
|
799
816
|
? './dist/index.js'
|
|
800
817
|
: './index.js',
|
|
801
|
-
module: options.isUsingTsSolutionConfig
|
|
802
|
-
? './dist/index.mjs'
|
|
803
|
-
: './index.mjs',
|
|
804
818
|
typings: options.isUsingTsSolutionConfig
|
|
805
819
|
? './dist/index.d.ts'
|
|
806
820
|
: './index.d.ts',
|
|
@@ -325,7 +325,7 @@ function getTsConfigPathFromReferencePath(tree, ownerTsConfigPath, referencePath
|
|
|
325
325
|
*/
|
|
326
326
|
function patchTsconfigJsonReferences(tree, tsconfigInfoCaches, tsconfigPath, updatedReferences) {
|
|
327
327
|
const stringifiedJsonContents = readRawTsconfigContents(tree, tsconfigInfoCaches, tsconfigPath);
|
|
328
|
-
const edits = (0, jsonc_parser_1.modify)(stringifiedJsonContents, ['references'], updatedReferences, { formattingOptions: { keepLines:
|
|
328
|
+
const edits = (0, jsonc_parser_1.modify)(stringifiedJsonContents, ['references'], updatedReferences, { formattingOptions: { keepLines: true, insertSpaces: true, tabSize: 2 } });
|
|
329
329
|
const updatedJsonContents = (0, jsonc_parser_1.applyEdits)(stringifiedJsonContents, edits);
|
|
330
330
|
// The final contents will be formatted by formatFiles() later
|
|
331
331
|
tree.write(tsconfigPath, updatedJsonContents);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
export declare function readTsConfig(tsConfigPath: string, sys?: ts.System): ts.ParsedCommandLine;
|
|
4
|
+
export declare function readTsConfigFromTree(tree: Tree, tsConfigPath: string): ts.ParsedCommandLine;
|
|
4
5
|
export declare function getRootTsConfigPathInTree(tree: Tree): string | null;
|
|
5
6
|
export declare function getRelativePathToRootTsConfig(tree: Tree, targetPath: string): string;
|
|
6
7
|
export declare function getRootTsConfigPath(): string | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readTsConfig = readTsConfig;
|
|
4
|
+
exports.readTsConfigFromTree = readTsConfigFromTree;
|
|
4
5
|
exports.getRootTsConfigPathInTree = getRootTsConfigPathInTree;
|
|
5
6
|
exports.getRelativePathToRootTsConfig = getRelativePathToRootTsConfig;
|
|
6
7
|
exports.getRootTsConfigPath = getRootTsConfigPath;
|
|
@@ -20,6 +21,16 @@ function readTsConfig(tsConfigPath, sys) {
|
|
|
20
21
|
const readResult = tsModule.readConfigFile(tsConfigPath, sys.readFile);
|
|
21
22
|
return tsModule.parseJsonConfigFileContent(readResult.config, sys, (0, path_1.dirname)(tsConfigPath));
|
|
22
23
|
}
|
|
24
|
+
function readTsConfigFromTree(tree, tsConfigPath) {
|
|
25
|
+
if (!tsModule) {
|
|
26
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
27
|
+
}
|
|
28
|
+
const tsSysFromTree = {
|
|
29
|
+
...tsModule.sys,
|
|
30
|
+
readFile: (path) => tree.read(path, 'utf-8'),
|
|
31
|
+
};
|
|
32
|
+
return readTsConfig(tsConfigPath, tsSysFromTree);
|
|
33
|
+
}
|
|
23
34
|
function getRootTsConfigPathInTree(tree) {
|
|
24
35
|
for (const path of ['tsconfig.base.json', 'tsconfig.json']) {
|
|
25
36
|
if (tree.exists(path)) {
|
|
@@ -66,7 +66,7 @@ function assertNotUsingTsSolutionSetup(tree, pluginName, generatorName) {
|
|
|
66
66
|
`We're working hard to support the existing TypeScript setup with the ${artifactString}. We'll soon release a new version of Nx with support for it.`,
|
|
67
67
|
],
|
|
68
68
|
});
|
|
69
|
-
|
|
69
|
+
throw new Error(`The ${artifactString} doesn't yet support the existing TypeScript setup. See the error above.`);
|
|
70
70
|
}
|
|
71
71
|
function findRuntimeTsConfigName(tree, projectRoot) {
|
|
72
72
|
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.app.json')))
|
|
@@ -94,8 +94,20 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
|
|
|
94
94
|
rootDir,
|
|
95
95
|
...compilerOptions,
|
|
96
96
|
};
|
|
97
|
+
if (rootDir && rootDir !== '.') {
|
|
98
|
+
// when rootDir is different from '.', the tsbuildinfo file is output
|
|
99
|
+
// at `<outDir>/<relative path to config from rootDir>/`, so we need
|
|
100
|
+
// to set it explicitly to ensure it's output to the outDir
|
|
101
|
+
// https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile
|
|
102
|
+
json.compilerOptions.tsBuildInfoFile = (0, posix_1.join)('out-tsc', projectRoot.split('/').at(-1), (0, posix_1.basename)(runtimeTsconfigFileName, '.json') + '.tsbuildinfo');
|
|
103
|
+
}
|
|
104
|
+
else if (json.compilerOptions.tsBuildInfoFile) {
|
|
105
|
+
// when rootDir is '.' or not set, it would be output to the outDir, so
|
|
106
|
+
// we don't need to set it explicitly
|
|
107
|
+
delete json.compilerOptions.tsBuildInfoFile;
|
|
108
|
+
}
|
|
97
109
|
const excludeSet = json.exclude
|
|
98
|
-
? new Set(['dist', ...json.exclude, ...exclude])
|
|
110
|
+
? new Set(['out-tsc', 'dist', ...json.exclude, ...exclude])
|
|
99
111
|
: new Set(exclude);
|
|
100
112
|
json.exclude = Array.from(excludeSet);
|
|
101
113
|
return json;
|