Skip to content

Commit

Permalink
Fixes for esbuild/jsr/npm
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Sep 29, 2024
1 parent b8ead4a commit 878b2cb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ test.js
deno.lock

# Built npm module
dist
dist
package.json
25 changes: 18 additions & 7 deletions build/clean.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import { resolve, fromFileUrl, dirname } from "@std/path";
import { rmdir } from "@cross/fs";
import { isDir } from "@cross/fs/stat";
import { rm, rmdir } from "@cross/fs";
import { isDir, isFile } from "@cross/fs/stat";

const relativeProjectRoot = "../";
const outputFolder = "dist";

const currentScriptDir = dirname(fromFileUrl(import.meta.url));

const resolvedPath = resolve(currentScriptDir, relativeProjectRoot, outputFolder);
const resolvedDistPath = resolve(currentScriptDir, relativeProjectRoot, outputFolder);
const resolvedNodeModulesPath = resolve(currentScriptDir, relativeProjectRoot, "node_modules");
const resolvedPackageJsonPath = resolve(currentScriptDir, relativeProjectRoot, "package.json");

if (await isDir(resolvedPath)) {
await rmdir(resolvedPath, {
recursive: true,
force: true
if (await isDir(resolvedDistPath)) {
await rmdir(resolvedDistPath, {
recursive: true
});
}

if (await isDir(resolvedNodeModulesPath)) {
await rmdir(resolvedNodeModulesPath, {
recursive: true
});
}

if (await isFile(resolvedPackageJsonPath)) {
await rm(resolvedPackageJsonPath);
}
2 changes: 1 addition & 1 deletion build/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function build() {
// ESM build
await esbuild.build({
entryPoints: [resolve(relativeProjectRoot, 'src/base64.ts')],
outfile: resolve(relativeProjectRoot, outputFolder, 'base64.esm.js'),
outfile: resolve(relativeProjectRoot, outputFolder, 'base64.js'),
bundle: true,
platform: 'neutral',
format: 'esm',
Expand Down
10 changes: 4 additions & 6 deletions build/npm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readJson, writeJson } from "https://deno.land/std/fs/mod.ts";

import { readFile, writeFile } from "@cross/fs";
import { resolve, fromFileUrl, dirname } from "@std/path";

const relativeProjectRoot = "../";
Expand All @@ -12,7 +11,7 @@ async function generatePackageJson() {

// Read deno.json
const denoConfigPath = resolve(resolvedPath, "deno.json");
const denoConfig = await readJson(denoConfigPath) as { name: string; version: string };
const denoConfig = JSON.parse(new TextDecoder().decode(await readFile(denoConfigPath))) as { name: string; version: string };

// Define package.json template
const packageJson = {
Expand Down Expand Up @@ -43,7 +42,6 @@ async function generatePackageJson() {
"base64",
"base64url",
"parser",
"base64",
"isomorphic",
"arraybuffer",
"string"
Expand All @@ -55,7 +53,7 @@ async function generatePackageJson() {
types: "./dist/base64.d.ts",
exports: {
".": {
import: "./src/base64.js",
import: "./dist/base64.js",
require: "./dist/base64.cjs.js",
browser: "./dist/base64.umd.js"
}
Expand All @@ -65,7 +63,7 @@ async function generatePackageJson() {

// Write package.json
const packageJsonPath = resolve(resolvedPath, "package.json");
await writeJson(packageJsonPath, packageJson, { spaces: 2 });
await writeFile(packageJsonPath, new TextEncoder().encode(JSON.stringify(packageJson,undefined, 2)));

console.log("package.json has been generated successfully.");
}
Expand Down
16 changes: 10 additions & 6 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"name": "@hexagon/base64",
"version": "2.0.0-dev.1",
"version": "2.0.0-dev.2",
"exports": "./src/base64.ts",
"lint": {
"include": ["src", "test"],
"exclude": ["dist"]
"exclude": ["dist", "build"]
},
"fmt": {
"include": ["src", "test"],
"exclude": ["dist"],
"exclude": ["dist", "build"],
"lineWidth": 100
},
"test": {
"exclude": ["dist"]
"exclude": ["dist", "build"]
},
"tasks": {
"clean": "deno run --allow-read --allow-write build/clean.ts",
"build": "deno test && deno task clean && deno run --allow-read --allow-write --allow-env --allow-run build/esbuild.ts",
"build:clean": "deno run --allow-read --allow-write build/clean.ts",
"build:npm": "deno run --allow-read --allow-write build/npm.ts",
"build": "deno test && deno task build:clean && deno run --allow-read --allow-write --allow-env --allow-run build/esbuild.ts && deno task build:npm",
"check-deps": "deno run -A jsr:@check/deps"
},
"imports": {
Expand All @@ -26,5 +27,8 @@
"@std/path": "jsr:@std/path@^1.0.6",
"esbuild": "npm:esbuild@^0.24.0",
"esbuild-plugin-d.ts": "npm:esbuild-plugin-d.ts@^1.3.0"
},
"publish": {
"exclude": ["build", "dist", "package.json", ".github"]
}
}

0 comments on commit 878b2cb

Please sign in to comment.