Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function showOutput(cwd, options = {}, compile = svelte.compile) {
glob('**/*.svelte', { cwd }).forEach(file => {
if (file[0] === '_') return;
try {
const { js } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
Object.assign(options, {
filename: file
})
);
console.log( // eslint-disable-line no-console
`\n>> ${colors.cyan().bold(file)}\n${addLineNumbers(js.code)}\n<< ${colors.cyan().bold(file)}`
);
} catch (err) {
console.log(`failed to generate output: ${err.message}`);
}
// this file will replace all the expected.js and expected-bundle.js files with
// their _actual equivalents. Only use it when you're sure that you haven't
// broken anything!
const fs = require("fs");
const glob = require("tiny-glob/sync.js");
glob("samples/*/_actual.json", { cwd: __dirname }).forEach(file => {
const actual = fs.readFileSync(`${__dirname}/${file}`, "utf-8");
fs.writeFileSync(
`${__dirname}/${file.replace("_actual", "output")}`,
actual
);
});
// this file will replace all the expected.js and expected-bundle.js files with
// their _actual equivalents. Only use it when you're sure that you haven't
// broken anything!
const fs = require("fs");
const glob = require("tiny-glob/sync.js");
glob("samples/*/_actual*", { cwd: __dirname }).forEach(file => {
const actual = fs.readFileSync(`${__dirname}/${file}`, "utf-8");
fs.writeFileSync(
`${__dirname}/${file.replace("_actual", "expected")}`,
actual
);
});
);
if (commandErr) {
done(commandErr);
return;
}
const actual = glob('**', { cwd: 'actual', filesOnly: true })
.map(file => {
return {
file,
contents: normalize(fs.readFileSync(`actual/${file}`, 'utf-8'))
};
});
const expected = glob('**', { cwd: 'expected', filesOnly: true })
.map(file => {
return {
file,
contents: normalize(
fs.readFileSync(`expected/${file}`, 'utf-8')
)
};
});
actual.forEach((a, i) => {
const e = expected[i];
assert.equal(a.file, e.file, 'File list mismatch');
if (/\.map$/.test(a.file)) {
assert.deepEqual(JSON.parse(a.contents), JSON.parse(e.contents));
Object.keys(require.cache)
.filter(x => x.endsWith('.svelte'))
.forEach(file => {
delete require.cache[file];
});
delete global.window;
const compileOptions = Object.assign({ sveltePath }, config.compileOptions, {
generate: 'ssr',
format: 'cjs'
});
require("../../register")(compileOptions);
glob('**/*.svelte', { cwd }).forEach(file => {
if (file[0] === '_') return;
const dir = `${cwd}/_output/ssr`;
const out = `${dir}/${file.replace(/\.svelte$/, '.js')}`;
if (fs.existsSync(out)) {
fs.unlinkSync(out);
}
mkdirp(dir);
try {
const { js } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
{
...compileOptions,
compileOptions.accessors = 'accessors' in config ? config.accessors : true;
Object.keys(require.cache)
.filter(x => x.endsWith('.svelte'))
.forEach(file => {
delete require.cache[file];
});
let mod;
let SvelteComponent;
let unintendedError = null;
const window = env();
glob('**/*.svelte', { cwd }).forEach(file => {
if (file[0] === '_') return;
const dir = `${cwd}/_output/${hydrate ? 'hydratable' : 'normal'}`;
const out = `${dir}/${file.replace(/\.svelte$/, '.js')}`;
if (fs.existsSync(out)) {
fs.unlinkSync(out);
}
mkdirp(dir);
try {
const { js } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
{
...compileOptions,