@niscorp/cli 0.4.0 → 0.5.0

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 CHANGED
@@ -66,7 +66,7 @@ page in the manifest), and what each one needs once it has been drawn.
66
66
  | `checks?` | the check suite `nisc check` runs (default `src/dev/all-checks.ts`) |
67
67
  | `app?`, `runtime?` | what `nisc migrate` needs: the manifest, and a function that opens the environment it runs on (`NiscRuntime`, plus `close` if there is something to let go of) |
68
68
  | `tokenKey?` | the wire's token key, when it is not `nisc.token` |
69
- | `dev?` | what only `nisc dev` uses: `dev.signIn(server, who)` mints a token for `/dev/as/<who>` (`null`: nobody of that name) |
69
+ | `dev?` | what only `nisc dev` uses: `dev.signIn(server, who)` mints a token for `/dev/as/<who>` (`null`: nobody of that name); `dev.signInFromNetwork`, `dev.watch` and `dev.owned` are handed to moss's dev plugin |
70
70
 
71
71
  ### An app with its own shell
72
72
 
@@ -328,7 +328,14 @@ and `start` do:
328
328
  re-boots the app (a fresh database, fresh shells) and reloads the page — the
329
329
  old server answers until the new one is up;
330
330
  - `dev.signIn(server, who)` in the config, if the app gives one, makes
331
- `/dev/as/<who>` a signed-in URL — in the dev server and nowhere else.
331
+ `/dev/as/<who>` a signed-in URL — in the dev server and nowhere else, and
332
+ for a request from this machine only: one from another device is answered
333
+ `403`, unless the config says `dev.signInFromNetwork: true`;
334
+ - `dev.watch` (a `RegExp`) says which changed files re-boot the app, in place
335
+ of the folders above, and `dev.owned` (a `RegExp`) which paths go to the app
336
+ server, in place of moss's own prefixes: an app with routes of its own under
337
+ another prefix names moss's and its own. All three are read when the command
338
+ starts.
332
339
 
333
340
  The app's `vite.config.ts` holds its framework's plugin and nothing about the
334
341
  server. An app with its own shell is a vite app and nothing more.
@@ -368,7 +375,8 @@ will take, for as long.
368
375
  tables it changes itself are changed before the step can check them, and
369
376
  `--check` would then change the database. Every table an entry reads or writes
370
377
  comes from a sequence in the run — the app's own go in `runtime.tables`, and so
371
- does tide's (`TIDE_SEQUENCE`) when the app keeps tide's tables.
378
+ does tide's (`TIDE_SEQUENCE`, from `@niscorp/tide/postgres`) when the app keeps
379
+ tide's tables.
372
380
 
373
381
  It checks entries. It does not see SQL written by hand, and it does not know
374
382
  what a value means.
