Skip to content

Commit 74b682b

Browse files
fix: Enhance Node API shims
1 parent ccc37a6 commit 74b682b

12 files changed

Lines changed: 2363 additions & 679 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
},
2828
"pnpm": {
2929
"patchedDependencies": {
30-
"buffer": "patches/buffer.patch"
30+
"vite@6.3.5": "patches/vite@6.3.5.patch",
31+
"buffer@6.0.3": "patches/buffer@6.0.3.patch"
3132
},
3233
"onlyBuiltDependencies": [
3334
"@biomejs/biome",

packages/cli-bundle/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@v/config": "workspace:*",
3535
"@v/theme-registry": "workspace:*",
3636
"@vivliostyle/cli": "catalog:",
37+
"buffer": "6.0.3",
3738
"comlink": "catalog:",
3839
"connect": "3.7.0",
3940
"crypto-browserify": "3.12.1",
@@ -47,6 +48,7 @@
4748
"os-browserify": "0.3.0",
4849
"path-browserify": "1.0.1",
4950
"pkg-dir": "8.0.0",
51+
"readable-stream": "4.7.0",
5052
"rollup": "4.34.5",
5153
"rollup-plugin-dts": "6.2.1",
5254
"rollup-plugin-visualizer": "catalog:",

packages/cli-bundle/rollup.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ const workerConfig = defineConfig({
6565
'../src/stubs/node/process',
6666
),
6767
},
68+
{
69+
find: 'buffer/',
70+
replacement: require.resolve('buffer'),
71+
},
6872
...Object.entries({
6973
...stdLibBrowser,
7074
...Object.fromEntries(
7175
[
76+
'buffer',
7277
'child_process',
7378
'crypto',
7479
'dns',
@@ -79,6 +84,7 @@ const workerConfig = defineConfig({
7984
'path',
8085
'perf_hooks',
8186
'process',
87+
'stream',
8288
'util',
8389
'v8',
8490
'worker_threads',
@@ -136,7 +142,10 @@ const workerConfig = defineConfig({
136142
},
137143
],
138144
}),
139-
commonjs(),
145+
commonjs({
146+
extensions: ['.js', '.ts'],
147+
transformMixedEsModules: true,
148+
}),
140149
nodeResolve({
141150
browser: true,
142151
preferBuiltins: false,

packages/cli-bundle/src/index.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import './volume';
22

33
import path from 'node:path';
4-
import { createVitePlugin, build as vivliostyleBuild } from '@vivliostyle/cli';
4+
import {
5+
createVitePlugin,
6+
build as vivliostyleBuild,
7+
create as vivliostyleCreate,
8+
} from '@vivliostyle/cli';
9+
import type { VivliostyleInlineConfig } from '@vivliostyle/cli/schema';
510
import connect from 'connect';
611
import { initialize } from 'esbuild-wasm/lib/browser.js';
712
import { type Zippable, type ZippableFile, zipSync } from 'fflate';
@@ -190,6 +195,32 @@ export async function exportProjectZip() {
190195
return zipDirectory('/workdir');
191196
}
192197

198+
export async function setupTemplate(options: VivliostyleInlineConfig) {
199+
fs.rmSync('/workdir', { recursive: true, force: true });
200+
fs.mkdirSync('/workdir', { recursive: true });
201+
await vivliostyleCreate({
202+
...options,
203+
logger: {
204+
info: (message) => {
205+
console.log(`INFO: ${message}`);
206+
},
207+
warn: (message) => {
208+
console.warn(`WARN: ${message}`);
209+
},
210+
error: (message) => {
211+
console.warn(`ERROR: ${message}`);
212+
},
213+
},
214+
stdout: {
215+
write: () => true,
216+
} as any,
217+
cwd: '/workdir',
218+
logLevel: 'debug',
219+
projectPath: '.',
220+
installDependencies: false,
221+
});
222+
}
223+
193224
export const read = (...args: Parameters<typeof fs.promises.readFile>) =>
194225
fs.promises.readFile(...args);
195226
export const write = (...args: Parameters<typeof fs.promises.writeFile>) =>

0 commit comments

Comments
 (0)