Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Codex-/cosmiconfig-typescript-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.3.0
Choose a base ref
...
head repository: Codex-/cosmiconfig-typescript-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4.4.0
Choose a head ref
Loading
Showing with 15,511 additions and 7,768 deletions.
  1. +1 −1 .eslintrc.json
  2. +7 −2 .github/renovate.json
  3. +1 −2 .github/workflows/build.yml
  4. +18 −0 CHANGELOG.md
  5. +16 −0 jest.config.ts
  6. +3 −2 lib/index.spec.ts
  7. +6 −36 lib/loader.spec.ts
  8. +1 −0 lib/loader.ts
  9. +0 −1 lib/typescript-compile-error.spec.ts
  10. +15,439 −7,695 package-lock.json
  11. +19 −17 package.json
  12. +0 −12 vite.config.ts
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"ignorePatterns": [
"lib/__fixtures__/**/*.ts",
"esbuild.config.mjs",
"vite.config.ts",
"jest.config.ts",
"coverage",
"dist",
"smoke-tests"
9 changes: 7 additions & 2 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base", ":preserveSemverRanges"],
"extends": ["config:base", "group:allNonMajor", "schedule:monthly"],
"timezone": "Pacific/Auckland",
"labels": ["dependencies"],
"rangeStrategy": "bump",
"lockFileMaintenance": {
"enabled": true,
"automerge": true,
"schedule": ["on the first day of the month"]
"schedule": ["every 3 months on the first day of the month"]
},
"packageRules": [
{
"matchDepTypes": ["devDependencies"],
"automerge": true
},
{
"depTypeList": ["peerDependencies"],
"enabled": false
},
{
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
"automerge": true
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: build
on:
pull_request:
push:

jobs:
@@ -61,6 +60,6 @@ jobs:
cache: npm
- run: npm ci
- name: test
run: npm run test -- --coverage
run: npm run test:coverage
- name: codecov
uses: codecov/codecov-action@v3
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,8 +4,26 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [4.4.0](https://github.com/Codex-/cosmiconfig-typescript-loader/compare/4.3.0...4.4.0)

- chore(deps): update all non-major dependencies [`#107`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/107)
- build(deps-dev): bump word-wrap from 1.2.3 to 1.2.4 [`#104`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/104)
- build(deps): bump vm2 from 3.9.17 to 3.9.18 [`#94`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/94)
- build(deps): bump vm2 from 3.9.16 to 3.9.17 [`#92`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/92)
- build(deps): bump vm2 from 3.9.15 to 3.9.16 [`#91`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/91)
- build(deps): bump vm2 from 3.9.14 to 3.9.15 [`#90`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/90)
- Revert to jest [`#83`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/83)
- build(deps): bump cacheable-request from 10.2.5 to 10.2.7 [`#81`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/81)
- chore(deps): lock file maintenance [`#72`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/72)
- chore(deps): update vitest monorepo to ^0.28.0 [`#71`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/71)
- test: rever to jest to test cjs/require things [`26e9bf4`](https://github.com/Codex-/cosmiconfig-typescript-loader/commit/26e9bf421029c1ccbfa13cc482f98bf72651998f)
- chore(deps): update dependency esbuild to ^0.17.0 [`7a951f4`](https://github.com/Codex-/cosmiconfig-typescript-loader/commit/7a951f4b9325024d53cf51c8f4e751fec2f769fd)
- test: use @swc instead of ts-jest [`8058bac`](https://github.com/Codex-/cosmiconfig-typescript-loader/commit/8058bac377d686984e57a4929f8effd3d354b9e4)

#### [4.3.0](https://github.com/Codex-/cosmiconfig-typescript-loader/compare/4.2.0...4.3.0)

> 11 December 2022
- chore(deps): lock file maintenance [`#58`](https://github.com/Codex-/cosmiconfig-typescript-loader/pull/58)
- chore(deps): bump root dependencies in package. [`6e18a83`](https://github.com/Codex-/cosmiconfig-typescript-loader/commit/6e18a83ab6c3ab02bf86dc1411cf13ee32646680)
- chore(deps): update dependency esbuild to ^0.16.0 [`82da489`](https://github.com/Codex-/cosmiconfig-typescript-loader/commit/82da4890bed9e026132510a0664694cecf91f1a9)
16 changes: 16 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from "@jest/types";

const config: Config.InitialOptions = {
collectCoverageFrom: [
"<rootDir>/lib/**/*",
"!<rootDir>/lib/__fixtures__/**/*",
],
moduleFileExtensions: ["ts", "js"],
transform: {
"^.+\\.ts$": "@swc/jest",
},
testEnvironment: "node",
testRegex: "\\.spec\\.[jt]s$",
};

export default config;
5 changes: 3 additions & 2 deletions lib/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "node:path";

import { cosmiconfig, cosmiconfigSync } from "cosmiconfig";
import { describe, expect, it } from "vitest";

import { TypeScriptLoader } from ".";

describe("TypeScriptLoader", () => {
@@ -37,7 +38,7 @@ describe("TypeScriptLoader", () => {

try {
await cfg.load(path.resolve(fixturesPath, "invalid.fixture.ts"));
throw new Error("Should fail to load invalid TS");
fail("Should fail to load invalid TS");
} catch (error: any) {
expect(error?.name).toStrictEqual("TypeScriptCompileError");
}
42 changes: 6 additions & 36 deletions lib/loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,15 @@
import fs from "node:fs";
import path from "node:path";

import { Loader } from "cosmiconfig";
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
SpyInstance,
vi,
} from "vitest";
import * as tsnode from "ts-node";

import { TypeScriptLoader } from "./loader";
import { TypeScriptCompileError } from "./typescript-compile-error";

vi.mock("ts-node", async () => {
const actualTsnode = await vi.importActual<typeof import("ts-node")>(
"ts-node"
);

const writableTsNode: any = {};
Object.keys(actualTsnode).forEach((key) =>
Object.defineProperty(writableTsNode, key, {
value: (actualTsnode as any)[key],
writable: true,
})
);

return writableTsNode;
});

describe("TypeScriptLoader", () => {
const fixturesPath = path.resolve(__dirname, "__fixtures__");
const tsNodeSpy = vi.spyOn(tsnode, "register");
const tsNodeSpy = jest.spyOn(tsnode, "register");

let loader: Loader;

@@ -47,10 +21,6 @@ describe("TypeScriptLoader", () => {
loader = TypeScriptLoader();
});

afterAll(() => {
vi.restoreAllMocks();
});

it("should parse a valid TS file", () => {
const filePath = path.resolve(fixturesPath, "valid.fixture.ts");
loader(filePath, readFixtureContent(filePath));
@@ -72,7 +42,7 @@ describe("TypeScriptLoader", () => {
try {
const filePath = path.resolve(fixturesPath, "invalid.fixture.ts");
loader(filePath, readFixtureContent(filePath));
throw new Error(
fail(
"Error should be thrown upon failing to transpile an invalid TS file."
);
} catch (error: unknown) {
@@ -83,10 +53,10 @@ describe("TypeScriptLoader", () => {
describe("ts-node", () => {
const unknownError = "Test Error";

let stub: SpyInstance<[service: tsnode.Service], tsnode.Service>;
let stub: jest.SpyInstance<tsnode.Service, [service: tsnode.Service]>;

beforeEach(() => {
stub = vi.spyOn(tsnode, "register").mockImplementation(
stub = jest.spyOn(tsnode, "register").mockImplementation(
() =>
({
compile: (): string => {
@@ -105,7 +75,7 @@ describe("TypeScriptLoader", () => {
it("rethrows an error if it is not an instance of Error", () => {
try {
loader("filePath", "readFixtureContent(filePath)");
throw new Error(
fail(
"Error should be thrown upon failing to transpile an invalid TS file."
);
} catch (error: unknown) {
1 change: 1 addition & 0 deletions lib/loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Loader } from "cosmiconfig";
import { register, RegisterOptions } from "ts-node";

import { TypeScriptCompileError } from "./typescript-compile-error";

export function TypeScriptLoader(options?: RegisterOptions): Loader {
1 change: 0 additions & 1 deletion lib/typescript-compile-error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { describe, expect, it } from "vitest";
import { TypeScriptCompileError } from "./typescript-compile-error";

describe("TypeScriptCompileError", () => {
Loading