-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundle-source): Zip original sources with --no-transforms (#2294)
Closes: #2295 Refs: #400, #2252 ## Description This change adds a mode to the `bundle-source` command with the initial flag `--no-transforms` that generates “endo zip base64” style bundles without applying the module-to-program transform and SES shim censorship evasion transforms, such that the original files on disk appear in the zip file. This is a preparatory step, necessary for building test artifacts, in advance of full support for this bundle style. ### Security Considerations `bundle-source` is part of the Endo and Agoric toolkit and it, or its surrogate, participate in the toolchain for generating content that can be confined by Hardened JavaScript, but is not trusted by Hardened JavaScript at runtime. It does however _currently_ run with all the authority of the developer in their development environment and its integrity must be carefully guarded. ### Scaling Considerations No improvements expected at this time, but in pursuit of #400, it may be possible to move the heavy and performance sensitive JavaScript transform components from `bundle-source` to `import-bundle` and only suffer the performance cost of these transforms on Node.js, where those costs are more readily born by some runtimes. Precompiled bundles may continue to be the preferred medium for deployment to the web, for example. ### Documentation Considerations We will need to advertise the `--no-transforms` flag eventually, since there will be a period where it is advisable if not necessary to generate contracts and caplets targeting the XS runtime. ### Testing Considerations I have included a test that verifies the API behavior and manually run the following to verify behavior for the CLI: ```sh rm -rf bundles yarn bundle-source --no-transforms --cache-json bundles demo/circular/a.js circular-a rm -rf circular-a mkdir -p circular-a jq -r .endoZipBase64 bundles/bundle-circular-a.json | base64 -d > circular-a/circular-a.zip (cd circular-a; unzip circular-a.zip) jq . circular-a/compartment-map.json # verifying the final module entires have parser: 'mjs' ``` ### Compatibility Considerations This flag is opt-in and breaks no prior behaviors. This introduces a new entry to the build cache meta-data and may cause some bundles to be regenerated one extra time after upgrading. ### Upgrade Considerations This should not impact upgrade, though it participates in the greater #400 story which will require xsnap upgrades to come to bear.
- Loading branch information
Showing
7 changed files
with
184 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @ts-check | ||
import test from '@endo/ses-ava/prepare-endo.js'; | ||
|
||
import fs from 'fs'; | ||
import url from 'url'; | ||
import { decodeBase64 } from '@endo/base64'; | ||
import { ZipReader } from '@endo/zip'; | ||
import bundleSource from '../src/index.js'; | ||
|
||
test('no-transforms applies no transforms', async t => { | ||
const entryPath = url.fileURLToPath( | ||
new URL(`../demo/circular/a.js`, import.meta.url), | ||
); | ||
const { endoZipBase64 } = await bundleSource(entryPath, { | ||
moduleFormat: 'endoZipBase64', | ||
noTransforms: true, | ||
}); | ||
const endoZipBytes = decodeBase64(endoZipBase64); | ||
const zipReader = new ZipReader(endoZipBytes); | ||
const compartmentMapBytes = zipReader.read('compartment-map.json'); | ||
const compartmentMapText = new TextDecoder().decode(compartmentMapBytes); | ||
const compartmentMap = JSON.parse(compartmentMapText); | ||
const { entry, compartments } = compartmentMap; | ||
const compartment = compartments[entry.compartment]; | ||
const module = compartment.modules[entry.module]; | ||
// Alleged module type is not precompiled (pre-mjs-json) | ||
t.is(module.parser, 'mjs'); | ||
|
||
const moduleBytes = zipReader.read( | ||
`${compartment.location}/${module.location}`, | ||
); | ||
const moduleText = new TextDecoder().decode(moduleBytes); | ||
const originalModuleText = await fs.promises.readFile(entryPath, 'utf-8'); | ||
// And, just to be sure, the text in the bundle matches the original text. | ||
t.is(moduleText, originalModuleText); | ||
}); |
Oops, something went wrong.