Skip to content

Commit

Permalink
Added TypeScript declaration maps (#401).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jan 19, 2021
1 parent 5c27b45 commit 3396846
Show file tree
Hide file tree
Showing 699 changed files with 823 additions and 91 deletions.
35 changes: 26 additions & 9 deletions misc/admin/lib/cmds/esm-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const depgraph_1 = require("../depgraph");
const path_2 = require("../path");
const utils_1 = require("../utils");
const log_1 = require("../log");
function diff(a, b) {
return (Buffer.compare(fs_1.default.readFileSync(a), fs_1.default.readFileSync(b)) !== 0);
}
//function diff(a: string, b: string): boolean {
// return (Buffer.compare(fs.readFileSync(a), fs.readFileSync(b)) !== 0);
//}
function alias(name) {
return __awaiter(this, void 0, void 0, function* () {
console.log(` Aliasing: ${name}`);
Expand All @@ -32,6 +32,7 @@ function alias(name) {
accum[replace] = true;
accum[replace + ".map"] = true;
accum[replace.replace(/\.js$/, ".d.ts")] = true;
accum[replace.replace(/\.js$/, ".d.ts.map")] = true;
return accum;
}, ({}));
const transforms = [];
Expand Down Expand Up @@ -79,26 +80,41 @@ function alias(name) {
}
if (replace) {
inputFilename = replace.replace(/\.js$/i, ".d.ts");
if (diff(path_1.join(baseDir, input, filename), path_1.join(baseDir, input, inputFilename))) {
console.log(`Warning: TypeScript Definition files differ: ${filename} != ${inputFilename}`);
}
transform = function (content) {
content = content.replace(/(\/\/# sourceMappingURL=)(.*)$/g, (all, prefix, mapFilename) => {
return prefix + filename + ".map";
});
return content;
};
//if (diff(join(baseDir, input, filename), join(baseDir, input, inputFilename))) {
// console.log(`Warning: TypeScript Definition files differ: ${ filename } != ${ inputFilename }`);
//}
}
}
else if (filename.match(/\.map$/)) {
// Map files; swap in the replacement
// e.g. (filename = geturl.js.map) => (inputFilename = browser-geturl.js.map)
// + transform the map JSON to reference "geturl.js"
// We need to swap in the replacement and update its data
const replace = replacements[filename.replace(/\.js.map$/i, ".js")];
const replace = replacements[filename.replace(/\.d.ts\.map$|\.js\.map$/i, ".js")];
console.log(filename, replace);
// Skip!
if (replace === "") {
return;
}
if (replace) {
inputFilename = replace + ".map";
if (filename.match(/\.js\.map$/)) {
inputFilename = replace + ".map";
}
else if (filename.match(/\.d\.ts\.map$/)) {
inputFilename = replace.replace(/\.js$/, ".d.ts.map");
}
else {
throw new Error(`unhandled map extension: ${filename}`);
}
transform = function (content) {
const data = JSON.parse(content);
data["file"] = filename.replace(/\.js\.map$/, ".js");
data["file"] = filename.replace(/\.map$/, "");
return JSON.stringify(data);
};
}
Expand All @@ -125,6 +141,7 @@ function alias(name) {
console.log(log_1.colorify.bold(`Aliasing Node ESM to Browser ESM...`));
const dirnames = depgraph_1.getOrdered(true);
for (let i = 0; i < dirnames.length; i++) {
//if (dirnames[i] !== "base64") { continue; }
yield alias(dirnames[i]);
}
});
Expand Down
32 changes: 24 additions & 8 deletions misc/admin/src.ts/cmds/esm-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { resolve } from "../path";
import { loadJson, mkdir } from "../utils";
import { colorify } from "../log";

function diff(a: string, b: string): boolean {
return (Buffer.compare(fs.readFileSync(a), fs.readFileSync(b)) !== 0);
}
//function diff(a: string, b: string): boolean {
// return (Buffer.compare(fs.readFileSync(a), fs.readFileSync(b)) !== 0);
//}

async function alias(name: string): Promise<void> {
console.log(` Aliasing: ${ name }`);
Expand All @@ -22,6 +22,7 @@ async function alias(name: string): Promise<void> {
accum[replace] = true;
accum[replace + ".map"] = true;
accum[replace.replace(/\.js$/, ".d.ts")] = true;
accum[replace.replace(/\.js$/, ".d.ts.map")] = true;
return accum;
}, <Record<string, boolean>>({ }));

Expand Down Expand Up @@ -70,26 +71,40 @@ async function alias(name: string): Promise<void> {

if (replace) {
inputFilename = replace.replace(/\.js$/i, ".d.ts");
if (diff(join(baseDir, input, filename), join(baseDir, input, inputFilename))) {
console.log(`Warning: TypeScript Definition files differ: ${ filename } != ${ inputFilename }`);
transform = function(content: string) {
content = content.replace(/(\/\/# sourceMappingURL=)(.*)$/g, (all, prefix, mapFilename) => {
return prefix + filename + ".map";
});
return content;
}
//if (diff(join(baseDir, input, filename), join(baseDir, input, inputFilename))) {
// console.log(`Warning: TypeScript Definition files differ: ${ filename } != ${ inputFilename }`);
//}
}

} else if (filename.match(/\.map$/)) {
// Map files; swap in the replacement
// e.g. (filename = geturl.js.map) => (inputFilename = browser-geturl.js.map)
// + transform the map JSON to reference "geturl.js"
// We need to swap in the replacement and update its data
const replace = replacements[filename.replace(/\.js.map$/i, ".js")];
const replace = replacements[filename.replace(/\.d.ts\.map$|\.js\.map$/i, ".js")];
console.log(filename, replace);

// Skip!
if (replace === "") { return; }

if (replace) {
inputFilename = replace + ".map";
if (filename.match(/\.js\.map$/)) {
inputFilename = replace + ".map";
} else if (filename.match(/\.d\.ts\.map$/)) {
inputFilename = replace.replace(/\.js$/, ".d.ts.map");
} else {
throw new Error(`unhandled map extension: ${ filename }`);
}

transform = function(content: string) {
const data = JSON.parse(content);
data["file"] = filename.replace(/\.js\.map$/, ".js");
data["file"] = filename.replace(/\.map$/, "");
return JSON.stringify(data);
}
}
Expand Down Expand Up @@ -118,6 +133,7 @@ async function alias(name: string): Promise<void> {
console.log(colorify.bold(`Aliasing Node ESM to Browser ESM...`));
const dirnames = getOrdered(true);
for (let i = 0; i < dirnames.length; i++) {
//if (dirnames[i] !== "base64") { continue; }
await alias(dirnames[i]);
}
})();
3 changes: 2 additions & 1 deletion packages/abi/lib.esm/_version.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export declare const version = "abi/5.0.10";
export declare const version = "abi/5.0.11";
//# sourceMappingURL=_version.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/_version.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/abi-coder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export declare class AbiCoder {
decode(types: Array<string | ParamType>, data: BytesLike, loose?: boolean): Result;
}
export declare const defaultAbiCoder: AbiCoder;
//# sourceMappingURL=abi-coder.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/abi-coder.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/abstract-coder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export declare class Reader {
readBytes(length: number, loose?: boolean): Uint8Array;
readValue(): BigNumber;
}
//# sourceMappingURL=abstract-coder.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/abstract-coder.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/address.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export declare class AddressCoder extends Coder {
encode(writer: Writer, value: string): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=address.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/address.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/anonymous.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export declare class AnonymousCoder extends Coder {
encode(writer: Writer, value: any): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=anonymous.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/anonymous.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/array.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export declare class ArrayCoder extends Coder {
encode(writer: Writer, value: Array<any>): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=array.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/array.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/boolean.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export declare class BooleanCoder extends Coder {
encode(writer: Writer, value: boolean): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=boolean.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/boolean.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/bytes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export declare class BytesCoder extends DynamicBytesCoder {
constructor(localName: string);
decode(reader: Reader): any;
}
//# sourceMappingURL=bytes.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/bytes.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/fixed-bytes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export declare class FixedBytesCoder extends Coder {
encode(writer: Writer, value: BytesLike): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=fixed-bytes.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/fixed-bytes.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/null.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export declare class NullCoder extends Coder {
encode(writer: Writer, value: any): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=null.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/null.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/number.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export declare class NumberCoder extends Coder {
encode(writer: Writer, value: BigNumberish): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=number.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/number.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/string.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export declare class StringCoder extends DynamicBytesCoder {
encode(writer: Writer, value: any): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=string.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/string.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/tuple.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export declare class TupleCoder extends Coder {
}): number;
decode(reader: Reader): any;
}
//# sourceMappingURL=tuple.d.ts.map
1 change: 1 addition & 0 deletions packages/abi/lib.esm/coders/tuple.d.ts.map

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

1 change: 1 addition & 0 deletions packages/abi/lib.esm/fragments.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ export declare class FunctionFragment extends ConstructorFragment {
static fromString(value: string): FunctionFragment;
static isFunctionFragment(value: any): value is FunctionFragment;
}
//# sourceMappingURL=fragments.d.ts.map
Loading

0 comments on commit 3396846

Please sign in to comment.