From a1fe2c1d8cc1e02a8298c071d3e876bf63eebb5d Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Fri, 22 Nov 2024 17:27:58 +0100 Subject: [PATCH] fixed adding bundle metadata on stage when no main in package.json --- package.json | 1 + subsystems/sidecar/ops/stage.js | 9 +++- test/07-warmup.test.js | 56 +++++++++++++++++++++ test/fixtures/app-without-main/app.js | 1 + test/fixtures/app-without-main/dep.js | 1 + test/fixtures/app-without-main/index.html | 8 +++ test/fixtures/app-without-main/package.json | 7 +++ 7 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/app-without-main/app.js create mode 100644 test/fixtures/app-without-main/dep.js create mode 100644 test/fixtures/app-without-main/index.html create mode 100644 test/fixtures/app-without-main/package.json diff --git a/package.json b/package.json index 655e21dfd..e22067c03 100644 --- a/package.json +++ b/package.json @@ -132,6 +132,7 @@ "brittle": "^3.5.2", "graceful-goodbye": "^1.3.0", "hyperschema": "^1.0.3", + "random-access-memory": "^6.2.1", "standard": "^17.0.0" }, "repository": { diff --git a/subsystems/sidecar/ops/stage.js b/subsystems/sidecar/ops/stage.js index 08f7158f0..42646bbc2 100644 --- a/subsystems/sidecar/ops/stage.js +++ b/subsystems/sidecar/ops/stage.js @@ -85,7 +85,14 @@ module.exports = class Stage extends Opstream { const opts = { ignore, dryRun, batch: true } const builtins = isTerminal ? sidecar.gunk.bareBuiltins : sidecar.gunk.builtins const linker = new ScriptLinker(src, { builtins }) - const entrypoints = [...(state.manifest.main ? [state.main] : []), ...(state.manifest.pear?.stage?.entrypoints || [])].map((entry) => unixPathResolve('/', entry)) + + const mainExists = !!(await src.entry(unixPathResolve('/', state.main))) + const entrypoints = [ + ...(mainExists ? [state.main] : []), + ...(state.manifest.pear?.stage?.entrypoints || []) + ] + .map(entrypoint => unixPathResolve('/', entrypoint)) + .filter(entrypoint => entrypoint !== null) for (const entrypoint of entrypoints) { const entry = await src.entry(entrypoint) diff --git a/test/07-warmup.test.js b/test/07-warmup.test.js index 44a716a27..2280166cb 100644 --- a/test/07-warmup.test.js +++ b/test/07-warmup.test.js @@ -3,9 +3,15 @@ const test = require('brittle') const path = require('bare-path') const Helper = require('./helper') +const Hyperswarm = require('hyperswarm') +const Corestore = require('corestore') +const RAM = require('random-access-memory') +const Hyperdrive = require('hyperdrive') + const warmup = path.join(Helper.localDir, 'test', 'fixtures', 'warmup') const desktop = path.join(Helper.localDir, 'test', 'fixtures', 'desktop-warmup') const prefetch = path.join(Helper.localDir, 'test', 'fixtures', 'warmup-with-prefetch') +const appWithoutMain = path.join(Helper.localDir, 'test', 'fixtures', 'app-without-main') test('stage warmup with entrypoints', async function ({ ok, is, plan, comment, teardown, timeout }) { timeout(180000) @@ -81,3 +87,53 @@ test('stage warmup with prefetch', async function ({ ok, is, plan, comment, tear ok(warming.total > 0, 'Warmup total is correct') is(warming.success, true, 'Warmup completed') }) + +test('staged bundle contains entries metadata', async function ({ ok, is, plan, comment, teardown, timeout }) { + plan(2) + + const dir = appWithoutMain + + const helper = new Helper() + teardown(() => helper.close(), { order: Infinity }) + await helper.ready() + + const id = Math.floor(Math.random() * 10000) + + comment('staging') + const staging = helper.stage({ channel: `test-${id}`, name: `test-${id}`, dir, dryRun: false, bare: true }) + teardown(() => Helper.teardownStream(staging)) + + const staged = await Helper.pick(staging, [{ tag: 'warming' }, { tag: 'final' }]) + await staged.final + + comment('seeding') + const seeding = helper.seed({ channel: `test-${id}`, name: `test-${id}`, dir, key: null, cmdArgs: [] }) + teardown(() => Helper.teardownStream(seeding)) + const until = await Helper.pick(seeding, [{ tag: 'key' }, { tag: 'announced' }]) + const key = await until.key + await until.announced + + const swarm = new Hyperswarm({ bootstrap: Pear.config.dht.bootstrap }) + const store = new Corestore(RAM) + await store.ready() + const drive = new Hyperdrive(store, key) + await drive.ready() + + teardown(() => swarm.destroy()) + + swarm.on('connection', (conn) => { + drive.corestore.replicate(conn) + }) + + swarm.join(drive.discoveryKey) + + await new Promise((resolve) => setTimeout(resolve, 500)) + + comment('bundle entries should contain metadata') + for await (const file of drive.list()) { + if (file.key === '/app.js' || file.key === '/dep.js') { + const entry = await drive.entry(file.key) + ok(entry.value.metadata) + } + } +}) diff --git a/test/fixtures/app-without-main/app.js b/test/fixtures/app-without-main/app.js new file mode 100644 index 000000000..418effbc4 --- /dev/null +++ b/test/fixtures/app-without-main/app.js @@ -0,0 +1 @@ +import dep from './dep.js' diff --git a/test/fixtures/app-without-main/dep.js b/test/fixtures/app-without-main/dep.js new file mode 100644 index 000000000..2120c1074 --- /dev/null +++ b/test/fixtures/app-without-main/dep.js @@ -0,0 +1 @@ +console.log('-') diff --git a/test/fixtures/app-without-main/index.html b/test/fixtures/app-without-main/index.html new file mode 100644 index 000000000..40a48a122 --- /dev/null +++ b/test/fixtures/app-without-main/index.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/test/fixtures/app-without-main/package.json b/test/fixtures/app-without-main/package.json new file mode 100644 index 000000000..e8283cfb0 --- /dev/null +++ b/test/fixtures/app-without-main/package.json @@ -0,0 +1,7 @@ +{ + "name": "app-without-main", + "pear": { + "name": "app-without-main", + "type": "desktop" + } +}