From 7a719894be11297228fdcec8cb6150f25a5be903 Mon Sep 17 00:00:00 2001 From: Maxim Samoilov Date: Mon, 20 Sep 2021 18:24:17 +0300 Subject: [PATCH] Update deno and all dependencies. Bump version to v0.2.0-alpha.1 --- .tool-versions | 1 + Makefile | 7 +++---- e2e-tests/e2e.test.ts | 18 ++++++++++-------- plugin.yaml | 9 ++++----- src/args/__tests__/parse-args.test.ts | 2 +- src/args/__tests__/parse-helm-args.test.ts | 2 +- .../__tests__/parse-helm-fetch-args.test.ts | 2 +- .../__tests__/parse-helm-template-args.test.ts | 2 +- src/args/parse-helm-deno-args.ts | 6 +++--- src/args/parse-helm-fetch-args.ts | 6 +++--- src/args/parse-helm-template-args.ts | 6 +++--- src/deno/render-chart.ts | 15 ++++++++------- src/helm/execute.ts | 4 +++- src/helm/fetch.ts | 12 +++++++----- src/helm/get-chart-context.ts | 11 ++++++----- src/index.ts | 11 ++++++----- src/utils/process.ts | 6 +++++- 17 files changed, 66 insertions(+), 54 deletions(-) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..08845be --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +deno 1.14.0 diff --git a/Makefile b/Makefile index d2a6e65..cd4eead 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ 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 @@ -11,7 +11,7 @@ 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 . @@ -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 diff --git a/e2e-tests/e2e.test.ts b/e2e-tests/e2e.test.ts index 47ba1d4..df2d9ef 100644 --- a/e2e-tests/e2e.test.ts +++ b/e2e-tests/e2e.test.ts @@ -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" @@ -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( @@ -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( @@ -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, diff --git a/plugin.yaml b/plugin.yaml index 34293f9..0ee4a52 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -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" diff --git a/src/args/__tests__/parse-args.test.ts b/src/args/__tests__/parse-args.test.ts index 60da416..10880ae 100644 --- a/src/args/__tests__/parse-args.test.ts +++ b/src/args/__tests__/parse-args.test.ts @@ -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", () => { diff --git a/src/args/__tests__/parse-helm-args.test.ts b/src/args/__tests__/parse-helm-args.test.ts index caf5b74..6b099c9 100644 --- a/src/args/__tests__/parse-helm-args.test.ts +++ b/src/args/__tests__/parse-helm-args.test.ts @@ -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`", () => { diff --git a/src/args/__tests__/parse-helm-fetch-args.test.ts b/src/args/__tests__/parse-helm-fetch-args.test.ts index e48edc2..0ca88a8 100644 --- a/src/args/__tests__/parse-helm-fetch-args.test.ts +++ b/src/args/__tests__/parse-helm-fetch-args.test.ts @@ -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", () => { diff --git a/src/args/__tests__/parse-helm-template-args.test.ts b/src/args/__tests__/parse-helm-template-args.test.ts index b0fa20a..f91963c 100644 --- a/src/args/__tests__/parse-helm-template-args.test.ts +++ b/src/args/__tests__/parse-helm-template-args.test.ts @@ -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", () => { diff --git a/src/args/parse-helm-deno-args.ts b/src/args/parse-helm-deno-args.ts index 16e5723..01d93d5 100644 --- a/src/args/parse-helm-deno-args.ts +++ b/src/args/parse-helm-deno-args.ts @@ -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" diff --git a/src/args/parse-helm-fetch-args.ts b/src/args/parse-helm-fetch-args.ts index 68033bd..e51eb00 100644 --- a/src/args/parse-helm-fetch-args.ts +++ b/src/args/parse-helm-fetch-args.ts @@ -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, { diff --git a/src/args/parse-helm-template-args.ts b/src/args/parse-helm-template-args.ts index b311301..d906b23 100644 --- a/src/args/parse-helm-template-args.ts +++ b/src/args/parse-helm-template-args.ts @@ -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, { diff --git a/src/deno/render-chart.ts b/src/deno/render-chart.ts index cf1b918..f9b32b9 100644 --- a/src/deno/render-chart.ts +++ b/src/deno/render-chart.ts @@ -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" @@ -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}`) @@ -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) { @@ -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 } diff --git a/src/helm/execute.ts b/src/helm/execute.ts index 8f77834..620b145 100644 --- a/src/helm/execute.ts +++ b/src/helm/execute.ts @@ -1,3 +1,5 @@ +import { isSigterm } from "../utils/process.ts" + export async function helmExecute( args: readonly string[], { autoExitOnError = false }: { autoExitOnError?: boolean } = {} @@ -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") } diff --git a/src/helm/fetch.ts b/src/helm/fetch.ts index 0ea142e..7d7cd82 100644 --- a/src/helm/fetch.ts +++ b/src/helm/fetch.ts @@ -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" @@ -10,7 +12,7 @@ export async function fetchChart( chartPath: string, args: readonly string[] ): Promise { - const destinationExists = await fs.exists(tmpDirectory) + const destinationExists = await exists(tmpDirectory) if (!destinationExists) { return Promise.reject(`Could not find ${tmpDirectory}`) } @@ -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")) { @@ -47,7 +49,7 @@ export async function fetchChart( } await withErrorMsg( - fs.copy(directories[0], chartPath), + copy(directories[0], chartPath), `Could not fetch chart ${chartBlob}` ) } diff --git a/src/helm/get-chart-context.ts b/src/helm/get-chart-context.ts index 272abd3..7b697fd 100644 --- a/src/helm/get-chart-context.ts +++ b/src/helm/get-chart-context.ts @@ -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" @@ -42,12 +43,12 @@ export async function getChartContext( ): Promise { 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"), diff --git a/src/index.ts b/src/index.ts index 69712df..e9d3b88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { @@ -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() { diff --git a/src/utils/process.ts b/src/utils/process.ts index c51514d..d6bd0f0 100644 --- a/src/utils/process.ts +++ b/src/utils/process.ts @@ -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 } = {} @@ -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}` }