@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,198 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const child_process_1 = require("child_process");
5
+ const npm_run_path_1 = require("npm-run-path");
6
+ const log_tar_1 = require("./log-tar");
7
+ const chalk = require("chalk");
8
+ const LARGE_BUFFER = 1024 * 1000000;
9
+ function processEnv(color) {
10
+ const env = {
11
+ ...process.env,
12
+ ...(0, npm_run_path_1.env)(),
13
+ };
14
+ if (color) {
15
+ env.FORCE_COLOR = `${color}`;
16
+ }
17
+ return env;
18
+ }
19
+ async function runExecutor(options, context) {
20
+ /**
21
+ * We need to check both the env var and the option because the executor may have been triggered
22
+ * indirectly via dependsOn, in which case the env var will be set, but the option will not.
23
+ */
24
+ const isDryRun = process.env.NX_DRY_RUN === 'true' || options.dryRun || false;
25
+ const projectConfig = context.projectsConfigurations.projects[context.projectName];
26
+ const packageRoot = (0, devkit_1.joinPathFragments)(context.root, options.packageRoot ?? projectConfig.root);
27
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
28
+ const projectPackageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
29
+ const packageName = projectPackageJson.name;
30
+ // If package and project name match, we can make log messages terser
31
+ let packageTxt = packageName === context.projectName
32
+ ? `package "${packageName}"`
33
+ : `package "${packageName}" from project "${context.projectName}"`;
34
+ if (projectPackageJson.private === true) {
35
+ console.warn(`Skipped ${packageTxt}, because it has \`"private": true\` in ${packageJsonPath}`);
36
+ return {
37
+ success: true,
38
+ };
39
+ }
40
+ const npmPublishCommandSegments = [`npm publish --json`];
41
+ const npmViewCommandSegments = [
42
+ `npm view ${packageName} versions dist-tags --json`,
43
+ ];
44
+ if (options.registry) {
45
+ npmPublishCommandSegments.push(`--registry=${options.registry}`);
46
+ npmViewCommandSegments.push(`--registry=${options.registry}`);
47
+ }
48
+ if (options.tag) {
49
+ npmPublishCommandSegments.push(`--tag=${options.tag}`);
50
+ }
51
+ if (options.otp) {
52
+ npmPublishCommandSegments.push(`--otp=${options.otp}`);
53
+ }
54
+ if (isDryRun) {
55
+ npmPublishCommandSegments.push(`--dry-run`);
56
+ }
57
+ // Resolve values using the `npm config` command so that things like environment variables and `publishConfig`s are accounted for
58
+ const registry = options.registry ?? (0, child_process_1.execSync)(`npm config get registry`).toString().trim();
59
+ const tag = options.tag ?? (0, child_process_1.execSync)(`npm config get tag`).toString().trim();
60
+ /**
61
+ * In a dry-run scenario, it is most likely that all commands are being run with dry-run, therefore
62
+ * the most up to date/relevant version might not exist on disk for us to read and make the npm view
63
+ * request with.
64
+ *
65
+ * Therefore, so as to not produce misleading output in dry around dist-tags being altered, we do not
66
+ * perform the npm view step, and just show npm publish's dry-run output.
67
+ */
68
+ if (!isDryRun && !options.firstRelease) {
69
+ const currentVersion = projectPackageJson.version;
70
+ try {
71
+ const result = (0, child_process_1.execSync)(npmViewCommandSegments.join(' '), {
72
+ env: processEnv(true),
73
+ cwd: packageRoot,
74
+ stdio: ['ignore', 'pipe', 'pipe'],
75
+ });
76
+ const resultJson = JSON.parse(result.toString());
77
+ const distTags = resultJson['dist-tags'] || {};
78
+ if (distTags[tag] === currentVersion) {
79
+ console.warn(`Skipped ${packageTxt} because v${currentVersion} already exists in ${registry} with tag "${tag}"`);
80
+ return {
81
+ success: true,
82
+ };
83
+ }
84
+ if (resultJson.versions.includes(currentVersion)) {
85
+ try {
86
+ if (!isDryRun) {
87
+ (0, child_process_1.execSync)(`npm dist-tag add ${packageName}@${currentVersion} ${tag} --registry=${registry}`, {
88
+ env: processEnv(true),
89
+ cwd: packageRoot,
90
+ stdio: 'ignore',
91
+ });
92
+ console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`);
93
+ }
94
+ else {
95
+ console.log(`Would add the dist-tag ${tag} to v${currentVersion} for registry ${registry}, but ${chalk.keyword('orange')('[dry-run]')} was set.\n`);
96
+ }
97
+ return {
98
+ success: true,
99
+ };
100
+ }
101
+ catch (err) {
102
+ try {
103
+ const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
104
+ // If the error is that the package doesn't exist, then we can ignore it because we will be publishing it for the first time in the next step
105
+ if (!(stdoutData.error?.code?.includes('E404') &&
106
+ stdoutData.error?.summary?.includes('no such package available')) &&
107
+ !(err.stderr?.toString().includes('E404') &&
108
+ err.stderr?.toString().includes('no such package available'))) {
109
+ console.error('npm dist-tag add error:');
110
+ if (stdoutData.error.summary) {
111
+ console.error(stdoutData.error.summary);
112
+ }
113
+ if (stdoutData.error.detail) {
114
+ console.error(stdoutData.error.detail);
115
+ }
116
+ if (context.isVerbose) {
117
+ console.error('npm dist-tag add stdout:');
118
+ console.error(JSON.stringify(stdoutData, null, 2));
119
+ }
120
+ return {
121
+ success: false,
122
+ };
123
+ }
124
+ }
125
+ catch (err) {
126
+ console.error('Something unexpected went wrong when processing the npm dist-tag add output\n', err);
127
+ return {
128
+ success: false,
129
+ };
130
+ }
131
+ }
132
+ }
133
+ }
134
+ catch (err) {
135
+ const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
136
+ // If the error is that the package doesn't exist, then we can ignore it because we will be publishing it for the first time in the next step
137
+ if (!(stdoutData.error?.code?.includes('E404') &&
138
+ stdoutData.error?.summary?.toLowerCase().includes('not found')) &&
139
+ !(err.stderr?.toString().includes('E404') &&
140
+ err.stderr?.toString().toLowerCase().includes('not found'))) {
141
+ console.error(`Something unexpected went wrong when checking for existing dist-tags.\n`, err);
142
+ return {
143
+ success: false,
144
+ };
145
+ }
146
+ }
147
+ }
148
+ if (options.firstRelease && context.isVerbose) {
149
+ console.log('Skipped npm view because --first-release was set');
150
+ }
151
+ try {
152
+ const output = (0, child_process_1.execSync)(npmPublishCommandSegments.join(' '), {
153
+ maxBuffer: LARGE_BUFFER,
154
+ env: processEnv(true),
155
+ cwd: packageRoot,
156
+ stdio: ['ignore', 'pipe', 'pipe'],
157
+ });
158
+ const stdoutData = JSON.parse(output.toString());
159
+ // If npm workspaces are in use, the publish output will nest the data under the package name, so we normalize it first
160
+ const normalizedStdoutData = stdoutData[packageName] ?? stdoutData;
161
+ (0, log_tar_1.logTar)(normalizedStdoutData);
162
+ if (isDryRun) {
163
+ console.log(`Would publish to ${registry} with tag "${tag}", but ${chalk.keyword('orange')('[dry-run]')} was set`);
164
+ }
165
+ else {
166
+ console.log(`Published to ${registry} with tag "${tag}"`);
167
+ }
168
+ return {
169
+ success: true,
170
+ };
171
+ }
172
+ catch (err) {
173
+ try {
174
+ const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
175
+ console.error('npm publish error:');
176
+ if (stdoutData.error.summary) {
177
+ console.error(stdoutData.error.summary);
178
+ }
179
+ if (stdoutData.error.detail) {
180
+ console.error(stdoutData.error.detail);
181
+ }
182
+ if (context.isVerbose) {
183
+ console.error('npm publish stdout:');
184
+ console.error(JSON.stringify(stdoutData, null, 2));
185
+ }
186
+ return {
187
+ success: false,
188
+ };
189
+ }
190
+ catch (err) {
191
+ console.error('Something unexpected went wrong when processing the npm publish output\n', err);
192
+ return {
193
+ success: false,
194
+ };
195
+ }
196
+ }
197
+ }
198
+ exports.default = runExecutor;
@@ -0,0 +1,8 @@
1
+ export interface PublishExecutorSchema {
2
+ packageRoot?: string;
3
+ registry?: string;
4
+ tag?: string;
5
+ otp?: number;
6
+ dryRun?: boolean;
7
+ firstRelease?: boolean;
8
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "version": 2,
4
+ "title": "Implementation details of `nx release publish`",
5
+ "description": "DO NOT INVOKE DIRECTLY WITH `nx run`. Use `nx release publish` instead.",
6
+ "type": "object",
7
+ "properties": {
8
+ "packageRoot": {
9
+ "type": "string",
10
+ "description": "The root directory of the directory (containing a manifest file at its root) to publish. Defaults to the project root."
11
+ },
12
+ "registry": {
13
+ "type": "string",
14
+ "description": "The registry to publish the package to."
15
+ },
16
+ "tag": {
17
+ "type": "string",
18
+ "description": "The distribution tag to apply to the published package."
19
+ },
20
+ "dryRun": {
21
+ "type": "boolean",
22
+ "description": "Whether to run the command without actually publishing the package to the registry."
23
+ }
24
+ },
25
+ "required": []
26
+ }
@@ -0,0 +1,154 @@
1
+ {
2
+ "version": 2,
3
+ "outputCapture": "direct-nodejs",
4
+ "$schema": "https://json-schema.org/schema",
5
+ "cli": "nx",
6
+ "title": "Typescript Build Target",
7
+ "description": "Builds using SWC.",
8
+ "type": "object",
9
+ "properties": {
10
+ "main": {
11
+ "type": "string",
12
+ "description": "The name of the main entry-point file.",
13
+ "x-completion-type": "file",
14
+ "x-completion-glob": "main@(.js|.ts|.tsx)",
15
+ "x-priority": "important"
16
+ },
17
+ "generateExportsField": {
18
+ "type": "boolean",
19
+ "alias": "exports",
20
+ "description": "Update the output package.json file's 'exports' field. This field is used by Node and bundles.",
21
+ "x-priority": "important",
22
+ "default": false
23
+ },
24
+ "additionalEntryPoints": {
25
+ "type": "array",
26
+ "description": "Additional entry-points to add to exports field in the package.json file.",
27
+ "items": {
28
+ "type": "string"
29
+ },
30
+ "x-priority": "important"
31
+ },
32
+ "outputPath": {
33
+ "type": "string",
34
+ "description": "The output path of the generated files.",
35
+ "x-completion-type": "directory",
36
+ "x-priority": "important"
37
+ },
38
+ "tsConfig": {
39
+ "type": "string",
40
+ "description": "The path to the Typescript configuration file.",
41
+ "x-completion-type": "file",
42
+ "x-completion-glob": "tsconfig.*.json",
43
+ "x-priority": "important"
44
+ },
45
+ "swcrc": {
46
+ "type": "string",
47
+ "description": "The path to the SWC configuration file. Default: .swcrc",
48
+ "x-completion-type": "file",
49
+ "x-completion-glob": ".swcrc"
50
+ },
51
+ "assets": {
52
+ "type": "array",
53
+ "description": "List of static assets.",
54
+ "default": [],
55
+ "items": {
56
+ "$ref": "#/definitions/assetPattern"
57
+ }
58
+ },
59
+ "watch": {
60
+ "type": "boolean",
61
+ "description": "Enable re-building when files change.",
62
+ "default": false
63
+ },
64
+ "clean": {
65
+ "type": "boolean",
66
+ "description": "Remove previous output before build.",
67
+ "default": true
68
+ },
69
+ "skipTypeCheck": {
70
+ "type": "boolean",
71
+ "description": "Whether to skip TypeScript type checking.",
72
+ "default": false,
73
+ "x-priority": "important"
74
+ },
75
+ "swcExclude": {
76
+ "type": "array",
77
+ "description": "List of SWC Glob/Regex to be excluded from compilation (https://swc.rs/docs/configuration/compilation#exclude).",
78
+ "default": [
79
+ "./src/**/.*.spec.ts$",
80
+ "./**/.*.spec.ts$",
81
+ "./src/**/jest-setup.ts$",
82
+ "./**/jest-setup.ts$",
83
+ "./**/.*.js$"
84
+ ],
85
+ "hidden": true
86
+ },
87
+ "external": {
88
+ "description": "A list projects to be treated as external. This feature is experimental",
89
+ "oneOf": [
90
+ {
91
+ "type": "string",
92
+ "enum": ["all", "none"]
93
+ },
94
+ {
95
+ "type": "array",
96
+ "items": {
97
+ "type": "string"
98
+ }
99
+ }
100
+ ]
101
+ },
102
+ "externalBuildTargets": {
103
+ "type": "array",
104
+ "items": {
105
+ "type": "string"
106
+ },
107
+ "description": "List of target names that annotate a build target for a project",
108
+ "default": ["build"]
109
+ },
110
+ "generateLockfile": {
111
+ "type": "boolean",
112
+ "description": "Generate a lockfile (e.g. package-lock.json) that matches the workspace lockfile to ensure package versions match.",
113
+ "default": false,
114
+ "x-priority": "internal"
115
+ }
116
+ },
117
+ "required": ["main", "outputPath", "tsConfig"],
118
+ "definitions": {
119
+ "assetPattern": {
120
+ "oneOf": [
121
+ {
122
+ "type": "object",
123
+ "properties": {
124
+ "glob": {
125
+ "type": "string",
126
+ "description": "The pattern to match."
127
+ },
128
+ "input": {
129
+ "type": "string",
130
+ "description": "The input directory path in which to apply 'glob'. Defaults to the project root."
131
+ },
132
+ "ignore": {
133
+ "description": "An array of globs to ignore.",
134
+ "type": "array",
135
+ "items": {
136
+ "type": "string"
137
+ }
138
+ },
139
+ "output": {
140
+ "type": "string",
141
+ "description": "Absolute path within the output."
142
+ }
143
+ },
144
+ "additionalProperties": false,
145
+ "required": ["glob", "input", "output"]
146
+ },
147
+ {
148
+ "type": "string"
149
+ }
150
+ ]
151
+ }
152
+ },
153
+ "examplesFile": "../../../docs/swc-examples.md"
154
+ }
@@ -0,0 +1,10 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import { SwcExecutorOptions } from '../../utils/schema';
3
+ export declare function swcExecutor(_options: SwcExecutorOptions, context: ExecutorContext): AsyncGenerator<{
4
+ success: boolean;
5
+ outfile?: undefined;
6
+ } | {
7
+ success: boolean;
8
+ outfile: string;
9
+ }, any, undefined>;
10
+ export default swcExecutor;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.swcExecutor = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const assets_1 = require("../../utils/assets/assets");
6
+ const fs_extra_1 = require("fs-extra");
7
+ const fast_glob_1 = require("fast-glob");
8
+ const path_1 = require("path");
9
+ const assets_2 = require("../../utils/assets");
10
+ const check_dependencies_1 = require("../../utils/check-dependencies");
11
+ const compiler_helper_dependency_1 = require("../../utils/compiler-helper-dependency");
12
+ const inline_1 = require("../../utils/inline");
13
+ const package_json_1 = require("../../utils/package-json");
14
+ const compile_swc_1 = require("../../utils/swc/compile-swc");
15
+ const get_swcrc_path_1 = require("../../utils/swc/get-swcrc-path");
16
+ const inline_2 = require("../../utils/swc/inline");
17
+ function normalizeOptions(options, root, sourceRoot, projectRoot) {
18
+ const outputPath = (0, path_1.join)(root, options.outputPath);
19
+ if (options.skipTypeCheck == null) {
20
+ options.skipTypeCheck = false;
21
+ }
22
+ if (options.watch == null) {
23
+ options.watch = false;
24
+ }
25
+ // TODO: put back when inlining story is more stable
26
+ // if (options.external == null) {
27
+ // options.external = 'all';
28
+ // } else if (Array.isArray(options.external) && options.external.length === 0) {
29
+ // options.external = 'none';
30
+ // }
31
+ if (Array.isArray(options.external) && options.external.length > 0) {
32
+ const firstItem = options.external[0];
33
+ if (firstItem === 'all' || firstItem === 'none') {
34
+ options.external = firstItem;
35
+ }
36
+ }
37
+ const files = (0, assets_1.assetGlobsToFiles)(options.assets, root, outputPath);
38
+ const projectRootParts = projectRoot.split('/');
39
+ // We pop the last part of the `projectRoot` to pass
40
+ // the last part (projectDir) and the remainder (projectRootParts) to swc
41
+ const projectDir = projectRootParts.pop();
42
+ // default to current directory if projectRootParts is [].
43
+ // Eg: when a project is at the root level, outside of layout dir
44
+ const swcCwd = projectRootParts.join('/') || '.';
45
+ const { swcrcPath, tmpSwcrcPath } = (0, get_swcrc_path_1.getSwcrcPath)(options, root, projectRoot);
46
+ const swcCliOptions = {
47
+ srcPath: projectDir,
48
+ destPath: (0, path_1.relative)((0, path_1.join)(root, swcCwd), outputPath),
49
+ swcCwd,
50
+ swcrcPath,
51
+ };
52
+ return {
53
+ ...options,
54
+ mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')),
55
+ files,
56
+ root,
57
+ sourceRoot,
58
+ projectRoot,
59
+ originalProjectRoot: projectRoot,
60
+ outputPath,
61
+ tsConfig: (0, path_1.join)(root, options.tsConfig),
62
+ swcCliOptions,
63
+ tmpSwcrcPath,
64
+ };
65
+ }
66
+ async function* swcExecutor(_options, context) {
67
+ const { sourceRoot, root } = context.projectsConfigurations.projects[context.projectName];
68
+ const options = normalizeOptions(_options, context.root, sourceRoot, root);
69
+ const { tmpTsConfig, dependencies } = (0, check_dependencies_1.checkDependencies)(context, options.tsConfig);
70
+ if (tmpTsConfig) {
71
+ options.tsConfig = tmpTsConfig;
72
+ }
73
+ const swcHelperDependency = (0, compiler_helper_dependency_1.getHelperDependency)(compiler_helper_dependency_1.HelperDependency.swc, options.swcCliOptions.swcrcPath, dependencies, context.projectGraph);
74
+ if (swcHelperDependency) {
75
+ dependencies.push(swcHelperDependency);
76
+ }
77
+ const inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, options.tsConfig);
78
+ if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
79
+ options.projectRoot = '.'; // set to root of workspace to include other libs for type check
80
+ // remap paths for SWC compilation
81
+ options.swcCliOptions.srcPath = options.swcCliOptions.swcCwd;
82
+ options.swcCliOptions.swcCwd = '.';
83
+ options.swcCliOptions.destPath = (0, path_1.join)(options.swcCliOptions.destPath.split((0, path_1.normalize)('../')).at(-1), options.swcCliOptions.srcPath);
84
+ // tmp swcrc with dependencies to exclude
85
+ // - buildable libraries
86
+ // - other libraries that are not dependent on the current project
87
+ options.swcCliOptions.swcrcPath = (0, inline_2.generateTmpSwcrc)(inlineProjectGraph, options.swcCliOptions.swcrcPath, options.tmpSwcrcPath);
88
+ }
89
+ function determineModuleFormatFromSwcrc(absolutePathToSwcrc) {
90
+ const swcrc = (0, devkit_1.readJsonFile)(absolutePathToSwcrc);
91
+ return swcrc.module?.type?.startsWith('es') ? 'esm' : 'cjs';
92
+ }
93
+ if (options.watch) {
94
+ let disposeFn;
95
+ process.on('SIGINT', () => disposeFn());
96
+ process.on('SIGTERM', () => disposeFn());
97
+ return yield* (0, compile_swc_1.compileSwcWatch)(context, options, async () => {
98
+ const assetResult = await (0, assets_2.copyAssets)(options, context);
99
+ const packageJsonResult = await (0, package_json_1.copyPackageJson)({
100
+ ...options,
101
+ additionalEntryPoints: createEntryPoints(options, context),
102
+ format: [
103
+ determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
104
+ ],
105
+ // As long as d.ts files match their .js counterparts, we don't need to emit them.
106
+ // TSC can match them correctly based on file names.
107
+ skipTypings: true,
108
+ }, context);
109
+ removeTmpSwcrc(options.swcCliOptions.swcrcPath);
110
+ disposeFn = () => {
111
+ assetResult?.stop();
112
+ packageJsonResult?.stop();
113
+ };
114
+ });
115
+ }
116
+ else {
117
+ return yield (0, compile_swc_1.compileSwc)(context, options, async () => {
118
+ await (0, assets_2.copyAssets)(options, context);
119
+ await (0, package_json_1.copyPackageJson)({
120
+ ...options,
121
+ additionalEntryPoints: createEntryPoints(options, context),
122
+ format: [
123
+ determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
124
+ ],
125
+ // As long as d.ts files match their .js counterparts, we don't need to emit them.
126
+ // TSC can match them correctly based on file names.
127
+ skipTypings: true,
128
+ extraDependencies: swcHelperDependency ? [swcHelperDependency] : [],
129
+ }, context);
130
+ removeTmpSwcrc(options.swcCliOptions.swcrcPath);
131
+ (0, inline_1.postProcessInlinedDependencies)(options.outputPath, options.originalProjectRoot, inlineProjectGraph);
132
+ });
133
+ }
134
+ }
135
+ exports.swcExecutor = swcExecutor;
136
+ function removeTmpSwcrc(swcrcPath) {
137
+ if (swcrcPath.includes((0, path_1.normalize)('tmp/')) &&
138
+ swcrcPath.includes('.generated.swcrc')) {
139
+ (0, fs_extra_1.removeSync)((0, path_1.dirname)(swcrcPath));
140
+ }
141
+ }
142
+ function createEntryPoints(options, context) {
143
+ if (!options.additionalEntryPoints?.length)
144
+ return [];
145
+ return (0, fast_glob_1.sync)(options.additionalEntryPoints, {
146
+ cwd: context.root,
147
+ });
148
+ }
149
+ exports.default = swcExecutor;
@@ -0,0 +1,5 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { NormalizedExecutorOptions } from '../../../../utils/schema';
3
+ import type { TypescriptInMemoryTsConfig } from '../typescript-compilation';
4
+ import type { TaskInfo } from './types';
5
+ export declare function createTaskInfoPerTsConfigMap(tasksOptions: Record<string, NormalizedExecutorOptions>, context: ExecutorContext, tasks: string[], taskInMemoryTsConfigMap: Record<string, TypescriptInMemoryTsConfig>): Record<string, TaskInfo>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTaskInfoPerTsConfigMap = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const copy_assets_handler_1 = require("../../../../utils/assets/copy-assets-handler");
7
+ const buildable_libs_utils_1 = require("../../../../utils/buildable-libs-utils");
8
+ const get_task_options_1 = require("../get-task-options");
9
+ const taskTsConfigCache = new Set();
10
+ function createTaskInfoPerTsConfigMap(tasksOptions, context, tasks, taskInMemoryTsConfigMap) {
11
+ const tsConfigTaskInfoMap = {};
12
+ processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOptions, context, tasks, taskInMemoryTsConfigMap);
13
+ return tsConfigTaskInfoMap;
14
+ }
15
+ exports.createTaskInfoPerTsConfigMap = createTaskInfoPerTsConfigMap;
16
+ function processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOptions, context, tasks, taskInMemoryTsConfigMap) {
17
+ for (const taskName of tasks) {
18
+ if (taskTsConfigCache.has(taskName)) {
19
+ continue;
20
+ }
21
+ const tsConfig = taskInMemoryTsConfigMap[taskName];
22
+ if (!tsConfig) {
23
+ continue;
24
+ }
25
+ let taskOptions = tasksOptions[taskName] ?? (0, get_task_options_1.getTaskOptions)(taskName, context);
26
+ if (taskOptions) {
27
+ const taskInfo = createTaskInfo(taskName, taskOptions, context, tsConfig);
28
+ const tsConfigPath = (0, path_1.join)(context.root, (0, path_1.relative)(context.root, taskOptions.tsConfig)).replace(/\\/g, '/');
29
+ tsConfigTaskInfoMap[tsConfigPath] = taskInfo;
30
+ taskTsConfigCache.add(taskName);
31
+ }
32
+ processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOptions, context, context.taskGraph.dependencies[taskName], taskInMemoryTsConfigMap);
33
+ }
34
+ }
35
+ function createTaskInfo(taskName, taskOptions, context, tsConfig) {
36
+ const target = (0, devkit_1.parseTargetString)(taskName, context);
37
+ const taskContext = {
38
+ ...context,
39
+ // batch executors don't get these in the context, we provide them
40
+ // here per task
41
+ projectName: target.project,
42
+ targetName: target.target,
43
+ configurationName: target.configuration,
44
+ };
45
+ const assetsHandler = new copy_assets_handler_1.CopyAssetsHandler({
46
+ projectDir: taskOptions.projectRoot,
47
+ rootDir: context.root,
48
+ outputDir: taskOptions.outputPath,
49
+ assets: taskOptions.assets,
50
+ });
51
+ const { target: projectGraphNode, dependencies: buildableProjectNodeDependencies, } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.taskGraph.tasks[taskName].target.project, context.taskGraph.tasks[taskName].target.target, context.taskGraph.tasks[taskName].target.configuration);
52
+ return {
53
+ task: taskName,
54
+ options: taskOptions,
55
+ context: taskContext,
56
+ assetsHandler,
57
+ buildableProjectNodeDependencies,
58
+ projectGraphNode,
59
+ tsConfig,
60
+ terminalOutput: '',
61
+ };
62
+ }
@@ -0,0 +1,4 @@
1
+ export * from './build-task-info-per-tsconfig-map';
2
+ export * from './normalize-tasks-options';
3
+ export * from './types';
4
+ export * from './watch';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./build-task-info-per-tsconfig-map"), exports);
5
+ tslib_1.__exportStar(require("./normalize-tasks-options"), exports);
6
+ tslib_1.__exportStar(require("./types"), exports);
7
+ tslib_1.__exportStar(require("./watch"), exports);
@@ -0,0 +1,3 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { ExecutorOptions, NormalizedExecutorOptions } from '../../../../utils/schema';
3
+ export declare function normalizeTasksOptions(inputs: Record<string, ExecutorOptions>, context: ExecutorContext): Record<string, NormalizedExecutorOptions>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeTasksOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const normalize_options_1 = require("../normalize-options");
6
+ function normalizeTasksOptions(inputs, context) {
7
+ return Object.entries(inputs).reduce((tasksOptions, [taskName, options]) => {
8
+ const { project } = (0, devkit_1.parseTargetString)(taskName, context);
9
+ const { sourceRoot, root } = context.projectsConfigurations.projects[project];
10
+ tasksOptions[taskName] = (0, normalize_options_1.normalizeOptions)(options, context.root, sourceRoot, root);
11
+ return tasksOptions;
12
+ }, {});
13
+ }
14
+ exports.normalizeTasksOptions = normalizeTasksOptions;