@powerhousedao/builder-tools 0.9.5-dev.0 → 0.9.5-dev.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.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../connect-studio/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAIzE,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAUjE;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,UAAQ,QAS/D;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,QAgCpD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAStE"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../connect-studio/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAIzE,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAUjE;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,UAAQ,QAS/D;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,QAiCpD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAStE"}
@@ -29,6 +29,7 @@ export function removeBase64EnvValues(appPath) {
29
29
  return;
30
30
  }
31
31
  // Use regex to replace the dynamic Base64 values with empty strings
32
+ // TODO is this needed?
32
33
  const modifiedData = data
33
34
  .replace(/"LOCAL_DOCUMENT_MODELS":\s*".*?",/, `"LOCAL_DOCUMENT_MODELS": "",`)
34
35
  .replace(/"LOCAL_DOCUMENT_EDITORS":\s*".*?"/, `"LOCAL_DOCUMENT_EDITORS": ""`);
@@ -1,8 +1,7 @@
1
1
  export { backupIndexHtml, removeBase64EnvValues } from "./helpers.js";
2
- export { hmr } from "./hmr.js";
3
2
  export { startConnectStudio } from "./studio.js";
4
3
  export type { ConnectStudioOptions } from "./types.js";
5
- export { externalIds, getStudioConfig } from "./vite-plugins/base.js";
4
+ export { externalIds } from "./vite-plugins/base.js";
6
5
  export { viteLoadExternalPackages } from "./vite-plugins/external-packages.js";
7
6
  export { generateImportMapPlugin } from "./vite-plugins/importmap.js";
8
7
  export { viteConnectDevStudioPlugin } from "./vite-plugins/studio.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../connect-studio/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../connect-studio/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1,7 +1,6 @@
1
1
  export { backupIndexHtml, removeBase64EnvValues } from "./helpers.js";
2
- export { hmr } from "./hmr.js";
3
2
  export { startConnectStudio } from "./studio.js";
4
- export { externalIds, getStudioConfig } from "./vite-plugins/base.js";
3
+ export { externalIds } from "./vite-plugins/base.js";
5
4
  export { viteLoadExternalPackages } from "./vite-plugins/external-packages.js";
6
5
  export { generateImportMapPlugin } from "./vite-plugins/importmap.js";
7
6
  export { viteConnectDevStudioPlugin } from "./vite-plugins/studio.js";
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../connect-studio/server.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAkErD,wBAAsB,WAAW,CAC/B,OAAO,GAAE,kBAER,iBAoFF"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../connect-studio/server.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAiErD,wBAAsB,WAAW,CAC/B,OAAO,GAAE,kBAER,iBAyFF"}
@@ -1,4 +1,6 @@
1
+ import tailwindcss from "@tailwindcss/vite";
1
2
  import basicSsl from "@vitejs/plugin-basic-ssl";
3
+ import viteReact from "@vitejs/plugin-react";
2
4
  import { exec } from "node:child_process";
3
5
  import fs from "node:fs";
4
6
  import { createRequire } from "node:module";
@@ -6,7 +8,6 @@ import { join, resolve } from "node:path";
6
8
  import { createLogger, createServer, } from "vite";
7
9
  import { viteEnvs } from "vite-envs";
8
10
  import { backupIndexHtml, copyConnect, removeBase64EnvValues, } from "./helpers.js";
9
- import { getStudioConfig } from "./vite-plugins/base.js";
10
11
  import { viteLoadExternalPackages } from "./vite-plugins/external-packages.js";
11
12
  import { generateImportMapPlugin } from "./vite-plugins/importmap.js";
12
13
  import { viteConnectDevStudioPlugin } from "./vite-plugins/studio.js";
