Skip to content

Commit bd80185

Browse files
ilyavfmihar-22
authored andcommitted
feat: adds maxBuffer option that sets buffer limit for preprocess
fixes #20
1 parent a0f5fb1 commit bd80185

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,17 @@ The default mode is to load `svelte.config.js` from the current project root to
158158
159159
When `upward` is set it will stop at the first config file it finds above the file being transformed, but will walk up the directory structure all the way to the filesystem root if it cannot find any config file. This means that if there is no `svelte.config.js` file in the project above the file being transformed, it is always possible that someone will have a forgotten `svelte.config.js` in their home directory which could cause unexpected errors in your builds.
160160
161+
`maxBuffer` (default: 10485760): Sets limit for buffer when `preprocess` is true. It defines the largest amount of data in bytes allowed on stdout or stderr for [child_process.spawnSync](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options). If exceeded, the child process is terminated and any output is truncated. The default value of 10Mb overrides Node's default value of 1Mb.
162+
161163
```json
162164
"transform": {
163165
"^.+\\.js$": "babel-jest",
164166
"^.+\\.svelte$": ["svelte-jester", {
165167
"preprocess": false,
166168
"debug": false,
167169
"compilerOptions": {},
168-
"rootMode": ""
170+
"rootMode": "",
171+
"maxBuffer": 15000000
169172
}]
170173
}
171174
```

src/__tests__/transformer.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ describe('transformer', () => {
4444
const esInterop = 'Object.defineProperty(exports, "__esModule", { value: true });'
4545
expect(global.window.console.log).toHaveBeenCalledWith(code.replace(esInterop, ''))
4646
})
47+
48+
it('should accept maxBuffer option for preprocess buffer limit', () => {
49+
expect(
50+
() => runTransformer('SassComp', { preprocess: true, maxBuffer: 1 })
51+
).toThrow('spawnSync /bin/sh ENOBUFS');
52+
runTransformer('SassComp', { preprocess: true, maxBuffer: 5 * 1024 * 1024 })
53+
})
4754
})

src/transformer.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ const svelte = require('svelte/compiler')
55
const { getSvelteConfig } = require('./svelteconfig.js')
66

77
const transformer = (options = {}) => (source, filename) => {
8-
const { debug, compilerOptions, preprocess, rootMode } = options
8+
const { debug, compilerOptions, preprocess, rootMode, maxBuffer } = options
99

1010
let processed = source
1111

1212
if (preprocess) {
1313
const svelteConfig = getSvelteConfig(rootMode, filename)
1414
const preprocessor = require.resolve('./preprocess.js')
1515
processed = execSync(`node --unhandled-rejections=strict --abort-on-uncaught-exception "${preprocessor}"`, {
16-
env: { PATH: process.env.PATH, source, filename, svelteConfig }
16+
env: { PATH: process.env.PATH, source, filename, svelteConfig },
17+
maxBuffer: maxBuffer || 10 * 1024 * 1024
1718
}).toString()
1819
}
1920

0 commit comments

Comments
 (0)