Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getPages,
getPageId,
readFileWithProps,
gracefullyShutDown,
sleep,
Config,
} from '@react-ssr/core';
const cwd = process.cwd();
const env = process.env.NODE_ENV === 'production' ? 'production' : 'development';
const ext = '.' + getEngine();
const codec = require('json-url')('lzw');
const ufs = require('unionfs').ufs;
const memfs = new MemoryFileSystem();
ufs.use(fs).use(memfs);
// onchange bundling
async function bundle(config: Config, ufs: any, memfs: any): Promise;
// initial bundling
async function bundle(config: Config, ufs: any, memfs: any, app: NestExpressApplication): Promise;
async function bundle(config: Config, ufs: any, memfs: any, app?: NestExpressApplication) {
const entry: webpack.Entry = {};
const entryPages = await getPages();
const entryPath = path.resolve(require.resolve('@react-ssr/core'), '../webpack/entry.js');
const template = fse.readFileSync(entryPath).toString();
memfs.mkdirpSync(path.join(cwd, 'react-ssr-src'));
for (let i = 0; i < entryPages.length; i++) {
getEngine,
getPages,
getPageId,
readFileWithProps,
// gracefullyShutDown,
sleep,
} from '@react-ssr/core';
const cwd = process.cwd();
const env = process.env.NODE_ENV === 'production' ? 'production' : 'development';
const ext = '.' + getEngine();
const codec = require('json-url')('lzw');
const ufs = require('unionfs').ufs;
const memfs = new MemoryFileSystem();
ufs.use(fs).use(memfs);
// onchange bundling
async function bundle(config: Config, ufs: any, memfs: any): Promise;
// initial bundling
async function bundle(config: Config, ufs: any, memfs: any, app: NestExpressApplication): Promise;
async function bundle(config: Config, ufs: any, memfs: any, app?: NestExpressApplication) {
const entry: webpack.Entry = {};
const [entryPages, otherPages] = await getPages(config);
const entryPath = path.resolve(require.resolve('@react-ssr/core'), '../webpack/entry.js');
const template = fse.readFileSync(entryPath).toString();
for (let i = 0; i < entryPages.length; i++) {
const page = entryPages[i];
const pageId = getPageId(page, config, '/');
test('cloudcmd: rest: mv', async (t) => {
const volume = {
'/fixture/mv.txt': 'hello',
'/fixture/tmp/a.txt': 'a',
};
const vol = Volume.fromJSON(volume, '/');
const unionFS = ufs
.use(vol)
.use(fs);
assign(unionFS, {
promises: fs.promises,
});
mockRequire('fs', unionFS);
reRequire('@cloudcmd/rename-files');
reRequire('@cloudcmd/move-files');
reRequire(restPath);
const cloudcmd = reRequire(cloudcmdPath);
const {createConfigManager} = cloudcmd;
const configManager = createConfigManager();
import express from 'express';
import webpack from 'webpack';
import { configureWebpack } from './webpack.config';
import { getEntry } from './helpers';
import {
getSsrConfig,
getPageId,
sleep,
} from '../helpers';
const cwd = process.cwd();
const config = getSsrConfig();
const ufs = require('unionfs').ufs;
const memfs = new MemoryFileSystem();
ufs.use(fs).use(memfs);
export default async (app: express.Application): Promise => {
fse.removeSync(path.join(cwd, config.distDir));
let compiled = false;
const [entry, entryPages] = await getEntry(memfs);
const webpackConfig: webpack.Configuration = configureWebpack(entry);
const compiler: webpack.Compiler = webpack(webpackConfig);
compiler.hooks.afterCompile.tap('finish', () => { compiled = true });
compiler.inputFileSystem = ufs;
compiler.run((err: Error, stats: webpack.Stats) => {
err && console.error(err.stack || err);
stats.hasErrors() && console.error(stats.toString());
for (let i = 0; i < entryPages.length; i++) {
const page = entryPages[i];
let html: string = '';
const cwd: string = process.cwd();
const distDir: string = config.distDir as string;
const pagePath: string = getPagePath(file, config);
const cache: string = resolve(cwd, distDir, pagePath.replace('.jsx', '.html'));
if (existsSync(cache)) {
return readFileSync(cache).toString();
}
const name: string = basename(pagePath).replace('.jsx', '');
const compiler: webpack.Compiler = webpack(configure(name, distDir));
const mfs = new MemoryFileSystem;
const { ufs } = require('unionfs');
ufs.use(mfs).use(fs);
mfs.mkdirpSync(resolve(cwd, 'react-ssr-src'));
mfs.writeFileSync(resolve(cwd, 'react-ssr-src/entry.js'), template(resolve(__dirname, 'page.jsx'), { props }));
mfs.writeFileSync(resolve(cwd, 'react-ssr-src/page.js'), template(file, props));
compiler.inputFileSystem = ufs;
compiler.outputFileSystem = mfs;
try {
compiler.run((err: any) => {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
return;
}
});
import path from 'path';
import express from 'express';
import webpack from 'webpack';
import { configureWebpack } from './webpack.config';
import { getEntry } from './helpers';
import {
getPageId,
staticConfig,
sleep,
} from '../helpers';
const cwd = process.cwd();
const ufs = require('unionfs').ufs;
const memfs = new MemoryFileSystem();
ufs.use(fs).use(memfs);
export default async (app: express.Application): Promise => {
fse.removeSync(path.join(cwd, staticConfig.distDir));
let compiled = false;
const [entry, entryPages] = await getEntry(memfs);
const webpackConfig: webpack.Configuration = configureWebpack(entry);
const compiler: webpack.Compiler = webpack(webpackConfig);
compiler.hooks.afterCompile.tap('finish', () => { compiled = true });
compiler.inputFileSystem = ufs;
compiler.run((err: Error, stats: webpack.Stats) => {
err && console.error(err.stack || err);
stats.hasErrors() && console.error(stats.toString());
for (let i = 0; i < entryPages.length; i++) {
const page = entryPages[i];
import { configureWebpack } from '../webpack.config';
import { getEntry } from './helpers';
import {
getSsrConfig,
getPageId,
readFileWithProps,
sleep,
} from '../helpers/core';
const cwd = process.cwd();
const config = getSsrConfig();
const codec = require('json-url')('lzw');
const ufs = require('unionfs').ufs;
const memfs = new MemoryFileSystem();
ufs.use(fs).use(memfs);
export default async (app: express.Application): Promise => {
fse.removeSync(path.join(cwd, config.distDir));
let compiled = false;
const [entry, entryPages] = await getEntry(memfs);
const webpackConfig: webpack.Configuration = configureWebpack(entry);
const compiler: webpack.Compiler = webpack(webpackConfig);
compiler.hooks.afterCompile.tap('finish', () => { compiled = true });
compiler.inputFileSystem = ufs;
const devServerPort = 8888;
const devServer = new WebpackDevServer(compiler, {
hot: true,
noInfo: true,
stats: 'errors-only',
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import { configureWebpack } from './webpack.config';
import { getEntry } from './helpers';
import {
getSsrConfig,
getPageId,
sleep,
} from '../helpers';
const cwd = process.cwd();
const config = getSsrConfig();
const ufs = require('unionfs').ufs;
const memfs = new MemoryFileSystem();
ufs.use(fs).use(memfs);
export default async (app: express.Application): Promise => {
fse.removeSync(path.join(cwd, config.distDir));
let compiled = false;
const [entry, entryPages] = await getEntry(memfs);
const webpackConfig: webpack.Configuration = configureWebpack(entry);
const compiler: webpack.Compiler = webpack(webpackConfig);
compiler.hooks.afterCompile.tap('finish', () => { compiled = true });
compiler.inputFileSystem = ufs;
const devServerPort = 8888;
const devServer = new WebpackDevServer(compiler, {
hot: true,
noInfo: true,
stats: 'errors-only',
export function createCompiler(
patterns: CompilerPattern[],
options: { id: string; cwd: string; infrastructure: boolean }
): webpack.Compiler {
const inputFs = new MemoryFs();
inputFs.mkdirpSync(options.cwd);
const layeredInputFileSystem = ufs.use(inputFs).use(Fs);
const outputFs = new MemoryFs();
const entryFile = createEntryFile(patterns);
inputFs.writeFileSync(inputFs.join(options.cwd, `/${options.id}.js`), entryFile);
const compiler = webpack({
mode: 'development',
context: options.cwd,
entry: {
[options.id]: inputFs.join(options.cwd, `/${options.id}.js`)
},
output: {
filename: '[name].js',
library: '[name]',
libraryTarget: 'window',
path: '/'