@nx/js 0.0.0-pr-27957-a99d5ea → 0.0.0-pr-28229-afe192c
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 +6 -1
- package/package.json +7 -6
- package/src/executors/node/lib/kill-tree.js +9 -9
- package/src/executors/release-publish/release-publish.impl.js +3 -0
- package/src/executors/verdaccio/verdaccio.impl.js +20 -14
- 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 +61 -54
- 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/non-ts-solution/tsconfig.lib.json__tmpl__ +9 -0
- 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 +301 -108
- package/src/generators/library/schema.d.ts +53 -0
- package/src/generators/library/schema.json +19 -30
- 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/release-version/release-version.js +71 -8
- package/src/generators/release-version/utils/update-lock-file.js +1 -0
- package/src/generators/setup-prettier/generator.d.ts +4 -0
- package/src/generators/setup-prettier/generator.js +21 -0
- package/src/generators/setup-prettier/schema.d.ts +4 -0
- package/src/generators/setup-prettier/schema.json +22 -0
- package/src/generators/setup-verdaccio/generator.js +19 -12
- package/src/generators/typescript-sync/typescript-sync.d.ts +1 -1
- package/src/generators/typescript-sync/typescript-sync.js +9 -8
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -3
- package/src/plugins/jest/start-local-registry.js +6 -2
- package/src/plugins/typescript/plugin.js +8 -0
- package/src/utils/find-npm-dependencies.js +12 -0
- package/src/utils/npm-config.js +1 -1
- 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 +5 -0
- package/src/utils/prettier.js +102 -6
- package/src/utils/schema.d.ts +0 -33
- package/src/utils/swc/add-swc-dependencies.d.ts +4 -0
- package/src/utils/swc/add-swc-dependencies.js +11 -4
- package/src/utils/swc/compile-swc.js +2 -0
- 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/library/files/lib/tsconfig.lib.json__tmpl__ +0 -14
- /package/src/generators/init/files/{__fileName__ → non-ts-solution/__fileName__} +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",
|
|
@@ -48,6 +48,11 @@
|
|
|
48
48
|
"description": "Synchronize TypeScript project references based on the project graph",
|
|
49
49
|
"alias": ["sync"],
|
|
50
50
|
"hidden": true
|
|
51
|
+
},
|
|
52
|
+
"setup-prettier": {
|
|
53
|
+
"factory": "./src/generators/setup-prettier/generator",
|
|
54
|
+
"schema": "./src/generators/setup-prettier/schema.json",
|
|
55
|
+
"description": "Setup Prettier as the formatting tool."
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-28229-afe192c",
|
|
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,14 +39,16 @@
|
|
|
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": "0.0.0-pr-
|
|
43
|
-
"@nx/workspace": "0.0.0-pr-
|
|
42
|
+
"@nx/devkit": "0.0.0-pr-28229-afe192c",
|
|
43
|
+
"@nx/workspace": "0.0.0-pr-28229-afe192c",
|
|
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",
|
|
47
48
|
"chalk": "^4.1.0",
|
|
48
49
|
"columnify": "^1.6.0",
|
|
49
50
|
"detect-port": "^1.5.1",
|
|
51
|
+
"enquirer": "~2.3.6",
|
|
50
52
|
"fast-glob": "3.2.7",
|
|
51
53
|
"ignore": "^5.0.4",
|
|
52
54
|
"js-tokens": "^4.0.0",
|
|
@@ -59,8 +61,7 @@
|
|
|
59
61
|
"source-map-support": "0.5.19",
|
|
60
62
|
"ts-node": "10.9.1",
|
|
61
63
|
"tsconfig-paths": "^4.1.2",
|
|
62
|
-
"tslib": "^2.3.0"
|
|
63
|
-
"@nrwl/js": "0.0.0-pr-27957-a99d5ea"
|
|
64
|
+
"tslib": "^2.3.0"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
67
|
"verdaccio": "^5.0.4"
|
|
@@ -75,4 +76,4 @@
|
|
|
75
76
|
},
|
|
76
77
|
"type": "commonjs",
|
|
77
78
|
"types": "./src/index.d.ts"
|
|
78
|
-
}
|
|
79
|
+
}
|
|
@@ -19,7 +19,9 @@ async function killTree(pid, signal) {
|
|
|
19
19
|
};
|
|
20
20
|
switch (process.platform) {
|
|
21
21
|
case 'win32':
|
|
22
|
-
(0, child_process_1.exec)('taskkill /pid ' + pid + ' /T /F',
|
|
22
|
+
(0, child_process_1.exec)('taskkill /pid ' + pid + ' /T /F', {
|
|
23
|
+
windowsHide: true,
|
|
24
|
+
}, (error) => {
|
|
23
25
|
// Ignore Fatal errors (128) because it might be due to the process already being killed.
|
|
24
26
|
// On Linux/Mac we can check ESRCH (no such process), but on Windows we can't.
|
|
25
27
|
callback(error?.code !== 128 ? error : null);
|
|
@@ -27,20 +29,18 @@ async function killTree(pid, signal) {
|
|
|
27
29
|
break;
|
|
28
30
|
case 'darwin':
|
|
29
31
|
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
|
|
30
|
-
return (0, child_process_1.spawn)('pgrep', ['-P', parentPid]
|
|
32
|
+
return (0, child_process_1.spawn)('pgrep', ['-P', parentPid], {
|
|
33
|
+
windowsHide: true,
|
|
34
|
+
});
|
|
31
35
|
}, function () {
|
|
32
36
|
killAll(tree, signal, callback);
|
|
33
37
|
});
|
|
34
38
|
break;
|
|
35
39
|
default: // Linux
|
|
36
40
|
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
|
|
37
|
-
return (0, child_process_1.spawn)('ps', [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
'--no-headers',
|
|
41
|
-
'--ppid',
|
|
42
|
-
parentPid,
|
|
43
|
-
]);
|
|
41
|
+
return (0, child_process_1.spawn)('ps', ['-o', 'pid', '--no-headers', '--ppid', parentPid], {
|
|
42
|
+
windowsHide: true,
|
|
43
|
+
});
|
|
44
44
|
}, function () {
|
|
45
45
|
killAll(tree, signal, callback);
|
|
46
46
|
});
|
|
@@ -96,6 +96,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
96
96
|
env: processEnv(true),
|
|
97
97
|
cwd: context.root,
|
|
98
98
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
99
|
+
windowsHide: true,
|
|
99
100
|
});
|
|
100
101
|
const resultJson = JSON.parse(result.toString());
|
|
101
102
|
const distTags = resultJson['dist-tags'] || {};
|
|
@@ -116,6 +117,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
116
117
|
env: processEnv(true),
|
|
117
118
|
cwd: context.root,
|
|
118
119
|
stdio: 'ignore',
|
|
120
|
+
windowsHide: true,
|
|
119
121
|
});
|
|
120
122
|
console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`);
|
|
121
123
|
}
|
|
@@ -202,6 +204,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
202
204
|
env: processEnv(true),
|
|
203
205
|
cwd: context.root,
|
|
204
206
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
207
|
+
windowsHide: true,
|
|
205
208
|
});
|
|
206
209
|
/**
|
|
207
210
|
* We cannot JSON.parse the output directly because if the user is using lifecycle scripts, npm/pnpm will mix its publish output with the JSON output all on stdout.
|
|
@@ -113,7 +113,7 @@ function createVerdaccioOptions(options, workspaceRoot) {
|
|
|
113
113
|
}
|
|
114
114
|
function setupNpm(options) {
|
|
115
115
|
try {
|
|
116
|
-
(0, child_process_1.execSync)('npm --version', { env });
|
|
116
|
+
(0, child_process_1.execSync)('npm --version', { env, windowsHide: true });
|
|
117
117
|
}
|
|
118
118
|
catch (e) {
|
|
119
119
|
return () => { };
|
|
@@ -124,13 +124,13 @@ function setupNpm(options) {
|
|
|
124
124
|
scopes.forEach((scope) => {
|
|
125
125
|
const registryName = scope ? `${scope}:registry` : 'registry';
|
|
126
126
|
try {
|
|
127
|
-
npmRegistryPaths.push((0, child_process_1.execSync)(`npm config get ${registryName} --location ${options.location}`, { env })
|
|
127
|
+
npmRegistryPaths.push((0, child_process_1.execSync)(`npm config get ${registryName} --location ${options.location}`, { env, windowsHide: true })
|
|
128
128
|
?.toString()
|
|
129
129
|
?.trim()
|
|
130
130
|
?.replace('\u001b[2K\u001b[1G', '') // strip out ansi codes
|
|
131
131
|
);
|
|
132
|
-
(0, child_process_1.execSync)(`npm config set ${registryName} http://localhost:${options.port}/ --location ${options.location}`, { env });
|
|
133
|
-
(0, child_process_1.execSync)(`npm config set //localhost:${options.port}/:_authToken="secretVerdaccioToken" --location ${options.location}`, { env });
|
|
132
|
+
(0, child_process_1.execSync)(`npm config set ${registryName} http://localhost:${options.port}/ --location ${options.location}`, { env, windowsHide: true });
|
|
133
|
+
(0, child_process_1.execSync)(`npm config set //localhost:${options.port}/:_authToken="secretVerdaccioToken" --location ${options.location}`, { env, windowsHide: true });
|
|
134
134
|
devkit_1.logger.info(`Set npm ${registryName} to http://localhost:${options.port}/`);
|
|
135
135
|
}
|
|
136
136
|
catch (e) {
|
|
@@ -139,7 +139,7 @@ function setupNpm(options) {
|
|
|
139
139
|
});
|
|
140
140
|
return () => {
|
|
141
141
|
try {
|
|
142
|
-
const currentNpmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`, { env })
|
|
142
|
+
const currentNpmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`, { env, windowsHide: true })
|
|
143
143
|
?.toString()
|
|
144
144
|
?.trim()
|
|
145
145
|
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
|
|
@@ -147,17 +147,18 @@ function setupNpm(options) {
|
|
|
147
147
|
const registryName = scope ? `${scope}:registry` : 'registry';
|
|
148
148
|
if (npmRegistryPaths[index] &&
|
|
149
149
|
currentNpmRegistryPath.includes('localhost')) {
|
|
150
|
-
(0, child_process_1.execSync)(`npm config set ${registryName} ${npmRegistryPaths[index]} --location ${options.location}`, { env });
|
|
150
|
+
(0, child_process_1.execSync)(`npm config set ${registryName} ${npmRegistryPaths[index]} --location ${options.location}`, { env, windowsHide: true });
|
|
151
151
|
devkit_1.logger.info(`Reset npm ${registryName} to ${npmRegistryPaths[index]}`);
|
|
152
152
|
}
|
|
153
153
|
else {
|
|
154
154
|
(0, child_process_1.execSync)(`npm config delete ${registryName} --location ${options.location}`, {
|
|
155
155
|
env,
|
|
156
|
+
windowsHide: true,
|
|
156
157
|
});
|
|
157
158
|
devkit_1.logger.info('Cleared custom npm registry');
|
|
158
159
|
}
|
|
159
160
|
});
|
|
160
|
-
(0, child_process_1.execSync)(`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`, { env });
|
|
161
|
+
(0, child_process_1.execSync)(`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`, { env, windowsHide: true });
|
|
161
162
|
}
|
|
162
163
|
catch (e) {
|
|
163
164
|
throw new Error(`Failed to reset npm registry: ${e.message}`);
|
|
@@ -172,16 +173,17 @@ function getYarnUnsafeHttpWhitelist(isYarnV1) {
|
|
|
172
173
|
return !isYarnV1
|
|
173
174
|
? new Set(JSON.parse((0, child_process_1.execSync)(`yarn config get unsafeHttpWhitelist --json`, {
|
|
174
175
|
env,
|
|
176
|
+
windowsHide: true,
|
|
175
177
|
}).toString()))
|
|
176
178
|
: null;
|
|
177
179
|
}
|
|
178
180
|
function setYarnUnsafeHttpWhitelist(currentWhitelist, options) {
|
|
179
181
|
if (currentWhitelist.size > 0) {
|
|
180
|
-
(0, child_process_1.execSync)(`yarn config set unsafeHttpWhitelist --json '${JSON.stringify(Array.from(currentWhitelist))}'` + (options.location === 'user' ? ' --home' : ''), { env });
|
|
182
|
+
(0, child_process_1.execSync)(`yarn config set unsafeHttpWhitelist --json '${JSON.stringify(Array.from(currentWhitelist))}'` + (options.location === 'user' ? ' --home' : ''), { env, windowsHide: true });
|
|
181
183
|
}
|
|
182
184
|
else {
|
|
183
185
|
(0, child_process_1.execSync)(`yarn config unset unsafeHttpWhitelist` +
|
|
184
|
-
(options.location === 'user' ? ' --home' : ''), { env });
|
|
186
|
+
(options.location === 'user' ? ' --home' : ''), { env, windowsHide: true });
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
189
|
function setupYarn(options) {
|
|
@@ -190,7 +192,7 @@ function setupYarn(options) {
|
|
|
190
192
|
const scopes = ['', ...(options.scopes || [])];
|
|
191
193
|
try {
|
|
192
194
|
isYarnV1 =
|
|
193
|
-
(0, semver_1.major)((0, child_process_1.execSync)('yarn --version', { env }).toString().trim()) === 1;
|
|
195
|
+
(0, semver_1.major)((0, child_process_1.execSync)('yarn --version', { env, windowsHide: true }).toString().trim()) === 1;
|
|
194
196
|
}
|
|
195
197
|
catch {
|
|
196
198
|
// This would fail if yarn is not installed which is okay
|
|
@@ -202,13 +204,14 @@ function setupYarn(options) {
|
|
|
202
204
|
const scopeName = scope ? `${scope}:` : '';
|
|
203
205
|
yarnRegistryPaths.push((0, child_process_1.execSync)(`yarn config get ${scopeName}${registryConfigName}`, {
|
|
204
206
|
env,
|
|
207
|
+
windowsHide: true,
|
|
205
208
|
})
|
|
206
209
|
?.toString()
|
|
207
210
|
?.trim()
|
|
208
211
|
?.replace('\u001b[2K\u001b[1G', '') // strip out ansi codes
|
|
209
212
|
);
|
|
210
213
|
(0, child_process_1.execSync)(`yarn config set ${scopeName}${registryConfigName} http://localhost:${options.port}/` +
|
|
211
|
-
(options.location === 'user' ? ' --home' : ''), { env });
|
|
214
|
+
(options.location === 'user' ? ' --home' : ''), { env, windowsHide: true });
|
|
212
215
|
devkit_1.logger.info(`Set yarn ${scopeName}registry to http://localhost:${options.port}/`);
|
|
213
216
|
});
|
|
214
217
|
const currentWhitelist = getYarnUnsafeHttpWhitelist(isYarnV1);
|
|
@@ -221,7 +224,7 @@ function setupYarn(options) {
|
|
|
221
224
|
}
|
|
222
225
|
return () => {
|
|
223
226
|
try {
|
|
224
|
-
const currentYarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`, { env })
|
|
227
|
+
const currentYarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`, { env, windowsHide: true })
|
|
225
228
|
?.toString()
|
|
226
229
|
?.trim()
|
|
227
230
|
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
|
|
@@ -232,12 +235,15 @@ function setupYarn(options) {
|
|
|
232
235
|
if (yarnRegistryPaths[index] &&
|
|
233
236
|
currentYarnRegistryPath.includes('localhost')) {
|
|
234
237
|
(0, child_process_1.execSync)(`yarn config set ${registryName} ${yarnRegistryPaths[index]}` +
|
|
235
|
-
(options.location === 'user' ? ' --home' : ''), {
|
|
238
|
+
(options.location === 'user' ? ' --home' : ''), {
|
|
239
|
+
env,
|
|
240
|
+
windowsHide: true,
|
|
241
|
+
});
|
|
236
242
|
devkit_1.logger.info(`Reset yarn ${registryName} to ${yarnRegistryPaths[index]}`);
|
|
237
243
|
}
|
|
238
244
|
else {
|
|
239
245
|
(0, child_process_1.execSync)(`yarn config ${isYarnV1 ? 'delete' : 'unset'} ${registryName}` +
|
|
240
|
-
(options.location === 'user' ? ' --home' : ''), { env });
|
|
246
|
+
(options.location === 'user' ? ' --home' : ''), { env, windowsHide: true });
|
|
241
247
|
devkit_1.logger.info(`Cleared custom yarn ${registryConfigName}`);
|
|
242
248
|
}
|
|
243
249
|
});
|
|
@@ -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,16 @@ 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");
|
|
9
|
+
const path_1 = require("path");
|
|
8
10
|
const semver_2 = require("semver");
|
|
11
|
+
const plugin_1 = require("../../plugins/typescript/plugin");
|
|
12
|
+
const prettier_1 = require("../../utils/prettier");
|
|
9
13
|
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
14
|
+
const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
10
15
|
const versions_1 = require("../../utils/versions");
|
|
11
|
-
const path_1 = require("path");
|
|
12
16
|
async function getInstalledTypescriptVersion(tree) {
|
|
13
17
|
const rootPackageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
14
18
|
const tsVersionInRootPackageJson = rootPackageJson.devDependencies?.['typescript'] ??
|
|
@@ -36,19 +40,47 @@ async function getInstalledTypescriptVersion(tree) {
|
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
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';
|
|
39
46
|
return initGeneratorInternal(tree, {
|
|
40
47
|
addTsConfigBase: true,
|
|
41
|
-
setUpPrettier: true,
|
|
42
48
|
...schema,
|
|
43
49
|
});
|
|
44
50
|
}
|
|
45
51
|
async function initGeneratorInternal(tree, schema) {
|
|
46
52
|
const tasks = [];
|
|
47
|
-
|
|
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
|
+
}
|
|
48
73
|
if (schema.addTsConfigBase && !(0, ts_config_1.getRootTsConfigFileName)(tree)) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
}
|
|
52
84
|
}
|
|
53
85
|
const devDependencies = {
|
|
54
86
|
'@nx/js': versions_1.nxVersion,
|
|
@@ -67,61 +99,36 @@ async function initGeneratorInternal(tree, schema) {
|
|
|
67
99
|
devDependencies['typescript'] = versions_1.typescriptVersion;
|
|
68
100
|
}
|
|
69
101
|
}
|
|
70
|
-
if (schema.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const prettierrcNameOptions = [
|
|
74
|
-
'.prettierrc',
|
|
75
|
-
'.prettierrc.json',
|
|
76
|
-
'.prettierrc.yml',
|
|
77
|
-
'.prettierrc.yaml',
|
|
78
|
-
'.prettierrc.json5',
|
|
79
|
-
'.prettierrc.js',
|
|
80
|
-
'.prettierrc.cjs',
|
|
81
|
-
'.prettierrc.mjs',
|
|
82
|
-
'.prettierrc.toml',
|
|
83
|
-
'prettier.config.js',
|
|
84
|
-
'prettier.config.cjs',
|
|
85
|
-
'prettier.config.mjs',
|
|
86
|
-
];
|
|
87
|
-
if (prettierrcNameOptions.every((name) => !tree.exists(name))) {
|
|
88
|
-
(0, devkit_1.writeJson)(tree, '.prettierrc', {
|
|
89
|
-
singleQuote: true,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
if (!tree.exists(`.prettierignore`)) {
|
|
93
|
-
tree.write('.prettierignore', (0, devkit_1.stripIndents) `
|
|
94
|
-
# Add files here to ignore them from prettier formatting
|
|
95
|
-
/dist
|
|
96
|
-
/coverage
|
|
97
|
-
/.nx/cache
|
|
98
|
-
/.nx/workspace-data
|
|
99
|
-
`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (tree.exists('.vscode/extensions.json')) {
|
|
103
|
-
(0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
|
|
104
|
-
json.recommendations ??= [];
|
|
105
|
-
const extension = 'esbenp.prettier-vscode';
|
|
106
|
-
if (!json.recommendations.includes(extension)) {
|
|
107
|
-
json.recommendations.push(extension);
|
|
108
|
-
}
|
|
109
|
-
return json;
|
|
102
|
+
if (schema.formatter === 'prettier') {
|
|
103
|
+
const prettierTask = (0, prettier_1.generatePrettierSetup)(tree, {
|
|
104
|
+
skipPackageJson: schema.skipPackageJson,
|
|
110
105
|
});
|
|
106
|
+
tasks.push(prettierTask);
|
|
107
|
+
}
|
|
108
|
+
const rootTsConfigFileName = (0, ts_config_1.getRootTsConfigFileName)(tree);
|
|
109
|
+
// If the root tsconfig file uses `importHelpers` then we must install tslib
|
|
110
|
+
// in order to run tsc for build and typecheck.
|
|
111
|
+
if (rootTsConfigFileName) {
|
|
112
|
+
const rootTsConfig = (0, devkit_1.readJson)(tree, rootTsConfigFileName);
|
|
113
|
+
if (rootTsConfig.compilerOptions?.importHelpers) {
|
|
114
|
+
devDependencies['tslib'] = versions_1.tsLibVersion;
|
|
115
|
+
}
|
|
111
116
|
}
|
|
112
117
|
const installTask = !schema.skipPackageJson
|
|
113
118
|
? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions)
|
|
114
119
|
: () => { };
|
|
115
120
|
tasks.push(installTask);
|
|
116
|
-
if (schema.
|
|
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') {
|
|
117
125
|
(0, devkit_1.ensurePackage)('prettier', versions_1.prettierVersion);
|
|
118
|
-
if (!schema.skipFormat)
|
|
119
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
120
126
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
127
|
+
if (!schema.skipFormat) {
|
|
128
|
+
// even if skipPackageJson === true, we can safely run formatFiles, prettier might
|
|
129
|
+
// have been installed earlier and if not, the formatFiles function still handles it
|
|
130
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
131
|
+
}
|
|
132
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
126
133
|
}
|
|
127
134
|
exports.default = initGenerator;
|
|
@@ -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;
|