-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ses): Add XS variant of shim #2471
Open
kriskowal
wants to merge
4
commits into
master
Choose a base branch
from
kriskowal-ses-xs-shim
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d9d9cf3
feat(ses): Add XS variant of shim
kriskowal 5820885
feat(compartment-mapper): Export all parsers
kriskowal 569c441
feat(compartment-mapper): Thread native flag to opt-in for native XS …
kriskowal 52598c1
chore(compartment-mapper): Improve makeBundle diagnostics
kriskowal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { defaultParserForLanguage } from './src/import-archive-all-parsers.js'; |
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -117,8 +117,14 @@ const sortedModules = ( | |||||||
const source = compartmentSources[compartmentName][moduleSpecifier]; | ||||||||
if (source !== undefined) { | ||||||||
const { record, parser, deferredError, bytes } = source; | ||||||||
assert(parser !== undefined); | ||||||||
assert(bytes !== undefined); | ||||||||
assert( | ||||||||
bytes !== undefined, | ||||||||
`No bytes for ${moduleSpecifier} in ${compartmentName}`, | ||||||||
); | ||||||||
assert( | ||||||||
parser !== undefined, | ||||||||
`No parser for ${moduleSpecifier} in ${compartmentName}`, | ||||||||
); | ||||||||
if (deferredError) { | ||||||||
throw Error( | ||||||||
`Cannot bundle: encountered deferredError ${deferredError}`, | ||||||||
Comment on lines
129
to
130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the errors connected re causal console log output
Suggested change
Also, consider for other asserts. Unless we're trying to avoid our assertion support and style in this package for some reason. Are we? Why? |
||||||||
|
29 changes: 29 additions & 0 deletions
29
packages/compartment-mapper/src/import-archive-all-parsers.js
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,29 @@ | ||
/* Provides a set of default language behaviors (parsers) suitable for | ||
* evaluating archives (zip files with a `compartment-map.json` and a file for | ||
* each module) with pre-compiled _or_ original ESM and CommonJS. | ||
* | ||
* This module does not entrain a dependency on Babel on XS, but does on other | ||
* platforms like Node.js. | ||
*/ | ||
/** @import {ParserForLanguage} from './types.js' */ | ||
|
||
import parserPreCjs from './parse-pre-cjs.js'; | ||
import parserJson from './parse-json.js'; | ||
import parserText from './parse-text.js'; | ||
import parserBytes from './parse-bytes.js'; | ||
import parserPreMjs from './parse-pre-mjs.js'; | ||
import parserMjs from './parse-mjs.js'; | ||
import parserCjs from './parse-cjs.js'; | ||
|
||
/** @satisfies {Readonly<ParserForLanguage>} */ | ||
export const defaultParserForLanguage = Object.freeze( | ||
/** @type {const} */ ({ | ||
'pre-cjs-json': parserPreCjs, | ||
'pre-mjs-json': parserPreMjs, | ||
cjs: parserCjs, | ||
mjs: parserMjs, | ||
json: parserJson, | ||
text: parserText, | ||
bytes: parserBytes, | ||
}), | ||
); |
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 @@ | ||
tmp |
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,56 @@ | ||
/* eslint-env node */ | ||
/* glimport/no-extraneous-dependenciesobal process */ | ||
import '../index.js'; | ||
import { promises as fs } from 'fs'; | ||
// Lerna does not like dependency cycles. | ||
// With an explicit devDependency from module-source to compartment-mapper, | ||
// the build script stalls before running every package's build script. | ||
// yarn lerna run build | ||
// Omitting the dependency from package.json solves the problem and works | ||
// by dint of shared workspace node_modules. | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { makeBundle } from '@endo/compartment-mapper/bundle.js'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { ModuleSource } from '@endo/module-source'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const read = async location => { | ||
const path = fileURLToPath(location); | ||
return fs.readFile(path); | ||
}; | ||
const write = async (location, content) => { | ||
const path = fileURLToPath(location); | ||
await fs.writeFile(path, content); | ||
}; | ||
|
||
const main = async () => { | ||
await fs.mkdir(fileURLToPath(new URL('../tmp', import.meta.url)), { | ||
recursive: true, | ||
}); | ||
|
||
const meaningText = await fs.readFile( | ||
fileURLToPath(new URL('../test/_meaning.js', import.meta.url)), | ||
'utf8', | ||
); | ||
const meaningModuleSource = new ModuleSource(meaningText); | ||
|
||
await fs.writeFile( | ||
fileURLToPath(new URL('../tmp/_meaning.pre-mjs.json', import.meta.url)), | ||
JSON.stringify(meaningModuleSource), | ||
); | ||
|
||
const xsPrelude = await makeBundle( | ||
read, | ||
new URL('../test/_xs.js', import.meta.url).href, | ||
{ | ||
tags: new Set(['xs']), | ||
}, | ||
); | ||
|
||
await write(new URL('../tmp/test-xs.js', import.meta.url).href, xsPrelude); | ||
}; | ||
|
||
main().catch(err => { | ||
console.error('Error running main:', err); | ||
process.exitCode = 1; | ||
}); |
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,22 @@ | ||
/** | ||
* @module In the spirit of ../src/commons.js, this module captures native | ||
* functions specific to the XS engine during initialization, so vetted shims | ||
* are free to modify any intrinsic without risking the integrity of SES. | ||
*/ | ||
|
||
import { | ||
getOwnPropertyDescriptor, | ||
globalThis, | ||
uncurryThis, | ||
} from '../src/commons.js'; | ||
|
||
export const NativeStartCompartment = globalThis.Compartment; | ||
export const nativeCompartmentPrototype = NativeStartCompartment.prototype; | ||
export const nativeImport = uncurryThis(nativeCompartmentPrototype.import); | ||
export const nativeImportNow = uncurryThis( | ||
nativeCompartmentPrototype.importNow, | ||
); | ||
export const nativeEvaluate = uncurryThis(nativeCompartmentPrototype.evaluate); | ||
export const nativeGetGlobalThis = uncurryThis( | ||
getOwnPropertyDescriptor(nativeCompartmentPrototype, 'globalThis').get, | ||
); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to include this under "v1.3.0" rather than "Next version"?