Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
81722c2
Added build strategy defaults for JS
namesty Aug 22, 2023
41f464f
Added wrap/js as a language
namesty Aug 28, 2023
0e16386
FIxed naming and giving typescript its own language definition
namesty Sep 1, 2023
0726fed
Merge remote-tracking branch 'origin/origin-dev' into namesty/wrap-js…
namesty Sep 1, 2023
97f13db
Added ts to bind language outputs
namesty Sep 1, 2023
367f349
Image strategy working and building fine
namesty Sep 1, 2023
ea10982
Added template project + create command addition
namesty Sep 4, 2023
8a28933
Added build test cases
namesty Sep 4, 2023
3f2dde0
Edited local strategy skip reason
namesty Sep 4, 2023
7e6f22c
Enabled VM build strategy + separated bindings language from build lang
namesty Sep 5, 2023
530e06e
Updated TS template to use VM strategy by default. Like the others
namesty Sep 5, 2023
25e4836
Fixed create spec
namesty Sep 5, 2023
1b174b6
Merge remote-tracking branch 'origin/origin-dev' into namesty/wrap-js…
namesty Sep 5, 2023
5cf3694
Moved buildable language definition + added comments for build strats
namesty Sep 6, 2023
08195b2
Changed bindings URI to Wrapscan URI
namesty Sep 6, 2023
3e60c84
Init VM image at version 0.0.1
namesty Sep 6, 2023
2661b89
Copying moduleFilePath in JS wrap strategies, instead of moduleDirs
namesty Sep 6, 2023
fc45feb
Lint fixes
namesty Sep 6, 2023
285ad3b
Merge branch 'origin-dev' into namesty/wrap-ts-support
dOrgJelli Sep 7, 2023
2ddc176
Merge branch 'origin-dev' into namesty/wrap-ts-support
dOrgJelli Sep 7, 2023
702862f
chore: fix polywrap cli install
dOrgJelli Sep 7, 2023
04f2071
chore: fix template tests
dOrgJelli Sep 7, 2023
7419b56
chore: add tests to wrap/typescript
dOrgJelli Sep 7, 2023
eaaf9cb
chore: fix lint
dOrgJelli Sep 7, 2023
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
22 changes: 22 additions & 0 deletions packages/cli/jest.ts.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
collectCoverage: true,
preset: "ts-jest",
testEnvironment: "node",
globals: {
"ts-jest": {
diagnostics: false
},
},
modulePathIgnorePatterns: [
"<rootDir>/build",
"<rootDir>/src/__tests__/project/.polywrap"
],
testPathIgnorePatterns: [
"<rootDir>/src/__tests__/project/.polywrap"
],
transformIgnorePatterns: [
"<rootDir>/src/__tests__/project/.polywrap"
],
setupFilesAfterEnv: ["./jest.setup.js"],
testMatch: ["**/build-ts.spec.ts"]
};
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"test:e2e:p2": "yarn test:cmd -- ./src/__tests__/e2e/p2/*.spec.ts",
"test:rust": "yarn test:cmd -- --config ./jest.rs.config.js",
"test:golang": "yarn test:cmd -- --config ./jest.go.config.js",
"test:typescript": "yarn test:cmd -- --config ./jest.ts.config.js",
"test:watch": "yarn test -- --watch",
"test:pkg": "PKG_CLI=true yarn test:e2e:p1 && yarn test:e2e:p2",
"pkg:prod": "pkg . --compress Brotli",
Expand Down
72 changes: 72 additions & 0 deletions packages/cli/src/__tests__/e2e/build-ts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { polywrapCli } from "./utils";
import { Commands } from "@polywrap/cli-js";
import { GetPathToCliTestFiles } from "@polywrap/test-cases";
import fs from "fs";
import path from "path";

jest.setTimeout(1500000);

describe("e2e tests for build command", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "build-cmd/wasm/typescript");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);

const getTestCaseDir = (index: number) =>
path.join(testCaseRoot, testCases[index]);

describe("Image strategy", () => {
it("Builds for typescript", async () => {
const { exitCode: code, stdout: output } = await Commands.build({
strategy: "image",
verbose: true
}, {
cwd: getTestCaseDir(0),
cli: polywrapCli,
});
const buildDir = `./build`;

expect(code).toEqual(0);
expect(output).toContain(`Artifacts written to ${buildDir}`);
expect(output).toContain(`WRAP manifest written in ${buildDir}/wrap.info`);
});
})

