Skip to content

Commit

Permalink
fix: fast-json-patch commonjs import is wrong (#175)
Browse files Browse the repository at this point in the history
<!-- GITHUB_RELEASE PR BODY: canary-version -->
<details>
  <summary>📦 Published PR as canary version: <code>Canary Versions</code></summary>
  <br />

  ✨ Test out this PR locally via:
  
  ```bash
  npm install @dotinc/[email protected]
  npm install @dotinc/[email protected]
  # or 
  yarn add @dotinc/[email protected]
  yarn add @dotinc/[email protected]
  ```
</details>
<!-- GITHUB_RELEASE PR BODY: canary-version -->
  • Loading branch information
nadilas authored Apr 27, 2024
2 parents 350df5d + c319746 commit fde819a
Show file tree
Hide file tree
Showing 20 changed files with 550 additions and 89 deletions.
518 changes: 478 additions & 40 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"lint": "turbo run lint",
"test": "turbo run test",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"release": "auto shipit"
"release": "auto shipit",
"postinstall": "patch-package"
},
"license": "MIT",
"devDependencies": {
Expand All @@ -27,7 +28,8 @@
"auto": "^11.0.7",
"dotenv-cli": "^7.3.0",
"prettier": "^3.2.5",
"turbo": "latest"
"turbo": "latest",
"patch-package": "^8.0.0"
},
"engines": {
"npm": ">=7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ogre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"private": false,
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"test": "nyc --reporter=lcov tap --coverage-report=none --allow-incomplete-coverage",
Expand All @@ -22,7 +23,6 @@
"dependencies": {
"fast-json-patch": "^3.1.1",
"fflate": "^0.8.2",
"immutable-json-patch": "^6.0.1",
"tslib": "^2.6.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ogre/src/branch.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "tap";
import { getBaseline, sumChanges, testAuthor } from "./test.utils";
import { getBaseline, sumChanges, testAuthor } from "./test.utils.js";

test("current branch on empty repo is HEAD", async (t) => {
const [repo] = await getBaseline();
Expand Down
4 changes: 2 additions & 2 deletions packages/ogre/src/checkout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
sumChanges,
testAuthor,
updateHeaderData,
} from "./test.utils";
import { Repository } from "./repository";
} from "./test.utils.js";
import { Repository } from "./repository.js";

test("checkout prev commit", async (t) => {
const [repo, obj] = await getBaseline();
Expand Down
5 changes: 2 additions & 3 deletions packages/ogre/src/commit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
sumChanges,
testAuthor,
updateHeaderData,
} from "./test.utils";
import { Repository } from "./repository";
import { printChangeLog } from "./utils";
} from "./test.utils.js";
import { Repository } from "./repository.js";

test("baseline with 1 commit and zero changelog entries", async (t) => {
const [repo] = await getBaseline();
Expand Down
14 changes: 7 additions & 7 deletions packages/ogre/src/commit.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { digest } from "./hash";
import { digest } from "./hash.js";
import { Operation } from "fast-json-patch";

export interface Commit {
/*The hash of the commit. Is a sha256 of:
- tree object reference (changes?)
- parent object reference (parent hash)
- author
- author commit timestamp with timezone
- commit message
*/
- tree object reference (changes?)
- parent object reference (parent hash)
- author
- author commit timestamp with timezone
- commit message
*/
hash: string;
tree: string;

Expand Down
6 changes: 3 additions & 3 deletions packages/ogre/src/git2json.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Commit } from "./commit";
import { History, Reference } from "./interfaces";
import { Commit } from "./commit.js";
import { History, Reference } from "./interfaces.js";
import {
cleanAuthor,
createHeadRefValue,
isTagRef,
REFS_HEAD_KEY,
} from "./utils";
} from "./utils.js";

const findRefs = (commit: Commit, refs: Map<string, Reference>) => {
const list = [];
Expand Down
6 changes: 3 additions & 3 deletions packages/ogre/src/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
export function digest(
obj: any,
algorithm = "SHA-256",
isBrowser = false
isBrowser = false,
): Promise<string> {
// eslint-disable-line
const algorithms = ["SHA-1", "SHA-256", "SHA-384", "SHA-512"];
if (!algorithms.includes(algorithm)) {
throw RangeError(
`Valid hash algorithm values are any of ${JSON.stringify(algorithms)}`
`Valid hash algorithm values are any of ${JSON.stringify(algorithms)}`,
);
}
return (async function (obj, algorithm) {
Expand All @@ -46,7 +46,7 @@ export function digest(
});
} else {
const nodeAlg = algorithm.toLowerCase().replace("-", "");
digest = require("crypto")
digest = (await import("crypto"))
.createHash(nodeAlg)
.update(Buffer.from(hashInput))
.digest("hex"); // eslint-disable-line
Expand Down
14 changes: 7 additions & 7 deletions packages/ogre/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export * from "./interfaces";
export * from "./repository";
export { Commit } from "./commit";
export * from "./ref";
export * from "./size";
export * from "./utils";
export * from "./git2json";
export * from "./interfaces.js";
export * from "./repository.js";
export { Commit } from "./commit.js";
export * from "./ref.js";
export * from "./size.js";
export * from "./utils.js";
export * from "./git2json.js";

export { compare, deepClone, Operation, JsonPatchError } from "fast-json-patch";
2 changes: 1 addition & 1 deletion packages/ogre/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Commit } from "./commit";
import { Commit } from "./commit.js";

export interface Reference {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/ogre/src/merge.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "tap";
import { getBaseline, testAuthor } from "./test.utils";
import { getBaseline, testAuthor } from "./test.utils.js";

test("merge with no commit fails", async (t) => {
const [repo] = await getBaseline();
Expand Down
6 changes: 3 additions & 3 deletions packages/ogre/src/repository.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "tap";

import { Repository } from "./repository";
import { Repository } from "./repository.js";
import {
addOneStep,
addOneStep as addOneNested,
Expand All @@ -9,8 +9,8 @@ import {
sumChanges,
testAuthor,
updateHeaderData,
} from "./test.utils";
import { Reference } from "./interfaces";
} from "./test.utils.js";
import { Reference } from "./interfaces.js";
import { compare } from "fast-json-patch";

test("diff is ok", async (t) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/ogre/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
unobserve,
validate,
} from "fast-json-patch";
import { calculateCommitHash, Commit } from "./commit";
import { History, Reference } from "./interfaces";
import { calculateCommitHash, Commit } from "./commit.js";
import { History, Reference } from "./interfaces.js";
import { compressSync, strToU8 } from "fflate";
import {
brancheNameToRef,
Expand All @@ -34,7 +34,7 @@ import {
treeToObject,
validateBranchName,
validateRef,
} from "./utils";
} from "./utils.js";

export interface RepositoryOptions<T extends { [k: string]: any }> {
history?: History;
Expand Down
2 changes: 1 addition & 1 deletion packages/ogre/src/tag.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "tap";
import { getBaseline, testAuthor } from "./test.utils";
import { getBaseline, testAuthor } from "./test.utils.js";

test("cannot tag on an empty repo", async (t) => {
const [repo] = await getBaseline();
Expand Down
4 changes: 2 additions & 2 deletions packages/ogre/src/test.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { v4 as uuid4 } from "uuid";
import { Repository, RepositoryObject } from "./repository";
import { Commit } from "./commit";
import { Repository, RepositoryObject } from "./repository.js";
import { Commit } from "./commit.js";

export type NestedObject = {
name?: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/ogre/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from "tap";
import { cleanAuthor, mapPath, shaishToCommit } from "./utils";
import { Repository } from "./repository";
import { ComplexObject, testAuthor } from "./test.utils";
import { cleanAuthor, mapPath, shaishToCommit } from "./utils.js";
import { Repository } from "./repository.js";
import { ComplexObject, testAuthor } from "./test.utils.js";

test("author <[email protected]>", (t) => {
const [name, email] = cleanAuthor("author <[email protected]>");
Expand Down
8 changes: 4 additions & 4 deletions packages/ogre/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// [RFC5322](https://www.ietf.org/rfc/rfc5322.txt)
import { Commit } from "./commit";
import { Reference } from "./interfaces";
import { Commit } from "./commit.js";
import { Reference } from "./interfaces.js";
import { decompressSync, strFromU8 } from "fflate";
import { validBranch, validRef } from "./ref";
import { validBranch, validRef } from "./ref.js";
import { deepClone, Operation } from "fast-json-patch";
import { RepositoryObject } from "./repository";
import { RepositoryObject } from "./repository.js";

const emailRegex =
/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;
Expand Down
8 changes: 6 additions & 2 deletions packages/ogre/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"moduleResolution": "nodenext",
"declaration": true,
"importHelpers": true,
"module": "commonjs",
"module": "NodeNext",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
Expand All @@ -12,5 +13,8 @@
"include": [
"./src/**/*.ts"
],
"exclude": ["lib", "node_modules"]
"exclude": [
"lib",
"node_modules"
]
}
18 changes: 18 additions & 0 deletions patches/fast-json-patch+3.1.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/node_modules/fast-json-patch/package.json b/node_modules/fast-json-patch/package.json
index 688a6d0..8eb9957 100644
--- a/node_modules/fast-json-patch/package.json
+++ b/node_modules/fast-json-patch/package.json
@@ -25,6 +25,13 @@
"main": "index.js",
"module": "index.mjs",
"typings": "index.d.ts",
+ "exports": {
+ ".": {
+ "import": "./index.mjs",
+ "require": "./index.js",
+ "types": "./index.d.ts"
+ }
+ },
"devDependencies": {
"benchmark": "^2.1.4",
"bluebird": "^3.5.5",

0 comments on commit fde819a

Please sign in to comment.