Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (_, argv) => {
const platformName = platform()
const developerName = userInfo().username
const mode = argv.mode ? argv.mode : 'none'
const isProd = mode === 'production'
const isDev = mode === 'development'
// Show general information
console.log('whoIsMe:', white(developerName))
console.log('whichOs:', white(platformName))
console.log('devMode:', isDev ? green('true') : red('false'), '\n')
return {
target: 'node',
entry: resolve(__dirname, 'src', 'extension.ts'),
output: {
path: resolve(__dirname, 'dist'),
filename: 'extension.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
devtool: isDev ? 'cheap-module-source-map' : 'source-map',
externals: {
// the vscode-module is created on-the-fly and must be excluded.
// See: https://webpack.js.org/configuration/externals/
vscode: 'commonjs vscode',
async function depWalker(manifest, options = Object.create(null)) {
const { verbose = true } = options;
// Create TMP directory
const tmpLocation = join(TMP, uniqueSlug());
await mkdir(tmpLocation, { recursive: true });
const spinner = new Spinner({
spinner: "dots",
verbose
}).start(white().bold("Fetching all dependencies ..."));
/** @type {Map} */
const flattenedDeps = new Map();
const promisesToWait = [];
// We are dealing with an exclude Map to avoid checking a package more than one time in searchDeepDependencies
const exclude = new Map();
for await (const currentDep of getRootDependencies(manifest, { maxDepth: options.maxDepth, exclude })) {
const { name, version } = currentDep;
const current = currentDep.flatten(name === manifest.name ? 0 : void 0);
// Note: These are not very well handled in my opinion (not so much lazy ...).
promisesToWait.push(searchPackageAuthors(name, current.metadata));
promisesToWait.push(processPackageTarball(name, version, {
ref: current[version],
msg += `\n– Your ${colors.dim('$ pwa export')} is missing the ${colors.cyan('--routes')} argument.`;
msg += `\n Please run ${colors.dim('$ pwa export --help')} for more info\n`;
log.warn(msg);
}
let fn;
let onNoMatch = res => fn({ path:'/' }, res, r => (r.statusCode=404,r.end()));
let server = createServer(fn=sirv(dest, { onNoMatch })).listen();
// Disable sandboxing (on command) for dead-simple CI/CD/Docker integrations
// @see https://developers.google.com/web/updates/2017/04/headless-chrome#faq
let chromeFlags = ['--headless', '--disable-gpu'];
if (opts.insecure) chromeFlags.push('--no-sandbox');
let base = 'http://localhost:' + server.address().port;
log.log(`Started local server on ${ colors.white().bold().underline(base) }`);
let toHTML = x => x.constructor.name === 'HtmlWebpackPlugin';
let minify_opts = ctx.options.plugins.find(toHTML).options.minify;
function print(obj) {
writer(join(dest, obj.file)).end('' + minify(obj.html, minify_opts));
log.info(`Wrote file: ${colors.bold().magenta(obj.file)}`);
}
launch({ chromeFlags }).then(proc => {
return remote({ port:proc.port }).then(chrome => {
let { Page, Network, DOM } = chrome;
let scrape = dump.bind(null, chrome, opts.wait, base);
return Promise.all([Page, Network, DOM].map(x => x.enable())).then(() => {
return chain(routes.map(x => () => scrape(x).then(print))).then(arr => {
proc.kill();
if (argv.d || argv.details || failed) {
console.log('')
console.log('------------- uncovered types ---------------')
for (const { file, line, character, text } of anys) {
console.log(`${path.resolve(process.cwd(), file)}: ` + cyan(`${line + 1}:${character + 1}`) + ` - ${text}`)
}
}
console.log('')
console.log('')
console.log('----------------- coverage ------------------')
console.log(cyan(`${totalCount}`) + ` - max reachable type coverage`)
console.log(cyan(`${correctCount}`) + ` - types covered`)
console.log(cyan(`${openCount}`) + ` - types uncovered`)
console.log('')
if (success) {
console.log(green(`${percentage.toFixed(2)}%`) + ` - coverage percentage` + white(`\nYou can run ` + cyan('"tscov --details"') + ` to show all uncovered types.`))
}
if (failed) {
console.log((red(`${percentage.toFixed(2)}%`) + white(` - the type coverage rate is lower than your target: `) + cyan(`${minCoverage}%.`)))
}
return !failed
}
msg += '\n – Develop within a live-reload server:';
msg += `\n ${colors.dim('$ pwa watch')}\n`;
msg += '\n – Build your application for production:';
msg += `\n ${colors.dim('$ pwa build')}\n`;
msg += '\n – Export routes\' HTML for static hosting:';
msg += `\n ${colors.dim('$ pwa export')}\n`;
msg += '\n – Start a production HTTP file server:';
msg += `\n ${colors.dim('$ npm start')}\n`;
msg += `\nThese commands have been added to your ${colors.white().underline('package.json')} already.`;
msg += '\nWe suggest you begin by typing:\n';
msg += '\n ' + colors.dim(`$ cd ${dir}`);
msg += `\n ${colors.dim('$ npm install')}`;
msg += `\n ${colors.dim('$ npm run watch')}`;
msg += `\n\nDocumentation can be found at ${colors.white().bold().underline('https://pwa.cafe/docs')}`;
log.success(msg);
log.success('Enjoy! 😍');
});
}
export function createBanner(currentVersion: string, newVersion: string, releaseType: string): string {
const changelog = `${UPDATE_BANNER.CHANGELOG_URL}v${newVersion}`;
const versionUpdate = `${bold().red(currentVersion)} → ${bold().green(newVersion)}`;
const banner = `
${white().bold('A new ' + _.upperCase(releaseType) + ' version of Verdaccio is available. ' + versionUpdate)}
${white().bold('Run ' + green('npm install -g verdaccio') + ' to update.')}
${white().bold('Registry: ' + DEFAULT_REGISTRY)}
${blue().bold('Changelog: ' + changelog)}
`;
return banner;
}
async function hydrateCmd() {
deleteDB();
const spinner = new Spinner({
text: white().bold(`Hydrating local vulnerabilities with '${yellow().bold("nodejs security-wg")} db'`)
}).start();
try {
await hydrateDB();
spinner.succeed(white().bold(`Successfully hydrated vulnerabilities db in ${cyan(ms(spinner.elapsedTime))}`));
}
catch (err) {
spinner.failed(err.message);
}
}
function formatSize(size, filename, type, raw) {
const pretty = raw ? `${size} B` : prettyBytes(size);
const color = size < 5000 ? green : size > 40000 ? red : yellow;
const MAGIC_INDENTATION = type === 'br' ? 13 : 10;
return `${' '.repeat(MAGIC_INDENTATION - pretty.length)}${color(
pretty,
)}: ${white(basename(filename))}.${type}`;
}
c.hooks.invalid.tap('PWA', file => {
file = relative(cwd, file);
log.info(`File changed: ${ colors.white().bold(file) }`);
});
let dir = parse(argv.dir).base;
let txt = argv.preset ? (colors.magenta().underline(argv.preset) + ' ') : '';
let msg = `Created a new ${txt}project within ${ colors.green().bold(dir) } 🎉\n`;
msg += '\nInside this directory, you may:\n';
msg += '\n – Develop within a live-reload server:';
msg += `\n ${colors.dim('$ pwa watch')}\n`;
msg += '\n – Build your application for production:';
msg += `\n ${colors.dim('$ pwa build')}\n`;
msg += '\n – Export routes\' HTML for static hosting:';
msg += `\n ${colors.dim('$ pwa export')}\n`;
msg += '\n – Start a production HTTP file server:';
msg += `\n ${colors.dim('$ npm start')}\n`;
msg += `\nThese commands have been added to your ${colors.white().underline('package.json')} already.`;
msg += '\nWe suggest you begin by typing:\n';
msg += '\n ' + colors.dim(`$ cd ${dir}`);
msg += `\n ${colors.dim('$ npm install')}`;
msg += `\n ${colors.dim('$ npm run watch')}`;
msg += `\n\nDocumentation can be found at ${colors.white().bold().underline('https://pwa.cafe/docs')}`;
log.success(msg);
log.success('Enjoy! 😍');
});
}