@nx/js 20.0.0-beta.3 → 20.0.0-beta.5
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/generators.json +1 -1
- package/package.json +5 -5
- package/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ +34 -0
- package/src/generators/init/files/ts-solution/tsconfig.json__tmpl__ +6 -0
- package/src/generators/init/init.js +41 -7
- package/src/generators/init/schema.d.ts +4 -1
- package/src/generators/init/schema.json +6 -6
- package/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +4 -4
- package/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +1 -1
- package/src/generators/library/files/readme/README.md +3 -11
- package/src/generators/library/files/tsconfig-lib/ts-solution/tsconfig.lib.json__tmpl__ +14 -0
- package/src/generators/library/library.d.ts +2 -11
- package/src/generators/library/library.js +295 -74
- package/src/generators/library/schema.d.ts +53 -0
- package/src/generators/library/schema.json +18 -17
- package/src/generators/library/utils/package-manager-workspaces.d.ts +3 -0
- package/src/generators/library/utils/package-manager-workspaces.js +52 -0
- package/src/generators/library/utils/plugin-registrations.d.ts +3 -0
- package/src/generators/library/utils/plugin-registrations.js +108 -0
- package/src/generators/setup-verdaccio/generator.js +14 -10
- package/src/generators/typescript-sync/typescript-sync.d.ts +1 -1
- package/src/generators/typescript-sync/typescript-sync.js +9 -8
- package/src/plugins/typescript/plugin.js +8 -0
- package/src/utils/find-npm-dependencies.js +12 -0
- package/src/utils/package-manager-workspaces.d.ts +4 -0
- package/src/utils/package-manager-workspaces.js +19 -0
- package/src/utils/prettier.d.ts +1 -0
- package/src/utils/prettier.js +53 -0
- package/src/utils/schema.d.ts +0 -32
- package/src/utils/swc/add-swc-dependencies.d.ts +4 -0
- package/src/utils/swc/add-swc-dependencies.js +11 -4
- package/src/utils/typescript/configuration.d.ts +7 -0
- package/src/utils/typescript/configuration.js +64 -0
- package/src/utils/typescript/ts-solution-setup.d.ts +3 -0
- package/src/utils/typescript/ts-solution-setup.js +48 -0
- /package/src/generators/init/files/{__fileName__ → non-ts-solution/__fileName__} +0 -0
- /package/src/generators/library/files/{lib → tsconfig-lib/non-ts-solution}/tsconfig.lib.json__tmpl__ +0 -0
package/generators.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"description": "Create a library"
|
|
11
11
|
},
|
|
12
12
|
"init": {
|
|
13
|
-
"factory": "./src/generators/init/init#
|
|
13
|
+
"factory": "./src/generators/init/init#initGeneratorInternal",
|
|
14
14
|
"schema": "./src/generators/init/schema.json",
|
|
15
15
|
"aliases": ["lib"],
|
|
16
16
|
"x-type": "init",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "20.0.0-beta.
|
|
3
|
+
"version": "20.0.0-beta.5",
|
|
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,9 @@
|
|
|
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.0.0-beta.
|
|
43
|
-
"@nx/workspace": "20.0.0-beta.
|
|
42
|
+
"@nx/devkit": "20.0.0-beta.5",
|
|
43
|
+
"@nx/workspace": "20.0.0-beta.5",
|
|
44
|
+
"@zkochan/js-yaml": "0.0.7",
|
|
44
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
45
46
|
"babel-plugin-macros": "^2.8.0",
|
|
46
47
|
"babel-plugin-transform-typescript-metadata": "^0.3.1",
|
|
@@ -60,8 +61,7 @@
|
|
|
60
61
|
"source-map-support": "0.5.19",
|
|
61
62
|
"ts-node": "10.9.1",
|
|
62
63
|
"tsconfig-paths": "^4.1.2",
|
|
63
|
-
"tslib": "^2.3.0"
|
|
64
|
-
"@nrwl/js": "20.0.0-beta.3"
|
|
64
|
+
"tslib": "^2.3.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"verdaccio": "^5.0.4"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": false,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"composite": true,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"emitDeclarationOnly": true,
|
|
9
|
+
"emitDecoratorMetadata": false,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"experimentalDecorators": false,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"importHelpers": true,
|
|
14
|
+
"incremental": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"lib": ["es2022"],
|
|
17
|
+
"module": "NodeNext",
|
|
18
|
+
"moduleResolution": "NodeNext",
|
|
19
|
+
"noEmitOnError": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noImplicitOverride": true,
|
|
22
|
+
"noImplicitReturns": true,
|
|
23
|
+
"noUnusedLocals": true,
|
|
24
|
+
"pretty": true,
|
|
25
|
+
"removeComments": false,
|
|
26
|
+
"resolveJsonModule": false,
|
|
27
|
+
"skipDefaultLibCheck": false,
|
|
28
|
+
"skipLibCheck": true,
|
|
29
|
+
"sourceMap": false,
|
|
30
|
+
"strict": true,
|
|
31
|
+
"target": "es2022",
|
|
32
|
+
"verbatimModuleSyntax": false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.initGenerator = initGenerator;
|
|
4
4
|
exports.initGeneratorInternal = initGeneratorInternal;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
|
|
6
7
|
const semver_1 = require("@nx/devkit/src/utils/semver");
|
|
7
8
|
const package_json_1 = require("nx/src/utils/package-json");
|
|
8
9
|
const path_1 = require("path");
|
|
9
10
|
const semver_2 = require("semver");
|
|
11
|
+
const plugin_1 = require("../../plugins/typescript/plugin");
|
|
10
12
|
const prettier_1 = require("../../utils/prettier");
|
|
11
13
|
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
14
|
+
const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
12
15
|
const versions_1 = require("../../utils/versions");
|
|
13
16
|
async function getInstalledTypescriptVersion(tree) {
|
|
14
17
|
const rootPackageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
@@ -37,19 +40,47 @@ async function getInstalledTypescriptVersion(tree) {
|
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
async function initGenerator(tree, schema) {
|
|
43
|
+
schema.addTsPlugin ??= false;
|
|
44
|
+
const isUsingNewTsSetup = schema.addTsPlugin || (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
45
|
+
schema.formatter ??= isUsingNewTsSetup ? 'none' : 'prettier';
|
|
40
46
|
return initGeneratorInternal(tree, {
|
|
41
47
|
addTsConfigBase: true,
|
|
42
|
-
setUpPrettier: true,
|
|
43
48
|
...schema,
|
|
44
49
|
});
|
|
45
50
|
}
|
|
46
51
|
async function initGeneratorInternal(tree, schema) {
|
|
47
52
|
const tasks = [];
|
|
48
|
-
|
|
53
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
54
|
+
schema.addPlugin ??=
|
|
55
|
+
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
56
|
+
nxJson.useInferencePlugins !== false;
|
|
57
|
+
schema.addTsPlugin ??=
|
|
58
|
+
schema.addPlugin && process.env.NX_ADD_TS_PLUGIN === 'true';
|
|
59
|
+
if (schema.addTsPlugin) {
|
|
60
|
+
await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/js/typescript', plugin_1.createNodesV2, {
|
|
61
|
+
typecheck: [
|
|
62
|
+
{ targetName: 'typecheck' },
|
|
63
|
+
{ targetName: 'tsc:typecheck' },
|
|
64
|
+
{ targetName: 'tsc-typecheck' },
|
|
65
|
+
],
|
|
66
|
+
build: [
|
|
67
|
+
{ targetName: 'build', configName: 'tsconfig.lib.json' },
|
|
68
|
+
{ targetName: 'tsc:build', configName: 'tsconfig.lib.json' },
|
|
69
|
+
{ targetName: 'tsc-build', configName: 'tsconfig.lib.json' },
|
|
70
|
+
],
|
|
71
|
+
}, schema.updatePackageScripts);
|
|
72
|
+
}
|
|
49
73
|
if (schema.addTsConfigBase && !(0, ts_config_1.getRootTsConfigFileName)(tree)) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
74
|
+
if (schema.addTsPlugin) {
|
|
75
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/ts-solution'), '.', {
|
|
76
|
+
tmpl: '',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/non-ts-solution'), '.', {
|
|
81
|
+
fileName: schema.tsConfigName ?? 'tsconfig.base.json',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
53
84
|
}
|
|
54
85
|
const devDependencies = {
|
|
55
86
|
'@nx/js': versions_1.nxVersion,
|
|
@@ -68,7 +99,7 @@ async function initGeneratorInternal(tree, schema) {
|
|
|
68
99
|
devDependencies['typescript'] = versions_1.typescriptVersion;
|
|
69
100
|
}
|
|
70
101
|
}
|
|
71
|
-
if (schema.
|
|
102
|
+
if (schema.formatter === 'prettier') {
|
|
72
103
|
const prettierTask = (0, prettier_1.generatePrettierSetup)(tree, {
|
|
73
104
|
skipPackageJson: schema.skipPackageJson,
|
|
74
105
|
});
|
|
@@ -87,7 +118,10 @@ async function initGeneratorInternal(tree, schema) {
|
|
|
87
118
|
? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions)
|
|
88
119
|
: () => { };
|
|
89
120
|
tasks.push(installTask);
|
|
90
|
-
if (!schema.skipPackageJson &&
|
|
121
|
+
if (!schema.skipPackageJson &&
|
|
122
|
+
// For `create-nx-workspace` or `nx g @nx/js:init`, we want to make sure users didn't set formatter to none.
|
|
123
|
+
// For programmatic usage, the formatter is normally undefined, and we want prettier to continue to be ensured, even if not ultimately installed.
|
|
124
|
+
schema.formatter !== 'none') {
|
|
91
125
|
(0, devkit_1.ensurePackage)('prettier', versions_1.prettierVersion);
|
|
92
126
|
}
|
|
93
127
|
if (!schema.skipFormat) {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export interface InitSchema {
|
|
2
2
|
addTsConfigBase?: boolean;
|
|
3
|
+
formatter?: 'none' | 'prettier';
|
|
3
4
|
js?: boolean;
|
|
4
5
|
keepExistingVersions?: boolean;
|
|
5
|
-
setUpPrettier?: boolean;
|
|
6
6
|
skipFormat?: boolean;
|
|
7
7
|
skipPackageJson?: boolean;
|
|
8
8
|
tsConfigName?: string;
|
|
9
|
+
addPlugin?: boolean;
|
|
10
|
+
updatePackageScripts?: boolean;
|
|
11
|
+
addTsPlugin?: boolean;
|
|
9
12
|
}
|
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
"title": "Init nx/js",
|
|
6
6
|
"description": "Init generator placeholder for nx/js.",
|
|
7
7
|
"properties": {
|
|
8
|
+
"formatter": {
|
|
9
|
+
"description": "The tool to use for code formatting.",
|
|
10
|
+
"type": "string",
|
|
11
|
+
"enum": ["none", "prettier"],
|
|
12
|
+
"default": "none"
|
|
13
|
+
},
|
|
8
14
|
"js": {
|
|
9
15
|
"type": "boolean",
|
|
10
16
|
"default": false,
|
|
@@ -37,12 +43,6 @@
|
|
|
37
43
|
"type": "string",
|
|
38
44
|
"description": "Customize the generated base tsconfig file name.",
|
|
39
45
|
"x-priority": "internal"
|
|
40
|
-
},
|
|
41
|
-
"setUpPrettier": {
|
|
42
|
-
"type": "boolean",
|
|
43
|
-
"description": "Add Prettier and corresponding configuration files.",
|
|
44
|
-
"x-priority": "internal",
|
|
45
|
-
"default": false
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { <%= propertyName %> } from './<%= fileName %>';
|
|
2
2
|
|
|
3
3
|
describe('<%= propertyName %>', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})
|
|
4
|
+
it('should work', () => {
|
|
5
|
+
expect(<%= propertyName %>()).toEqual('<%= name %>');
|
|
6
|
+
})
|
|
7
|
+
})
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
# <%= name %>
|
|
2
2
|
|
|
3
|
-
This library was generated with [Nx](https://nx.dev)
|
|
4
|
-
|
|
5
|
-
<% if (buildable) { %>
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).<% if (buildable) { %>
|
|
6
4
|
|
|
7
5
|
## Building
|
|
8
6
|
|
|
9
|
-
Run `<%= cliCommand %> build <%= name %>` to build the library
|
|
10
|
-
|
|
11
|
-
<% } %>
|
|
12
|
-
|
|
13
|
-
<% if (hasUnitTestRunner) { %>
|
|
7
|
+
Run `<%= cliCommand %> build <%= name %>` to build the library.<% } %><% if (unitTestRunner !== 'none') { %>
|
|
14
8
|
|
|
15
9
|
## Running unit tests
|
|
16
10
|
|
|
17
|
-
Run `<%= cliCommand %> test <%= name %>` to execute the unit tests via <% if(unitTestRunner === 'jest') { %>[Jest](https://jestjs.io)<% } else { %>[Vitest](https://vitest.dev/)<% }
|
|
18
|
-
|
|
19
|
-
<% } %>
|
|
11
|
+
Run `<%= cliCommand %> test <%= name %>` to execute the unit tests via <% if(unitTestRunner === 'jest') { %>[Jest](https://jestjs.io)<% } else { %>[Vitest](https://vitest.dev/)<% } %>.<% } %>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "<%= offsetFromRoot %>tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
|
8
|
+
"emitDeclarationOnly": false,<% if (compilerOptions.length) { %>
|
|
9
|
+
<%- compilerOptions %>,<% } %>
|
|
10
|
+
"types": ["node"]
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*.ts"<% if (js) { %>, "src/**/*.js"<% } %>],
|
|
13
|
+
"references": []
|
|
14
|
+
}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
-
import {
|
|
3
|
-
import { LibraryGeneratorSchema } from '../../utils/schema';
|
|
2
|
+
import type { LibraryGeneratorSchema, NormalizedLibraryGeneratorOptions } from './schema';
|
|
4
3
|
export declare function libraryGenerator(tree: Tree, schema: LibraryGeneratorSchema): Promise<GeneratorCallback>;
|
|
5
4
|
export declare function libraryGeneratorInternal(tree: Tree, schema: LibraryGeneratorSchema): Promise<GeneratorCallback>;
|
|
6
|
-
export
|
|
7
|
-
name: string;
|
|
8
|
-
projectNames: ProjectNameAndRootOptions['names'];
|
|
9
|
-
fileName: string;
|
|
10
|
-
projectRoot: string;
|
|
11
|
-
parsedTags: string[];
|
|
12
|
-
importPath?: string;
|
|
13
|
-
}
|
|
14
|
-
export type AddLintOptions = Pick<NormalizedSchema, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'setParserOptionsProject' | 'rootProject' | 'bundler' | 'addPlugin'>;
|
|
5
|
+
export type AddLintOptions = Pick<NormalizedLibraryGeneratorOptions, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'setParserOptionsProject' | 'rootProject' | 'bundler' | 'addPlugin'>;
|
|
15
6
|
export declare function addLint(tree: Tree, options: AddLintOptions): Promise<GeneratorCallback>;
|
|
16
7
|
export default libraryGenerator;
|