@webiny/project 0.0.0-unstable.e2758ee1cf → 0.0.0-unstable.e6f0dc8ca7
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/abstractions/features/DeployApp.d.ts +0 -1
- package/abstractions/features/DeployApp.js.map +1 -1
- package/abstractions/features/index.d.ts +0 -1
- package/abstractions/features/index.js +0 -1
- package/abstractions/features/index.js.map +1 -1
- package/defineExtension/models/ExtensionDefinitionModel.d.ts +4 -4
- package/defineExtension/models/ExtensionDefinitionModel.js.map +1 -1
- package/defineExtension/models/ExtensionInstanceModel.js +4 -1
- package/defineExtension/models/ExtensionInstanceModel.js.map +1 -1
- package/defineExtension/zodTypes/zodSrcPath.d.ts +1 -1
- package/defineExtension/zodTypes/zodSrcPath.js +11 -0
- package/defineExtension/zodTypes/zodSrcPath.js.map +1 -1
- package/exports/infra/admin.d.ts +0 -1
- package/exports/infra/admin.js +0 -1
- package/exports/infra/admin.js.map +1 -1
- package/exports/infra/api.d.ts +0 -1
- package/exports/infra/api.js +0 -1
- package/exports/infra/api.js.map +1 -1
- package/exports/infra/core.d.ts +0 -1
- package/exports/infra/core.js +0 -1
- package/exports/infra/core.js.map +1 -1
- package/exports/infra.d.ts +8 -0
- package/exports/infra.js +10 -0
- package/exports/{infra/index.js.map → infra.js.map} +1 -1
- package/extensions/AdminBuildParam.d.ts +2 -8
- package/extensions/AdminBuildParam.js +1 -1
- package/extensions/AdminBuildParam.js.map +1 -1
- package/extensions/AdminExtension.d.ts +2 -8
- package/extensions/ApiBuildParam.d.ts +2 -8
- package/extensions/ApiBuildParam.js +4 -4
- package/extensions/ApiBuildParam.js.map +1 -1
- package/extensions/ApiExtension.d.ts +2 -8
- package/extensions/ApiExtension.js +5 -5
- package/extensions/ApiExtension.js.map +1 -1
- package/extensions/DatabaseSetup.d.ts +7 -7
- package/extensions/EnvVar.d.ts +4 -7
- package/extensions/EnvVar.js +4 -0
- package/extensions/EnvVar.js.map +1 -1
- package/extensions/ExtensionDefinitions.d.ts +1 -5
- package/extensions/FeatureFlags.d.ts +17 -79
- package/extensions/FeatureFlags.js +12 -0
- package/extensions/FeatureFlags.js.map +1 -1
- package/extensions/Project/EnsureTelemetryEnabledForOss.js +1 -1
- package/extensions/Project/EnsureTelemetryEnabledForOss.js.map +1 -1
- package/extensions/Project/SetAdminAppEnvVarsBeforeBuild.js +1 -0
- package/extensions/Project/SetAdminAppEnvVarsBeforeBuild.js.map +1 -1
- package/extensions/Project/SetAdminAppEnvVarsBeforeWatch.js +1 -0
- package/extensions/Project/SetAdminAppEnvVarsBeforeWatch.js.map +1 -1
- package/extensions/Project/ValidateEncryptionBeforeDeploy.d.ts +12 -0
- package/extensions/Project/ValidateEncryptionBeforeDeploy.js +32 -0
- package/extensions/Project/ValidateEncryptionBeforeDeploy.js.map +1 -0
- package/extensions/Project.js +2 -0
- package/extensions/Project.js.map +1 -1
- package/extensions/ProjectDecorator.d.ts +3 -7
- package/extensions/ProjectId.d.ts +3 -7
- package/extensions/ProjectId.js +1 -1
- package/extensions/ProjectId.js.map +1 -1
- package/extensions/ProjectImplementation.d.ts +3 -9
- package/extensions/Telemetry.d.ts +2 -6
- package/extensions/hooks/AdminAfterBuild.d.ts +2 -6
- package/extensions/hooks/AdminAfterDeploy.d.ts +2 -6
- package/extensions/hooks/AdminBeforeBuild.d.ts +2 -6
- package/extensions/hooks/AdminBeforeDeploy.d.ts +2 -6
- package/extensions/hooks/AdminBeforeWatch.d.ts +2 -6
- package/extensions/hooks/AfterBuild.d.ts +2 -6
- package/extensions/hooks/AfterDeploy.d.ts +2 -6
- package/extensions/hooks/ApiAfterBuild.d.ts +2 -6
- package/extensions/hooks/ApiAfterDeploy.d.ts +2 -6
- package/extensions/hooks/ApiBeforeBuild.d.ts +2 -6
- package/extensions/hooks/ApiBeforeDeploy.d.ts +2 -6
- package/extensions/hooks/ApiBeforeWatch.d.ts +2 -6
- package/extensions/hooks/BeforeBuild.d.ts +2 -6
- package/extensions/hooks/BeforeDeploy.d.ts +2 -6
- package/extensions/hooks/BeforeWatch.d.ts +2 -6
- package/extensions/hooks/CoreAfterBuild.d.ts +2 -6
- package/extensions/hooks/CoreAfterDeploy.d.ts +2 -6
- package/extensions/hooks/CoreBeforeBuild.d.ts +2 -6
- package/extensions/hooks/CoreBeforeDeploy.d.ts +2 -6
- package/extensions/hooks/CoreBeforeWatch.d.ts +2 -6
- package/extensions/index.d.ts +38 -145
- package/extensions/index.js +5 -8
- package/extensions/index.js.map +1 -1
- package/extensions/infra/Ci.d.ts +14 -0
- package/extensions/infra/Ci.js +29 -0
- package/extensions/infra/Ci.js.map +1 -0
- package/extensions/infra/Env.d.ts +6 -0
- package/extensions/infra/Env.js +21 -0
- package/extensions/infra/Env.js.map +1 -1
- package/extensions/infra/index.d.ts +1 -0
- package/extensions/infra/index.js +1 -0
- package/extensions/infra/index.js.map +1 -1
- package/extensions/pulumi/AdminStackOutputValue.d.ts +1 -7
- package/extensions/pulumi/ApiStackOutputValue.d.ts +1 -7
- package/extensions/pulumi/CoreStackOutputValue.d.ts +1 -7
- package/extensions/pulumi/ProductionEnvironments.d.ts +2 -6
- package/extensions/pulumi/ProductionEnvironments.js +16 -1
- package/extensions/pulumi/ProductionEnvironments.js.map +1 -1
- package/extensions/pulumi/PulumiResourceNamePrefix.d.ts +1 -5
- package/extensions/pulumi/index.d.ts +0 -3
- package/extensions/pulumi/index.js +0 -3
- package/extensions/pulumi/index.js.map +1 -1
- package/features/BuildApp/PackagesBuilder/worker.js +1 -1
- package/features/BuildApp/PackagesBuilder/worker.js.map +1 -1
- package/features/GetFeatureFlags/GetFeatureFlags.d.ts +1 -2
- package/features/GetFeatureFlags/GetFeatureFlags.js +1 -2
- package/features/GetFeatureFlags/GetFeatureFlags.js.map +1 -1
- package/features/Watch/initInvocationForwarding.d.ts +1 -1
- package/features/Watch/initInvocationForwarding.js +1 -1
- package/features/Watch/initInvocationForwarding.js.map +1 -1
- package/features/Watch/localInvocationWorker.js +5 -1
- package/features/Watch/localInvocationWorker.js.map +1 -1
- package/features/index.d.ts +0 -1
- package/features/index.js +0 -1
- package/features/index.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +38 -39
- package/services/BuildAppWorkspaceService/BuildAppWorkspaceService.js +4 -4
- package/services/BuildAppWorkspaceService/BuildAppWorkspaceService.js.map +1 -1
- package/services/GetProjectConfigService/GetProjectConfigService.js +2 -1
- package/services/GetProjectConfigService/GetProjectConfigService.js.map +1 -1
- package/services/GetProjectConfigService/ProductionEnvironmentsContext.d.ts +6 -0
- package/services/GetProjectConfigService/ProductionEnvironmentsContext.js +21 -0
- package/services/GetProjectConfigService/ProductionEnvironmentsContext.js.map +1 -0
- package/services/GetProjectConfigService/renderConfigWorker.js +14 -4
- package/services/GetProjectConfigService/renderConfigWorker.js.map +1 -1
- package/services/GetProjectIdService/GetProjectIdService.js +1 -1
- package/services/GetProjectIdService/GetProjectIdService.js.map +1 -1
- package/services/GetProjectService/GetProjectService.js +2 -2
- package/services/GetProjectService/GetProjectService.js.map +1 -1
- package/services/GetProjectVersionService/GetProjectVersionService.js +4 -4
- package/services/GetProjectVersionService/GetProjectVersionService.js.map +1 -1
- package/services/InitProjectSdkService/InitProjectSdkService.js +0 -6
- package/services/InitProjectSdkService/InitProjectSdkService.js.map +1 -1
- package/services/InitProjectSdkService/applyWcpEnvVars.js +10 -8
- package/services/InitProjectSdkService/applyWcpEnvVars.js.map +1 -1
- package/services/InitProjectSdkService/registerPulumiExtensions.js +5 -3
- package/services/InitProjectSdkService/registerPulumiExtensions.js.map +1 -1
- package/services/InstallExtensionService/downloadFolderFromS3.js +33 -42
- package/services/InstallExtensionService/downloadFolderFromS3.js.map +1 -1
- package/services/InstallExtensionService/types.d.ts +4 -0
- package/services/InstallExtensionService/types.js.map +1 -1
- package/services/InstallExtensionService/updateWebinyConfig.js +74 -47
- package/services/InstallExtensionService/updateWebinyConfig.js.map +1 -1
- package/services/ListPackagesService/ListPackagesService.js +1 -1
- package/services/ListPackagesService/ListPackagesService.js.map +1 -1
- package/services/ProjectInfoService/ProjectInfoService.js +3 -3
- package/services/ProjectInfoService/ProjectInfoService.js.map +1 -1
- package/utils/ExtensionSrcResolver.js +2 -1
- package/utils/ExtensionSrcResolver.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/index.js.map +1 -1
- package/utils/requireConfig.js +9 -5
- package/utils/requireConfig.js.map +1 -1
- package/utils/toImportSpecifier.d.ts +5 -0
- package/utils/toImportSpecifier.js +12 -0
- package/utils/toImportSpecifier.js.map +1 -0
- package/abstractions/features/pulumi/AdminPulumi.d.ts +0 -8
- package/abstractions/features/pulumi/AdminPulumi.js +0 -4
- package/abstractions/features/pulumi/AdminPulumi.js.map +0 -1
- package/abstractions/features/pulumi/ApiPulumi.d.ts +0 -8
- package/abstractions/features/pulumi/ApiPulumi.js +0 -4
- package/abstractions/features/pulumi/ApiPulumi.js.map +0 -1
- package/abstractions/features/pulumi/CorePulumi.d.ts +0 -8
- package/abstractions/features/pulumi/CorePulumi.js +0 -4
- package/abstractions/features/pulumi/CorePulumi.js.map +0 -1
- package/abstractions/features/pulumi/index.d.ts +0 -3
- package/abstractions/features/pulumi/index.js +0 -5
- package/abstractions/features/pulumi/index.js.map +0 -1
- package/exports/infra/index.d.ts +0 -8
- package/exports/infra/index.js +0 -10
- package/extensions/pulumi/AdminPulumi.d.ts +0 -8
- package/extensions/pulumi/AdminPulumi.js +0 -25
- package/extensions/pulumi/AdminPulumi.js.map +0 -1
- package/extensions/pulumi/ApiPulumi.d.ts +0 -8
- package/extensions/pulumi/ApiPulumi.js +0 -25
- package/extensions/pulumi/ApiPulumi.js.map +0 -1
- package/extensions/pulumi/CorePulumi.d.ts +0 -8
- package/extensions/pulumi/CorePulumi.js +0 -25
- package/extensions/pulumi/CorePulumi.js.map +0 -1
- package/features/BuildApp/PackagesBuilder/utils/requireConfig.d.ts +0 -18
- package/features/BuildApp/PackagesBuilder/utils/requireConfig.js +0 -15
- package/features/BuildApp/PackagesBuilder/utils/requireConfig.js.map +0 -1
- package/features/Watch/watchers/utils/requireConfig.d.ts +0 -18
- package/features/Watch/watchers/utils/requireConfig.js +0 -15
- package/features/Watch/watchers/utils/requireConfig.js.map +0 -1
- package/features/pulumi/AdminPulumi/AdminPulumi.d.ts +0 -7
- package/features/pulumi/AdminPulumi/AdminPulumi.js +0 -21
- package/features/pulumi/AdminPulumi/AdminPulumi.js.map +0 -1
- package/features/pulumi/AdminPulumi/index.d.ts +0 -1
- package/features/pulumi/AdminPulumi/index.js +0 -3
- package/features/pulumi/AdminPulumi/index.js.map +0 -1
- package/features/pulumi/ApiPulumi/ApiPulumi.d.ts +0 -7
- package/features/pulumi/ApiPulumi/ApiPulumi.js +0 -21
- package/features/pulumi/ApiPulumi/ApiPulumi.js.map +0 -1
- package/features/pulumi/ApiPulumi/index.d.ts +0 -1
- package/features/pulumi/ApiPulumi/index.js +0 -3
- package/features/pulumi/ApiPulumi/index.js.map +0 -1
- package/features/pulumi/CorePulumi/CorePulumi.d.ts +0 -7
- package/features/pulumi/CorePulumi/CorePulumi.js +0 -21
- package/features/pulumi/CorePulumi/CorePulumi.js.map +0 -1
- package/features/pulumi/CorePulumi/index.d.ts +0 -1
- package/features/pulumi/CorePulumi/index.js +0 -3
- package/features/pulumi/CorePulumi/index.js.map +0 -1
- package/features/pulumi/index.d.ts +0 -3
- package/features/pulumi/index.js +0 -5
- package/features/pulumi/index.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { S3Client, ListObjectsV2Command, GetObjectCommand } from "@webiny/aws-sdk/client-s3/index.js";
|
|
2
1
|
import fs from "fs";
|
|
3
2
|
import path from "path";
|
|
4
3
|
export class NoObjectsFoundError extends Error {
|
|
@@ -15,65 +14,57 @@ export const downloadFolderFromS3 = async params => {
|
|
|
15
14
|
bucketFolderKey,
|
|
16
15
|
downloadFolderPath
|
|
17
16
|
} = params;
|
|
18
|
-
|
|
19
|
-
// Prepend v6/ to the folder key
|
|
20
17
|
const s3FolderKey = `v6/${bucketFolderKey}`;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
const baseUrl = `https://${bucketName}.s3.${bucketRegion}.amazonaws.com`;
|
|
19
|
+
const listObjects = async () => {
|
|
20
|
+
const keys = [];
|
|
21
|
+
let continuationToken;
|
|
22
|
+
do {
|
|
23
|
+
let url = `${baseUrl}/?list-type=2&prefix=${encodeURIComponent(s3FolderKey)}`;
|
|
24
|
+
if (continuationToken) {
|
|
25
|
+
url += `&continuation-token=${encodeURIComponent(continuationToken)}`;
|
|
26
|
+
}
|
|
27
|
+
const response = await fetch(url);
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error(`Failed to list objects: ${response.status} ${response.statusText}`);
|
|
30
|
+
}
|
|
31
|
+
const xml = await response.text();
|
|
32
|
+
for (const match of xml.matchAll(/<Key>([^<]+)<\/Key>/g)) {
|
|
33
|
+
keys.push(match[1]);
|
|
34
|
+
}
|
|
35
|
+
const isTruncated = xml.includes("<IsTruncated>true</IsTruncated>");
|
|
36
|
+
continuationToken = isTruncated ? xml.match(/<NextContinuationToken>([^<]+)<\/NextContinuationToken>/)?.[1] : undefined;
|
|
37
|
+
} while (continuationToken);
|
|
38
|
+
return keys;
|
|
35
39
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
const response = await s3Client.send(command);
|
|
44
|
-
return new Promise((resolve, reject) => {
|
|
45
|
-
const fileStream = fs.createWriteStream(localPath);
|
|
46
|
-
// @ts-expect-error Body is a stream
|
|
47
|
-
response.Body.pipe(fileStream);
|
|
48
|
-
// @ts-expect-error Body is a stream
|
|
49
|
-
response.Body.on("error", reject);
|
|
50
|
-
fileStream.on("finish", () => resolve());
|
|
51
|
-
});
|
|
40
|
+
const downloadFile = async (key, localPath) => {
|
|
41
|
+
const response = await fetch(`${baseUrl}/${key}`);
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`Failed to download ${key}: ${response.status} ${response.statusText}`);
|
|
44
|
+
}
|
|
45
|
+
fs.writeFileSync(localPath, Buffer.from(await response.arrayBuffer()));
|
|
52
46
|
};
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
47
|
+
const keys = await listObjects();
|
|
48
|
+
if (!keys.length) {
|
|
55
49
|
throw new NoObjectsFoundError(`No objects found in the specified S3 folder.`);
|
|
56
50
|
}
|
|
57
|
-
for (const
|
|
58
|
-
const
|
|
59
|
-
const relativePath = path.relative(s3FolderKey, s3Key);
|
|
51
|
+
for (const key of keys) {
|
|
52
|
+
const relativePath = path.relative(s3FolderKey, key);
|
|
60
53
|
const localFilePath = path.join(downloadFolderPath, relativePath);
|
|
61
|
-
if (
|
|
62
|
-
// It's a directory, create it if it doesn't exist.
|
|
54
|
+
if (key.endsWith("/")) {
|
|
63
55
|
if (!fs.existsSync(localFilePath)) {
|
|
64
56
|
fs.mkdirSync(localFilePath, {
|
|
65
57
|
recursive: true
|
|
66
58
|
});
|
|
67
59
|
}
|
|
68
60
|
} else {
|
|
69
|
-
// It's a file, download it.
|
|
70
61
|
const localDirPath = path.dirname(localFilePath);
|
|
71
62
|
if (!fs.existsSync(localDirPath)) {
|
|
72
63
|
fs.mkdirSync(localDirPath, {
|
|
73
64
|
recursive: true
|
|
74
65
|
});
|
|
75
66
|
}
|
|
76
|
-
await downloadFile(
|
|
67
|
+
await downloadFile(key, localFilePath);
|
|
77
68
|
}
|
|
78
69
|
}
|
|
79
70
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["fs","path","NoObjectsFoundError","Error","code","constructor","message","name","downloadFolderFromS3","params","bucketName","bucketRegion","bucketFolderKey","downloadFolderPath","s3FolderKey","baseUrl","listObjects","keys","continuationToken","url","encodeURIComponent","response","fetch","ok","status","statusText","xml","text","match","matchAll","push","isTruncated","includes","undefined","downloadFile","key","localPath","writeFileSync","Buffer","from","arrayBuffer","length","relativePath","relative","localFilePath","join","endsWith","existsSync","mkdirSync","recursive","localDirPath","dirname"],"sources":["downloadFolderFromS3.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\ninterface DownloadFolderFromS3Params {\n bucketName: string;\n bucketRegion: string;\n bucketFolderKey: string;\n downloadFolderPath: string;\n}\n\nexport class NoObjectsFoundError extends Error {\n code = \"NO_OBJECTS_FOUND\";\n constructor(message: string) {\n super(message);\n this.name = \"NoObjectsFoundError\";\n }\n}\n\nexport const downloadFolderFromS3 = async (params: DownloadFolderFromS3Params) => {\n const { bucketName, bucketRegion, bucketFolderKey, downloadFolderPath } = params;\n\n const s3FolderKey = `v6/${bucketFolderKey}`;\n const baseUrl = `https://${bucketName}.s3.${bucketRegion}.amazonaws.com`;\n\n const listObjects = async (): Promise<string[]> => {\n const keys: string[] = [];\n let continuationToken: string | undefined;\n\n do {\n let url = `${baseUrl}/?list-type=2&prefix=${encodeURIComponent(s3FolderKey)}`;\n if (continuationToken) {\n url += `&continuation-token=${encodeURIComponent(continuationToken)}`;\n }\n\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(\n `Failed to list objects: ${response.status} ${response.statusText}`\n );\n }\n\n const xml = await response.text();\n\n for (const match of xml.matchAll(/<Key>([^<]+)<\\/Key>/g)) {\n keys.push(match[1]);\n }\n\n const isTruncated = xml.includes(\"<IsTruncated>true</IsTruncated>\");\n continuationToken = isTruncated\n ? xml.match(/<NextContinuationToken>([^<]+)<\\/NextContinuationToken>/)?.[1]\n : undefined;\n } while (continuationToken);\n\n return keys;\n };\n\n const downloadFile = async (key: string, localPath: string): Promise<void> => {\n const response = await fetch(`${baseUrl}/${key}`);\n if (!response.ok) {\n throw new Error(`Failed to download ${key}: ${response.status} ${response.statusText}`);\n }\n fs.writeFileSync(localPath, Buffer.from(await response.arrayBuffer()));\n };\n\n const keys = await listObjects();\n if (!keys.length) {\n throw new NoObjectsFoundError(`No objects found in the specified S3 folder.`);\n }\n\n for (const key of keys) {\n const relativePath = path.relative(s3FolderKey, key);\n const localFilePath = path.join(downloadFolderPath, relativePath);\n\n if (key.endsWith(\"/\")) {\n if (!fs.existsSync(localFilePath)) {\n fs.mkdirSync(localFilePath, { recursive: true });\n }\n } else {\n const localDirPath = path.dirname(localFilePath);\n if (!fs.existsSync(localDirPath)) {\n fs.mkdirSync(localDirPath, { recursive: true });\n }\n await downloadFile(key, localFilePath);\n }\n }\n};\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AASvB,OAAO,MAAMC,mBAAmB,SAASC,KAAK,CAAC;EAC3CC,IAAI,GAAG,kBAAkB;EACzBC,WAAWA,CAACC,OAAe,EAAE;IACzB,KAAK,CAACA,OAAO,CAAC;IACd,IAAI,CAACC,IAAI,GAAG,qBAAqB;EACrC;AACJ;AAEA,OAAO,MAAMC,oBAAoB,GAAG,MAAOC,MAAkC,IAAK;EAC9E,MAAM;IAAEC,UAAU;IAAEC,YAAY;IAAEC,eAAe;IAAEC;EAAmB,CAAC,GAAGJ,MAAM;EAEhF,MAAMK,WAAW,GAAG,MAAMF,eAAe,EAAE;EAC3C,MAAMG,OAAO,GAAG,WAAWL,UAAU,OAAOC,YAAY,gBAAgB;EAExE,MAAMK,WAAW,GAAG,MAAAA,CAAA,KAA+B;IAC/C,MAAMC,IAAc,GAAG,EAAE;IACzB,IAAIC,iBAAqC;IAEzC,GAAG;MACC,IAAIC,GAAG,GAAG,GAAGJ,OAAO,wBAAwBK,kBAAkB,CAACN,WAAW,CAAC,EAAE;MAC7E,IAAII,iBAAiB,EAAE;QACnBC,GAAG,IAAI,uBAAuBC,kB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IACd,MAAM,IAAIvC,mBAAmB,CAAC,8CAA8C,CAAC;EACjF;EAEA,KAAK,MAAMiC,GAAG,IAAIlB,IAAI,EAAE;IACpB,MAAMyB,YAAY,GAAGzC,IAAI,CAAC0C,QAAQ,CAAC7B,WAAW,EAAEqB,GAAG,CAAC;IACpD,MAAMS,aAAa,GAAG3C,IAAI,CAAC4C,IAAI,CAAChC,kBAAkB,EAAE6B,YAAY,CAAC;IAEjE,IAAIP,GAAG,CAACW,QAAQ,CAAC,GAAG,CAAC,EAAE;MACnB,IAAI,CAAC9C,EAAE,CAAC+C,UAAU,CAACH,aAAa,CAAC,EAAE;QAC/B5C,EAAE,CAACgD,SAAS,CAACJ,aAAa,EAAE;UAAEK,SAAS,EAAE;QAAK,CAAC,CAAC;MACpD;IACJ,CAAC,MAAM;MACH,MAAMC,YAAY,GAAGjD,IAAI,CAACkD,OAAO,CAACP,aAAa,CAAC;MAChD,IAAI,CAAC5C,EAAE,CAAC+C,UAAU,CAACG,YAAY,CAAC,EAAE;QAC9BlD,EAAE,CAACgD,SAAS,CAACE,YAAY,EAAE;UAAED,SAAS,EAAE;QAAK,CAAC,CAAC;MACnD;MACA,MAAMf,YAAY,CAACC,GAAG,EAAES,aAAa,CAAC;IAC1C;EACJ;AACJ,CAAC","ignoreList":[]}
|
|
@@ -38,6 +38,10 @@ export interface ExtensionWebinyConfigTsx {
|
|
|
38
38
|
* Component to render in the Extensions component.
|
|
39
39
|
*/
|
|
40
40
|
component?: ExtensionComponent;
|
|
41
|
+
/**
|
|
42
|
+
* Multiple components to render in the Extensions component.
|
|
43
|
+
*/
|
|
44
|
+
components?: ExtensionComponent[];
|
|
41
45
|
}
|
|
42
46
|
export interface ExtensionImport {
|
|
43
47
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/**\n * Schema for Webiny extension.json configuration files.\n * Based on: https://github.com/webiny/extensions/blob/main/schemas/extension.schema.json\n */\nexport interface ExtensionJson {\n $schema?: string;\n /**\n * The unique name of the extension.\n */\n name: string;\n /**\n * The type of extension.\n */\n type: \"admin\" | \"api\" | \"cli\" | \"infra\";\n /**\n * Configuration for how this extension integrates with webiny.config.tsx.\n */\n webinyConfigTsx?: ExtensionWebinyConfigTsx;\n /**\n * Next steps to display after installation (legacy support).\n */\n nextSteps?: ExtensionMessagesConfig;\n /**\n * Additional notes and messages for the extension.\n */\n additionalNotes?: ExtensionMessagesConfig;\n /**\n * Additional package.json properties to merge.\n */\n packageJson?: Record<string, any>;\n}\n\nexport interface ExtensionWebinyConfigTsx {\n /**\n * Array of imports to add to the user's webiny.config.tsx.\n */\n imports?: ExtensionImport[];\n /**\n * Component to render in the Extensions component.\n */\n component?: ExtensionComponent;\n}\n\nexport interface ExtensionImport {\n /**\n * The named import specifier (e.g., 'AdminLogo').\n */\n specifier: string;\n /**\n * The relative path to import from (e.g., './extensions/AdminLogo/AdminLogo.js').\n */\n path: string;\n}\n\nexport interface ExtensionComponent {\n /**\n * The component name to render (should match one of the imported specifiers).\n */\n name: string;\n /**\n * Props to pass to the component (optional).\n */\n props?: Record<string, any>;\n}\n\nexport interface ExtensionMessage {\n /**\n * Message text (can include %s placeholders for variables).\n */\n text: string;\n /**\n * Variables to substitute into the message text.\n */\n variables?: string[];\n}\n\nexport interface ExtensionMessagesConfig {\n /**\n * Array of messages to display to users.\n */\n messages?: ExtensionMessage[];\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/**\n * Schema for Webiny extension.json configuration files.\n * Based on: https://github.com/webiny/extensions/blob/main/schemas/extension.schema.json\n */\nexport interface ExtensionJson {\n $schema?: string;\n /**\n * The unique name of the extension.\n */\n name: string;\n /**\n * The type of extension.\n */\n type: \"admin\" | \"api\" | \"cli\" | \"infra\";\n /**\n * Configuration for how this extension integrates with webiny.config.tsx.\n */\n webinyConfigTsx?: ExtensionWebinyConfigTsx;\n /**\n * Next steps to display after installation (legacy support).\n */\n nextSteps?: ExtensionMessagesConfig;\n /**\n * Additional notes and messages for the extension.\n */\n additionalNotes?: ExtensionMessagesConfig;\n /**\n * Additional package.json properties to merge.\n */\n packageJson?: Record<string, any>;\n}\n\nexport interface ExtensionWebinyConfigTsx {\n /**\n * Array of imports to add to the user's webiny.config.tsx.\n */\n imports?: ExtensionImport[];\n /**\n * Component to render in the Extensions component.\n */\n component?: ExtensionComponent;\n /**\n * Multiple components to render in the Extensions component.\n */\n components?: ExtensionComponent[];\n}\n\nexport interface ExtensionImport {\n /**\n * The named import specifier (e.g., 'AdminLogo').\n */\n specifier: string;\n /**\n * The relative path to import from (e.g., './extensions/AdminLogo/AdminLogo.js').\n */\n path: string;\n}\n\nexport interface ExtensionComponent {\n /**\n * The component name to render (should match one of the imported specifiers).\n */\n name: string;\n /**\n * Props to pass to the component (optional).\n */\n props?: Record<string, any>;\n}\n\nexport interface ExtensionMessage {\n /**\n * Message text (can include %s placeholders for variables).\n */\n text: string;\n /**\n * Variables to substitute into the message text.\n */\n variables?: string[];\n}\n\nexport interface ExtensionMessagesConfig {\n /**\n * Array of messages to display to users.\n */\n messages?: ExtensionMessage[];\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -10,27 +10,27 @@ import fs from "fs";
|
|
|
10
10
|
const serializePropsToJsx = props => {
|
|
11
11
|
const attributes = [];
|
|
12
12
|
for (const [key, value] of Object.entries(props)) {
|
|
13
|
-
// Skip undefined values
|
|
13
|
+
// Skip undefined values.
|
|
14
14
|
if (value === undefined) {
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
// Determine the serialization based on value type
|
|
18
|
+
// Determine the serialization based on value type.
|
|
19
19
|
let serializedValue;
|
|
20
20
|
if (typeof value === "string") {
|
|
21
|
-
// Strings: use JSON.stringify to handle escaping, then wrap in curly braces
|
|
21
|
+
// Strings: use JSON.stringify to handle escaping, then wrap in curly braces.
|
|
22
22
|
serializedValue = `{${JSON.stringify(value)}}`;
|
|
23
23
|
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
24
|
-
// Numbers and booleans: wrap in curly braces without quotes
|
|
24
|
+
// Numbers and booleans: wrap in curly braces without quotes.
|
|
25
25
|
serializedValue = `{${value}}`;
|
|
26
26
|
} else if (value === null) {
|
|
27
|
-
// Null values
|
|
27
|
+
// Null values.
|
|
28
28
|
serializedValue = `{null}`;
|
|
29
29
|
} else if (Array.isArray(value) || typeof value === "object") {
|
|
30
|
-
// Arrays and objects: use JSON.stringify, then wrap in curly braces
|
|
30
|
+
// Arrays and objects: use JSON.stringify, then wrap in curly braces.
|
|
31
31
|
serializedValue = `{${JSON.stringify(value)}}`;
|
|
32
32
|
} else {
|
|
33
|
-
// Fallback for any other types
|
|
33
|
+
// Fallback for any other types.
|
|
34
34
|
serializedValue = `{${JSON.stringify(value)}}`;
|
|
35
35
|
}
|
|
36
36
|
attributes.push(`${key}=${serializedValue}`);
|
|
@@ -38,6 +38,48 @@ const serializePropsToJsx = props => {
|
|
|
38
38
|
return attributes.join(" ");
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Adds a component to the Extensions function in the webiny.config.tsx content.
|
|
43
|
+
*/
|
|
44
|
+
const addComponentToExtensions = (content, componentName, props) => {
|
|
45
|
+
// Serialize props to JSX attributes.
|
|
46
|
+
const propsString = props ? serializePropsToJsx(props) : "";
|
|
47
|
+
|
|
48
|
+
// Generate component tag with or without props.
|
|
49
|
+
const componentTag = propsString ? `<${componentName} ${propsString} />` : `<${componentName} />`;
|
|
50
|
+
|
|
51
|
+
// Check if component already exists.
|
|
52
|
+
if (content.includes(componentTag)) {
|
|
53
|
+
return content;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Find the Extensions function's return statement and add component before the final </>.
|
|
57
|
+
// Strategy: Find "export const Extensions" block, then find the last </> and insert before it.
|
|
58
|
+
const extensionsFuncRegex = /export const Extensions = \(\) => \{[\s\S]*?\};/;
|
|
59
|
+
const extensionsFuncMatch = content.match(extensionsFuncRegex);
|
|
60
|
+
if (!extensionsFuncMatch) {
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
63
|
+
const funcContent = extensionsFuncMatch[0];
|
|
64
|
+
// Find all </> in the function - the last one closes the return statement.
|
|
65
|
+
const closingTags = [...funcContent.matchAll(/<\/>/g)];
|
|
66
|
+
if (closingTags.length === 0) {
|
|
67
|
+
return content;
|
|
68
|
+
}
|
|
69
|
+
const lastClosingTag = closingTags[closingTags.length - 1];
|
|
70
|
+
const lastClosingTagIndex = lastClosingTag.index;
|
|
71
|
+
|
|
72
|
+
// Find the indentation of the line containing the last </>.
|
|
73
|
+
const beforeClosing = funcContent.substring(0, lastClosingTagIndex);
|
|
74
|
+
const lines = beforeClosing.split("\n");
|
|
75
|
+
const lastLine = lines[lines.length - 1];
|
|
76
|
+
const indent = lastLine.match(/^(\s*)/)?.[1] || " ";
|
|
77
|
+
|
|
78
|
+
// Insert the component before the last </>.
|
|
79
|
+
const newFuncContent = funcContent.substring(0, lastClosingTagIndex) + `${indent}${componentTag}\n${indent}` + funcContent.substring(lastClosingTagIndex);
|
|
80
|
+
return content.replace(extensionsFuncRegex, newFuncContent);
|
|
81
|
+
};
|
|
82
|
+
|
|
41
83
|
/**
|
|
42
84
|
* Update the webiny.config.tsx file to add extension imports and component.
|
|
43
85
|
*/
|
|
@@ -54,62 +96,47 @@ export const updateWebinyConfig = async params => {
|
|
|
54
96
|
// Add imports at the top (after existing imports)
|
|
55
97
|
if (webinyConfigTsx.imports && webinyConfigTsx.imports.length > 0) {
|
|
56
98
|
for (const importStatement of webinyConfigTsx.imports) {
|
|
57
|
-
|
|
99
|
+
// Check if we need to add to an existing import from the same path.
|
|
100
|
+
const existingImportRegex = new RegExp(`import\\s+{([^}]+)}\\s+from\\s+["']${importStatement.path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}["'];?`, "m");
|
|
101
|
+
const existingImportMatch = content.match(existingImportRegex);
|
|
102
|
+
if (existingImportMatch) {
|
|
103
|
+
// Import from this path exists, check if specifier is already imported.
|
|
104
|
+
const existingSpecifiers = existingImportMatch[1].split(",").map(s => s.trim());
|
|
105
|
+
if (!existingSpecifiers.includes(importStatement.specifier)) {
|
|
106
|
+
// Append the new specifier to the existing import.
|
|
107
|
+
const updatedSpecifiers = [...existingSpecifiers, importStatement.specifier].join(", ");
|
|
108
|
+
const updatedImportLine = `import { ${updatedSpecifiers} } from "${importStatement.path}";`;
|
|
109
|
+
content = content.replace(existingImportRegex, updatedImportLine);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
// No existing import from this path, add a new import line.
|
|
113
|
+
const importLine = `import { ${importStatement.specifier} } from "${importStatement.path}";`;
|
|
58
114
|
|
|
59
|
-
|
|
60
|
-
if (!content.includes(importLine)) {
|
|
61
|
-
// Find the position after the last import or at the beginning
|
|
115
|
+
// Find the position after the last import or at the beginning.
|
|
62
116
|
const importRegex = /^import\s+.*?from\s+["'].*?["'];?\s*$/gm;
|
|
63
117
|
const matches = Array.from(content.matchAll(importRegex));
|
|
64
118
|
if (matches.length > 0) {
|
|
65
|
-
// Add after the last import
|
|
119
|
+
// Add after the last import.
|
|
66
120
|
const lastImport = matches[matches.length - 1];
|
|
67
121
|
const lastImportEnd = lastImport.index + lastImport[0].length;
|
|
68
122
|
content = content.slice(0, lastImportEnd) + "\n" + importLine + content.slice(lastImportEnd);
|
|
69
123
|
} else {
|
|
70
|
-
// No imports found, add at the beginning
|
|
124
|
+
// No imports found, add at the beginning.
|
|
71
125
|
content = importLine + "\n\n" + content;
|
|
72
126
|
}
|
|
73
127
|
}
|
|
74
128
|
}
|
|
75
129
|
}
|
|
76
130
|
|
|
77
|
-
// Add component to the Extensions function
|
|
131
|
+
// Add component to the Extensions function.
|
|
78
132
|
if (webinyConfigTsx.component) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// Serialize props to JSX attributes
|
|
83
|
-
const propsString = props ? serializePropsToJsx(props) : "";
|
|
84
|
-
|
|
85
|
-
// Generate component tag with or without props
|
|
86
|
-
const componentTag = propsString ? `<${componentName} ${propsString} />` : `<${componentName} />`;
|
|
87
|
-
|
|
88
|
-
// Check if component already exists
|
|
89
|
-
if (!content.includes(componentTag)) {
|
|
90
|
-
// Find the Extensions function's return statement and add component before the final </>
|
|
91
|
-
// Strategy: Find "export const Extensions" block, then find the last </> and insert before it
|
|
92
|
-
const extensionsFuncRegex = /export const Extensions = \(\) => \{[\s\S]*?\};/;
|
|
93
|
-
const extensionsFuncMatch = content.match(extensionsFuncRegex);
|
|
94
|
-
if (extensionsFuncMatch) {
|
|
95
|
-
const funcContent = extensionsFuncMatch[0];
|
|
96
|
-
// Find all </> in the function - the last one closes the return statement
|
|
97
|
-
const closingTags = [...funcContent.matchAll(/<\/>/g)];
|
|
98
|
-
if (closingTags.length > 0) {
|
|
99
|
-
const lastClosingTag = closingTags[closingTags.length - 1];
|
|
100
|
-
const lastClosingTagIndex = lastClosingTag.index;
|
|
101
|
-
|
|
102
|
-
// Find the indentation of the line containing the last </>
|
|
103
|
-
const beforeClosing = funcContent.substring(0, lastClosingTagIndex);
|
|
104
|
-
const lines = beforeClosing.split("\n");
|
|
105
|
-
const lastLine = lines[lines.length - 1];
|
|
106
|
-
const indent = lastLine.match(/^(\s*)/)?.[1] || " ";
|
|
133
|
+
content = addComponentToExtensions(content, webinyConfigTsx.component.name, webinyConfigTsx.component.props);
|
|
134
|
+
}
|
|
107
135
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
136
|
+
// Add multiple components to the Extensions function.
|
|
137
|
+
if (webinyConfigTsx.components && webinyConfigTsx.components.length > 0) {
|
|
138
|
+
for (const component of webinyConfigTsx.components) {
|
|
139
|
+
content = addComponentToExtensions(content, component.name, component.props);
|
|
113
140
|
}
|
|
114
141
|
}
|
|
115
142
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["fs","serializePropsToJsx","props","attributes","key","value","Object","entries","undefined","serializedValue","JSON","stringify","Array","isArray","push","join","updateWebinyConfig","params","projectRoot","webinyConfigTsx","webinyConfigPath","content","readFileSync","imports","length","importStatement","importLine","specifier","path","includes","importRegex","matches","from","matchAll","lastImport","lastImportEnd","index","slice","component","componentName","name","propsString","componentTag","extensionsFuncRegex","extensionsFuncMatch","match","funcContent","closingTags","lastClosingTag","lastClosingTagIndex","beforeClosing","substring","lines","split","lastLine","indent","newFuncContent","replace","writeFileSync"],"sources":["updateWebinyConfig.ts"],"sourcesContent":["import fs from \"fs\";\nimport { ExtensionWebinyConfigTsx } from \"./types.js\";\n\ninterface UpdateWebinyConfigParams {\n projectRoot: string;\n webinyConfigTsx: ExtensionWebinyConfigTsx;\n}\n\n/**\n * Serializes a props object to JSX attribute syntax.\n * Examples:\n * - { secretKey: \"value\" } => 'secretKey={\"value\"}'\n * - { enabled: true } => 'enabled={true}'\n * - { count: 42 } => 'count={42}'\n * - { config: { key: \"value\" } } => 'config={{\"key\":\"value\"}}'\n */\nconst serializePropsToJsx = (props: Record<string, any>): string => {\n const attributes: string[] = [];\n\n for (const [key, value] of Object.entries(props)) {\n // Skip undefined values\n if (value === undefined) {\n continue;\n }\n\n // Determine the serialization based on value type\n let serializedValue: string;\n\n if (typeof value === \"string\") {\n // Strings: use JSON.stringify to handle escaping, then wrap in curly braces\n serializedValue = `{${JSON.stringify(value)}}`;\n } else if (typeof value === \"number\" || typeof value === \"boolean\") {\n // Numbers and booleans: wrap in curly braces without quotes\n serializedValue = `{${value}}`;\n } else if (value === null) {\n // Null values\n serializedValue = `{null}`;\n } else if (Array.isArray(value) || typeof value === \"object\") {\n // Arrays and objects: use JSON.stringify, then wrap in curly braces\n serializedValue = `{${JSON.stringify(value)}}`;\n } else {\n // Fallback for any other types\n serializedValue = `{${JSON.stringify(value)}}`;\n }\n\n attributes.push(`${key}=${serializedValue}`);\n }\n\n return attributes.join(\" \");\n};\n\n/**\n * Update the webiny.config.tsx file to add extension imports and component.\n */\nexport const updateWebinyConfig = async (params: UpdateWebinyConfigParams): Promise<void> => {\n const { projectRoot, webinyConfigTsx } = params;\n\n const webinyConfigPath = `${projectRoot}/webiny.config.tsx`;\n\n // Read the current webiny.config.tsx\n let content = fs.readFileSync(webinyConfigPath, \"utf-8\");\n\n // Add imports at the top (after existing imports)\n if (webinyConfigTsx.imports && webinyConfigTsx.imports.length > 0) {\n for (const importStatement of webinyConfigTsx.imports) {\n const importLine = `import { ${importStatement.specifier} } from \"${importStatement.path}\";`;\n\n // Check if import already exists\n if (!content.includes(importLine)) {\n // Find the position after the last import or at the beginning\n const importRegex = /^import\\s+.*?from\\s+[\"'].*?[\"'];?\\s*$/gm;\n const matches = Array.from(content.matchAll(importRegex));\n\n if (matches.length > 0) {\n // Add after the last import\n const lastImport = matches[matches.length - 1];\n const lastImportEnd = lastImport.index! + lastImport[0].length;\n content =\n content.slice(0, lastImportEnd) +\n \"\\n\" +\n importLine +\n content.slice(lastImportEnd);\n } else {\n // No imports found, add at the beginning\n content = importLine + \"\\n\\n\" + content;\n }\n }\n }\n }\n\n // Add component to the Extensions function\n if (webinyConfigTsx.component) {\n const componentName = webinyConfigTsx.component.name;\n const props = webinyConfigTsx.component.props;\n\n // Serialize props to JSX attributes\n const propsString = props ? serializePropsToJsx(props) : \"\";\n\n // Generate component tag with or without props\n const componentTag = propsString\n ? `<${componentName} ${propsString} />`\n : `<${componentName} />`;\n\n // Check if component already exists\n if (!content.includes(componentTag)) {\n // Find the Extensions function's return statement and add component before the final </>\n // Strategy: Find \"export const Extensions\" block, then find the last </> and insert before it\n const extensionsFuncRegex = /export const Extensions = \\(\\) => \\{[\\s\\S]*?\\};/;\n const extensionsFuncMatch = content.match(extensionsFuncRegex);\n\n if (extensionsFuncMatch) {\n const funcContent = extensionsFuncMatch[0];\n // Find all </> in the function - the last one closes the return statement\n const closingTags = [...funcContent.matchAll(/<\\/>/g)];\n\n if (closingTags.length > 0) {\n const lastClosingTag = closingTags[closingTags.length - 1];\n const lastClosingTagIndex = lastClosingTag.index!;\n\n // Find the indentation of the line containing the last </>\n const beforeClosing = funcContent.substring(0, lastClosingTagIndex);\n const lines = beforeClosing.split(\"\\n\");\n const lastLine = lines[lines.length - 1];\n const indent = lastLine.match(/^(\\s*)/)?.[1] || \" \";\n\n // Insert the component before the last </>\n const newFuncContent =\n funcContent.substring(0, lastClosingTagIndex) +\n `${indent}${componentTag}\\n${indent}` +\n funcContent.substring(lastClosingTagIndex);\n\n content = content.replace(extensionsFuncRegex, newFuncContent);\n }\n }\n }\n }\n\n // Write the updated content back\n fs.writeFileSync(webinyConfigPath, content, \"utf-8\");\n};\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AAQnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAIC,KAA0B,IAAa;EAChE,MAAMC,UAAoB,GAAG,EAAE;EAE/B,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,KAAK,CAAC,EAAE;IAC9C;IACA,IAAIG,KAAK,KAAKG,SAAS,EAAE;MACrB;IACJ;;IAEA;IACA,IAAIC,eAAuB;IAE3B,IAAI,OAAOJ,KAAK,KAAK,QAAQ,EAAE;MAC3B;MACAI,eAAe,GAAG,IAAIC,IAAI,CAACC,SAAS,CAACN,KAAK,CAAC,GAAG;IAClD,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,SAAS,EAAE;MAChE;MACAI,eAAe,GAAG,IAAIJ,KAAK,GAAG;IAClC,CAAC,MAAM,IAAIA,KAAK,KAAK,IAAI,EAAE;MACvB;MACAI,eAAe,GAAG,QAAQ;IAC9B,CAAC,MAAM,IAAIG,KAAK,CAACC,OAAO,CAACR,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC1D;MACAI,eAAe,GAAG,IAAIC,IAAI,CAACC,SAAS,CAACN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,MAAMC,QAAQ,GAAGF,KAAK,CAACA,KAAK,CAAC5B,MAAM,GAAG,CAAC,CAAC;UACxC,MAAM+B,MAAM,GAAGD,QAAQ,CAACT,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,UAAU;;UAE1D;UACA,MAAMW,cAAc,GAChBV,WAAW,CAACK,SAAS,CAAC,CAAC,EAAEF,mBAAmB,CAAC,GAC7C,GAAGM,MAAM,GAAGb,YAAY,KAAKa,MAAM,EAAE,GACrCT,WAAW,CAACK,SAAS,CAACF,mBAAmB,CAAC;UAE9C5B,OAAO,GAAGA,OAAO,CAACoC,OAAO,CAACd,mBAAmB,EAAEa,cAAc,CAAC;QAClE;MACJ;IACJ;EACJ;;EAEA;EACAxD,EAAE,CAAC0D,aAAa,CAACtC,gBAAgB,EAAEC,OAAO,EAAE,OAAO,CAAC;AACxD,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["fs","serializePropsToJsx","props","attributes","key","value","Object","entries","undefined","serializedValue","JSON","stringify","Array","isArray","push","join","addComponentToExtensions","content","componentName","propsString","componentTag","includes","extensionsFuncRegex","extensionsFuncMatch","match","funcContent","closingTags","matchAll","length","lastClosingTag","lastClosingTagIndex","index","beforeClosing","substring","lines","split","lastLine","indent","newFuncContent","replace","updateWebinyConfig","params","projectRoot","webinyConfigTsx","webinyConfigPath","readFileSync","imports","importStatement","existingImportRegex","RegExp","path","existingImportMatch","existingSpecifiers","map","s","trim","specifier","updatedSpecifiers","updatedImportLine","importLine","importRegex","matches","from","lastImport","lastImportEnd","slice","component","name","components","writeFileSync"],"sources":["updateWebinyConfig.ts"],"sourcesContent":["import fs from \"fs\";\nimport { ExtensionWebinyConfigTsx } from \"./types.js\";\n\ninterface UpdateWebinyConfigParams {\n projectRoot: string;\n webinyConfigTsx: ExtensionWebinyConfigTsx;\n}\n\n/**\n * Serializes a props object to JSX attribute syntax.\n * Examples:\n * - { secretKey: \"value\" } => 'secretKey={\"value\"}'\n * - { enabled: true } => 'enabled={true}'\n * - { count: 42 } => 'count={42}'\n * - { config: { key: \"value\" } } => 'config={{\"key\":\"value\"}}'\n */\nconst serializePropsToJsx = (props: Record<string, any>): string => {\n const attributes: string[] = [];\n\n for (const [key, value] of Object.entries(props)) {\n // Skip undefined values.\n if (value === undefined) {\n continue;\n }\n\n // Determine the serialization based on value type.\n let serializedValue: string;\n\n if (typeof value === \"string\") {\n // Strings: use JSON.stringify to handle escaping, then wrap in curly braces.\n serializedValue = `{${JSON.stringify(value)}}`;\n } else if (typeof value === \"number\" || typeof value === \"boolean\") {\n // Numbers and booleans: wrap in curly braces without quotes.\n serializedValue = `{${value}}`;\n } else if (value === null) {\n // Null values.\n serializedValue = `{null}`;\n } else if (Array.isArray(value) || typeof value === \"object\") {\n // Arrays and objects: use JSON.stringify, then wrap in curly braces.\n serializedValue = `{${JSON.stringify(value)}}`;\n } else {\n // Fallback for any other types.\n serializedValue = `{${JSON.stringify(value)}}`;\n }\n\n attributes.push(`${key}=${serializedValue}`);\n }\n\n return attributes.join(\" \");\n};\n\n/**\n * Adds a component to the Extensions function in the webiny.config.tsx content.\n */\nconst addComponentToExtensions = (\n content: string,\n componentName: string,\n props?: Record<string, any>\n): string => {\n // Serialize props to JSX attributes.\n const propsString = props ? serializePropsToJsx(props) : \"\";\n\n // Generate component tag with or without props.\n const componentTag = propsString\n ? `<${componentName} ${propsString} />`\n : `<${componentName} />`;\n\n // Check if component already exists.\n if (content.includes(componentTag)) {\n return content;\n }\n\n // Find the Extensions function's return statement and add component before the final </>.\n // Strategy: Find \"export const Extensions\" block, then find the last </> and insert before it.\n const extensionsFuncRegex = /export const Extensions = \\(\\) => \\{[\\s\\S]*?\\};/;\n const extensionsFuncMatch = content.match(extensionsFuncRegex);\n\n if (!extensionsFuncMatch) {\n return content;\n }\n\n const funcContent = extensionsFuncMatch[0];\n // Find all </> in the function - the last one closes the return statement.\n const closingTags = [...funcContent.matchAll(/<\\/>/g)];\n\n if (closingTags.length === 0) {\n return content;\n }\n\n const lastClosingTag = closingTags[closingTags.length - 1];\n const lastClosingTagIndex = lastClosingTag.index!;\n\n // Find the indentation of the line containing the last </>.\n const beforeClosing = funcContent.substring(0, lastClosingTagIndex);\n const lines = beforeClosing.split(\"\\n\");\n const lastLine = lines[lines.length - 1];\n const indent = lastLine.match(/^(\\s*)/)?.[1] || \" \";\n\n // Insert the component before the last </>.\n const newFuncContent =\n funcContent.substring(0, lastClosingTagIndex) +\n `${indent}${componentTag}\\n${indent}` +\n funcContent.substring(lastClosingTagIndex);\n\n return content.replace(extensionsFuncRegex, newFuncContent);\n};\n\n/**\n * Update the webiny.config.tsx file to add extension imports and component.\n */\nexport const updateWebinyConfig = async (params: UpdateWebinyConfigParams): Promise<void> => {\n const { projectRoot, webinyConfigTsx } = params;\n\n const webinyConfigPath = `${projectRoot}/webiny.config.tsx`;\n\n // Read the current webiny.config.tsx\n let content = fs.readFileSync(webinyConfigPath, \"utf-8\");\n\n // Add imports at the top (after existing imports)\n if (webinyConfigTsx.imports && webinyConfigTsx.imports.length > 0) {\n for (const importStatement of webinyConfigTsx.imports) {\n // Check if we need to add to an existing import from the same path.\n const existingImportRegex = new RegExp(\n `import\\\\s+{([^}]+)}\\\\s+from\\\\s+[\"']${importStatement.path.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")}[\"'];?`,\n \"m\"\n );\n const existingImportMatch = content.match(existingImportRegex);\n\n if (existingImportMatch) {\n // Import from this path exists, check if specifier is already imported.\n const existingSpecifiers = existingImportMatch[1].split(\",\").map(s => s.trim());\n\n if (!existingSpecifiers.includes(importStatement.specifier)) {\n // Append the new specifier to the existing import.\n const updatedSpecifiers = [\n ...existingSpecifiers,\n importStatement.specifier\n ].join(\", \");\n const updatedImportLine = `import { ${updatedSpecifiers} } from \"${importStatement.path}\";`;\n content = content.replace(existingImportRegex, updatedImportLine);\n }\n } else {\n // No existing import from this path, add a new import line.\n const importLine = `import { ${importStatement.specifier} } from \"${importStatement.path}\";`;\n\n // Find the position after the last import or at the beginning.\n const importRegex = /^import\\s+.*?from\\s+[\"'].*?[\"'];?\\s*$/gm;\n const matches = Array.from(content.matchAll(importRegex));\n\n if (matches.length > 0) {\n // Add after the last import.\n const lastImport = matches[matches.length - 1];\n const lastImportEnd = lastImport.index! + lastImport[0].length;\n content =\n content.slice(0, lastImportEnd) +\n \"\\n\" +\n importLine +\n content.slice(lastImportEnd);\n } else {\n // No imports found, add at the beginning.\n content = importLine + \"\\n\\n\" + content;\n }\n }\n }\n }\n\n // Add component to the Extensions function.\n if (webinyConfigTsx.component) {\n content = addComponentToExtensions(\n content,\n webinyConfigTsx.component.name,\n webinyConfigTsx.component.props\n );\n }\n\n // Add multiple components to the Extensions function.\n if (webinyConfigTsx.components && webinyConfigTsx.components.length > 0) {\n for (const component of webinyConfigTsx.components) {\n content = addComponentToExtensions(content, component.name, component.props);\n }\n }\n\n // Write the updated content back\n fs.writeFileSync(webinyConfigPath, content, \"utf-8\");\n};\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AAQnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAIC,KAA0B,IAAa;EAChE,MAAMC,UAAoB,GAAG,EAAE;EAE/B,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,KAAK,CAAC,EAAE;IAC9C;IACA,IAAIG,KAAK,KAAKG,SAAS,EAAE;MACrB;IACJ;;IAEA;IACA,IAAIC,eAAuB;IAE3B,IAAI,OAAOJ,KAAK,KAAK,QAAQ,EAAE;MAC3B;MACAI,eAAe,GAAG,IAAIC,IAAI,CAACC,SAAS,CAACN,KAAK,CAAC,GAAG;IAClD,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,SAAS,EAAE;MAChE;MACAI,eAAe,GAAG,IAAIJ,KAAK,GAAG;IAClC,CAAC,MAAM,IAAIA,KAAK,KAAK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CAACgD,KAAK,CAACD,aAAa,CAAC;QACpC,CAAC,MAAM;UACH;UACA/C,OAAO,GAAG0C,UAAU,GAAG,MAAM,GAAG1C,OAAO;QAC3C;MACJ;IACJ;EACJ;;EAEA;EACA,IAAI0B,eAAe,CAACuB,SAAS,EAAE;IAC3BjD,OAAO,GAAGD,wBAAwB,CAC9BC,OAAO,EACP0B,eAAe,CAACuB,SAAS,CAACC,IAAI,EAC9BxB,eAAe,CAACuB,SAAS,CAAChE,KAC9B,CAAC;EACL;;EAEA;EACA,IAAIyC,eAAe,CAACyB,UAAU,IAAIzB,eAAe,CAACyB,UAAU,CAACxC,MAAM,GAAG,CAAC,EAAE;IACrE,KAAK,MAAMsC,SAAS,IAAIvB,eAAe,CAACyB,UAAU,EAAE;MAChDnD,OAAO,GAAGD,wBAAwB,CAACC,OAAO,EAAEiD,SAAS,CAACC,IAAI,EAAED,SAAS,CAAChE,KAAK,CAAC;IAChF;EACJ;;EAEA;EACAF,EAAE,CAACqE,aAAa,CAACzB,gBAAgB,EAAE3B,OAAO,EAAE,OAAO,CAAC;AACxD,CAAC","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ import path from "path";
|
|
|
5
5
|
import glob from "fast-glob";
|
|
6
6
|
const globToRegex = pattern => {
|
|
7
7
|
// Escape regex special chars except *
|
|
8
|
-
const escaped = pattern.replace(/[
|
|
8
|
+
const escaped = pattern.replace(/[-/\\^$+?.()|[\]{}]/g, "\\$&");
|
|
9
9
|
// Replace * with .* in regex pattern
|
|
10
10
|
const regexStr = "^" + escaped.replace(/\*/g, ".*") + "$";
|
|
11
11
|
return new RegExp(regexStr);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createImplementation","GetAppService","GetProjectService","ListPackagesService","fs","path","glob","globToRegex","pattern","escaped","replace","regexStr","RegExp","matchesGlobPattern","packageName","regex","test","withoutPrefix","startsWith","regexWithPrefix","DefaultListPackagesService","constructor","getProjectService","getAppService","execute","params","appName","packageWhitelist","Error","project","app","packagesFullList","packagesFolderPath","paths","rootFolder","join","toString","existsSync","readdirSync","map","name","pkgFolderPath","webinyConfigPath","packageFolder","webinyConfigFile","filter","Boolean","webinyConfigPaths","sync","cwd","workspaceFolder","absolute","ignore","appPackages","packageFolderPath","dirname","basename","push","packagesToWatch","length","whitelistedPackages","whitelistedPkgName","split","flat","trim","pkg","includes","listPackagesService","abstraction","implementation","dependencies"],"sources":["ListPackagesService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { GetAppService, GetProjectService, ListPackagesService } from \"~/abstractions/index.js\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport glob from \"fast-glob\";\n\nconst globToRegex = (pattern: string) => {\n // Escape regex special chars except *\n const escaped = pattern.replace(/[-\\/\\\\^$+?.()|[\\]{}]/g, \"\\\\$&\");\n // Replace * with .* in regex pattern\n const regexStr = \"^\" + escaped.replace(/\\*/g, \".*\") + \"$\";\n return new RegExp(regexStr);\n};\n\nconst matchesGlobPattern = (packageName: string, pattern: string): boolean => {\n // Try matching with the full package name\n const regex = globToRegex(pattern);\n if (regex.test(packageName)) {\n return true;\n }\n\n // Also try matching against the name without @webiny/ or @app/ prefix\n const withoutPrefix = packageName.replace(/^@[^/]+\\//, \"\");\n if (regex.test(withoutPrefix)) {\n return true;\n }\n\n // If pattern doesn't start with @, also try adding @webiny/ prefix to pattern\n if (!pattern.startsWith(\"@\")) {\n const regexWithPrefix = globToRegex(`@webiny/${pattern}`);\n if (regexWithPrefix.test(packageName)) {\n return true;\n }\n }\n\n return false;\n};\n\nexport class DefaultListPackagesService implements ListPackagesService.Interface {\n constructor(\n private getProjectService: GetProjectService.Interface,\n private getAppService: GetAppService.Interface\n ) {}\n\n async execute(params: ListPackagesService.Params) {\n if (!params.appName && !params.packageWhitelist) {\n throw new Error(`Either \"packageWhitelist\" or \"appName\" argument must be provided.`);\n }\n\n const { packageWhitelist = [], appName } = params;\n const project = this.getProjectService.execute();\n const app = appName ? this.getAppService.execute(appName) : null;\n\n // List all packages in `packages` folder.\n let packagesFullList: ListPackagesService.Result = [];\n\n const packagesFolderPath = project.paths.rootFolder.join(\"packages\").toString();\n if (fs.existsSync(packagesFolderPath)) {\n packagesFullList = fs\n .readdirSync(project.paths.rootFolder.join(\"packages\").toString())\n .map(name => {\n const pkgFolderPath = project.paths.rootFolder\n .join(\"/packages/\", name)\n .toString();\n\n let webinyConfigPath = path.join(pkgFolderPath, \"webiny.config.ts\");\n if (!fs.existsSync(webinyConfigPath)) {\n webinyConfigPath = path.join(pkgFolderPath, \"webiny.config.js\");\n }\n\n return {\n name: `@webiny/${name}`,\n paths: {\n packageFolder: pkgFolderPath,\n webinyConfigFile: webinyConfigPath\n }\n } as ListPackagesService.Package;\n })\n .filter(Boolean);\n }\n\n if (app) {\n const webinyConfigPaths = glob.sync(\"**/webiny.config.@(ts|js)\", {\n cwd: app.paths.workspaceFolder.toString(),\n absolute: true,\n ignore: [\"**/node_modules/**\", \"**/dist/**\"]\n });\n\n const appPackages = webinyConfigPaths.map(webinyConfigPath => {\n const packageFolderPath = path.dirname(webinyConfigPath);\n const packageName = path.basename(packageFolderPath);\n\n return {\n name: `@${app.name}/${packageName}`,\n paths: {\n packageFolder: packageFolderPath,\n webinyConfigFile: webinyConfigPath\n }\n } as ListPackagesService.Package;\n });\n\n packagesFullList.push(...appPackages);\n }\n\n const packagesToWatch = [];\n\n if (packageWhitelist.length) {\n const whitelistedPackages = packageWhitelist\n .map(whitelistedPkgName => {\n return whitelistedPkgName.split(\",\");\n })\n .flat()\n .map(whitelistedPkgName => whitelistedPkgName.trim())\n .map(whitelistedPkgName => {\n return packagesFullList.filter(pkg => {\n if (whitelistedPkgName.includes(\"*\")) {\n return matchesGlobPattern(pkg.name, whitelistedPkgName);\n }\n\n // We consider both `name` and `@webiny/name` as valid package names.\n // The @webiny/ prefix is optional (makes it easier to type for us).\n return (\n pkg.name === whitelistedPkgName ||\n pkg.name === `@webiny/${whitelistedPkgName}`\n );\n });\n })\n .flat()\n .filter(Boolean) as ListPackagesService.Result;\n\n packagesToWatch.push(...whitelistedPackages);\n }\n\n if (app) {\n // We've hardcoded this filtering here just because of lack of time.\n // With v5, these \"presets\" were located within `webiny.application.ts` files.\n if (app.name === \"api\") {\n packagesToWatch.push(\n ...packagesFullList.filter(pkg => {\n return pkg.name === \"@api/graphql\";\n })\n );\n\n return packagesToWatch;\n }\n\n packagesToWatch.push(\n ...packagesFullList.filter(pkg => {\n return pkg.name.startsWith(`@${app.name}`);\n })\n );\n }\n\n return packagesToWatch;\n }\n}\n\nexport const listPackagesService = createImplementation({\n abstraction: ListPackagesService,\n implementation: DefaultListPackagesService,\n // TODO: move getApp into a service\n dependencies: [GetProjectService, GetAppService]\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,YAAY;AACjD,SAASC,aAAa,EAAEC,iBAAiB,EAAEC,mBAAmB;AAC9D,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,IAAI,MAAM,WAAW;AAE5B,MAAMC,WAAW,GAAIC,OAAe,IAAK;EACrC;EACA,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC;EAChE;EACA,MAAMC,QAAQ,GAAG,GAAG,GAAGF,OAAO,CAACC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,GAAG;EACzD,OAAO,IAAIE,MAAM,CAACD,QAAQ,CAAC;AAC/B,CAAC;AAED,MAAME,kBAAkB,GAAGA,CAACC,WAAmB,EAAEN,OAAe,KAAc;EAC1E;EACA,MAAMO,KAAK,GAAGR,WAAW,CAACC,OAAO,CAAC;EAClC,IAAIO,KAAK,CAACC,IAAI,CAACF,WAAW,CAAC,EAAE;IACzB,OAAO,IAAI;EACf;;EAEA;EACA,MAAMG,aAAa,GAAGH,WAAW,CAACJ,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;EAC1D,IAAIK,KAAK,CAACC,IAAI,CAACC,a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AACzB,IAAI,CAACtB,UAAU,CAAC,IAAIY,GAAG,CAACU,IAAI,EAAE,CAAC;MAC9C,CAAC,CACL,CAAC;IACL;IAEA,OAAOkB,eAAe;EAC1B;AACJ;AAEA,OAAO,MAAMS,mBAAmB,GAAGnE,oBAAoB,CAAC;EACpDoE,WAAW,EAAEjE,mBAAmB;EAChCkE,cAAc,EAAEjD,0BAA0B;EAC1C;EACAkD,YAAY,EAAE,CAACpE,iBAAiB,EAAED,aAAa;AACnD,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createImplementation","GetAppService","GetProjectService","ListPackagesService","fs","path","glob","globToRegex","pattern","escaped","replace","regexStr","RegExp","matchesGlobPattern","packageName","regex","test","withoutPrefix","startsWith","regexWithPrefix","DefaultListPackagesService","constructor","getProjectService","getAppService","execute","params","appName","packageWhitelist","Error","project","app","packagesFullList","packagesFolderPath","paths","rootFolder","join","toString","existsSync","readdirSync","map","name","pkgFolderPath","webinyConfigPath","packageFolder","webinyConfigFile","filter","Boolean","webinyConfigPaths","sync","cwd","workspaceFolder","absolute","ignore","appPackages","packageFolderPath","dirname","basename","push","packagesToWatch","length","whitelistedPackages","whitelistedPkgName","split","flat","trim","pkg","includes","listPackagesService","abstraction","implementation","dependencies"],"sources":["ListPackagesService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { GetAppService, GetProjectService, ListPackagesService } from \"~/abstractions/index.js\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport glob from \"fast-glob\";\n\nconst globToRegex = (pattern: string) => {\n // Escape regex special chars except *\n const escaped = pattern.replace(/[-/\\\\^$+?.()|[\\]{}]/g, \"\\\\$&\");\n // Replace * with .* in regex pattern\n const regexStr = \"^\" + escaped.replace(/\\*/g, \".*\") + \"$\";\n return new RegExp(regexStr);\n};\n\nconst matchesGlobPattern = (packageName: string, pattern: string): boolean => {\n // Try matching with the full package name\n const regex = globToRegex(pattern);\n if (regex.test(packageName)) {\n return true;\n }\n\n // Also try matching against the name without @webiny/ or @app/ prefix\n const withoutPrefix = packageName.replace(/^@[^/]+\\//, \"\");\n if (regex.test(withoutPrefix)) {\n return true;\n }\n\n // If pattern doesn't start with @, also try adding @webiny/ prefix to pattern\n if (!pattern.startsWith(\"@\")) {\n const regexWithPrefix = globToRegex(`@webiny/${pattern}`);\n if (regexWithPrefix.test(packageName)) {\n return true;\n }\n }\n\n return false;\n};\n\nexport class DefaultListPackagesService implements ListPackagesService.Interface {\n constructor(\n private getProjectService: GetProjectService.Interface,\n private getAppService: GetAppService.Interface\n ) {}\n\n async execute(params: ListPackagesService.Params) {\n if (!params.appName && !params.packageWhitelist) {\n throw new Error(`Either \"packageWhitelist\" or \"appName\" argument must be provided.`);\n }\n\n const { packageWhitelist = [], appName } = params;\n const project = this.getProjectService.execute();\n const app = appName ? this.getAppService.execute(appName) : null;\n\n // List all packages in `packages` folder.\n let packagesFullList: ListPackagesService.Result = [];\n\n const packagesFolderPath = project.paths.rootFolder.join(\"packages\").toString();\n if (fs.existsSync(packagesFolderPath)) {\n packagesFullList = fs\n .readdirSync(project.paths.rootFolder.join(\"packages\").toString())\n .map(name => {\n const pkgFolderPath = project.paths.rootFolder\n .join(\"/packages/\", name)\n .toString();\n\n let webinyConfigPath = path.join(pkgFolderPath, \"webiny.config.ts\");\n if (!fs.existsSync(webinyConfigPath)) {\n webinyConfigPath = path.join(pkgFolderPath, \"webiny.config.js\");\n }\n\n return {\n name: `@webiny/${name}`,\n paths: {\n packageFolder: pkgFolderPath,\n webinyConfigFile: webinyConfigPath\n }\n } as ListPackagesService.Package;\n })\n .filter(Boolean);\n }\n\n if (app) {\n const webinyConfigPaths = glob.sync(\"**/webiny.config.@(ts|js)\", {\n cwd: app.paths.workspaceFolder.toString(),\n absolute: true,\n ignore: [\"**/node_modules/**\", \"**/dist/**\"]\n });\n\n const appPackages = webinyConfigPaths.map(webinyConfigPath => {\n const packageFolderPath = path.dirname(webinyConfigPath);\n const packageName = path.basename(packageFolderPath);\n\n return {\n name: `@${app.name}/${packageName}`,\n paths: {\n packageFolder: packageFolderPath,\n webinyConfigFile: webinyConfigPath\n }\n } as ListPackagesService.Package;\n });\n\n packagesFullList.push(...appPackages);\n }\n\n const packagesToWatch = [];\n\n if (packageWhitelist.length) {\n const whitelistedPackages = packageWhitelist\n .map(whitelistedPkgName => {\n return whitelistedPkgName.split(\",\");\n })\n .flat()\n .map(whitelistedPkgName => whitelistedPkgName.trim())\n .map(whitelistedPkgName => {\n return packagesFullList.filter(pkg => {\n if (whitelistedPkgName.includes(\"*\")) {\n return matchesGlobPattern(pkg.name, whitelistedPkgName);\n }\n\n // We consider both `name` and `@webiny/name` as valid package names.\n // The @webiny/ prefix is optional (makes it easier to type for us).\n return (\n pkg.name === whitelistedPkgName ||\n pkg.name === `@webiny/${whitelistedPkgName}`\n );\n });\n })\n .flat()\n .filter(Boolean) as ListPackagesService.Result;\n\n packagesToWatch.push(...whitelistedPackages);\n }\n\n if (app) {\n // We've hardcoded this filtering here just because of lack of time.\n // With v5, these \"presets\" were located within `webiny.application.ts` files.\n if (app.name === \"api\") {\n packagesToWatch.push(\n ...packagesFullList.filter(pkg => {\n return pkg.name === \"@api/graphql\";\n })\n );\n\n return packagesToWatch;\n }\n\n packagesToWatch.push(\n ...packagesFullList.filter(pkg => {\n return pkg.name.startsWith(`@${app.name}`);\n })\n );\n }\n\n return packagesToWatch;\n }\n}\n\nexport const listPackagesService = createImplementation({\n abstraction: ListPackagesService,\n implementation: DefaultListPackagesService,\n // TODO: move getApp into a service\n dependencies: [GetProjectService, GetAppService]\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,YAAY;AACjD,SAASC,aAAa,EAAEC,iBAAiB,EAAEC,mBAAmB;AAC9D,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,IAAI,MAAM,WAAW;AAE5B,MAAMC,WAAW,GAAIC,OAAe,IAAK;EACrC;EACA,MAAMC,OAAO,GAAGD,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B,kBAAkB,EAAE;QAEpD,CAAC,CAAC;MACN,CAAC,CAAC,CACDE,IAAI,CAAC,CAAC,CACNlB,MAAM,CAACC,OAAO,CAA+B;MAElDY,eAAe,CAACD,IAAI,CAAC,GAAGG,mBAAmB,CAAC;IAChD;IAEA,IAAI9B,GAAG,EAAE;MACL;MACA;MACA,IAAIA,GAAG,CAACU,IAAI,KAAK,KAAK,EAAE;QACpBkB,eAAe,CAACD,IAAI,CAChB,GAAG1B,gBAAgB,CAACc,MAAM,CAACoB,GAAG,IAAI;UAC9B,OAAOA,GAAG,CAACzB,IAAI,KAAK,cAAc;QACtC,CAAC,CACL,CAAC;QAED,OAAOkB,eAAe;MAC1B;MAEAA,eAAe,CAACD,IAAI,CAChB,GAAG1B,gBAAgB,CAACc,MAAM,CAACoB,GAAG,IAAI;QAC9B,OAAOA,GAAG,CAACzB,IAAI,CAACtB,UAAU,CAAC,IAAIY,GAAG,CAACU,IAAI,EAAE,CAAC;MAC9C,CAAC,CACL,CAAC;IACL;IAEA,OAAOkB,eAAe;EAC1B;AACJ;AAEA,OAAO,MAAMS,mBAAmB,GAAGnE,oBAAoB,CAAC;EACpDoE,WAAW,EAAEjE,mBAAmB;EAChCkE,cAAc,EAAEjD,0BAA0B;EAC1C;EACAkD,YAAY,EAAE,CAACpE,iBAAiB,EAAED,aAAa;AACnD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -10,10 +10,10 @@ export class DefaultProjectInfoService {
|
|
|
10
10
|
this.getProjectVersion = getProjectVersion;
|
|
11
11
|
}
|
|
12
12
|
async execute() {
|
|
13
|
-
const wcpProjectId = process.env.WCP_PROJECT_ID || "";
|
|
13
|
+
const wcpProjectId = process.env.WEBINY_PROJECT_ID || process.env.WCP_PROJECT_ID || "";
|
|
14
14
|
// const wcpUser = await getUser().catch(() => null);
|
|
15
|
-
//
|
|
16
|
-
const wcpUsingProjectEnvironmentApiKey = Boolean(process.env.WCP_ENVIRONMENT_API_KEY);
|
|
15
|
+
// oxlint-disable-next-line typescript/no-unused-vars
|
|
16
|
+
const wcpUsingProjectEnvironmentApiKey = Boolean(process.env.WEBINY_PROJECT_API_KEY || process.env.WCP_PROJECT_ENVIRONMENT_API_KEY || process.env.WCP_ENVIRONMENT_API_KEY);
|
|
17
17
|
const isCI = this.getIsCi.execute();
|
|
18
18
|
const npmVersion = this.getNpmVersion.execute();
|
|
19
19
|
const npxVersion = this.getNpxVersion.execute();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createImplementation","ProjectInfoService","GetIsCiService","GetNpmVersionService","GetNpxVersionService","GetPulumiVersionService","GetYarnVersionService","GetProjectVersionService","DefaultProjectInfoService","constructor","getIsCi","getNpmVersion","getNpxVersion","getPulumiVersion","getYarnVersion","getProjectVersion","execute","wcpProjectId","process","env","WCP_PROJECT_ID","wcpUsingProjectEnvironmentApiKey","Boolean","WCP_ENVIRONMENT_API_KEY","isCI","npmVersion","npxVersion","yarnVersion","pulumiVersion","pulumiAwsVersion","webiny","version","debugEnabled","DEBUG","featureFlags","WEBINY_FEATURE_FLAGS","wcp","projectId","usingProjectEnvironmentApiKey","host","os","platform","arch","nodeJs","npm","npx","yarn","pulumi","secretsProvider","PULUMI_SECRETS_PROVIDER","usingPassword","PULUMI_CONFIG_PASSPHRASE","projectInfoService","abstraction","implementation","dependencies"],"sources":["ProjectInfoService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport {\n ProjectInfoService,\n GetIsCiService,\n GetNpmVersionService,\n GetNpxVersionService,\n GetPulumiVersionService,\n GetYarnVersionService,\n GetProjectVersionService\n} from \"~/abstractions/index.js\";\nimport { IProjectInfoServiceResult } from \"~/abstractions/services/ProjectInfoService/ProjectInfoService.js\";\n\nexport class DefaultProjectInfoService implements ProjectInfoService.Interface {\n constructor(\n private getIsCi: GetIsCiService.Interface,\n private getNpmVersion: GetNpmVersionService.Interface,\n private getNpxVersion: GetNpxVersionService.Interface,\n private getPulumiVersion: GetPulumiVersionService.Interface,\n private getYarnVersion: GetYarnVersionService.Interface,\n private getProjectVersion: GetProjectVersionService.Interface\n ) {}\n\n async execute() {\n const wcpProjectId = process.env.WCP_PROJECT_ID || \"\";\n // const wcpUser = await getUser().catch(() => null);\n //
|
|
1
|
+
{"version":3,"names":["createImplementation","ProjectInfoService","GetIsCiService","GetNpmVersionService","GetNpxVersionService","GetPulumiVersionService","GetYarnVersionService","GetProjectVersionService","DefaultProjectInfoService","constructor","getIsCi","getNpmVersion","getNpxVersion","getPulumiVersion","getYarnVersion","getProjectVersion","execute","wcpProjectId","process","env","WEBINY_PROJECT_ID","WCP_PROJECT_ID","wcpUsingProjectEnvironmentApiKey","Boolean","WEBINY_PROJECT_API_KEY","WCP_PROJECT_ENVIRONMENT_API_KEY","WCP_ENVIRONMENT_API_KEY","isCI","npmVersion","npxVersion","yarnVersion","pulumiVersion","pulumiAwsVersion","webiny","version","debugEnabled","DEBUG","featureFlags","WEBINY_FEATURE_FLAGS","wcp","projectId","usingProjectEnvironmentApiKey","host","os","platform","arch","nodeJs","npm","npx","yarn","pulumi","secretsProvider","PULUMI_SECRETS_PROVIDER","usingPassword","PULUMI_CONFIG_PASSPHRASE","projectInfoService","abstraction","implementation","dependencies"],"sources":["ProjectInfoService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport {\n ProjectInfoService,\n GetIsCiService,\n GetNpmVersionService,\n GetNpxVersionService,\n GetPulumiVersionService,\n GetYarnVersionService,\n GetProjectVersionService\n} from \"~/abstractions/index.js\";\nimport { IProjectInfoServiceResult } from \"~/abstractions/services/ProjectInfoService/ProjectInfoService.js\";\n\nexport class DefaultProjectInfoService implements ProjectInfoService.Interface {\n constructor(\n private getIsCi: GetIsCiService.Interface,\n private getNpmVersion: GetNpmVersionService.Interface,\n private getNpxVersion: GetNpxVersionService.Interface,\n private getPulumiVersion: GetPulumiVersionService.Interface,\n private getYarnVersion: GetYarnVersionService.Interface,\n private getProjectVersion: GetProjectVersionService.Interface\n ) {}\n\n async execute() {\n const wcpProjectId = process.env.WEBINY_PROJECT_ID || process.env.WCP_PROJECT_ID || \"\";\n // const wcpUser = await getUser().catch(() => null);\n // oxlint-disable-next-line typescript/no-unused-vars\n const wcpUsingProjectEnvironmentApiKey = Boolean(\n process.env.WEBINY_PROJECT_API_KEY ||\n process.env.WCP_PROJECT_ENVIRONMENT_API_KEY ||\n process.env.WCP_ENVIRONMENT_API_KEY\n );\n\n const isCI = this.getIsCi.execute();\n const npmVersion = this.getNpmVersion.execute();\n const npxVersion = this.getNpxVersion.execute();\n const yarnVersion = this.getYarnVersion.execute();\n const [pulumiVersion, pulumiAwsVersion] = this.getPulumiVersion.execute();\n\n return {\n webiny: {\n version: this.getProjectVersion.execute(),\n debugEnabled: process.env.DEBUG === \"true\",\n featureFlags: process.env.WEBINY_FEATURE_FLAGS || {}\n },\n wcp: {\n projectId: wcpProjectId,\n // user: wcpUser?.email || \"N/A\",\n usingProjectEnvironmentApiKey: false // wcpUsingProject\n },\n host: {\n os: `${process.platform} (${process.arch})`,\n nodeJs: process.version,\n npm: npmVersion,\n npx: npxVersion,\n yarn: yarnVersion,\n isCI: isCI\n },\n pulumi: {\n \"@pulumi/pulumi\": pulumiVersion,\n \"@pulumi/aws\": pulumiAwsVersion,\n secretsProvider: process.env.PULUMI_SECRETS_PROVIDER || \"\",\n usingPassword: !!process.env.PULUMI_CONFIG_PASSPHRASE\n }\n } as IProjectInfoServiceResult;\n }\n}\n\nexport const projectInfoService = createImplementation({\n abstraction: ProjectInfoService,\n implementation: DefaultProjectInfoService,\n dependencies: [\n GetIsCiService,\n GetNpmVersionService,\n GetNpxVersionService,\n GetPulumiVersionService,\n GetYarnVersionService,\n GetProjectVersionService\n ]\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,YAAY;AACjD,SACIC,kBAAkB,EAClBC,cAAc,EACdC,oBAAoB,EACpBC,oBAAoB,EACpBC,uBAAuB,EACvBC,qBAAqB,EACrBC,wBAAwB;AAI5B,OAAO,MAAMC,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AO,CAACC,GAAG,CAACmB,oBAAoB,IAAI,CAAC;MACvD,CAAC;MACDC,GAAG,EAAE;QACDC,SAAS,EAAEvB,YAAY;QACvB;QACAwB,6BAA6B,EAAE,KAAK,CAAC;MACzC,CAAC;MACDC,IAAI,EAAE;QACFC,EAAE,EAAE,GAAGzB,OAAO,CAAC0B,QAAQ,KAAK1B,OAAO,CAAC2B,IAAI,GAAG;QAC3CC,MAAM,EAAE5B,OAAO,CAACgB,OAAO;QACvBa,GAAG,EAAEnB,UAAU;QACfoB,GAAG,EAAEnB,UAAU;QACfoB,IAAI,EAAEnB,WAAW;QACjBH,IAAI,EAAEA;MACV,CAAC;MACDuB,MAAM,EAAE;QACJ,gBAAgB,EAAEnB,aAAa;QAC/B,aAAa,EAAEC,gBAAgB;QAC/BmB,eAAe,EAAEjC,OAAO,CAACC,GAAG,CAACiC,uBAAuB,IAAI,EAAE;QAC1DC,aAAa,EAAE,CAAC,CAACnC,OAAO,CAACC,GAAG,CAACmC;MACjC;IACJ,CAAC;EACL;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAGvD,oBAAoB,CAAC;EACnDwD,WAAW,EAAEvD,kBAAkB;EAC/BwD,cAAc,EAAEjD,yBAAyB;EACzCkD,YAAY,EAAE,CACVxD,cAAc,EACdC,oBAAoB,EACpBC,oBAAoB,EACpBC,uBAAuB,EACvBC,qBAAqB,EACrBC,wBAAwB;AAEhC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import { getTsconfig } from "get-tsconfig";
|
|
4
|
+
import { toImportSpecifier } from "./toImportSpecifier.js";
|
|
4
5
|
export class ExtensionSrcResolver {
|
|
5
6
|
static pathMappings = null;
|
|
6
7
|
|
|
@@ -14,7 +15,7 @@ export class ExtensionSrcResolver {
|
|
|
14
15
|
static async importFromPath(filePath, project) {
|
|
15
16
|
const importPath = this.resolvePath(filePath, project);
|
|
16
17
|
const exportName = path.basename(filePath).replace(path.extname(filePath), "");
|
|
17
|
-
const importedModule = await import(importPath);
|
|
18
|
+
const importedModule = await import(toImportSpecifier(importPath));
|
|
18
19
|
|
|
19
20
|
// Support both default and named exports.
|
|
20
21
|
// Check for 'default' property existence rather than truthiness.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["path","fs","getTsconfig","ExtensionSrcResolver","pathMappings","importFromPath","filePath","project","importPath","resolvePath","exportName","basename","replace","extname","importedModule","default","startsWith","paths","rootFolder","join","toString","resolved","resolvePathAlias","existsSync","absolutePath","projectRoot","loadPathMappings","pattern","targets","Object","entries","match","matchPattern","target","resolvedPath","replacePlaceholder","resolve","tsConfigPath","tsConfigFile","tsconfig","config","compilerOptions","endsWith","prefix","slice","length","mapping"],"sources":["ExtensionSrcResolver.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport { getTsconfig } from \"get-tsconfig\";\nimport { type IProjectModel } from \"~/abstractions/models/index.js\";\n\nexport class ExtensionSrcResolver {\n private static pathMappings: { [key: string]: string[] } | null = null;\n\n /**\n * Import a module from a given file path.\n * - If path starts with \"/extensions/\", it resolves from project root\n * - If path matches tsconfig path alias (e.g., \"@/*\"), it resolves using tsconfig\n * - Otherwise, treats path as absolute\n * Returns the default export or named export matching the filename.\n */\n static async importFromPath(filePath: string, project: IProjectModel) {\n const importPath = this.resolvePath(filePath, project);\n const exportName = path.basename(filePath).replace(path.extname(filePath), \"\");\n\n const importedModule = await import(importPath);\n\n // Support both default and named exports.\n // Check for 'default' property existence rather than truthiness.\n return (\n (\"default\" in importedModule && importedModule.default) || importedModule[exportName]\n );\n }\n\n /**\n * Resolve a file path to an absolute path.\n * - If path starts with \"/extensions/\", it resolves from project root\n * - If path matches tsconfig path alias (e.g., \"@/*\"), it resolves using tsconfig\n * - Otherwise, treats path as absolute\n * Returns the absolute path without importing.\n */\n static resolvePath(filePath: string, project: IProjectModel): string {\n if (filePath.startsWith(\"/extensions/\")) {\n // Resolve from project root.\n return project.paths.rootFolder.join(filePath).toString();\n } else {\n // Try to resolve using tsconfig path aliases.\n const resolved = this.resolvePathAlias(filePath, project);\n if (resolved) {\n return resolved;\n } else {\n // Treat as absolute path.\n return filePath;\n }\n }\n }\n\n /**\n * Check if a file exists at the given path.\n * Resolves the path using the same logic as resolvePath before checking.\n * - If path starts with \"/extensions/\", it resolves from project root\n * - If path matches tsconfig path alias (e.g., \"@/*\"), it resolves using tsconfig\n * - Otherwise, treats path as absolute\n * Returns true if the file exists, false otherwise.\n */\n static existsSync(filePath: string, project: IProjectModel): boolean {\n const absolutePath = this.resolvePath(filePath, project);\n return fs.existsSync(absolutePath);\n }\n\n private static resolvePathAlias(filePath: string, project: IProjectModel): string | null {\n const projectRoot = project.paths.rootFolder.toString();\n\n // Load path mappings from tsconfig if not already cached.\n if (this.pathMappings === null) {\n this.loadPathMappings(project);\n }\n\n if (!this.pathMappings) {\n return null;\n }\n\n // Try to match against each path pattern.\n for (const [pattern, targets] of Object.entries(this.pathMappings)) {\n const match = this.matchPattern(filePath, pattern);\n if (match !== null) {\n // Use the first mapping.\n const target = targets[0];\n const resolvedPath = this.replacePlaceholder(target, match);\n return path.resolve(projectRoot, resolvedPath);\n }\n }\n\n return null;\n }\n\n private static loadPathMappings(project: IProjectModel): void {\n const tsConfigPath = project.paths.tsConfigFile.toString();\n\n try {\n // Use get-tsconfig to parse tsconfig with extends resolution.\n const tsconfig = getTsconfig(tsConfigPath);\n\n if (tsconfig?.config.compilerOptions?.paths) {\n this.pathMappings = tsconfig.config.compilerOptions.paths;\n } else {\n this.pathMappings = {};\n }\n } catch {\n // Ignore tsconfig parsing errors.\n this.pathMappings = {};\n }\n }\n\n private static matchPattern(importPath: string, pattern: string): string | null {\n // Handle wildcard patterns like \"@/*\" or \"@extensions/*\".\n if (pattern.endsWith(\"/*\")) {\n const prefix = pattern.slice(0, -2);\n // Only match if there's a slash after the prefix.\n if (importPath.startsWith(prefix + \"/\")) {\n return importPath.slice(prefix.length + 1);\n }\n } else if (pattern === importPath) {\n return \"\";\n }\n\n return null;\n }\n\n private static replacePlaceholder(mapping: string, match: string): string {\n // Replace wildcard with the matched part.\n if (mapping.endsWith(\"/*\")) {\n return mapping.slice(0, -2) + \"/\" + match;\n }\n return mapping;\n }\n}\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAOC,EAAE,MAAM,IAAI;AACnB,SAASC,WAAW,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"names":["path","fs","getTsconfig","toImportSpecifier","ExtensionSrcResolver","pathMappings","importFromPath","filePath","project","importPath","resolvePath","exportName","basename","replace","extname","importedModule","default","startsWith","paths","rootFolder","join","toString","resolved","resolvePathAlias","existsSync","absolutePath","projectRoot","loadPathMappings","pattern","targets","Object","entries","match","matchPattern","target","resolvedPath","replacePlaceholder","resolve","tsConfigPath","tsConfigFile","tsconfig","config","compilerOptions","endsWith","prefix","slice","length","mapping"],"sources":["ExtensionSrcResolver.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport { getTsconfig } from \"get-tsconfig\";\nimport { toImportSpecifier } from \"./toImportSpecifier.js\";\nimport { type IProjectModel } from \"~/abstractions/models/index.js\";\n\nexport class ExtensionSrcResolver {\n private static pathMappings: { [key: string]: string[] } | null = null;\n\n /**\n * Import a module from a given file path.\n * - If path starts with \"/extensions/\", it resolves from project root\n * - If path matches tsconfig path alias (e.g., \"@/*\"), it resolves using tsconfig\n * - Otherwise, treats path as absolute\n * Returns the default export or named export matching the filename.\n */\n static async importFromPath(filePath: string, project: IProjectModel) {\n const importPath = this.resolvePath(filePath, project);\n const exportName = path.basename(filePath).replace(path.extname(filePath), \"\");\n\n const importedModule = await import(toImportSpecifier(importPath));\n\n // Support both default and named exports.\n // Check for 'default' property existence rather than truthiness.\n return (\n (\"default\" in importedModule && importedModule.default) || importedModule[exportName]\n );\n }\n\n /**\n * Resolve a file path to an absolute path.\n * - If path starts with \"/extensions/\", it resolves from project root\n * - If path matches tsconfig path alias (e.g., \"@/*\"), it resolves using tsconfig\n * - Otherwise, treats path as absolute\n * Returns the absolute path without importing.\n */\n static resolvePath(filePath: string, project: IProjectModel): string {\n if (filePath.startsWith(\"/extensions/\")) {\n // Resolve from project root.\n return project.paths.rootFolder.join(filePath).toString();\n } else {\n // Try to resolve using tsconfig path aliases.\n const resolved = this.resolvePathAlias(filePath, project);\n if (resolved) {\n return resolved;\n } else {\n // Treat as absolute path.\n return filePath;\n }\n }\n }\n\n /**\n * Check if a file exists at the given path.\n * Resolves the path using the same logic as resolvePath before checking.\n * - If path starts with \"/extensions/\", it resolves from project root\n * - If path matches tsconfig path alias (e.g., \"@/*\"), it resolves using tsconfig\n * - Otherwise, treats path as absolute\n * Returns true if the file exists, false otherwise.\n */\n static existsSync(filePath: string, project: IProjectModel): boolean {\n const absolutePath = this.resolvePath(filePath, project);\n return fs.existsSync(absolutePath);\n }\n\n private static resolvePathAlias(filePath: string, project: IProjectModel): string | null {\n const projectRoot = project.paths.rootFolder.toString();\n\n // Load path mappings from tsconfig if not already cached.\n if (this.pathMappings === null) {\n this.loadPathMappings(project);\n }\n\n if (!this.pathMappings) {\n return null;\n }\n\n // Try to match against each path pattern.\n for (const [pattern, targets] of Object.entries(this.pathMappings)) {\n const match = this.matchPattern(filePath, pattern);\n if (match !== null) {\n // Use the first mapping.\n const target = targets[0];\n const resolvedPath = this.replacePlaceholder(target, match);\n return path.resolve(projectRoot, resolvedPath);\n }\n }\n\n return null;\n }\n\n private static loadPathMappings(project: IProjectModel): void {\n const tsConfigPath = project.paths.tsConfigFile.toString();\n\n try {\n // Use get-tsconfig to parse tsconfig with extends resolution.\n const tsconfig = getTsconfig(tsConfigPath);\n\n if (tsconfig?.config.compilerOptions?.paths) {\n this.pathMappings = tsconfig.config.compilerOptions.paths;\n } else {\n this.pathMappings = {};\n }\n } catch {\n // Ignore tsconfig parsing errors.\n this.pathMappings = {};\n }\n }\n\n private static matchPattern(importPath: string, pattern: string): string | null {\n // Handle wildcard patterns like \"@/*\" or \"@extensions/*\".\n if (pattern.endsWith(\"/*\")) {\n const prefix = pattern.slice(0, -2);\n // Only match if there's a slash after the prefix.\n if (importPath.startsWith(prefix + \"/\")) {\n return importPath.slice(prefix.length + 1);\n }\n } else if (pattern === importPath) {\n return \"\";\n }\n\n return null;\n }\n\n private static replacePlaceholder(mapping: string, match: string): string {\n // Replace wildcard with the matched part.\n if (mapping.endsWith(\"/*\")) {\n return mapping.slice(0, -2) + \"/\" + match;\n }\n return mapping;\n }\n}\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAOC,EAAE,MAAM,IAAI;AACnB,SAASC,WAAW,QAAQ,cAAc;AAC1C,SAASC,iBAAiB;AAG1B,OAAO,MAAMC,oBAAoB,CAAC;EAC9B,OAAeC,YAAY,GAAuC,IAAI;;EAEtE;AACJ;AACA;AACA;AACA;AACA;AACA;EACI,aAAaC,cAAcA,CAACC,QAAgB,EAAEC,OAAsB,EAAE;IAClE,MAAMC,UAAU,GAAG,IAAI,CAACC,WAAW,CAACH,QAAQ,EAAEC,OAAO,CAAC;IACtD,MAAMG,UAAU,GAAGX,IAAI,CAACY,QAAQ,CAACL,QAAQ,CAAC,CAACM,OAAO,CAACb,IAAI,CAACc,OAAO,CAACP,QAAQ,CAAC,EAAE,EAAE,CAAC;IAE9E,MAAMQ,cAAc,GAAG,MAAM,MAAM,CAACZ,iBAAiB,CAACM,UAAU,CAAC,CAAC;;IAElE;IACA;IACA,OACK,SAAS,IAAIM,cAAc,IAAIA,cAAc,CAACC,OAAO,IAAKD,cAAc,CAACJ,UAAU,CAAC;EAE7F;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;EACI,OAAOD,WAAWA,CAACH,QAAgB,EAAEC,OAAsB,EAAU;IACjE,IAAID,QAAQ,CAACU,UAAU,CAAC,cAAc,CAAC,EAAE;MACrC;MACA,OAAOT,OAAO,CAACU,KAAK,CAACC,UAAU,CAACC,IAAI,CAACb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;EAClB;AACJ","ignoreList":[]}
|
package/utils/index.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export * from "./isValidRegionName.js";
|
|
|
8
8
|
export * from "./isValidVariantName.js";
|
|
9
9
|
export * from "./measureDuration.js";
|
|
10
10
|
export * from "./requireConfig.js";
|
|
11
|
+
export * from "./toImportSpecifier.js";
|
|
11
12
|
export * from "./projectSdkContext.js";
|
|
12
13
|
export * from "./registerExtension.js";
|