@lasso-ai/cli 1.0.11 → 1.0.12
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/README.md +4 -0
- package/dist/cli/index.js +8 -0
- package/dist/cli/next-config.d.ts +8 -0
- package/dist/cli/next-config.js +45 -0
- package/dist/cli/project.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -217,6 +217,10 @@ project is served at `http://app.lasso:<port>` or the secure
|
|
|
217
217
|
domain (reuse, generate, or change one); never duplicates.
|
|
218
218
|
- `lasso unregister [domain]` — remove the current directory’s `.lasso`
|
|
219
219
|
registration, or pass a domain explicitly.
|
|
220
|
+
|
|
221
|
+
For Next.js projects, `lasso init` and `lasso register` automatically add the
|
|
222
|
+
project’s `.lasso` domain to `allowedDevOrigins` in `next.config.*`, allowing
|
|
223
|
+
HMR and development assets to work through the secure Host URL.
|
|
220
224
|
- `lasso projects` — list registered domains and running state.
|
|
221
225
|
- `lasso daemon install/uninstall` — attach a macOS LaunchAgent (auto-start on
|
|
222
226
|
login) and configure the system DNS resolver so bare `app.lasso` works.
|
package/dist/cli/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const paths_1 = require("./host/paths");
|
|
|
19
19
|
const install_1 = require("./host/install");
|
|
20
20
|
const client_1 = require("./host/client");
|
|
21
21
|
const registry_1 = require("./host/registry");
|
|
22
|
+
const next_config_1 = require("./next-config");
|
|
22
23
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
23
24
|
const VERSION = package_json_1.default.version;
|
|
24
25
|
const program = new commander_1.Command();
|
|
@@ -279,6 +280,13 @@ program.command("register [domain]")
|
|
|
279
280
|
console.log(chalk_1.default.dim(` Added domain to ${project_1.LASSO_CONFIG_FILE}.`));
|
|
280
281
|
}
|
|
281
282
|
}
|
|
283
|
+
if ((0, framework_1.detectFramework)(cwd) === "next") {
|
|
284
|
+
const injected = (0, next_config_1.ensureNextAllowedDevOrigin)(cwd, domain);
|
|
285
|
+
if (!injected.ok)
|
|
286
|
+
console.warn(chalk_1.default.yellow("!") + ` Could not add ${domain} to Next.js allowedDevOrigins: ${injected.reason}`);
|
|
287
|
+
else if (injected.changed)
|
|
288
|
+
console.log(chalk_1.default.green("✓") + ` Added ${chalk_1.default.cyan(domain)} to ${node_path_1.default.basename(injected.file)}`);
|
|
289
|
+
}
|
|
282
290
|
});
|
|
283
291
|
// prettier-ignore
|
|
284
292
|
program.command("unregister [domain]")
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type NextConfigInjectionResult = {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
changed: boolean;
|
|
4
|
+
file?: string;
|
|
5
|
+
reason?: string;
|
|
6
|
+
};
|
|
7
|
+
/** Adds the Host domain without replacing existing Next.js configuration. */
|
|
8
|
+
export declare function ensureNextAllowedDevOrigin(directory: string, domain: string): NextConfigInjectionResult;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ensureNextAllowedDevOrigin = ensureNextAllowedDevOrigin;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const CONFIG_NAMES = ["next.config.ts", "next.config.js", "next.config.mjs", "next.config.cjs"];
|
|
10
|
+
function configFile(directory) {
|
|
11
|
+
for (const name of CONFIG_NAMES) {
|
|
12
|
+
const file = node_path_1.default.join(directory, name);
|
|
13
|
+
if (node_fs_1.default.existsSync(file))
|
|
14
|
+
return file;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
/** Adds the Host domain without replacing existing Next.js configuration. */
|
|
19
|
+
function ensureNextAllowedDevOrigin(directory, domain) {
|
|
20
|
+
const file = configFile(directory);
|
|
21
|
+
if (!file)
|
|
22
|
+
return { ok: false, changed: false, reason: "No next.config file was found." };
|
|
23
|
+
const source = node_fs_1.default.readFileSync(file, "utf8");
|
|
24
|
+
const quotedDomain = JSON.stringify(domain);
|
|
25
|
+
const existingOrigin = new RegExp(`(?:["']${domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}['"])`);
|
|
26
|
+
if (existingOrigin.test(source))
|
|
27
|
+
return { ok: true, changed: false, file };
|
|
28
|
+
const originsProperty = /(allowedDevOrigins\s*:\s*\[)([\s\S]*?)(\])/m;
|
|
29
|
+
const propertyMatch = source.match(originsProperty);
|
|
30
|
+
if (propertyMatch && propertyMatch.index !== undefined) {
|
|
31
|
+
const current = propertyMatch[2].trim();
|
|
32
|
+
const replacement = `${propertyMatch[1]}${current ? `${propertyMatch[2].trimEnd()}, ` : ""}${quotedDomain}${propertyMatch[3]}`;
|
|
33
|
+
const nextSource = source.slice(0, propertyMatch.index) + replacement + source.slice(propertyMatch.index + propertyMatch[0].length);
|
|
34
|
+
node_fs_1.default.writeFileSync(file, nextSource);
|
|
35
|
+
return { ok: true, changed: true, file };
|
|
36
|
+
}
|
|
37
|
+
const objectStart = source.search(/(?:const\s+\w+(?:\s*:\s*[^=]+)?\s*=\s*|module\.exports\s*=\s*|export\s+default\s+)\{/m);
|
|
38
|
+
if (objectStart < 0) {
|
|
39
|
+
return { ok: false, changed: false, file, reason: "The Next config does not expose a plain configuration object." };
|
|
40
|
+
}
|
|
41
|
+
const brace = source.indexOf("{", objectStart);
|
|
42
|
+
const insertion = `\n allowedDevOrigins: [${quotedDomain}],`;
|
|
43
|
+
node_fs_1.default.writeFileSync(file, source.slice(0, brace + 1) + insertion + source.slice(brace + 1));
|
|
44
|
+
return { ok: true, changed: true, file };
|
|
45
|
+
}
|
package/dist/cli/project.js
CHANGED
|
@@ -21,6 +21,7 @@ const auth_1 = require("./auth");
|
|
|
21
21
|
const registry_1 = require("./host/registry");
|
|
22
22
|
const client_1 = require("./host/client");
|
|
23
23
|
const paths_1 = require("./host/paths");
|
|
24
|
+
const next_config_1 = require("./next-config");
|
|
24
25
|
const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
25
26
|
exports.LASSO_CONFIG_FILE = "lasso.config.json";
|
|
26
27
|
const PROJECT_STATE_FILE = ".lasso-project.json";
|
|
@@ -224,6 +225,13 @@ async function initProject(cwd, fileEnv) {
|
|
|
224
225
|
const existing = (0, registry_1.findByDirectory)(registry, cwd);
|
|
225
226
|
const domain = existing ? existing.domain : (0, registry_1.generateUniqueDomain)(cwd, registry);
|
|
226
227
|
await (0, client_1.registerWithHost)(domain, cwd, projectId, (0, paths_1.hostProxyPort)(fileEnv));
|
|
228
|
+
if (framework === "next") {
|
|
229
|
+
const injected = (0, next_config_1.ensureNextAllowedDevOrigin)(cwd, domain);
|
|
230
|
+
if (!injected.ok)
|
|
231
|
+
console.warn(chalk_1.default.yellow("!") + ` Could not add ${domain} to Next.js allowedDevOrigins: ${injected.reason}`);
|
|
232
|
+
else if (injected.changed)
|
|
233
|
+
console.log(chalk_1.default.green("✓") + ` Added ${chalk_1.default.cyan(domain)} to ${node_path_1.default.basename(injected.file)}`);
|
|
234
|
+
}
|
|
227
235
|
node_fs_1.default.writeFileSync(node_path_1.default.join(cwd, exports.LASSO_CONFIG_FILE), JSON.stringify({ id: projectId, domain }, null, 2) + "\n");
|
|
228
236
|
return {
|
|
229
237
|
ok: true,
|
package/package.json
CHANGED