-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bfc047
commit c8a85ef
Showing
14 changed files
with
149 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Foo { | ||
extern "../valid/external_js.js" inflight getGreeting(name: str): str; | ||
extern "../valid/external_ts.ts" inflight getGreeting(name: str): str; | ||
//^ Error: extern methods must be declared "static" | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Foo1 { | ||
extern "../../valid/external_js.js" static getGreeting(name: str): str; | ||
extern "../../valid/external_ts.ts" static getGreeting(name: str): str; | ||
//^ must be a sub directory of the entrypoint | ||
} |
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 was deleted.
Oops, something went wrong.
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,31 @@ | ||
import assert from "assert"; | ||
import extern from "./external_ts.extern"; | ||
|
||
export const getGreeting: extern["getGreeting"] = function (name) { | ||
return `Hello, ${name}!`; | ||
}; | ||
|
||
export const regexInflight: extern["regexInflight"] = async function ( | ||
pattern, | ||
text | ||
) { | ||
const regex = new RegExp(pattern); | ||
return regex.test(text); | ||
}; | ||
|
||
export const getUuid: extern["getUuid"] = async function () { | ||
let uuid = require("uuid"); | ||
return uuid.v4(); | ||
}; | ||
|
||
export const getData: extern["getData"] = async function () { | ||
return require("./exported_data.js"); | ||
}; | ||
|
||
export const print: extern["print"] = async function (msg) { | ||
console.log(`printing ${msg}`); | ||
}; | ||
|
||
export const preflightBucket: extern["preflightBucket"] = (bucket, id) => { | ||
assert.strictEqual(bucket.node.id, id); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
/// This serves as the preflight execution entrypoint to set up the following behaviors | ||
/// 1. Register jiti to handle transforms in loaded modules whenever necessary | ||
/// 2. Override module resolution to force @winglang/sdk to always resolve to the same path | ||
/// 3. Handle communication with parent process to handle errors and load the true entrypoint | ||
/// | ||
/// This file has the following expectations: | ||
/// 1. The environment variable WING_JITI_ENTRYPOINT is a JSON string of the entrypoint to load | ||
/// 2. Runs in a child process with an IPC channel to the parent process | ||
|
||
process.setUncaughtExceptionCaptureCallback((reason) => { | ||
if (reason instanceof Error) { | ||
// The Error object does not serialize well over IPC (even with 'advanced' serialization) | ||
// So we extract the properties we need to recreate most error objects | ||
reason = { | ||
message: reason.message, | ||
stack: reason.stack, | ||
name: reason.name, | ||
code: reason.code, | ||
}; | ||
} | ||
process.send(reason); | ||
}); | ||
|
||
if (!process.send) { | ||
throw new Error( | ||
"process.send is undefined. This file should only be run in a child process with an IPC connection to the parent." | ||
); | ||
} | ||
|
||
var Module = require("module"); | ||
const { join } = require("path"); | ||
const original_resolveFilename = Module._resolveFilename; | ||
const WINGSDK = "@winglang/sdk"; | ||
const WINGSDK_PATH = require.resolve(WINGSDK); | ||
const WINGSDK_DIR = join(WINGSDK_PATH, "..", ".."); | ||
|
||
Module._resolveFilename = function () { | ||
const path = arguments[0]; | ||
if (path === WINGSDK) return WINGSDK_PATH; | ||
if (path.startsWith(WINGSDK)) { | ||
arguments[0] = path.replace(WINGSDK, WINGSDK_DIR); | ||
} | ||
return original_resolveFilename.apply(this, arguments); | ||
}; | ||
|
||
if (!process.env.WING_JITI_ENTRYPOINT) { | ||
throw new Error("Missing environment variable WING_JITI_ENTRYPOINT"); | ||
} | ||
const entrypoint = JSON.parse(process.env.WING_JITI_ENTRYPOINT); | ||
delete process.env.WING_JITI_ENTRYPOINT; | ||
|
||
const jiti = require("jiti")(__filename, { | ||
sourceMaps: true, | ||
interopDefault: true, | ||
}); | ||
jiti(entrypoint); | ||
|
||
process.send(null); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.