Skip to content

Commit

Permalink
Fix dprint config for typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Sep 4, 2024
1 parent 6c05b68 commit f2bd6a8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
5 changes: 4 additions & 1 deletion dprint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"typescript": {
"quoteStyle": "preferSingle"
},
"json": {
"trailingCommas": "never"
},
Expand All @@ -7,7 +10,7 @@
"malva": {
"quotes": "preferSingle"
},
"excludes": ["*.ts*", "dist/", "node_modules/", ".git/", "vendor/"],
"excludes": ["dist/", "node_modules/", ".git/", "vendor/"],
"plugins": [
"https://plugins.dprint.dev/typescript-0.91.7.wasm",
"https://plugins.dprint.dev/json-0.19.3.wasm",
Expand Down
64 changes: 30 additions & 34 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { encodeHex } from "@std/encoding";
import { basename, extname, join } from "@std/path";
import manifestJson from "../src/manifest.json" with {
type: "json",
import { assertEquals } from '@std/assert';
import { encodeHex } from '@std/encoding';
import { basename, extname, join } from '@std/path';
import manifestJson from '../src/manifest.json' with {
type: 'json',
};
import manifestSchema from "../src/manifestSchemaAdjusted.json" with {
type: "json",
import manifestSchema from '../src/manifestSchemaAdjusted.json' with {
type: 'json',
};
import { assertEquals } from "@std/assert";
// Always require --allow-net https://github.com/denoland/deno_emit/issues/81
import { bundle } from "@deno/emit";
import * as fflate from "fflate";
import { Ajv } from "ajv";
import prettyBytes from "pretty-bytes";
import { bundle } from '@deno/emit';
import { Ajv } from 'ajv';
import * as fflate from 'fflate';
import prettyBytes from 'pretty-bytes';

const cleanUpSync = () => {
try {
Deno.removeSync("./dist", { recursive: true });
Deno.removeSync('./dist', { recursive: true });
} catch (error) {
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
}

Deno.mkdirSync("dist/assets", { recursive: true });
Deno.mkdirSync('dist/assets', { recursive: true });
};

cleanUpSync();

const transpile = async () => {
for (const entryTsPath of ["src/github-patcher.ts", "src/options.tsx"]) {
for (const entryTsPath of ['src/github-patcher.ts', 'src/options.tsx']) {
const bundled = await bundle(entryTsPath);
const outputPath = `dist/${basename(entryTsPath, extname(entryTsPath))}.js`;
Deno.writeTextFileSync(outputPath, bundled.code);
Expand All @@ -37,42 +37,40 @@ const transpile = async () => {

const gatherDist = Promise.all([
transpile(),
Deno.copyFile("README.md", "dist/README.md"),
Deno.copyFile("LICENSE", "dist/LICENSE"),
Deno.copyFile("src/manifest.json", "dist/manifest.json"),
Deno.copyFile("src/github-patcher.css", "dist/github-patcher.css"),
Deno.copyFile("src/options.html", "dist/options.html"),
Deno.copyFile("src/options.css", "dist/options.css"),
Deno.copyFile("vendor/primer.css", "dist/primer.css"),
Deno.copyFile('README.md', 'dist/README.md'),
Deno.copyFile('LICENSE', 'dist/LICENSE'),
Deno.copyFile('src/manifest.json', 'dist/manifest.json'),
Deno.copyFile('src/github-patcher.css', 'dist/github-patcher.css'),
Deno.copyFile('src/options.html', 'dist/options.html'),
Deno.copyFile('src/options.css', 'dist/options.css'),
Deno.copyFile('vendor/primer.css', 'dist/primer.css'),
Deno.copyFile(
"assets/icons/3.edit_by_me/from-icon-sadness-star-2024-03-25-128x128-t.png",
"dist/icon-sadness-star.png",
'assets/icons/3.edit_by_me/from-icon-sadness-star-2024-03-25-128x128-t.png',
'dist/icon-sadness-star.png',
),
]);

await gatherDist;

const getOrderedPathList = (dirPath: string): string[] =>
Array.from(Deno.readDirSync(dirPath)).flatMap((dirEntity) =>
dirEntity.isFile ? [dirEntity.name] : []
).toSorted();
Array.from(Deno.readDirSync(dirPath)).flatMap((dirEntity) => dirEntity.isFile ? [dirEntity.name] : []).toSorted();

const zipStructure = new Map<
string,
{ content: Uint8Array; sha256: string; isCompressed: boolean }
>();

const sha256 = async (content: Uint8Array) => {
const digest = await crypto.subtle.digest("SHA-256", content);
const digest = await crypto.subtle.digest('SHA-256', content);
return encodeHex(digest);
};

for (const path of getOrderedPathList("dist")) {
const content = Deno.readFileSync(join("dist", path));
for (const path of getOrderedPathList('dist')) {
const content = Deno.readFileSync(join('dist', path));
zipStructure.set(path, {
content,
sha256: await sha256(content),
isCompressed: extname(path) === ".png",
isCompressed: extname(path) === '.png',
});
}

Expand All @@ -97,16 +95,14 @@ const structure = Array.from(zipStructure.entries()).reduce(
const structureSha256 = await sha256(
textEncoder.encode(JSON.stringify(structure)),
);
const productBasename = `depop-${manifestJson.version}-${
structureSha256.slice(0, 7)
}.zip`;
const productBasename = `depop-${manifestJson.version}-${structureSha256.slice(0, 7)}.zip`;
const productPath = `dist/${productBasename}`;
Deno.writeFileSync(productPath, zipped);

const validateProduct = async (zipped: Uint8Array) => {
const unzipped = fflate.unzipSync(zipped);

assertEquals(JSON.parse(toString(unzipped["manifest.json"])), manifestJson);
assertEquals(JSON.parse(toString(unzipped['manifest.json'])), manifestJson);

const ajv = new Ajv({ allErrors: true });
const schemaOk = await ajv.validate(manifestSchema, manifestJson);
Expand Down
4 changes: 2 additions & 2 deletions scripts/manifestValidator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Ajv } from 'ajv';
// Do not include from https://json.schemastore.org/chrome-manifest, current official stored has wrong definitions
// See https://github.com/SchemaStore/schemastore/issues/2861 for further detail
import manifestSchema from '../src/manifestSchemaAdjusted.json' with {
import manifestJson from '../src/manifest.json' with {
type: 'json',
};
import manifestJson from '../src/manifest.json' with {
import manifestSchema from '../src/manifestSchemaAdjusted.json' with {
type: 'json',
};

Expand Down
2 changes: 1 addition & 1 deletion src/options.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StrictMode } from 'https://esm.sh/v135/[email protected]';
import { createRoot } from 'https://esm.sh/v135/[email protected]/client';
import { StrictMode } from 'https://esm.sh/v135/[email protected]';
import App from './options/App.tsx';
import { assertIsDefined } from './typeguards.ts';

Expand Down

0 comments on commit f2bd6a8

Please sign in to comment.