Skip to content

Commit

Permalink
feat: Publish to npm (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassjogreen authored Sep 24, 2024
1 parent 5055896 commit bf8b521
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
- run: deno run -A scripts/npm.ts
- run: deno publish
- run: npm publish --provenance
working-directory: ./npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
npm/
examples/
typefetch.d.ts
tests/*/schemas/*.ts
tests/*/schemas/*.ts
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@denosaurs/typefetch",
"version": "0.0.22",
"version": "0.0.23",
"exports": {
".": "./main.ts"
},
Expand All @@ -13,7 +13,7 @@
"openapi-types": "npm:[email protected]",
"ts-morph": "npm:[email protected]"
},
"exclude": ["tests/*/schemas/*.ts"],
"exclude": ["tests/*/schemas/*.ts", "npm/*"],
"test": {
"include": ["tests/test.ts"]
},
Expand Down
4 changes: 2 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseArgs } from "@std/cli";
import * as yaml from "@std/yaml";
import { parseArgs } from "@std/cli/parse-args";
import * as yaml from "@std/yaml/parse";
import { wait } from "@denosaurs/wait";

import { ModuleDeclarationKind, Project } from "ts-morph";
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
ModuleDeclaration,
SourceFile,
} from "ts-morph";
import { STATUS_CODE } from "@std/http";
import { STATUS_CODE } from "@std/http/status";

import type { OpenAPI } from "./types/openapi.ts";

Expand Down
30 changes: 30 additions & 0 deletions node/shims.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// deno-lint-ignore-file no-explicit-any
import process from "node:process";

export function addEventListener(
type: "unload",
listener: () => any,
options?: never,
): void {
if (type !== "unload") {
console.warn(
"The `addEventListener` shim does not support any event type other than `unload`",
);
return;
}
if (listener.length >= 1) {
console.warn(
"The `addEventListener` shim does not support any arguments passed to the listener",
);
return;
}
if (options !== undefined) {
console.warn("The `addEventListener` shim does not support options");
return;
}

process.on("exit", listener);
process.on("beforeExit", listener);
process.on("SIGINT", listener);
process.on("uncaughtException", listener);
}
60 changes: 60 additions & 0 deletions scripts/npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import manifest from "../deno.json" with { type: "json" };

import { build, emptyDir } from "jsr:@deno/dnt";

await emptyDir("./npm");

await build({
entryPoints: ["./main.ts"],
scriptModule: false,
outDir: "./npm",
shims: {
deno: true,
timers: true,
custom: [{
globalNames: ["addEventListener"],
module: "./node/shims.ts",
}],
},
test: false,
importMap: "./deno.json",
package: {
name: manifest.name,
version: manifest.version,
description:
"📤 Magically generate `fetch` types from OpenAPI schemas for zero-cost browser-native api clients",
keywords: [
"fetch",
"openapi",
"swagger",
"api",
"rest",
"typescript",
"types",
"ts",
"dts",
"node",
"deno",
"browser",
],
license: "MIT",
repository: {
type: "git",
url: "git+https://github.com/denosaurs/typefetch.git",
},
bugs: {
url: "https://github.com/denosaurs/typefetch/issues",
},
},
postBuild() {
Deno.copyFileSync("LICENSE", "npm/LICENSE");
Deno.copyFileSync("README.md", "npm/README.md");

// Add shebang to main.js
const main = Deno.readTextFileSync("npm/esm/main.js");
Deno.writeTextFileSync(
"npm/esm/main.js",
`#!/usr/bin/env node --no-warnings=ExperimentalWarning\n${main}`,
);
},
});
2 changes: 1 addition & 1 deletion utils/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function resolveRef<T = unknown>(object: unknown, ref: string): T {
* Resolves a path to an absolute path with support for file URLs.
*/
export function resolve(path: string | URL): string {
if (URL.canParse(path)) {
if (URL.canParse(path.toString())) {
try {
path = fromFileUrl(path);
// deno-lint-ignore no-empty
Expand Down

0 comments on commit bf8b521

Please sign in to comment.