package/dist/adopt.js CHANGED
@@ -30,7 +30,7 @@ var main = async () => {
30
30
  const [root, asked, answered] = process.argv.slice(2);
31
31
  if (root === void 0 || asked === void 0 || answered === void 0) throw new Error("usage: adopt <root> <pages.json> <answer.json>");
32
32
  standDom(root);
33
- const { isShellProject, loadProject } = await import('./project-UVB6UCJU.js');
33
+ const { isShellProject, loadProject } = await import('./project-CH37UEL7.js');
34
34
  const project = await loadProject(root);
35
35
  if (!isShellProject(project)) throw new Error("nisc: this app has no shell of its own to adopt with.");
36
36
  const pages = JSON.parse(readFileSync(asked, "utf8"));
@@ -42,5 +42,5 @@ var loadProject = async (root) => {
42
42
  };
43
43
 
44
44
  export { configFileOf, isProject, isShellProject, loadProject };
45
- //# sourceMappingURL=chunk-6BXG4AD5.js.map
46
- //# sourceMappingURL=chunk-6BXG4AD5.js.map
45
+ //# sourceMappingURL=chunk-I2SDNSH5.js.map
46
+ //# sourceMappingURL=chunk-I2SDNSH5.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/project.ts"],"names":[],"mappings":";;;;;AAmHA,IAAM,YAAA,GAAe,CAAC,gBAAA,EAAkB,iBAAA,EAAmB,kBAAkB,iBAAiB,CAAA;AAE9F,IAAM,GAAA,GAAM,CAAC,KAAA,EAAe,GAAA,KAAyB,OAAO,OAAA,CAAQ,GAAA,CAAI,KAAA,EAAO,GAAG,CAAA,KAAM,UAAA;AAEjF,IAAM,cAAA,GAAiB,CAAC,OAAA,KAAsD,OAAA,IAAW;AAEzF,IAAM,SAAA,GAAY,CAAC,KAAA,KAAyC;AACjE,EAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,GAAA,CAAI,K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,aAAA,CAAc,IAAI,CAAA,CAAE,IAAA,EAAM,EAAE,SAAA,EAAW,MAAA,CAAA,IAAA,CAAY,KAAK,GAAI,UAAA,CAAW,QAAQ,CAAA,GAAI,EAAE,UAAS,GAAI,IAAK,CAAA;AAC9I,EAAA,MAAM,OAAA,GAAmB,MAAA,KAAW,IAAA,IAAQ,OAAO,MAAA,KAAW,WAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,SAAS,CAAA,GAAI,MAAA;AAC1G,EAAA,IAAI,CAAC,SAAA,CAAU,OAAO,CAAA,EAAG;AACvB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,SAAS,IAAI,CAAA,kLAAA;AAAA,KACf;AAAA,EACF;AACA,EAAA,IAAI,QAAQ,IAAA,KAAS,MAAA,IAAa,CAAC,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAG;AACvD,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,MAAA,EAAS,IAAI,CAAA,mBAAA,EAAsB,KAAK,SAAA,CAAU,OAAA,CAAQ,IAAI,CAAC,CAAA,8EAAA,CAA2E,CAAA;AAAA,EAC5J;AACA,EAAA,OAAO,OAAA;AACT","file":"chunk-6BXG4AD5.js","sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { DocumentConfig, MossServer, NiscApp, NiscRuntime } from '@niscorp/moss';\nimport type { Shell } from '@niscorp/nova';\n\n// ═══════════════════════════════════════════════════════════════\n// WHAT AN APP SAYS ABOUT ITSELF — `nisc.config.ts`, at the app's root, exporting\n// `project`. What only the app knows: how it stands up, and how one of its\n// screens is drawn. Everything the command does is derived from those.\n//\n// An app is one of two things, and its config says which by what it hands over.\n//\n// BEHIND MOSS — the shell lives on the server. The config hands over the\n// server; which paths exist and what each needs is read off its manifest.\n//\n// export const project: NiscProject = {\n// boot: async () => ({ server: (await boot()).server }),\n// draw: (snapshot) => renderSnapshot({ snapshot, registry, slotWrapper }),\n// };\n//\n// ITS OWN SHELL — the shell lives in the page (AGENTS.md, \"the client-degrade\n// path\"). The config hands over the app's own boot, the SAME one its browser\n// entry runs. A build runs it where there is no browser, draws the screen to\n// markup, and the page's boot picks that markup up.\n//\n// export const project: NiscShellProject = {\n// shell: async () => ({ shell: (await boot()).shell }),\n// draw: (shell) => renderToString(createElement(Screen, { shell })),\n// adopt: (root, shell) => { hydrateRoot(root, createElement(Screen, { shell })); },\n// };\n// ═══════════════════════════════════════════════════════════════\n\ntype Common = {\n // Where the bundler writes the terminal (default `dist`), relative to the root.\n dist?: string;\n // Where the built page's stylesheet goes. `page` (the default): written into\n // index.html as a <style>, so the first response paints the screen. `file`:\n // left as the bundler linked it — what a Content-Security-Policy that forbids\n // inline styles needs.\n stylesheet?: 'page' | 'file';\n // The app's check suite, for `nisc check` (default `src/dev/all-checks.ts`).\n checks?: string;\n // The address the site is served at (\"https://example.com\"). With it, every\n // path's document says its own canonical address. Without it, where a\n // document lives is left as index.html says — for every path alike.\n site?: string;\n};\n\nexport type NiscMossProject = Common & {\n // Stand the app up: the moss server, and how to let it go again. The same boot\n // the app's dev server and its checks run.\n boot: () => Promise<{ server: MossServer; close?: () => void | Promise<void> }>;\n // A terminal that draws one screen to a string — the app's kit bound to one of\n // moss's server targets (`@niscorp/moss/terminal/react/server`, …).\n draw: DocumentConfig['draw'];\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: DocumentConfig['htmlAttributes'];\n // The wire's token key, when it is not `nisc.token`.\n tokenKey?: string;\n // The paths to build. Default: `/`, and every page whose path has no\n // parameter. A page with parameters (\"/docs/:slug\") has as many paths as there\n // are rows, and only the app knows them — list them here (`server.executeAs`\n // runs a seeded read as a charter role).\n paths?: (server: MossServer) => readonly string[] | Promise<readonly string[]>;\n // Routes of the app's own that a served site needs before the catch-all — a\n // sign-in handoff, a webhook. `nisc start` registers them first.\n routes?: (server: MossServer) => void | Promise<void>;\n // What only `nisc migrate` uses: the manifest, and the environment it runs\n // on — opened by the command, and let go by it (`close`). The step applies\n // the tables' pending migrations and checks the manifest's entries against\n // what they leave; it stands no server up. `runtime` opens and nothing\n // else: tables it migrated itself are changed before the step can check them.\n app?: NiscApp;\n runtime?: () => Promise<NiscRuntime & { close?: () => void | Promise<void> }>;\n // What only `nisc dev` uses.\n dev?: {\n // A signed-in URL in development: `/dev/as/<who>` stores the token this\n // mints and goes to `/`. `null` is nobody of that name. It exists in the\n // dev server and nowhere else.\n signIn?: (server: MossServer, who: string) => string | null | Promise<string | null>;\n };\n};\n\nexport type NiscShellProject = Common & {\n // One fresh copy of the app's shell, for one path — the boot the browser entry\n // runs. It is handed the path and NOTHING ELSE: there is no credential to pass\n // and no way to pass one, so what a build draws is the screen as nobody in\n // particular sees it. Called more than once per path (the build boots twice\n // to compare, and once more inside a DOM to adopt), so it must not memoize.\n shell: (request: { path: string }) => Promise<{ shell: Shell; close?: () => void | Promise<void> }>;\n // Draw a shell to markup where there is no browser: the app's kit through an\n // adapter's string target (`react-dom/server`, `vue/server-renderer`,\n // `@niscorp/nova/adapters/dom/server`).\n draw: (shell: Shell) => string | Promise<string>;\n // Pick the markup up: `root` already holds it, `shell` is the page's own. The\n // SAME call the browser entry makes (`hydrateRoot`, `createSSRApp().mount`,\n // nova's `mountShell`). A build runs it inside a DOM and fails on anything it\n // complains about.\n adopt: (root: HTMLElement, shell: Shell) => void | Promise<void>;\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: (shell: Shell) => Record<string, string>;\n // The paths to build (default: `/`). An app that maps paths to actions lists\n // its own — only it knows them.\n paths?: () => readonly string[] | Promise<readonly string[]>;\n // How long a build waits for a screen to be whole (default 5000ms). Past it\n // the build FAILS: a file that says \"loading\" is not the page.\n waitMs?: number;\n};\n\n// What a config exports. Written against one of the two names above, a config's\n// callbacks are typed for it (`draw`'s argument is a snapshot in one and a shell\n// in the other).\nexport type NiscProject = NiscMossProject | NiscShellProject;\n\nconst CONFIG_NAMES = ['nisc.config.ts', 'nisc.config.mts', 'nisc.config.js', 'nisc.config.mjs'];\n\nconst has = (value: object, key: string): boolean => typeof Reflect.get(value, key) === 'function';\n\nexport const isShellProject = (project: NiscProject): project is NiscShellProject => 'shell' in project;\n\nexport const isProject = (value: unknown): value is NiscProject => {\n if (value === null || typeof value !== 'object' || !has(value, 'draw')) return false;\n const [moss, own] = [has(value, 'boot'), has(value, 'shell')];\n // one or the other — a config that hands over both has not said which it is\n return moss !== own && (moss || has(value, 'adopt'));\n};\n\n// An address a document can be said to live at: http or https, and whole.\nconst isSite = (value: unknown): boolean => {\n if (typeof value !== 'string') return false;\n try {\n return ['http:', 'https:'].includes(new URL(value).protocol);\n } catch {\n return false;\n }\n};\n\n// The config's file name, if the app has one.\nexport const configFileOf = (root: string): string | undefined => CONFIG_NAMES.find((name) => existsSync(join(root, name)));\n\n// Load the app's config through tsx, so it is TypeScript with the app's own\n// tsconfig (its path aliases included) — the way the app's checks already run.\nexport const loadProject = async (root: string): Promise<NiscProject> => {\n const name = configFileOf(root);\n const file = name === undefined ? undefined : join(root, name);\n if (file === undefined) {\n throw new Error(`nisc: no nisc.config.ts in ${root}. It exports \\`project\\`: how the app boots, and how one of its screens is drawn.`);\n }\n const { tsImport } = await import('tsx/esm/api');\n const tsconfig = join(root, 'tsconfig.json');\n const loaded: unknown = await tsImport(pathToFileURL(file).href, { parentURL: import.meta.url, ...(existsSync(tsconfig) ? { tsconfig } : {}) });\n const project: unknown = loaded !== null && typeof loaded === 'object' ? Reflect.get(loaded, 'project') : undefined;\n if (!isProject(project)) {\n throw new Error(\n `nisc: ${file} does not export a \\`project\\` the command can run. It hands over EITHER \\`boot\\` + \\`draw\\` (an app behind moss) OR \\`shell\\` + \\`draw\\` + \\`adopt\\` (an app with its own shell).`,\n );\n }\n if (project.site !== undefined && !isSite(project.site)) {\n throw new Error(`nisc: ${file} gives \\`site\\` as ${JSON.stringify(project.site)} — it is the address the site is served at, whole: \"https://example.com\".`);\n }\n return project;\n};\n"]}
1
+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port { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { DocumentConfig, MossServer, NiscApp, NiscRuntime } from '@niscorp/moss';\nimport type { Shell } from '@niscorp/nova';\n\n// ═══════════════════════════════════════════════════════════════\n// WHAT AN APP SAYS ABOUT ITSELF — `nisc.config.ts`, at the app's root, exporting\n// `project`. What only the app knows: how it stands up, and how one of its\n// screens is drawn. Everything the command does is derived from those.\n//\n// An app is one of two things, and its config says which by what it hands over.\n//\n// BEHIND MOSS — the shell lives on the server. The config hands over the\n// server; which paths exist and what each needs is read off its manifest.\n//\n// export const project: NiscProject = {\n// boot: async () => ({ server: (await boot()).server }),\n// draw: (snapshot) => renderSnapshot({ snapshot, registry, slotWrapper }),\n// };\n//\n// ITS OWN SHELL — the shell lives in the page (AGENTS.md, \"the client-degrade\n// path\"). The config hands over the app's own boot, the SAME one its browser\n// entry runs. A build runs it where there is no browser, draws the screen to\n// markup, and the page's boot picks that markup up.\n//\n// export const project: NiscShellProject = {\n// shell: async () => ({ shell: (await boot()).shell }),\n// draw: (shell) => renderToString(createElement(Screen, { shell })),\n// adopt: (root, shell) => { hydrateRoot(root, createElement(Screen, { shell })); },\n// };\n// ═══════════════════════════════════════════════════════════════\n\ntype Common = {\n // Where the bundler writes the terminal (default `dist`), relative to the root.\n dist?: string;\n // Where the built page's stylesheet goes. `page` (the default): written into\n // index.html as a <style>, so the first response paints the screen. `file`:\n // left as the bundler linked it — what a Content-Security-Policy that forbids\n // inline styles needs.\n stylesheet?: 'page' | 'file';\n // The app's check suite, for `nisc check` (default `src/dev/all-checks.ts`).\n checks?: string;\n // The address the site is served at (\"https://example.com\"). With it, every\n // path's document says its own canonical address. Without it, where a\n // document lives is left as index.html says — for every path alike.\n site?: string;\n};\n\nexport type NiscMossProject = Common & {\n // Stand the app up: the moss server, and how to let it go again. The same boot\n // the app's dev server and its checks run.\n boot: () => Promise<{ server: MossServer; close?: () => void | Promise<void> }>;\n // A terminal that draws one screen to a string — the app's kit bound to one of\n // moss's server targets (`@niscorp/moss/terminal/react/server`, …).\n draw: DocumentConfig['draw'];\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: DocumentConfig['htmlAttributes'];\n // The wire's token key, when it is not `nisc.token`.\n tokenKey?: string;\n // The paths to build. Default: `/`, and every page whose path has no\n // parameter. A page with parameters (\"/docs/:slug\") has as many paths as there\n // are rows, and only the app knows them — list them here (`server.executeAs`\n // runs a seeded read as a charter role).\n paths?: (server: MossServer) => readonly string[] | Promise<readonly string[]>;\n // Routes of the app's own that a served site needs before the catch-all — a\n // sign-in handoff, a webhook. `nisc start` registers them first.\n routes?: (server: MossServer) => void | Promise<void>;\n // What only `nisc migrate` uses: the manifest, and the environment it runs\n // on — opened by the command, and let go by it (`close`). The step applies\n // the tables' pending migrations and checks the manifest's entries against\n // what they leave; it stands no server up. `runtime` opens and nothing\n // else: tables it migrated itself are changed before the step can check them.\n app?: NiscApp;\n runtime?: () => Promise<NiscRuntime & { close?: () => void | Promise<void> }>;\n // What only `nisc dev` uses.\n dev?: {\n // A signed-in URL in development: `/dev/as/<who>` stores the token this\n // mints and goes to `/`. `null` is nobody of that name. It exists in the\n // dev server and nowhere else.\n signIn?: (server: MossServer, who: string) => string | null | Promise<string | null>;\n // Let `/dev/as/<who>` answer a device other than this machine (default:\n // this machine only). Anybody who can reach the dev server then signs in\n // as anybody.\n signInFromNetwork?: boolean;\n // Which changed files re-boot the app server (default: `src/app`,\n // `src/server`, `src/db`, `src/ui` and the config).\n watch?: RegExp;\n // Which paths go to the app server and not to vite (default: moss's own\n // prefixes). An app with routes of its own under another prefix names\n // moss's prefixes and its own.\n owned?: RegExp;\n };\n};\n\nexport type NiscShellProject = Common & {\n // One fresh copy of the app's shell, for one path — the boot the browser entry\n // runs. It is handed the path and NOTHING ELSE: there is no credential to pass\n // and no way to pass one, so what a build draws is the screen as nobody in\n // particular sees it. Called more than once per path (the build boots twice\n // to compare, and once more inside a DOM to adopt), so it must not memoize.\n shell: (request: { path: string }) => Promise<{ shell: Shell; close?: () => void | Promise<void> }>;\n // Draw a shell to markup where there is no browser: the app's kit through an\n // adapter's string target (`react-dom/server`, `vue/server-renderer`,\n // `@niscorp/nova/adapters/dom/server`).\n draw: (shell: Shell) => string | Promise<string>;\n // Pick the markup up: `root` already holds it, `shell` is the page's own. The\n // SAME call the browser entry makes (`hydrateRoot`, `createSSRApp().mount`,\n // nova's `mountShell`). A build runs it inside a DOM and fails on anything it\n // complains about.\n adopt: (root: HTMLElement, shell: Shell) => void | Promise<void>;\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: (shell: Shell) => Record<string, string>;\n // The paths to build (default: `/`). An app that maps paths to actions lists\n // its own — only it knows them.\n paths?: () => readonly string[] | Promise<readonly string[]>;\n // How long a build waits for a screen to be whole (default 5000ms). Past it\n // the build FAILS: a file that says \"loading\" is not the page.\n waitMs?: number;\n};\n\n// What a config exports. Written against one of the two names above, a config's\n// callbacks are typed for it (`draw`'s argument is a snapshot in one and a shell\n// in the other).\nexport type NiscProject = NiscMossProject | NiscShellProject;\n\nconst CONFIG_NAMES = ['nisc.config.ts', 'nisc.config.mts', 'nisc.config.js', 'nisc.config.mjs'];\n\nconst has = (value: object, key: string): boolean => typeof Reflect.get(value, key) === 'function';\n\nexport const isShellProject = (project: NiscProject): project is NiscShellProject => 'shell' in project;\n\nexport const isProject = (value: unknown): value is NiscProject => {\n if (value === null || typeof value !== 'object' || !has(value, 'draw')) return false;\n const [moss, own] = [has(value, 'boot'), has(value, 'shell')];\n // one or the other — a config that hands over both has not said which it is\n return moss !== own && (moss || has(value, 'adopt'));\n};\n\n// An address a document can be said to live at: http or https, and whole.\nconst isSite = (value: unknown): boolean => {\n if (typeof value !== 'string') return false;\n try {\n return ['http:', 'https:'].includes(new URL(value).protocol);\n } catch {\n return false;\n }\n};\n\n// The config's file name, if the app has one.\nexport const configFileOf = (root: string): string | undefined => CONFIG_NAMES.find((name) => existsSync(join(root, name)));\n\n// Load the app's config through tsx, so it is TypeScript with the app's own\n// tsconfig (its path aliases included) — the way the app's checks already run.\nexport const loadProject = async (root: string): Promise<NiscProject> => {\n const name = configFileOf(root);\n const file = name === undefined ? undefined : join(root, name);\n if (file === undefined) {\n throw new Error(`nisc: no nisc.config.ts in ${root}. It exports \\`project\\`: how the app boots, and how one of its screens is drawn.`);\n }\n const { tsImport } = await import('tsx/esm/api');\n const tsconfig = join(root, 'tsconfig.json');\n const loaded: unknown = await tsImport(pathToFileURL(file).href, { parentURL: import.meta.url, ...(existsSync(tsconfig) ? { tsconfig } : {}) });\n const project: unknown = loaded !== null && typeof loaded === 'object' ? Reflect.get(loaded, 'project') : undefined;\n if (!isProject(project)) {\n throw new Error(\n `nisc: ${file} does not export a \\`project\\` the command can run. It hands over EITHER \\`boot\\` + \\`draw\\` (an app behind moss) OR \\`shell\\` + \\`draw\\` + \\`adopt\\` (an app with its own shell).`,\n );\n }\n if (project.site !== undefined && !isSite(project.site)) {\n throw new Error(`nisc: ${file} gives \\`site\\` as ${JSON.stringify(project.site)} — it is the address the site is served at, whole: \"https://example.com\".`);\n }\n return project;\n};\n"]}
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import { loadProject, isShellProject, configFileOf, isProject } from './chunk-6BXG4AD5.js';
1
+ import { loadProject, isShellProject, configFileOf, isProject } from './chunk-I2SDNSH5.js';
2
2
  import { resolve, join, sep, extname, dirname } from 'path';
3
3
  import { spawn, spawnSync } from 'child_process';
4
4
  import { existsSync, statSync, readFileSync, rmSync, cpSync, mkdirSync, writeFileSync, mkdtempSync } from 'fs';
@@ -23,10 +23,16 @@ var viteOf = async (root) => {
23
23
  if (!isViteApi(loaded)) throw new Error(`nisc: ${entry} is not vite.`);
24
24
  return loaded;
25
25
  };
26
- var mossPlugin = async (configFile) => {
26
+ var devPluginOptionsOf = (dev2) => ({
27
+ ...dev2?.watch !== void 0 ? { watch: dev2.watch } : {},
28
+ ...dev2?.owned !== void 0 ? { owned: dev2.owned } : {},
29
+ ...dev2?.signInFromNetwork !== void 0 ? { signInFromNetwork: dev2.signInFromNetwork } : {}
30
+ });
31
+ var mossPlugin = async (configFile, dev2) => {
27
32
  const { mossDev } = await import('@niscorp/moss/vite');
28
33
  return mossDev({
29
34
  label: "nisc",
35
+ ...devPluginOptionsOf(dev2),
30
36
  app: async (load) => {
31
37
  const loaded = await load(`/${configFile}`);
32
38
  const project = Reflect.get(loaded, "project");
@@ -52,7 +58,7 @@ var devServer = async (options) => {
52
58
  const server = await vite.createServer({
53
59
  root: options.root,
54
60
  ...options.port !== void 0 ? { server: { port: options.port } } : {},
55
- plugins: isShellProject(project) || configFile === void 0 ? [] : [await mossPlugin(configFile)]
61
+ plugins: isShellProject(project) || configFile === void 0 ? [] : [await mossPlugin(configFile, project.dev)]
56
62
  });
57
63
  await server.listen();
58
64
  server.printUrls();