@trackunit/iris-app 2.3.3-alpha-06136b80b13.0 → 2.3.4
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/CHANGELOG.md +23 -0
- package/README.md +18 -0
- package/package.json +5 -3
- package/src/executors/submit/executor.js +115 -22
- package/src/executors/submit/executor.js.map +1 -1
- package/src/generators/create/generator.js +8 -11
- package/src/generators/create/generator.js.map +1 -1
- package/src/generators/extend/files/SERVERSIDE_API_EXTENSION_GRAPHQL/src/graphql/asset-by-id.graphql__template__ +6 -0
- package/src/generators/extend/files/SERVERSIDE_API_EXTENSION_GRAPHQL/src/index.ts__template__ +31 -0
- package/src/generators/extend/generator.d.ts +11 -0
- package/src/generators/extend/generator.js +53 -1
- package/src/generators/extend/generator.js.map +1 -1
- package/src/generators/extend/schema.d.ts +1 -0
- package/src/generators/extend/schema.json +5 -0
- package/src/generators/utils/get-package-manifest.d.ts +5 -0
- package/src/generators/utils/get-package-manifest.js +11 -0
- package/src/generators/utils/get-package-manifest.js.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
## 2.3.4 (2026-08-04)
|
|
2
|
+
|
|
3
|
+
This was a version bump only for iris-app to align it with other projects, there were no code changes.
|
|
4
|
+
|
|
5
|
+
## 2.3.3 (2026-08-04)
|
|
6
|
+
|
|
7
|
+
### 🧱 Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated iris-app-build-utilities to 2.2.3
|
|
10
|
+
- Updated iris-app-api to 2.2.3
|
|
11
|
+
- Updated react-vite-test-setup to 0.0.89
|
|
12
|
+
- Updated react-graphql-tools to 1.14.90
|
|
13
|
+
- Updated shared-utils to 1.15.91
|
|
14
|
+
|
|
15
|
+
## 2.3.2 (2026-08-03)
|
|
16
|
+
|
|
17
|
+
### 🧱 Updated Dependencies
|
|
18
|
+
|
|
19
|
+
- Updated iris-app-build-utilities to 2.2.2
|
|
20
|
+
- Updated iris-app-api to 2.2.2
|
|
21
|
+
- Updated react-vite-test-setup to 0.0.88
|
|
22
|
+
- Updated shared-utils to 1.15.90
|
|
23
|
+
|
|
1
24
|
## 2.3.1 (2026-08-03)
|
|
2
25
|
|
|
3
26
|
### 🧱 Updated Dependencies
|
package/README.md
CHANGED
|
@@ -11,6 +11,24 @@ For more info and a full guide on Iris App SDK Development, please visit our [De
|
|
|
11
11
|
|
|
12
12
|
Run through the easy getting started guide here: [Getting Started](https://developers.trackunit.com/docs/getting-started)
|
|
13
13
|
|
|
14
|
+
## Serverside GraphQL scaffolding
|
|
15
|
+
|
|
16
|
+
Typed access to the Trackunit public GraphQL API is optional for serverside API extensions:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npx nx generate @trackunit/iris-app:extend \
|
|
20
|
+
--type=SERVERSIDE_API_EXTENSION \
|
|
21
|
+
--graphql
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The option is off by default. It reuses the standard `graphql-hooks` target, configures React-free code generation against the public schema, and adds a named typed asset query example. Regenerate documents after editing `.graphql` files:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx nx run <project>:graphql-hooks
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Local requests must include a user bearer token. Set `SDK_ENVIRONMENT=DEV` or `STAGE` in the extension's `.env` to target a non-production public API; unset defaults to production.
|
|
31
|
+
|
|
14
32
|
## Testing Local Changes
|
|
15
33
|
|
|
16
34
|
To test changes to the SDK generators locally, you can verify them in a full, temporary workspace environment.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/iris-app",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"generators": "./generators.json",
|
|
@@ -23,8 +23,10 @@
|
|
|
23
23
|
"@nx/react": "23.1.0",
|
|
24
24
|
"@npmcli/arborist": "^9.1.9",
|
|
25
25
|
"win-ca": "^3.5.1",
|
|
26
|
-
"@trackunit/
|
|
27
|
-
"@trackunit/
|
|
26
|
+
"@trackunit/iris-app-build-utilities": "2.2.3",
|
|
27
|
+
"@trackunit/react-graphql-tools": "1.14.90",
|
|
28
|
+
"@trackunit/shared-utils": "1.15.91",
|
|
29
|
+
"@trackunit/iris-app-api": "2.2.3",
|
|
28
30
|
"tslib": "^2.6.2",
|
|
29
31
|
"@clack/prompts": "^1.0.0",
|
|
30
32
|
"@npm/types": "^1.0.2",
|
|
@@ -15,12 +15,81 @@ const irisAppServerSettings_1 = require("../utils/irisAppServerSettings");
|
|
|
15
15
|
class NpmConflictError extends Error {
|
|
16
16
|
}
|
|
17
17
|
class NpmGeneralError extends Error {
|
|
18
|
+
constructor(message, statusCode, code, type) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.statusCode = statusCode;
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.type = type;
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
class ApproveError extends Error {
|
|
26
|
+
constructor(message, statusCode, code) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.statusCode = statusCode;
|
|
29
|
+
this.code = code;
|
|
30
|
+
}
|
|
20
31
|
}
|
|
21
32
|
function sleep(time) {
|
|
22
33
|
return new Promise(resolve => setTimeout(resolve, time));
|
|
23
34
|
}
|
|
35
|
+
// Errno-style codes that indicate the request never reached the registry at all
|
|
36
|
+
// (DNS/connection/timeout failures at the transport layer), as opposed to local
|
|
37
|
+
// validation errors (e.g. libnpmpublish's EPRIVATE/EBADSEMVER/EUSAGE) which carry
|
|
38
|
+
// a code but are permanent and can never succeed on retry. Kept aligned with
|
|
39
|
+
// make-fetch-happen's own RETRY_ERRORS list (used by the submit path) plus the
|
|
40
|
+
// undici error codes doApproveApp's native fetch can raise.
|
|
41
|
+
//
|
|
42
|
+
// ENOTFOUND (DNS failure) is deliberately included even though make-fetch-happen
|
|
43
|
+
// itself excludes it as "bad hostname, or offline" - a DNS blip during a VPN/
|
|
44
|
+
// network transition is common enough in practice that failing fast here would
|
|
45
|
+
// trade one wasted-wait problem for developers hitting spurious permanent
|
|
46
|
+
// failures on flaky networks. This is a judgment call, not a clear-cut default.
|
|
47
|
+
const RETRYABLE_TRANSPORT_CODES = new Set([
|
|
48
|
+
"ENOTFOUND",
|
|
49
|
+
"ECONNRESET",
|
|
50
|
+
"ECONNREFUSED",
|
|
51
|
+
"ETIMEDOUT",
|
|
52
|
+
"EAI_AGAIN",
|
|
53
|
+
"ERR_SOCKET_TIMEOUT",
|
|
54
|
+
"EADDRINUSE",
|
|
55
|
+
// from @npmcli/agent, surfaced through make-fetch-happen
|
|
56
|
+
"ECONNECTIONTIMEOUT",
|
|
57
|
+
"EIDLETIMEOUT",
|
|
58
|
+
"ERESPONSETIMEOUT",
|
|
59
|
+
"ETRANSFERTIMEOUT",
|
|
60
|
+
// doApproveApp uses Node's native fetch (undici), which raises its own
|
|
61
|
+
// codes distinct from the classic Node errno codes above.
|
|
62
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
63
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
64
|
+
"UND_ERR_BODY_TIMEOUT",
|
|
65
|
+
"UND_ERR_SOCKET", // e.g. "other side closed" on a reused keep-alive connection
|
|
66
|
+
]);
|
|
67
|
+
/**
|
|
68
|
+
* Decide whether a failed submit/approve attempt is worth retrying.
|
|
69
|
+
*
|
|
70
|
+
* This is an allowlist, not a denylist: only failures with a real chance of
|
|
71
|
+
* succeeding on a later attempt are retried - 5xx responses, 408/429 (timeout/
|
|
72
|
+
* rate-limited), a transport-level failure that never reached the registry at
|
|
73
|
+
* all (identified by a known transient errno code), or a minipass-fetch request
|
|
74
|
+
* timeout (which surfaces with the generic code FETCH_ERROR, distinguishable
|
|
75
|
+
* only via its `type: "request-timeout"`). Everything else - permanent 4xx
|
|
76
|
+
* errors, local validation errors with an unrelated code (e.g. EBADSEMVER), or
|
|
77
|
+
* any other unrecognized error shape - is treated as non-retryable by default.
|
|
78
|
+
*
|
|
79
|
+
* @param {number} [statusCode] The HTTP status code of the failed attempt, if any.
|
|
80
|
+
* @param {string} [code] The error's errno-style code, if any (no statusCode implies no HTTP response was received).
|
|
81
|
+
* @param {string} [type] The error's `type` field, if any. Only consulted when `code === "FETCH_ERROR"`, since that's the one code minipass-fetch's FetchError uses generically for several failure kinds - `type` is what distinguishes a timeout from the others.
|
|
82
|
+
* @returns {boolean} Whether the attempt should be retried.
|
|
83
|
+
*/
|
|
84
|
+
function isRetryableError(statusCode, code, type) {
|
|
85
|
+
if (statusCode !== undefined) {
|
|
86
|
+
return statusCode >= 500 || statusCode === 408 || statusCode === 429;
|
|
87
|
+
}
|
|
88
|
+
if (code === undefined) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return RETRYABLE_TRANSPORT_CODES.has(code) || (code === "FETCH_ERROR" && type === "request-timeout");
|
|
92
|
+
}
|
|
24
93
|
/**
|
|
25
94
|
* Submit the package to the npm registry.
|
|
26
95
|
*
|
|
@@ -72,16 +141,24 @@ async function doUploadAppWithRetry(accessToken, manifest, tarData, settings, re
|
|
|
72
141
|
console.error("❌ Unable to ship app package. Cannot submit over existing version.");
|
|
73
142
|
return { success: false };
|
|
74
143
|
}
|
|
144
|
+
if (!(e instanceof NpmGeneralError)) {
|
|
145
|
+
// An error shape we don't recognize (e.g. a bug elsewhere in this function) -
|
|
146
|
+
// log the full error/stack rather than a bare message so it stays debuggable.
|
|
147
|
+
console.error("❌ Unable to ship app package. Got error from Iris App SDK repository.", e);
|
|
148
|
+
return { success: false };
|
|
149
|
+
}
|
|
150
|
+
if (!isRetryableError(e.statusCode, e.code, e.type)) {
|
|
151
|
+
console.error("❌ Unable to ship app package.", e.message);
|
|
152
|
+
return { success: false };
|
|
153
|
+
}
|
|
154
|
+
if (retryCount > 1) {
|
|
155
|
+
console.error("⚠️ Unable to ship app package. Got error from Iris App SDK repository. Retrying submit...", e.message);
|
|
156
|
+
await sleep(30000);
|
|
157
|
+
return await doUploadAppWithRetry(accessToken, manifest, tarData, settings, retryCount - 1);
|
|
158
|
+
}
|
|
75
159
|
else {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await sleep(30000);
|
|
79
|
-
return await doUploadAppWithRetry(accessToken, manifest, tarData, settings, retryCount - 1);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
console.error("❌ Unable to ship app package. Got error from Iris App SDK repository.", e);
|
|
83
|
-
return { success: false };
|
|
84
|
-
}
|
|
160
|
+
console.error("❌ Unable to ship app package. Got error from Iris App SDK repository.", e.message);
|
|
161
|
+
return { success: false };
|
|
85
162
|
}
|
|
86
163
|
}
|
|
87
164
|
}
|
|
@@ -102,6 +179,9 @@ async function doUploadApp(accessToken, manifest, tarData, settings) {
|
|
|
102
179
|
else {
|
|
103
180
|
return {
|
|
104
181
|
ok: false,
|
|
182
|
+
statusCode: err.statusCode,
|
|
183
|
+
code: err.code,
|
|
184
|
+
type: err.type,
|
|
105
185
|
headers: new Headers(err.headers),
|
|
106
186
|
statusText: `Error`,
|
|
107
187
|
text: () => Promise.resolve(`${err.name} ${err.message}`),
|
|
@@ -130,7 +210,7 @@ async function doUploadApp(accessToken, manifest, tarData, settings) {
|
|
|
130
210
|
" " +
|
|
131
211
|
(await submitResult.text()) +
|
|
132
212
|
". Trace ID: " +
|
|
133
|
-
submitResult.headers.get("trace-id"));
|
|
213
|
+
submitResult.headers.get("trace-id"), "statusCode" in submitResult ? submitResult.statusCode : undefined, "code" in submitResult ? submitResult.code : undefined, "type" in submitResult ? submitResult.type : undefined);
|
|
134
214
|
}
|
|
135
215
|
}
|
|
136
216
|
async function promptUserForInput(query) {
|
|
@@ -150,19 +230,21 @@ async function doApproveAppWithRetry(token, manifest, settings, retryCount) {
|
|
|
150
230
|
return await doApproveApp(token, manifest, settings);
|
|
151
231
|
}
|
|
152
232
|
catch (e) {
|
|
153
|
-
if (e instanceof ApproveError) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
233
|
+
if (!(e instanceof ApproveError)) {
|
|
234
|
+
console.error("❌ Unable to approve app package. Got error from Iris App SDK repository.", e);
|
|
235
|
+
return { success: false };
|
|
236
|
+
}
|
|
237
|
+
if (!isRetryableError(e.statusCode, e.code)) {
|
|
238
|
+
console.error("❌ Unable to approve app package.", e.message);
|
|
239
|
+
return { success: false };
|
|
240
|
+
}
|
|
241
|
+
if (retryCount > 1) {
|
|
242
|
+
console.error("⚠️ Unable to approve app package. Got approve error from Iris App SDK repository. Retrying approve...", e.message);
|
|
243
|
+
await sleep(30000);
|
|
244
|
+
return await doApproveAppWithRetry(token, manifest, settings, retryCount - 1);
|
|
163
245
|
}
|
|
164
246
|
else {
|
|
165
|
-
console.error("❌ Unable to approve app package. Got error from Iris App SDK repository.", e);
|
|
247
|
+
console.error("❌ Unable to approve app package. Got approve error from Iris App SDK repository.", e.message);
|
|
166
248
|
return { success: false };
|
|
167
249
|
}
|
|
168
250
|
}
|
|
@@ -170,18 +252,29 @@ async function doApproveAppWithRetry(token, manifest, settings, retryCount) {
|
|
|
170
252
|
async function doApproveApp(token, manifest, settings) {
|
|
171
253
|
if (process.env.TU_APPROVE === "true") {
|
|
172
254
|
console.log(`🖋️ Approving the app...`);
|
|
255
|
+
// A rejection here (e.g. DNS/connection/timeout failure) never produced an HTTP
|
|
256
|
+
// response, so it's re-thrown as an ApproveError with no statusCode - carrying
|
|
257
|
+
// the underlying cause's errno code (if any) so isRetryableError can recognize
|
|
258
|
+
// genuine transport failures, and the cause's message so the log doesn't just
|
|
259
|
+
// say "fetch failed" with no indication of what actually broke.
|
|
173
260
|
const approveResult = await fetch(new URL(`${manifest.name}@${manifest.version}`, settings.approvalUrl), {
|
|
174
261
|
method: "PUT",
|
|
175
262
|
headers: {
|
|
176
263
|
Authorization: `Bearer ${token}`,
|
|
177
264
|
},
|
|
265
|
+
}).catch((err) => {
|
|
266
|
+
const cause = err.cause instanceof Error ? err.cause : undefined;
|
|
267
|
+
const causeCode = cause && "code" in cause ? cause.code : undefined;
|
|
268
|
+
const code = typeof causeCode === "string" ? causeCode : undefined;
|
|
269
|
+
const reason = cause ? `${err.message}: ${cause.message}` : err.message;
|
|
270
|
+
throw new ApproveError(reason, undefined, code);
|
|
178
271
|
});
|
|
179
272
|
if (approveResult.ok) {
|
|
180
273
|
console.log(`✅ Approved version ${manifest.version} of ${manifest.name}.`);
|
|
181
274
|
return { success: true };
|
|
182
275
|
}
|
|
183
276
|
else {
|
|
184
|
-
throw new ApproveError(`${approveResult.statusText}, ${await approveResult.text()}, Trace ID: ${approveResult.headers.get("trace-id")}
|
|
277
|
+
throw new ApproveError(`${approveResult.statusText}, ${await approveResult.text()}, Trace ID: ${approveResult.headers.get("trace-id")}`, approveResult.status);
|
|
185
278
|
}
|
|
186
279
|
}
|
|
187
280
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../libs/iris-app-sdk/iris-app/src/executors/submit/executor.ts"],"names":[],"mappings":";;AA+BA,8BAqCC;;AAlED,+CAA4C;AAC5C,kFAA0E;AAC1E,8DAAwC;AACxC,uDAAiC;AACjC,gEAAgC;AAChC,mCAAgC;AAChC,4DAAyD;AACzD,0EAAuE;AAGvE,+FAA+F;AAC/F,IAAA,eAAM,EAAC,GAAG,CAAC,CAAC;AAIZ,MAAM,gBAAiB,SAAQ,KAAK;CAAG;AACvC,MAAM,eAAgB,SAAQ,KAAK;CAAG;AACtC,MAAM,YAAa,SAAQ,KAAK;CAAG;AAEnC,SAAS,KAAK,CAAC,IAAY;IACzB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACY,KAAK,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0B,CAAC,CAAC;QACxC,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE;YACvG,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;aACjC;SACF,CAAC,CAAC;QAEH,IAAI,aAAa,CAAC,EAAE,EAAE,CAAC;YACrB,OAAO,CAAC,GAAG,CAAC,sBAAsB,QAAQ,CAAC,OAAO,OAAO,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;YAC3E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,YAAY,CACpB,GAAG,aAAa,CAAC,UAAU,KAAK,MAAM,aAAa,CAAC,IAAI,EAAE,eAAe,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CACjH,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable no-console */\nimport { PackageJson } from \"@npm/types\";\nimport { Arborist } from \"@npmcli/arborist\";\nimport { checkPackageVersion } from \"@trackunit/iris-app-build-utilities\";\nimport * as libpub from \"libnpmpublish\";\nimport * as pacote from \"pacote\";\nimport readline from \"readline\";\nimport { inject } from \"win-ca\";\nimport { getAccessToken } from \"../utils/authentication\";\nimport { getSettings, Settings } from \"../utils/irisAppServerSettings\";\nimport { SubmitExecutorSchema } from \"./schema\";\n\n// Inject Windows trusted certificates to support Zscalar and other traffic inspection systems.\ninject(\"+\");\n\ntype SubmitError = Error & { statusCode?: number; code?: string; headers?: { [key: string]: string } };\n\nclass NpmConflictError extends Error {}\nclass NpmGeneralError extends Error {}\nclass ApproveError extends Error {}\n\nfunction sleep(time: number) {\n return new Promise(resolve => setTimeout(resolve, time));\n}\n\n/**\n * Submit the package to the npm registry.\n *\n * @param {SubmitExecutorSchema} options The options provided to the executor.\n * @returns {Promise<{ success: boolean }>} The result of the submit.\n */\nexport default async function runExecutor(options: SubmitExecutorSchema) {\n await checkPackageVersion(true);\n const settings = getSettings();\n const linkToTerms = \"https://trackunit.com/terms-conditions-marketplace/\";\n\n try {\n if (options.devTermsAndConditions?.toLowerCase() !== \"accept\" && !settings.devTermsAccept) {\n // Ask user if they accept dev terms and conditions.\n const userInput = await promptUserForInput(\n `Do you accept the developer terms and conditions? \\n(${linkToTerms}) \\n\\n 📝 Type 'accept' to proceed: `\n );\n if (userInput.toLowerCase() !== \"accept\") {\n throw new Error(`You must accept the developer terms and conditions (${linkToTerms}) to continue.`);\n }\n }\n const tokenData = await getAccessToken(settings.env);\n\n if (\"access_token\" in tokenData) {\n console.log(\"🥳 Successfully authenticated.\");\n\n const manifest = (await pacote.manifest(options.inputPath)) as PackageJson;\n const tarData = await pacote.tarball(options.inputPath, { Arborist });\n\n return await doUploadAppWithRetry(tokenData.access_token, manifest, tarData, settings, 10);\n } else if (\"error\" in tokenData) {\n if (tokenData.error === \"expired_token\") {\n throw new Error(\"⌛️ Authentication attempt expired\");\n } else {\n throw new Error(`Error occurred: ${tokenData.error} ${tokenData.error_description}`);\n }\n } else {\n throw new Error(\"Unknown error occurred\");\n }\n } catch (e) {\n console.error(\"❌ \", e);\n return { success: false };\n }\n}\n\nasync function doUploadAppWithRetry(\n accessToken: string,\n manifest: PackageJson,\n tarData: Buffer & pacote.FetchResult,\n settings: Settings,\n retryCount: number\n): Promise<{ success: boolean }> {\n try {\n return await doUploadApp(accessToken, manifest, tarData, settings);\n } catch (e) {\n if (e instanceof NpmConflictError) {\n console.error(\"❌ Unable to ship app package. Cannot submit over existing version.\");\n return { success: false };\n } else {\n if (retryCount > 1) {\n console.error(\"⚠️ Unable to ship app package. Got error from Iris App SDK repository. Retrying submit...\", e);\n await sleep(30000);\n return await doUploadAppWithRetry(accessToken, manifest, tarData, settings, retryCount - 1);\n } else {\n console.error(\"❌ Unable to ship app package. Got error from Iris App SDK repository.\", e);\n return { success: false };\n }\n }\n }\n}\n\nasync function doUploadApp(\n accessToken: string,\n manifest: PackageJson,\n tarData: Buffer & pacote.FetchResult,\n settings: Settings\n): Promise<{ success: boolean }> {\n const npmFetchOptions: { registry?: string } & Record<string, string | boolean> = {};\n npmFetchOptions.registry = settings.repoUrl.toString();\n const repoHostAndPort = settings.repoUrl.hostname + (settings.repoUrl.port ? \":\" + settings.repoUrl.port : \"\");\n npmFetchOptions[`//${repoHostAndPort}${settings.repoUrl.pathname}:_authToken`] = accessToken;\n npmFetchOptions[`//${repoHostAndPort}${settings.repoUrl.pathname}/repo/:always-auth`] = true;\n\n console.log(\"🚢 Shipping the app package...\");\n const submitResult = await libpub.publish(manifest, tarData, npmFetchOptions).catch((err: SubmitError) => {\n if (err.statusCode === 409 || err.code === \"E409\" || err.code === \"EPUBLISHCONFLICT\") {\n return {\n ok: false,\n submitConflict: true,\n };\n } else {\n return {\n ok: false,\n headers: new Headers(err.headers),\n statusText: `Error`,\n text: () => Promise.resolve(`${err.name} ${err.message}`),\n };\n }\n });\n\n const warningsText = submitResult.headers?.get(\"TU-IRIS-APP-WARNINGS\");\n if (warningsText) {\n console.log(\"⚠️ \" + decodeURI(warningsText));\n }\n\n if (submitResult.ok) {\n console.log(`🚀 Uploaded the app package version ${manifest.version}`);\n\n return await doApproveAppWithRetry(accessToken, manifest, settings, 3);\n } else if (\"submitConflict\" in submitResult) {\n if (process.env.SKIP_EXISTING === \"true\") {\n console.log(`⏩ Skipped submitting ${manifest.version} because the version is already submitted`);\n return await doApproveAppWithRetry(accessToken, manifest, settings, 3);\n } else {\n throw new NpmConflictError();\n }\n } else {\n throw new NpmGeneralError(\n submitResult.statusText +\n \" \" +\n (await submitResult.text()) +\n \". Trace ID: \" +\n submitResult.headers.get(\"trace-id\")\n );\n }\n}\n\nasync function promptUserForInput(query: string): Promise<string> {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n return new Promise(resolve => {\n rl.question(query, (input: string) => {\n rl.close();\n resolve(input);\n });\n });\n}\n\nasync function doApproveAppWithRetry(\n token: string,\n manifest: PackageJson,\n settings: Settings,\n retryCount: number\n): Promise<{ success: boolean }> {\n try {\n return await doApproveApp(token, manifest, settings);\n } catch (e) {\n if (e instanceof ApproveError) {\n if (retryCount > 1) {\n console.error(\n \"⚠️ Unable to approve app package. Got approve error from Iris App SDK repository. Retrying approve...\",\n e\n );\n await sleep(30000);\n return await doApproveAppWithRetry(token, manifest, settings, retryCount - 1);\n } else {\n console.error(\"❌ Unable to approve app package. Got approve error from Iris App SDK repository.\", e);\n return { success: false };\n }\n } else {\n console.error(\"❌ Unable to approve app package. Got error from Iris App SDK repository.\", e);\n return { success: false };\n }\n }\n}\n\nasync function doApproveApp(token: string, manifest: PackageJson, settings: Settings) {\n if (process.env.TU_APPROVE === \"true\") {\n console.log(`🖋️ Approving the app...`);\n const approveResult = await fetch(new URL(`${manifest.name}@${manifest.version}`, settings.approvalUrl), {\n method: \"PUT\",\n headers: {\n Authorization: `Bearer ${token}`,\n },\n });\n\n if (approveResult.ok) {\n console.log(`✅ Approved version ${manifest.version} of ${manifest.name}.`);\n return { success: true };\n } else {\n throw new ApproveError(\n `${approveResult.statusText}, ${await approveResult.text()}, Trace ID: ${approveResult.headers.get(\"trace-id\")}`\n );\n }\n } else {\n return { success: true };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../libs/iris-app-sdk/iris-app/src/executors/submit/executor.ts"],"names":[],"mappings":";;AAmHA,8BAqCC;;AAtJD,+CAA4C;AAC5C,kFAA0E;AAC1E,8DAAwC;AACxC,uDAAiC;AACjC,gEAAgC;AAChC,mCAAgC;AAChC,4DAAyD;AACzD,0EAAuE;AAGvE,+FAA+F;AAC/F,IAAA,eAAM,EAAC,GAAG,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O,OAAO,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;YAC3E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,YAAY,CACpB,GAAG,aAAa,CAAC,UAAU,KAAK,MAAM,aAAa,CAAC,IAAI,EAAE,eAAe,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAChH,aAAa,CAAC,MAAM,CACrB,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable no-console */\nimport { PackageJson } from \"@npm/types\";\nimport { Arborist } from \"@npmcli/arborist\";\nimport { checkPackageVersion } from \"@trackunit/iris-app-build-utilities\";\nimport * as libpub from \"libnpmpublish\";\nimport * as pacote from \"pacote\";\nimport readline from \"readline\";\nimport { inject } from \"win-ca\";\nimport { getAccessToken } from \"../utils/authentication\";\nimport { getSettings, Settings } from \"../utils/irisAppServerSettings\";\nimport { SubmitExecutorSchema } from \"./schema\";\n\n// Inject Windows trusted certificates to support Zscalar and other traffic inspection systems.\ninject(\"+\");\n\ntype SubmitError = Error & {\n statusCode?: number;\n code?: string;\n type?: string;\n headers?: { [key: string]: string };\n};\n\nclass NpmConflictError extends Error {}\n\nclass NpmGeneralError extends Error {\n public constructor(\n message: string,\n public readonly statusCode?: number,\n public readonly code?: string,\n public readonly type?: string\n ) {\n super(message);\n }\n}\n\nclass ApproveError extends Error {\n public constructor(\n message: string,\n public readonly statusCode?: number,\n public readonly code?: string\n ) {\n super(message);\n }\n}\n\nfunction sleep(time: number) {\n return new Promise(resolve => setTimeout(resolve, time));\n}\n\n// Errno-style codes that indicate the request never reached the registry at all\n// (DNS/connection/timeout failures at the transport layer), as opposed to local\n// validation errors (e.g. libnpmpublish's EPRIVATE/EBADSEMVER/EUSAGE) which carry\n// a code but are permanent and can never succeed on retry. Kept aligned with\n// make-fetch-happen's own RETRY_ERRORS list (used by the submit path) plus the\n// undici error codes doApproveApp's native fetch can raise.\n//\n// ENOTFOUND (DNS failure) is deliberately included even though make-fetch-happen\n// itself excludes it as \"bad hostname, or offline\" - a DNS blip during a VPN/\n// network transition is common enough in practice that failing fast here would\n// trade one wasted-wait problem for developers hitting spurious permanent\n// failures on flaky networks. This is a judgment call, not a clear-cut default.\nconst RETRYABLE_TRANSPORT_CODES = new Set([\n \"ENOTFOUND\",\n \"ECONNRESET\",\n \"ECONNREFUSED\",\n \"ETIMEDOUT\",\n \"EAI_AGAIN\",\n \"ERR_SOCKET_TIMEOUT\",\n \"EADDRINUSE\",\n // from @npmcli/agent, surfaced through make-fetch-happen\n \"ECONNECTIONTIMEOUT\",\n \"EIDLETIMEOUT\",\n \"ERESPONSETIMEOUT\",\n \"ETRANSFERTIMEOUT\",\n // doApproveApp uses Node's native fetch (undici), which raises its own\n // codes distinct from the classic Node errno codes above.\n \"UND_ERR_CONNECT_TIMEOUT\",\n \"UND_ERR_HEADERS_TIMEOUT\",\n \"UND_ERR_BODY_TIMEOUT\",\n \"UND_ERR_SOCKET\", // e.g. \"other side closed\" on a reused keep-alive connection\n]);\n\n/**\n * Decide whether a failed submit/approve attempt is worth retrying.\n *\n * This is an allowlist, not a denylist: only failures with a real chance of\n * succeeding on a later attempt are retried - 5xx responses, 408/429 (timeout/\n * rate-limited), a transport-level failure that never reached the registry at\n * all (identified by a known transient errno code), or a minipass-fetch request\n * timeout (which surfaces with the generic code FETCH_ERROR, distinguishable\n * only via its `type: \"request-timeout\"`). Everything else - permanent 4xx\n * errors, local validation errors with an unrelated code (e.g. EBADSEMVER), or\n * any other unrecognized error shape - is treated as non-retryable by default.\n *\n * @param {number} [statusCode] The HTTP status code of the failed attempt, if any.\n * @param {string} [code] The error's errno-style code, if any (no statusCode implies no HTTP response was received).\n * @param {string} [type] The error's `type` field, if any. Only consulted when `code === \"FETCH_ERROR\"`, since that's the one code minipass-fetch's FetchError uses generically for several failure kinds - `type` is what distinguishes a timeout from the others.\n * @returns {boolean} Whether the attempt should be retried.\n */\nfunction isRetryableError(statusCode?: number, code?: string, type?: string): boolean {\n if (statusCode !== undefined) {\n return statusCode >= 500 || statusCode === 408 || statusCode === 429;\n }\n if (code === undefined) {\n return false;\n }\n return RETRYABLE_TRANSPORT_CODES.has(code) || (code === \"FETCH_ERROR\" && type === \"request-timeout\");\n}\n\n/**\n * Submit the package to the npm registry.\n *\n * @param {SubmitExecutorSchema} options The options provided to the executor.\n * @returns {Promise<{ success: boolean }>} The result of the submit.\n */\nexport default async function runExecutor(options: SubmitExecutorSchema) {\n await checkPackageVersion(true);\n const settings = getSettings();\n const linkToTerms = \"https://trackunit.com/terms-conditions-marketplace/\";\n\n try {\n if (options.devTermsAndConditions?.toLowerCase() !== \"accept\" && !settings.devTermsAccept) {\n // Ask user if they accept dev terms and conditions.\n const userInput = await promptUserForInput(\n `Do you accept the developer terms and conditions? \\n(${linkToTerms}) \\n\\n 📝 Type 'accept' to proceed: `\n );\n if (userInput.toLowerCase() !== \"accept\") {\n throw new Error(`You must accept the developer terms and conditions (${linkToTerms}) to continue.`);\n }\n }\n const tokenData = await getAccessToken(settings.env);\n\n if (\"access_token\" in tokenData) {\n console.log(\"🥳 Successfully authenticated.\");\n\n const manifest = (await pacote.manifest(options.inputPath)) as PackageJson;\n const tarData = await pacote.tarball(options.inputPath, { Arborist });\n\n return await doUploadAppWithRetry(tokenData.access_token, manifest, tarData, settings, 10);\n } else if (\"error\" in tokenData) {\n if (tokenData.error === \"expired_token\") {\n throw new Error(\"⌛️ Authentication attempt expired\");\n } else {\n throw new Error(`Error occurred: ${tokenData.error} ${tokenData.error_description}`);\n }\n } else {\n throw new Error(\"Unknown error occurred\");\n }\n } catch (e) {\n console.error(\"❌ \", e);\n return { success: false };\n }\n}\n\nasync function doUploadAppWithRetry(\n accessToken: string,\n manifest: PackageJson,\n tarData: Buffer & pacote.FetchResult,\n settings: Settings,\n retryCount: number\n): Promise<{ success: boolean }> {\n try {\n return await doUploadApp(accessToken, manifest, tarData, settings);\n } catch (e) {\n if (e instanceof NpmConflictError) {\n console.error(\"❌ Unable to ship app package. Cannot submit over existing version.\");\n return { success: false };\n }\n\n if (!(e instanceof NpmGeneralError)) {\n // An error shape we don't recognize (e.g. a bug elsewhere in this function) -\n // log the full error/stack rather than a bare message so it stays debuggable.\n console.error(\"❌ Unable to ship app package. Got error from Iris App SDK repository.\", e);\n return { success: false };\n }\n\n if (!isRetryableError(e.statusCode, e.code, e.type)) {\n console.error(\"❌ Unable to ship app package.\", e.message);\n return { success: false };\n }\n\n if (retryCount > 1) {\n console.error(\n \"⚠️ Unable to ship app package. Got error from Iris App SDK repository. Retrying submit...\",\n e.message\n );\n await sleep(30000);\n return await doUploadAppWithRetry(accessToken, manifest, tarData, settings, retryCount - 1);\n } else {\n console.error(\"❌ Unable to ship app package. Got error from Iris App SDK repository.\", e.message);\n return { success: false };\n }\n }\n}\n\nasync function doUploadApp(\n accessToken: string,\n manifest: PackageJson,\n tarData: Buffer & pacote.FetchResult,\n settings: Settings\n): Promise<{ success: boolean }> {\n const npmFetchOptions: { registry?: string } & Record<string, string | boolean> = {};\n npmFetchOptions.registry = settings.repoUrl.toString();\n const repoHostAndPort = settings.repoUrl.hostname + (settings.repoUrl.port ? \":\" + settings.repoUrl.port : \"\");\n npmFetchOptions[`//${repoHostAndPort}${settings.repoUrl.pathname}:_authToken`] = accessToken;\n npmFetchOptions[`//${repoHostAndPort}${settings.repoUrl.pathname}/repo/:always-auth`] = true;\n\n console.log(\"🚢 Shipping the app package...\");\n const submitResult = await libpub.publish(manifest, tarData, npmFetchOptions).catch((err: SubmitError) => {\n if (err.statusCode === 409 || err.code === \"E409\" || err.code === \"EPUBLISHCONFLICT\") {\n return {\n ok: false,\n submitConflict: true,\n };\n } else {\n return {\n ok: false,\n statusCode: err.statusCode,\n code: err.code,\n type: err.type,\n headers: new Headers(err.headers),\n statusText: `Error`,\n text: () => Promise.resolve(`${err.name} ${err.message}`),\n };\n }\n });\n\n const warningsText = submitResult.headers?.get(\"TU-IRIS-APP-WARNINGS\");\n if (warningsText) {\n console.log(\"⚠️ \" + decodeURI(warningsText));\n }\n\n if (submitResult.ok) {\n console.log(`🚀 Uploaded the app package version ${manifest.version}`);\n\n return await doApproveAppWithRetry(accessToken, manifest, settings, 3);\n } else if (\"submitConflict\" in submitResult) {\n if (process.env.SKIP_EXISTING === \"true\") {\n console.log(`⏩ Skipped submitting ${manifest.version} because the version is already submitted`);\n return await doApproveAppWithRetry(accessToken, manifest, settings, 3);\n } else {\n throw new NpmConflictError();\n }\n } else {\n throw new NpmGeneralError(\n submitResult.statusText +\n \" \" +\n (await submitResult.text()) +\n \". Trace ID: \" +\n submitResult.headers.get(\"trace-id\"),\n \"statusCode\" in submitResult ? submitResult.statusCode : undefined,\n \"code\" in submitResult ? submitResult.code : undefined,\n \"type\" in submitResult ? submitResult.type : undefined\n );\n }\n}\n\nasync function promptUserForInput(query: string): Promise<string> {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n return new Promise(resolve => {\n rl.question(query, (input: string) => {\n rl.close();\n resolve(input);\n });\n });\n}\n\nasync function doApproveAppWithRetry(\n token: string,\n manifest: PackageJson,\n settings: Settings,\n retryCount: number\n): Promise<{ success: boolean }> {\n try {\n return await doApproveApp(token, manifest, settings);\n } catch (e) {\n if (!(e instanceof ApproveError)) {\n console.error(\"❌ Unable to approve app package. Got error from Iris App SDK repository.\", e);\n return { success: false };\n }\n\n if (!isRetryableError(e.statusCode, e.code)) {\n console.error(\"❌ Unable to approve app package.\", e.message);\n return { success: false };\n }\n\n if (retryCount > 1) {\n console.error(\n \"⚠️ Unable to approve app package. Got approve error from Iris App SDK repository. Retrying approve...\",\n e.message\n );\n await sleep(30000);\n return await doApproveAppWithRetry(token, manifest, settings, retryCount - 1);\n } else {\n console.error(\"❌ Unable to approve app package. Got approve error from Iris App SDK repository.\", e.message);\n return { success: false };\n }\n }\n}\n\nasync function doApproveApp(token: string, manifest: PackageJson, settings: Settings) {\n if (process.env.TU_APPROVE === \"true\") {\n console.log(`🖋️ Approving the app...`);\n // A rejection here (e.g. DNS/connection/timeout failure) never produced an HTTP\n // response, so it's re-thrown as an ApproveError with no statusCode - carrying\n // the underlying cause's errno code (if any) so isRetryableError can recognize\n // genuine transport failures, and the cause's message so the log doesn't just\n // say \"fetch failed\" with no indication of what actually broke.\n const approveResult = await fetch(new URL(`${manifest.name}@${manifest.version}`, settings.approvalUrl), {\n method: \"PUT\",\n headers: {\n Authorization: `Bearer ${token}`,\n },\n }).catch((err: Error) => {\n const cause = err.cause instanceof Error ? err.cause : undefined;\n const causeCode = cause && \"code\" in cause ? (cause as NodeJS.ErrnoException).code : undefined;\n const code = typeof causeCode === \"string\" ? causeCode : undefined;\n const reason = cause ? `${err.message}: ${cause.message}` : err.message;\n throw new ApproveError(reason, undefined, code);\n });\n\n if (approveResult.ok) {\n console.log(`✅ Approved version ${manifest.version} of ${manifest.name}.`);\n return { success: true };\n } else {\n throw new ApproveError(\n `${approveResult.statusText}, ${await approveResult.text()}, Trace ID: ${approveResult.headers.get(\"trace-id\")}`,\n approveResult.status\n );\n }\n } else {\n return { success: true };\n }\n}\n"]}
|
|
@@ -4,8 +4,8 @@ exports.IrisAppGenerator = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const internal_1 = require("@nx/js/internal");
|
|
7
|
-
const pacote = tslib_1.__importStar(require("pacote"));
|
|
8
7
|
const path = tslib_1.__importStar(require("path"));
|
|
8
|
+
const get_package_manifest_1 = require("../utils/get-package-manifest");
|
|
9
9
|
function normalizeOptions(tree, options) {
|
|
10
10
|
const name = (0, devkit_1.names)(options.name).fileName;
|
|
11
11
|
const projectDirectory = options.directory ? path.join(options.directory, name) : name;
|
|
@@ -36,9 +36,6 @@ function addFiles(tree, options, packageJson) {
|
|
|
36
36
|
};
|
|
37
37
|
(0, devkit_1.generateFiles)(tree, path.join(__dirname, "files"), options.projectRoot, templateOptions);
|
|
38
38
|
}
|
|
39
|
-
const getManifest = (packageName) => {
|
|
40
|
-
return pacote.manifest(packageName, process.env.TU_NPM_REGISTRY ? { registry: process.env.TU_NPM_REGISTRY } : undefined);
|
|
41
|
-
};
|
|
42
39
|
/**
|
|
43
40
|
* Iris App Generator.
|
|
44
41
|
* This generator will create a new iris app, you can call this from your own generator.
|
|
@@ -49,24 +46,24 @@ const getManifest = (packageName) => {
|
|
|
49
46
|
*/
|
|
50
47
|
const IrisAppGenerator = async function (tree, options) {
|
|
51
48
|
const normalizedOptions = normalizeOptions(tree, options);
|
|
52
|
-
const packageJsonFromNpm = await
|
|
49
|
+
const packageJsonFromNpm = await (0, get_package_manifest_1.getPackageManifest)("@trackunit/iris-app");
|
|
53
50
|
const packageJsonLocally = (0, devkit_1.readJsonFile)(path.join(__dirname, "..", "..", "..", "package.json"));
|
|
54
51
|
if (options.updatePackageJson) {
|
|
55
52
|
if (packageJsonFromNpm.version !== packageJsonLocally.version) {
|
|
56
53
|
// eslint-disable-next-line no-console
|
|
57
54
|
console.warn(`⚠️ This version of the iris-app package does not match the version of the iris-app package from NPM JS. Please update using: npm i @trackunit/iris-app@${packageJsonFromNpm.version}`);
|
|
58
55
|
}
|
|
59
|
-
const reactComponentsPackageJsonFromNpm =
|
|
60
|
-
const reactCoreContextsPackageJsonFromNpm =
|
|
61
|
-
const cssCorePackageJsonFromNpm =
|
|
56
|
+
const reactComponentsPackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/react-components");
|
|
57
|
+
const reactCoreContextsPackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/react-core-contexts");
|
|
58
|
+
const cssCorePackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/css-core");
|
|
62
59
|
const tuDependencies = {
|
|
63
60
|
"@trackunit/react-components": (await reactComponentsPackageJsonFromNpm).version,
|
|
64
61
|
"@trackunit/react-core-contexts": (await reactCoreContextsPackageJsonFromNpm).version,
|
|
65
62
|
"@trackunit/css-core": (await cssCorePackageJsonFromNpm).version,
|
|
66
63
|
};
|
|
67
|
-
const irisAppSdkVitePackageJsonFromNpm =
|
|
68
|
-
const reactCoreContextsTestPackageJsonFromNpm =
|
|
69
|
-
const reactTestSetupPackageJsonFromNpm =
|
|
64
|
+
const irisAppSdkVitePackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/iris-app-sdk-vite");
|
|
65
|
+
const reactCoreContextsTestPackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/react-core-contexts-test");
|
|
66
|
+
const reactTestSetupPackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/react-test-setup");
|
|
70
67
|
const tuDevDependencies = {
|
|
71
68
|
"@trackunit/iris-app-sdk-vite": (await irisAppSdkVitePackageJsonFromNpm).version,
|
|
72
69
|
"@trackunit/react-core-contexts-test": (await reactCoreContextsTestPackageJsonFromNpm).version,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/iris-app-sdk/iris-app/src/generators/create/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAYoB;AACpB,8CAA8C;AAE9C,uDAAiC;AACjC,mDAA6B;AAe7B,SAAS,gBAAgB,CAAC,IAAU,EAAE,OAA+B;IACnE,MAAM,IAAI,GAAG,IAAA,cAAK,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC;IAC1C,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvF,MAAM,QAAQ,GAAG,SAAS,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC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,EAAC,IAAI,CAAC,CAAC;IACxB,OAAO,GAAG,EAAE;QACV,IAAA,4BAAmB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAEhC,sCAAsC;QACtC,OAAO,CAAC,GAAG,CACT,wGAAwG,CACzG,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAvIW,QAAA,gBAAgB,oBAuI3B","sourcesContent":["import {\n addDependenciesToPackageJson,\n addProjectConfiguration,\n formatFiles,\n generateFiles,\n getWorkspaceLayout,\n installPackagesTask,\n names,\n offsetFromRoot,\n readJsonFile,\n Tree,\n updateJson,\n} from \"@nx/devkit\";\nimport { getNpmScope } from \"@nx/js/internal\";\nimport { PackageJson as PackageJsonBase } from \"nx/src/utils/package-json\";\nimport * as pacote from \"pacote\";\nimport * as path from \"path\";\nimport { IrisAppGeneratorSchema } from \"./schema\";\n\ntype PackageJson = PackageJsonBase & {\n engines?: Record<string, string>;\n};\n\ninterface NormalizedSchema extends IrisAppGeneratorSchema {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n toNxRoot: string;\n npmScope: string;\n}\n\nfunction normalizeOptions(tree: Tree, options: IrisAppGeneratorSchema): NormalizedSchema {\n const name = names(options.name).fileName;\n const projectDirectory = options.directory ? path.join(options.directory, name) : name;\n const toNxRoot = `../../${projectDirectory.indexOf(\"/\") !== -1 ? \"../\" : \"\"}`;\n const projectName = name.replace(new RegExp(\"/\", \"g\"), \"_\");\n const npmScope = getNpmScope(tree);\n if (!npmScope) {\n throw new Error(\"Could not find npm scope in package.json\");\n }\n const projectRoot = `${getWorkspaceLayout(tree).appsDir}/${projectDirectory}`;\n return {\n ...options,\n projectName,\n projectRoot,\n projectDirectory,\n toNxRoot,\n npmScope,\n };\n}\n\nfunction addFiles(tree: Tree, options: NormalizedSchema, packageJson: PackageJson | null) {\n const nodeVersion = packageJson?.engines?.node ?? \">=20.x\";\n const templateOptions = {\n ...options,\n ...names(options.name),\n offsetFromRoot: offsetFromRoot(options.projectRoot),\n template: \"\",\n nodeVersion,\n };\n generateFiles(tree, path.join(__dirname, \"files\"), options.projectRoot, templateOptions);\n}\n\nconst getManifest = (packageName: string) => {\n return pacote.manifest(\n packageName,\n process.env.TU_NPM_REGISTRY ? { registry: process.env.TU_NPM_REGISTRY } : undefined\n );\n};\n\n/**\n * Iris App Generator.\n * This generator will create a new iris app, you can call this from your own generator.\n *\n * @param tree the nx tree\n * @param options the generator options\n * @returns { Promise<void> } void\n */\nexport const IrisAppGenerator = async function (tree: Tree, options: IrisAppGeneratorSchema) {\n const normalizedOptions = normalizeOptions(tree, options);\n const packageJsonFromNpm = await getManifest(\"@trackunit/iris-app\");\n\n const packageJsonLocally: PackageJson = readJsonFile(path.join(__dirname, \"..\", \"..\", \"..\", \"package.json\"));\n\n if (options.updatePackageJson) {\n if (packageJsonFromNpm.version !== packageJsonLocally.version) {\n // eslint-disable-next-line no-console\n console.warn(\n `⚠️ This version of the iris-app package does not match the version of the iris-app package from NPM JS. Please update using: npm i @trackunit/iris-app@${packageJsonFromNpm.version}`\n );\n }\n\n const reactComponentsPackageJsonFromNpm = getManifest(\"@trackunit/react-components\");\n const reactCoreContextsPackageJsonFromNpm = getManifest(\"@trackunit/react-core-contexts\");\n const cssCorePackageJsonFromNpm = getManifest(\"@trackunit/css-core\");\n\n const tuDependencies = {\n \"@trackunit/react-components\": (await reactComponentsPackageJsonFromNpm).version,\n \"@trackunit/react-core-contexts\": (await reactCoreContextsPackageJsonFromNpm).version,\n \"@trackunit/css-core\": (await cssCorePackageJsonFromNpm).version,\n };\n\n const irisAppSdkVitePackageJsonFromNpm = getManifest(\"@trackunit/iris-app-sdk-vite\");\n const reactCoreContextsTestPackageJsonFromNpm = getManifest(\"@trackunit/react-core-contexts-test\");\n const reactTestSetupPackageJsonFromNpm = getManifest(\"@trackunit/react-test-setup\");\n\n const tuDevDependencies = {\n \"@trackunit/iris-app-sdk-vite\": (await irisAppSdkVitePackageJsonFromNpm).version,\n \"@trackunit/react-core-contexts-test\": (await reactCoreContextsTestPackageJsonFromNpm).version,\n \"@trackunit/react-test-setup\": (await reactTestSetupPackageJsonFromNpm).version,\n };\n\n addDependenciesToPackageJson(\n tree,\n {\n ...tuDependencies,\n \"@apollo/client\": \"3.14.1\",\n graphql: \"16.10.0\",\n \"@tanstack/react-router\": \"1.114.29\",\n tslib: \"2.4.0\",\n react: \"19.0.0\",\n \"react-dom\": \"19.0.0\",\n \"single-spa-react\": \"5.1.4\",\n },\n {\n ...tuDevDependencies,\n nx: \"23.1.0\",\n \"@nx/react\": \"23.1.0\",\n \"@nx/workspace\": \"23.1.0\",\n \"@nx/devkit\": \"23.1.0\",\n \"@nx/eslint-plugin\": \"23.1.0\",\n \"@types/react\": \"19.0.8\",\n eslint: \"9.33.0\",\n \"eslint-plugin-react-hooks\": \"7.0.1\",\n \"eslint-plugin-react\": \"7.37.5\",\n \"eslint-plugin-import\": \"2.32.0\",\n \"eslint-plugin-jsx-a11y\": \"6.10.2\",\n \"typescript-eslint\": \"8.58.1\",\n typescript: \"6.0.2\",\n }\n );\n\n updateJson(tree, \"package.json\", packageJson => {\n packageJson.overrides = {\n react: \"19.0.0\", // to avoid resolution warnings when running npm install\n \"react-dom\": \"19.0.0\", // fix resolution warnings and test\n \"zod-validation-error\": \"4.0.2\",\n };\n return packageJson;\n });\n }\n addProjectConfiguration(tree, normalizedOptions.projectName, {\n root: normalizedOptions.projectRoot,\n projectType: \"application\",\n sourceRoot: `${normalizedOptions.projectRoot}/src`,\n targets: {\n build: {\n executor: \"@trackunit/iris-app-sdk-vite:build\",\n dependsOn: [\n {\n target: \"build\",\n params: \"forward\",\n dependencies: true,\n },\n ],\n options: {\n viteConfig: `${normalizedOptions.projectRoot}/vite.config.ts`,\n outputPath: `dist/${normalizedOptions.projectRoot}`,\n },\n outputs: [\"{options.outputPath}\"],\n },\n serve: {\n executor: \"@trackunit/iris-app-sdk-vite:serve\",\n options: {\n viteConfig: `${normalizedOptions.projectRoot}/vite.config.ts`,\n },\n outputs: [\"{options.outputPath}\"],\n },\n submitApp: {\n executor: \"@trackunit/iris-app:submit\",\n dependsOn: [\"build\"],\n options: {\n inputPath: `dist/${normalizedOptions.projectRoot}`,\n },\n outputs: [\"{workspaceRoot}/dist/\" + normalizedOptions.projectRoot],\n },\n unpublishApp: {\n executor: \"@trackunit/iris-app:unpublish\",\n options: {\n inputPath: `dist/${normalizedOptions.projectRoot}`,\n },\n dependsOn: [\n {\n target: \"build\",\n },\n ],\n outputs: [\"{workspaceRoot}/dist/\" + normalizedOptions.projectRoot],\n },\n },\n });\n addFiles(tree, normalizedOptions, packageJsonLocally);\n // enforcing engine versions specified in package.json\n tree.write(\".npmrc\", \"engine-strict=true\\n\");\n\n await formatFiles(tree);\n return () => {\n installPackagesTask(tree, true);\n\n // eslint-disable-next-line no-console\n console.log(\n \"🥳 Successfully created an Iris App - review the iris-app-manifest.ts and start adding app extensions!\"\n );\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/iris-app-sdk/iris-app/src/generators/create/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAYoB;AACpB,8CAA8C;AAE9C,mDAA6B;AAC7B,wEAAmE;AAenE,SAAS,gBAAgB,CAAC,IAAU,EAAE,OAA+B;IACnE,MAAM,IAAI,GAAG,IAAA,cAAK,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC;IAC1C,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvF,MAAM,QAAQ,GAAG,SAAS,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC9E,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,MAA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n getWorkspaceLayout,\n installPackagesTask,\n names,\n offsetFromRoot,\n readJsonFile,\n Tree,\n updateJson,\n} from \"@nx/devkit\";\nimport { getNpmScope } from \"@nx/js/internal\";\nimport { PackageJson as PackageJsonBase } from \"nx/src/utils/package-json\";\nimport * as path from \"path\";\nimport { getPackageManifest } from \"../utils/get-package-manifest\";\nimport { IrisAppGeneratorSchema } from \"./schema\";\n\ntype PackageJson = PackageJsonBase & {\n engines?: Record<string, string>;\n};\n\ninterface NormalizedSchema extends IrisAppGeneratorSchema {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n toNxRoot: string;\n npmScope: string;\n}\n\nfunction normalizeOptions(tree: Tree, options: IrisAppGeneratorSchema): NormalizedSchema {\n const name = names(options.name).fileName;\n const projectDirectory = options.directory ? path.join(options.directory, name) : name;\n const toNxRoot = `../../${projectDirectory.indexOf(\"/\") !== -1 ? \"../\" : \"\"}`;\n const projectName = name.replace(new RegExp(\"/\", \"g\"), \"_\");\n const npmScope = getNpmScope(tree);\n if (!npmScope) {\n throw new Error(\"Could not find npm scope in package.json\");\n }\n const projectRoot = `${getWorkspaceLayout(tree).appsDir}/${projectDirectory}`;\n return {\n ...options,\n projectName,\n projectRoot,\n projectDirectory,\n toNxRoot,\n npmScope,\n };\n}\n\nfunction addFiles(tree: Tree, options: NormalizedSchema, packageJson: PackageJson | null) {\n const nodeVersion = packageJson?.engines?.node ?? \">=20.x\";\n const templateOptions = {\n ...options,\n ...names(options.name),\n offsetFromRoot: offsetFromRoot(options.projectRoot),\n template: \"\",\n nodeVersion,\n };\n generateFiles(tree, path.join(__dirname, \"files\"), options.projectRoot, templateOptions);\n}\n\n/**\n * Iris App Generator.\n * This generator will create a new iris app, you can call this from your own generator.\n *\n * @param tree the nx tree\n * @param options the generator options\n * @returns { Promise<void> } void\n */\nexport const IrisAppGenerator = async function (tree: Tree, options: IrisAppGeneratorSchema) {\n const normalizedOptions = normalizeOptions(tree, options);\n const packageJsonFromNpm = await getPackageManifest(\"@trackunit/iris-app\");\n\n const packageJsonLocally: PackageJson = readJsonFile(path.join(__dirname, \"..\", \"..\", \"..\", \"package.json\"));\n\n if (options.updatePackageJson) {\n if (packageJsonFromNpm.version !== packageJsonLocally.version) {\n // eslint-disable-next-line no-console\n console.warn(\n `⚠️ This version of the iris-app package does not match the version of the iris-app package from NPM JS. Please update using: npm i @trackunit/iris-app@${packageJsonFromNpm.version}`\n );\n }\n\n const reactComponentsPackageJsonFromNpm = getPackageManifest(\"@trackunit/react-components\");\n const reactCoreContextsPackageJsonFromNpm = getPackageManifest(\"@trackunit/react-core-contexts\");\n const cssCorePackageJsonFromNpm = getPackageManifest(\"@trackunit/css-core\");\n\n const tuDependencies = {\n \"@trackunit/react-components\": (await reactComponentsPackageJsonFromNpm).version,\n \"@trackunit/react-core-contexts\": (await reactCoreContextsPackageJsonFromNpm).version,\n \"@trackunit/css-core\": (await cssCorePackageJsonFromNpm).version,\n };\n\n const irisAppSdkVitePackageJsonFromNpm = getPackageManifest(\"@trackunit/iris-app-sdk-vite\");\n const reactCoreContextsTestPackageJsonFromNpm = getPackageManifest(\"@trackunit/react-core-contexts-test\");\n const reactTestSetupPackageJsonFromNpm = getPackageManifest(\"@trackunit/react-test-setup\");\n\n const tuDevDependencies = {\n \"@trackunit/iris-app-sdk-vite\": (await irisAppSdkVitePackageJsonFromNpm).version,\n \"@trackunit/react-core-contexts-test\": (await reactCoreContextsTestPackageJsonFromNpm).version,\n \"@trackunit/react-test-setup\": (await reactTestSetupPackageJsonFromNpm).version,\n };\n\n addDependenciesToPackageJson(\n tree,\n {\n ...tuDependencies,\n \"@apollo/client\": \"3.14.1\",\n graphql: \"16.10.0\",\n \"@tanstack/react-router\": \"1.114.29\",\n tslib: \"2.4.0\",\n react: \"19.0.0\",\n \"react-dom\": \"19.0.0\",\n \"single-spa-react\": \"5.1.4\",\n },\n {\n ...tuDevDependencies,\n nx: \"23.1.0\",\n \"@nx/react\": \"23.1.0\",\n \"@nx/workspace\": \"23.1.0\",\n \"@nx/devkit\": \"23.1.0\",\n \"@nx/eslint-plugin\": \"23.1.0\",\n \"@types/react\": \"19.0.8\",\n eslint: \"9.33.0\",\n \"eslint-plugin-react-hooks\": \"7.0.1\",\n \"eslint-plugin-react\": \"7.37.5\",\n \"eslint-plugin-import\": \"2.32.0\",\n \"eslint-plugin-jsx-a11y\": \"6.10.2\",\n \"typescript-eslint\": \"8.58.1\",\n typescript: \"6.0.2\",\n }\n );\n\n updateJson(tree, \"package.json\", packageJson => {\n packageJson.overrides = {\n react: \"19.0.0\", // to avoid resolution warnings when running npm install\n \"react-dom\": \"19.0.0\", // fix resolution warnings and test\n \"zod-validation-error\": \"4.0.2\",\n };\n return packageJson;\n });\n }\n addProjectConfiguration(tree, normalizedOptions.projectName, {\n root: normalizedOptions.projectRoot,\n projectType: \"application\",\n sourceRoot: `${normalizedOptions.projectRoot}/src`,\n targets: {\n build: {\n executor: \"@trackunit/iris-app-sdk-vite:build\",\n dependsOn: [\n {\n target: \"build\",\n params: \"forward\",\n dependencies: true,\n },\n ],\n options: {\n viteConfig: `${normalizedOptions.projectRoot}/vite.config.ts`,\n outputPath: `dist/${normalizedOptions.projectRoot}`,\n },\n outputs: [\"{options.outputPath}\"],\n },\n serve: {\n executor: \"@trackunit/iris-app-sdk-vite:serve\",\n options: {\n viteConfig: `${normalizedOptions.projectRoot}/vite.config.ts`,\n },\n outputs: [\"{options.outputPath}\"],\n },\n submitApp: {\n executor: \"@trackunit/iris-app:submit\",\n dependsOn: [\"build\"],\n options: {\n inputPath: `dist/${normalizedOptions.projectRoot}`,\n },\n outputs: [\"{workspaceRoot}/dist/\" + normalizedOptions.projectRoot],\n },\n unpublishApp: {\n executor: \"@trackunit/iris-app:unpublish\",\n options: {\n inputPath: `dist/${normalizedOptions.projectRoot}`,\n },\n dependsOn: [\n {\n target: \"build\",\n },\n ],\n outputs: [\"{workspaceRoot}/dist/\" + normalizedOptions.projectRoot],\n },\n },\n });\n addFiles(tree, normalizedOptions, packageJsonLocally);\n // enforcing engine versions specified in package.json\n tree.write(\".npmrc\", \"engine-strict=true\\n\");\n\n await formatFiles(tree);\n return () => {\n installPackagesTask(tree, true);\n\n // eslint-disable-next-line no-console\n console.log(\n \"🥳 Successfully created an Iris App - review the iris-app-manifest.ts and start adding app extensions!\"\n );\n };\n};\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createTrackunitGraphqlClient, getUserToken } from "@trackunit/serverside-utils";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { <%= className %>AssetByIdDocument } from "./generated/graphql-api/graphql";
|
|
4
|
+
|
|
5
|
+
const app = new Hono();
|
|
6
|
+
|
|
7
|
+
app.get("/health", c => {
|
|
8
|
+
return c.json({
|
|
9
|
+
status: "ok",
|
|
10
|
+
timestamp: new Date().toISOString(),
|
|
11
|
+
service: "<%= projectName %>",
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.get("/assets/:id", async c => {
|
|
16
|
+
const token = getUserToken({ context: c });
|
|
17
|
+
if (!token) {
|
|
18
|
+
return c.json({ error: "Unauthorized" }, 401);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const client = createTrackunitGraphqlClient({ context: c });
|
|
22
|
+
const data = await client.request({
|
|
23
|
+
document: <%= className %>AssetByIdDocument,
|
|
24
|
+
variables: { id: c.req.param("id") },
|
|
25
|
+
signal: c.req.raw.signal,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return c.json(data);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export default app.fetch;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { Tree } from "@nx/devkit";
|
|
2
2
|
import { IrisAppExtensionGeneratorSchema } from "./schema";
|
|
3
|
+
type ServersideGraphqlOptions = {
|
|
4
|
+
readonly projectName: string;
|
|
5
|
+
readonly projectRoot: string;
|
|
6
|
+
readonly className: string;
|
|
7
|
+
readonly serversideUtilsVersion: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Adds public-schema codegen and a typed Hono example to a generated serverside extension.
|
|
11
|
+
*/
|
|
12
|
+
export declare const addServersideGraphql: (tree: Tree, options: ServersideGraphqlOptions) => Promise<void>;
|
|
3
13
|
/**
|
|
4
14
|
* Ensures that jest.preset.js exists and includes the required @trackunit/react-test-setup preset.
|
|
5
15
|
* If the file doesn't exist, creates it. If it exists but doesn't include the preset, updates it.
|
|
@@ -13,3 +23,4 @@ export declare function ensureJestPresetConfiguration(tree: Tree, templateOption
|
|
|
13
23
|
* @returns { Promise<void> } void
|
|
14
24
|
*/
|
|
15
25
|
export declare const IrisAppExtensionGenerator: (tree: Tree, options: IrisAppExtensionGeneratorSchema) => Promise<() => void>;
|
|
26
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IrisAppExtensionGenerator = void 0;
|
|
3
|
+
exports.IrisAppExtensionGenerator = exports.addServersideGraphql = void 0;
|
|
4
4
|
exports.ensureJestPresetConfiguration = ensureJestPresetConfiguration;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -9,12 +9,53 @@ const js_1 = require("@nx/js");
|
|
|
9
9
|
const internal_1 = require("@nx/js/internal");
|
|
10
10
|
const react_1 = require("@nx/react");
|
|
11
11
|
const iris_app_api_1 = require("@trackunit/iris-app-api");
|
|
12
|
+
const react_graphql_tools_1 = require("@trackunit/react-graphql-tools");
|
|
12
13
|
const fs = tslib_1.__importStar(require("fs"));
|
|
13
14
|
const path = tslib_1.__importStar(require("path"));
|
|
14
15
|
const string_ts_1 = require("string-ts");
|
|
15
16
|
const ts_morph_1 = require("ts-morph");
|
|
16
17
|
const astUtils_1 = require("../../utils/ast/astUtils");
|
|
18
|
+
const get_package_manifest_1 = require("../utils/get-package-manifest");
|
|
17
19
|
const dependencies_1 = require("./dependencies");
|
|
20
|
+
const addGraphqlDependency = (target) => {
|
|
21
|
+
if (!target) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const dependsOn = target.dependsOn ?? [];
|
|
25
|
+
if (!dependsOn.includes("graphql-hooks")) {
|
|
26
|
+
target.dependsOn = [...dependsOn, "graphql-hooks"];
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Adds public-schema codegen and a typed Hono example to a generated serverside extension.
|
|
31
|
+
*/
|
|
32
|
+
const addServersideGraphql = async (tree, options) => {
|
|
33
|
+
await (0, react_graphql_tools_1.addGraphqlGenerator)(tree, {
|
|
34
|
+
project: options.projectName,
|
|
35
|
+
schemaSource: "public",
|
|
36
|
+
generateMocks: false,
|
|
37
|
+
});
|
|
38
|
+
(0, devkit_1.generateFiles)(tree, path.join(__dirname, "files", "SERVERSIDE_API_EXTENSION_GRAPHQL"), options.projectRoot, {
|
|
39
|
+
...options,
|
|
40
|
+
template: "",
|
|
41
|
+
});
|
|
42
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, "project.json"), projectJson => {
|
|
43
|
+
addGraphqlDependency(projectJson.targets.build);
|
|
44
|
+
addGraphqlDependency(projectJson.targets.test);
|
|
45
|
+
addGraphqlDependency(projectJson.targets.serve);
|
|
46
|
+
addGraphqlDependency(projectJson.targets["tsc-validate"]);
|
|
47
|
+
return projectJson;
|
|
48
|
+
});
|
|
49
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, "package.json"), packageJson => {
|
|
50
|
+
packageJson.dependencies = {
|
|
51
|
+
...packageJson.dependencies,
|
|
52
|
+
"@trackunit/serverside-utils": options.serversideUtilsVersion,
|
|
53
|
+
};
|
|
54
|
+
return packageJson;
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
exports.addServersideGraphql = addServersideGraphql;
|
|
58
|
+
const getPackageVersion = async (packageName) => (await (0, get_package_manifest_1.getPackageManifest)(packageName)).version;
|
|
18
59
|
function normalizeOptions(tree, options) {
|
|
19
60
|
const name = (0, devkit_1.names)(options.name).fileName;
|
|
20
61
|
const projectDirectory = options.directory ? `${(0, devkit_1.names)(options.directory).fileName}/${name}` : name;
|
|
@@ -86,6 +127,9 @@ const IrisAppExtensionGenerator = async function (tree, options) {
|
|
|
86
127
|
template: "",
|
|
87
128
|
};
|
|
88
129
|
const irisAppExtensionType = normalizedOptions.type;
|
|
130
|
+
if (normalizedOptions.graphql && irisAppExtensionType !== "SERVERSIDE_API_EXTENSION") {
|
|
131
|
+
throw new Error("GraphQL setup is only supported for SERVERSIDE_API_EXTENSION");
|
|
132
|
+
}
|
|
89
133
|
if (!tree.exists(`${(0, devkit_1.getWorkspaceLayout)(tree).appsDir}/${normalizedOptions.app}`)) {
|
|
90
134
|
throw new Error(`The app does not exist: ${(0, devkit_1.getWorkspaceLayout)(tree).appsDir}/${normalizedOptions.app} make sure you enter the right app name`);
|
|
91
135
|
}
|
|
@@ -193,6 +237,14 @@ const IrisAppExtensionGenerator = async function (tree, options) {
|
|
|
193
237
|
return projectJson;
|
|
194
238
|
});
|
|
195
239
|
}
|
|
240
|
+
if (normalizedOptions.graphql) {
|
|
241
|
+
await (0, exports.addServersideGraphql)(tree, {
|
|
242
|
+
projectName: normalizedOptions.projectName,
|
|
243
|
+
projectRoot: normalizedOptions.projectRoot,
|
|
244
|
+
className: (0, devkit_1.names)(normalizedOptions.name).className,
|
|
245
|
+
serversideUtilsVersion: await getPackageVersion("@trackunit/serverside-utils"),
|
|
246
|
+
});
|
|
247
|
+
}
|
|
196
248
|
//TODO: Change the following to update the manifest in the virtual Tree - not on the file system.
|
|
197
249
|
const project = new ts_morph_1.Project({
|
|
198
250
|
tsConfigFilePath: `${(0, devkit_1.getWorkspaceLayout)(tree).appsDir}/${normalizedOptions.app}/tsconfig.app.json`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["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AC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YAED,OAAO,CAAC,GAAG,GAAG,WAAW,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {\n addDependenciesToPackageJson,\n formatFiles,\n generateFiles,\n getWorkspaceLayout,\n installPackagesTask,\n joinPathFragments,\n names,\n offsetFromRoot,\n Tree,\n updateJson,\n} from \"@nx/devkit\";\nimport { Linter } from \"@nx/eslint\";\nimport { getRootTsConfigPathInTree } from \"@nx/js\";\nimport { getNpmScope } from \"@nx/js/internal\";\nimport { libraryGenerator } from \"@nx/react\";\nimport { nonUiExtensionTypes, serverSideExtensionTypes } from \"@trackunit/iris-app-api\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { camelCase } from \"string-ts\";\nimport { Project, SyntaxKind, VariableDeclaration } from \"ts-morph\";\nimport { addRequireStatement, addSpreadAssignment } from \"../../utils/ast/astUtils\";\nimport { spaDependencies, testDependencies } from \"./dependencies\";\nimport { IrisAppExtensionGeneratorSchema } from \"./schema\";\n\ntype Schema = Parameters<typeof libraryGenerator>[1];\n\ninterface NormalizedSchema extends IrisAppExtensionGeneratorSchema {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n projectCamelcase: string;\n importPath: string;\n sourceRoot: string;\n dependencyDefinitionFile: string;\n}\n\nfunction normalizeOptions(tree: Tree, options: IrisAppExtensionGeneratorSchema): NormalizedSchema {\n const name = names(options.name).fileName;\n const projectDirectory = options.directory ? `${names(options.directory).fileName}/${name}` : name;\n const projectName = projectDirectory.replace(new RegExp(\"/\", \"g\"), \"-\");\n const projectCamelcase = camelCase(projectName);\n const wsLayout = getWorkspaceLayout(tree);\n const projectRoot = `${wsLayout.libsDir}/${projectDirectory}`;\n const sourceRoot = `${wsLayout.libsDir}/${projectDirectory}/src`;\n const dependencyDefinitionFile = `${wsLayout.libsDir}/${projectDirectory}/package.json`;\n\n const npmScope = getNpmScope(tree);\n if (!npmScope) {\n throw new Error(\"Could not find npm scope in package.json\");\n }\n const importPath = `@${npmScope}/${projectName}`;\n\n return {\n ...options,\n projectName,\n projectRoot,\n projectDirectory,\n projectCamelcase,\n importPath,\n sourceRoot,\n dependencyDefinitionFile,\n };\n}\n\n/**\n * Ensures that jest.preset.js exists and includes the required @trackunit/react-test-setup preset.\n * If the file doesn't exist, creates it. If it exists but doesn't include the preset, updates it.\n */\nexport function ensureJestPresetConfiguration(tree: Tree, templateOptions?: object): void {\n const jestPresetPath = \"jest.preset.js\";\n\n if (!tree.exists(jestPresetPath)) {\n // File doesn't exist, generate it using the template\n generateFiles(tree, path.join(__dirname, \"files\", \"preset\"), \"/\", templateOptions || {});\n return;\n }\n\n // File exists, use AST utilities for reliable manipulation\n let currentContent = tree.read(jestPresetPath, \"utf-8\");\n if (!currentContent) {\n throw new Error(`Could not read ${jestPresetPath}`);\n }\n\n // Extract variable name from existing import if it exists\n let presetVariableName = \"irisPreset\"; // default name\n const existingImportMatch = currentContent.match(\n /const\\s+(\\w+)\\s*=\\s*require\\([\"']@trackunit\\/react-test-setup\\/preset[\"']\\)/\n );\n if (existingImportMatch && existingImportMatch[1]) {\n presetVariableName = existingImportMatch[1];\n }\n\n // Add the require statement if it doesn't exist\n currentContent = addRequireStatement(currentContent, presetVariableName, \"@trackunit/react-test-setup/preset\");\n\n // Add the spread assignment to the module.exports object\n currentContent = addSpreadAssignment(currentContent, presetVariableName);\n\n // Write the updated content back to the tree\n tree.write(jestPresetPath, currentContent);\n}\n\n/**\n * Iris App Extension Generator.\n *\n * @param tree the nx tree\n * @param options the generator options\n * @returns { Promise<void> } void\n */\nexport const IrisAppExtensionGenerator = async function (tree: Tree, options: IrisAppExtensionGeneratorSchema) {\n const adjustedOptions = await updateAppName(tree, options);\n\n const normalizedOptions = normalizeOptions(tree, adjustedOptions);\n\n const templateOptions = {\n ...normalizedOptions,\n ...names(normalizedOptions.name),\n offsetFromRoot: offsetFromRoot(normalizedOptions.projectRoot),\n template: \"\",\n };\n const irisAppExtensionType = normalizedOptions.type;\n\n if (!tree.exists(`${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}`)) {\n throw new Error(\n `The app does not exist: ${getWorkspaceLayout(tree).appsDir}/${\n normalizedOptions.app\n } make sure you enter the right app name`\n );\n }\n\n const manifestPath = `${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}/iris-app-manifest.ts`;\n if (!tree.exists(manifestPath)) {\n throw new Error(\n `The app does not have an iris-app-manifest.ts: ${manifestPath} make sure you enter the right app name, which has an iris-app-manifest.ts`\n );\n }\n\n if (normalizedOptions.updatePackageJson) {\n addDependenciesToPackageJson(\n tree,\n {},\n {\n ...spaDependencies,\n ...testDependencies,\n }\n );\n }\n\n const schema: Schema = {\n name: normalizedOptions.projectName,\n style: \"none\",\n skipFormat: false,\n strict: true,\n // Nx 23 warns that \"jest\" emits the deprecated @nx/jest:jest target, but unlike\n // createSubgraph this generator has no jest.config/tsconfig.spec templates of its\n // own and updates the generated tsconfig.spec.json below. Switching to \"none\"\n // requires shipping those templates first.\n unitTestRunner: \"jest\",\n linter: Linter.EsLint,\n routing: false,\n directory: normalizedOptions.projectRoot,\n skipTsConfig: false,\n skipPackageJson: true,\n };\n\n await libraryGenerator(tree, schema);\n\n generateFiles(\n tree,\n path.join(__dirname, \"files\", irisAppExtensionType),\n normalizedOptions.projectRoot,\n templateOptions\n );\n\n if (!nonUiExtensionTypes.includes(irisAppExtensionType)) {\n generateFiles(tree, path.join(__dirname, \"files\", \"react-app\"), normalizedOptions.projectRoot, templateOptions);\n if (normalizedOptions.extendJestPreset) {\n ensureJestPresetConfiguration(tree, templateOptions);\n }\n }\n\n const rootTsConfigPath = getRootTsConfigPathInTree(tree);\n if (!rootTsConfigPath) {\n throw new Error(\"Could not find root tsconfig.json\");\n }\n updateJson(tree, rootTsConfigPath, tsConfigBase => {\n // For server side extension types, we need to add deno types to the tsconfig and make Typescript accept Deno import syntax\n if (serverSideExtensionTypes.includes(irisAppExtensionType)) {\n tsConfigBase.compilerOptions = {\n ...tsConfigBase.compilerOptions,\n types: [\"node\"],\n esModuleInterop: true,\n };\n }\n\n tsConfigBase.compilerOptions.paths[normalizedOptions.importPath] = [\n path.join(normalizedOptions.projectRoot, \"extension-manifest.ts\"),\n ];\n return tsConfigBase;\n });\n\n // Add working serve target to the project.json for DENO extensions\n if (serverSideExtensionTypes.includes(irisAppExtensionType)) {\n updateJson(tree, joinPathFragments(normalizedOptions.projectRoot, \"project.json\"), projectJson => {\n projectJson.targets.serve = {\n executor: \"@nx/js:node\",\n options: {\n buildTarget: `${normalizedOptions.projectName}:build:development`,\n inspect: true,\n },\n configurations: {\n breakOnStart: {\n inspect: \"inspect-brk\",\n },\n },\n };\n projectJson.targets.build = {\n executor: \"@nx/esbuild:esbuild\",\n outputs: [\"{options.outputPath}\"],\n defaultConfiguration: \"production\",\n options: {\n platform: \"node\",\n outputPath: `dist/${normalizedOptions.projectRoot}`,\n format: [\"cjs\"],\n bundle: true,\n thirdParty: true,\n external: [],\n main: `${normalizedOptions.sourceRoot}/index.ts`,\n tsConfig: `libs/${normalizedOptions.projectDirectory}/tsconfig.lib.json`,\n esbuildOptions: {\n sourcemap: true,\n outExtension: {\n \".js\": \".js\",\n },\n },\n },\n configurations: {\n development: {\n main: `${normalizedOptions.sourceRoot}/local-serve.ts`,\n },\n production: {\n esbuildOptions: {\n sourcemap: false,\n outExtension: {\n \".js\": \".js\",\n },\n },\n },\n },\n };\n return projectJson;\n });\n }\n\n //TODO: Change the following to update the manifest in the virtual Tree - not on the file system.\n const project = new Project({\n tsConfigFilePath: `${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}/tsconfig.app.json`,\n });\n\n const manifest = project.getSourceFileOrThrow(manifestPath);\n\n manifest.addImportDeclaration({\n moduleSpecifier: normalizedOptions.importPath,\n defaultImport: normalizedOptions.projectCamelcase,\n });\n\n // Get the default export symbol from the manifest\n const defaultExportSymbol = manifest.getDefaultExportSymbolOrThrow();\n\n // Get the aliased symbol if the default export is an alias\n const aliasedSymbol = defaultExportSymbol.getAliasedSymbol() || defaultExportSymbol;\n\n // Get the declaration of the aliased symbol\n const declaration = aliasedSymbol.getDeclarations()[0];\n\n if (!VariableDeclaration.isVariableDeclaration(declaration)) {\n throw new Error(\"Expected variable declaration\");\n }\n const irisAppManifestObject = declaration.getInitializer()?.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n if (!irisAppManifestObject) {\n throw new Error(`irisAppManifest not exported from the file: ${manifestPath}`);\n }\n // Find the extensions property within the irisAppManifest object\n const extensionsProperty = irisAppManifestObject.getPropertyOrThrow(\"extensions\");\n\n if (extensionsProperty.getKind() === SyntaxKind.PropertyAssignment) {\n const extensionsArray = extensionsProperty.getFirstChildByKindOrThrow(SyntaxKind.ArrayLiteralExpression);\n extensionsArray.addElement(`${normalizedOptions.projectCamelcase}`);\n }\n\n await manifest.save();\n\n if (!serverSideExtensionTypes.includes(irisAppExtensionType)) {\n tree.delete(joinPathFragments(normalizedOptions.projectRoot, \"src\", \"index.ts\"));\n }\n\n updateJson(tree, joinPathFragments(normalizedOptions.projectRoot, \"tsconfig.spec.json\"), tsConfigSpec => {\n // extension-manifest.ts is a build time file, so we only need to include it in the spec file for type/lint checking\n tsConfigSpec.include = [...tsConfigSpec.include, \"**/jest.setup.ts*\", \"extension-manifest.ts\"];\n return tsConfigSpec;\n });\n\n await formatFiles(tree);\n installPackagesTask(tree, true);\n return () => {\n // eslint-disable-next-line no-console\n console.log(\"🥳 Successfully created an app extensions and it is already added to the Iris App!\");\n };\n};\nconst updateAppName = async (tree: Tree, options: IrisAppExtensionGeneratorSchema) => {\n if (!options.app) {\n const folders = fs\n .readdirSync(getWorkspaceLayout(tree).appsDir, { withFileTypes: true })\n .filter(item => item.isDirectory());\n\n const tileApps: Array<string> = [];\n\n folders.forEach(folder => {\n const irisAppManifest = fs\n .readdirSync(`${getWorkspaceLayout(tree).appsDir}/${folder.name}`, { withFileTypes: true })\n .find(item => item.name === \"iris-app-manifest.ts\");\n\n if (irisAppManifest) {\n tileApps.push(folder.name);\n } else {\n const subFolders = fs\n .readdirSync(path.join(getWorkspaceLayout(tree).appsDir, folder.name), { withFileTypes: true })\n .filter(item => item.isDirectory());\n subFolders.forEach(subFolder => {\n const subDirIrisAppManifest = fs\n .readdirSync(`${getWorkspaceLayout(tree).appsDir}/${folder.name}/${subFolder.name}`, {\n withFileTypes: true,\n })\n .find(item => item.name === \"iris-app-manifest.ts\");\n\n if (subDirIrisAppManifest) {\n tileApps.push(path.join(folder.name, subFolder.name));\n }\n });\n }\n });\n\n if (tileApps.length === 1) {\n options.app = tileApps[0] || \"<Missing iris app name>\";\n } else if (tileApps.length === 0) {\n throw new Error(\"Please add an iris-app using: nx g @trackunit/iris-app:create \");\n } else {\n // Dynamic import to avoid loading ESM module at test time when not needed\n const { autocomplete, isCancel, cancel } = await import(\"@clack/prompts\");\n\n const selectedApp = await autocomplete({\n message: \"Select the iris app that this extension should belong to (type to filter):\",\n options: tileApps.map(item => ({ value: item, label: item })),\n maxItems: 15,\n });\n\n if (isCancel(selectedApp)) {\n cancel(\"Operation cancelled.\");\n process.exit(0);\n }\n\n options.app = selectedApp;\n }\n }\n return options;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/iris-app-sdk/iris-app/src/generators/extend/generator.ts"],"names":[],"mappings":";;;AAwIA,sEAgCC;;AAxKD,uCAWoB;AACpB,uCAAoC;AACpC,+BAAmD;AACnD,8CAA8C;AAC9C,qCAA6C;AAC7C,0DAAwF;AACxF,wEAAqE;AACrE,+CAAyB;AACzB,mDAA6B;AAC7B,yCAAsC;AACtC,uCAAoE;AACpE,uDAAoF;AACpF,wEAAmE;AACnE,iDAAmE;AAkCnE,MAAM,oBAAoB,GAAG,CAAC,MAAiC,EAAQ,EAAE;IACvE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;IACT,CAAC;IAED,MAAM,SAAS,G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CAAC;QACpF,CAAC;aAAM,CAAC;YACN,0EAA0E;YAC1E,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,gEAAa,gBAAgB,GAAC,CAAC;YAE1E,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC;gBACrC,OAAO,EAAE,4EAA4E;gBACrF,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC7D,QAAQ,EAAE,EAAE;aACb,CAAC,CAAC;YAEH,IAAI,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC1B,MAAM,CAAC,sBAAsB,CAAC,CAAC;gBAC/B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YAED,OAAO,CAAC,GAAG,GAAG,WAAW,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {\n addDependenciesToPackageJson,\n formatFiles,\n generateFiles,\n getWorkspaceLayout,\n installPackagesTask,\n joinPathFragments,\n names,\n offsetFromRoot,\n Tree,\n updateJson,\n} from \"@nx/devkit\";\nimport { Linter } from \"@nx/eslint\";\nimport { getRootTsConfigPathInTree } from \"@nx/js\";\nimport { getNpmScope } from \"@nx/js/internal\";\nimport { libraryGenerator } from \"@nx/react\";\nimport { nonUiExtensionTypes, serverSideExtensionTypes } from \"@trackunit/iris-app-api\";\nimport { addGraphqlGenerator } from \"@trackunit/react-graphql-tools\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { camelCase } from \"string-ts\";\nimport { Project, SyntaxKind, VariableDeclaration } from \"ts-morph\";\nimport { addRequireStatement, addSpreadAssignment } from \"../../utils/ast/astUtils\";\nimport { getPackageManifest } from \"../utils/get-package-manifest\";\nimport { spaDependencies, testDependencies } from \"./dependencies\";\nimport { IrisAppExtensionGeneratorSchema } from \"./schema\";\n\ntype Schema = Parameters<typeof libraryGenerator>[1];\n\ninterface NormalizedSchema extends IrisAppExtensionGeneratorSchema {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n projectCamelcase: string;\n importPath: string;\n sourceRoot: string;\n dependencyDefinitionFile: string;\n}\n\ntype ServersideGraphqlOptions = {\n readonly projectName: string;\n readonly projectRoot: string;\n readonly className: string;\n readonly serversideUtilsVersion: string;\n};\n\ntype ProjectTarget = {\n dependsOn?: Array<string | Record<string, unknown>>;\n};\n\ntype ProjectJson = {\n targets: Record<string, ProjectTarget>;\n};\n\ntype DependencyPackageJson = {\n dependencies?: Record<string, string>;\n};\n\nconst addGraphqlDependency = (target: ProjectTarget | undefined): void => {\n if (!target) {\n return;\n }\n\n const dependsOn = target.dependsOn ?? [];\n if (!dependsOn.includes(\"graphql-hooks\")) {\n target.dependsOn = [...dependsOn, \"graphql-hooks\"];\n }\n};\n\n/**\n * Adds public-schema codegen and a typed Hono example to a generated serverside extension.\n */\nexport const addServersideGraphql = async (tree: Tree, options: ServersideGraphqlOptions): Promise<void> => {\n await addGraphqlGenerator(tree, {\n project: options.projectName,\n schemaSource: \"public\",\n generateMocks: false,\n });\n\n generateFiles(tree, path.join(__dirname, \"files\", \"SERVERSIDE_API_EXTENSION_GRAPHQL\"), options.projectRoot, {\n ...options,\n template: \"\",\n });\n\n updateJson<ProjectJson>(tree, joinPathFragments(options.projectRoot, \"project.json\"), projectJson => {\n addGraphqlDependency(projectJson.targets.build);\n addGraphqlDependency(projectJson.targets.test);\n addGraphqlDependency(projectJson.targets.serve);\n addGraphqlDependency(projectJson.targets[\"tsc-validate\"]);\n return projectJson;\n });\n\n updateJson<DependencyPackageJson>(tree, joinPathFragments(options.projectRoot, \"package.json\"), packageJson => {\n packageJson.dependencies = {\n ...packageJson.dependencies,\n \"@trackunit/serverside-utils\": options.serversideUtilsVersion,\n };\n return packageJson;\n });\n};\n\nconst getPackageVersion = async (packageName: string): Promise<string> =>\n (await getPackageManifest(packageName)).version;\n\nfunction normalizeOptions(tree: Tree, options: IrisAppExtensionGeneratorSchema): NormalizedSchema {\n const name = names(options.name).fileName;\n const projectDirectory = options.directory ? `${names(options.directory).fileName}/${name}` : name;\n const projectName = projectDirectory.replace(new RegExp(\"/\", \"g\"), \"-\");\n const projectCamelcase = camelCase(projectName);\n const wsLayout = getWorkspaceLayout(tree);\n const projectRoot = `${wsLayout.libsDir}/${projectDirectory}`;\n const sourceRoot = `${wsLayout.libsDir}/${projectDirectory}/src`;\n const dependencyDefinitionFile = `${wsLayout.libsDir}/${projectDirectory}/package.json`;\n\n const npmScope = getNpmScope(tree);\n if (!npmScope) {\n throw new Error(\"Could not find npm scope in package.json\");\n }\n const importPath = `@${npmScope}/${projectName}`;\n\n return {\n ...options,\n projectName,\n projectRoot,\n projectDirectory,\n projectCamelcase,\n importPath,\n sourceRoot,\n dependencyDefinitionFile,\n };\n}\n\n/**\n * Ensures that jest.preset.js exists and includes the required @trackunit/react-test-setup preset.\n * If the file doesn't exist, creates it. If it exists but doesn't include the preset, updates it.\n */\nexport function ensureJestPresetConfiguration(tree: Tree, templateOptions?: object): void {\n const jestPresetPath = \"jest.preset.js\";\n\n if (!tree.exists(jestPresetPath)) {\n // File doesn't exist, generate it using the template\n generateFiles(tree, path.join(__dirname, \"files\", \"preset\"), \"/\", templateOptions || {});\n return;\n }\n\n // File exists, use AST utilities for reliable manipulation\n let currentContent = tree.read(jestPresetPath, \"utf-8\");\n if (!currentContent) {\n throw new Error(`Could not read ${jestPresetPath}`);\n }\n\n // Extract variable name from existing import if it exists\n let presetVariableName = \"irisPreset\"; // default name\n const existingImportMatch = currentContent.match(\n /const\\s+(\\w+)\\s*=\\s*require\\([\"']@trackunit\\/react-test-setup\\/preset[\"']\\)/\n );\n if (existingImportMatch && existingImportMatch[1]) {\n presetVariableName = existingImportMatch[1];\n }\n\n // Add the require statement if it doesn't exist\n currentContent = addRequireStatement(currentContent, presetVariableName, \"@trackunit/react-test-setup/preset\");\n\n // Add the spread assignment to the module.exports object\n currentContent = addSpreadAssignment(currentContent, presetVariableName);\n\n // Write the updated content back to the tree\n tree.write(jestPresetPath, currentContent);\n}\n\n/**\n * Iris App Extension Generator.\n *\n * @param tree the nx tree\n * @param options the generator options\n * @returns { Promise<void> } void\n */\nexport const IrisAppExtensionGenerator = async function (tree: Tree, options: IrisAppExtensionGeneratorSchema) {\n const adjustedOptions = await updateAppName(tree, options);\n\n const normalizedOptions = normalizeOptions(tree, adjustedOptions);\n\n const templateOptions = {\n ...normalizedOptions,\n ...names(normalizedOptions.name),\n offsetFromRoot: offsetFromRoot(normalizedOptions.projectRoot),\n template: \"\",\n };\n const irisAppExtensionType = normalizedOptions.type;\n\n if (normalizedOptions.graphql && irisAppExtensionType !== \"SERVERSIDE_API_EXTENSION\") {\n throw new Error(\"GraphQL setup is only supported for SERVERSIDE_API_EXTENSION\");\n }\n\n if (!tree.exists(`${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}`)) {\n throw new Error(\n `The app does not exist: ${getWorkspaceLayout(tree).appsDir}/${\n normalizedOptions.app\n } make sure you enter the right app name`\n );\n }\n\n const manifestPath = `${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}/iris-app-manifest.ts`;\n if (!tree.exists(manifestPath)) {\n throw new Error(\n `The app does not have an iris-app-manifest.ts: ${manifestPath} make sure you enter the right app name, which has an iris-app-manifest.ts`\n );\n }\n\n if (normalizedOptions.updatePackageJson) {\n addDependenciesToPackageJson(\n tree,\n {},\n {\n ...spaDependencies,\n ...testDependencies,\n }\n );\n }\n\n const schema: Schema = {\n name: normalizedOptions.projectName,\n style: \"none\",\n skipFormat: false,\n strict: true,\n // Nx 23 warns that \"jest\" emits the deprecated @nx/jest:jest target, but unlike\n // createSubgraph this generator has no jest.config/tsconfig.spec templates of its\n // own and updates the generated tsconfig.spec.json below. Switching to \"none\"\n // requires shipping those templates first.\n unitTestRunner: \"jest\",\n linter: Linter.EsLint,\n routing: false,\n directory: normalizedOptions.projectRoot,\n skipTsConfig: false,\n skipPackageJson: true,\n };\n\n await libraryGenerator(tree, schema);\n\n generateFiles(\n tree,\n path.join(__dirname, \"files\", irisAppExtensionType),\n normalizedOptions.projectRoot,\n templateOptions\n );\n\n if (!nonUiExtensionTypes.includes(irisAppExtensionType)) {\n generateFiles(tree, path.join(__dirname, \"files\", \"react-app\"), normalizedOptions.projectRoot, templateOptions);\n if (normalizedOptions.extendJestPreset) {\n ensureJestPresetConfiguration(tree, templateOptions);\n }\n }\n\n const rootTsConfigPath = getRootTsConfigPathInTree(tree);\n if (!rootTsConfigPath) {\n throw new Error(\"Could not find root tsconfig.json\");\n }\n updateJson(tree, rootTsConfigPath, tsConfigBase => {\n // For server side extension types, we need to add deno types to the tsconfig and make Typescript accept Deno import syntax\n if (serverSideExtensionTypes.includes(irisAppExtensionType)) {\n tsConfigBase.compilerOptions = {\n ...tsConfigBase.compilerOptions,\n types: [\"node\"],\n esModuleInterop: true,\n };\n }\n\n tsConfigBase.compilerOptions.paths[normalizedOptions.importPath] = [\n path.join(normalizedOptions.projectRoot, \"extension-manifest.ts\"),\n ];\n return tsConfigBase;\n });\n\n // Add working serve target to the project.json for DENO extensions\n if (serverSideExtensionTypes.includes(irisAppExtensionType)) {\n updateJson(tree, joinPathFragments(normalizedOptions.projectRoot, \"project.json\"), projectJson => {\n projectJson.targets.serve = {\n executor: \"@nx/js:node\",\n options: {\n buildTarget: `${normalizedOptions.projectName}:build:development`,\n inspect: true,\n },\n configurations: {\n breakOnStart: {\n inspect: \"inspect-brk\",\n },\n },\n };\n projectJson.targets.build = {\n executor: \"@nx/esbuild:esbuild\",\n outputs: [\"{options.outputPath}\"],\n defaultConfiguration: \"production\",\n options: {\n platform: \"node\",\n outputPath: `dist/${normalizedOptions.projectRoot}`,\n format: [\"cjs\"],\n bundle: true,\n thirdParty: true,\n external: [],\n main: `${normalizedOptions.sourceRoot}/index.ts`,\n tsConfig: `libs/${normalizedOptions.projectDirectory}/tsconfig.lib.json`,\n esbuildOptions: {\n sourcemap: true,\n outExtension: {\n \".js\": \".js\",\n },\n },\n },\n configurations: {\n development: {\n main: `${normalizedOptions.sourceRoot}/local-serve.ts`,\n },\n production: {\n esbuildOptions: {\n sourcemap: false,\n outExtension: {\n \".js\": \".js\",\n },\n },\n },\n },\n };\n return projectJson;\n });\n }\n\n if (normalizedOptions.graphql) {\n await addServersideGraphql(tree, {\n projectName: normalizedOptions.projectName,\n projectRoot: normalizedOptions.projectRoot,\n className: names(normalizedOptions.name).className,\n serversideUtilsVersion: await getPackageVersion(\"@trackunit/serverside-utils\"),\n });\n }\n\n //TODO: Change the following to update the manifest in the virtual Tree - not on the file system.\n const project = new Project({\n tsConfigFilePath: `${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}/tsconfig.app.json`,\n });\n\n const manifest = project.getSourceFileOrThrow(manifestPath);\n\n manifest.addImportDeclaration({\n moduleSpecifier: normalizedOptions.importPath,\n defaultImport: normalizedOptions.projectCamelcase,\n });\n\n // Get the default export symbol from the manifest\n const defaultExportSymbol = manifest.getDefaultExportSymbolOrThrow();\n\n // Get the aliased symbol if the default export is an alias\n const aliasedSymbol = defaultExportSymbol.getAliasedSymbol() || defaultExportSymbol;\n\n // Get the declaration of the aliased symbol\n const declaration = aliasedSymbol.getDeclarations()[0];\n\n if (!VariableDeclaration.isVariableDeclaration(declaration)) {\n throw new Error(\"Expected variable declaration\");\n }\n const irisAppManifestObject = declaration.getInitializer()?.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n if (!irisAppManifestObject) {\n throw new Error(`irisAppManifest not exported from the file: ${manifestPath}`);\n }\n // Find the extensions property within the irisAppManifest object\n const extensionsProperty = irisAppManifestObject.getPropertyOrThrow(\"extensions\");\n\n if (extensionsProperty.getKind() === SyntaxKind.PropertyAssignment) {\n const extensionsArray = extensionsProperty.getFirstChildByKindOrThrow(SyntaxKind.ArrayLiteralExpression);\n extensionsArray.addElement(`${normalizedOptions.projectCamelcase}`);\n }\n\n await manifest.save();\n\n if (!serverSideExtensionTypes.includes(irisAppExtensionType)) {\n tree.delete(joinPathFragments(normalizedOptions.projectRoot, \"src\", \"index.ts\"));\n }\n\n updateJson(tree, joinPathFragments(normalizedOptions.projectRoot, \"tsconfig.spec.json\"), tsConfigSpec => {\n // extension-manifest.ts is a build time file, so we only need to include it in the spec file for type/lint checking\n tsConfigSpec.include = [...tsConfigSpec.include, \"**/jest.setup.ts*\", \"extension-manifest.ts\"];\n return tsConfigSpec;\n });\n\n await formatFiles(tree);\n installPackagesTask(tree, true);\n return () => {\n // eslint-disable-next-line no-console\n console.log(\"🥳 Successfully created an app extensions and it is already added to the Iris App!\");\n };\n};\nconst updateAppName = async (tree: Tree, options: IrisAppExtensionGeneratorSchema) => {\n if (!options.app) {\n const folders = fs\n .readdirSync(getWorkspaceLayout(tree).appsDir, { withFileTypes: true })\n .filter(item => item.isDirectory());\n\n const tileApps: Array<string> = [];\n\n folders.forEach(folder => {\n const irisAppManifest = fs\n .readdirSync(`${getWorkspaceLayout(tree).appsDir}/${folder.name}`, { withFileTypes: true })\n .find(item => item.name === \"iris-app-manifest.ts\");\n\n if (irisAppManifest) {\n tileApps.push(folder.name);\n } else {\n const subFolders = fs\n .readdirSync(path.join(getWorkspaceLayout(tree).appsDir, folder.name), { withFileTypes: true })\n .filter(item => item.isDirectory());\n subFolders.forEach(subFolder => {\n const subDirIrisAppManifest = fs\n .readdirSync(`${getWorkspaceLayout(tree).appsDir}/${folder.name}/${subFolder.name}`, {\n withFileTypes: true,\n })\n .find(item => item.name === \"iris-app-manifest.ts\");\n\n if (subDirIrisAppManifest) {\n tileApps.push(path.join(folder.name, subFolder.name));\n }\n });\n }\n });\n\n if (tileApps.length === 1) {\n options.app = tileApps[0] || \"<Missing iris app name>\";\n } else if (tileApps.length === 0) {\n throw new Error(\"Please add an iris-app using: nx g @trackunit/iris-app:create \");\n } else {\n // Dynamic import to avoid loading ESM module at test time when not needed\n const { autocomplete, isCancel, cancel } = await import(\"@clack/prompts\");\n\n const selectedApp = await autocomplete({\n message: \"Select the iris app that this extension should belong to (type to filter):\",\n options: tileApps.map(item => ({ value: item, label: item })),\n maxItems: 15,\n });\n\n if (isCancel(selectedApp)) {\n cancel(\"Operation cancelled.\");\n process.exit(0);\n }\n\n options.app = selectedApp;\n }\n }\n return options;\n};\n"]}
|
|
@@ -64,6 +64,11 @@
|
|
|
64
64
|
"type": "boolean",
|
|
65
65
|
"description": "If the root jest.preset.js should be extended with the Iris app preset",
|
|
66
66
|
"default": true
|
|
67
|
+
},
|
|
68
|
+
"graphql": {
|
|
69
|
+
"type": "boolean",
|
|
70
|
+
"description": "Add typed Trackunit public GraphQL support (SERVERSIDE_API_EXTENSION only)",
|
|
71
|
+
"default": false
|
|
67
72
|
}
|
|
68
73
|
},
|
|
69
74
|
"required": ["name", "directory", "type"]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPackageManifest = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pacote = tslib_1.__importStar(require("pacote"));
|
|
6
|
+
/**
|
|
7
|
+
* Keeps Trackunit registry overrides consistent across package-consuming generators.
|
|
8
|
+
*/
|
|
9
|
+
const getPackageManifest = (packageName) => pacote.manifest(packageName, process.env.TU_NPM_REGISTRY ? { registry: process.env.TU_NPM_REGISTRY } : undefined);
|
|
10
|
+
exports.getPackageManifest = getPackageManifest;
|
|
11
|
+
//# sourceMappingURL=get-package-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-package-manifest.js","sourceRoot":"","sources":["../../../../../../../libs/iris-app-sdk/iris-app/src/generators/utils/get-package-manifest.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AAEjC;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAAC,WAAmB,EAAE,EAAE,CACxD,MAAM,CAAC,QAAQ,CACb,WAAW,EACX,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,SAAS,CACpF,CAAC;AAJS,QAAA,kBAAkB,sBAI3B","sourcesContent":["import * as pacote from \"pacote\";\n\n/**\n * Keeps Trackunit registry overrides consistent across package-consuming generators.\n */\nexport const getPackageManifest = (packageName: string) =>\n pacote.manifest(\n packageName,\n process.env.TU_NPM_REGISTRY ? { registry: process.env.TU_NPM_REGISTRY } : undefined\n );\n"]}
|