@file-viewer/vite-plugin 3.2.3 → 3.3.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/dist/index.d.ts CHANGED
@@ -4,103 +4,28 @@ export type FileViewerVitePresetMode = FileViewerVitePreset | 'auto';
4
4
  export type FileViewerMissingRendererMode = 'error' | 'warn' | 'ignore';
5
5
  export type FileViewerChunkStrategy = 'renderer' | 'none';
6
6
  export interface FileViewerRendererScanOptions {
7
- /**
8
- * Disable a shared scan object without branching user config.
9
- */
10
7
  enabled?: boolean;
11
- /**
12
- * Source roots, relative to Vite root, that should be inspected for format hints.
13
- * Defaults to common application source folders.
14
- */
15
8
  roots?: readonly string[];
16
- /**
17
- * Text-like source extensions to inspect. Values may include or omit the dot.
18
- */
19
9
  extensions?: readonly string[];
20
- /**
21
- * Large generated files are ignored by default to keep config/startup fast.
22
- */
23
10
  maxFileSize?: number;
24
11
  }
25
12
  export interface FileViewerCopyAssetsOptions {
26
- /**
27
- * Directory used by Vite dev. Defaults to config.publicDir.
28
- */
29
13
  publicDir?: string;
30
- /**
31
- * Directory used after production build. Defaults to build.outDir.
32
- */
33
14
  outDir?: string;
34
- /**
35
- * Directory below publicDir/outDir where assets are published. When omitted,
36
- * projects with an installed @file-viewer/*-full package use `file-viewer`;
37
- * other projects keep the existing output-root layout. Use an empty string
38
- * to explicitly publish at the output root. The injected runtime module
39
- * keeps every renderer's default asset base aligned with this directory.
40
- */
41
15
  baseDir?: string;
42
- /**
43
- * Copy during dev server startup, build closeBundle, or both.
44
- */
45
16
  mode?: 'dev' | 'build' | 'both';
46
17
  }
47
18
  export interface FileViewerRenderersPluginOptions {
48
- /**
49
- * File extensions or renderer ids. Examples: pdf, .dwg, typst, zip, xmind.
50
- */
51
19
  formats?: readonly string[];
52
- /**
53
- * Explicit renderer ids. Useful when several extensions share one renderer.
54
- */
55
20
  renderers?: readonly string[];
56
- /**
57
- * Presets import their dedicated @file-viewer/preset-* package. Use `auto`
58
- * to discover installed preset packages, and add `formats` / `renderers`
59
- * when you need to extend a preset with extra lines.
60
- */
61
21
  preset?: FileViewerVitePresetMode;
62
- /**
63
- * Auto-discovers installed `@file-viewer/preset-*` packages and registers
64
- * them globally for framework components. Defaults to true only when no
65
- * explicit preset/formats/renderers are configured, or when `preset: 'auto'`.
66
- */
67
22
  autoPresets?: boolean | readonly FileViewerVitePreset[];
68
- /**
69
- * Injects the virtual renderer module into Vite HTML entrypoints so
70
- * framework components can consume auto-registered renderers without
71
- * application code importing `virtual:file-viewer-renderers`.
72
- */
73
23
  inject?: boolean;
74
- /**
75
- * Virtual module id consumed by application code.
76
- */
77
24
  moduleId?: string;
78
- /**
79
- * Controls how planned-but-not-yet-extracted renderer lines are reported.
80
- */
81
25
  missingRenderer?: FileViewerMissingRendererMode;
82
- /**
83
- * Adds renderer-oriented manualChunks when the user did not define one.
84
- */
85
26
  chunkStrategy?: FileViewerChunkStrategy;
86
- /**
87
- * Stabilizes default chunk groups and wraps existing manualChunks functions.
88
- * This keeps CodeMirror/Lezer/Sandpack in one chunk when host
89
- * apps split node_modules by package name, avoiding production TDZ errors.
90
- * Pako and the shared CommonJS helpers also stay outside renderer/app chunks
91
- * so compressed-format imports cannot form an initialization cycle.
92
- */
93
27
  stabilizeInteropChunks?: boolean;
94
- /**
95
- * Copies known worker/WASM/vendor assets for selected renderer lines.
96
- */
97
28
  copyAssets?: boolean | FileViewerCopyAssetsOptions;
98
- /**
99
- * Opt-in source scan. The plugin reads lightweight hints such as
100
- * `fileViewerFormats = ['pdf', 'docx']`, `data-file-viewer-formats="pdf,docx"`,
101
- * and upload `accept=".pdf,.docx"` declarations, then merges them with
102
- * `formats` / `renderers` before generating the virtual module.
103
- */
104
29
  scan?: boolean | FileViewerRendererScanOptions;
105
30
  }
