From 5b312237d719ae931a14c8a31647ef6373817e6b Mon Sep 17 00:00:00 2001 From: William Bergamin Date: Thu, 29 Aug 2024 15:11:03 +0000 Subject: [PATCH] chore: update esbuild dependencies for bundling (#94) * Update es build bundler deps * Update deps.ts * update dependency * Update deps.ts * Update dependencies * Remove deps.ts * Allow read access to system when building * Update src/mod.ts Co-authored-by: Fil Maj * Add allow-sys to start hook --------- Co-authored-by: Fil Maj --- deno.jsonc | 2 +- src/build.ts | 15 +++++++-------- src/bundler/esbuild_bundler.ts | 3 ++- src/check_update.ts | 6 ++++-- src/deps.ts | 10 ---------- src/doctor.ts | 4 +++- src/flags.ts | 4 ++-- src/get_manifest.ts | 5 ++++- src/get_trigger.ts | 7 +++++-- src/install_update.ts | 10 ++++++++-- src/mod.ts | 6 +++--- src/tests/get_manifest_test.ts | 2 +- src/utilities.ts | 7 ++++--- 13 files changed, 44 insertions(+), 37 deletions(-) delete mode 100644 src/deps.ts diff --git a/deno.jsonc b/deno.jsonc index 10967c7..b8ee617 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -33,7 +33,7 @@ "tasks": { "test": "deno fmt --check && deno lint && deno test --allow-read --allow-net --allow-write --allow-run --allow-env src", "generate-lcov": "rm -rf .coverage && deno test --reporter=dot --allow-read --allow-net --allow-write --allow-run --allow-env --coverage=.coverage src && deno coverage --exclude=fixtures --exclude=test --lcov --output=lcov.info .coverage", - "test:coverage":"deno task generate-lcov && deno coverage --exclude=fixtures --exclude=test .coverage" + "test:coverage": "deno task generate-lcov && deno coverage --exclude=fixtures --exclude=test .coverage" }, "lock": false } diff --git a/src/build.ts b/src/build.ts index cb7dcd1..2f60d33 100644 --- a/src/build.ts +++ b/src/build.ts @@ -1,10 +1,9 @@ -import { - ensureDir, - getProtocolInterface, - parseCLIArguments, - path, -} from "./deps.ts"; -import type { Protocol } from "./deps.ts"; +import * as path from "jsr:@std/path@^1.0.3"; +import { parseArgs } from "jsr:@std/cli@^1.0.4"; +import { ensureDir } from "jsr:@std/fs@^1.0.2"; +import { getProtocolInterface } from "https://deno.land/x/deno_slack_protocols@0.0.2/mod.ts"; +import type { Protocol } from "https://deno.land/x/deno_slack_protocols@0.0.2/types.ts"; + import { cleanManifest, getManifest } from "./get_manifest.ts"; import { validateManifestFunctions } from "./utilities.ts"; import { DenoBundler, EsbuildBundler } from "./bundler/mods.ts"; @@ -127,7 +126,7 @@ if (import.meta.main) { const protocol = getProtocolInterface(Deno.args); // Massage source and output directories - let { source, output } = parseCLIArguments(Deno.args); + let { source, output } = parseArgs(Deno.args); if (!output) output = "dist"; const outputDirectory = path.isAbsolute(output) ? output diff --git a/src/bundler/esbuild_bundler.ts b/src/bundler/esbuild_bundler.ts index c6205c1..3aceea7 100644 --- a/src/bundler/esbuild_bundler.ts +++ b/src/bundler/esbuild_bundler.ts @@ -1,4 +1,5 @@ -import { denoPlugins, esbuild } from "../deps.ts"; +import * as esbuild from "npm:esbuild@0.23.1"; +import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@0.10.3"; type EsbuildBundleOptions = { /** The path to the file being bundled */ diff --git a/src/check_update.ts b/src/check_update.ts index de37e03..a129524 100644 --- a/src/check_update.ts +++ b/src/check_update.ts @@ -1,9 +1,11 @@ +import type { JsonValue } from "jsr:@std/jsonc@^1.0.1"; +import { getProtocolInterface } from "https://deno.land/x/deno_slack_protocols@0.0.2/mod.ts"; + import { DENO_SLACK_API, DENO_SLACK_HOOKS, DENO_SLACK_SDK, } from "./libraries.ts"; -import { getProtocolInterface, JSONValue } from "./deps.ts"; import { getJSON, isNewSemverRelease } from "./utilities.ts"; const IMPORT_MAP_SDKS = [DENO_SLACK_SDK, DENO_SLACK_API]; @@ -197,7 +199,7 @@ export async function getDenoImportMapFiles( * value pairs that make use of the dependencies. */ export function extractDependencies( - json: JSONValue, + json: JsonValue, key: string, ): [string, string][] { // Determine if the JSON passed is an object diff --git a/src/deps.ts b/src/deps.ts deleted file mode 100644 index 36b79b1..0000000 --- a/src/deps.ts +++ /dev/null @@ -1,10 +0,0 @@ -export { parse as parseCLIArguments } from "https://deno.land/std@0.138.0/flags/mod.ts"; -export * as path from "https://deno.land/std@0.134.0/path/mod.ts"; -export { ensureDir } from "https://deno.land/std@0.134.0/fs/mod.ts"; -export { parse as parseJSONC } from "https://deno.land/std@0.149.0/encoding/jsonc.ts"; -export type { JSONValue } from "https://deno.land/std@0.149.0/encoding/jsonc.ts"; -export { deepMerge } from "https://deno.land/std@0.134.0/collections/deep_merge.ts"; -export { getProtocolInterface } from "https://deno.land/x/deno_slack_protocols@0.0.2/mod.ts"; -export type { Protocol } from "https://deno.land/x/deno_slack_protocols@0.0.2/types.ts"; -export * as esbuild from "https://deno.land/x/esbuild@v0.19.4/mod.js"; -export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.2/mod.ts"; diff --git a/src/doctor.ts b/src/doctor.ts index c194b58..b3f6a16 100644 --- a/src/doctor.ts +++ b/src/doctor.ts @@ -1,4 +1,6 @@ -import { getProtocolInterface, Protocol } from "./deps.ts"; +import { getProtocolInterface } from "https://deno.land/x/deno_slack_protocols@0.0.2/mod.ts"; +import type { Protocol } from "https://deno.land/x/deno_slack_protocols@0.0.2/types.ts"; + import { isNewSemverRelease } from "./utilities.ts"; type RuntimeVersion = { diff --git a/src/flags.ts b/src/flags.ts index 5b7db01..045112e 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -1,11 +1,11 @@ -import { parseCLIArguments } from "./deps.ts"; +import { parseArgs } from "jsr:@std/cli@^1.0.4"; const UNSAFELY_IGNORE_CERT_ERRORS_FLAG = "sdk-unsafely-ignore-certificate-errors"; const SLACK_DEV_DOMAIN_FLAG = "sdk-slack-dev-domain"; export const getStartHookAdditionalDenoFlags = (args: string[]): string => { - const parsedArgs = parseCLIArguments(args); + const parsedArgs = parseArgs(args); const extraFlagValue = parsedArgs[SLACK_DEV_DOMAIN_FLAG] ?? parsedArgs[UNSAFELY_IGNORE_CERT_ERRORS_FLAG] ?? ""; diff --git a/src/get_manifest.ts b/src/get_manifest.ts index b7ed721..5743159 100644 --- a/src/get_manifest.ts +++ b/src/get_manifest.ts @@ -1,4 +1,7 @@ -import { deepMerge, getProtocolInterface, path } from "./deps.ts"; +import { getProtocolInterface } from "https://deno.land/x/deno_slack_protocols@0.0.2/mod.ts"; +import * as path from "jsr:@std/path@^1.0.3"; +import { deepMerge } from "jsr:@std/collections@^1.0.5"; + import { getDefaultExport, validateManifestFunctions } from "./utilities.ts"; // Responsible for taking a working directory, and an output directory diff --git a/src/get_trigger.ts b/src/get_trigger.ts index 7d69b00..73e937b 100644 --- a/src/get_trigger.ts +++ b/src/get_trigger.ts @@ -1,8 +1,11 @@ -import { getProtocolInterface, parseCLIArguments, path } from "./deps.ts"; +import { getProtocolInterface } from "https://deno.land/x/deno_slack_protocols@0.0.2/mod.ts"; +import * as path from "jsr:@std/path@^1.0.3"; +import { parseArgs } from "jsr:@std/cli@^1.0.4"; + import { getDefaultExport } from "./utilities.ts"; export const getTrigger = async (args: string[]) => { - const source = parseCLIArguments(args).source as string; + const source = parseArgs(args).source as string; if (!source) throw new Error("A source path needs to be defined"); diff --git a/src/install_update.ts b/src/install_update.ts index 0864799..6f5d74e 100644 --- a/src/install_update.ts +++ b/src/install_update.ts @@ -1,3 +1,6 @@ +import { getProtocolInterface } from "https://deno.land/x/deno_slack_protocols@0.0.2/mod.ts"; +import type { JsonValue } from "jsr:@std/jsonc@^1.0.1"; + import { checkForSDKUpdates, gatherDependencyFiles, @@ -5,7 +8,6 @@ import { } from "./check_update.ts"; import { getJSON } from "./utilities.ts"; import { projectScripts } from "./mod.ts"; -import { getProtocolInterface, JSONValue } from "./deps.ts"; export const SDK_NAME = "the Slack SDK"; @@ -114,6 +116,10 @@ export async function updateDependencyFile( const dependencyKey = dependencyJSON.imports ? "imports" : "hooks"; + if (dependencyJSON[dependencyKey] === undefined) { + return []; + } + // Update only the dependency-related key in given file ("imports" or "hooks") const { updatedDependencies, updateSummary } = updateDependencyMap( dependencyJSON[dependencyKey], @@ -142,7 +148,7 @@ export async function updateDependencyFile( * an updated map of all dependencies, as well as an update summary of each. */ export function updateDependencyMap( - dependencyMap: JSONValue, + dependencyMap: JsonValue, releases: Release[], ) { const mapIsObject = dependencyMap && typeof dependencyMap === "object" && diff --git a/src/mod.ts b/src/mod.ts index 8de06bb..09c033f 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -7,13 +7,13 @@ export const projectScripts = (args: string[]) => { "runtime": "deno", "hooks": { "get-manifest": - `deno run -q --config=deno.jsonc --allow-read --allow-net --allow-env https://deno.land/x/${HOOKS_TAG}/get_manifest.ts`, + `deno run -q --config=deno.jsonc --allow-read --allow-net --allow-env --allow-sys=osRelease https://deno.land/x/${HOOKS_TAG}/get_manifest.ts`, "get-trigger": `deno run -q --config=deno.jsonc --allow-read --allow-net --allow-env https://deno.land/x/${HOOKS_TAG}/get_trigger.ts`, "build": - `deno run -q --config=deno.jsonc --allow-read --allow-write --allow-net --allow-run --allow-env https://deno.land/x/${HOOKS_TAG}/build.ts`, + `deno run -q --config=deno.jsonc --allow-read --allow-write --allow-net --allow-run --allow-env --allow-sys=osRelease https://deno.land/x/${HOOKS_TAG}/build.ts`, "start": - `deno run -q --config=deno.jsonc --allow-read --allow-net --allow-run --allow-env https://deno.land/x/${RUNTIME_TAG}/local-run.ts ${startHookFlags}`, + `deno run -q --config=deno.jsonc --allow-read --allow-net --allow-run --allow-env --allow-sys=osRelease https://deno.land/x/${RUNTIME_TAG}/local-run.ts ${startHookFlags}`, "check-update": `deno run -q --config=deno.jsonc --allow-read --allow-net https://deno.land/x/${HOOKS_TAG}/check_update.ts`, "install-update": diff --git a/src/tests/get_manifest_test.ts b/src/tests/get_manifest_test.ts index a7196e3..a014f2d 100644 --- a/src/tests/get_manifest_test.ts +++ b/src/tests/get_manifest_test.ts @@ -8,7 +8,7 @@ import { assertRejects, assertStringIncludes, } from "../dev_deps.ts"; -import { path } from "../deps.ts"; +import * as path from "jsr:@std/path@^1.0.3"; Deno.test("get-manifest hook tests", async (t) => { await t.step( diff --git a/src/utilities.ts b/src/utilities.ts index 1c87f30..dfe44c0 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -1,12 +1,13 @@ -import { parseJSONC, path } from "./deps.ts"; -import type { JSONValue } from "./deps.ts"; +import * as path from "jsr:@std/path@^1.0.3"; +import { parse as parseJSONC } from "jsr:@std/jsonc@^1.0.1"; +import type { JsonValue } from "jsr:@std/jsonc@^1.0.1"; /** * getJSON attempts to read the given file. If successful, * it returns the contents of the file. If the extraction * fails, it returns an empty object. */ -export async function getJSON(file: string): Promise { +export async function getJSON(file: string): Promise { try { const fileContents = await Deno.readTextFile(file); return parseJSONC(fileContents);