add another-json as a dependency

also add a postinstall script to turn it into an ES module,
so it works with our setup
This commit is contained in:
Bruno Windels 2020-08-27 18:45:54 +02:00
parent 3b24ea34f3
commit 7bf2a3929c
3 changed files with 61 additions and 1 deletions

View file

@ -9,7 +9,8 @@
"scripts": {
"test": "node_modules/.bin/impunity --entry-point src/main.js --force-esm",
"start": "node scripts/serve-local.js",
"build": "node --experimental-modules scripts/build.mjs"
"build": "node --experimental-modules scripts/build.mjs",
"postinstall": "node ./scripts/post-install.mjs"
},
"repository": {
"type": "git",
@ -46,6 +47,7 @@
"xxhash": "^0.3.0"
},
"dependencies": {
"another-json": "^0.2.0",
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz"
}
}

53
scripts/post-install.mjs Normal file
View file

@ -0,0 +1,53 @@
/*
Copyright 2020 Bruno Windels <bruno@windels.cloud>
Copyright 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import fsRoot from "fs";
const fs = fsRoot.promises;
import path from "path";
import { rollup } from 'rollup';
import { fileURLToPath } from 'url';
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
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectDir = path.join(__dirname, "../");
async function commonjsToESM(src, dst) {
// create js bundle
const bundle = await rollup({
input: src,
plugins: [commonjs()]
});
const {output} = await bundle.generate({
format: 'es'
});
const code = output[0].code;
await fs.writeFile(dst, code, "utf8");
}
async function transpile() {
await fs.mkdir(path.join(projectDir, "lib/another-json/"));
await commonjsToESM(
path.join(projectDir, 'node_modules/another-json/another-json.js'),
path.join(projectDir, "lib/another-json/index.js")
);
}
transpile();

View file

@ -907,6 +907,11 @@
dependencies:
"@types/node" "*"
another-json@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/another-json/-/another-json-0.2.0.tgz#b5f4019c973b6dd5c6506a2d93469cb6d32aeedc"
integrity sha1-tfQBnJc7bdXGUGotk0acttMq7tw=
ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"