-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See if the 'web' build target is actually cross platform for our use …
…case Shrink generate WASM by 25% Save 9KB Set up web test Add more scripts Restore node testing Without wee_alloc, we grow ~ 450KB With no allocator, we get down to 540KB, but the thing doesn't run Back up to 1.2MB, but working in the browser With no changes to the allocator, we are at 1.2MB Give up on custom allocators since they all have problems Switch to dual build Update the README and document how to use Browser (ESM), Node (ESM) and Node (CJS) Update ci.yml Determine that it's simpler to not use a custom allocator -- there must be other ways to get the wasm size down tho Remove browser test experiments
- Loading branch information
1 parent
a396fcf
commit 2ebc973
Showing
10 changed files
with
193 additions
and
6 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
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,2 +1,3 @@ | ||
pkg/ | ||
/target | ||
/node_modules | ||
/node_modules |
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
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,23 @@ | ||
#!/bin/bash | ||
|
||
rm -rf pkg | ||
|
||
# wasm-pack knows to use wasm-opt, when present | ||
# NOTE: wasm-pack does not support multi-target building | ||
# so we'll build twice, and then tweak package.json | ||
# "exports" to point at the correct build depending on node or browser | ||
wasm-pack build --target web --out-dir pkg/browser --weak-refs --no-pack --release | ||
wasm-pack build --target nodejs --out-dir pkg/node --weak-refs --no-pack --release | ||
|
||
# Rename the node js file to cjs, because we emit type=module | ||
mv pkg/node/content_tag.js pkg/node/content_tag.cjs | ||
|
||
# generate the rest of the package for npm, since | ||
# we disabled package.json generation above with --no-pack. | ||
# this needs to be done because we're targeting | ||
# both browser and node, which wasm-packg doesn't natively support. | ||
node ./post-wasm-build.mjs | ||
|
||
# --------- | ||
cp LICENSE pkg/LICENSE | ||
cp README.md pkg/README.md |
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,22 @@ | ||
<html> | ||
<head> | ||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/> | ||
<script type="module"> | ||
import init, { Preprocessor } from './pkg/browser/content_tag.js'; | ||
|
||
async function run() { | ||
await init(); | ||
|
||
const p = new Preprocessor(); | ||
const output = p.process('<template>Hi</template>'); | ||
|
||
document.querySelector('#output').innerHTML = output; | ||
} | ||
|
||
run(); | ||
</script> | ||
</head> | ||
<body> | ||
<pre id="output"></pre> | ||
</body> | ||
</html> |
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 |
---|---|---|
|
@@ -5,15 +5,18 @@ | |
"url": "[email protected]:embroider-build/content-tag.git" | ||
}, | ||
"scripts": { | ||
"web": "npx html-pages . --no-cache", | ||
"test": "mocha" | ||
}, | ||
"devDependencies": { | ||
"@release-it-plugins/lerna-changelog": "^6.0.0", | ||
"@release-it/bumper": "^5.1.0", | ||
"chai": "^4.3.7", | ||
"code-equality-assertions": "github:mansona/code-equality-assertions#add-chai-build", | ||
"content-tag": "file:./pkg", | ||
"eslint": "^8.44.0", | ||
"mocha": "^10.2.0", | ||
"toml": "^3.0.0", | ||
"release-it": "^16.2.1" | ||
}, | ||
"publishConfig": { | ||
|
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,37 @@ | ||
// This post-wasm-build.js script is called from build.sh | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import toml from 'toml'; | ||
|
||
let cargo = await fs.readFile('Cargo.toml', 'utf8'); | ||
let config = toml.parse(cargo); | ||
|
||
|
||
const manifest = { | ||
"name": config.package.name, | ||
"description": config.package.description, | ||
"version": config.package.version, | ||
"license": config.package.license, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/embroider-build/content-tag" | ||
}, | ||
"files": [ | ||
"browser", | ||
"node" | ||
], | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./browser/content_tag.js", | ||
"require": "./node/content_tag.cjs", | ||
"types": "./browser/content_tag.d.ts" | ||
} | ||
} | ||
}; | ||
|
||
|
||
|
||
const content = JSON.stringify(manifest, null, 2); | ||
|
||
await fs.writeFile('pkg/package.json', content); |
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,60 @@ | ||
import { createRequire } from 'node:module'; | ||
import chai from 'chai'; | ||
import { codeEquality } from "code-equality-assertions/chai"; | ||
|
||
chai.use(codeEquality) | ||
|
||
const { expect } = chai; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
const { Preprocessor } = require('content-tag'); | ||
const p = new Preprocessor(); | ||
|
||
describe("Node ESM", function() { | ||
it("works for a basic example", function() { | ||
let output = p.process('<template>Hi</template>'); | ||
|
||
expect(output).to.equalCode(`import { template } from "@ember/template-compiler"; | ||
export default template("Hi", { | ||
eval () { | ||
return eval(arguments[0]); | ||
} | ||
});`); | ||
}); | ||
|
||
it("Emits parse errors with anonymous file", function() { | ||
expect(function() { | ||
p.process(`const thing = "face"; | ||
<template>Hi`); | ||
}).to.throw(`Parse Error at <anon>:2:15: 2:15`); | ||
}); | ||
|
||
it("Emits parse errors with real file", function() { | ||
expect(function() { | ||
p.process(`const thing = "face"; | ||
<template>Hi`, "path/to/my/component.gjs"); | ||
}).to.throw(`Parse Error at path/to/my/component.gjs:2:15: 2:15`); | ||
}); | ||
|
||
it("Offers source_code snippet on parse errors", function() { | ||
let parseError; | ||
try { | ||
p.process(`class {`) | ||
} catch (err) { | ||
parseError = err; | ||
} | ||
expect(parseError).to.have.property("source_code").matches(/Expected ident.*class \{/s); | ||
}); | ||
|
||
it("Offers source_code_color snippet on parse errors", function() { | ||
let parseError; | ||
try { | ||
p.process(`class {`) | ||
} catch (err) { | ||
parseError = err; | ||
} | ||
// eslint-disable-next-line no-control-regex | ||
expect(parseError).to.have.property("source_code_color").matches(/Expected ident.*[\u001b].*class \{/s); | ||
}); | ||
}) |
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