@@ -81,14 +82,13 @@ export async function startServer(options = {
81
82
  const OPEN_BROWSER = typeof process.env.OPEN_BROWSER === "string"
82
83
  ? process.env.OPEN_BROWSER === "true"
83
84
  : false;
84
- const studioConfig = getStudioConfig();
85
85
  // needed for viteEnvs
86
86
  if (!fs.existsSync(join(studioPath, "src"))) {
87
87
  fs.mkdirSync(join(studioPath, "src"));
88
88
  }
89
89
  process.env.PH_CONNECT_STUDIO_MODE = "true";
90
90
  process.env.PH_CONNECT_CLI_VERSION = options.phCliVersion;
91
- const computedEnv = { ...studioConfig, LOG_LEVEL: options.logLevel };
91
+ const computedEnv = { LOG_LEVEL: options.logLevel };
92
92
  const config = {
93
93
  customLogger: logger,
94
94
  configFile: false,
@@ -113,8 +113,14 @@ export async function startServer(options = {
113
113
  dedupe: ["@powerhousedao/reactor-browser"],
114
114
  },
115
115
  plugins: [
116
+ tailwindcss(),
117
+ viteReact({
118
+ // includes js|jsx|ts|tsx)$/ inside projectRoot
119
+ include: [join(projectRoot, "**/*.(js|jsx|ts|tsx)")],
120
+ exclude: ["node_modules", join(studioPath, "assets/*.js")],
121
+ }),
116
122
  viteConnectDevStudioPlugin(true, studioPath),
117
- viteLoadExternalPackages(options.packages, studioPath, true),
123
+ viteLoadExternalPackages(true, options.packages, studioPath),
118
124
  viteEnvs({
119
125
  declarationFile: join(studioPath, ".env"),
120
126
  computedEnv,
@@ -1,15 +1,6 @@
1
1
  import type { Package } from "resolve.exports";
2
2
  import { type Plugin, type PluginOption } from "vite";
3
3
  export declare const externalIds: RegExp[];
4
- export declare const LOCAL_DOCUMENT_MODELS_IMPORT = "LOCAL_DOCUMENT_MODELS";
5
- export declare const LOCAL_DOCUMENT_EDITORS_IMPORT = "LOCAL_DOCUMENT_EDITORS";
6
- export declare const HMR_MODULE_IMPORT = "@powerhousedao/builder-tools/connect-studio/hmr";
7
- export declare const STUDIO_IMPORTS: readonly ["LOCAL_DOCUMENT_MODELS", "LOCAL_DOCUMENT_EDITORS", "@powerhousedao/builder-tools/connect-studio/hmr"];
8
- export declare function getStudioConfig(env?: Record<string, string>): {
9
- [LOCAL_DOCUMENT_MODELS_IMPORT]?: string;
10
- [LOCAL_DOCUMENT_EDITORS_IMPORT]?: string;
11
- LOAD_EXTERNAL_PACKAGES?: string;
12
- };
13
4
  export declare function viteIgnoreStaticImport(_importKeys: (string | RegExp | false | undefined)[]): Plugin;
14
5
  export declare function viteReplaceImports(imports: Record<string, string>): PluginOption;
15
6
  export declare function findPackageJson(packageName: string): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/base.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,YAAY,EAElB,MAAM,MAAM,CAAC;AAGd,eAAO,MAAM,WAAW,UAIvB,CAAC;AAEF,eAAO,MAAM,4BAA4B,0BAA0B,CAAC;AACpE,eAAO,MAAM,6BAA6B,2BAA2B,CAAC;AACtE,eAAO,MAAM,iBAAiB,oDACqB,CAAC;AAEpD,eAAO,MAAM,cAAc,iHAIjB,CAAC;AAEX,wBAAgB,eAAe,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IAC7D,CAAC,4BAA4B,CAAC,CAAC,EAAE,MAAM,CAAC;IACxC,CAAC,6BAA6B,CAAC,CAAC,EAAE,MAAM,CAAC;IACzC,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC,CA8BA;AAKD,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC,EAAE,GACnD,MAAM,CAgER;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,YAAY,CAgDd;AAED,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM;iBAsBT,OAAO;;GAOtD"}
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/base.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAGd,eAAO,MAAM,WAAW,UAIvB,CAAC;AAKF,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC,EAAE,GACnD,MAAM,CAgER;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,YAAY,CAgDd;AAED,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM;iBAsBT,OAAO;;GAOtD"}
@@ -1,43 +1,13 @@
1
1
  import fs from "fs/promises";
2
2
  import MagicString from "magic-string";
3
3
  import { createRequire } from "node:module";
4
- import path, { basename, dirname } from "node:path";
5
- import { normalizePath, } from "vite";
4
+ import { basename, dirname } from "node:path";
6
5
  // matches @powerhousedao/connect, react, react-dom and all their sub-imports like react-dom/client
7
6
  export const externalIds = [
8
7
  /^react(-dom)?(\/.*)?$/,
9
8
  /^@powerhousedao\/reactor-browser(\/.*)?$/,
10
9
  /^node:.*$/,
11
10
  ];
12
- export const LOCAL_DOCUMENT_MODELS_IMPORT = "LOCAL_DOCUMENT_MODELS";
13
- export const LOCAL_DOCUMENT_EDITORS_IMPORT = "LOCAL_DOCUMENT_EDITORS";
14
- export const HMR_MODULE_IMPORT = "@powerhousedao/builder-tools/connect-studio/hmr";
15
- export const STUDIO_IMPORTS = [
16
- LOCAL_DOCUMENT_MODELS_IMPORT,
17
- LOCAL_DOCUMENT_EDITORS_IMPORT,
18
- HMR_MODULE_IMPORT,
19
- ];
20
- export function getStudioConfig(env) {
21
- const config = {};
22
- const LOCAL_DOCUMENT_MODELS = process.env.LOCAL_DOCUMENT_MODELS ?? env?.LOCAL_DOCUMENT_MODELS;
23
- const LOCAL_DOCUMENT_EDITORS = process.env.LOCAL_DOCUMENT_EDITORS ?? env?.LOCAL_DOCUMENT_EDITORS;
24
- const LOCAL_DOCUMENT_MODELS_PATH = LOCAL_DOCUMENT_MODELS
25
- ? path.resolve(process.cwd(), LOCAL_DOCUMENT_MODELS)
26
- : undefined;
27
- const LOCAL_DOCUMENT_EDITORS_PATH = LOCAL_DOCUMENT_EDITORS
28
- ? path.resolve(process.cwd(), LOCAL_DOCUMENT_EDITORS)
29
- : undefined;
30
- if (LOCAL_DOCUMENT_MODELS_PATH) {
31
- config[LOCAL_DOCUMENT_MODELS_IMPORT] = normalizePath(LOCAL_DOCUMENT_MODELS_PATH);
32
- }
33
- if (LOCAL_DOCUMENT_EDITORS_PATH) {
34
- config[LOCAL_DOCUMENT_EDITORS_IMPORT] = normalizePath(LOCAL_DOCUMENT_EDITORS_PATH);
35
- }
36
- if (typeof process.env.LOAD_EXTERNAL_PACKAGES !== "undefined") {
37
- config.LOAD_EXTERNAL_PACKAGES = process.env.LOAD_EXTERNAL_PACKAGES;
38
- }
39
- return config;
40
- }
41
11
  // https://github.com/vitejs/vite/issues/6393#issuecomment-1006819717
42
12
  // vite dev server doesn't support setting dependencies as external
43
13
  // as when building the app.
@@ -1,5 +1,6 @@
1
1
  import { type PluginOption } from "vite";
2
2
  export declare const EXTERNAL_PACKAGES_IMPORT = "PH:EXTERNAL_PACKAGES";
3
3
  export declare const IMPORT_SCRIPT_FILE = "external-packages.js";
4
- export declare const viteLoadExternalPackages: (packages: string[] | undefined, targetDir: string, hmr?: boolean) => PluginOption[];
4
+ export declare const LOCAL_PACKAGE_ID = "ph:local-package";
5
+ export declare const viteLoadExternalPackages: (localPackage: boolean, packages: string[] | undefined, targetDir: string) => PluginOption[];
5
6
  //# sourceMappingURL=external-packages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-packages.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/external-packages.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAOzC,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAC/D,eAAO,MAAM,kBAAkB,yBAAyB,CAAC;AAqCzD,eAAO,MAAM,wBAAwB,GACnC,UAAU,MAAM,EAAE,GAAG,SAAS,EAC9B,WAAW,MAAM,EACjB,aAAW,KACV,YAAY,EA8Cd,CAAC"}
1
+ {"version":3,"file":"external-packages.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/external-packages.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,MAAM,CAAC;AAE7D,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAC/D,eAAO,MAAM,kBAAkB,yBAAyB,CAAC;AACzD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAmGnD,eAAO,MAAM,wBAAwB,GACnC,cAAc,OAAO,EACrB,UAAU,MAAM,EAAE,GAAG,SAAS,EAC9B,WAAW,MAAM,KAChB,YAAY,EAwDd,CAAC"}
@@ -1,18 +1,16 @@
1
1
  import { getConfig } from "@powerhousedao/config/powerhouse";
2
+ import { exec } from "node:child_process";
2
3
  import fs from "node:fs";
3
- import { join } from "node:path";
4
- import { viteIgnoreStaticImport, viteReplaceImports } from "./base.js";
5
- // TODO use config path?
6
- const __dirname = join(process.cwd(), ".ph/");
7
- // import.meta.dirname || dirname(fileURLToPath(import.meta.url));
4
+ import { dirname, join } from "node:path";
8
5
  export const EXTERNAL_PACKAGES_IMPORT = "PH:EXTERNAL_PACKAGES";
9
6
  export const IMPORT_SCRIPT_FILE = "external-packages.js";
10
- function generateImportScript(packages, targetDir) {
7
+ export const LOCAL_PACKAGE_ID = "ph:local-package";
8
+ function generateImportScript(packages, targetPath, localPackage) {
11
9
  // create file if it doesn't exist, also create path if it doesn't exist (recursive)
10
+ const targetDir = dirname(targetPath);
12
11
  if (!fs.existsSync(targetDir)) {
13
12
  fs.mkdirSync(targetDir, { recursive: true });
14
13
  }
15
- const scriptPath = join(targetDir, IMPORT_SCRIPT_FILE);
16
14
  const imports = [];
17
15
  const moduleNames = [];
18
16
  let counter = 0;
@@ -23,50 +21,105 @@ function generateImportScript(packages, targetDir) {
23
21
  imports.push(`import '${packageName}/style.css';`);
24
22
  counter++;
25
23
  }
24
+ const exports = moduleNames.map((name, index) => `{
25
+ id: "${packages[index]}",
26
+ ...${name},
27
+ }`);
28
+ if (localPackage) {
29
+ const moduleName = `module${counter}`;
30
+ imports.push(`import * as ${moduleName} from '../../index.js';`);
31
+ imports.push(`import '../../style.css';`);
32
+ exports.push(`{
33
+ id: "${LOCAL_PACKAGE_ID}",
34
+ ...${moduleName},
35
+ }`);
36
+ }
26
37
  const exportStatement = `export default [
27
- ${moduleNames
28
- .map((name, index) => `{
29
- id: "${packages[index]}",
30
- ...${name},
31
- }`)
32
- .join(",\n")}
38
+ ${exports.join(",\n")}
33
39
  ];`;
34
40
  const fileContent = `${imports.join("\n")}\n\n${exportStatement}`;
35
- fs.writeFileSync(scriptPath, fileContent);
36
- return scriptPath;
41
+ fs.writeFileSync(targetPath, fileContent);
42
+ return targetPath;
37
43
  }
38
- export const viteLoadExternalPackages = (packages, targetDir, hmr = false) => {
39
- if (!packages?.length && !hmr) {
40
- return [viteIgnoreStaticImport([EXTERNAL_PACKAGES_IMPORT])];
41
- }
42
- const importScriptPath = generateImportScript(packages ?? [], targetDir);
43
- process.env.LOAD_EXTERNAL_PACKAGES = "true";
44
+ const handleExternalPackageEvents = (server) => {
45
+ server.ws.on("studio:add-external-package", (data, client) => {
46
+ const { name } = data;
47
+ const installProcess = exec(`ph install ${name}`, {
48
+ cwd: process.cwd(),
49
+ }, (error) => {
50
+ if (error) {
51
+ console.error(`\t[${name}]: ${error.message}`);
52
+ }
53
+ else {
54
+ server.ws.send("studio:external-package-added", {
55
+ name,
56
+ });
57
+ }
58
+ });
59
+ installProcess.stdout?.on("data", (data) => {
60
+ console.log(`\t[${name}]: ${data.toString().trim()}`);
61
+ });
62
+ console.log("Installing external package:", name);
63
+ });
64
+ server.ws.on("studio:remove-external-package", (data, client) => {
65
+ const { name } = data;
66
+ const uninstallProcess = exec(`ph uninstall ${name}`, {
67
+ cwd: process.cwd(),
68
+ }, (error) => {
69
+ if (error) {
70
+ console.error(`\t[${name}]: ${error.message}`);
71
+ }
72
+ else {
73
+ server.ws.send("studio:external-package-removed", {
74
+ name,
75
+ });
76
+ }
77
+ });
78
+ uninstallProcess.stdout?.on("data", (data) => {
79
+ console.log(`\t[${name}]: ${data.toString().trim()}`);
80
+ });
81
+ console.log("Removing external package:", name);
82
+ });
83
+ };
84
+ export const viteLoadExternalPackages = (localPackage, packages, targetDir) => {
85
+ const importPath = join(targetDir, IMPORT_SCRIPT_FILE);
44
86
  return [
45
- viteReplaceImports({ [EXTERNAL_PACKAGES_IMPORT]: importScriptPath }),
46
- hmr && {
47
- name: "vite-plugin-studio-external-packages",
48
- handleHotUpdate({ file, server, modules }) {
87
+ {
88
+ name: "vite-plugin-ph-external-packages",
89
+ closeBundle() {
90
+ generateImportScript(packages ?? [], importPath, localPackage);
91
+ },
92
+ configureServer(server) {
93
+ generateImportScript(packages ?? [], importPath, localPackage);
94
+ handleExternalPackageEvents(server);
95
+ },
96
+ handleHotUpdate({ file, server, modules, timestamp }) {
49
97
  if (file.endsWith("powerhouse.config.json")) {
50
98
  const config = getConfig(file);
51
- generateImportScript(config.packages?.map((p) => p.packageName) ?? [], targetDir);
99
+ generateImportScript(config.packages?.map((p) => p.packageName) ?? [], importPath, true);
52
100
  config.packages?.forEach((pkg) => console.log("-> Loading package:", pkg.packageName));
53
- const module = server.moduleGraph.getModuleById(IMPORT_SCRIPT_FILE);
101
+ const module = server.moduleGraph.getModuleById(importPath);
54
102
  if (module) {
55
103
  server.moduleGraph.invalidateModule(module);
56
104
  return [module].concat(...module.importers.values());
57
105
  }
58
106
  }
59
- else if (file === IMPORT_SCRIPT_FILE) {
107
+ else if (file === importPath) {
60
108
  modules
61
- .filter((module) => module.id === IMPORT_SCRIPT_FILE)
109
+ .filter((module) => module.id === importPath)
62
110
  .forEach((module) => {
63
111
  server.ws.send("studio:external-packages-updated", {
64
112
  url: module.url,
65
- timestamp: module.lastHMRTimestamp,
113
+ timestamp: timestamp,
66
114
  });
67
115
  });
68
116
  return modules;
69
117
  }
118
+ else if (!file.startsWith(targetDir) &&
119
+ !file.includes("node_modules")) {
120
+ const config = getConfig(file);
121
+ generateImportScript(config.packages?.map((p) => p.packageName) ?? [], importPath, localPackage);
122
+ }
70
123
  return modules;
71
124
  },
72
125
  },
@@ -1,4 +1,3 @@
1
- import { type PluginOption, type ViteDevServer } from "vite";
2
- export declare function watchLocalFiles(server: ViteDevServer, documentModelsPath?: string, editorsPath?: string): void;
1
+ import { type PluginOption } from "vite";
3
2
  export declare function viteConnectDevStudioPlugin(enabled: boolean | undefined, connectPath: string, env?: Record<string, string>): PluginOption[];
4
3
  //# sourceMappingURL=studio.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/studio.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAa7D,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,WAAW,CAAC,EAAE,MAAM,QA8DrB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,qBAAQ,EACf,WAAW,EAAE,MAAM,EACnB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,YAAY,EAAE,CAkFhB"}
1
+ {"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/studio.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAGzC,wBAAgB,0BAA0B,CACxC,OAAO,qBAAQ,EACf,WAAW,EAAE,MAAM,EACnB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,YAAY,EAAE,CAsChB"}
@@ -1,64 +1,7 @@
1
1
  import fs from "node:fs";
2
- import path, { join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { externalIds, getStudioConfig, HMR_MODULE_IMPORT, LOCAL_DOCUMENT_EDITORS_IMPORT, LOCAL_DOCUMENT_MODELS_IMPORT, STUDIO_IMPORTS, viteIgnoreStaticImport, viteReplaceImports, } from "./base.js";
5
- import { viteLoadHMRModule } from "./hmr.js";
6
- export function watchLocalFiles(server, documentModelsPath, editorsPath) {
7
- const debounce = (callback, delay = 100) => {
8
- let timeout;
9
- return function () {
10
- clearTimeout(timeout);
11
- timeout = setTimeout(() => {
12
- callback();
13
- }, delay);
14
- };
15
- };
16
- const refreshModelsWithDebounce = debounce(() => {
17
- console.log(`Local document models changed, reloading Connect...`);
18
- server.ws.send({
19
- type: "full-reload",
20
- path: "*",
21
- });
22
- });
23
- const refreshEditorsWithDebounce = debounce(() => {
24
- console.log(`Local document editors changed, reloading Connect...`);
25
- server.ws.send({
26
- type: "full-reload",
27
- path: "*",
28
- });
29
- });
30
- if (documentModelsPath) {
31
- // Use fs to watch the file and trigger a server reload when it changes
32
- console.log(`Watching local document models at '${documentModelsPath}'...`);
33
- try {
34
- fs.watch(documentModelsPath, {
35
- recursive: true,
36
- }, (event, filename) => {
37
- refreshModelsWithDebounce();
38
- });
39
- }
40
- catch (e) {
41
- console.error("Error watching local document models", e);
42
- }
43
- }
44
- if (editorsPath) {
45
- console.log(`Watching local document editors at '${editorsPath}'...`);
46
- try {
47
- fs.watch(editorsPath, {
48
- recursive: true,
49
- }, (event, filename) => {
50
- refreshEditorsWithDebounce();
51
- });
52
- }
53
- catch (e) {
54
- console.error("Error watching local document models", e);
55
- }
56
- }
57
- }
2
+ import { join } from "node:path";
3
+ import { externalIds, viteIgnoreStaticImport } from "./base.js";
58
4
  export function viteConnectDevStudioPlugin(enabled = false, connectPath, env) {
59
- const studioConfig = getStudioConfig(env);
60
- const localDocumentModelsPath = studioConfig[LOCAL_DOCUMENT_MODELS_IMPORT];
61
- const localDocumentEditorsPath = studioConfig[LOCAL_DOCUMENT_EDITORS_IMPORT];
62
5
  return [
63
6
  enabled &&
64
7
  viteIgnoreStaticImport([
@@ -67,19 +10,6 @@ export function viteConnectDevStudioPlugin(enabled = false, connectPath, env) {
67
10
  "@powerhousedao/reactor-browser",
68
11
  ...externalIds,
69
12
  ]),
70
- localDocumentModelsPath
71
- ? viteReplaceImports({
72
- [LOCAL_DOCUMENT_MODELS_IMPORT]: localDocumentModelsPath,
73
- })
74
- : viteIgnoreStaticImport([LOCAL_DOCUMENT_MODELS_IMPORT]),
75
- localDocumentEditorsPath
76
- ? viteReplaceImports({
77
- [LOCAL_DOCUMENT_EDITORS_IMPORT]: localDocumentEditorsPath,
78
- })
79
- : viteIgnoreStaticImport([LOCAL_DOCUMENT_EDITORS_IMPORT]),
80
- enabled
81
- ? viteLoadHMRModule(connectPath)
82
- : viteIgnoreStaticImport([HMR_MODULE_IMPORT]),
83
13
  {
84
14
  name: "vite-plugin-connect-dev-studio",
85
15
  enforce: "pre",
@@ -93,35 +23,16 @@ export function viteConnectDevStudioPlugin(enabled = false, connectPath, env) {
93
23
  if (!Array.isArray(config.build.rollupOptions.external)) {
94
24
  config.build.rollupOptions.external = [];
95
25
  }
96
- const buildStudioExternals = enabled
97
- ? [...externalIds, ...STUDIO_IMPORTS]
98
- : STUDIO_IMPORTS;
99
- config.build.rollupOptions.external.push(...buildStudioExternals);
26
+ if (enabled) {
27
+ config.build.rollupOptions.external.push(...externalIds);
28
+ }
100
29
  },
101
30
  closeBundle() {
102
31
  if (!enabled) {
103
- fs.copyFileSync(fileURLToPath(import.meta.resolve("../hmr.js")), join(connectPath, "hmr.js"));
104
32
  // Copy the .env file to the dist folder
105
33
  fs.copyFileSync(join(connectPath, "../.env"), join(connectPath, ".env"));
106
34
  }
107
35
  },
108
- configureServer(server) {
109
- watchLocalFiles(server, localDocumentModelsPath, localDocumentEditorsPath);
110
- },
111
- transformIndexHtml(html) {
112
- if (!enabled || html.includes("editors/style.css"))
113
- return;
114
- return [
115
- {
116
- tag: "link",
117
- attrs: {
118
- type: "text/css",
119
- rel: "stylesheet",
120
- href: path.join(connectPath, "../../editors/style.css"),
121
- },
122
- },
123
- ];
124
- },
125
36
  },
126
37
  ];
127
38
  }