Skip to content

Commit

Permalink
Stricter typescript settings (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellmcc authored Sep 14, 2024
1 parent 78e1589 commit 05a3f23
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 25 deletions.
5 changes: 5 additions & 0 deletions web/create/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Copyright (c) 2024 by Conformal Authors

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3 changes: 2 additions & 1 deletion web/create/template/web/eslint-config-custom/config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:react-hooks/recommended",
"plugin:react/recommended",
Expand All @@ -23,6 +23,7 @@ module.exports = {
argsIgnorePattern: "^_",
},
],
"@typescript-eslint/no-non-null-assertion": "off",
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
Expand Down
11 changes: 8 additions & 3 deletions web/create/template/web/tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"compilerOptions": {
"target": "es2020",
"useDefineForClassFields": true,
"lib": ["es2020", "dom", "dom.iterable"],
"lib": [
"es2020",
"dom",
"dom.iterable"
],
"module": "esnext",
"skipLibCheck": true,
/* Bundler mode */
Expand All @@ -15,6 +19,7 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true
}
}
}
11 changes: 9 additions & 2 deletions web/create/template/web/{{plug_slug}}/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import react from "@vitejs/plugin-react-swc";
import license from "rollup-plugin-license";
import { join } from "path";

const unwrap = (x: string | null, name: string, field: string): string => {
if (x === null) {
throw new Error(`Malformed dependency ${name} (${field})`);
}
return x;
};