106
31
  interface MissingRendererNotice {
@@ -111,11 +36,8 @@ interface MissingRendererNotice {
111
36
  export declare function extractFileViewerRendererHintTokens(source: string): string[];
112
37
  export declare function collectFileViewerRendererScanTokens(projectRoot: string, scan: FileViewerRenderersPluginOptions['scan']): string[];
113
38
  export interface FileViewerCopyAssetsTargetConfig {
114
- /** Vite project root. Defaults to process.cwd(). */
115
39
  projectRoot?: string;
116
- /** Resolved Vite publicDir. Defaults to `public`. */
117
40
  publicDir?: string;
118
- /** Resolved Vite build.outDir. Defaults to `dist`. */
119
41
  outDir?: string;
120
42
  }
121
43
  export interface FileViewerCopyAssetsTarget {
@@ -126,10 +48,6 @@ export interface FileViewerCopyAssetsTarget {
126
48
  installedFullPackages: string[];
127
49
  installedAssetPackages: string[];
128
50
  }
129
- /**
130
- * Resolves the exact directory used by copyAssets without running a Vite build.
131
- * This is exported so integrations can validate their deployment contract.
132
- */
133
51
  export declare function resolveFileViewerCopyAssetsTarget(mode: 'dev' | 'build', value?: true | FileViewerCopyAssetsOptions, config?: FileViewerCopyAssetsTargetConfig): FileViewerCopyAssetsTarget;
134
52
  export declare function fileViewerRenderers(options?: FileViewerRenderersPluginOptions): Plugin;
135
53
  export declare function createFileViewerManualChunks(options?: FileViewerRenderersPluginOptions): (id: string) => string | undefined;
package/dist/index.js CHANGED
@@ -578,10 +578,6 @@ const fileViewerFullPackages = [
578
578
  '@file-viewer/jquery-full',
579
579
  '@file-viewer/svelte-full'
580
580
  ];
581
- // Vite dep optimization rewrites import.meta.url into node_modules/.vite/deps
582
- // and can trigger full-preset dev-server re-optimization reloads. Keep File
583
- // Viewer packages out of dep optimization while still optimizing their
584
- // CommonJS/UMD helper dependencies below.
585
581
  const fileViewerOptimizationExcludedPackages = [
586
582
  '@file-viewer/core',
587
583
  '@file-viewer/ppt',
@@ -690,24 +686,15 @@ export function extractFileViewerRendererHintTokens(source) {
690
686
  }
691
687
  });
692
688
  };
693
- // Explicit JavaScript/TypeScript hints:
694
- // const fileViewerFormats = ['pdf', 'docx']
695
- // fileViewerRenderers: ['pdf', 'cad']
696
689
  for (const match of source.matchAll(/\bfileViewer(?:Formats?|Renderers?)\b\s*[:=]\s*\[([\s\S]*?)\]/g)) {
697
690
  push(collectQuotedTokens(match[1]));
698
691
  }
699
- // HTML / template hints:
700
- // <div data-file-viewer-formats="pdf,docx"></div>
701
- // <input accept=".pdf,.docx,application/vnd.ms-excel">
702
692
  for (const match of source.matchAll(/\bdata-file-viewer-(?:formats?|renderers?)\s*=\s*["']([^"']+)["']/g)) {
703
693
  push(collectDelimitedTokens(match[1]));
704
694
  }
705
695
  for (const match of source.matchAll(/\baccept\s*=\s*["']([^"']+)["']/g)) {
706
696
  push(collectDelimitedTokens(match[1]));
707
697
  }
708
- // Comment hints are useful in non-framework projects where the upload UI is
709
- // assembled dynamically:
710
- // // file-viewer-formats: pdf,docx,dwg
711
698
  for (const match of source.matchAll(/file-viewer-(?:formats?|renderers?)\s*:\s*([^\n\r<]+)/g)) {
712
699
  push(collectDelimitedTokens(match[1]));
713
700
  }
@@ -936,7 +923,6 @@ function resolveProjectViteMajor(projectRoot) {
936
923
  return major;
937
924
  }
938
925
  catch {
939
- // Try the plugin's own Vite installation when the project does not expose one.
940
926
  }
941
927
  }
942
928
  return 7;
@@ -966,9 +952,6 @@ function getNodeModulePackageName(id) {
966
952
  : parts[0];
967
953
  }
