Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update esbuild dependencies for bundling #94

Merged
merged 10 commits into from
Aug 29, 2024
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 @@ -88,7 +87,7 @@
throw denoBundleErr;
}

// TODO: once Protocol can handle debug add a debug statement here

Check warning on line 90 in src/build.ts

View workflow job for this annotation

GitHub Actions / Health Score

src/build.ts#L90

Problematic comment ("TODO") identified

try {
const bundle = await EsbuildBundler.bundle({
Expand Down Expand Up @@ -127,7 +126,7 @@
const protocol = getProtocolInterface(Deno.args);

// Massage source and output directories
let { source, output } = parseCLIArguments(Deno.args);
let { source, output } = parseArgs(Deno.args);

Check warning on line 129 in src/build.ts

View check run for this annotation

Codecov / codecov/patch

src/build.ts#L129

Added line #L129 was not covered by tests
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 All @@ -16,7 +17,7 @@
const result = await esbuild.build({
entryPoints: [options.entrypoint],
platform: "browser",
// TODO: the versions should come from the user defined input

Check warning on line 20 in src/bundler/esbuild_bundler.ts

View workflow job for this annotation

GitHub Actions / Health Score

src/bundler/esbuild_bundler.ts#L20

Problematic comment ("TODO") identified
target: "deno1",
format: "esm", // esm format stands for "ECMAScript module"
bundle: true, // inline any imported dependencies into the file itself
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 @@ -42,7 +44,7 @@
// project as a means to cache the changes
if (!updateResp.error) {
try {
// TODO: This try/catch should be nested within createUpdateResp

Check warning on line 47 in src/install_update.ts

View workflow job for this annotation

GitHub Actions / Health Score

src/install_update.ts#L47

Problematic comment ("TODO") identified
// but doing so surfaces an issue with the --allow-run flag not
// being used, despite its presence and success at this level
runBuildHook();
Expand Down Expand Up @@ -114,6 +116,10 @@

const dependencyKey = dependencyJSON.imports ? "imports" : "hooks";

if (dependencyJSON[dependencyKey] === undefined) {
return [];

Check warning on line 120 in src/install_update.ts

View check run for this annotation

Codecov / codecov/patch

src/install_update.ts#L120

Added line #L120 was not covered by tests
}

// 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 @@
* 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 @@
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 Expand Up @@ -62,7 +62,7 @@
);

await t.step("getManifest function", async (tt) => {
// TODO: one of two things need to happen in order to test getManifest out more:

Check warning on line 65 in src/tests/get_manifest_test.ts

View workflow job for this annotation

GitHub Actions / Health Score

src/tests/get_manifest_test.ts#L65

Problematic comment ("TODO") identified
// 1. need the ability to mock out `Deno.stat` using mock-file (see https://github.com/ayame113/mock-file/issues/7), or
// 2. we re-write the code in get_manifest.ts to use `Deno.fstat` in place of `Deno.stat`
// In the mean time, we can use actual files on the actual filesystem, as un-unit-testy as that is,
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