Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
const scopeGlobals = {
self: {
XMLHttpRequest: XMLHttpRequest
},
XMLHttpRequest: XMLHttpRequest,
_globalJSONAsset: function writeJSON({ name, json }) {
debug(`writeJSON ${name}`);
// the filename here should be the URL of the "current
// page", because the client-side relay network layer relies
// on the URL hash to fetch the json file
compiler.assets[name] = createAssetFromContents(JSON.stringify(json));
}
}
let render = evaluate(source, /* filename: */ renderSrc, /* scope: */ scopeGlobals, /* includeGlobals: */ true);
// if the exported function is an es6 default export, use it
if (render.hasOwnProperty('__esModule')) {
render = render['default'];
}
if (typeof render !== 'function') {
throw new Error(`Export from "${renderSrc}" must be a function that returns an HTML string`);
}
each(outputPaths, (outputPath, cb) => {
var outputFileName = outputPath.replace(/^(\/|\\)/, ''); // Remove leading slashes for webpack-dev-server
// jsonOutputFileName should be in scaffolding-relay
var jsonOutputFileName = path.join('api', md5('/' + outputFileName) + '.json');
if (!/\.(html?)$/i.test(outputFileName)) {
outputFileName = path.join(outputFileName, 'index.html');
}
export default function parser(content, file) {
try {
return yaml.safeLoad(stripJsonComments(content))
}
catch (e) {
// `(module.)exports` = JS ?
if (/exports/.test(content)) {
return evalModule(content)
}
throw new Error(
"Cannot parse runtime configuration as YAML, JSON or JS" +
(file ? `from '${file}'` : "")
)
}
}
const jsonStats = stats.toJson();
if (jsonStats.errors.length > 0) {
//soft failure
debug('webpack stats errors', jsonStats.errors[0]);
callback(jsonStats.errors);
return;
}
if (jsonStats.warnings.length > 0) {
debug('webpack stats warnings', jsonStats.warnings);
callback(jsonStats.warnings);
return;
}
// End Error Checking
debug('dist output', fs.readdirSync(distFolder));
const apiJSONAsString = fs.readFileSync(resolve(distFolder, 'database-bundle.js'), 'utf-8');
const apiJSON = evaluate(apiJSONAsString, 'api-database.json', null, true);
letPluginsPostProcessData(plugins, apiJSON, (err, resultingData) => {
if(err) {
debug('caught err', err);
// facilitate callback if error is thrown
return callback(err);
}
debug('resultingData count', resultingData.length);
return callback(null, resultingData);
})
}
}
function localRequire(module) {
// $FlowIssue: ...
return require(localResolve(module));
}
localRequire.resolve = localResolve;
scope = {
console,
process,
require: localRequire,
setTimeout,
__filename: filename,
__dirname: dirname,
...scope,
};
return evaluate(source, filename, scope);
}
if (jsonStats.errors.length > 0) {
//soft failure
debug('webpack stats errors', jsonStats.errors[0])
return console.warn(jsonStats.errors);
}
if (jsonStats.warnings.length > 0) {
debug('webpack stats warnings', jsonStats.warnings)
return console.warn(jsonStats.warnings);
}
/**
* End Error Checking
*/
debug('dist output', fs.readdirSync(distFolder));
const str = fs.readFileSync(distFolder + '/bundle.js').toString('utf-8');
callback(null, {
data: evaluate(str, 'api-database.json', null, true),
plugins: conf.plugins
});
})
})
const jsonStats = stats.toJson();
if (jsonStats.errors.length > 0) {
//soft failure
debug('webpack stats errors', jsonStats.errors[0])
return console.warn(jsonStats.errors);
}
if (jsonStats.warnings.length > 0) {
debug('webpack stats warnings', jsonStats.warnings)
return console.warn(jsonStats.warnings);
}
/**
* End Error Checking
*/
debug('dist output', fs.readdirSync(distFolder));
const apiJSONAsString = fs.readFileSync(distFolder + '/bundle.js', 'utf-8');
const apiJSON = evaluate(apiJSONAsString, 'api-database.json', null, true);
letPluginsPostProcessData(conf.plugins, apiJSON, (err, resultingData) => {
callback(null, {
data: resultingData,
plugins: conf.plugins
});
})
})
}
function evalBundle(assets) {
let source = assetSource(assets['bundle.js']);
let scope = {
console,
process,
require,
setTimeout,
};
return evaluate('module.exports = ' + source, '', scope);
}
compiler.plugin('emit', (compilation, done) => {
let bundle = compilation.assets[JS_BUNDLE_NAME];
let source = bundle._source ?
bundle._source.source() :
bundle.source();
let window = {};
let scope = {
console,
process,
setTimeout,
window
};
let routes = evaluate('module.exports = ' + source, '', scope);
cleanAssets(compilation.assets);
function addToAssets(path, markup) {
compilation.assets[routePathToAssetPath(path)] = createAssetFromContents(markup);
}
let collectedRoutes = collectRoutes(routes);
collectedRoutes
.then(childRoutes => {
let linkRegistry = LinkRegistry.createFromRoutes(childRoutes);
let pageRegistry = PageRegistry.createFromRoutes(childRoutes);
linkRegistry.install(window);
pageRegistry.install(window);
return forEachSeq(childRoutes, route =>