@primeuicom/mcp 1.2.1 → 1.2.2

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/dist/service.js CHANGED
@@ -3741,6 +3741,15 @@ var PACKAGE_JSON_RELATIVE_PATH2 = "package.json";
3741
3741
  var VIRTUAL_ROUTE_SEGMENT = "__primeui-component-export";
3742
3742
  var COMPONENT_PAGES_PREFIX = "src/components/pages/";
3743
3743
  var COMPONENT_UI_PREFIX = "src/components/ui/";
3744
+ var COMPONENT_SHARED_PREFIX = "src/components/shared/";
3745
+ var NATURAL_SUPPORT_PREFIXES = [
3746
+ COMPONENT_UI_PREFIX,
3747
+ "src/lib/",
3748
+ "src/types/",
3749
+ "src/contexts/"
3750
+ ];
3751
+ var PUBLIC_PREFIX = "public/";
3752
+ var PUBLIC_ASSET_REFERENCE_RE = /["'`(]\/([^"'`()\s]+\.(?:avif|gif|ico|jpeg|jpg|json|mp4|otf|png|svg|ttf|txt|webm|webmanifest|webp|woff|woff2|xml))(?:\?[^"'`()\s]*)?["'`)]/giu;
3744
3753
  function normalizeComponentId(componentId) {
3745
3754
  const trimmed = componentId.trim();
3746
3755
  if (!trimmed) {
@@ -3773,6 +3782,35 @@ function isVirtualRouteFile(relativePath) {
3773
3782
  const segments = relativePath.split("/");
3774
3783
  return segments[0] === "src" && segments[1] === "app" && segments.includes(VIRTUAL_ROUTE_SEGMENT);
3775
3784
  }
3785
+ function getVirtualComponentRelativePath(relativePath, componentId) {
3786
+ const prefix = `${COMPONENT_PAGES_PREFIX}${VIRTUAL_ROUTE_SEGMENT}/${componentId}/`;
3787
+ if (!relativePath.startsWith(prefix)) {
3788
+ return null;
3789
+ }
3790
+ const componentRelativePath = relativePath.slice(prefix.length);
3791
+ return componentRelativePath || null;
3792
+ }
3793
+ function getComponentPageSourceArea(relativePath) {
3794
+ if (!relativePath.startsWith(COMPONENT_PAGES_PREFIX)) {
3795
+ return null;
3796
+ }
3797
+ const rest = relativePath.slice(COMPONENT_PAGES_PREFIX.length);
3798
+ const slashIndex = rest.indexOf("/");
3799
+ if (slashIndex <= 0) {
3800
+ return null;
3801
+ }
3802
+ const sourceArea = rest.slice(0, slashIndex);
3803
+ return sourceArea === VIRTUAL_ROUTE_SEGMENT ? null : sourceArea;
3804
+ }
3805
+ function getSourceAreaComponentRelativePath(relativePath, sourceAreas) {
3806
+ const sourceArea = getComponentPageSourceArea(relativePath);
3807
+ if (!sourceArea || !sourceAreas.has(sourceArea)) {
3808
+ return null;
3809
+ }
3810
+ const prefix = `${COMPONENT_PAGES_PREFIX}${sourceArea}/`;
3811
+ const componentRelativePath = relativePath.slice(prefix.length);
3812
+ return componentRelativePath || null;
3813
+ }
3776
3814
  function isComponentEntryFile(relativePath, componentId) {
3777
3815
  if (!relativePath.startsWith(COMPONENT_PAGES_PREFIX)) {
3778
3816
  return false;
@@ -3788,7 +3826,155 @@ function isComponentEntryFile(relativePath, componentId) {
3788
3826
  return basename === "index" && path13.basename(path13.dirname(relativePath)) === componentId;
3789
3827
  }
3790
3828
  function isManifestSupportFile(relativePath) {
3791
- return relativePath.startsWith(COMPONENT_UI_PREFIX);
3829
+ return NATURAL_SUPPORT_PREFIXES.some(
3830
+ (prefix) => relativePath.startsWith(prefix)
3831
+ );
3832
+ }
3833
+ function isEnvFile(relativePath) {
3834
+ return relativePath === ".env" || relativePath.startsWith(".env.");
3835
+ }
3836
+ function isSearchRuntimeFile(relativePath) {
3837
+ return relativePath.startsWith("src/app/api/search/") || relativePath.startsWith("src/lib/search/") || relativePath.startsWith("src/lib/search-runtime/") || relativePath.startsWith("src/search/");
3838
+ }
3839
+ function isProjectLevelFile(relativePath) {
3840
+ return isEnvFile(relativePath) || isSearchRuntimeFile(relativePath) || relativePath.startsWith("scripts/") || relativePath.startsWith("src/app/") || relativePath.startsWith("src/components/header/") || relativePath.startsWith("src/components/footer/") || relativePath.startsWith("src/components/layout/");
3841
+ }
3842
+ function toComponentSharedTargetPath(componentRelativePath) {
3843
+ return `${COMPONENT_SHARED_PREFIX}${componentRelativePath}`;
3844
+ }
3845
+ function toImportPath(relativePath) {
3846
+ const withoutExtension = relativePath.replace(/\.[cm]?[jt]sx?$/u, "");
3847
+ const withoutIndex = withoutExtension.replace(/\/index$/u, "");
3848
+ return `@/${withoutIndex.replace(/^src\//u, "")}`;
3849
+ }
3850
+ function escapeRegExp(value) {
3851
+ return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
3852
+ }
3853
+ function sourceImportSpecifiers(relativePath) {
3854
+ const withAlias = toImportPath(relativePath);
3855
+ const specifiers = [withAlias];
3856
+ if (withAlias.endsWith("/index")) {
3857
+ specifiers.push(withAlias.replace(/\/index$/u, ""));
3858
+ }
3859
+ return [...new Set(specifiers)];
3860
+ }
3861
+ function rewriteComponentLocalImports(content, transfers) {
3862
+ let updated = content;
3863
+ for (const transfer of transfers) {
3864
+ const targetSpecifier = toImportPath(transfer.targetPath);
3865
+ for (const sourceSpecifier of sourceImportSpecifiers(transfer.sourcePath)) {
3866
+ updated = updated.replace(
3867
+ new RegExp(escapeRegExp(sourceSpecifier), "gu"),
3868
+ targetSpecifier
3869
+ );
3870
+ }
3871
+ }
3872
+ return updated;
3873
+ }
3874
+ function collectReferencedPublicAssetFiles(content) {
3875
+ const referencedFiles = /* @__PURE__ */ new Set();
3876
+ let match = null;
3877
+ PUBLIC_ASSET_REFERENCE_RE.lastIndex = 0;
3878
+ while ((match = PUBLIC_ASSET_REFERENCE_RE.exec(content)) !== null) {
3879
+ const referencedPath = match[1]?.trim();
3880
+ if (referencedPath) {
3881
+ referencedFiles.add(
3882
+ `${PUBLIC_PREFIX}${normalizeManifestFilePath(referencedPath)}`
3883
+ );
3884
+ }
3885
+ }
3886
+ return [...referencedFiles];
3887
+ }
3888
+ function findComponentSourceAreas(relativePaths) {
3889
+ const sourceAreas = /* @__PURE__ */ new Set();
3890
+ for (const relativePath of relativePaths) {
3891
+ const sourceArea = getComponentPageSourceArea(relativePath);
3892
+ if (sourceArea) {
3893
+ sourceAreas.add(sourceArea);
3894
+ }
3895
+ }
3896
+ return sourceAreas;
3897
+ }
3898
+ function getComponentLocalTargetPath(input) {
3899
+ const virtualRelativePath = getVirtualComponentRelativePath(
3900
+ input.relativePath,
3901
+ input.componentId
3902
+ );
3903
+ if (virtualRelativePath) {
3904
+ return toComponentSharedTargetPath(virtualRelativePath);
3905
+ }
3906
+ const sourceAreaRelativePath = getSourceAreaComponentRelativePath(
3907
+ input.relativePath,
3908
+ input.sourceAreas
3909
+ );
3910
+ if (sourceAreaRelativePath) {
3911
+ return toComponentSharedTargetPath(sourceAreaRelativePath);
3912
+ }
3913
+ return null;
3914
+ }
3915
+ function getTransferTargetPath(input) {
3916
+ if (input.relativePath === PACKAGE_JSON_RELATIVE_PATH2 || isVirtualRouteFile(input.relativePath) || isProjectLevelFile(input.relativePath)) {
3917
+ return null;
3918
+ }
3919
+ const componentLocalTargetPath = getComponentLocalTargetPath(input);
3920
+ if (componentLocalTargetPath) {
3921
+ return componentLocalTargetPath;
3922
+ }
3923
+ if (isManifestSupportFile(input.relativePath)) {
3924
+ return input.relativePath;
3925
+ }
3926
+ if (input.relativePath.startsWith(PUBLIC_PREFIX) && input.referencedPublicFiles.has(input.relativePath)) {
3927
+ return input.relativePath;
3928
+ }
3929
+ return null;
3930
+ }
3931
+ async function collectReferencedPublicFiles(input) {
3932
+ const referencedPublicFiles = /* @__PURE__ */ new Set();
3933
+ for (const relativePath of input.graphInternalFiles) {
3934
+ if (!input.manifestFileSet.has(relativePath)) {
3935
+ continue;
3936
+ }
3937
+ const sourcePath = path13.join(input.exportPath, relativePath);
3938
+ let content = "";
3939
+ try {
3940
+ content = await readFile7(sourcePath, "utf-8");
3941
+ } catch {
3942
+ continue;
3943
+ }
3944
+ for (const referencedFile of collectReferencedPublicAssetFiles(content)) {
3945
+ if (input.manifestFileSet.has(referencedFile)) {
3946
+ referencedPublicFiles.add(referencedFile);
3947
+ }
3948
+ }
3949
+ }
3950
+ return referencedPublicFiles;
3951
+ }
3952
+ function buildFileTransfers(input) {
3953
+ const sourceAreas = findComponentSourceAreas([...input.graphInternalFiles]);
3954
+ const transfers = [];
3955
+ const usedTargetPaths = /* @__PURE__ */ new Set();
3956
+ for (const relativePath of input.files) {
3957
+ const isGraphFile = input.graphInternalFiles.has(relativePath);
3958
+ const isReferencedPublicFile = input.referencedPublicFiles.has(relativePath);
3959
+ if (!isGraphFile && !isReferencedPublicFile) {
3960
+ continue;
3961
+ }
3962
+ const targetPath = getTransferTargetPath({
3963
+ relativePath,
3964
+ componentId: input.componentId,
3965
+ sourceAreas,
3966
+ referencedPublicFiles: input.referencedPublicFiles
3967
+ });
3968
+ if (!targetPath || usedTargetPaths.has(targetPath)) {
3969
+ continue;
3970
+ }
3971
+ usedTargetPaths.add(targetPath);
3972
+ transfers.push({
3973
+ sourcePath: relativePath,
3974
+ targetPath
3975
+ });
3976
+ }
3977
+ return transfers.sort((a, b) => a.targetPath.localeCompare(b.targetPath));
3792
3978
  }
3793
3979
  function toSkippedFile(targetPath, reason) {
3794
3980
  return {
@@ -3828,7 +4014,7 @@ function splitManifestFiles(input) {
3828
4014
  };
3829
4015
  }
3830
4016
  async function createConflictReportEntry2(input) {
3831
- const sourceBuffer = await readFile7(input.sourceFilePath);
4017
+ const sourceBuffer = input.sourceBuffer ?? await readFile7(input.sourceFilePath);
3832
4018
  let targetBuffer = null;
3833
4019
  try {
3834
4020
  targetBuffer = await readFile7(input.targetFilePath);
@@ -3896,7 +4082,7 @@ function buildMessage(input) {
3896
4082
  );
3897
4083
  }
3898
4084
  parts.push(
3899
- "The virtual component export page was skipped; manually insert the copied component into a real target page."
4085
+ `The virtual component export page was skipped; manually import ${input.componentImportPath} into a real target page.`
3900
4086
  );
3901
4087
  return parts.join(" ");
3902
4088
  }
@@ -3963,23 +4149,37 @@ async function copyRegistryComponentFromExport(input) {
3963
4149
  (filePath) => toProjectRelative(exportPath, filePath)
3964
4150
  )
3965
4151
  );
3966
- const exportableFileSet = new Set(
3967
- uniqueNormalizedManifestFiles(getSuccessfulExportableFiles(manifest))
4152
+ const referencedPublicFiles = await collectReferencedPublicFiles({
4153
+ exportPath,
4154
+ graphInternalFiles,
4155
+ manifestFileSet
4156
+ });
4157
+ const fileTransfers = buildFileTransfers({
4158
+ files: initialSelection.manifestFiles,
4159
+ componentId: normalizedComponentId,
4160
+ graphInternalFiles,
4161
+ referencedPublicFiles
4162
+ });
4163
+ const copyableSourceFiles = fileTransfers.map((transfer) => transfer.sourcePath);
4164
+ const copyableFiles = fileTransfers.map((transfer) => transfer.targetPath);
4165
+ const transferBySourcePath = new Map(
4166
+ fileTransfers.map((transfer) => [transfer.sourcePath, transfer])
4167
+ );
4168
+ const componentEntryTransfer = fileTransfers.find(
4169
+ (transfer) => initialSelection.componentEntryFiles.includes(transfer.sourcePath)
4170
+ );
4171
+ const componentImportPath = toImportPath(
4172
+ componentEntryTransfer?.targetPath ?? `${COMPONENT_SHARED_PREFIX}${normalizedComponentId}.tsx`
3968
4173
  );
3969
- const copyableFiles = initialSelection.manifestFiles.filter(
3970
- (relativePath) => graphInternalFiles.has(relativePath) || isManifestSupportFile(relativePath) || exportableFileSet.has(relativePath)
3971
- ).filter(
3972
- (relativePath) => relativePath !== PACKAGE_JSON_RELATIVE_PATH2 && !isVirtualRouteFile(relativePath)
3973
- ).sort((a, b) => a.localeCompare(b));
3974
4174
  const { manifestFiles, skippedFiles } = splitManifestFiles({
3975
4175
  files: initialSelection.manifestFiles,
3976
4176
  componentId: normalizedComponentId,
3977
- copyableFiles
4177
+ copyableFiles: copyableSourceFiles
3978
4178
  });
3979
4179
  const candidateFiles = await resolveManifestCandidateFiles({
3980
4180
  exportPath,
3981
4181
  manifestOwnerLabel: `registry component "${normalizedComponentId}"`,
3982
- files: copyableFiles,
4182
+ files: copyableSourceFiles,
3983
4183
  requireExisting: false
3984
4184
  });
3985
4185
  for (const sourceFilePath of candidateFiles) {
@@ -3989,9 +4189,21 @@ async function copyRegistryComponentFromExport(input) {
3989
4189
  missingManifestFiles.add(relativeToExport);
3990
4190
  continue;
3991
4191
  }
3992
- const targetFilePath = path13.join(input.projectRoot, relativeToExport);
4192
+ const transfer = transferBySourcePath.get(relativeToExport);
4193
+ if (!transfer) {
4194
+ continue;
4195
+ }
4196
+ const targetRelativePath = transfer.targetPath;
4197
+ const targetFilePath = path13.join(input.projectRoot, targetRelativePath);
3993
4198
  ensureSafeTargetPath(input.projectRoot, targetFilePath);
3994
4199
  const sourceBuffer = await readFile7(sourceFilePath);
4200
+ const rewrittenSourceBuffer = isBinaryBuffer(sourceBuffer) ? sourceBuffer : Buffer.from(
4201
+ rewriteComponentLocalImports(
4202
+ sourceBuffer.toString("utf-8"),
4203
+ fileTransfers
4204
+ ),
4205
+ "utf-8"
4206
+ );
3995
4207
  let targetBuffer = null;
3996
4208
  try {
3997
4209
  targetBuffer = await readFile7(targetFilePath);
@@ -4000,19 +4212,20 @@ async function copyRegistryComponentFromExport(input) {
4000
4212
  }
4001
4213
  if (!targetBuffer) {
4002
4214
  await ensureDir(path13.dirname(targetFilePath));
4003
- await writeFile6(targetFilePath, sourceBuffer);
4004
- newFiles.push(relativeToExport);
4215
+ await writeFile6(targetFilePath, rewrittenSourceBuffer);
4216
+ newFiles.push(targetRelativePath);
4005
4217
  continue;
4006
4218
  }
4007
- if (sourceBuffer.equals(targetBuffer)) {
4008
- identicalFiles.push(relativeToExport);
4219
+ if (rewrittenSourceBuffer.equals(targetBuffer)) {
4220
+ identicalFiles.push(targetRelativePath);
4009
4221
  continue;
4010
4222
  }
4011
4223
  const entry = await createConflictReportEntry2({
4012
4224
  sourceFilePath,
4013
4225
  targetFilePath,
4014
4226
  exportPath,
4015
- projectRoot: input.projectRoot
4227
+ projectRoot: input.projectRoot,
4228
+ sourceBuffer: rewrittenSourceBuffer
4016
4229
  });
4017
4230
  if (entry) {
4018
4231
  conflictReportEntries.push(entry);
@@ -4053,6 +4266,7 @@ async function copyRegistryComponentFromExport(input) {
4053
4266
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
4054
4267
  exportId,
4055
4268
  componentId: normalizedComponentId,
4269
+ componentImportPath,
4056
4270
  manifestFiles,
4057
4271
  copyableFiles,
4058
4272
  skippedFiles,
@@ -4074,6 +4288,7 @@ async function copyRegistryComponentFromExport(input) {
4074
4288
  status,
4075
4289
  message: buildMessage({
4076
4290
  componentId: normalizedComponentId,
4291
+ componentImportPath,
4077
4292
  status,
4078
4293
  reportPath,
4079
4294
  newFiles: sortedNewFiles,
@@ -4089,6 +4304,7 @@ async function copyRegistryComponentFromExport(input) {
4089
4304
  exportPath,
4090
4305
  manifestPath,
4091
4306
  component: manifest.component,
4307
+ componentImportPath,
4092
4308
  manifestFiles,
4093
4309
  copyableFiles,
4094
4310
  newFiles: sortedNewFiles,
@@ -4111,7 +4327,7 @@ async function copyRegistryComponentFromExport(input) {
4111
4327
  },
4112
4328
  guidance: {
4113
4329
  artifacts: guidanceArtifacts,
4114
- requiredActions: "Do not install the skipped virtual component export page as a route. Manually import the copied component/support files into a real target page, install newly added dependencies, and resolve any reported conflicts or dependency version mismatches before treating the registry component transfer as complete."
4330
+ requiredActions: `Do not install the skipped virtual component export page as a route. Manually import ${componentImportPath} into a real target page, install newly added dependencies, and resolve any reported conflicts or dependency version mismatches before treating the registry component transfer as complete.`
4115
4331
  }
4116
4332
  };
4117
4333
  }
@@ -5594,10 +5810,12 @@ WHEN TO USE:
5594
5810
  BEHAVIOR:
5595
5811
  - Reads the component sidecar manifest saved by create_component_export.
5596
5812
  - Validates that manifest.component.componentId matches input.componentId.
5597
- - Copies files strictly from page.manifest.files in the component sidecar manifest.
5813
+ - Copies only the selected registry component import graph, narrowly referenced public assets, and safe support files from the component sidecar manifest/export.
5814
+ - Remaps component-local files into src/components/shared/** and returns componentImportPath for manual insertion.
5598
5815
  - Skips virtual route files that include __primeui-component-export, because those are reference/insertion hints and must not be installed as normal app routes.
5816
+ - Skips app/search/layout/header/footer/env/project-shell files instead of copying whole exportable buckets.
5599
5817
  - Never copies package.json directly. package.json is used only to add missing dependency entries and report dependency version conflicts.
5600
- - Preserves export-relative paths for copied files in this first version.
5818
+ - Keeps safe support files on their natural target paths, such as src/components/ui/**, src/lib/**, src/types/**, and src/contexts/**.
5601
5819
  - Never overwrites existing conflicting files.
5602
5820
  - Writes full conflict details to .primeui/temp/exports/[exportId].copy-registry-component-report-[copyId].json.
5603
5821
  - Reports copied files, identical files, conflicts, skipped files, dependency additions, dependency version conflicts, missing manifest files, and manual insertion guidance.
@@ -5628,11 +5846,14 @@ ${WORKFLOW_SUMMARY}`,
5628
5846
  component: componentExportComponentSchema.describe(
5629
5847
  "Component metadata from the validated component sidecar manifest."
5630
5848
  ),
5849
+ componentImportPath: z4.string().describe(
5850
+ "Canonical import path for the copied registry component entrypoint, for example @/components/shared/hero--pricing."
5851
+ ),
5631
5852
  manifestFiles: z4.array(z4.string()).describe(
5632
- "Normalized page.manifest.files from the component sidecar manifest."
5853
+ "Normalized component sidecar manifest files considered by the copy service."
5633
5854
  ),
5634
5855
  copyableFiles: z4.array(z4.string()).describe(
5635
- "Manifest files considered for copying after filtering virtual route files and package.json."
5856
+ "Relative target paths considered for copying after component remapping and safety filtering."
5636
5857
  ),
5637
5858
  newFiles: z4.array(z4.string()).describe("Relative target paths for new files copied."),
5638
5859
  identicalFiles: z4.array(z4.string()).describe("Relative target paths for existing byte-identical files."),