UNPKG

reg

Version:

`reg` is a package manager for native ES Modules. It's built to enable dependency management for Universal JavaScript (JavaScript that can run in the Browser and in Node.js w/o a compiler).

44 lines (36 loc) 1.07 kB
'use strict' const tmp = require('tmp') const path = require('path') const assert = require('assert') const { writeFile } = require('fs').promises const { it } = require('mocha') const { push, storage } = require('../index.js') const { execSync } = require('child_process') const test = it const full = p => path.join(__dirname, p) const store = storage.local() const fixture = async p => { const pkg = await push(full('fixture/src/hello-world.js'), store.put) return pkg.block().cid() } const write = async str => { const f = tmp.tmpNameSync() + '.js' await writeFile(f, Buffer.from(str)) return f } const bin = path.join(__dirname, '..', 'cli.js') const run = script => { const ret = execSync(`${bin} ${script}`) return ret.toString() } /* disable tests temporarily test('basic push and import', async () => { const pkg = await fixture('src/hello-world.js', store.put) const module = ` import { hello } from '@reg/${pkg.toString()}' console.log(hello) ` const f = await write(module) assert.strictEqual(run(f), 'world\n') }) */