-
Notifications
You must be signed in to change notification settings - Fork 75
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f6c8456
feat(ses): Add XS variant of shim
kriskowal c5f5d43
feat(compartment-mapper): Export all parsers
kriskowal aa1e77f
feat(compartment-mapper): Thread native flag to opt-in for native XS …
kriskowal bd79347
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
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
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,29 @@ | ||
/** | ||
* @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. | ||
*/ | ||
|
||
/// <reference types="ses"/> | ||
|
||
import { | ||
getOwnPropertyDescriptor, | ||
globalThis, | ||
uncurryThis, | ||
} from '../src/commons.js'; | ||
|
||
/** @type {typeof Compartment} */ | ||
export const NativeStartCompartment = /** @type {any} */ (globalThis) | ||
.Compartment; | ||
export const nativeCompartmentPrototype = NativeStartCompartment.prototype; | ||
export const nativeImport = uncurryThis(nativeCompartmentPrototype.import); | ||
export const nativeImportNow = uncurryThis( | ||
nativeCompartmentPrototype.importNow, | ||
); | ||
/** @type {(compartment: any, source: string) => unknown} */ | ||
export const nativeEvaluate = uncurryThis(nativeCompartmentPrototype.evaluate); | ||
/** @type {(compartment: typeof Compartment) => typeof globalThis} */ | ||
export const nativeGetGlobalThis = uncurryThis( | ||
// @ts-expect-error we know it is there on XS | ||
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.
Keep the errors connected re causal console log output
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?
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.
Re-raising @erights's comment: