Skip to content

Commit

Permalink
Update deno and all dependencies. Bump version to v0.2.0-alpha.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitive committed Sep 20, 2021
1 parent fe13457 commit 7a71989
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 54 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deno 1.14.0
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
HELM=$(shell which helm3 || which helm)

build:
bin/deno bundle --unstable src/index.ts bin/bundle.js
bin/deno --unstable bundle src/index.ts bin/bundle.js

install: install-tools install-plugin

install-tools:
@ yarn --frozen-lockfile

install-plugin:
@ HELM_PLUGIN_DIR="$$PWD" ./scripts/install.sh v1.8.3
@ HELM_PLUGIN_DIR="$$PWD" ./scripts/install.sh v1.14.0

lint:
@ yarn prettier --check .
Expand All @@ -38,5 +38,4 @@ test-all:
@ $(shell $(HELM) env) RUN_ALL_TESTS=true bin/deno test --unstable --allow-run --allow-read --allow-write --allow-env --allow-net src/ e2e-tests/

update-deps:
@ # Install udd: https://github.com/hayd/deno-udd
udd src/**/*.ts
deno run -A https://deno.land/x/udd@0.5.0/main.ts src/**/*.ts
18 changes: 10 additions & 8 deletions e2e-tests/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { getAvailablePort } from "https://deno.land/x/port@1.0.0/mod.ts"
import * as fs from "https://deno.land/std@0.93.0/fs/mod.ts"
import * as path from "https://deno.land/std@0.93.0/path/mod.ts"
import * as yaml from "https://deno.land/std@0.93.0/encoding/yaml.ts"
// Use fork until https://github.com/piyush-bhatt/deno-port/pull/1 is merged
import { getAvailablePort } from "https://raw.githubusercontent.com/Nitive/deno-port/fix-getting-random-port/mod.ts"

import { exists } from "https://deno.land/std@0.107.0/fs/exists.ts"
import * as path from "https://deno.land/std@0.107.0/path/mod.ts"
import * as yaml from "https://deno.land/std@0.107.0/encoding/yaml.ts"
import {
assertEquals,
assertStringIncludes,
} from "https://deno.land/std@0.93.0/testing/asserts.ts"
} from "https://deno.land/std@0.107.0/testing/asserts.ts"
import { ignoreNotFoundError } from "../src/utils/ignore-not-found-error.ts"
import { waitForProcess } from "../src/utils/process.ts"