// NOTE: Skipped because CI needs system prequisites: pwr CLI
describe.skip("Local strategy", () => {
it("Builds for typescript", async () => {
const { exitCode: code, stdout: output } = await Commands.build({
strategy: "local",
verbose: true
}, {
cwd: getTestCaseDir(0),
cli: polywrapCli,
});

const buildDir = `./build`;

expect(code).toEqual(0);
expect(output).toContain(`Artifacts written to ${buildDir}`);
expect(output).toContain(`WRAP manifest written in ${buildDir}/wrap.info`);
});
})

describe("VM strategy", () => {
it("Builds for typescript", async () => {
const { exitCode: code, stdout: output } = await Commands.build({
strategy: "vm",
verbose: true
}, {
cwd: getTestCaseDir(0),
cli: polywrapCli,
});

const buildDir = `./build`;

expect(code).toEqual(0);
expect(output).toContain(`Artifacts written to ${buildDir}`);
expect(output).toContain(`WRAP manifest written in ${buildDir}/wrap.info`);
});
})
});
3 changes: 2 additions & 1 deletion packages/cli/src/__tests__/e2e/p1/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Options:

Commands:
wasm [options] <language> <name> Create a Polywrap wasm wrapper. langs:
assemblyscript, rust, golang, interface
assemblyscript, rust, golang, typescript,
interface
app [options] <language> <name> Create a Polywrap application. langs:
typescript, python, rust, android, ios
plugin [options] <language> <name> Create a Polywrap plugin. langs:
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ const pathStr = intlMsg.commands_create_options_o_path();
const urlStr = intlMsg.commands_create_options_t_url();

export const supportedLangs = {
wasm: ["assemblyscript", "rust", "golang", "interface"] as const,
wasm: [
"assemblyscript",
"rust",
"golang",
"typescript",
"interface",
] as const,
app: ["typescript", "python", "rust", "android", "ios"] as const,
plugin: ["typescript", "rust", "python"] as const,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/build-strategies/BuildOverrides.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PolywrapManifestLanguage } from "../";
import { PolywrapBuildLanguage } from "../";

import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js";
import path from "path";
Expand All @@ -11,7 +11,7 @@ export interface BuildOverrides {
}

