Skip to content

Commit

Permalink
chore: update esbuild dependencies for bundling (#94)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Add allow-sys to start hook

---------

Co-authored-by: Fil Maj <[email protected]>
  • Loading branch information
WilliamBergamin and filmaj authored Aug 29, 2024
1 parent 29c0527 commit 5b31223
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 7 additions & 8 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -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/[email protected]/mod.ts";
import type { Protocol } from "https://deno.land/x/[email protected]/types.ts";

import { cleanManifest, getManifest } from "./get_manifest.ts";
import { validateManifestFunctions } from "./utilities.ts";
import { DenoBundler, EsbuildBundler } from "./bundler/mods.ts";
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/bundler/esbuild_bundler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { denoPlugins, esbuild } from "../deps.ts";
import * as esbuild from "npm:[email protected]";
import { denoPlugins } from "jsr:@luca/[email protected]";

type EsbuildBundleOptions = {
/** The path to the file being bundled */
Expand Down
6 changes: 4 additions & 2 deletions src/check_update.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { JsonValue } from "jsr:@std/jsonc@^1.0.1";
import { getProtocolInterface } from "https://deno.land/x/[email protected]/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];
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/deps.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/doctor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getProtocolInterface, Protocol } from "./deps.ts";
import { getProtocolInterface } from "https://deno.land/x/[email protected]/mod.ts";
import type { Protocol } from "https://deno.land/x/[email protected]/types.ts";

import { isNewSemverRelease } from "./utilities.ts";

type RuntimeVersion = {
Expand Down
4 changes: 2 additions & 2 deletions src/flags.ts
Original file line number Diff line number Diff line change
@@ -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] ?? "";

Expand Down
5 changes: 4 additions & 1 deletion src/get_manifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { deepMerge, getProtocolInterface, path } from "./deps.ts";
import { getProtocolInterface } from "https://deno.land/x/[email protected]/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
Expand Down
7 changes: 5 additions & 2 deletions src/get_trigger.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { getProtocolInterface, parseCLIArguments, path } from "./deps.ts";
import { getProtocolInterface } from "https://deno.land/x/[email protected]/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");

Expand Down
10 changes: 8 additions & 2 deletions src/install_update.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { getProtocolInterface } from "https://deno.land/x/[email protected]/mod.ts";
import type { JsonValue } from "jsr:@std/jsonc@^1.0.1";

import {
checkForSDKUpdates,
gatherDependencyFiles,
Release,
} 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";

Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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" &&
Expand Down
6 changes: 3 additions & 3 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion src/tests/get_manifest_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions src/utilities.ts
Original file line number Diff line number Diff line change
@@ -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<JSONValue> {
export async function getJSON(file: string): Promise<JsonValue> {
try {
const fileContents = await Deno.readTextFile(file);
return parseJSONC(fileContents);
Expand Down

0 comments on commit 5b31223

Please sign in to comment.