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: apollographql/invariant-packages
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ts-invariant@0.7.4
Choose a base ref
...
head repository: apollographql/invariant-packages
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ts-invariant@0.7.5
Choose a head ref
  • 2 commits
  • 13 files changed
  • 1 contributor

Commits on Jun 16, 2021

  1. Revert "Expose ts-invariant/process entry point for optional global.p…

    …rocess polyfill (#139)"
    
    This reverts commit 5f290c9, which was
    intended to be published in a minor version (ts-invariant@0.8.0) but was
    accidentally published in version 0.7.4.
    benjamn committed Jun 16, 2021
    Copy the full SHA
    4b46bb2 View commit details
  2. Publish

     - rollup-plugin-invariant@0.8.1
     - ts-invariant@0.7.5
    benjamn committed Jun 16, 2021
    Copy the full SHA
    ddf99bc View commit details
2 changes: 1 addition & 1 deletion packages/rollup-plugin-invariant/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/rollup-plugin-invariant/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-invariant",
"version": "0.8.0",
"version": "0.8.1",
"author": "Ben Newman <ben@apollographql.com>",
"description": "Rollup plugin to strip invariant(condition, message) strings in production",
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/ts-invariant/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ts-invariant/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-invariant",
"version": "0.7.4",
"version": "0.7.5",
"author": "Ben Newman <ben@apollographql.com>",
"description": "TypeScript implementation of invariant(condition, message)",
"license": "MIT",
45 changes: 0 additions & 45 deletions packages/ts-invariant/process/main.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/ts-invariant/process/main.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions packages/ts-invariant/process/module.d.ts

This file was deleted.

37 changes: 0 additions & 37 deletions packages/ts-invariant/process/module.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/ts-invariant/process/package.json

This file was deleted.

24 changes: 3 additions & 21 deletions packages/ts-invariant/rollup.config.js
Original file line number Diff line number Diff line change
@@ -11,10 +11,7 @@ function external(id) {
return id in globals;
}

const jobs = [];
export default jobs;

jobs.push({
export default [{
input: "src/invariant.ts",
external,
output: {
@@ -29,9 +26,7 @@ jobs.push({
tsconfig: "./tsconfig.rollup.json",
}),
],
});

jobs.push({
}, {
input: "lib/invariant.esm.js",
external,
output: {
@@ -43,17 +38,4 @@ jobs.push({
name: "ts-invariant",
globals,
},
});

jobs.push({
input: "process/module.js",
external,
output: {
file: "process/main.js",
format: "cjs",
exports: "named",
sourcemap: true,
name: "ts-invariant/process",
globals,
},
});
}];
16 changes: 16 additions & 0 deletions packages/ts-invariant/src/invariant.ts
Original file line number Diff line number Diff line change
@@ -53,4 +53,20 @@ export function setVerbosity(level: VerbosityLevel): VerbosityLevel {
return old;
}

// Code that uses ts-invariant with rollup-plugin-invariant may want to
// import this process stub to avoid errors evaluating process.env.NODE_ENV.
// However, because most ESM-to-CJS compilers will rewrite the process import
// as tsInvariant.process, which prevents proper replacement by minifiers, we
// also export processStub, so you can import { invariant, processStub } from
// "ts-invariant" and assign processStub to a local variable named process.
export const processStub: {
env: Record<string, any>;
[key: string]: any;
} = (
typeof process === "object" &&
typeof process.env === "object"
) ? process : { env: {} };

export { processStub as process };

export default invariant;
43 changes: 19 additions & 24 deletions packages/ts-invariant/src/tests.ts
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@ import defaultExport, {
invariant,
InvariantError,
setVerbosity,
process,
processStub,
} from "./invariant";
import reactInvariant from "invariant";

import { install, remove } from "../process";

describe("ts-invariant", function () {
it("should support both named and default exports", function () {
assert.strictEqual(defaultExport, invariant);
@@ -145,33 +145,28 @@ describe("ts-invariant", function () {
checkConsoleMethod("error", true);
});

it("should export a usable process polyfill", function () {
assert.strictEqual(typeof process, "object");
assert.strictEqual(typeof process.env, "object");
if (process.versions) {
assert.strictEqual(typeof process.versions.node, "string");
}
});

it("should export a usable processStub", function () {
const process = processStub;
assert.strictEqual(typeof process, "object");
assert.strictEqual(typeof process.env, "object");
if (process.versions) {
assert.strictEqual(typeof process.versions.node, "string");
}
});

it("should let TypeScript know about the assertion made", function () {
const value: { foo?: { bar?: string } } = {foo: {bar: "bar"}};
invariant(value.foo, 'fail');

// On compile time this should not raise "TS2532: Object is possibly 'undefined'."
assert.strictEqual(value.foo.bar, "bar");
});

describe("ts-invariant/process", function () {
it("install and remove", function () {
const origDesc = Object.getOwnPropertyDescriptor(global, "process");
Object.defineProperty(global, "process", {
value: void 0,
configurable: true,
});
assert.strictEqual(process, void 0);
install();
assert.deepStrictEqual(process, {
env: {
NODE_ENV: "production",
},
});
remove();
assert.strictEqual(typeof process, "undefined");
if (origDesc) {
Object.defineProperty(global, "process", origDesc);
}
});
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"lib": ["es2015", "DOM"],
"lib": ["es2015"],
"types": ["node", "mocha"],
"strict": true,
"noImplicitAny": true,