fun icon indicating copy to clipboard operation
fun copied to clipboard

Building for NPM

Open pixeleet opened this issue 2 years ago • 2 comments

As a developer I would like to be able to use functional both in a Deno and Node context. To achieve this I have did a bit of research and found that the deno team has released dnt which makes it rather straightforward to enable publishing npm packages from deno as a source.

This could be discussed in the context of release management.

We have briefly touched on it previously and as long as the repository has the right NPM credentials set up (for the nullpub org) it should be pretty self-evident to publish the package to NPM too.

pixeleet avatar Mar 19 '22 14:03 pixeleet

import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
import { parse } from "https://deno.land/x/[email protected]/mod.ts";

const version = Deno.args[0];

if (!version) {
  throw new Error("A version must be provided as 1st argument.");
}

const semVer = parse(version);
if (!semVer) {
  throw new Error("Couldn't parse version number.");
}

const outDir = "./out/node";

await emptyDir(outDir);
await build({
  entryPoints: ["./mod.ts"],
  outDir,
  typeCheck: false,
  test: true,
  shims: {
    // see JS docs for overview and more options
    deno: true,
  },
  package: {
    // package.json properties
    name: "fun",
    version: semVer.toString(),
    description: "FP",
    license: "MIT",
    repository: {
      type: "git",
      url: "git+https://github.com/nullpub/fun.git",
    },
    bugs: {
      url: "https://github.com/nullpub/fun/issues",
    },
  },
});

// post build steps
Deno.copyFileSync("LICENSE", `${outDir}/LICENSE`);
Deno.copyFileSync("README.md", `${outDir}/README.md`);

pixeleet avatar Mar 19 '22 15:03 pixeleet

This will be done alongside #4 and wrapped in a nix flake.

baetheus avatar Mar 19 '22 15:03 baetheus