vite-plugin-prism-design 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +26 -16
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -21,17 +21,18 @@ function findWidgetScript() {
21
21
  return null;
22
22
  }
23
23
  function findAgentCli() {
24
- const candidates = [
25
- // Monorepo sibling
26
- path.resolve(new URL(import.meta.url).pathname, "../../../agent/dist/cli.js"),
27
- // npm global / local
28
- "prism-design-agent"
29
- ];
30
- for (const c of candidates) {
31
- try {
32
- if (path.isAbsolute(c) && fs.existsSync(c)) return c;
33
- } catch {
34
- }
24
+ try {
25
+ const agentPkg = require2.resolve("prism-design-agent/package.json");
26
+ const agentDir = path.dirname(agentPkg);
27
+ const cliFile = path.join(agentDir, "dist", "cli.js");
28
+ if (fs.existsSync(cliFile)) return cliFile;
29
+ } catch {
30
+ }
31
+ try {
32
+ const thisDir = path.dirname(new URL(import.meta.url).pathname);
33
+ const candidate = path.resolve(thisDir, "../../agent/dist/cli.js");
34
+ if (fs.existsSync(candidate)) return candidate;
35
+ } catch {
35
36
  }
36
37
  return null;
37
38
  }
@@ -111,8 +112,8 @@ function prismDesign(options = {}) {
111
112
  agentProcess = null;
112
113
  });
113
114
  const actualPort = await portPromise;
114
- agentUrl = `http://localhost:${actualPort}`;
115
- config.logger.info(`[PrismDesign] Agent ready at ${agentUrl}`);
115
+ agentUrl = `__AGENT_PORT__:${actualPort}`;
116
+ config.logger.info(`[PrismDesign] Agent ready on port ${actualPort}`);
116
117
  } else {
117
118
  config.logger.warn("[PrismDesign] Agent CLI not found. Install prism-design-agent or run agent manually.");
118
119
  config.logger.info("[PrismDesign] Widget will show connection form for manual URL input.");
@@ -130,10 +131,19 @@ function prismDesign(options = {}) {
130
131
  },
131
132
  transformIndexHtml() {
132
133
  const initOptions = {};
133
- if (agentUrl) initOptions.agentUrl = agentUrl;
134
134
  if (position !== "bottom-right") initOptions.position = position;
135
135
  if (locale) initOptions.locale = locale;
136
- const optionsJson = JSON.stringify(initOptions);
136
+ let initScript;
137
+ if (agentUrl.startsWith("__AGENT_PORT__:")) {
138
+ const port = agentUrl.split(":")[1];
139
+ const optionsJson = JSON.stringify(initOptions);
140
+ initScript = `(function(){var o=${optionsJson};o.agentUrl="http://"+location.hostname+":${port}";PrismDesignWidget.init(o)})();`;
141
+ } else if (agentUrl) {
142
+ initOptions.agentUrl = agentUrl;
143
+ initScript = `PrismDesignWidget.init(${JSON.stringify(initOptions)});`;
144
+ } else {
145
+ initScript = `PrismDesignWidget.init(${JSON.stringify(initOptions)});`;
146
+ }
137
147
  return [
138
148
  {
139
149
  tag: "script",
@@ -142,7 +152,7 @@ function prismDesign(options = {}) {
142
152
  },
143
153
  {
144
154
  tag: "script",
145
- children: `PrismDesignWidget.init(${optionsJson});`,
155
+ children: initScript,
146
156
  injectTo: "body"
147
157
  }
148
158
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-prism-design",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -9,6 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "dependencies": {
12
+ "prism-design-agent": "0.2.2",
12
13
  "prism-design-widget": "0.1.2"
13
14
  },
14
15
  "peerDependencies": {