Skip to content
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

fix: process.stdout regression #6933

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/tests/valid/print-helpers.extern.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default interface extern {
write: (s: string) => void,
}
3 changes: 3 additions & 0 deletions examples/tests/valid/print-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.write = function(s) {
return process.stdout.write(s);
};
5 changes: 5 additions & 0 deletions examples/tests/valid/print.test.w
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
bring cloud;

class Process {
pub extern "./print-helpers.js" static write(s: str);
}

log("preflight log");
Process.write("start ");
Process.write("end\n");

test "log1" {
log("inflight log 1.1");
Expand Down
4 changes: 2 additions & 2 deletions libs/wingcompiler/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function determineTargetFromPlatforms(platforms: string[]): string {
*/
export async function compile(entrypoint: string, options: CompileOptions): Promise<string> {
const { log } = options;
const preflightLog = options.preflightLog ?? console.log;
const preflightLog = options.preflightLog ?? process.stdout.write.bind(process.stdout);
Chriscbr marked this conversation as resolved.
Show resolved Hide resolved
// create a unique temporary directory for the compilation
const targetdir = options.targetDir ?? join(dirname(entrypoint), "target");
const entrypointFile = resolve(entrypoint);
Expand Down Expand Up @@ -211,7 +211,7 @@ export async function compile(entrypoint: string, options: CompileOptions): Prom
await runPreflightCodeInWorkerThread(
compileForPreflightResult.preflightEntrypoint,
preflightEnv,
(data) => preflightLog?.(data.toString().trim())
(data) => preflightLog?.(data.toString())
);
}
return synthDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ module.exports = function({ }) {
//# sourceMappingURL=inflight.$Closure2-1.cjs.map
```

## inflight.Process-1.cjs
```cjs
"use strict";
const $helpers = require("@winglang/sdk/lib/helpers");
const $macros = require("@winglang/sdk/lib/macros");
module.exports = function({ }) {
class Process {
constructor({ }) {
}
}
return Process;
}
//# sourceMappingURL=inflight.Process-1.cjs.map
```

## main.tf.json
```json
{
Expand Down Expand Up @@ -81,6 +96,37 @@ class $Root extends $stdlib.std.Resource {
let $preflightTypesMap = {};
const cloud = $stdlib.cloud;
$helpers.nodeof(this).root.$preflightTypesMap = $preflightTypesMap;
class Process extends $stdlib.std.Resource {
constructor($scope, $id, ) {
super($scope, $id);
}
static write(s) {
return ($extern("../../../print-helpers.js")["write"])(s)
}
static _toInflightType() {
return `
require("${$helpers.normalPath(__dirname)}/inflight.Process-1.cjs")({
})
`;
}
_toInflight() {
return `
(await (async () => {
const ProcessClient = ${Process._toInflightType()};
const client = new ProcessClient({
});
if (client.$inflight_init) { await client.$inflight_init(); }
return client;
})())
`;
}
get _liftMap() {
return ({
"$inflight_init": [
],
});
}
}
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
Expand Down Expand Up @@ -146,6 +192,8 @@ class $Root extends $stdlib.std.Resource {
}
}
console.log("preflight log");
(Process.write("start "));
(Process.write("end\n"));
globalThis.$ClassFactory.new("@winglang/sdk.std.Test", std.Test, this, "test:log1", new $Closure1(this, "$Closure1"));
globalThis.$ClassFactory.new("@winglang/sdk.std.Test", std.Test, this, "test:log2", new $Closure2(this, "$Closure2"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## stdout.log
```log
preflight log
start end
preflight log
start end
[INFO] log1 | inflight log 1.1
[INFO] log1 | inflight log 1.2
[INFO] log2 | inflight log 2.1
Expand Down
Loading