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.
Fix build, a few errors found in core and express
- Fixes Vite build - Fixes `tsc` - Adds types for config/build.shared.js - Uses shared build config where possible - Adds typedef emit - Fixes reference to `config.json` which works locally but failed in CI
- Loading branch information
1 parent
874b4b8
commit 5af98f3
Showing
10 changed files
with
161 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// @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(); |
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,7 @@ | ||
export { | ||
config, | ||
external, | ||
resolvePath, | ||
readFile, | ||
rootDir, | ||
} from './build.shared'; |
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,42 @@ | ||
// @ts-check | ||
|
||
import fs from 'fs'; | ||
import { createRequire } from 'module'; | ||
import { dirname, resolve } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
export const config = require('./config.json'); | ||
|
||
export const external = [ | ||
'body-parser', | ||
'crypto', | ||
'css.escape', | ||
'express', | ||
'fs', | ||
'language-tags', | ||
'libxslt', | ||
'node1-libxmljsmt-myh', | ||
'path', | ||
'string-direction', | ||
'undici', | ||
'url', | ||
'vite-node', | ||
'vite', | ||
]; | ||
|
||
export const rootDir = dirname(fileURLToPath(import.meta.url)).replace( | ||
/(\/enketo-transformer)(\/.*$)/, | ||
'$1' | ||
); | ||
|
||
/** | ||
* @param {string} path | ||
*/ | ||
export const resolvePath = (path) => resolve(rootDir, path); | ||
|
||
/** | ||
* @param {string} path | ||
*/ | ||
export const readFile = (path) => fs.readFileSync(resolvePath(path), 'utf-8'); |
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,6 +1,6 @@ | ||
{ | ||
"extends": "./tsconfig.base.json", | ||
"exclude": ["dist", "node_modules", "./typings/test.d.ts"], | ||
"include": ["app.ts", "src", "typings"], | ||
"include": ["app.ts", "config", "src", "typings"], | ||
"files": ["./typings/env.d.ts"] | ||
} |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"noEmit": false, | ||
"outDir": "./dist" | ||
}, | ||
"extends": "./tsconfig.json", | ||
"include": ["./src/transformer.ts", "./typings"] | ||
} |
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