-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
132 changed files
with
1,147 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
node_modules/ | ||
packages/*/node_modules | ||
packages/*/lib._esm | ||
.package_node_modules/ | ||
obsolete/ | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** bundle-testcases | ||
* | ||
* This sript converts all the testase data (including needed | ||
* text files) into a single JSON file. | ||
* | ||
* All gzip files (mostly .json.gz) are decompressed and recompressed | ||
* using deflate, so a much more simple deflate library can be used. | ||
*/ | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = require("path"); | ||
const zlib_1 = __importDefault(require("zlib")); | ||
const log_1 = require("../log"); | ||
const path_2 = require("../path"); | ||
const config = { | ||
dirs: [ | ||
"./input/easyseed-bip39", | ||
"./testcases", | ||
"./input/wordlists" | ||
] | ||
}; | ||
(function () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log(log_1.colorify.bold(`Bundling Testcase Data...`)); | ||
const data = { "_": JSON.stringify({ name: "browser-fs", config: config }) }; | ||
config.dirs.forEach((dirname) => { | ||
let fulldirname = path_2.resolve("packages/testcases", dirname); | ||
fs_1.default.readdirSync(fulldirname).forEach((filename) => { | ||
const key = path_1.join(dirname, filename); | ||
const content = fs_1.default.readFileSync(path_1.join(fulldirname, filename)); | ||
if (filename.split(".").pop() === "gz") { | ||
const contentData = zlib_1.default.gunzipSync(content); | ||
data[key] = String(contentData.length) + "," + zlib_1.default.deflateRawSync(contentData).toString("base64"); | ||
} | ||
else { | ||
data[key] = content.toString("base64"); | ||
} | ||
console.log(` - Added ${key} (${data[key].length} bytes)`); | ||
}); | ||
}); | ||
// We write it out to all needed places | ||
fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib/browser-data.json"), JSON.stringify(data)); | ||
fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data)); | ||
fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib.esm/browser-data.json"), JSON.stringify(data)); | ||
// Write it to the TypeScript source last, in case it is running it will | ||
// be regenerated overwriting the above files, but with identical content | ||
fs_1.default.writeFileSync(path_2.resolve("packages/testcases/src.ts/browser-data.json"), JSON.stringify(data)); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = require("path"); | ||
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 alias(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log(` Aliasing: ${name}`); | ||
const baseDir = path_2.resolve("packages", name); | ||
const info = utils_1.loadJson(path_2.resolve(baseDir, "package.json")); | ||
const replacements = info["_ethers.alias"] || {}; | ||
const skip = Object.keys(replacements).reduce((accum, key) => { | ||
const replace = replacements[key]; | ||
accum[replace] = true; | ||
accum[replace + ".map"] = true; | ||
accum[replace.replace(/\.js$/, ".d.ts")] = true; | ||
return accum; | ||
}, ({})); | ||
const transforms = []; | ||
const recurse = function (input, output) { | ||
fs_1.default.readdirSync(path_1.join(baseDir, input)).forEach((filename) => { | ||
const stat = fs_1.default.statSync(path_1.join(baseDir, input, filename)); | ||
if (stat.isDirectory()) { | ||
recurse(path_1.join(input, filename), path_1.join(output, filename)); | ||
return; | ||
} | ||
if (skip[filename]) { | ||
return; | ||
} | ||
let inputFilename = filename; | ||
let transform = null; | ||
if (filename.match(/\.js(on)?$/)) { | ||
// JavaScript; swap in any replacement | ||
// e.g. (filename = geturl.js) => (inputFilename = browser-geturl.js) | ||
// + transform (//# sourceMappingURL=browser-geturl.js.map) to | ||
// (//# sourceMappingURL=geturl.js.map) | ||
const replace = replacements[filename]; | ||
// Skip! | ||
if (replace === "") { | ||
return; | ||
} | ||
if (replace) { | ||
inputFilename = replace; | ||
transform = function (content) { | ||
content = content.replace(/(\/\/# sourceMappingURL=)(.*)$/g, (all, prefix, mapFilename) => { | ||
return prefix + filename + ".map"; | ||
}); | ||
return content; | ||
}; | ||
} | ||
} | ||
else if (filename.match(/\.d\.ts$/)) { | ||
// TypeScript definietion file | ||
// e.g. (filename = geturl.d.ts) => diff(geturl.d.ts, browser-geturl.d.ts) | ||
// We do not need to swap anything out, but we need to ensure | ||
// the definition of the node and browser are identical | ||
const replace = replacements[filename.replace(/\.d\.ts$/i, ".js")]; | ||
// Skip! | ||
if (replace === "") { | ||
return; | ||
} | ||
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}`); | ||
} | ||
} | ||
} | ||
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")]; | ||
// Skip! | ||
if (replace === "") { | ||
return; | ||
} | ||
if (replace) { | ||
inputFilename = replace + ".map"; | ||
transform = function (content) { | ||
const data = JSON.parse(content); | ||
data["file"] = filename.replace(/\.js\.map$/, ".js"); | ||
return JSON.stringify(data); | ||
}; | ||
} | ||
} | ||
transforms.push({ input: path_1.join(input, inputFilename), output: path_1.join(output, filename), transform }); | ||
}); | ||
}; | ||
recurse("lib._esm", "lib.esm"); | ||
transforms.forEach(({ input, output, transform }) => { | ||
const sourceFile = path_1.join(baseDir, input); | ||
let content = fs_1.default.readFileSync(sourceFile).toString(); | ||
if (transform) { | ||
content = transform(content); | ||
} | ||
const targetFile = path_1.join(baseDir, output); | ||
const targetDir = path_1.dirname(targetFile); | ||
utils_1.mkdir(targetDir); | ||
fs_1.default.writeFileSync(targetFile, content); | ||
}); | ||
}); | ||
} | ||
(function () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
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++) { | ||
yield alias(dirnames[i]); | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use strict"; | ||
|
||
/** bundle-testcases | ||
* | ||
* This sript converts all the testase data (including needed | ||
* text files) into a single JSON file. | ||
* | ||
* All gzip files (mostly .json.gz) are decompressed and recompressed | ||
* using deflate, so a much more simple deflate library can be used. | ||
*/ | ||
|
||
|
||
import fs from "fs"; | ||
import { join } from "path"; | ||
import zlib from "zlib"; | ||
|
||
import { colorify } from "../log"; | ||
import { resolve } from "../path"; | ||
|
||
const config = { | ||
dirs: [ | ||
"./input/easyseed-bip39", | ||
"./testcases", | ||
"./input/wordlists" | ||
] | ||
}; | ||
|
||
(async function() { | ||
console.log(colorify.bold(`Bundling Testcase Data...`)); | ||
|
||
const data: Record<string, string> = { "_": JSON.stringify({ name: "browser-fs", config: config }) }; | ||
|
||
config.dirs.forEach((dirname) => { | ||
let fulldirname = resolve("packages/testcases", dirname); | ||
fs.readdirSync(fulldirname).forEach((filename) => { | ||
const key = join(dirname, filename); | ||
const content = fs.readFileSync(join(fulldirname, filename)); | ||
if (filename.split(".").pop() === "gz") { | ||
const contentData = zlib.gunzipSync(content); | ||
data[key] = String(contentData.length) + "," + zlib.deflateRawSync(contentData).toString("base64"); | ||
} else { | ||
data[key] = content.toString("base64"); | ||
} | ||
console.log(` - Added ${ key } (${ data[key].length } bytes)`); | ||
}); | ||
}); | ||
|
||
// We write it out to all needed places | ||
fs.writeFileSync(resolve("packages/testcases/lib/browser-data.json"), JSON.stringify(data)); | ||
fs.writeFileSync(resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data)); | ||
fs.writeFileSync(resolve("packages/testcases/lib.esm/browser-data.json"), JSON.stringify(data)); | ||
|
||
// Write it to the TypeScript source last, in case it is running it will | ||
// be regenerated overwriting the above files, but with identical content | ||
fs.writeFileSync(resolve("packages/testcases/src.ts/browser-data.json"), JSON.stringify(data)); | ||
})(); |
Oops, something went wrong.