Skip to content

Commit

Permalink
Remove implicit protobuf package dependencies from all Dataform proje…
Browse files Browse the repository at this point in the history
…cts. (#410)
  • Loading branch information
BenBirt authored and probot-auto-merge[bot] committed Sep 2, 2019
1 parent 965aea1 commit e1086ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 4 additions & 7 deletions core/gen_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ export function genIndex(base64EncodedConfig: string): string {
dataform.ProjectConfig.create(config.compileConfig.projectConfigOverride).toJSON()
);

// NOTE:
// - The returned script must be valid JavaScript (not TypeScript)
// - The returned script may not require() any package that is not "@dataform/core"
return `
require("@dataform/core");
const protos = require("@dataform/protos");
const { util } = require("protobufjs");
${includeRequires}
let projectConfig = require("./dataform.json");
// For backwards compatibility, in case core version is ahead of api.
Expand All @@ -50,11 +51,7 @@ export function genIndex(base64EncodedConfig: string): string {
projectConfig = { ...projectConfig, ...${projectOverridesJsonString} };
global.session.init("${config.compileConfig.projectDir}", projectConfig);
${definitionRequires}
const compiledGraph = global.session.compile();
// Keep backwards compatibility with un-namespaced protobufs (i.e. before dataform protobufs were inside a package).
const protoNamespace = (protos.dataform) ? protos.dataform : protos;
// We return a base64 encoded proto via NodeVM, as returning a Uint8Array directly causes issues.
const encodedGraphBytes = protoNamespace.CompiledGraph.encode(compiledGraph).finish();
const base64EncodedGraphBytes = util.base64.encode(encodedGraphBytes, 0, encodedGraphBytes.length);
const base64EncodedGraphBytes = global.session.compileToBase64();
return ${config.returnOverride || "base64EncodedGraphBytes"};`;
}
6 changes: 6 additions & 0 deletions core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as table from "@dataform/core/table";
import * as test from "@dataform/core/test";
import * as utils from "@dataform/core/utils";
import { dataform } from "@dataform/protos";
import { util } from "protobufjs";

interface IActionProto {
name?: string;
Expand Down Expand Up @@ -426,6 +427,11 @@ export class Session {
return compiledGraph;
}

public compileToBase64() {
const encodedGraphBytes = dataform.CompiledGraph.encode(this.compile()).finish();
return util.base64.encode(encodedGraphBytes, 0, encodedGraphBytes.length);
}

public findActions(res: Resolvable) {
const adapter = this.adapter();
return this.actions.filter(action => {
Expand Down
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# NOTE: If you change the format of this line, you must change the bash command
# in /scripts/publish to extract the version string correctly.
DF_VERSION = "1.3.1"
DF_VERSION = "1.3.2"

0 comments on commit e1086ae

Please sign in to comment.