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

feat: add polywrap.yaml project resources #1430

Merged
merged 6 commits into from
Nov 21, 2022
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Polywrap Origin (0.10.0-pre.4)
## Features
* [PR-1430](https://github.com/polywrap/toolchain/pull/1430) `polywrap` CLI: Polywrap projects can now include a list of `resources:` that are included in the `polywrap.yaml` project manifest. Each resource is a path to a file. For example:
```yaml
format: 0.3.0
project:
...
source:
...
resources:
- ./README.md
- ./resource.dat
```
* [PR-1430](https://github.com/polywrap/toolchain/pull/1430) `@polywrap/polywrap-manifest-types-js`, `@polywrap/polywrap-manifest-schemas`: Added version `0.3.0` of the `PolywrapManifest`, which includes the new `resources: string[]` field, containing file paths.
* [PR-1411](https://github.com/polywrap/toolchain/pull/1411) `@polywrap/client-config-builder-js`: The `ens-text-record-resolver` wrapper @ [`wrap://ipfs/QmfRCVA1MSAjUbrXXjya4xA9QHkbWeiKRsT7Um1cvrR7FY`](https://wrappers.io/v/ipfs/QmfRCVA1MSAjUbrXXjya4xA9QHkbWeiKRsT7Um1cvrR7FY) has been added to the default client config bundle. This resolver enables ENS, text-record based, WRAP URI resolution. The text-record's key must be prepended with the `wrap/...` identifier. For example, the URI `wrap://ens/domain.eth:foo` maps to `domain.eth`'s `wrap/foo` text record. The `wrap/foo` text-record's value must contain another valid WRAP URI. For examples, see [dev.polywrap.eth](https://app.ens.domains/name/dev.polywrap.eth/details).
* [PR-1369](https://github.com/polywrap/toolchain/pull/1369) `@polywrap/core-js`:
* `GetImplementationsOptions` now accepts an optional resolution context, to be used to handle infinite recursion when a resolver uses `getImplementations`
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@
"lib_compiler_noInvoke": "WASM module is missing the _wrap_invoke export. This should never happen...",
"lib_compiler_invalid_module": "Invalid Wasm module found. {modulePath} is invalid. Error: {error}",
"lib_compiler_cannotBuildInterfaceModules": "Cannot build modules for an Interface Polywrap",
"lib_compiler_copyResourcesFolderText": "Copying resources folder: {folder}",
"lib_compiler_copyResourcesFolderError": "Failed to copy resources folder: {folder}",
"lib_compiler_copyResourcesFolderWarning": "Warnings copying resources folder: {folder}",
"lib_compiler_outputMetadataText": "Metadata written",
"lib_compiler_outputMetadataError": "Failed to output metadata",
"lib_compiler_outputMetadataWarning": "Warnings writing metadata",
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@
"lib_compiler_noInvoke": "WASM module is missing the _wrap_invoke export. This should never happen...",
"lib_compiler_invalid_module": "Invalid Wasm module found. {modulePath} is invalid. Error: {error}",
"lib_compiler_cannotBuildInterfaceModules": "Cannot build modules for an Interface Polywrap",
"lib_compiler_copyResourcesFolderText": "Copying resources folder: {folder}",
"lib_compiler_copyResourcesFolderError": "Failed to copy resources folder: {folder}",
"lib_compiler_copyResourcesFolderWarning": "Warnings copying resources folder: {folder}",
"lib_compiler_outputMetadataText": "Metadata written",
"lib_compiler_outputMetadataError": "Failed to output metadata",
"lib_compiler_outputMetadataWarning": "Warnings writing metadata",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/__tests__/e2e/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ describe("e2e tests for build command", () => {

for (const file of expectedFiles) {
if (!fs.existsSync(path.join(buildDir, file))) {
expect(path.join(buildDir, file)).toBe("debug")
fail(`Did not find expected file: ${path.join(buildDir, file)}`);
}
expect(fs.existsSync(path.join(buildDir, file))).toBeTruthy();
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ const runMigrateCommand = async (
return migrateManifestFile(
manifestFile,
migrateAppProjectManifest,
options.format ?? latestPolywrapManifestFormat,
options.format ?? latestAppManifestFormat,
logger
);
} else if (isPluginManifestLanguage(language)) {
Expand All @@ -444,7 +444,7 @@ const runMigrateCommand = async (
return migrateManifestFile(
manifestFile,
migratePluginProjectManifest,
options.format ?? latestPolywrapManifestFormat,
options.format ?? latestPluginManifestFormat,
logger
);
}
Expand Down
47 changes: 40 additions & 7 deletions packages/cli/src/lib/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
generateWrapFile,
intlMsg,
outputManifest,
outputMetadata,
copyMetadata,
PolywrapProject,
resetDir,
SchemaComposer,
Expand All @@ -19,6 +19,7 @@ import { WasmWrapper, WrapImports } from "@polywrap/wasm-js";
import { AsyncWasmInstance } from "@polywrap/asyncify-js";
import { normalizePath } from "@polywrap/os-js";
import fs from "fs";
import fse from "fs-extra";
import path from "path";

export interface CompilerConfig {
Expand Down Expand Up @@ -48,12 +49,15 @@ export class Compiler {
await codeGenerator.generate();
}

// Compile the Wrapper
// Compile & Output: wrap.wasm
await this._buildModules();
}

// Output Polywrap Metadata
await this._outputPolywrapMetadata();
// Copy: Resources folder
await this._copyResourcesFolder();

// Copy: Polywrap Metadata
await this._copyPolywrapMetadata();
};

try {
Expand Down Expand Up @@ -127,16 +131,45 @@ export class Compiler {
);
}

private async _outputPolywrapMetadata(): Promise<void> {
private async _copyResourcesFolder(): Promise<void> {
const { outputDir, project } = this._config;

const projectManifest = await project.getManifest();

if (!projectManifest || !projectManifest.resources) {
return Promise.resolve();
}

const logger = project.logger;

const folder = projectManifest.resources;
const folderPath = path.resolve(projectManifest.resources);

await logActivity(
logger,
intlMsg.lib_compiler_copyResourcesFolderText({ folder }),
intlMsg.lib_compiler_copyResourcesFolderError({ folder }),
intlMsg.lib_compiler_copyResourcesFolderWarning({ folder }),
async () => {
if (!fs.existsSync(folderPath)) {
throw Error(`Resource can't be found.`);
}

await fse.copy(folderPath, outputDir, { recursive: true });
}
);
}

private async _copyPolywrapMetadata(): Promise<void> {
const { outputDir, project } = this._config;

const projectMetaManifest = await project.getMetaManifest();

if (!projectMetaManifest) {
return undefined;
return Promise.resolve();
}

const builtMetaManifest = await outputMetadata(
const builtMetaManifest = await copyMetadata(
projectMetaManifest,
outputDir,
project.getManifestDir(),
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/helpers/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MetaManifest } from "@polywrap/polywrap-manifest-types-js";
import fs from "fs";
import path from "path";

export async function outputMetadata(
export async function copyMetadata(
metaManifest: MetaManifest,
outputDir: string,
rootDir: string,
Expand Down
80 changes: 80 additions & 0 deletions packages/js/manifests/polywrap/src/formats/polywrap/0.3.0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* tslint:disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

export interface PolywrapManifest {
/**
* Polywrap manifest format version.
*/
format: "0.3.0";
/**
* Basic project properties.
*/
project: {
/**
* Name of this project.
*/
name: string;
/**
* Type of this project.
*/
type: string;
};
/**
* Project source files.
*/
source: {
/**
* Path to the project's entry point.
*/
module?: string;
/**
* Path to the project's graphql schema.
*/
schema: string;
/**
* Specify ABIs to be used for the import URIs within your schema.
*/
import_abis?: ImportAbis[];
};
/**
* Project resources folder
*/
resources?: string;
/**
* Project extension files (build, meta, deploy, infra).
*/
extensions?: {
/**
* Path to the project build manifest file.
*/
build?: string;
/**
* Path to project metadata manifest file.
*/
meta?: string;
/**
* Path to project deploy manifest file.
*/
deploy?: string;
/**
* Path to project infra manifest file.
*/
infra?: string;
};
__type: "PolywrapManifest";
}
export interface ImportAbis {
/**
* One of the schema's import URI.
*/
uri: string;
/**
* Path to a local ABI (or schema). Supported file formats: [*.graphql, *.info, *.json, *.yaml]
*/
abi: string;
}
11 changes: 9 additions & 2 deletions packages/js/manifests/polywrap/src/formats/polywrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,42 @@ import {
import {
PolywrapManifest as PolywrapManifest_0_2_0,
} from "./0.2.0";
import {
PolywrapManifest as PolywrapManifest_0_3_0,
} from "./0.3.0";

export {
PolywrapManifest_0_1_0,
PolywrapManifest_0_2_0,
PolywrapManifest_0_3_0,
};

export enum PolywrapManifestFormats {
// NOTE: Patch fix for backwards compatability
"v0.1" = "0.1",
"v0.1.0" = "0.1.0",
"v0.2.0" = "0.2.0",
"v0.3.0" = "0.3.0",
}

export const PolywrapManifestSchemaFiles: Record<string, string> = {
// NOTE: Patch fix for backwards compatability
"0.1": "formats/polywrap/0.1.0.json",
"0.1.0": "formats/polywrap/0.1.0.json",
"0.2.0": "formats/polywrap/0.2.0.json",
"0.3.0": "formats/polywrap/0.3.0.json",
}

export type AnyPolywrapManifest =
| PolywrapManifest_0_1_0
| PolywrapManifest_0_2_0
| PolywrapManifest_0_3_0



export type PolywrapManifest = PolywrapManifest_0_2_0;
export type PolywrapManifest = PolywrapManifest_0_3_0;

export const latestPolywrapManifestFormat = PolywrapManifestFormats["v0.2.0"]
export const latestPolywrapManifestFormat = PolywrapManifestFormats["v0.3.0"]

export { migratePolywrapManifest } from "./migrate";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ILogger } from "@polywrap/logging-js";
import { PolywrapManifest as OldManifest } from "../0.2.0";
import { PolywrapManifest as NewManifest } from "../0.3.0";

export function migrate(migrate: OldManifest, logger?: ILogger): NewManifest {
return {
...migrate,
format: "0.3.0",
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Migrator } from "../../../migrations";
import { migrate as migrate_0_1_0_to_0_2_0 } from "./0.1.0_to_0.2.0";
import { migrate as migrate_0_2_0_to_0_3_0 } from "./0.2.0_to_0.3.0";

export const migrators: Migrator[] = [
{
Expand All @@ -11,5 +12,10 @@ export const migrators: Migrator[] = [
from: "0.1.0",
to: "0.2.0",
migrate: migrate_0_1_0_to_0_2_0
},
{
from: "0.2.0",
to: "0.3.0",
migrate: migrate_0_2_0_to_0_3_0
}
];
];
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

import PolywrapManifestSchema_0_1_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap/0.1.0.json";
import PolywrapManifestSchema_0_2_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap/0.2.0.json";
import PolywrapManifestSchema_0_3_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap/0.3.0.json";

import {
Schema,
Expand All @@ -28,6 +29,7 @@ const schemas: PolywrapManifestSchemas = {
"0.1": PolywrapManifestSchema_0_1_0,
"0.1.0": PolywrapManifestSchema_0_1_0,
"0.2.0": PolywrapManifestSchema_0_2_0,
"0.3.0": PolywrapManifestSchema_0_3_0,
};

const validator = new Validator();
Expand Down
Loading