@prosopo/config 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -5
- package/src/dependencies.ts +228 -0
- package/src/index.ts +5 -0
- package/src/polkadot/exclude.ts +30 -0
- package/src/polkadot/index.ts +1 -0
- package/src/polkadot/mock.ts +5 -0
- package/src/projectInfo.ts +108 -0
- package/src/provider/index.ts +1 -0
- package/src/provider/test.ts +40 -0
- package/src/tests/paths.test.ts +29 -0
- package/src/vite/index.ts +7 -0
- package/src/vite/types.ts +0 -0
- package/src/vite/vite-plugin-close-and-copy.ts +44 -0
- package/src/vite/vite-plugin-fix-absolute-imports.ts +24 -0
- package/src/vite/vite-plugin-sourcemap-exclude.ts +21 -0
- package/src/vite/vite.backend.config.ts +212 -0
- package/src/vite/vite.commonjs.config.ts +42 -0
- package/src/vite/vite.frontend.config.ts +153 -0
- package/src/vite/vite.test.config.ts +29 -0
- package/tsconfig.json +17 -0
- package/tsconfig.tsbuildinfo +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "Prosopo config library",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,13 +17,14 @@
|
|
|
17
17
|
"author": "Prosopo Limited",
|
|
18
18
|
"license": "Apache-2.0",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@prosopo/common": "0.2.
|
|
21
|
-
"@prosopo/types": "0.2.
|
|
22
|
-
"glob": "^10.0.0"
|
|
20
|
+
"@prosopo/common": "0.2.13",
|
|
21
|
+
"@prosopo/types": "0.2.13",
|
|
22
|
+
"glob": "^10.0.0",
|
|
23
|
+
"path-scurry": "^1.10.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@polkadot/dev": "^0.76.11",
|
|
26
|
-
"@prosopo/util": "0.2.
|
|
27
|
+
"@prosopo/util": "0.2.13",
|
|
27
28
|
"@rollup/plugin-alias": "^5.0.0",
|
|
28
29
|
"@rollup/plugin-babel": "^6.0.3",
|
|
29
30
|
"@rollup/plugin-commonjs": "^24.1.0",
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Glob } from 'glob'
|
|
2
|
+
import { ProjectReference } from 'typescript'
|
|
3
|
+
import { ProsopoEnvError, getLogger } from '@prosopo/common'
|
|
4
|
+
import { at } from '@prosopo/util'
|
|
5
|
+
import child_process from 'child_process'
|
|
6
|
+
import fs from 'fs'
|
|
7
|
+
import path from 'path'
|
|
8
|
+
import util from 'util'
|
|
9
|
+
|
|
10
|
+
const logger = getLogger(`Info`, `config.dependencies.js`)
|
|
11
|
+
const exec = util.promisify(child_process.exec)
|
|
12
|
+
// find a tScOnFiG.jSoN file
|
|
13
|
+
const tsConfigRegex = /\/[A-Za-z.]*\.json$/
|
|
14
|
+
const peerDepsRegex = /UNMET\sOPTIONAL\sDEPENDENCY\s+(@*[\w\-/.]+)@/
|
|
15
|
+
const depsRegex = /\s+(@*[\w\-/.]+)@/
|
|
16
|
+
async function getPackageDir(packageName: string): Promise<string> {
|
|
17
|
+
let pkg = packageName
|
|
18
|
+
if (packageName && !packageName.startsWith('@prosopo/')) {
|
|
19
|
+
pkg = `@prosopo/${packageName}`
|
|
20
|
+
}
|
|
21
|
+
const pkgCommand = `npm list ${pkg} -ap`
|
|
22
|
+
logger.info(`Running command ${pkgCommand}`)
|
|
23
|
+
// get package directory
|
|
24
|
+
const { stdout: packageDir, stderr } = await exec(pkgCommand)
|
|
25
|
+
if (stderr) {
|
|
26
|
+
throw new ProsopoEnvError(new Error(stderr))
|
|
27
|
+
}
|
|
28
|
+
return packageDir.trim()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the tsconfig path for a reference using the initial tsconfig path and the reference path. If the reference
|
|
33
|
+
* does not contain a tsconfig filename, `tsconfig.json` will be appended to the path.
|
|
34
|
+
* @param initialTsConfigPath
|
|
35
|
+
* @param reference
|
|
36
|
+
*/
|
|
37
|
+
function getReferenceTsConfigPath(initialTsConfigPath: string, reference: ProjectReference) {
|
|
38
|
+
// remove tsconfig.*.json from the path and get the path to the new directory via the reference path
|
|
39
|
+
let refTSConfigPath = path.resolve(initialTsConfigPath.replace(tsConfigRegex, ''), reference.path)
|
|
40
|
+
if (!refTSConfigPath.endsWith('.json')) {
|
|
41
|
+
refTSConfigPath = path.resolve(refTSConfigPath, 'tsconfig.json')
|
|
42
|
+
}
|
|
43
|
+
return refTSConfigPath
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the tsconfig paths for a package
|
|
48
|
+
* @param tsConfigPath the tsconfig path to start with
|
|
49
|
+
* @param ignorePatterns the patterns to ignore
|
|
50
|
+
* @param tsConfigPaths the tsconfig paths to add to
|
|
51
|
+
* @param includeInitialTsConfig return the initial tsconfig path in the returned array
|
|
52
|
+
*/
|
|
53
|
+
export function getTsConfigs(
|
|
54
|
+
tsConfigPath: string,
|
|
55
|
+
ignorePatterns: RegExp[] = [],
|
|
56
|
+
tsConfigPaths: string[] = [],
|
|
57
|
+
includeInitialTsConfig = true
|
|
58
|
+
): string[] {
|
|
59
|
+
let tsConfigs = [...tsConfigPaths]
|
|
60
|
+
//TODO use dynamic import with JSON assertion (TS complains that resolveJsonModule is not set)
|
|
61
|
+
const references = JSON.parse(fs.readFileSync(tsConfigPath).toString()).references
|
|
62
|
+
if (!tsConfigs.includes(tsConfigPath)) {
|
|
63
|
+
const ignore =
|
|
64
|
+
ignorePatterns && ignorePatterns.length > 0 ? new RegExp(`${ignorePatterns.join('|')}`) : undefined
|
|
65
|
+
if (includeInitialTsConfig) {
|
|
66
|
+
tsConfigs.push(tsConfigPath)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ignore the packages we don't want to bundle
|
|
70
|
+
const filteredReferences = references.filter((reference: ProjectReference) =>
|
|
71
|
+
ignore ? !ignore.test(reference.path) : false
|
|
72
|
+
)
|
|
73
|
+
// for each reference, get the tsconfig paths - recursively calling this function
|
|
74
|
+
for (const reference of filteredReferences) {
|
|
75
|
+
// remove tsconfig.*.json from the path and get the path to the new directory via the reference path
|
|
76
|
+
const refTSConfigPath = getReferenceTsConfigPath(tsConfigPath, reference)
|
|
77
|
+
|
|
78
|
+
// take the reference TS config path (refTSConfigPath) and get the tsconfig paths for it (newTsConfigs),
|
|
79
|
+
// adding both to a distinct list, as there may be duplicates
|
|
80
|
+
const newTsConfigs = getTsConfigs(refTSConfigPath, ignorePatterns, tsConfigs)
|
|
81
|
+
if (newTsConfigs.length > 0) {
|
|
82
|
+
const distinctTsConfigPaths = new Set(tsConfigs.concat(newTsConfigs))
|
|
83
|
+
tsConfigs = [...distinctTsConfigPaths]
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return tsConfigs
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the workspace externals for a package
|
|
92
|
+
* @param tsConfigPath
|
|
93
|
+
* @param ignorePatterns
|
|
94
|
+
*/
|
|
95
|
+
export async function getExternalsFromReferences(
|
|
96
|
+
tsConfigPath: string,
|
|
97
|
+
ignorePatterns: RegExp[] = []
|
|
98
|
+
): Promise<string[]> {
|
|
99
|
+
const tsConfigPaths = getTsConfigs(tsConfigPath, ignorePatterns, [], false)
|
|
100
|
+
logger.debug('tsConfigPaths', tsConfigPaths)
|
|
101
|
+
const promises: Promise<string>[] = []
|
|
102
|
+
for (const refTsConfigPath of tsConfigPaths) {
|
|
103
|
+
const packageJsonPath = path.resolve(refTsConfigPath.replace(tsConfigRegex, ''), 'package.json')
|
|
104
|
+
promises.push(
|
|
105
|
+
new Promise((resolve, reject) => {
|
|
106
|
+
// if package.json exists, read it and get the package name
|
|
107
|
+
fs.stat(packageJsonPath, (err) => {
|
|
108
|
+
if (err) {
|
|
109
|
+
reject(err)
|
|
110
|
+
}
|
|
111
|
+
fs.readFile(new URL(packageJsonPath, import.meta.url), function (err, buffer) {
|
|
112
|
+
if (err) {
|
|
113
|
+
reject(err)
|
|
114
|
+
} else {
|
|
115
|
+
const packageJson = JSON.parse(buffer.toString())
|
|
116
|
+
const pkg = packageJson.name
|
|
117
|
+
resolve(pkg)
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
const externals = await Promise.all(promises)
|
|
125
|
+
logger.debug('externals', externals)
|
|
126
|
+
return externals
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Get the dependencies for a package
|
|
131
|
+
* @param packageName
|
|
132
|
+
* @param production
|
|
133
|
+
*/
|
|
134
|
+
export async function getDependencies(
|
|
135
|
+
packageName?: string,
|
|
136
|
+
production?: boolean
|
|
137
|
+
): Promise<{ dependencies: string[]; optionalPeerDependencies: string[] }> {
|
|
138
|
+
let cmd = production ? 'npm ls -a --omit=dev' : 'npm ls -a'
|
|
139
|
+
|
|
140
|
+
if (packageName) {
|
|
141
|
+
const packageDir = await getPackageDir(packageName)
|
|
142
|
+
cmd = `cd ${packageDir.trim()} && ${cmd}`
|
|
143
|
+
logger.info(`Running command ${cmd} in ${packageDir}`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const { stdout, stderr } = await exec(cmd)
|
|
147
|
+
if (stderr) {
|
|
148
|
+
throw new ProsopoEnvError(new Error(stderr))
|
|
149
|
+
}
|
|
150
|
+
const deps: string[] = []
|
|
151
|
+
const peerDeps: string[] = []
|
|
152
|
+
// for each line, check if there is an unmet optional dependency
|
|
153
|
+
stdout.split('\n').forEach((line) => {
|
|
154
|
+
if (line.includes('UNMET OPTIONAL DEPENDENCY')) {
|
|
155
|
+
// │ │ │ ├── UNMET OPTIONAL DEPENDENCY bufferutil@^4.0.1
|
|
156
|
+
const parts = line.match(peerDepsRegex)
|
|
157
|
+
if (parts && parts.length > 1) {
|
|
158
|
+
peerDeps.push(at(parts, 1))
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
// │ │ │ ├─┬ mongodb-memory-server-core@8.15.1
|
|
162
|
+
const parts = line.match(depsRegex)
|
|
163
|
+
if (parts && parts.length > 1) {
|
|
164
|
+
deps.push(at(parts, 1))
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
// dedupe and return deps and peer deps
|
|
169
|
+
return {
|
|
170
|
+
dependencies: deps.filter((x, i) => i === deps.indexOf(x)),
|
|
171
|
+
optionalPeerDependencies: peerDeps.filter((x, i) => i === peerDeps.indexOf(x)),
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Filter out the dependencies we don't want
|
|
177
|
+
* @param deps
|
|
178
|
+
* @param filters
|
|
179
|
+
*/
|
|
180
|
+
export function filterDependencies(deps: string[], filters: string[]): { internal: string[]; external: string[] } {
|
|
181
|
+
const depsDeduped = deps.filter((x, i) => i === deps.indexOf(x))
|
|
182
|
+
const depsWithLength = depsDeduped.filter((dep) => dep.length > 0).sort()
|
|
183
|
+
const exclude = new RegExp(`${filters.join('|')}`)
|
|
184
|
+
// filter out the deps we don't want
|
|
185
|
+
const internal: string[] = []
|
|
186
|
+
const external: string[] = []
|
|
187
|
+
for (const dep of depsWithLength) {
|
|
188
|
+
if (exclude.test(dep)) {
|
|
189
|
+
external.push(dep)
|
|
190
|
+
} else {
|
|
191
|
+
internal.push(dep)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return { internal, external }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Takes an array of partial module directories, finds the full path, and returns an array containing the file paths
|
|
198
|
+
* of the files contained within the matching module directories [ filePath, filePath, ... ]
|
|
199
|
+
* @param startDir
|
|
200
|
+
* @param includePatterns
|
|
201
|
+
* @param excludePatterns
|
|
202
|
+
* @returns
|
|
203
|
+
* @example
|
|
204
|
+
* const includePatterns = ['kusama.js', 'westend.js']
|
|
205
|
+
* const excludePatterns = ['bytes.js']
|
|
206
|
+
* const startDir = path.resolve(__dirname, '../../node_modules/@polkadot')
|
|
207
|
+
* const files = getFilesInDirs(startDir, includePatterns, excludePatterns)
|
|
208
|
+
* console.log(files)
|
|
209
|
+
* // [ '/home/.../node_modules/@polkadot/types/interfaces/bytes/bytes.js',
|
|
210
|
+
* // '/home/.../node_modules/@polkadot/types/interfaces/bytes/bytes.d.ts']
|
|
211
|
+
* */
|
|
212
|
+
export function getFilesInDirs(startDir: string, includePatterns: string[] = [], excludePatterns: string[] = []) {
|
|
213
|
+
const files: string[] = []
|
|
214
|
+
logger.info(`getFilesInDirs: ${startDir} excluding ${includePatterns} including ${excludePatterns}`)
|
|
215
|
+
const ignorePatterns = excludePatterns.map((pattern) => `${startDir}/**/${pattern}`)
|
|
216
|
+
includePatterns.forEach((searchPattern) => {
|
|
217
|
+
// get matching module directories
|
|
218
|
+
const globPattern = `${startDir}/**/${searchPattern}${searchPattern.indexOf('.') > -1 ? '' : '/*'}`
|
|
219
|
+
//log.info(`globPattern: ${globPattern}`)
|
|
220
|
+
const globResult = new Glob(globPattern, { recursive: true, ignore: ignorePatterns }).walkSync()
|
|
221
|
+
//log.info(`globResult: ${globResult}`)
|
|
222
|
+
for (const filePath of globResult) {
|
|
223
|
+
files.push(filePath)
|
|
224
|
+
//log.info(`ignoring ${filePath}`)
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
return files
|
|
228
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Alias } from 'vite'
|
|
2
|
+
import { getLogger } from '@prosopo/common'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
|
|
5
|
+
const log = getLogger(`Info`, `config.polkadot.exclude.js`)
|
|
6
|
+
export function excludePolkadot() {
|
|
7
|
+
//'bytes.js'] //...interfacesToIgnore]
|
|
8
|
+
//const startDir = path.resolve(path.resolve(), '../../node_modules/@polkadot')
|
|
9
|
+
//log.info(`startDir: ${startDir}`)
|
|
10
|
+
//return getFilesInDirs(startDir, excludeFiles)
|
|
11
|
+
return ['./kusama.js', './westend.js', './cjs/bytes.js']
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getAliases(dir: string): Alias[] {
|
|
15
|
+
const polkadotFilesToAlias = excludePolkadot()
|
|
16
|
+
const alias: Alias[] = []
|
|
17
|
+
// TODO Is there a way to determine this path by importing mock.js?
|
|
18
|
+
const mockFile = path.resolve(dir, '../config/dist/polkadot/mock.js')
|
|
19
|
+
polkadotFilesToAlias.forEach((file) => {
|
|
20
|
+
log.info(`resolving ${file} to mock.js`)
|
|
21
|
+
alias.push({ find: file, replacement: mockFile })
|
|
22
|
+
})
|
|
23
|
+
for (const pkg of ['api', 'api-contract', 'extension-dapp', 'types', 'util', 'util-crypto']) {
|
|
24
|
+
alias.push({
|
|
25
|
+
find: new RegExp(`/@polkadot/${pkg}$/`),
|
|
26
|
+
replacement: path.resolve(dir, `../../node_modules/@polkadot/${pkg}/bundle-polkadot-${pkg}.js`),
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
return alias
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { excludePolkadot, getAliases } from './exclude.js'
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export const getContractNames = () => {
|
|
2
|
+
return ['captcha', 'common', 'proxy']
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export type Paths = {
|
|
6
|
+
root: string
|
|
7
|
+
dev: string
|
|
8
|
+
demos: string
|
|
9
|
+
contract: string
|
|
10
|
+
protocol: string
|
|
11
|
+
packages: string
|
|
12
|
+
config: string
|
|
13
|
+
scripts: string
|
|
14
|
+
protocolCli: string
|
|
15
|
+
protocolDist: string
|
|
16
|
+
clientExample: string
|
|
17
|
+
clientExampleServer: string
|
|
18
|
+
clientBundleExample: string
|
|
19
|
+
dappExample: string
|
|
20
|
+
common: string
|
|
21
|
+
api: string
|
|
22
|
+
cli: string
|
|
23
|
+
util: string
|
|
24
|
+
database: string
|
|
25
|
+
datasets: string
|
|
26
|
+
datasetsFs: string
|
|
27
|
+
env: string
|
|
28
|
+
fileServer: string
|
|
29
|
+
procaptcha: string
|
|
30
|
+
procaptchaReact: string
|
|
31
|
+
procaptchaBundle: string
|
|
32
|
+
provider: string
|
|
33
|
+
server: string
|
|
34
|
+
typesDatabase: string
|
|
35
|
+
typesEnv: string
|
|
36
|
+
types: string
|
|
37
|
+
contractPackagesDir: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const getPaths = (): Paths => {
|
|
41
|
+
const root = new URL('../../..', import.meta.url).pathname.slice(0, -1)
|
|
42
|
+
const dev = `${root}/dev`
|
|
43
|
+
const packages = `${root}/packages`
|
|
44
|
+
const protocol = `${root}/protocol`
|
|
45
|
+
const demos = `${root}/demos`
|
|
46
|
+
const contract = `${packages}/contract`
|
|
47
|
+
const types = `${packages}/types`
|
|
48
|
+
const config = `${dev}/config`
|
|
49
|
+
const scripts = `${dev}/scripts`
|
|
50
|
+
const protocolCli = `${protocol}/dist/cli`
|
|
51
|
+
const protocolDist = `${protocol}/target/ink`
|
|
52
|
+
const clientExample = `${demos}/client-example`
|
|
53
|
+
const clientExampleServer = `${demos}/client-example-server`
|
|
54
|
+
const clientBundleExample = `${demos}/client-bundle-example`
|
|
55
|
+
const dappExample = `${demos}/dapp-example`
|
|
56
|
+
const common = `${packages}/common`
|
|
57
|
+
const api = `${packages}/api`
|
|
58
|
+
const cli = `${packages}/cli`
|
|
59
|
+
const util = `${packages}/util`
|
|
60
|
+
const database = `${packages}/database`
|
|
61
|
+
const datasets = `${packages}/datasets`
|
|
62
|
+
const datasetsFs = `${packages}/datasets-fs`
|
|
63
|
+
const env = `${packages}/env`
|
|
64
|
+
const fileServer = `${packages}/file-server`
|
|
65
|
+
const procaptcha = `${packages}/procaptcha`
|
|
66
|
+
const procaptchaReact = `${packages}/procaptcha-react`
|
|
67
|
+
const procaptchaBundle = `${packages}/procaptcha-bundle`
|
|
68
|
+
const provider = `${packages}/provider`
|
|
69
|
+
const server = `${packages}/server`
|
|
70
|
+
const typesDatabase = `${packages}/types-database`
|
|
71
|
+
const typesEnv = `${packages}/types-env`
|
|
72
|
+
const contractPackagesDir = `${root}/contracts`
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
contractPackagesDir,
|
|
76
|
+
root,
|
|
77
|
+
dev,
|
|
78
|
+
demos,
|
|
79
|
+
contract,
|
|
80
|
+
protocol,
|
|
81
|
+
packages,
|
|
82
|
+
config,
|
|
83
|
+
scripts,
|
|
84
|
+
protocolCli,
|
|
85
|
+
protocolDist,
|
|
86
|
+
clientExample,
|
|
87
|
+
clientExampleServer,
|
|
88
|
+
clientBundleExample,
|
|
89
|
+
dappExample,
|
|
90
|
+
common,
|
|
91
|
+
api,
|
|
92
|
+
cli,
|
|
93
|
+
util,
|
|
94
|
+
database,
|
|
95
|
+
datasets,
|
|
96
|
+
datasetsFs,
|
|
97
|
+
env,
|
|
98
|
+
fileServer,
|
|
99
|
+
procaptcha,
|
|
100
|
+
procaptchaReact,
|
|
101
|
+
procaptchaBundle,
|
|
102
|
+
provider,
|
|
103
|
+
server,
|
|
104
|
+
typesDatabase,
|
|
105
|
+
typesEnv,
|
|
106
|
+
types,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as getTestConfig } from './test.js'
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DatabaseTypes,
|
|
3
|
+
EnvironmentTypesSchema,
|
|
4
|
+
NetworkNamesSchema,
|
|
5
|
+
NetworkPairTypeSchema,
|
|
6
|
+
ProsopoConfigSchema,
|
|
7
|
+
} from '@prosopo/types'
|
|
8
|
+
import { getLogLevel } from '@prosopo/common'
|
|
9
|
+
|
|
10
|
+
const logLevel = getLogLevel()
|
|
11
|
+
export default function getTestConfig() {
|
|
12
|
+
return ProsopoConfigSchema.parse({
|
|
13
|
+
logLevel,
|
|
14
|
+
defaultEnvironment: EnvironmentTypesSchema.Values.development,
|
|
15
|
+
defaultNetwork: NetworkNamesSchema.Values.development,
|
|
16
|
+
account: {
|
|
17
|
+
password: '',
|
|
18
|
+
address: '',
|
|
19
|
+
},
|
|
20
|
+
database: {
|
|
21
|
+
development: { type: DatabaseTypes.enum.mongoMemory, endpoint: '', dbname: 'prosopo_test', authSource: '' },
|
|
22
|
+
},
|
|
23
|
+
server: {
|
|
24
|
+
baseURL: 'http://localhost',
|
|
25
|
+
port: 9229,
|
|
26
|
+
fileServePaths: '[]',
|
|
27
|
+
},
|
|
28
|
+
networks: {
|
|
29
|
+
development: {
|
|
30
|
+
endpoint: 'ws://localhost:9944',
|
|
31
|
+
contract: {
|
|
32
|
+
address: process.env.PROTOCOL_CONTRACT_ADDRESS || '',
|
|
33
|
+
name: 'prosopo',
|
|
34
|
+
},
|
|
35
|
+
pairType: NetworkPairTypeSchema.parse('sr25519'),
|
|
36
|
+
ss58Format: 42,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { describe, expect, test } from 'vitest'
|
|
15
|
+
import { flattenObj } from '@prosopo/util'
|
|
16
|
+
import { getPaths } from '../projectInfo.js'
|
|
17
|
+
import fs from 'fs'
|
|
18
|
+
|
|
19
|
+
describe('paths', () => {
|
|
20
|
+
test('paths exist', () => {
|
|
21
|
+
const paths = getPaths()
|
|
22
|
+
const flat = flattenObj(paths)
|
|
23
|
+
for (const [key, value] of Object.entries(flat)) {
|
|
24
|
+
expect(value).to.not.be.undefined
|
|
25
|
+
expect(value).to.not.be.null
|
|
26
|
+
expect(fs.existsSync(String(value))).to.be.true
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as VitePluginCloseAndCopy } from './vite-plugin-close-and-copy.js'
|
|
2
|
+
export { default as ViteTestConfig } from './vite.test.config.js'
|
|
3
|
+
export { default as VitePluginSourceMapExclude } from './vite-plugin-sourcemap-exclude.js'
|
|
4
|
+
export { default as ViteFrontendConfig } from './vite.frontend.config.js'
|
|
5
|
+
export { default as ViteBackendConfig } from './vite.backend.config.js'
|
|
6
|
+
export { default as VitePluginFixAbsoluteImports } from './vite-plugin-fix-absolute-imports.js'
|
|
7
|
+
export { default as ViteCommonJSConfig } from './vite.commonjs.config.js'
|
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Plugin } from 'vite'
|
|
2
|
+
import { getLogger } from '@prosopo/common'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
const log = getLogger(`Info`, `config.vite.vite-plugin-close.js`)
|
|
6
|
+
export interface ClosePluginOptions {
|
|
7
|
+
srcDir: string
|
|
8
|
+
destDir: string
|
|
9
|
+
bundleName: string
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* description: Closes Vite after the bundle has been build. Optionally copies the bundle to a different directory.
|
|
13
|
+
* @param { ClosePluginOptions } options - The options object
|
|
14
|
+
**/
|
|
15
|
+
export default function VitePluginCloseAndCopy(options?: ClosePluginOptions): Plugin {
|
|
16
|
+
const __dirname = path.resolve()
|
|
17
|
+
return {
|
|
18
|
+
name: 'close-plugin', // required, will show up in warnings and errors
|
|
19
|
+
buildStart() {
|
|
20
|
+
log.info('Bundle build started')
|
|
21
|
+
},
|
|
22
|
+
buildEnd(error) {
|
|
23
|
+
log.info('Build end')
|
|
24
|
+
if (error) {
|
|
25
|
+
console.log(error)
|
|
26
|
+
log.error(error)
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
closeBundle() {
|
|
30
|
+
if (options) {
|
|
31
|
+
for (const file of fs.readdirSync(path.resolve(__dirname, options.srcDir))) {
|
|
32
|
+
if (file.startsWith(options.bundleName) && file.endsWith('js')) {
|
|
33
|
+
const src = path.resolve(__dirname, options.srcDir, file)
|
|
34
|
+
const dest = path.resolve(__dirname, options.destDir, file)
|
|
35
|
+
fs.copyFileSync(src, dest)
|
|
36
|
+
log.info(`Copied ${src} to ${dest}`)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
log.info('Bundle closed')
|
|
41
|
+
process.exit(0)
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { builtinModules } from 'module'
|
|
2
|
+
import type { Plugin } from 'vite'
|
|
3
|
+
|
|
4
|
+
export default function VitePluginFixAbsoluteImports(): Plugin {
|
|
5
|
+
return {
|
|
6
|
+
name: 'fix-absolute-imports',
|
|
7
|
+
transform(code: string, id: string) {
|
|
8
|
+
for (const module of builtinModules) {
|
|
9
|
+
const moduleImportRegex = new RegExp(`from "(${module}(/.*)*/.*.js)";`, 'g')
|
|
10
|
+
// if matches, replace match with _module
|
|
11
|
+
const matches = code.match(moduleImportRegex)
|
|
12
|
+
if (matches) {
|
|
13
|
+
for (const match of matches) {
|
|
14
|
+
code = code.replace(match, `from "${module}";`)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
code,
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
enforce: 'post',
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Plugin } from 'vite'
|
|
2
|
+
|
|
3
|
+
interface SourcemapExclude {
|
|
4
|
+
excludeNodeModules?: boolean
|
|
5
|
+
}
|
|
6
|
+
// Taken from https://github.com/vitejs/vite/issues/2433#issuecomment-1487472995 to prevent memory leaks
|
|
7
|
+
export default function VitePluginSourcemapExclude(opts?: SourcemapExclude): Plugin {
|
|
8
|
+
return {
|
|
9
|
+
name: 'sourcemap-exclude',
|
|
10
|
+
transform(code: string, id: string) {
|
|
11
|
+
if (opts?.excludeNodeModules && id.includes('node_modules')) {
|
|
12
|
+
return {
|
|
13
|
+
code,
|
|
14
|
+
// https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations
|
|
15
|
+
map: { mappings: '' },
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
}
|