Skip to content

Commit

Permalink
improve build
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed May 7, 2024
1 parent ab88823 commit 9e88f89
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 26 deletions.
4 changes: 2 additions & 2 deletions packages/preact/preact/src/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ComponentFrame {
): FinalizedFormula {
const frame = ComponentFrame.#frames.get(component);

verify(
verify?.(
frame,
isPresent,
expected?.when("in Preact's _diff hook").as("a tracking frame"),
Expand Down Expand Up @@ -101,7 +101,7 @@ export class ComponentFrame {
}

#end(subscription: (() => void) | undefined) {
verify(
verify?.(
this.#active,
isPresent,
expected?.when("in preact's _diff hook").as("an active tracking frame"),
Expand Down
2 changes: 1 addition & 1 deletion packages/universal/collections/src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const cached = <T>(
): void => {
const get = descriptor.get;

verify(
verify?.(
get,
isPresent,
expected?.(`the target of @cached`)
Expand Down
2 changes: 1 addition & 1 deletion packages/universal/verify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export {
export { type TypeOf } from "./src/assertions/types.js";
export { type Expectation, VerificationError } from "./src/verify.js";

export const expected: typeof expectedDev = import.meta.env.DEV ? expectedDev : (noop as typeof expectedDev)
export const expected: typeof expectedDev = import.meta.env.DEV ? expectedDev : null as any

Check warning on line 29 in packages/universal/verify/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an `any` value

Check failure on line 29 in packages/universal/verify/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
export const hasType: typeof hasTypeDev = import.meta.env.DEV ? hasTypeDev : (noop as typeof hasTypeDev)
export const isOneOf: typeof isOneOfDev = import.meta.env.DEV ? isOneOfDev : (noop as typeof isOneOfDev)

Expand Down
37 changes: 19 additions & 18 deletions packages/universal/verify/src/assertions/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export function isPresent<T>(value: T): value is Exclude<T, null | undefined> {
return value !== null && value !== undefined;
}

expected.associate(isPresent, expected.toBe("present"));

export function exhaustive(_value: never, type?: string): never {
if (type) {
throw Error(`unexpected types left in ${type}`);
Expand Down Expand Up @@ -66,26 +64,12 @@ export function isObject(value: unknown): value is object {
return typeof value === "object" && value !== null;
}

expected.associate(
isObject,
expected
.toBe("an object")
.butGot((value) => (value === null ? "null" : typeof value)),
);

export function isWeakKey(value: unknown): value is Record<string, unknown> {
return (
(typeof value === "object" || typeof value === "function") && value !== null
);
}

expected.associate(
isWeakKey,
expected
.toBe("an object or function")
.butGot((value) => (value === null ? "null" : typeof value)),
);

interface HasLength<L extends number> {
<T>(value: T[]): value is FixedArray<T, L>;
<T>(value: T[] | readonly T[]): value is ReadonlyFixedArray<T, L>;
Expand All @@ -107,8 +91,6 @@ export const hasItems = isPresentArray;
// return value.length > 0;
// }

expected.associate(hasItems, expected.toHave(`at least one item`));

export function isNullable<In, Out extends In>(
verifier: (value: In) => value is Out,
): (value: In | null) => value is Out | null {
Expand Down Expand Up @@ -145,3 +127,22 @@ export function isNullable<In, Out extends In>(

return verify;
}


if (import.meta.env.DEV) {
expected.associate(isPresent, expected.toBe("present"));
expected.associate(hasItems, expected.toHave(`at least one item`));
expected.associate(
isWeakKey,
expected
.toBe("an object or function")
.butGot((value) => (value === null ? "null" : typeof value)),
);
expected.associate(
isObject,
expected
.toBe("an object")
.butGot((value) => (value === null ? "null" : typeof value)),
);

}
50 changes: 49 additions & 1 deletion pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions workspace/dev-compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"rollup": "^4.1.4",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-ts": "^3.4.5",
"rollup-plugin-prettier": "^4.1.1",

Check failure on line 29 in workspace/dev-compile/package.json

View workflow job for this annotation

GitHub Actions / Lint

Expected object keys to be in natural ascending order. 'rollup-plugin-prettier' should be before 'rollup-plugin-ts'
"typescript": "^5.2.2"
},
"devDependencies": {
Expand Down
8 changes: 5 additions & 3 deletions workspace/dev-compile/src/rollup/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import externals from "./plugins/external.js";
import importMeta from "./plugins/import-meta.js";
import typescript from "./plugins/typescript.js";
import type { RollupPlugin } from "./utils.js";
import prettier from 'rollup-plugin-prettier';

const MODES = ["development", "production", undefined] as const;

Expand Down Expand Up @@ -81,15 +82,16 @@ function compilePackage(pkg: PackageInfo, options: CompileOptions): RollupOption
format: {
comments: false
},
// prevent any compression
compress: {
dead_code: true,
module: true,
keep_fargs: false,
passes: 5
keep_fargs: false
},
mangle: false,
}),
prettier({
parser: 'babel'
})
] : [])
],
}));
Expand Down

0 comments on commit 9e88f89

Please sign in to comment.