Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
buildId: string;
onDiagnostic?: DiagnosticHandler;
}) {
const deviceJSPipeline: Stream[] = [
// TODO: remove is-defined assertion ('!')
buildComponent({
projectConfig,
onDiagnostic,
component: ComponentType.DEVICE,
})!,
];
const processedJS = new playbackStream({ objectMode: true });
deviceJSPipeline.push(processedJS);
return multistream.obj([
// Sequence the build process: wait until compilation finishes
// before building the resources for each component.
new pumpify.obj(
...deviceJSPipeline,
// We don't want to send the JS file downstream directly. It will
// be played back into the individual device component pipelines.
dropStream.obj(),
),
...projectConfig.buildTargets.map((family) =>
lazyObjectReadable(() => {
const { platform, displayName, maxDeviceBundleSize } = buildTargets[
family
];
onDiagnostic({
messageText: `Building app for ${displayName}`,
category: DiagnosticCategory.Message,
}
// options.zoom===0 is a temp workaround because the info data used to be stored in the zoom=0,idx=1
if (end < blockEnd || options.zoom === 0) {
conds += ' AND idx < ?';
params.push(end);
}
let query = 'SELECT ' + fields + ' FROM ' + self.table + ' WHERE ' + conds;
return self.client.stream(query, params, {prepare: true, autoPage: true});
};
let ms;
if (self.blocksize) {
let blockIdx = Math.floor(start / self.blocksize),
toBlockIdx = Math.floor((end - 1) / self.blocksize);
ms = multistream.obj(cb => {
if (blockIdx > toBlockIdx) {
cb();
} else {
try {
let bi = blockIdx++;
cb(null, createStream(bi * self.blocksize, Math.min(maxEnd, (bi + 1) * self.blocksize)));
} catch (err) {
cb(err);
}
}
});
} else {
ms = createStream(0, maxEnd);
}
return promistreamus(ms, value => {
const styledStream = createStyleStream(projectStyles, (style) => (
// just return it
createLink(`dist/${style}`)
));
// allow client to start loading js bundle
res.write(`<div id="app">`);
const endStream = readableString('');
const streams = [
styledStream,
endStream,
];
MultiStream(streams).pipe(res);
// start by piping react and styled transform stream
htmlStream.pipe(styledStream);
styledStream.on('end', () => {
res.write('</div>');
// push loaded chunks information
res.write(printDrainHydrateMarks(streamUID));
res.write('');
res.end();
});
}
toStream(): NodeJS.ReadableStream {
let flag = false;
// eslint-disable-next-line consistent-return
return multiStream(cb => {
if (flag) return cb(null, null);
flag = true;
this.toStreamAsync()
.then(stream => {
cb(null, stream);
})
.catch(error => {
cb(error, null);
});
});
}
}
createStringStream(beforeContent),
createStringStream(afterContent)
]
if (renderContent !== false) {
// Render page content to a `Stream`
// inserting this stream in the middle of `streams` array.
// `array.splice(index, 0, element)` inserts `element` at `index`.
const pageElement = React.createElement(container, containerProps, content)
streams.splice(streams.length / 2, 0, ReactDOM.renderToNodeStream(pageElement))
}
return {
route,
status,
content: combineStreams(streams),
time,
cookies: newCookies
}
}
async handler(_, h) {
const cssFiles = await globby(
testingPluginIds
? testingPluginIds.split(',').map((id) => `built_assets/css/plugins/${id}/**/*.css`)
: `built_assets/css/**/*.css`,
{ cwd: fromRoot('.'), absolute: true }
);
const stream = replacePlaceholder(
new MultiStream(cssFiles.map(path => createReadStream(path))),
'/built_assets/css/'
);
return h.response(stream).code(200).type('text/css');
}
});
return new Promise((resolve, reject) => {
try {
const nxsPackagePath = join(dirPath, 'nxs_package.json');
const filePaths = module.files.sort().map(file => join(dirPath, file));
const streams = [
normalizeFile(nxsPackagePath),
...filePaths.map(normalizeFile),
];
const hash = crypto.createHash('sha256');
hash.setEncoding('base64');
hash.on('readable', () => {
resolve(hash.read());
});
new Multistream(streams).pipe(hash);
} catch (err) {
console.error(err);
reject(err);
}
});
}
if (!module) {
const nxsPackageContent = await fs.promises.readFile(nxsPackagePath);
module = JSON.parse(nxsPackageContent);
}
const filePaths = module.files.sort().map(file => join(dirPath, file));
const streams = [
normalizeFile(nxsPackagePath),
...filePaths.map(normalizeFile),
];
const hash = crypto.createHash('sha256');
hash.setEncoding('base64');
hash.on('readable', () => {
resolve(hash.read());
});
new Multistream(streams).pipe(hash);
} catch (err) {
console.error(err);
reject(err);
}
});
}
PixelMultiStream.prototype._gotNextStream = function (stream) {
if (stream) {
if (stream.format && stream.format.height) {
onFormat.call(this, stream.format)
} else {
stream.on('format', onFormat.bind(this))
}
} else if (this._actualHeight !== this.format.height) {
this.emit('error', new Error('Total height of mosaiced images (' + this._actualHeight +
'px) did not match specified height (' + this.format.height + 'px)'))
}
MultiStream.prototype._gotNextStream.call(this, stream)
}
const executeStrategy = (strategy, opts, store) => {
const streamFactories = strategy.paths.map(
(path) => generateStreamFactoryForPath(store, strategy, path),
);
let multiStream = multistream.obj(streamFactories);
if (opts.offset || opts.limit) {
let multiIterator = AsyncIterator.wrap(multiStream);
if (opts.offset) {
multiIterator = multiIterator.skip(opts.offset);
}
if (opts.limit) {
multiIterator = multiIterator.take(opts.limit);
}
multiStream = utils.createIteratorStream(multiIterator);
}
return multiStream;
};