968
954
  function getStableInteropChunkName(id) {
969
- // Rollup's virtual helper is shared by every converted CommonJS package.
970
- // Leaving it in an app/renderer chunk makes Pako depend back on that chunk
971
- // before its exported utility object has been initialized (issue #311).
972
955
  if (id.startsWith('\0') && /(?:^|\/)commonjsHelpers\.js$/.test(id.slice(1))) {
973
956
  return 'vendor-commonjs';
974
957
  }
@@ -1154,7 +1137,6 @@ function collectWorkspacePackageJsons(root) {
1154
1137
  }
1155
1138
  }
1156
1139
  catch {
1157
- // Ignore malformed package.json files in unrelated workspace folders.
1158
1140
  }
1159
1141
  }
1160
1142
  for (const entry of readdirSync(directory)) {
@@ -1352,7 +1334,6 @@ function resolvePackageEntry(packageName, anchorPackages = []) {
1352
1334
  return requireFn.resolve(packageName);
1353
1335
  }
1354
1336
  catch {
1355
- // Continue probing alternate anchors.
1356
1337
  }
1357
1338
  }
1358
1339
  return null;
@@ -1370,14 +1351,12 @@ function resolvePackageEntry(packageName, anchorPackages = []) {
1370
1351
  }
1371
1352
  }
1372
1353
  catch {
1373
- // Fall back to Node resolution below.
1374
1354
  }
1375
1355
  for (const requireFn of requireFns) {
1376
1356
  try {
1377
1357
  return requireFn.resolve(packageName);
1378
1358
  }
1379
1359
  catch {
1380
- // Continue probing alternate anchors.
1381
1360
  }
1382
1361
  }
1383
1362
  return null;
@@ -1579,7 +1558,6 @@ async function copyVersionedCadRuntimeDirectoryIfPresent(from, to, runtimeVersio
1579
1558
  return false;
1580
1559
  }
1581
1560
  const versionedTarget = join(to, runtimeVersion);
1582
- // These files are copied from the package root after its runtime directory.
1583
1561
  return copyDirectoryIfPresent(from, versionedTarget, { exclude: ['LICENSE', 'NOTICE'] });
1584
1562
  }
1585
1563
  async function copyPdfCjkFontAssets(from, to) {
@@ -1686,9 +1664,6 @@ async function copyKnownRendererAssets(targetRoot, rendererIds) {
1686
1664
  '@file-viewer/renderer-pdf'
1687
1665
  ]);
1688
1666
  const pdfCjkFontTarget = join(targetRoot, 'vendor/pdf/fonts');
1689
- // The PDF renderer owns the runtime font dependency so direct renderer installs retain
1690
- // CJK fallback support. The standard profile pack is only a pre-staged copy source.
1691
- // A missing source means an incomplete install and must not silently drop the fallback.
1692
1667
  const hasStandardPdfCjkFont = hasPdfCjkFontAssets(standardPdfCjkFontRoot, 'noto-sans-sc.css', 'OFL-1.1.txt');
1693
1668
  const hasStagedPdfCjkFont = hasPdfCjkFontAssets(stagedPdfCjkFontRoot, 'wght.css', 'LICENSE');
1694
1669
  const hasDependencyPdfCjkFont = hasPdfCjkFontAssets(dependencyPdfCjkFontRoot, 'wght.css', 'LICENSE');
@@ -2064,8 +2039,6 @@ function resolveBundledFullAssetSource(installedFullPackages) {
2064
2039
  };
2065
2040
  }
2066
2041
  }
2067
- // Source workspaces may not have staged file-viewer-copy-assets/viewer yet.
2068
- // @file-viewer/web keeps the same tracked payload for local development.
2069
2042
  const webPackageRoot = resolvePackageRoot('@file-viewer/web', installedFullPackages);
2070
2043
  const webPayloadRoot = webPackageRoot ? join(webPackageRoot, 'viewer') : null;
2071
2044
  const sourceVersion = readPackageVersion(webPackageRoot);
@@ -2113,8 +2086,6 @@ async function copyBundledFullRendererAssets(targetRoot, rendererIds, installedF
2113
2086
  throw new Error(`[file-viewer:vite-plugin] Unsupported full asset manifest in ${sourceManifestPath}.`);
2114
2087
  }
2115
2088
  const packageJson = JSON.parse(readFileSync(join(source.packageRoot, 'package.json'), 'utf8'));
