Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const swSrcBasename = (context) => {
const {name} = upath.parse(context.swSrc);
// Always use the .js extension when generating a default filename.
return name + '.js';
};
swSrcBasename.description = 'derived from the swSrc file name';
module.exports = async ({
babelPresetEnvTargets,
inlineWorkboxRuntime,
mode,
sourcemap,
swDest,
unbundledCode,
}) => {
// We need to write this to the "real" file system, as Rollup won't read from
// a custom file system.
const {dir, base} = upath.parse(swDest);
const temporaryFile = tempy.file({name: base});
await writeFile(temporaryFile, unbundledCode);
const plugins = [
resolve(),
replace({'process.env.NODE_ENV': JSON.stringify(mode)}),
babel({
// Disable the logic that checks for local Babel config files:
// https://github.com/GoogleChrome/workbox/issues/2111
babelrc: false,
configFile: false,
presets: [[presetEnv, {
targets: {
browsers: babelPresetEnvTargets,
},
resolvePathPackage (req: string) {
if (!path.isAbsolute(req)) {
req = path.resolve(this.cwd, req)
}
const normalized = fsExistsFallback([
req,
req + '.js',
path.resolve(req, 'index.js')
])
if (!normalized) {
throw new Error(`${req} Not Found.`)
}
const dirname = path.parse(normalized).name
const { shortcut, name } = this.normalizeName(dirname)
try {
const module = this.load ? require(normalized) : normalized
return new CommonModule(module, name, shortcut, false /* fromDep */)
} catch (error) {
return getNoopModule(error)
}
}
.map((file) => ({
url: relativeUrl(baseDirectory, file.relative),
title: upath.parse(upath.parse(file.relative).dir).name
}))
fileOutput(filePath: string, content: string): Promise {
const bundle = Buffer.from(content, 'utf8');
const info = upath.parse(filePath);
const size = prettyBytes(bundle.byteLength);
Shout.timed(chalk.blue(info.base), chalk.magenta(size), chalk.grey('in ' + info.dir + '/'));
return fse.outputFile(filePath, bundle);
}
};
removeFilesInDirectory: filePath => {
fs.unlinkSync(filePath);
let folder = upath.dirname(filePath);
while (fs.readdirSync(folder).length === 0) {
fs.rmdirSync(folder);
folder = upath.parse(folder).dir;
}
},
fileOutput(filePath, content) {
const bundle = Buffer.from(content, 'utf8');
const info = upath.parse(filePath);
const size = PrettyUnits_1.prettyBytes(bundle.byteLength);
exports.Shout.timed(chalk.blue(info.base), chalk.magenta(size), chalk.grey('in ' + info.dir + '/'));
return fse.outputFile(filePath, bundle);
}
};
var targetExt = this.path.ext.toLowerCase()
if (this.type === 'page') targetExt = '.html'
if (this.type === 'script') targetExt = '.js'
if (this.type === 'stylesheet') targetExt = '.css'
var targetFull = this.path.full
.replace(sourceDir, targetDir)
.replace(this.path.ext, targetExt)
this.path.target = {
full: targetFull,
relative: targetFull.replace(targetDir, '')
}
Object.assign(this.path.target, path.parse(this.path.target.relative))
}
.then(() => {
const pathData = path.parse(data.filePath);
Util.verify(pathData.ext === '.tex', `'${pathData.base}' isn't a TeX file!`);
const count = Constants.AuxExtensions.length;
const promises = new Array(count);
for (let i = 0; i < count; i++) {
const ext = Constants.AuxExtensions[i];
const filePath = path.join(pathData.dir, `${pathData.name}${ext}`);
promises[i] = Promise.resolve()
.then(() => fs.pathExists(filePath))
.then(fileExists => fileExists ? fs.unlink(filePath) : null);
}
return Promise.all(promises);
});
}