Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just like the DTS build, the web build now exports functions instead of being spawned as a child process. Also, the web build no longer fails silently upon error.
- Loading branch information
1 parent
12a2867
commit 5fc8a8f
Showing
2 changed files
with
52 additions
and
51 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,42 +1,43 @@ | ||
import path from "path"; | ||
import {dirname, join} from "path"; | ||
import fs from "fs"; | ||
import { createRequire } from "module"; | ||
import { fileURLToPath } from "url"; | ||
|
||
const dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const require = createRequire(import.meta.url); | ||
const pkg = require("../package-lock.json"); | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const mainVersion = pkg.version; | ||
const binaryenVersion = pkg.dependencies.binaryen.version; | ||
const longVersion = pkg.dependencies.long.version; | ||
export function buildWeb() { | ||
const pkg = JSON.parse(fs.readFileSync(join(__dirname, "../package-lock.json"))); | ||
|
||
const distUrl = mainVersion === "0.0.0" ? `./` : `https://cdn.jsdelivr.net/npm/assemblyscript@${mainVersion}/dist/`; | ||
const binaryenUrl = `https://cdn.jsdelivr.net/npm/binaryen@${binaryenVersion}/index.js`; | ||
const longUrl = `https://cdn.jsdelivr.net/npm/long@${longVersion}/index.js`; | ||
const importmap = { | ||
"imports": { | ||
"assemblyscript": `${distUrl}assemblyscript.js`, | ||
"assemblyscript/asc": `${distUrl}asc.js`, | ||
"binaryen": binaryenUrl, | ||
"long": longUrl | ||
} | ||
}; | ||
const mainVersion = pkg.version; | ||
const binaryenVersion = pkg.dependencies.binaryen.version; | ||
const longVersion = pkg.dependencies.long.version; | ||
|
||
const distUrl = mainVersion === "0.0.0" ? `./` : `https://cdn.jsdelivr.net/npm/assemblyscript@${mainVersion}/dist/`; | ||
const binaryenUrl = `https://cdn.jsdelivr.net/npm/binaryen@${binaryenVersion}/index.js`; | ||
const longUrl = `https://cdn.jsdelivr.net/npm/long@${longVersion}/index.js`; | ||
const importmap = { | ||
"imports": { | ||
"assemblyscript": `${distUrl}assemblyscript.js`, | ||
"assemblyscript/asc": `${distUrl}asc.js`, | ||
"binaryen": binaryenUrl, | ||
"long": longUrl | ||
} | ||
}; | ||
|
||
fs.writeFileSync(path.join(dirname, "..", "dist", "importmap.json"), `${JSON.stringify(importmap, null, 2)} | ||
`); | ||
fs.writeFileSync(path.join(dirname, "..", "dist", "web.js"), `var ASSEMBLYSCRIPT_VERSION = ${JSON.stringify(mainVersion)}; | ||
var ASSEMBLYSCRIPT_IMPORTMAP = ${JSON.stringify(importmap, null, 2)}; | ||
if (!document.currentScript.src.includes("noinstall")) { | ||
let elem = document.createElement("script"); | ||
elem.type = "importmap"; | ||
elem.text = JSON.stringify(ASSEMBLYSCRIPT_IMPORTMAP); | ||
document.head.appendChild(elem); | ||
} | ||
if (!document.currentScript.src.includes("noshim")) { | ||
let elem = document.createElement("script"); | ||
elem.async = true; | ||
elem.src = "https://cdn.jsdelivr.net/npm/es-module-shims@1/dist/es-module-shims.wasm.min.js"; | ||
document.head.appendChild(elem); | ||
} | ||
`); | ||
fs.writeFileSync(join(__dirname, "..", "dist", "importmap.json"), `${JSON.stringify(importmap, null, 2)} | ||
`); | ||
fs.writeFileSync(join(__dirname, "..", "dist", "web.js"), `var ASSEMBLYSCRIPT_VERSION = ${JSON.stringify(mainVersion)}; | ||
var ASSEMBLYSCRIPT_IMPORTMAP = ${JSON.stringify(importmap, null, 2)}; | ||
if (!document.currentScript.src.includes("noinstall")) { | ||
let elem = document.createElement("script"); | ||
elem.type = "importmap"; | ||
elem.text = JSON.stringify(ASSEMBLYSCRIPT_IMPORTMAP); | ||
document.head.appendChild(elem); | ||
} | ||
if (!document.currentScript.src.includes("noshim")) { | ||
let elem = document.createElement("script"); | ||
elem.async = true; | ||
elem.src = "https://cdn.jsdelivr.net/npm/es-module-shims@1/dist/es-module-shims.wasm.min.js"; | ||
document.head.appendChild(elem); | ||
} | ||
`); | ||
} |
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