2116
- // Full may split large asset families into version-paired dependencies.
2117
- // Resolve only its declared owners, never an unrelated project-level pack.
2118
2089
  const dependencies = packageJson.dependencies || {};
2119
2090
  const splitPackageNames = Object.keys(dependencies)
2120
2091
  .filter(name => name.startsWith('@file-viewer/assets-'));
@@ -2148,8 +2119,6 @@ async function copyBundledFullRendererAssets(targetRoot, rendererIds, installedF
2148
2119
  }
2149
2120
  }
2150
2121
  await mkdir(targetRoot, { recursive: true });
2151
- // The runtime manifest is generated below; never overwrite it with the bundled
2152
- // source first, otherwise an unchanged copy still writes it twice.
2153
2122
  await copyDirectoryIfPresent(source.payloadRoot, targetRoot, {
2154
2123
  merge: true,
2155
2124
  exclude: ['flyfish-viewer-assets.json']
@@ -2213,7 +2182,6 @@ async function copyRendererAssets(target, rendererIds) {
2213
2182
  id: 'missing-independent-asset-owner',
2214
2183
  to: target.targetRoot,
2215
2184
  copied: false,
2216
- // Specialist offline payloads stay opt-in; warn instead of failing the build.
2217
2185
  required: false,
2218
2186
  reason: `install ${requiredOwner} for this capability`
2219
2187
  });
@@ -2272,8 +2240,6 @@ function resolveInstalledFullPackages(projectRoot) {
2272
2240
  return fileViewerFullPackages.filter(packageName => declaredPackages.has(packageName) &&
2273
2241
  Boolean(tryResolvePackageJson(packageName, projectPackageRequire)));
2274
2242
  }
2275
- // Vite roots can contain a metadata-only package.json while runtime
2276
- // dependencies live in an ancestor. A nearer light runtime is a boundary.
2277
2243
  const directory = dirname(packageJsonPath);
2278
2244
  const parent = dirname(directory);
2279
2245
  packageJsonPath = parent === directory ? null : findNearestProjectPackageJson(parent);
@@ -2345,10 +2311,6 @@ function resolveOutputRoot(value, fallback, projectRoot) {
2345
2311
  const output = value || fallback;
2346
2312
  return isAbsolute(output) ? resolve(output) : resolve(projectRoot, output);
2347
2313
  }
2348
- /**
2349
- * Resolves the exact directory used by copyAssets without running a Vite build.
2350
- * This is exported so integrations can validate their deployment contract.
2351
- */
2352
2314
  export function resolveFileViewerCopyAssetsTarget(mode, value = true, config = {}) {
2353
2315
  const projectRoot = resolve(config.projectRoot || process.cwd());
2354
2316
  const options = copyOptions(value);
@@ -2408,10 +2370,6 @@ function resolveViteFullAssetBase(base, baseDir) {
2408
2370
  function resolveDevAssetRequestPath(targetRoot, baseDir, requestPathname, viteBasePath) {
2409
2371
  let requestRelativePath;
2410
2372
  try {
2411
- // Depending on the Vite major and middleware ordering, configureServer can
2412
- // observe either the original base-prefixed URL or the pathname after
2413
- // Vite's base middleware has stripped it. Accept both shapes, then keep the
2414
- // strict viewer-asset allowlist and target-root boundary checks below.
2415
2373
  const encodedRelativePath = viteBasePath === '/' || requestPathname.startsWith(viteBasePath)
2416
2374
  ? requestPathname.slice(viteBasePath === '/' ? 1 : viteBasePath.length)
2417
2375
  : requestPathname.replace(/^\/+/, '');
@@ -2680,7 +2638,6 @@ export function fileViewerRenderers(options = {}) {
2680
2638
  }
2681
2639
  }
2682
2640
  catch {
2683
- // Let Vite return its normal 404/fallback response.
2684
2641
  }
2685
2642
  }
2686
2643
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/vite-plugin",
3
- "version": "3.2.3",
3
+ "version": "3.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Vite plugin for File Viewer on-demand renderer assembly, chunk planning, and offline asset deployment.",
@@ -47,12 +47,12 @@
47
47
  "./package.json": "./package.json"
48
48
  },
49
49
  "files": [
50
- "LICENSE",
51
50
  "client.d.ts",
52
- "dist/index.js",
53
51
  "dist/index.d.ts",
54
- "README.md",
52
+ "dist/index.js",
53
+ "LICENSE",
55
54
  "README.en.md",
55
+ "README.md",
56
56
  "README.zh-CN.md"
57
57
  ],
58
58
  "peerDependencies": {