export async function tryGetBuildOverrides(
language: PolywrapManifestLanguage
language: PolywrapBuildLanguage
): Promise<BuildOverrides | undefined> {
const modulePath = path.join(
__dirname,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/build-strategies/BuildStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export abstract class BuildStrategy<TBuildReturn = unknown> {
abstract getStrategyName(): string;

async build(): Promise<TBuildReturn> {
const language = await this.project.getManifestLanguage();
const language = await this.project.getBuildLanguage();
const buildStrategyDir = path.join(
__dirname,
"..",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class DockerImageBuildStrategy extends BuildStrategy<BuildImageId> {
buildManifest?.strategies?.image?.name ||
generateDockerImageName(await this.project.getBuildUuid());

const language = await this.project.getManifestLanguage();
const language = await this.project.getBuildLanguage();

const dockerfileTemplatePath = path.join(
__dirname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BuildStrategyConfig, BuildStrategy } from "../BuildStrategy";
import { intlMsg } from "../../intl";
import {
BuildManifestConfig,
PolywrapManifestLanguage,
BuildableLanguage,
PolywrapProject,
} from "../../project";
import { logActivity } from "../../logging";
Expand All @@ -17,7 +17,6 @@ import fse from "fs-extra";
import path from "path";
import Mustache from "mustache";

type BuildableLanguage = Exclude<PolywrapManifestLanguage, "interface">;
const DEFAULTS_DIR = path.join(
__dirname,
"..",
Expand Down Expand Up @@ -48,6 +47,11 @@ const CONFIGS: Record<BuildableLanguage, VMConfig> = {
baseImage: "polywrap/vm-base-go",
version: "0.1.6",
},
"wasm/javascript": {
defaultIncludes: [],
baseImage: "polywrap/vm-base-js",
version: "0.1.6",
},
};

export class DockerVMBuildStrategy extends BuildStrategy<void> {
Expand Down Expand Up @@ -98,7 +102,7 @@ export class DockerVMBuildStrategy extends BuildStrategy<void> {
);
});

const language = (await this.project.getManifestLanguage()) as BuildableLanguage;
const language = (await this.project.getBuildLanguage()) as BuildableLanguage;

if (buildManifestConfig.polywrap_linked_packages) {
if (fse.existsSync(this._volumePaths.linkedPackages)) {
Expand Down Expand Up @@ -138,14 +142,28 @@ export class DockerVMBuildStrategy extends BuildStrategy<void> {

// Copy sources and build
if (buildManifestConfig.polywrap_module) {
const sourcesSubDirectory =
this.overrides?.sourcesSubDirectory ||
buildManifestConfig.polywrap_module.dir;
// TODO: find more general solution: sources array or glob
// JS needs to copy a single file; others may need several or dirs
if (language === "wasm/javascript") {
const moduleFilePath =
buildManifestConfig.polywrap_module.moduleFilePath;
const outputPath = path.join(
this._volumePaths.project,
moduleFilePath
);
const outputDir = path.dirname(outputPath);
fse.mkdirSync(outputDir, { recursive: true });
fse.copyFileSync(moduleFilePath, outputPath);
} else {
const sourcesSubDirectory =
this.overrides?.sourcesSubDirectory ||
buildManifestConfig.polywrap_module.dir;

fse.copySync(
path.join(manifestDir, sourcesSubDirectory),
path.join(this._volumePaths.project, sourcesSubDirectory)
);
fse.copySync(
path.join(manifestDir, sourcesSubDirectory),
path.join(this._volumePaths.project, sourcesSubDirectory)
);
}

const scriptTemplate = fse.readFileSync(
path.join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ export class LocalBuildStrategy extends BuildStrategy<void> {

public async buildSources(): Promise<void> {
const run = async () => {
const bindLanguage = await this.project.getManifestLanguage();
const bindLanguage = await this.project.getBuildLanguage();

const buildManifest = await this.project.getBuildManifest();
const buildManifestConfig = buildManifest.config as BuildManifestConfig;

if (buildManifestConfig.polywrap_module) {
const polywrapModuleDir = buildManifestConfig.polywrap_module.dir;
const polywrapModuleFilePath =
buildManifestConfig.polywrap_module.moduleFilePath;
let scriptPath = `${__dirname}/../../defaults/build-strategies/${bindLanguage}/${this.getStrategyName()}/local.sh`;

if (bindLanguage.startsWith("wasm")) {
Expand All @@ -39,7 +42,13 @@ export class LocalBuildStrategy extends BuildStrategy<void> {
).then(() =>
runCommand(
scriptPath,
[polywrapModuleDir, this.outputDir],
[
polywrapModuleDir,
this.outputDir,
// TODO: this is an arg for JS wraps only. This should be
// removed in favor of a more general sources passing solution
polywrapModuleFilePath,
],
logger,
undefined,
process.cwd()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
format: 0.3.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:latest
# Install curl and git
RUN apt-get update && apt-get install -y curl git

# Download and install pwrup
RUN curl -L https://raw.githubusercontent.com/polywrap/pwr/main/pwrup/install | bash
# Source bash and use pwrup to install pwr
RUN /bin/bash -i -c "source ~/.bashrc; pwrup"

WORKDIR /project
# Copy the script file to build
COPY {{#polywrap_module}}{{moduleFilePath}}{{/polywrap_module}} ./wrap.js
# Use pwr to build the script
RUN /bin/bash -i -c "pwr js build -f ./wrap.js -o build"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Assumes user has curl and git installed
# Install pwrup
curl -L https://raw.githubusercontent.com/polywrap/pwr/main/pwrup/install | bash

# Use pwrup to install pwr
$HOME/.pwr/bin/pwrup
# Use pwr to build the script
$HOME/.pwr/bin/pwr js build -f $3 -o build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"properties": {
"config": {
"type": "object",
"required": ["scriptFile"],
"properties": {
"scriptFile": {
"description": "Path to the JS file to build the wrap from",
"type": "string"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ubuntu:latest
# Install curl and git
RUN apt-get update && apt-get install -y curl git

# Download and install pwrup and then use it to install pwr
RUN curl -L https://raw.githubusercontent.com/polywrap/pwr/main/pwrup/install | bash && /root/.pwr/bin/pwrup
Comment thread
namesty marked this conversation as resolved.

WORKDIR /project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
polywrap/vm-base-js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -e

{{! Use pwr to build the script }}
/root/.pwr/bin/pwr js build -f {{#polywrap_module}}{{moduleFilePath}}{{/polywrap_module}} -o build
Loading