Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function requireImplementation(file, {disableCache} = {}) {
let implementation;
try {
if (disableCache) {
decache(file);
}
implementation = require(file);
if (implementation.default) {
// ES Module
implementation = implementation.default;
}
if (typeof implementation !== 'function') {
throw createClientError(
`A resource implementation file must export a function (file: ${formatPath(file)})`
);
}
} catch (err) {
implementation = () => {
throw err;
test.afterEach(() => {
// remove old cached every time to avoid side-effects
decache('./dist')
decache('./dist/tweet')
decache('./dist/moment')
decache('./dist/timeline')
})
test.afterEach(() => {
// remove old cached every time to avoid side-effects
decache('./dist')
decache('./dist/tweet')
decache('./dist/moment')
decache('./dist/timeline')
})
test.afterEach(() => {
// remove old cached every time to avoid side-effects
decache('./dist')
decache('./dist/tweet')
decache('./dist/moment')
decache('./dist/timeline')
})
function assertModule(t, filename, expected) {
const absFilename = path.join(__dirname, '../fixture', filename);
decache(absFilename);
return t.is(require(absFilename), expected);
}
const fs = require('fs').default || require('fs');
const minimatch = require('minimatch');
const decache = require('decache').default || require('decache');
function matchesGlobs(filePath, globs) {
return (globs || []).some(glob => minimatch(filePath, glob, { matchBase: true }));
}
function WebpackPluginGraphqlSchemaHot(options) {
this._canRun = true;
const startupError = msg => {
this._canRun = false;
console.error('[WebpackPluginGraphqlSchemaHot]:\n' + msg);
};
const opts = options || {};
this._isFirstRun = true;
///////////
files.forEach((f): void => {
decache(f.handler);
});
const routeObjs = importRoutes(files, routesPath, true);
watcher.on('change', changePath => {
const displayPath = path.relative(process.cwd(), changePath)
log(`\n\nRebuilding. Detected change in ${displayPath}}`)
decache(appFile)
const updatedApp = require(appFile)
const updatedElement = updatedApp.default
rerenderElement(updatedElement, state)
})
}
watcher.on('change', (p: string): void => {
logger.hmr(`swapping out ${chalk.yellow(relative(cwd, p))}`);
app.router.reset();
decache(join(routesPath, '../', 'routes.js'));
const files: any[] = findRoutes(routesPath);
files.forEach((f): void => {
decache(f.handler);
});
const routeObjs = importRoutes(files, routesPath, true);
routeObjs.forEach((route: Route): void => {
addRoute(app.router, route, opts);
});
});
});
indexDocument(srcPath) {
const relPath = this.relPath(srcPath)
const distPath = this.distPath(srcPath)
const extension = path.extname(srcPath)
const basename = path.basename(srcPath, extension)
const relativeDir = path.dirname(relPath)
const trimed = path.join(relativeDir, basename)
const url = `/${trimed}`
const requirePath = `./${path.relative(__dirname, distPath)}`
try {
decache(requirePath)
} catch (err) {
debug("Couldn't decache(%o)", requirePath)
}
const Component = require(requirePath).default
if (!Component || !Component.document) return
this.index.set(url, {
filename: `${basename}.pdf`,
Component,
})
debug("Indexed %o (at url %o)", relPath, url)
}
}