Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"@vue/runtime-core": "3.5.25",
"@vue/runtime-dom": "3.5.25",
"@vue/server-renderer": "3.5.25",
"@vue/shared": "3.5.25"
"@vue/shared": "3.5.25",
"vite": "npm:rolldown-vite@7.3.1"
}
}
}
10 changes: 6 additions & 4 deletions packages/ai/vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export default defineConfig({
// step to build superdoc before running packages/ai tests.

{ find: '@stores', replacement: path.resolve(__dirname, '../superdoc/src/stores') },
{
find: /^@superdoc\/(?!common|contracts|geometry-utils|pm-adapter|layout-engine|layout-bridge|painter-dom|style-engine|measuring-dom|word-layout|url-validation|preset-geometry|super-editor|locale-utils|font-utils)(.*)/,
replacement: path.resolve(__dirname, '../superdoc/src/$1'),
},
// Rolldown doesn't support regex capture groups ($1) in alias replacements.
// Keep in sync with packages/superdoc/vite.config.js superdocSrcAliases.
...['components', 'composables', 'core', 'helpers', 'stores', 'dev', 'icons.js'].map(name => ({
find: `@superdoc/${name}`,
replacement: path.resolve(__dirname, `../superdoc/src/${name}`),
})),
],
},
plugins: [vue()],
Expand Down
88 changes: 55 additions & 33 deletions packages/superdoc/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import copy from 'rollup-plugin-copy'
import dts from 'vite-plugin-dts'
import { defineConfig } from 'vite'
import { configDefaults } from 'vitest/config'
import { createRequire } from 'node:module';
import { fileURLToPath, URL } from 'node:url';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { visualizer } from 'rollup-plugin-visualizer';
Expand All @@ -11,6 +12,17 @@ import vue from '@vitejs/plugin-vue'
import { version } from './package.json';
import sourceResolve from '../../vite.sourceResolve';

// WORKAROUND: rolldown doesn't support trailing-slash imports (e.g. 'punycode/')
// which Node.js treats as "resolve the package entry point". node-stdlib-browser's
// url polyfill uses `import from 'punycode/'` and rolldown tries to open the
// directory as a file. We resolve the actual entry point here and redirect via a
// small plugin in optimizeDeps.rollupOptions below.
// Track: https://github.com/nicolo-ribaudo/tc39-proposal-import-deferral/issues/3
// TODO: Remove once rolldown supports trailing-slash imports or node-stdlib-browser drops them.
const require = createRequire(import.meta.url);
const stdlibRequire = createRequire(require.resolve('node-stdlib-browser/package.json'));
const punycodeEntry = stdlibRequire.resolve('punycode/punycode.js');

