Skip to content

Commit

Permalink
force extensions into build
Browse files Browse the repository at this point in the history
  • Loading branch information
adraffy committed Sep 1, 2024
1 parent e73228f commit 6171866
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 30 deletions.
79 changes: 57 additions & 22 deletions v2/build-dist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { readFileSync, writeFileSync, mkdirSync, rmdirSync } from 'node:fs';
import {
readFileSync,
writeFileSync,
mkdirSync,
rmdirSync,
readdirSync,
renameSync,
} from 'node:fs';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';
Expand Down Expand Up @@ -26,7 +33,7 @@ log(`Saved configuration`);

// verify build
log(`Typechecking...`);
spawnSync('bun', ['tsc', '-p', '.', '--noEmit']);
runTypescript('--noEmit');
log('Ready!');

// clear dist
Expand All @@ -38,32 +45,60 @@ log(`Cleaned ${distDir}`);
tsc.include = tsc.include.filter((x) => !`^test\b`.match(x));
writeFileSync(tsconfigFile, JSON.stringify(tsc));

// create outputs
const cjsDir = join(distDir, 'cjs');
const esmDir = join(distDir, 'esm');
const typesDir = join(distDir, 'types');
try {
build('commonjs', 'cjs');
build('module', 'esm');
setPackageType('commonjs');
runTypescript('--outDir', cjsDir, '--module', 'node16');
forceExtension(cjsDir, 'cjs');
log('Built cjs');

setPackageType('module');
runTypescript('--outDir', esmDir);
forceExtension(esmDir, 'mjs');
log('Built esm');

runTypescript(
'--outDir',
typesDir,
'--module',
'esnext',
'--emitDeclarationOnly',
'--declaration',
'--declarationMap'
);
log('Built types');
} finally {
writeFileSync(packageFile, packageOriginal);
writeFileSync(tsconfigFile, tsconfigOriginal);
log(`Restored configuration`);
}

function build(packageType: string, dirName: string) {
pkg.type = packageType;
function runTypescript(...args: string[]) {
spawnSync('bun', ['tsc', '-p', '.', ...args]);
}

function setPackageType(type: string) {
pkg.type = type;
writeFileSync(packageFile, JSON.stringify(pkg));
log(`Set package type: "${packageType}"`);
const dir = join(distDir, dirName);
spawnSync('bun', [
'tsc',
'-p',
'.',
'--outDir',
dir,
'--declaration',
'--declarationMap',
]);
writeFileSync(
join(dir, 'package.json'),
JSON.stringify({ type: packageType, sideEffects: false })
);
log(`Built ${dirName}: ${dir}`);
log(`Set package type: "${type}"`);
}

function forceExtension(dir: string, ext: string) {
for (const x of readdirSync(dir, { withFileTypes: true })) {
const path = join(dir, x.name);
if (x.isDirectory()) {
forceExtension(path, ext);
} else if (x.name.endsWith('.js')) {
let code = readFileSync(path, { encoding: 'utf-8' });
code = code.replaceAll(
/(["'])(.*?\.)js\1/g,
(_, q, x) => q + x + ext + q
);
writeFileSync(path, code);
renameSync(path, join(dir, x.name.slice(0, -2) + ext));
}
}
}
9 changes: 4 additions & 5 deletions v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unruggable/evmgateway",
"version": "0.0.3",
"version": "0.0.4",
"keywords": [
"ethereum",
"evm",
Expand All @@ -22,10 +22,9 @@
},
"sideEffects": false,
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs"
},
"files": [
"dist/",
Expand Down
3 changes: 1 addition & 2 deletions v2/src/linea/LineaGatewayV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { requireV1Needs } from '../vm.js';
// https://github.com/Consensys/linea-ens/blob/main/packages/linea-ccip-gateway/src/L2ProofService.ts

// the deployed linea verifier is not compatible with the current gateway design
// 1. v0 request encoding (no OP_ADD_CONST)
// 2. strange proof encoding: incorrect negative proofs + unnecessary data (key)
// due to strange proof encoding: incorrect negative proofs + unnecessary data (key)

export class LineaGatewayV1 extends GatewayV1<LineaRollup> {
override async handleRequest(commit: LineaCommit, request: EVMRequestV1) {
Expand Down
2 changes: 1 addition & 1 deletion v2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"verbatimModuleSyntax": false,
"importHelpers": true,

"module": "node16",
"module": "NodeNext",
// "target": "ES2021",
// "lib": ["ES2022"],

Expand Down

0 comments on commit 6171866

Please sign in to comment.