Expand Down Expand Up @@ -445,7 +447,7 @@ Deno.test({
}
assertEquals(status.success, true, "should successfully push")

const isDenoBundleExists = await fs.exists(
const isDenoBundleExists = await exists(
path.join(chartPath, "deno-bundle.js")
)
assertEquals(
Expand All @@ -469,7 +471,7 @@ Deno.test({
"should successfully fetch"
)

const isDenoBundleInFetchedChartExists = await fs.exists(
const isDenoBundleInFetchedChartExists = await exists(
path.join(fetchDirectory, "one-service/deno-bundle.js")
)
assertEquals(
Expand Down Expand Up @@ -502,7 +504,7 @@ Deno.test({
assertEquals(status.success, false, "should not successfully push")
}

const isDenoBundleExists = await fs.exists(denoBundlePath)
const isDenoBundleExists = await exists(denoBundlePath)
assertEquals(
isDenoBundleExists,
false,
Expand Down
9 changes: 4 additions & 5 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: "deno"
version: "0.1.0-alpha.4"
version: "0.2.0-alpha.1"
usage: "Helm charts with Deno"
description: |-
This plugin provides Deno for Helm charts
useTunnel: false
This plugin allows to use Deno to prepare kubernetes manifests
hooks:
install: "$HELM_PLUGIN_DIR/scripts/install.sh v1.8.3"
update: "$HELM_PLUGIN_DIR/scripts/install.sh v1.8.3"
install: "$HELM_PLUGIN_DIR/scripts/install.sh v1.14.0"
update: "$HELM_PLUGIN_DIR/scripts/install.sh v1.14.0"
command: "$HELM_PLUGIN_DIR/scripts/run.sh"
2 changes: 1 addition & 1 deletion src/args/__tests__/parse-args.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts"
import { assertEquals } from "https://deno.land/std@0.107.0/testing/asserts.ts"
import { parseArgs } from "../parse-helm-deno-args.ts"

Deno.test("Should parse --deno-* flags", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/args/__tests__/parse-helm-args.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts"
import { assertEquals } from "https://deno.land/std@0.107.0/testing/asserts.ts"
import { parseHelmArgs } from "../parse-helm-args.ts"

Deno.test("Should parse helm template args for `helm upgrade`", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/args/__tests__/parse-helm-fetch-args.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts"
import { assertEquals } from "https://deno.land/std@0.107.0/testing/asserts.ts"
import { parseHelmFetchArgs } from "../parse-helm-fetch-args.ts"

Deno.test("Should parse helm fetch args", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/args/__tests__/parse-helm-template-args.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts"
import { assertEquals } from "https://deno.land/std@0.107.0/testing/asserts.ts"
import { parseHelmTemplateArgs } from "../parse-helm-template-args.ts"

Deno.test("Should parse helm template args", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/args/parse-helm-deno-args.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import args from "https://deno.land/x/args@2.1.0/wrapper.ts"
import args from "https://deno.land/x/args@2.1.1/wrapper.ts"
import {
PartialOption,
BinaryFlag,
} from "https://deno.land/x/args@2.1.0/flag-types.ts"
import { Choice, Text } from "https://deno.land/x/args@2.1.0/value-types.ts"
} from "https://deno.land/x/args@2.1.1/flag-types.ts"
import { Choice, Text } from "https://deno.land/x/args@2.1.1/value-types.ts"

type LogLevel = "info" | "debug"

Expand Down
6 changes: 3 additions & 3 deletions src/args/parse-helm-fetch-args.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import args from "https://deno.land/x/args@2.1.0/wrapper.ts"
import args from "https://deno.land/x/args@2.1.1/wrapper.ts"
import {
PartialOption,
BinaryFlag,
} from "https://deno.land/x/args@2.1.0/flag-types.ts"
import { Text } from "https://deno.land/x/args@2.1.0/value-types.ts"
} from "https://deno.land/x/args@2.1.1/flag-types.ts"
import { Text } from "https://deno.land/x/args@2.1.1/value-types.ts"

const textOption = (flag: string) =>
PartialOption(flag, {
Expand Down
6 changes: 3 additions & 3 deletions src/args/parse-helm-template-args.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import args from "https://deno.land/x/args@2.1.0/wrapper.ts"
import { CollectOption } from "https://deno.land/x/args@2.1.0/flag-types.ts"
import { Text } from "https://deno.land/x/args@2.1.0/value-types.ts"
import args from "https://deno.land/x/args@2.1.1/wrapper.ts"
import { CollectOption } from "https://deno.land/x/args@2.1.1/flag-types.ts"
import { Text } from "https://deno.land/x/args@2.1.1/value-types.ts"

const textOption = (flag: string, alias?: readonly string[]) =>
CollectOption(flag, {
Expand Down
15 changes: 8 additions & 7 deletions src/deno/render-chart.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ChartContext } from "../std/mod.ts"
import type { HelmDenoOptions } from "../args/parse-helm-deno-args.ts"
import * as yaml from "https://deno.land/std@0.93.0/encoding/yaml.ts"
import * as fs from "https://deno.land/std@0.93.0/fs/mod.ts"
import * as path from "https://deno.land/std@0.93.0/path/mod.ts"
import * as yaml from "https://deno.land/std@0.107.0/encoding/yaml.ts"
import { exists } from "https://deno.land/std@0.107.0/fs/exists.ts"
import { ensureDir } from "https://deno.land/std@0.107.0/fs/ensure_dir.ts"
import * as path from "https://deno.land/std@0.107.0/path/mod.ts"
import { ignoreNotFoundError } from "../utils/ignore-not-found-error.ts"
import { waitForProcess } from "../utils/process.ts"

Expand All @@ -21,7 +22,7 @@ async function getImportMapFlags(denoOptions: HelmDenoOptions) {
return []
}

const hasImportMap = await fs.exists(denoOptions.importMap)
const hasImportMap = await exists(denoOptions.importMap)

if (!hasImportMap) {
throw new Error(`Could not find import map ${denoOptions.importMap}`)
Expand All @@ -44,7 +45,7 @@ async function getDenoTemplateFilePath(
return indexFilePath
}

const bundleExists = await fs.exists(bundlePath)
const bundleExists = await exists(bundlePath)

if (denoOptions.bundlePolicy === "require") {
if (!bundleExists) {
Expand Down Expand Up @@ -112,10 +113,10 @@ export async function renderDenoChart(
bundlePath,
indexFilePath,
} = getPaths(chartPath)
await fs.ensureDir(templateFolderPath)
await ensureDir(templateFolderPath)

const isDenoChart =
(await fs.exists(bundlePath)) || (await fs.exists(indexFilePath))
(await exists(bundlePath)) || (await exists(indexFilePath))
if (!isDenoChart) {
return
}
Expand Down
4 changes: 3 additions & 1 deletion src/helm/execute.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isSigterm } from "../utils/process.ts"

export async function helmExecute(
args: readonly string[],
{ autoExitOnError = false }: { autoExitOnError?: boolean } = {}
Expand All @@ -11,7 +13,7 @@ export async function helmExecute(

const status = await cmd.status()
if (!status.success) {
if (status.signal === Deno.Signal.SIGTERM) {
if (isSigterm(status.signal)) {
console.error("Child process terminated via SIGTERM")
}

Expand Down
12 changes: 7 additions & 5 deletions src/helm/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as fs from "https://deno.land/std@0.93.0/fs/mod.ts"
import * as path from "https://deno.land/std@0.93.0/path/mod.ts"
import { exists } from "https://deno.land/std@0.107.0/fs/exists.ts"
import { copy } from "https://deno.land/std@0.107.0/fs/copy.ts"
import { expandGlob } from "https://deno.land/std@0.107.0/fs/expand_glob.ts"
import * as path from "https://deno.land/std@0.107.0/path/mod.ts"
import { parseHelmFetchArgs } from "../args/parse-helm-fetch-args.ts"
import { withErrorMsg } from "../std/mod.ts"
import { waitForProcess } from "../utils/process.ts"
Expand All @@ -10,7 +12,7 @@ export async function fetchChart(
chartPath: string,
args: readonly string[]
): Promise<void> {
const destinationExists = await fs.exists(tmpDirectory)
const destinationExists = await exists(tmpDirectory)
if (!destinationExists) {
return Promise.reject(`Could not find ${tmpDirectory}`)
}
Expand All @@ -34,7 +36,7 @@ export async function fetchChart(
await waitForProcess(cmd, { autoReject: true })

const directories = []
for await (const file of fs.expandGlob("*/", {
for await (const file of expandGlob("*/", {
root: fetchDestination,
})) {
if (file.isDirectory && !file.path.endsWith(".tgz")) {
Expand All @@ -47,7 +49,7 @@ export async function fetchChart(
}

await withErrorMsg(
fs.copy(directories[0], chartPath),
copy(directories[0], chartPath),
`Could not fetch chart ${chartBlob}`
)
}
11 changes: 6 additions & 5 deletions src/helm/get-chart-context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ChartContext, Release } from "../std/mod.ts"
import * as fs from "https://deno.land/std@0.93.0/fs/mod.ts"
import * as path from "https://deno.land/std@0.93.0/path/mod.ts"
import * as yaml from "https://deno.land/std@0.93.0/encoding/yaml.ts"
import { copy } from "https://deno.land/std@0.107.0/fs/copy.ts"
import { ensureDir } from "https://deno.land/std@0.107.0/fs/ensure_dir.ts"
import * as path from "https://deno.land/std@0.107.0/path/mod.ts"
import * as yaml from "https://deno.land/std@0.107.0/encoding/yaml.ts"
import { parseHelmTemplateArgs } from "../args/parse-helm-template-args.ts"
import { ignoreNotFoundError } from "../utils/ignore-not-found-error.ts"
import { waitForProcess } from "../utils/process.ts"
Expand Down Expand Up @@ -42,12 +43,12 @@ export async function getChartContext(
): Promise<ChartContext> {
const getValuesChartDir = path.join(tmpDir, "get-values-chart")
try {
await fs.copy(chartDir, getValuesChartDir)
await copy(chartDir, getValuesChartDir)
const getValuesTemplatesDir = path.join(getValuesChartDir, "templates")
await ignoreNotFoundError(
Deno.remove(getValuesTemplatesDir, { recursive: true })
)
await fs.ensureDir(getValuesTemplatesDir)
await ensureDir(getValuesTemplatesDir)

await Deno.writeFile(
path.join(getValuesChartDir, "templates/values-and-release.yaml"),
Expand Down
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// deno-lint-ignore-file
import * as fs from "https://deno.land/std@0.93.0/fs/mod.ts"
import * as path from "https://deno.land/std@0.93.0/path/mod.ts"
import { exists } from "https://deno.land/std@0.107.0/fs/exists.ts"
import { copy } from "https://deno.land/std@0.107.0/fs/copy.ts"
import * as path from "https://deno.land/std@0.107.0/path/mod.ts"
import { parseHelmArgs, supportedCommands } from "./args/parse-helm-args.ts"
import { parseArgs } from "./args/parse-helm-deno-args.ts"
import {
Expand Down Expand Up @@ -43,19 +44,19 @@ Typical usage:
}

async function copyChart(chartPath: string, destination: string) {
const destinationExists = await fs.exists(chartPath)
const destinationExists = await exists(chartPath)
if (!destinationExists) {
return Promise.reject(`Could not find ${chartPath}`)
}
await withErrorMsg(
fs.copy(chartPath, destination, { overwrite: true }),
copy(chartPath, destination, { overwrite: true }),
"Could not copy chart directory"
)
}

async function isChartExist(chartPath: string) {
const chartYamlPath = path.join(chartPath, "Chart.yaml")
return await fs.exists(chartYamlPath)
return await exists(chartYamlPath)
}

async function main() {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/process.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { toText } from "./text.ts"

export function isSigterm(signal: number | undefined) {
return signal === 15
}

export async function waitForProcess(
ps: Deno.Process,
opts: { autoReject?: boolean } = {}
Expand All @@ -13,7 +17,7 @@ export async function waitForProcess(

const stdout = toText(output)
let stderr = toText(error)
if (status.signal === Deno.Signal.SIGTERM) {
if (isSigterm(status.signal)) {
stderr = `Child process terminated via SIGTERM\n${stderr}`
}

Expand Down

0 comments on commit 7a71989

Please sign in to comment.