const visualizerConfig = {
filename: './dist/bundle-analysis.html',
template: 'treemap',
Expand All @@ -19,22 +31,14 @@ const visualizerConfig = {
open: true
}

// Internal @superdoc/ paths that map to ./src/ (not workspace packages).
// Rolldown doesn't support regex capture groups ($1) in alias replacements,
// so we list these explicitly instead of using /^@superdoc\/(.*)$/.
// Update this list when adding new src/ subdirectories imported via @superdoc/.
const superdocSrcAliases = ['components', 'composables', 'core', 'helpers', 'stores', 'dev', 'icons.js', 'index.js'];

export const getAliases = (_isDev) => {
const aliases = [
// NOTE: There are a number of packages named "@superdoc/PACKAGE", but we also alias
// "@superdoc" to the src directory of the superdoc package. This is error-prone and
// should be changed, e.g. by renaming the src alias to "@superdoc/superdoc".
//
// Until then, the alias for "./src" is a regexp that matches any imports starting
// with "@superdoc/" that don't also match one of the known packages.
//
// Also note: this regexp is duplicated in packages/ai/vitest.config.mjs

{
find: /^@superdoc\/(?!common|contracts|geometry-utils|pm-adapter|layout-engine|layout-bridge|painter-dom|style-engine|measuring-dom|word-layout|url-validation|preset-geometry|super-editor|locale-utils|font-utils)(.*)/,
replacement: path.resolve(__dirname, './src/$1'),
},

// Workspace packages (source paths for dev)
{ find: '@stores', replacement: fileURLToPath(new URL('./src/stores', import.meta.url)) },

Expand All @@ -51,6 +55,12 @@ export const getAliases = (_isDev) => {
{ find: '@superdoc/super-editor/presentation-editor', replacement: path.resolve(__dirname, '../super-editor/src/index.js') },
{ find: '@superdoc/super-editor', replacement: path.resolve(__dirname, '../super-editor/src/index.js') },

// Map @superdoc/<name> to ./src/<name> for internal paths
...superdocSrcAliases.map(name => ({
find: `@superdoc/${name}`,
replacement: path.resolve(__dirname, `./src/${name}`),
})),

// Super Editor aliases
{ find: '@', replacement: '@superdoc/super-editor' },
...sourceResolve.alias,
Expand All @@ -61,7 +71,7 @@ export const getAliases = (_isDev) => {


// https://vitejs.dev/config/
export default defineConfig(({ mode, command}) => {
export default defineConfig(({ mode, command }) => {
const skipDts = process.env.SUPERDOC_SKIP_DTS === '1';
const plugins = [
vue(),
Expand All @@ -71,7 +81,7 @@ export default defineConfig(({ mode, command}) => {
}),
copy({
targets: [
{
{
src: 'node_modules/pdfjs-dist/web/images/*',
dest: 'dist/images',
},
Expand Down Expand Up @@ -137,35 +147,47 @@ export default defineConfig(({ mode, command}) => {
format: 'es',
entryFileNames: '[name].es.js',
chunkFileNames: 'chunks/[name]-[hash].es.js',
manualChunks: {
'vue': ['vue'],
'blank-docx': ['@superdoc/common/data/blank.docx?url'],
'jszip': ['jszip'],
'eventemitter3': ['eventemitter3'],
'uuid': ['uuid'],
'xml-js': ['xml-js'],
manualChunks(id) {
if (id.includes('/node_modules/vue/')) return 'vue';
if (id.includes('/node_modules/jszip/')) return 'jszip';
if (id.includes('/node_modules/eventemitter3/')) return 'eventemitter3';
if (id.includes('/node_modules/uuid/')) return 'uuid';
if (id.includes('/node_modules/xml-js/')) return 'xml-js';
if (id.includes('blank.docx')) return 'blank-docx';
}
},
{
format: 'cjs',
entryFileNames: '[name].cjs',
chunkFileNames: 'chunks/[name]-[hash].cjs',
manualChunks: {
'vue': ['vue'],
'blank-docx': ['@superdoc/common/data/blank.docx?url'],
'jszip': ['jszip'],
'eventemitter3': ['eventemitter3'],
'uuid': ['uuid'],
'xml-js': ['xml-js'],
manualChunks(id) {
if (id.includes('/node_modules/vue/')) return 'vue';
if (id.includes('/node_modules/jszip/')) return 'jszip';
if (id.includes('/node_modules/eventemitter3/')) return 'eventemitter3';
if (id.includes('/node_modules/uuid/')) return 'uuid';
if (id.includes('/node_modules/xml-js/')) return 'xml-js';
if (id.includes('blank.docx')) return 'blank-docx';
}
}
],
],
}
},
optimizeDeps: {
include: ['yjs', '@hocuspocus/provider'],
esbuildOptions: {
target: 'es2020',
// Rolldown treats trailing-slash imports as directory paths.
// node-stdlib-browser's url polyfill imports 'punycode/' — resolve it to the
// actual file since punycode is also a Node.js builtin and pnpm isolates it.
rollupOptions: {
plugins: [
{
name: 'fix-punycode-trailing-slash',
resolveId(source) {
if (source === 'punycode/' || source === 'punycode') {
return { id: punycodeEntry };
}
},
},
],
},
},
resolve: {
Expand Down
22 changes: 22 additions & 0 deletions patches/readable-stream@3.6.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index df1f608d532606ba1df4eeaf3b6f577791dcd9ad..0e53b087f3471225523783bf68ccf356951f6818 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -155,7 +155,7 @@ function ReadableState(options, stream, isDuplex) {
this.decoder = null;
this.encoding = null;
if (options.encoding) {
- if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
+ if (!StringDecoder) StringDecoder = require('string_decoder').StringDecoder;
this.decoder = new StringDecoder(options.encoding);
this.encoding = options.encoding;
}
@@ -298,7 +298,7 @@ Readable.prototype.isPaused = function () {

// backwards compatibility.
Readable.prototype.setEncoding = function (enc) {
- if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
+ if (!StringDecoder) StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder(enc);
this._readableState.decoder = decoder;
// If setEncoding(null), decoder.encoding equals utf8
222 changes: 0 additions & 222 deletions patches/vite-plugin-node-polyfills.patch

This file was deleted.

Loading
Loading