/** @type {import('vite').UserConfig} */
export default {
plugins: [
Expand All @@ -15,9 +22,9 @@ export default {
.map(
(dependency) =>
`-----
${dependency.name} ${dependency.version} (${dependency.license})
${unwrap(dependency.name, "unknown", "name")} ${unwrap(dependency.version, dependency.name!, "version")} (${unwrap(dependency.license, dependency.name!, "license")})
${dependency.licenseText}
${unwrap(dependency.licenseText, dependency.name!, "licenseText")}
`,
)
.join("\n"),
Expand Down
8 changes: 7 additions & 1 deletion web/docs/theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const themeConfig: DocsThemeConfig = {
feedback: {
useLink: () => {
const config = useConfig();
return `https://github.com/russellmcc/conformal/discussions/new?category=q-a&title=Feedback regarding ${config.title}`;

// Not sure what's going on here, but typescript can't seem to correctly
// infer the type of `config` :'(.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const title: string = config.title;

return `https://github.com/russellmcc/conformal/discussions/new?category=q-a&title=Feedback regarding ${title}`;
},
},
footer: {
Expand Down
3 changes: 2 additions & 1 deletion web/eslint-config-custom/config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:react-hooks/recommended",
"plugin:react/recommended",
Expand All @@ -23,6 +23,7 @@ module.exports = {
argsIgnorePattern: "^_",
},
],
"@typescript-eslint/no-non-null-assertion": "off",
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
Expand Down
5 changes: 5 additions & 0 deletions web/plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Copyright (c) 2024 by Conformal Authors

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4 changes: 2 additions & 2 deletions web/plugin/src/mock_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const mockGeneric = (infos: Map<string, Info>): Family<Value> =>
atomFamily((path) => {
const paramPath = path.match(/^params\/(.*)$/);
if (paramPath) {
const param = paramPath[1];
const param = paramPath[1]!;
const info = infos.get(param);
if (!info) {
throw new Error(`Unknown param: ${param}`);
Expand All @@ -30,7 +30,7 @@ const mockGeneric = (infos: Map<string, Info>): Family<Value> =>
if (!paramInfoPath) {
throw new Error(`Unknown path: ${path}`);
}
const param = paramInfoPath[1];
const param = paramInfoPath[1]!;
const info = infos.get(param);
if (!info) {
throw new Error(`Unknown param: ${param}`);
Expand Down
3 changes: 2 additions & 1 deletion web/plugin/src/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ const createGeneric = (transport: Transport): Family<Value> => {
for (const [path, value] of Object.entries(response.values)) {
setters.get(path)?.(value);
}
} else if (response.m === "subscribe_error") {
} else {
// response.m === "subscribe_error"
setters.get(response.path)?.(
Promise.reject(new Error(`Subscribe Error at ${response.path}`)),
);
Expand Down
8 changes: 6 additions & 2 deletions web/plugin/src/stores_react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ export const useGrab = (path: string): Grab => {
const storage = useStores();
const grab = useAtom(storage.grabbed(path))[1];
return {
grab: () => grab(true),
release: () => grab(false),
grab: () => {
grab(true);
},
release: () => {
grab(false);
},
};
};

Expand Down
2 changes: 1 addition & 1 deletion web/plugin/src/wry_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare global {

// This is a function we add to the window object to receive messages from
// Wry. It is set by the setOnResponse function below.
receiveMessage: (m: string) => void | undefined;
receiveMessage: (m: string) => void;
}
}

Expand Down
5 changes: 5 additions & 0 deletions web/scripts/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Copyright (c) 2024 by Conformal Authors

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
12 changes: 10 additions & 2 deletions web/scripts/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ const rust = (): Tool => ({
try {
const cargoVersion = (await $`cargo --version`.text()).split(" ")[1];
if (cargoVersion !== RUST_VERSION) {
console.warn(`cargo installed, but wrong version ${cargoVersion}`);
console.warn(
cargoVersion
? `cargo installed, but wrong version ${cargoVersion}`
: "cargo installed, but could not get version",
);
return false;
}
return true;
Expand Down Expand Up @@ -83,7 +87,11 @@ const vst3Validator = (): Tool => ({

install: async () => {
// use cmake to build the validator
const buildPath = `${process.env.VST3_SDK_DIR}/build`;
const sdk = process.env.VST3_SDK_DIR;
if (!sdk) {
throw new Error("VST3_SDK_DIR is not set");
}
const buildPath = `${sdk}/build`;
await $`mkdir -p ${buildPath}`.quiet();
await $`cmake ..`.cwd(buildPath);
await $`cmake --build . --target validator`.cwd(buildPath);
Expand Down
8 changes: 6 additions & 2 deletions web/scripts/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const createBundle = async ({
await runShell(["defaults", "write", bundleData.id, "dev_mode", "true"]);

// Delete the bundle if it exists.
await runShell(["rm", "-rf", `${bundlePath}`]);
await runShell(["rm", "-rf", bundlePath]);

// Create the binary directory for the bundle.
await runShell(["mkdir", "-p", `${bundlePath}/Contents/MacOS`]);
Expand Down Expand Up @@ -123,8 +123,12 @@ export const createBundle = async ({
const bundle_absolute_path = resolve(bundlePath);

if (linkToLibrary) {
const home = process.env.HOME;
if (!home) {
throw new Error("HOME environment variable is not set");
}
const bundle_dest = resolve(
`${process.env.HOME}/Library/Audio/Plug-Ins/VST3/${bundleData.name}.vst3`,
`${home}/Library/Audio/Plug-Ins/VST3/${bundleData.name}.vst3`,
);

await runShell(["rm", "-rf", bundle_dest]);
Expand Down
2 changes: 1 addition & 1 deletion web/scripts/src/checkLfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const shouldLfsFiles = async function* () {
for await (const line of $`git ls-files`.lines()) {
if (line === "") continue;
const filter_raw = await $`git check-attr filter ${line}`.text();
const filter = filter_raw.split("filter: ").slice(-1)[0].trim();
const filter = filter_raw.split("filter: ").slice(-1)[0]?.trim();
if (filter === "lfs") {
yield line;
}
Expand Down
2 changes: 1 addition & 1 deletion web/scripts/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ More info [here](https://developer.apple.com/documentation/security/notarizing_m
"--root",
tmpDir,
"--identifier",
`${qualifiedIdent}`,
qualifiedIdent,
"--version",
bundleData.version,
"--sign",
Expand Down
10 changes: 5 additions & 5 deletions web/scripts/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export const execute = async (config: Config) => {
const { name } = await getBundleData(packageRoot);

const bundlePath = `target/${config}/${name}.vst3`;

await runShell([
`${process.env.VST3_SDK_DIR}/build/bin/validator`,
bundlePath,
]);
const sdkDir = process.env.VST3_SDK_DIR;
if (!sdkDir) {
throw new Error("VST3_SDK_DIR is not set");
}
await runShell([`${sdkDir}/build/bin/validator`, bundlePath]);
};

export const addValidateCommand = (command: Command) => {
Expand Down
1 change: 1 addition & 0 deletions web/tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
},
}

0 comments on commit 05a3f23

Please sign in to comment.