@nx/js 0.0.0-pr-22179-271588f

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.
Files changed (204) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/babel.d.ts +13 -0
  4. package/babel.js +91 -0
  5. package/executors.json +32 -0
  6. package/generators.json +46 -0
  7. package/migrations.json +159 -0
  8. package/package.json +76 -0
  9. package/plugins/jest/local-registry.d.ts +1 -0
  10. package/plugins/jest/local-registry.js +4 -0
  11. package/src/executors/node/lib/kill-tree.d.ts +2 -0
  12. package/src/executors/node/lib/kill-tree.js +114 -0
  13. package/src/executors/node/node-with-require-overrides.d.ts +7 -0
  14. package/src/executors/node/node-with-require-overrides.js +21 -0
  15. package/src/executors/node/node.impl.d.ts +7 -0
  16. package/src/executors/node/node.impl.js +288 -0
  17. package/src/executors/node/schema.d.ts +18 -0
  18. package/src/executors/node/schema.json +92 -0
  19. package/src/executors/release-publish/format-bytes.d.ts +1 -0
  20. package/src/executors/release-publish/format-bytes.js +28 -0
  21. package/src/executors/release-publish/log-tar.d.ts +1 -0
  22. package/src/executors/release-publish/log-tar.js +68 -0
  23. package/src/executors/release-publish/release-publish.impl.d.ts +5 -0
  24. package/src/executors/release-publish/release-publish.impl.js +198 -0
  25. package/src/executors/release-publish/schema.d.ts +8 -0
  26. package/src/executors/release-publish/schema.json +26 -0
  27. package/src/executors/swc/schema.json +154 -0
  28. package/src/executors/swc/swc.impl.d.ts +10 -0
  29. package/src/executors/swc/swc.impl.js +149 -0
  30. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +5 -0
  31. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +62 -0
  32. package/src/executors/tsc/lib/batch/index.d.ts +4 -0
  33. package/src/executors/tsc/lib/batch/index.js +7 -0
  34. package/src/executors/tsc/lib/batch/normalize-tasks-options.d.ts +3 -0
  35. package/src/executors/tsc/lib/batch/normalize-tasks-options.js +14 -0
  36. package/src/executors/tsc/lib/batch/types.d.ts +17 -0
  37. package/src/executors/tsc/lib/batch/types.js +2 -0
  38. package/src/executors/tsc/lib/batch/watch.d.ts +3 -0
  39. package/src/executors/tsc/lib/batch/watch.js +56 -0
  40. package/src/executors/tsc/lib/get-custom-transformers-factory.d.ts +3 -0
  41. package/src/executors/tsc/lib/get-custom-transformers-factory.js +13 -0
  42. package/src/executors/tsc/lib/get-task-options.d.ts +3 -0
  43. package/src/executors/tsc/lib/get-task-options.js +34 -0
  44. package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
  45. package/src/executors/tsc/lib/get-tsconfig.js +86 -0
  46. package/src/executors/tsc/lib/index.d.ts +4 -0
  47. package/src/executors/tsc/lib/index.js +7 -0
  48. package/src/executors/tsc/lib/normalize-options.d.ts +2 -0
  49. package/src/executors/tsc/lib/normalize-options.js +39 -0
  50. package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
  51. package/src/executors/tsc/lib/typescript-compilation.js +203 -0
  52. package/src/executors/tsc/lib/typescript-diagnostic-reporters.d.ts +3 -0
  53. package/src/executors/tsc/lib/typescript-diagnostic-reporters.js +37 -0
  54. package/src/executors/tsc/schema.json +163 -0
  55. package/src/executors/tsc/tsc.batch-impl.d.ts +5 -0
  56. package/src/executors/tsc/tsc.batch-impl.js +180 -0
  57. package/src/executors/tsc/tsc.impl.d.ts +7 -0
  58. package/src/executors/tsc/tsc.impl.js +97 -0
  59. package/src/executors/verdaccio/schema.d.ts +7 -0
  60. package/src/executors/verdaccio/schema.json +35 -0
  61. package/src/executors/verdaccio/verdaccio.impl.d.ts +12 -0
  62. package/src/executors/verdaccio/verdaccio.impl.js +220 -0
  63. package/src/generators/convert-to-swc/convert-to-swc.d.ts +4 -0
  64. package/src/generators/convert-to-swc/convert-to-swc.js +59 -0
  65. package/src/generators/convert-to-swc/schema.d.ts +4 -0
  66. package/src/generators/convert-to-swc/schema.json +36 -0
  67. package/src/generators/init/files/__fileName__ +20 -0
  68. package/src/generators/init/init.d.ts +4 -0
  69. package/src/generators/init/init.js +114 -0
  70. package/src/generators/init/schema.d.ts +7 -0
  71. package/src/generators/init/schema.json +36 -0
  72. package/src/generators/library/files/jest-config/jest.config.__ext__ +30 -0
  73. package/src/generators/library/files/lib/src/index.ts__tmpl__ +1 -0
  74. package/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +7 -0
  75. package/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +3 -0
  76. package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +14 -0
  77. package/src/generators/library/files/readme/README.md +19 -0
  78. package/src/generators/library/library.d.ts +16 -0
  79. package/src/generators/library/library.js +751 -0
  80. package/src/generators/library/schema.json +151 -0
  81. package/src/generators/release-version/release-version.d.ts +5 -0
  82. package/src/generators/release-version/release-version.js +390 -0
  83. package/src/generators/release-version/schema.d.ts +1 -0
  84. package/src/generators/release-version/schema.json +67 -0
  85. package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.d.ts +16 -0
  86. package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.js +40 -0
  87. package/src/generators/release-version/utils/package.d.ts +12 -0
  88. package/src/generators/release-version/utils/package.js +34 -0
  89. package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +12 -0
  90. package/src/generators/release-version/utils/resolve-local-package-dependencies.js +78 -0
  91. package/src/generators/release-version/utils/resolve-version-spec.d.ts +1 -0
  92. package/src/generators/release-version/utils/resolve-version-spec.js +29 -0
  93. package/src/generators/release-version/utils/update-lock-file.d.ts +5 -0
  94. package/src/generators/release-version/utils/update-lock-file.js +105 -0
  95. package/src/generators/setup-build/generator.d.ts +4 -0
  96. package/src/generators/setup-build/generator.js +142 -0
  97. package/src/generators/setup-build/schema.d.ts +7 -0
  98. package/src/generators/setup-build/schema.json +42 -0
  99. package/src/generators/setup-verdaccio/files/config.yml +28 -0
  100. package/src/generators/setup-verdaccio/generator.d.ts +4 -0
  101. package/src/generators/setup-verdaccio/generator.js +56 -0
  102. package/src/generators/setup-verdaccio/schema.d.ts +3 -0
  103. package/src/generators/setup-verdaccio/schema.json +16 -0
  104. package/src/index.d.ts +17 -0
  105. package/src/index.js +28 -0
  106. package/src/internal.d.ts +4 -0
  107. package/src/internal.js +15 -0
  108. package/src/migrations/update-15-8-0/rename-swcrc-config.d.ts +2 -0
  109. package/src/migrations/update-15-8-0/rename-swcrc-config.js +77 -0
  110. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  111. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  112. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.d.ts +2 -0
  113. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +34 -0
  114. package/src/migrations/update-16-8-2/update-swcrc.d.ts +2 -0
  115. package/src/migrations/update-16-8-2/update-swcrc.js +23 -0
  116. package/src/migrations/update-17-0-0/remove-deprecated-build-options.d.ts +6 -0
  117. package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +30 -0
  118. package/src/plugins/jest/start-local-registry.d.ts +12 -0
  119. package/src/plugins/jest/start-local-registry.js +63 -0
  120. package/src/plugins/rollup/type-definitions.d.ts +8 -0
  121. package/src/plugins/rollup/type-definitions.js +48 -0
  122. package/src/utils/add-babel-inputs.d.ts +3 -0
  123. package/src/utils/add-babel-inputs.js +23 -0
  124. package/src/utils/add-local-registry-scripts.d.ts +5 -0
  125. package/src/utils/add-local-registry-scripts.js +77 -0
  126. package/src/utils/assets/assets.d.ts +10 -0
  127. package/src/utils/assets/assets.js +36 -0
  128. package/src/utils/assets/copy-assets-handler.d.ts +32 -0
  129. package/src/utils/assets/copy-assets-handler.js +154 -0
  130. package/src/utils/assets/index.d.ts +16 -0
  131. package/src/utils/assets/index.js +27 -0
  132. package/src/utils/buildable-libs-utils.d.ts +43 -0
  133. package/src/utils/buildable-libs-utils.js +375 -0
  134. package/src/utils/check-dependencies.d.ts +8 -0
  135. package/src/utils/check-dependencies.js +23 -0
  136. package/src/utils/code-frames/highlight.d.ts +1 -0
  137. package/src/utils/code-frames/highlight.js +86 -0
  138. package/src/utils/code-frames/identifiers.d.ts +5 -0
  139. package/src/utils/code-frames/identifiers.js +52 -0
  140. package/src/utils/compiler-helper-dependency.d.ts +18 -0
  141. package/src/utils/compiler-helper-dependency.js +120 -0
  142. package/src/utils/find-npm-dependencies.d.ts +9 -0
  143. package/src/utils/find-npm-dependencies.js +140 -0
  144. package/src/utils/generate-globs.d.ts +6 -0
  145. package/src/utils/generate-globs.js +80 -0
  146. package/src/utils/get-import-path.d.ts +5 -0
  147. package/src/utils/get-import-path.js +14 -0
  148. package/src/utils/get-main-file-dir.d.ts +1 -0
  149. package/src/utils/get-main-file-dir.js +11 -0
  150. package/src/utils/inline.d.ts +19 -0
  151. package/src/utils/inline.js +210 -0
  152. package/src/utils/package-json/create-entry-points.d.ts +1 -0
  153. package/src/utils/package-json/create-entry-points.js +23 -0
  154. package/src/utils/package-json/get-npm-scope.d.ts +5 -0
  155. package/src/utils/package-json/get-npm-scope.js +16 -0
  156. package/src/utils/package-json/index.d.ts +13 -0
  157. package/src/utils/package-json/index.js +30 -0
  158. package/src/utils/package-json/update-package-json.d.ts +30 -0
  159. package/src/utils/package-json/update-package-json.js +179 -0
  160. package/src/utils/prettier.d.ts +6 -0
  161. package/src/utils/prettier.js +34 -0
  162. package/src/utils/schema.d.ts +87 -0
  163. package/src/utils/swc/add-swc-config.d.ts +3 -0
  164. package/src/utils/swc/add-swc-config.js +41 -0
  165. package/src/utils/swc/add-swc-dependencies.d.ts +3 -0
  166. package/src/utils/swc/add-swc-dependencies.js +18 -0
  167. package/src/utils/swc/compile-swc.d.ts +13 -0
  168. package/src/utils/swc/compile-swc.js +160 -0
  169. package/src/utils/swc/get-swcrc-path.d.ts +5 -0
  170. package/src/utils/swc/get-swcrc-path.js +15 -0
  171. package/src/utils/swc/inline.d.ts +2 -0
  172. package/src/utils/swc/inline.js +11 -0
  173. package/src/utils/typescript/__mocks__/plugin-a.d.ts +1 -0
  174. package/src/utils/typescript/__mocks__/plugin-a.js +5 -0
  175. package/src/utils/typescript/__mocks__/plugin-b.d.ts +1 -0
  176. package/src/utils/typescript/__mocks__/plugin-b.js +5 -0
  177. package/src/utils/typescript/add-tslib-dependencies.d.ts +2 -0
  178. package/src/utils/typescript/add-tslib-dependencies.js +11 -0
  179. package/src/utils/typescript/ast-utils.d.ts +32 -0
  180. package/src/utils/typescript/ast-utils.js +266 -0
  181. package/src/utils/typescript/compile-typescript-files.d.ts +10 -0
  182. package/src/utils/typescript/compile-typescript-files.js +43 -0
  183. package/src/utils/typescript/create-ts-config.d.ts +18 -0
  184. package/src/utils/typescript/create-ts-config.js +48 -0
  185. package/src/utils/typescript/ensure-typescript.d.ts +1 -0
  186. package/src/utils/typescript/ensure-typescript.js +9 -0
  187. package/src/utils/typescript/get-source-nodes.d.ts +2 -0
  188. package/src/utils/typescript/get-source-nodes.js +18 -0
  189. package/src/utils/typescript/load-ts-transformers.d.ts +5 -0
  190. package/src/utils/typescript/load-ts-transformers.js +62 -0
  191. package/src/utils/typescript/print-diagnostics.d.ts +1 -0
  192. package/src/utils/typescript/print-diagnostics.js +18 -0
  193. package/src/utils/typescript/run-type-check.d.ts +32 -0
  194. package/src/utils/typescript/run-type-check.js +128 -0
  195. package/src/utils/typescript/ts-config.d.ts +9 -0
  196. package/src/utils/typescript/ts-config.js +85 -0
  197. package/src/utils/typescript/tsnode-register.d.ts +1 -0
  198. package/src/utils/typescript/tsnode-register.js +24 -0
  199. package/src/utils/typescript/types.d.ts +18 -0
  200. package/src/utils/typescript/types.js +2 -0
  201. package/src/utils/versions.d.ts +17 -0
  202. package/src/utils/versions.js +21 -0
  203. package/src/utils/watch-for-single-file-changes.d.ts +1 -0
  204. package/src/utils/watch-for-single-file-changes.js +22 -0
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verdaccioExecutor = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const fs_extra_1 = require("fs-extra");
6
+ const child_process_1 = require("child_process");
7
+ const detectPort = require("detect-port");
8
+ const path_1 = require("path");
9
+ const semver_1 = require("semver");
10
+ let childProcess;
11
+ /**
12
+ * - set npm and yarn to use local registry
13
+ * - start verdaccio
14
+ * - stop local registry when done
15
+ */
16
+ async function verdaccioExecutor(options, context) {
17
+ try {
18
+ require.resolve('verdaccio');
19
+ }
20
+ catch (e) {
21
+ throw new Error('Verdaccio is not installed. Please run `npm install verdaccio` or `yarn add verdaccio`');
22
+ }
23
+ if (options.storage) {
24
+ options.storage = (0, path_1.resolve)(context.root, options.storage);
25
+ if (options.clear && (0, fs_extra_1.existsSync)(options.storage)) {
26
+ (0, fs_extra_1.rmSync)(options.storage, { recursive: true, force: true });
27
+ console.log(`Cleared local registry storage folder ${options.storage}`);
28
+ }
29
+ }
30
+ const port = await detectPort(options.port);
31
+ if (port !== options.port) {
32
+ devkit_1.logger.info(`Port ${options.port} was occupied. Using port ${port}.`);
33
+ options.port = port;
34
+ }
35
+ const cleanupFunctions = options.location === 'none' ? [] : [setupNpm(options), setupYarn(options)];
36
+ const processExitListener = (signal) => {
37
+ if (childProcess) {
38
+ childProcess.kill(signal);
39
+ }
40
+ for (const fn of cleanupFunctions) {
41
+ fn();
42
+ }
43
+ };
44
+ process.on('exit', processExitListener);
45
+ process.on('SIGTERM', processExitListener);
46
+ process.on('SIGINT', processExitListener);
47
+ process.on('SIGHUP', processExitListener);
48
+ try {
49
+ await startVerdaccio(options, context.root);
50
+ }
51
+ catch (e) {
52
+ devkit_1.logger.error('Failed to start verdaccio: ' + e?.toString());
53
+ return {
54
+ success: false,
55
+ port: options.port,
56
+ };
57
+ }
58
+ return {
59
+ success: true,
60
+ port: options.port,
61
+ };
62
+ }
63
+ exports.verdaccioExecutor = verdaccioExecutor;
64
+ /**
65
+ * Fork the verdaccio process: https://verdaccio.org/docs/verdaccio-programmatically/#using-fork-from-child_process-module
66
+ */
67
+ function startVerdaccio(options, workspaceRoot) {
68
+ return new Promise((resolve, reject) => {
69
+ childProcess = (0, child_process_1.fork)(require.resolve('verdaccio/bin/verdaccio'), createVerdaccioOptions(options, workspaceRoot), {
70
+ env: {
71
+ ...process.env,
72
+ VERDACCIO_HANDLE_KILL_SIGNALS: 'true',
73
+ ...(options.storage
74
+ ? { VERDACCIO_STORAGE_PATH: options.storage }
75
+ : {}),
76
+ },
77
+ stdio: 'inherit',
78
+ });
79
+ childProcess.on('error', (err) => {
80
+ reject(err);
81
+ });
82
+ childProcess.on('disconnect', (err) => {
83
+ reject(err);
84
+ });
85
+ childProcess.on('exit', (code) => {
86
+ if (code === 0) {
87
+ resolve(code);
88
+ }
89
+ else {
90
+ reject(code);
91
+ }
92
+ });
93
+ });
94
+ }
95
+ function createVerdaccioOptions(options, workspaceRoot) {
96
+ const verdaccioArgs = [];
97
+ if (options.port) {
98
+ verdaccioArgs.push('--listen', options.port.toString());
99
+ }
100
+ if (options.config) {
101
+ verdaccioArgs.push('--config', (0, path_1.join)(workspaceRoot, options.config));
102
+ }
103
+ return verdaccioArgs;
104
+ }
105
+ function setupNpm(options) {
106
+ try {
107
+ (0, child_process_1.execSync)('npm --version');
108
+ }
109
+ catch (e) {
110
+ return () => { };
111
+ }
112
+ let npmRegistryPath;
113
+ try {
114
+ npmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`)
115
+ ?.toString()
116
+ ?.trim()
117
+ ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
118
+ (0, child_process_1.execSync)(`npm config set registry http://localhost:${options.port}/ --location ${options.location}`);
119
+ (0, child_process_1.execSync)(`npm config set //localhost:${options.port}/:_authToken="secretVerdaccioToken" --location ${options.location}`);
120
+ devkit_1.logger.info(`Set npm registry to http://localhost:${options.port}/`);
121
+ }
122
+ catch (e) {
123
+ throw new Error(`Failed to set npm registry to http://localhost:${options.port}/: ${e.message}`);
124
+ }
125
+ return () => {
126
+ try {
127
+ const currentNpmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`)
128
+ ?.toString()
129
+ ?.trim()
130
+ ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
131
+ if (npmRegistryPath && currentNpmRegistryPath.includes('localhost')) {
132
+ (0, child_process_1.execSync)(`npm config set registry ${npmRegistryPath} --location ${options.location}`);
133
+ devkit_1.logger.info(`Reset npm registry to ${npmRegistryPath}`);
134
+ }
135
+ else {
136
+ (0, child_process_1.execSync)(`npm config delete registry --location ${options.location}`);
137
+ devkit_1.logger.info('Cleared custom npm registry');
138
+ }
139
+ (0, child_process_1.execSync)(`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`);
140
+ }
141
+ catch (e) {
142
+ throw new Error(`Failed to reset npm registry: ${e.message}`);
143
+ }
144
+ };
145
+ }
146
+ function getYarnUnsafeHttpWhitelist(isYarnV1) {
147
+ return !isYarnV1
148
+ ? new Set(JSON.parse((0, child_process_1.execSync)(`yarn config get unsafeHttpWhitelist --json`).toString()))
149
+ : null;
150
+ }
151
+ function setYarnUnsafeHttpWhitelist(currentWhitelist, options) {
152
+ if (currentWhitelist.size > 0) {
153
+ (0, child_process_1.execSync)(`yarn config set unsafeHttpWhitelist --json '${JSON.stringify(Array.from(currentWhitelist))}'` + (options.location === 'user' ? ' --home' : ''));
154
+ }
155
+ else {
156
+ (0, child_process_1.execSync)(`yarn config unset unsafeHttpWhitelist` +
157
+ (options.location === 'user' ? ' --home' : ''));
158
+ }
159
+ }
160
+ function setupYarn(options) {
161
+ let isYarnV1;
162
+ try {
163
+ isYarnV1 = (0, semver_1.major)((0, child_process_1.execSync)('yarn --version').toString().trim()) === 1;
164
+ }
165
+ catch {
166
+ // This would fail if yarn is not installed which is okay
167
+ return () => { };
168
+ }
169
+ try {
170
+ const registryConfigName = isYarnV1 ? 'registry' : 'npmRegistryServer';
171
+ const yarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`)
172
+ ?.toString()
173
+ ?.trim()
174
+ ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
175
+ (0, child_process_1.execSync)(`yarn config set ${registryConfigName} http://localhost:${options.port}/` +
176
+ (options.location === 'user' ? ' --home' : ''));
177
+ devkit_1.logger.info(`Set yarn registry to http://localhost:${options.port}/`);
178
+ const currentWhitelist = getYarnUnsafeHttpWhitelist(isYarnV1);
179
+ let whitelistedLocalhost = false;
180
+ if (!isYarnV1 && !currentWhitelist.has('localhost')) {
181
+ whitelistedLocalhost = true;
182
+ currentWhitelist.add('localhost');
183
+ setYarnUnsafeHttpWhitelist(currentWhitelist, options);
184
+ devkit_1.logger.info(`Whitelisted http://localhost:${options.port}/ as an unsafe http server`);
185
+ }
186
+ return () => {
187
+ try {
188
+ const currentYarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`)
189
+ ?.toString()
190
+ ?.trim()
191
+ ?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
192
+ if (yarnRegistryPath && currentYarnRegistryPath.includes('localhost')) {
193
+ (0, child_process_1.execSync)(`yarn config set ${registryConfigName} ${yarnRegistryPath}` +
194
+ (options.location === 'user' ? ' --home' : ''));
195
+ devkit_1.logger.info(`Reset yarn ${registryConfigName} to ${yarnRegistryPath}`);
196
+ }
197
+ else {
198
+ (0, child_process_1.execSync)(`yarn config ${isYarnV1 ? 'delete' : 'unset'} ${registryConfigName}` +
199
+ (options.location === 'user' ? ' --home' : ''));
200
+ devkit_1.logger.info(`Cleared custom yarn ${registryConfigName}`);
201
+ }
202
+ if (whitelistedLocalhost) {
203
+ const currentWhitelist = getYarnUnsafeHttpWhitelist(isYarnV1);
204
+ if (currentWhitelist.has('localhost')) {
205
+ currentWhitelist.delete('localhost');
206
+ setYarnUnsafeHttpWhitelist(currentWhitelist, options);
207
+ devkit_1.logger.info(`Removed http://localhost:${options.port}/ as an unsafe http server`);
208
+ }
209
+ }
210
+ }
211
+ catch (e) {
212
+ throw new Error(`Failed to reset yarn registry: ${e.message}`);
213
+ }
214
+ };
215
+ }
216
+ catch (e) {
217
+ throw new Error(`Failed to set yarn registry to http://localhost:${options.port}/: ${e.message}`);
218
+ }
219
+ }
220
+ exports.default = verdaccioExecutor;
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { ConvertToSwcGeneratorSchema } from './schema';
3
+ export declare function convertToSwcGenerator(tree: Tree, schema: ConvertToSwcGeneratorSchema): Promise<() => void>;
4
+ export default convertToSwcGenerator;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToSwcGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const add_swc_config_1 = require("../../utils/swc/add-swc-config");
7
+ const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
8
+ const versions_1 = require("../../utils/versions");
9
+ async function convertToSwcGenerator(tree, schema) {
10
+ const options = normalizeOptions(schema);
11
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.project);
12
+ updateProjectBuildTargets(tree, projectConfiguration, options.project, options.targets);
13
+ return checkSwcDependencies(tree, projectConfiguration);
14
+ }
15
+ exports.convertToSwcGenerator = convertToSwcGenerator;
16
+ function normalizeOptions(schema) {
17
+ const options = { ...schema };
18
+ if (!options.targets) {
19
+ options.targets = ['build'];
20
+ }
21
+ return options;
22
+ }
23
+ function updateProjectBuildTargets(tree, projectConfiguration, projectName, projectTargets) {
24
+ for (const target of projectTargets) {
25
+ const targetConfiguration = projectConfiguration.targets[target];
26
+ if (!targetConfiguration ||
27
+ (targetConfiguration.executor !== '@nx/js:tsc' &&
28
+ targetConfiguration.executor !== '@nrwl/js:tsc'))
29
+ continue;
30
+ targetConfiguration.executor = '@nx/js:swc';
31
+ }
32
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
33
+ }
34
+ function checkSwcDependencies(tree, projectConfiguration) {
35
+ const isSwcrcPresent = tree.exists((0, path_1.join)(projectConfiguration.root, '.swcrc'));
36
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
37
+ const projectPackageJsonPath = (0, path_1.join)(projectConfiguration.root, 'package.json');
38
+ const projectPackageJson = (0, devkit_1.readJson)(tree, projectPackageJsonPath);
39
+ const hasSwcDependency = packageJson.dependencies && packageJson.dependencies['@swc/core'];
40
+ const hasSwcHelpers = projectPackageJson.dependencies &&
41
+ projectPackageJson.dependencies['@swc/helpers'];
42
+ if (isSwcrcPresent && hasSwcDependency && hasSwcHelpers)
43
+ return;
44
+ if (!isSwcrcPresent) {
45
+ (0, add_swc_config_1.addSwcConfig)(tree, projectConfiguration.root);
46
+ }
47
+ if (!hasSwcDependency) {
48
+ (0, add_swc_dependencies_1.addSwcDependencies)(tree);
49
+ }
50
+ if (!hasSwcHelpers) {
51
+ (0, devkit_1.addDependenciesToPackageJson)(tree, { '@swc/helpers': versions_1.swcHelpersVersion }, {}, projectPackageJsonPath);
52
+ }
53
+ return () => {
54
+ if (!hasSwcDependency) {
55
+ (0, devkit_1.installPackagesTask)(tree);
56
+ }
57
+ };
58
+ }
59
+ exports.default = convertToSwcGenerator;
@@ -0,0 +1,4 @@
1
+ export interface ConvertToSwcGeneratorSchema {
2
+ project: string;
3
+ targets?: string[];
4
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxTypescriptLibrary",
4
+ "cli": "nx",
5
+ "title": "Convert a TSC library to SWC",
6
+ "description": "Convert a TSC library to SWC.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g swc mylib",
11
+ "description": "Convert `libs/myapp/mylib` to SWC."
12
+ }
13
+ ],
14
+ "properties": {
15
+ "project": {
16
+ "type": "string",
17
+ "description": "Library name.",
18
+ "$default": {
19
+ "$source": "argv",
20
+ "index": 0
21
+ },
22
+ "x-prompt": "What name would you like to use for the library?",
23
+ "pattern": "^[a-zA-Z].*$"
24
+ },
25
+ "targets": {
26
+ "type": "array",
27
+ "description": "List of targets to convert.",
28
+ "items": {
29
+ "type": "string",
30
+ "description": "Target to convert."
31
+ },
32
+ "default": ["build"]
33
+ }
34
+ },
35
+ "required": ["project"]
36
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "compileOnSave": false,
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "sourceMap": true,
6
+ "declaration": false,
7
+ "moduleResolution": "node",
8
+ "emitDecoratorMetadata": true,
9
+ "experimentalDecorators": true,
10
+ "importHelpers": true,
11
+ "target": "es2015",
12
+ "module": "esnext",
13
+ "lib": ["es2020", "dom"],
14
+ "skipLibCheck": true,
15
+ "skipDefaultLibCheck": true,
16
+ "baseUrl": ".",
17
+ "paths": {}
18
+ },
19
+ "exclude": ["node_modules", "tmp"]
20
+ }
@@ -0,0 +1,4 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { InitSchema } from './schema';
3
+ export declare function initGenerator(tree: Tree, schema: InitSchema): Promise<GeneratorCallback>;
4
+ export default initGenerator;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const semver_1 = require("@nx/devkit/src/utils/semver");
6
+ const package_json_1 = require("nx/src/utils/package-json");
7
+ const semver_2 = require("semver");
8
+ const ts_config_1 = require("../../utils/typescript/ts-config");
9
+ const versions_1 = require("../../utils/versions");
10
+ const path_1 = require("path");
11
+ async function getInstalledTypescriptVersion(tree) {
12
+ const rootPackageJson = (0, devkit_1.readJson)(tree, 'package.json');
13
+ const tsVersionInRootPackageJson = rootPackageJson.devDependencies?.['typescript'] ??
14
+ rootPackageJson.dependencies?.['typescript'];
15
+ if (!tsVersionInRootPackageJson) {
16
+ return null;
17
+ }
18
+ if ((0, semver_2.valid)(tsVersionInRootPackageJson)) {
19
+ // it's a pinned version, return it
20
+ return tsVersionInRootPackageJson;
21
+ }
22
+ // it's a version range, check whether the installed version matches it
23
+ try {
24
+ const tsPackageJson = (0, package_json_1.readModulePackageJson)('typescript').packageJson;
25
+ const installedTsVersion = tsPackageJson.devDependencies?.['typescript'] ??
26
+ tsPackageJson.dependencies?.['typescript'];
27
+ // the installed version matches the package.json version range
28
+ if (installedTsVersion &&
29
+ (0, semver_2.satisfies)(installedTsVersion, tsVersionInRootPackageJson)) {
30
+ return installedTsVersion;
31
+ }
32
+ }
33
+ finally {
34
+ return (0, semver_1.checkAndCleanWithSemver)('typescript', tsVersionInRootPackageJson);
35
+ }
36
+ }
37
+ async function initGenerator(tree, schema) {
38
+ const tasks = [];
39
+ // add tsconfig.base.json
40
+ if (!(0, ts_config_1.getRootTsConfigFileName)(tree)) {
41
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), '.', {
42
+ fileName: schema.tsConfigName ?? 'tsconfig.base.json',
43
+ });
44
+ }
45
+ const devDependencies = {
46
+ '@nx/js': versions_1.nxVersion,
47
+ prettier: versions_1.prettierVersion,
48
+ // When loading .ts config files (e.g. webpack.config.ts, jest.config.ts, etc.)
49
+ // we prefer to use SWC, and fallback to ts-node for workspaces that don't use SWC.
50
+ '@swc-node/register': versions_1.swcNodeVersion,
51
+ '@swc/core': versions_1.swcCoreVersion,
52
+ '@swc/helpers': versions_1.swcHelpersVersion,
53
+ };
54
+ if (!schema.js && !schema.keepExistingVersions) {
55
+ const installedTsVersion = await getInstalledTypescriptVersion(tree);
56
+ if (!installedTsVersion ||
57
+ !(0, semver_2.satisfies)(installedTsVersion, versions_1.supportedTypescriptVersions, {
58
+ includePrerelease: true,
59
+ })) {
60
+ devDependencies['typescript'] = versions_1.typescriptVersion;
61
+ }
62
+ }
63
+ // https://prettier.io/docs/en/configuration.html
64
+ const prettierrcNameOptions = [
65
+ '.prettierrc',
66
+ '.prettierrc.json',
67
+ '.prettierrc.yml',
68
+ '.prettierrc.yaml',
69
+ '.prettierrc.json5',
70
+ '.prettierrc.js',
71
+ '.prettierrc.cjs',
72
+ 'prettier.config.js',
73
+ 'prettier.config.cjs',
74
+ '.prettierrc.toml',
75
+ ];
76
+ if (prettierrcNameOptions.every((name) => !tree.exists(name))) {
77
+ (0, devkit_1.writeJson)(tree, '.prettierrc', {
78
+ singleQuote: true,
79
+ });
80
+ }
81
+ if (!tree.exists(`.prettierignore`)) {
82
+ tree.write('.prettierignore', (0, devkit_1.stripIndents) `
83
+ # Add files here to ignore them from prettier formatting
84
+ /dist
85
+ /coverage
86
+ /.nx/cache
87
+ `);
88
+ }
89
+ if (tree.exists('.vscode/extensions.json')) {
90
+ (0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
91
+ json.recommendations ??= [];
92
+ const extension = 'esbenp.prettier-vscode';
93
+ if (!json.recommendations.includes(extension)) {
94
+ json.recommendations.push(extension);
95
+ }
96
+ return json;
97
+ });
98
+ }
99
+ const installTask = !schema.skipPackageJson
100
+ ? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions)
101
+ : () => { };
102
+ tasks.push(installTask);
103
+ (0, devkit_1.ensurePackage)('prettier', versions_1.prettierVersion);
104
+ if (!schema.skipFormat) {
105
+ await (0, devkit_1.formatFiles)(tree);
106
+ }
107
+ return async () => {
108
+ for (const task of tasks) {
109
+ await task();
110
+ }
111
+ };
112
+ }
113
+ exports.initGenerator = initGenerator;
114
+ exports.default = initGenerator;
@@ -0,0 +1,7 @@
1
+ export interface InitSchema {
2
+ js?: boolean;
3
+ skipFormat?: boolean;
4
+ skipPackageJson?: boolean;
5
+ keepExistingVersions?: boolean;
6
+ tsConfigName?: string;
7
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxTypescriptInit",
4
+ "cli": "nx",
5
+ "title": "Init nx/js",
6
+ "description": "Init generator placeholder for nx/js.",
7
+ "properties": {
8
+ "js": {
9
+ "type": "boolean",
10
+ "default": false,
11
+ "description": "Use JavaScript instead of TypeScript"
12
+ },
13
+ "skipFormat": {
14
+ "type": "boolean",
15
+ "aliases": ["skip-format"],
16
+ "description": "Skip formatting files.",
17
+ "x-priority": "internal"
18
+ },
19
+ "skipPackageJson": {
20
+ "type": "boolean",
21
+ "description": "Skip adding package.json dependencies",
22
+ "x-priority": "internal"
23
+ },
24
+ "keepExistingVersions": {
25
+ "type": "boolean",
26
+ "x-priority": "internal",
27
+ "description": "Keep existing dependencies versions",
28
+ "default": false
29
+ },
30
+ "tsConfigName": {
31
+ "type": "string",
32
+ "description": "Customize the generated tsconfig file name.",
33
+ "x-priority": "internal"
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,30 @@
1
+ /* eslint-disable */
2
+ <% if(js) {%>const { readFileSync } = require('fs')<% } else { %>import { readFileSync } from 'fs';<% } %>
3
+
4
+ // Reading the SWC compilation config and remove the "exclude"
5
+ // for the test files to be compiled by SWC
6
+ const { exclude: _, ...swcJestConfig } = JSON.parse(
7
+ readFileSync(`${__dirname}/.swcrc`, 'utf-8')
8
+ );
9
+
10
+ // disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
11
+ // If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
12
+ if (swcJestConfig.swcrc === undefined) {
13
+ swcJestConfig.swcrc = false;
14
+ }
15
+
16
+ // Uncomment if using global setup/teardown files being transformed via swc
17
+ // https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
18
+ // jest needs EsModule Interop to find the default exported setup/teardown functions
19
+ // swcJestConfig.module.noInterop = false;
20
+
21
+ <% if(js) {%>module.exports =<% } else { %>export default<% } %> {
22
+ displayName: '<%= project %>',
23
+ preset: '<%= offsetFromRoot %>jest.preset.js',
24
+ transform: {
25
+ '^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
26
+ },
27
+ moduleFileExtensions: ['ts', 'js', 'html'],
28
+ testEnvironment: '<%= testEnvironment %>',
29
+ coverageDirectory: '<%= offsetFromRoot %>coverage/<%= projectRoot %>'
30
+ };
@@ -0,0 +1 @@
1
+ export * from './lib/<%= fileName %>';
@@ -0,0 +1,7 @@
1
+ import { <%= propertyName %> } from './<%= fileName %>';
2
+
3
+ describe('<%= propertyName %>', () => {
4
+ it('should work', () => {
5
+ expect(<%= propertyName %>()).toEqual('<%= name %>');
6
+ })
7
+ })
@@ -0,0 +1,3 @@
1
+ export function <%= propertyName %>(): string {
2
+ return '<%= name %>';
3
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
+ "declaration": true,
6
+ "types": ["node"]
7
+ },
8
+ "include": ["src/**/*.ts"<% if (js) { %>, "src/**/*.js"<% } %>],
9
+ "exclude": [
10
+ <% if (hasUnitTestRunner && unitTestRunner === 'jest') { %>"jest.config.ts",
11
+ <% } else if (hasUnitTestRunner) { %>"vite.config.ts",
12
+ <% } %>"src/**/*.spec.ts", "src/**/*.test.ts"<% if (js) { %>, "src/**/*.spec.js", "src/**/*.test.js"<% } %>
13
+ ]
14
+ }
@@ -0,0 +1,19 @@
1
+ # <%= name %>
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ <% if (buildable) { %>
6
+
7
+ ## Building
8
+
9
+ Run `<%= cliCommand %> build <%= name %>` to build the library.
10
+
11
+ <% } %>
12
+
13
+ <% if (hasUnitTestRunner) { %>
14
+
15
+ ## Running unit tests
16
+
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
+ <% } %>
@@ -0,0 +1,16 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { type ProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
3
+ import { LibraryGeneratorSchema } from '../../utils/schema';
4
+ export declare function libraryGenerator(tree: Tree, schema: LibraryGeneratorSchema): Promise<GeneratorCallback>;
5
+ export declare function libraryGeneratorInternal(tree: Tree, schema: LibraryGeneratorSchema): Promise<GeneratorCallback>;
6
+ export interface NormalizedSchema extends LibraryGeneratorSchema {
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'>;
15
+ export declare function addLint(tree: Tree, options: AddLintOptions): Promise<GeneratorCallback>;
16
+ export default libraryGenerator;