rewrite source code to point at correct files

This commit is contained in:
Richard Harris
2019-06-09 18:55:00 -04:00
parent a1d3927958
commit 6c9a90e87d

View File

@@ -1,7 +1,14 @@
import * as fs from 'fs';
import * as path from 'path';
import relative from 'require-relative';
import { mkdirp } from './fs_utils';
const svelte_pkg = relative('svelte/package.json', process.cwd());
const match = /(\d+)\.(\d+)\.(\d+)/.exec(svelte_pkg.version);
const legacy = match
? ((+match[1] - 3) || (+match[2] - 4) || (+match[3] - 4)) <= 0
: false; // ???
const runtime = [
'app.mjs',
'server.mjs',
@@ -16,6 +23,8 @@ const runtime = [
export function copy_runtime(output: string) {
runtime.forEach(({ file, source }) => {
mkdirp(path.dirname(`${output}/${file}`));
if (!legacy) source = source.replace(/svelte\/(.+)\.mjs/g, `svelte/$1/index.mjs`);
fs.writeFileSync(`${output}/${file}`, source);
});
}