This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Introduces an abstract subset of DOM APIs corresponding to previous usage of semantically equivalent `libxmljs` APIs. It would have been nicer to import these types and export the subset we care about, but this is inconsistent with how TypeScript `lib` works (it always augments the global scope). 2. Provides a Node implementation of those DOM APIs by extending `libxmljs` prototypes. This kind of extension isn't ideal, but it's the most reasonable way to achieve such a compatibility layer without sacrificing performance. An ealirer alternative approach used `WeakMap`s to cross reference the DOM/`libxmljs` interfaces, but this had a significant impact on perf. This implementation is type checked by default. 3. Provides a web implementation by... just exporting the relevant globals. This implementation is type checked by `tsc` using the `tsconfig.web.json` project file. This ensures that the abstract DOM interfaces are actully consistent with the built in DOM `lib` types. 4. Refactors transformer.ts to use the abstract DOM APIs. This uses the Node DOM compatibility implementation by default, and the native web DOM implementation when the environment variable `ENV` is set to "web". 5. Also when `ENV` is web, tests and benchmarks call `transform` in the specified `BROWSER` environment variable (defaulting to "fiefox") via a simple `playwright` bridge. In CI, all tests and benchmarks are run in: Node 14, Node 16, Firefox, Chromium, Webkit. 6. Build is updated to produce both Node and web targets. The build config itself is fairly complex, but it's been consolidated in `vite.config.ts`. This also includes a corresponding change to build `app.ts` rather than the previous, much more complex `app.js` using a Vite dev server (and roughly restores its implementation to what it had been prior to the initial TypeScript migration). 7. There are several known issues at the point of this commit. These either correspond to XSLT extensions not supported by browser targets, or to differences in behavior between DOM/`libxmljs`, all of which will be addressed in separate commits discussing each in greater detail.
- Loading branch information
1 parent
e02efa9
commit 6242fbe
Showing
47 changed files
with
1,646 additions
and
714 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
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,63 +1 @@ | ||
// @ts-check | ||
|
||
import { createServer } from 'vite'; | ||
import { VitePluginNode } from 'vite-plugin-node'; | ||
import { | ||
config, | ||
external, | ||
resolvePath, | ||
rootDir, | ||
} from './config/build.shared.js'; | ||
|
||
const appPath = resolvePath('./app.ts'); | ||
|
||
const init = async () => { | ||
/** @type {import('vite').UserConfig} */ | ||
const baseOptions = { | ||
mode: 'development', | ||
build: { | ||
rollupOptions: { | ||
external, | ||
}, | ||
}, | ||
optimizeDeps: { | ||
disabled: true, | ||
}, | ||
root: rootDir, | ||
ssr: { | ||
target: 'node', | ||
}, | ||
}; | ||
|
||
const servers = await Promise.all([ | ||
createServer({ | ||
...baseOptions, | ||
configFile: false, | ||
plugins: VitePluginNode({ | ||
adapter: 'express', | ||
appPath, | ||
exportName: 'app', | ||
tsCompiler: 'esbuild', | ||
}), | ||
server: { | ||
port: config.port, | ||
}, | ||
}), | ||
createServer({ | ||
...baseOptions, | ||
configFile: false, | ||
publicDir: resolvePath('./test/forms'), | ||
server: { | ||
port: 8081, | ||
}, | ||
}), | ||
]); | ||
|
||
await Promise.all(servers.map((server) => server.listen())); | ||
|
||
servers.forEach((server) => { | ||
server.printUrls(); | ||
}); | ||
}; | ||
|
||
init(); | ||
import './dist/enketo-transformer/app.cjs'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="./icon.png" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Enketo Transformer (web)</title> | ||
</head> | ||
<body> | ||
<script type="module"> | ||
import { transform } from './src/transformer.ts'; | ||
|
||
globalThis.enketo = { | ||
transformer: { transform }, | ||
}; | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.