mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
populate lib dir entirely in postinstall script
This commit is contained in:
parent
b14eed9309
commit
68a3e8867b
@ -1 +0,0 @@
|
||||
../../node_modules/olm/olm.js
|
@ -1 +0,0 @@
|
||||
../../node_modules/olm/olm.wasm
|
@ -1 +0,0 @@
|
||||
../../node_modules/olm/olm_legacy.js
|
12
scripts/common.mjs
Normal file
12
scripts/common.mjs
Normal file
@ -0,0 +1,12 @@
|
||||
import fsRoot from "fs";
|
||||
const fs = fsRoot.promises;
|
||||
|
||||
export async function removeDirIfExists(targetDir) {
|
||||
try {
|
||||
await fs.rmdir(targetDir, {recursive: true});
|
||||
} catch (err) {
|
||||
if (err.code !== "ENOENT") {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import { dirname } from 'path';
|
||||
// needed to translate commonjs modules to esm
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
// multi-entry plugin so we can add polyfill file to main
|
||||
import {removeDirIfExists} from "./common.mjs";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
@ -41,12 +42,23 @@ async function commonjsToESM(src, dst) {
|
||||
await fs.writeFile(dst, code, "utf8");
|
||||
}
|
||||
|
||||
async function transpile() {
|
||||
await fs.mkdir(path.join(projectDir, "lib/another-json/"));
|
||||
async function populateLib() {
|
||||
const libDir = path.join(projectDir, "lib/");
|
||||
const modulesDir = path.join(projectDir, "node_modules/");
|
||||
await removeDirIfExists(libDir);
|
||||
await fs.mkdir(libDir);
|
||||
const olmSrcDir = path.join(modulesDir, "olm/");
|
||||
const olmDstDir = path.join(libDir, "olm/");
|
||||
await fs.mkdir(olmDstDir);
|
||||
for (const file of ["olm.js", "olm.wasm", "olm_legacy.js"]) {
|
||||
await fs.symlink(path.join(olmSrcDir, file), path.join(olmDstDir, file));
|
||||
}
|
||||
// transpile another-json to esm
|
||||
await fs.mkdir(path.join(libDir, "another-json/"));
|
||||
await commonjsToESM(
|
||||
path.join(projectDir, 'node_modules/another-json/another-json.js'),
|
||||
path.join(projectDir, "lib/another-json/index.js")
|
||||
path.join(modulesDir, 'another-json/another-json.js'),
|
||||
path.join(libDir, "another-json/index.js")
|
||||
);
|
||||
}
|
||||
|
||||
transpile();
|
||||
populateLib();
|
||||
|
Loading…
Reference in New Issue
Block a user