Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
chore: restructure dist layout to work with existing tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshydra committed Apr 10, 2024
1 parent ed05d82 commit 02ded6a
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: lint
run: npm run lint
- name: compile typescript
run: npx tsc
run: npm run build && npx tsc
- name: test
run: npm run test
- name: generate coverage
Expand Down
2 changes: 1 addition & 1 deletion examples/bill.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

const zero = new Decimal128("0");
const one = new Decimal128("1");
Expand Down
2 changes: 1 addition & 1 deletion examples/floor.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

function floor(d: Decimal128): Decimal128 {
return d.round(0, "floor");
Expand Down
2 changes: 1 addition & 1 deletion examples/mortgage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";
import { pow } from "./pow.mjs";

const one = new Decimal128("1");
Expand Down
2 changes: 1 addition & 1 deletion examples/normalize.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

function normalize(d: Decimal128): string {
// Decimal128 object
Expand Down
2 changes: 1 addition & 1 deletion examples/pow.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

function pow(a: Decimal128, b: number): Decimal128 {
let result = a;
Expand Down
2 changes: 1 addition & 1 deletion examples/round.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Examples from the Intl.NumberFormat spec

import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

let minusOnePointFive = new Decimal128("-1.5");
let zeroPointFour = new Decimal128("0.4");
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "decimal128",
"version": "11.2.0",
"main": "dist/decimal128.cjs",
"module": "dist/decimal128.mjs",
"typings": "dist/decimal128.d.ts",
"main": "dist/cjs/decimal128.cjs",
"module": "dist/esm/decimal128.mjs",
"typings": "dist/esm/decimal128.d.ts",
"exports": {
".": {
"import": "./dist/decimal128.mjs",
"require": "./dist/decimal128.cjs",
"types": "./dist/decimal128.d.ts"
"import": "./dist/esm/decimal128.mjs",
"require": "./dist/cjs/decimal128.cjs",
"types": "./dist/esm/decimal128.d.ts"
}
},
"type": "module",
Expand Down
53 changes: 26 additions & 27 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@
import typescript from "@rollup/plugin-typescript";

/**
* @type { import("rollup").OutputOptions }
* @param {'esm' | 'cjs'} format
* @returns { import("rollup").RollupOptions }
*/
const commonOutput = {
sourcemap: true,
interop: "esModule",
const createConfig = (format) => {
const extension = format === "esm" ? "mjs" : "cjs";
return {
input: "src/decimal128.mts",
output: [
{
sourcemap: true,
interop: "esModule",
preserveModules: true,
dir: `./dist/${format}`,
format: format,
entryFileNames: `[name].${extension}`,
},
],
plugins: [
typescript({
tsconfig: "tsconfig.build.json",
outDir: `dist/${format}`,
sourceMap: false,
}),
],
};
};

/**
* @type { import("rollup").RollupOptions }
* @type { import("rollup").RollupOptions[] }
*/
const config = {
input: "src/decimal128.mts",
output: [
{
...commonOutput,
file: "./dist/decimal128.mjs",
format: "esm",
},
{
...commonOutput,
file: "./dist/decimal128.cjs",
format: "cjs",
},
],
plugins: [
typescript({
tsconfig: "tsconfig.build.json",
outDir: "dist",
sourceMap: false,
}),
],
};
const config = [createConfig("esm"), createConfig("cjs")];

export default config;
2 changes: 1 addition & 1 deletion tests/abs.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

const MAX_SIGNIFICANT_DIGITS = 34;
const bigDigits = "9".repeat(MAX_SIGNIFICANT_DIGITS);
Expand Down
2 changes: 1 addition & 1 deletion tests/add.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

const MAX_SIGNIFICANT_DIGITS = 34;
const bigDigits = "9".repeat(MAX_SIGNIFICANT_DIGITS);
Expand Down
2 changes: 1 addition & 1 deletion tests/common.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { countSignificantDigits } from "../src/common.mjs";
import { countSignificantDigits } from "../dist/esm/common.mjs";

describe("significant digits", () => {
test("basic example", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/constructor.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

const MAX_SIGNIFICANT_DIGITS = 34;

Expand Down
2 changes: 1 addition & 1 deletion tests/divide.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

describe("division", () => {
test("simple example", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/equals.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

const MAX_SIGNIFICANT_DIGITS = 34;
const nan = new Decimal128("NaN");
Expand Down
2 changes: 1 addition & 1 deletion tests/lessthan.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

const MAX_SIGNIFICANT_DIGITS = 34;
const nan = new Decimal128("NaN");
Expand Down
2 changes: 1 addition & 1 deletion tests/multiply.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

const examples = [
["123.456", "789.789", "97504.190784"],
Expand Down
2 changes: 1 addition & 1 deletion tests/rational.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Rational } from "../src/rational.mjs";
import { Rational } from "../dist/esm/rational.mjs";
describe("constructor", () => {
test("cannot divide by zero", () => {
expect(() => new Rational(1n, 0n)).toThrow(RangeError);
Expand Down
2 changes: 1 addition & 1 deletion tests/remainder.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

const a = "4.1";
const b = "1.25";
Expand Down
2 changes: 1 addition & 1 deletion tests/round.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";
import * as string_decoder from "string_decoder";
import { expectDecimal128 } from "./util.js";

Expand Down
2 changes: 1 addition & 1 deletion tests/subtract.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";
import { expectDecimal128 } from "./util.js";

const MAX_SIGNIFICANT_DIGITS = 34;
Expand Down
2 changes: 1 addition & 1 deletion tests/tostring.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";
import { expectDecimal128 } from "./util.js";

describe("NaN", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

export function expectDecimal128(a, b) {
let lhs = a instanceof Decimal128 ? a.toString({ normalize: false }) : a;
Expand Down
2 changes: 1 addition & 1 deletion tests/valueof.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Decimal128 } from "../src/decimal128.mjs";
import { Decimal128 } from "../dist/esm/decimal128.mjs";

describe("valueOf", () => {
test("throws unconditionally", () => {
Expand Down

0 comments on commit 02ded6a

Please sign in to comment.