@shware/workflow-ui 2.1.12 → 2.1.13
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 +5 -1
- package/dist/cli.mjs +79 -10
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/server.ts +79 -18
package/package.json
CHANGED
package/src/server.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { existsSync, realpathSync } from 'node:fs';
|
|
1
|
+
import { existsSync, lstatSync, readdirSync, realpathSync } from 'node:fs';
|
|
2
2
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
-
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
3
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import tailwindcss from '@tailwindcss/vite';
|
|
6
6
|
import react from '@vitejs/plugin-react';
|
|
@@ -439,7 +439,8 @@ const VITE_DEFAULT_DENY = ['.env', '.env.*', '*.{crt,pem}', '**/.git/**'];
|
|
|
439
439
|
|
|
440
440
|
/**
|
|
441
441
|
* What `server.fs.deny` refuses whatever the project: Vite's default, plus the credentials a
|
|
442
|
-
* journey project keeps beside its code. `fs.allow` spans the
|
|
442
|
+
* journey project keeps beside its code. `fs.allow` spans the project and its linked workspace
|
|
443
|
+
* packages (see {@link studioFsAllow}), so without these
|
|
443
444
|
* `/@fs/<path>/.dev.vars` (wrangler's secrets), an APNs `.p8` or a Firebase service account would
|
|
444
445
|
* be one request away for any page that can reach the port.
|
|
445
446
|
*/
|
|
@@ -457,8 +458,8 @@ export const STUDIO_FS_DENY: readonly string[] = [
|
|
|
457
458
|
/**
|
|
458
459
|
* `server.fs.deny` patterns for files the page must never be served.
|
|
459
460
|
*
|
|
460
|
-
* `fs.allow` covers the
|
|
461
|
-
*
|
|
461
|
+
* `fs.allow` covers the project so the browser can import the template
|
|
462
|
+
* registries, which also made `GET /@fs/<cwd>/workflow.stats.ts`
|
|
462
463
|
* answer with the stats source — a file the README calls server-only, and the
|
|
463
464
|
* one place a connection string is likely to be written as a literal. The
|
|
464
465
|
* browser never imports the config or the stats file (the virtual module
|
|
@@ -480,6 +481,78 @@ export function projectFileDeny(paths: readonly (string | undefined)[]): string[
|
|
|
480
481
|
return [...deny].map((path) => path.replace(/[\\*?[\]{}()!+@]/g, '\\$&'));
|
|
481
482
|
}
|
|
482
483
|
|
|
484
|
+
/** Whether `path` lies inside some `node_modules` directory (a store entry, not a workspace link). */
|
|
485
|
+
function inNodeModules(path: string): boolean {
|
|
486
|
+
return path.split(sep).includes('node_modules');
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Real paths of the workspace packages `dir` links in through `node_modules` (pnpm's
|
|
491
|
+
* `workspace:` dependencies, npm/yarn workspaces), followed transitively. A link that resolves
|
|
492
|
+
* into a `node_modules` directory is a store entry, covered by the store's own allow entry.
|
|
493
|
+
*/
|
|
494
|
+
function linkedWorkspacePackages(dir: string, found = new Set<string>()): Set<string> {
|
|
495
|
+
const modules = join(dir, 'node_modules');
|
|
496
|
+
let names: string[];
|
|
497
|
+
try {
|
|
498
|
+
names = readdirSync(modules);
|
|
499
|
+
} catch {
|
|
500
|
+
return found;
|
|
501
|
+
}
|
|
502
|
+
const entries = names.flatMap((name) => {
|
|
503
|
+
if (!name.startsWith('@')) return [join(modules, name)];
|
|
504
|
+
try {
|
|
505
|
+
return readdirSync(join(modules, name)).map((child) => join(modules, name, child));
|
|
506
|
+
} catch {
|
|
507
|
+
return [];
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
for (const entry of entries) {
|
|
511
|
+
let real: string;
|
|
512
|
+
try {
|
|
513
|
+
if (!lstatSync(entry).isSymbolicLink()) continue;
|
|
514
|
+
real = realpathSync(entry);
|
|
515
|
+
} catch {
|
|
516
|
+
continue; // a dangling link
|
|
517
|
+
}
|
|
518
|
+
if (inNodeModules(real) || found.has(real)) continue;
|
|
519
|
+
found.add(real);
|
|
520
|
+
linkedWorkspacePackages(real, found);
|
|
521
|
+
}
|
|
522
|
+
return found;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* `server.fs.allow` for the studio: only what the page actually imports.
|
|
527
|
+
*
|
|
528
|
+
* - the studio package itself (the app source, its css and fonts);
|
|
529
|
+
* - the consuming project: the directory the studio is started from, and the config's own
|
|
530
|
+
* directory when `--config` points outside it (the registries the browser imports live there);
|
|
531
|
+
* - the workspace packages those link in (a template importing `@acme/contract` from a sibling
|
|
532
|
+
* workspace package), followed transitively;
|
|
533
|
+
* - the `node_modules` of each workspace root involved: under pnpm every dependency's real path is
|
|
534
|
+
* in the virtual store `node_modules/.pnpm` beside the workspace root rather than below the app,
|
|
535
|
+
* and with npm/yarn or a hoisted pnpm layout they are directly in `node_modules`.
|
|
536
|
+
*
|
|
537
|
+
* Nothing else in the workspace: a sibling app's source and secrets are not one `/@fs/` request
|
|
538
|
+
* away. The deny list still applies inside every one of these.
|
|
539
|
+
*/
|
|
540
|
+
export function studioFsAllow(options: {
|
|
541
|
+
cwd: string;
|
|
542
|
+
configPath: string;
|
|
543
|
+
packageRoot: string;
|
|
544
|
+
appRoot: string;
|
|
545
|
+
}): string[] {
|
|
546
|
+
const { cwd, configPath, packageRoot, appRoot } = options;
|
|
547
|
+
const projectDirs = [cwd, dirname(configPath)];
|
|
548
|
+
const allow = new Set<string>([packageRoot, appRoot, ...projectDirs]);
|
|
549
|
+
for (const dir of [...projectDirs, packageRoot]) {
|
|
550
|
+
for (const linked of linkedWorkspacePackages(dir)) allow.add(linked);
|
|
551
|
+
allow.add(join(searchForWorkspaceRoot(dir), 'node_modules'));
|
|
552
|
+
}
|
|
553
|
+
return [...allow];
|
|
554
|
+
}
|
|
555
|
+
|
|
483
556
|
export interface StartOptions {
|
|
484
557
|
cwd?: string;
|
|
485
558
|
config?: string;
|
|
@@ -512,20 +585,8 @@ export async function startStudio(options: StartOptions = {}): Promise<ViteDevSe
|
|
|
512
585
|
server: {
|
|
513
586
|
port: options.port ?? 4321,
|
|
514
587
|
open: options.open ?? false,
|
|
515
|
-
/*
|
|
516
|
-
* Both workspace roots have to be readable: the user's project (the
|
|
517
|
-
* config and everything it imports) and ours — under pnpm our own
|
|
518
|
-
* dependencies (fonts, css) resolve into a store beside the workspace
|
|
519
|
-
* root rather than anywhere below the app.
|
|
520
|
-
*/
|
|
521
588
|
fs: {
|
|
522
|
-
allow:
|
|
523
|
-
searchForWorkspaceRoot(cwd),
|
|
524
|
-
/* A config outside cwd brings its own workspace: the registries the browser imports live there. */
|
|
525
|
-
searchForWorkspaceRoot(dirname(configPath)),
|
|
526
|
-
searchForWorkspaceRoot(packageRoot),
|
|
527
|
-
appRoot,
|
|
528
|
-
],
|
|
589
|
+
allow: studioFsAllow({ cwd, configPath, packageRoot, appRoot }),
|
|
529
590
|
deny: [...STUDIO_FS_DENY, ...projectFileDeny([configPath, statsPath])],
|
|
530
591
|
},
|
|
531
592
|
// The studio is its own origin and calls no one else's; no page elsewhere may read it
|